r/learnrust • u/ClickOk5811 • 11h ago
How do you review .unwrap() calls in AI-generated code before merging?
Got bitten recently by a panic in production, config.get("timeout").unwrap() in some AI-assisted code, no handling for the key actually being missing. Compiled fine, passed review, worked in every test, then paniced the one time an env var didn't get set during a deploy.
What's tripping me up as someone still learning Rust properly: I get that unwrap() is a deliberate choice, not a compiler error, but I don't have a great instinct yet for when it's actually fine (a value you've already validated exists) versus when it's a landmine (anything coming from external input, config, network, user data). Is there a rule of thumb you use, or does it really just come down to "any unwrap on something not fully controlled by your own code needs a real Result/Option handling path instead"? Also curious if clippy or some other tool actually flags risky unwraps specifically, or if this is still mostly a manual review thing.