Illegal sized bounds: only suggest mutability change if needed
In a scenario like
```
struct Type;
pub trait Trait {
fn function(&mut self)
where
Self: Sized;
}
impl Trait for Type {
fn function(&mut self) {}
}
fn main() {
(&mut Type as &mut dyn Trait).function();
}
```
the problem is Sized, not the mutability of self. Thus don't emit the
"you need &T instead of &mut T" note, or the other way around, as all
it does is just invert the mutability of whatever was supplied.
Fixes #103622.
This commit is contained in:
parent
7632db0e87
commit
40ba1c902f
5 changed files with 111 additions and 1 deletions
|
|
@ -210,7 +210,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
ProbeScope::TraitsInScope,
|
||||
) {
|
||||
Ok(ref new_pick) if pick.differs_from(new_pick) => {
|
||||
needs_mut = true;
|
||||
needs_mut = new_pick.self_ty.ref_mutability() != self_ty.ref_mutability();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue