-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Using &mut Trait
requires mut
local variable for some cases
#10088
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Issue still present in master. Updating code to compile. trait Foo {
fn foo(&mut self);
}
impl<'a> Foo for &'a mut Foo {
fn foo(&mut self) { self.foo(); }
}
struct S {
i :int
}
impl Foo for S {
fn foo(&mut self) {
self.i = self.i + 1;
}
}
trait Bar {
fn bar(&mut self);
}
impl<T: Foo> Bar for T {
fn bar(&mut self) {
self.foo();
}
}
fn main() {
let s = &mut S{i:0} as &mut Foo;
s.foo(); // works fine
s.bar(); // error: cannot borrow immutable local variable as mutable
let mut s = &mut S{i:0} as &mut Foo;
s.bar(); // works fine
} |
reading the updated example, I do wonder if this is "working as designed" ... I'm not 100% sure yet (I haven't tried playing around with it locally). (I'm also not sure if that |
@pnkfelix : You are right. It does "work as designed". Here's my explanation as to why. Please correct me if I'm wrong. When For the original code I submitted in the issue (the one with the &mut Reader), I was told in IRC that it was probably a bug and was asked to raise an issue. But even that was working per design, if the the above explanation is valid and correct. Shall I close this issue? |
Looks like this should be closed. |
fix manual_filter false positive fixes rust-lang#10088 fixes rust-lang#9766 changelog: FP: [`manual_filter`]: Now ignores if expressions where the else branch has side effects or doesn't return `None` [rust-lang#10091](rust-lang/rust-clippy#10091) <!-- changelog_checked -->
Looks like some cases were not tested in #8398
The following code:
still yields a compilation error:
The text was updated successfully, but these errors were encountered: