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
use std::io::prelude::*;traitFoo:Write{fnfoo(&mutself){}}impl<W:Write>FooforW{}fnfoo<W:Write+?Sized>(w:&mutW){
w.foo();}fnmain(){foo(&mut std::io::sink());}
test.rs:10:5: 10:6 error: cannot borrow immutable local variable `w` as mutable
test.rs:10 w.foo();
^
error: aborting due to previous error
Dropping the ?Sized bound or calling flush instead of foo makes it compile just fine.
The text was updated successfully, but these errors were encountered:
Also, changing the function signature to 'mut w: &mut W' fixes this.
use std::io::prelude::*;traitFoo:Write{fnfoo(&mutself){}}impl<W:Write>FooforW{}fnfoo<W:Write+?Sized>(/* HERE */mutw:&mutW){
w.foo();}fnmain(){foo(&mut std::io::sink());}
I think this is technically correct, though an oddity. &mut W as Foo means that self in Foo will be &mut W, which will then mean that in order to call foo, you need to pass &mut &mut W, and in order to make that work, you'd need to have w be mutable. I think this is because W is ?Sized, which means that it technically doesn't implement Foo itself, i.e., impl<W: Write> Foo for W {} isn't matching on it. That matches for &mut w, though, since Write is implemented for &mut T where T: Write.
I'm going to close per the above, but please reopen if I'm wrong.
Dropping the
?Sized
bound or callingflush
instead offoo
makes it compile just fine.The text was updated successfully, but these errors were encountered: