Learnings from 100K lines of Rust with AI (2025)

(zfhuang99.github.io)

40 points | by pramodbiligiri an hour ago ago

20 comments

  • jdw64 26 minutes ago

    I'm also shifting to an vibe coding workflow, but I have a genuine question: whenever I use AI for Rust, it makes an insane amount of lifetime errors. I have no idea how people are churning out so many lines of code so quickly.

    Honestly, despite all the hype around Rust in the community, the fact that AI can't handle lifetimes reliably makes me reluctant to use it. The AI constantly defaults to spamming .clone() or wrapping things in Rc, completely butchering idiomatic Rust and making the output a pain to work with.

    On the other hand, it writes higher-level languages better than I do. For those succeeding with it, how exactly are you configuring or prompting the AI to actually write good, idiomatic Rust

    • embedding-shape 6 minutes ago

      > I'm also shifting to an vibe coding workflow, but I have a genuine question: whenever I use AI for Rust, it makes an insane amount of lifetime errors. I have no idea how people are churning out so many lines of code so quickly.

      What harness and model you've been using? For the last few months, essentially since I did the whole "One Human + One Agent = One Browser From Scratch" experiment, I've almost exclusively been doing cross-platform native desktop development with Rust, currently with my own homegrown toolkit basically written from scratch, all with LLMs, mostly with codex.

      But I can't remember a single time the agent got stuck on lifetime errors, that's probably the least common issue in regards with agents + Rust I come across. Much bigger issue is the ever-expanding design and LLMs being unable to build proper abstractions that are actually used practically and reduces the amount of code instead of just adding to the hairball.

      The issue I'm trying to overcome now is that each change takes longer and longer to make, unless you're really hardcore about pulling back the design/architecture when the LLM goes overboard. I've only succeeded in having ~10 minute edits in +100K LOC codebases in two of the projects I've done so far, probably because I spent most of the time actually defining and thinking of the design myself instead of outsourcing it to the LLM. But this is the biggest issue I'm hitting over and over with agents right now.

    • hydra-f 19 minutes ago

      A lefthook:

      format: glob: ".rs" run: cargo fmt -- --check

      lint: glob: ".rs" run: cargo clippy -- -D warnings

      tests: run: cargo test

      audit: run: cargo audit

      + hooks that shove the lefthook automatically in the ai's face

      ---

      rustfmt.toml:

      edition = "2021" newline_style = "Unix" use_small_heuristics = "Max" max_width = 100

    • faitswulff 11 minutes ago

      What kinds of programs are you writing and with what models? I'm curious if the lifetimes your programs require are trickier than most.

    • altmanaltman a minute ago

      I think it's due to the lack of quality instructions on what is good Rust code; AI often literally doesn't know what idiomatic Rust is. It can be good to have a reference where you write the basic rules that you want it to follow (ideal to assume it has no idea why spamming clone is bad and you're speaking to someone who has just watched one of those youtube videos with a dude in black t-shirt speaking very slowly and going over basic programming concepts as if they're breaking you out of the matrix).

    • dijit 23 minutes ago

      The feedback loop is the interesting part, if you use standard software engineering practices (modularise, test/document your interfaces, etc) then I find things like Claude Code do an exceptional job: since they can actually run cargo check/test themselves and can validate the tests too.

    • vermilingua 13 minutes ago

      The irony of the machines having no mechanical sympathy is just too good

  • icemanx 6 minutes ago

    How many of those tests have you actually read yourself if all of them are generated by AI (also when you're sleeping) ?

    This is from 2025 - I would like to see an update now how that system turned out to be after the vibe hype

  • torben-friis an hour ago

    >Testing is the first layer of defense. My system now includes 1,300+ tests — from unit tests to minimal integration tests (e.g., proposer + acceptor only), all the way to multi-replica full integration tests with injected failures. See the project status.

    I know LOC is a silly metric, but ~1300 tests for 130k lines averages out to a test per 100 lines - isn't this awfully low for a highly complex piece of code, even discounting the fact that it's vibecoded? 100 LOC can carry a lot of logic for a single test, even for just happy paths.

    • kawogi 38 minutes ago

      IIUC only 50k LoC are non-test code, which improves the metric. Whether that's enough tests still depends on the code. If most are getters and setters, the coverage might be ok.

    • risyachka 39 minutes ago

      I may have missed it but are those tests written by person or generated? Otherwise how do you know they even test anything (like actually test, not appear to test)

  • staszewski an hour ago

    It's almost guaranteed with agents you could do the same job with less than half of 100k lines. I don't know whats impressive in lines of code generated by agent.

    • ndr an hour ago

      It just an anchor. If it were 50k would you say the same down to 25k? And if so how many more times would it apply?

      The interesting thing is that it was manageable solo (in many ways it's _more_ manageable solo+AIs than with coworkers+(their)AIs), and in such a short amount of time.

    • sreekanth850 10 minutes ago

      For a startup with limited funding, building a product is no more a bottleneck. every one doesn't have the same access to funding!

    • ashirviskas 21 minutes ago

      > It's almost guaranteed with agents you could do the same job with less than half of 100k lines.

      That's great, non-test code is only ~47k lines of code.

  • nilirl an hour ago

    Is the idea of the runtime contracts similar to the idea of runtime validation? Or are they different in some way?

    • pramodbiligiri 32 minutes ago

      It is described in the "Code Contracts" section of the article: "Code contracts specify preconditions, postconditions, and invariants for critical functions. These contracts are converted into runtime asserts during testing but can be disabled in production builds for performance". The .NET framework article that he links to: https://learn.microsoft.com/en-us/dotnet/framework/debug-tra...

      • nilirl 25 minutes ago

        Ah, I missed the reference. Thanks a lot!

  • faangguyindia 24 minutes ago

    Rust code generation consumes lot of token

    Go is much better target, i've observed rails/ruby code is also much easier for AI to spit out.

    And Haskell flies with AI

    • jgilias 12 minutes ago

      Yes, but it comes with much better “built-in” guardrails to rein in the autocomplete. Especially if compared to something runtime-surprise-prone-if-lovable like Ruby.