mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-19 03:03:21 +00:00
Use the root trait predicate to determine whether to remove references
Fix #84837.
This commit is contained in:
parent
bb7211702e
commit
8b8cce16bf
@ -1359,6 +1359,14 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||
) -> bool {
|
||||
let mut span = obligation.cause.span;
|
||||
let mut trait_pred = trait_pred;
|
||||
let mut code = obligation.cause.code();
|
||||
while let Some((c, Some(parent_trait_pred))) = code.parent() {
|
||||
// We want the root obligation, in order to detect properly handle
|
||||
// `for _ in &mut &mut vec![] {}`.
|
||||
code = c;
|
||||
trait_pred = parent_trait_pred;
|
||||
}
|
||||
while span.desugaring_kind().is_some() {
|
||||
// Remove all the hir desugaring contexts while maintaining the macro contexts.
|
||||
span.remove_mark();
|
||||
|
@ -4,7 +4,6 @@ error[E0277]: the trait bound `u32: Signed` is not satisfied
|
||||
LL | is_defaulted::<&'static u32>();
|
||||
| ^^^^^^^^^^^^ the trait `Signed` is not implemented for `u32`
|
||||
|
|
||||
= help: the trait `Signed` is implemented for `i32`
|
||||
note: required for `&'static u32` to implement `Defaulted`
|
||||
--> $DIR/typeck-default-trait-impl-precedence.rs:10:19
|
||||
|
|
||||
@ -15,6 +14,11 @@ note: required by a bound in `is_defaulted`
|
||||
|
|
||||
LL | fn is_defaulted<T:Defaulted>() { }
|
||||
| ^^^^^^^^^ required by this bound in `is_defaulted`
|
||||
help: consider removing the leading `&`-reference
|
||||
|
|
||||
LL - is_defaulted::<&'static u32>();
|
||||
LL + is_defaulted::<u32>();
|
||||
|
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -12,6 +12,11 @@ note: required by a bound in `assert`
|
||||
|
|
||||
LL | fn assert<T: UnwindSafe + ?Sized>() {}
|
||||
| ^^^^^^^^^^ required by this bound in `assert`
|
||||
help: consider removing the leading `&`-reference
|
||||
|
|
||||
LL - assert::<&RefCell<i32>>();
|
||||
LL + assert::<RefCell<i32>>();
|
||||
|
|
||||
|
||||
error[E0277]: the type `UnsafeCell<isize>` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary
|
||||
--> $DIR/not-panic-safe-4.rs:9:14
|
||||
@ -28,6 +33,11 @@ note: required by a bound in `assert`
|
||||
|
|
||||
LL | fn assert<T: UnwindSafe + ?Sized>() {}
|
||||
| ^^^^^^^^^^ required by this bound in `assert`
|
||||
help: consider removing the leading `&`-reference
|
||||
|
|
||||
LL - assert::<&RefCell<i32>>();
|
||||
LL + assert::<RefCell<i32>>();
|
||||
|
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
8
tests/ui/suggestions/suggest-remove-refs-5.fixed
Normal file
8
tests/ui/suggestions/suggest-remove-refs-5.fixed
Normal file
@ -0,0 +1,8 @@
|
||||
// run-rustfix
|
||||
fn main() {
|
||||
let v = &mut Vec::<i32>::new();
|
||||
for _ in v {} //~ ERROR E0277
|
||||
|
||||
let v = &mut [1u8];
|
||||
for _ in v {} //~ ERROR E0277
|
||||
}
|
8
tests/ui/suggestions/suggest-remove-refs-5.rs
Normal file
8
tests/ui/suggestions/suggest-remove-refs-5.rs
Normal file
@ -0,0 +1,8 @@
|
||||
// run-rustfix
|
||||
fn main() {
|
||||
let v = &mut &mut Vec::<i32>::new();
|
||||
for _ in &mut &mut v {} //~ ERROR E0277
|
||||
|
||||
let v = &mut &mut [1u8];
|
||||
for _ in &mut v {} //~ ERROR E0277
|
||||
}
|
37
tests/ui/suggestions/suggest-remove-refs-5.stderr
Normal file
37
tests/ui/suggestions/suggest-remove-refs-5.stderr
Normal file
@ -0,0 +1,37 @@
|
||||
error[E0277]: `Vec<i32>` is not an iterator
|
||||
--> $DIR/suggest-remove-refs-5.rs:4:14
|
||||
|
|
||||
LL | for _ in &mut &mut v {}
|
||||
| ^^^^^^^^^^^ `Vec<i32>` is not an iterator; try calling `.into_iter()` or `.iter()`
|
||||
|
|
||||
= help: the trait `Iterator` is not implemented for `Vec<i32>`
|
||||
= note: required for `&mut Vec<i32>` to implement `Iterator`
|
||||
= note: 3 redundant requirements hidden
|
||||
= note: required for `&mut &mut &mut &mut Vec<i32>` to implement `Iterator`
|
||||
= note: required for `&mut &mut &mut &mut Vec<i32>` to implement `IntoIterator`
|
||||
help: consider removing 3 leading `&`-references
|
||||
|
|
||||
LL ~ let v = &mut Vec::<i32>::new();
|
||||
LL ~ for _ in v {}
|
||||
|
|
||||
|
||||
error[E0277]: `[u8; 1]` is not an iterator
|
||||
--> $DIR/suggest-remove-refs-5.rs:7:14
|
||||
|
|
||||
LL | for _ in &mut v {}
|
||||
| ^^^^^^ `[u8; 1]` is not an iterator; try calling `.into_iter()` or `.iter()`
|
||||
|
|
||||
= help: the trait `Iterator` is not implemented for `[u8; 1]`
|
||||
= note: required for `&mut [u8; 1]` to implement `Iterator`
|
||||
= note: 2 redundant requirements hidden
|
||||
= note: required for `&mut &mut &mut [u8; 1]` to implement `Iterator`
|
||||
= note: required for `&mut &mut &mut [u8; 1]` to implement `IntoIterator`
|
||||
help: consider removing 2 leading `&`-references
|
||||
|
|
||||
LL ~ let v = &mut [1u8];
|
||||
LL ~ for _ in v {}
|
||||
|
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
Loading…
Reference in New Issue
Block a user