-
Notifications
You must be signed in to change notification settings - Fork 13.3k
&mut self to &mut Trait moves self #8813
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
Yes this is a bug. I've noticed it too. The compiler should reborrow automatically as we do almost everywhere else; you can workaround it temporarily by making the reborrow explicit ( |
I noticed that this is also an issue with references to generics. The following example should compile and run just fine: trait TraitA {}
struct A;
impl TraitA for A {}
fn foo1<T: TraitA>(something: &T) {
object_bar(something);
object_bar(something);
}
fn foo2<T: TraitA>(something: &mut T) {
generic_bar(something);
generic_bar(something);
}
fn foo3<T: TraitA>(something: &mut T) {
mut_object_bar(something);
mut_object_bar(something);
}
fn foo4<T: TraitA>(something: &mut T) {
object_bar(something);
object_bar(something);
}
fn object_bar(_something: &TraitA) {}
fn mut_object_bar(_something: &mut TraitA) {}
fn generic_bar<T: TraitA>(_something: &mut T) {}
fn main() {
let mut a = A;
foo1(&a);
foo2(&mut a);
foo3(&mut a);
foo4(&mut a);
} but
|
We no longer auto-borrow in this situation, so I think that this is invalid. @nikomatsakis @alexcrichton ? |
I think this is still as true as it ever was. In general, we aggressively "reborrow" all |
I'm pulling a massive triage effort to get us ready for 1.0. As part of this, I'm moving stuff that's wishlist-like to the RFCs repo, as that's where major new things should get discussed/prioritized. This issue has been moved to the RFCs repo: rust-lang/rfcs#800 |
…r=Alexendoo Fix redundant_allocation warning for Rc<Box<str>> changelog: [`redundant_allocation`] Fixes rust-lang#8604 Fixes false positives where a fat pointer with `str` type was made thin by another allocation, but that thinning allocation was marked as redundant
This code shows some odd behavior:
Because
good
works, I would expectbad
to work as well.cc @nikomatsakis
The text was updated successfully, but these errors were encountered: