You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Borrow checker determines borrows by examining lifetime parameters on unexpanded associated types instead of inspecting their lifetime bounds #50029
traitFoo<'a>{typeOut:'a;}fnfoo<'a,T>(_:&'amutT) -> <TasFoo<'a>>::OutwhereT:Foo<'a>{unimplemented!()}fnbaz<T>(mutx:T)wherefor<'a>T:Foo<'a>,for<'a> <TasFoo<'a>>::Out:'static{let y = foo(&mut x);let z = foo(&mut x);}fnmain(){structBar;impl<'a>Foo<'a>forBar{typeOut = i32;}letmut b = Bar;let y = foo(&mut b);let z = foo(&mut b);}
main compiles fine, as expected, since the associated type expands to i32, which does not use the lifetime 'a that the mutable reference input argument is bound by.
baz however fails to compile (error message below), despite the additional constraint on Out to be 'static, implying that the return value of foo does not borrow the argument.
error[E0499]: cannot borrow `x` as mutable more than once at a time
--> src/main.rs:11:22
|
10 | let y = foo(&mut x);
| - first mutable borrow occurs here
11 | let z = foo(&mut x);
| ^ second mutable borrow occurs here
12 | }
| - first borrow ends here
This problem appears to be unique to unexpanded associated types, as they are the only case where the lifetime parameters do not directly determine the lifetime bounds on the type.
Activity
oskgo commentedon Jan 25, 2024
No longer reproduces. Fixed by #116733.
searched nightlies: from nightly-2023-05-23 to nightly-2024-01-23
regressed nightly: nightly-2023-10-30
searched commit range: e5cfc55...608e968
regressed commit: ec2b311
bisected with cargo-bisect-rustc v0.6.7
Host triple: x86_64-pc-windows-msvc
Reproduce with: