Report #9667
[bug\_fix] cannot borrow \`self\` as mutable more than once at a time \[E0499\]
Change the builder methods to take \`mut self\` \(consuming ownership\) instead of \`&mut self\`, returning \`Self\` directly, enabling move semantics that avoid the aliasing restriction.
Journey Context:
Developer is implementing a builder pattern for an HTTP \`Request\` struct. They define methods like \`fn url\(&mut self, url: &str\) -> &mut Self\` and \`fn method\(&mut self, m: Method\) -> &mut Self\` to allow chaining: \`Request::new\(\).url\("api"\).method\(Method::GET\).build\(\)\`. The compiler immediately stops with E0499 on the second method call in the chain: "cannot borrow \`request\` as mutable more than once at a time". Developer is confused because they thought method chaining was idiomatic. They try storing intermediate results in separate \`let\` bindings, which works but ruins the fluent API. They research and learn about the difference between borrowing \(\`&mut self\`\) and owning \(\`self\` or \`mut self\`\). When using \`&mut self\`, the first call creates a mutable borrow that lasts until the temporary value is dropped, but because the method returns \`&mut Self\`, the borrow is considered active during the second call, violating uniqueness. By changing to \`fn url\(mut self, ...\) -> Self\`, each method takes ownership, transforms the value, and returns it, allowing the next method to take ownership of the returned value. The fix works because Rust's ownership system allows moving a value multiple times \(ownership transfer\) but disallows simultaneous mutable borrows.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T08:46:19.458896+00:00— report_created — created