Auto merge of #81149 - Aaron1011:feature/better-no-method-found-err, r=estebank
Avoid describing a method as 'not found' when bounds are unsatisfied Fixes #76267 When there is a single applicable method candidate, but its trait bounds are not satisfied, we avoid saying that the method is "not found". Insted, we update the error message to directly mention which bounds are not satisfied, rather than mentioning them in a note.
This commit is contained in:
commit
643a79af3d
47 changed files with 144 additions and 128 deletions
|
|
@ -1,12 +1,12 @@
|
|||
error[E0599]: no method named `to_string` found for raw pointer `*const u8` in the current scope
|
||||
error[E0599]: the method `to_string` exists for raw pointer `*const u8`, but its trait bounds were not satisfied
|
||||
--> $DIR/issue-21596.rs:4:22
|
||||
|
|
||||
LL | println!("{}", z.to_string());
|
||||
| ^^^^^^^^^ method not found in `*const u8`
|
||||
| ^^^^^^^^^ method cannot be called on `*const u8` due to unsatisfied trait bounds
|
||||
|
|
||||
= note: try using `<*const T>::as_ref()` to get a reference to the type behind the pointer: https://doc.rust-lang.org/std/primitive.pointer.html#method.as_ref
|
||||
= note: using `<*const T>::as_ref()` on a pointer which is unaligned or points to invalid or uninitialized memory is undefined behavior
|
||||
= note: the method `to_string` exists but the following trait bounds were not satisfied:
|
||||
= note: the following trait bounds were not satisfied:
|
||||
`*const u8: std::fmt::Display`
|
||||
which is required by `*const u8: ToString`
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ pub fn get_tok(it: &mut IntoIter<u8>) {
|
|||
//~^ ERROR type mismatch resolving
|
||||
//~| expected type `u8`
|
||||
//~| found reference `&_`
|
||||
.collect(); //~ ERROR no method named `collect`
|
||||
.collect(); //~ ERROR the method
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -7,11 +7,11 @@ LL | .cloned()
|
|||
= note: expected type `u8`
|
||||
found reference `&_`
|
||||
|
||||
error[E0599]: no method named `collect` found for struct `Cloned<TakeWhile<&mut std::vec::IntoIter<u8>, [closure@$DIR/issue-31173.rs:6:39: 9:6]>>` in the current scope
|
||||
error[E0599]: the method `collect` exists for struct `Cloned<TakeWhile<&mut std::vec::IntoIter<u8>, [closure@$DIR/issue-31173.rs:6:39: 9:6]>>`, but its trait bounds were not satisfied
|
||||
--> $DIR/issue-31173.rs:14:10
|
||||
|
|
||||
LL | .collect();
|
||||
| ^^^^^^^ method not found in `Cloned<TakeWhile<&mut std::vec::IntoIter<u8>, [closure@$DIR/issue-31173.rs:6:39: 9:6]>>`
|
||||
| ^^^^^^^ method cannot be called on `Cloned<TakeWhile<&mut std::vec::IntoIter<u8>, [closure@$DIR/issue-31173.rs:6:39: 9:6]>>` due to unsatisfied trait bounds
|
||||
|
|
||||
::: $SRC_DIR/core/src/iter/adapters/cloned.rs:LL:COL
|
||||
|
|
||||
|
|
@ -23,7 +23,7 @@ LL | pub struct Cloned<I> {
|
|||
LL | pub struct TakeWhile<I, P> {
|
||||
| -------------------------- doesn't satisfy `<_ as Iterator>::Item = &_`
|
||||
|
|
||||
= note: the method `collect` exists but the following trait bounds were not satisfied:
|
||||
= note: the following trait bounds were not satisfied:
|
||||
`<TakeWhile<&mut std::vec::IntoIter<u8>, [closure@$DIR/issue-31173.rs:6:39: 9:6]> as Iterator>::Item = &_`
|
||||
which is required by `Cloned<TakeWhile<&mut std::vec::IntoIter<u8>, [closure@$DIR/issue-31173.rs:6:39: 9:6]>>: Iterator`
|
||||
`Cloned<TakeWhile<&mut std::vec::IntoIter<u8>, [closure@$DIR/issue-31173.rs:6:39: 9:6]>>: Iterator`
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use std::collections::HashSet;
|
|||
|
||||
fn is_subset<T>(this: &HashSet<T>, other: &HashSet<T>) -> bool {
|
||||
this.is_subset(other)
|
||||
//~^ ERROR no method named
|
||||
//~^ ERROR the method
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
error[E0599]: no method named `is_subset` found for reference `&HashSet<T>` in the current scope
|
||||
error[E0599]: the method `is_subset` exists for reference `&HashSet<T>`, but its trait bounds were not satisfied
|
||||
--> $DIR/issue-35677.rs:4:10
|
||||
|
|
||||
LL | this.is_subset(other)
|
||||
| ^^^^^^^^^ method not found in `&HashSet<T>`
|
||||
| ^^^^^^^^^ method cannot be called on `&HashSet<T>` due to unsatisfied trait bounds
|
||||
|
|
||||
= note: the method `is_subset` exists but the following trait bounds were not satisfied:
|
||||
= note: the following trait bounds were not satisfied:
|
||||
`T: Eq`
|
||||
`T: Hash`
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
fn main() {
|
||||
let _result = &Some(42).as_deref();
|
||||
//~^ ERROR no method named `as_deref` found for enum `Option<{integer}>`
|
||||
//~^ ERROR the method
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
error[E0599]: no method named `as_deref` found for enum `Option<{integer}>` in the current scope
|
||||
error[E0599]: the method `as_deref` exists for enum `Option<{integer}>`, but its trait bounds were not satisfied
|
||||
--> $DIR/option-as_deref.rs:2:29
|
||||
|
|
||||
LL | let _result = &Some(42).as_deref();
|
||||
| ^^^^^^^^ help: there is an associated function with a similar name: `as_ref`
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= note: the method `as_deref` exists but the following trait bounds were not satisfied:
|
||||
= note: the following trait bounds were not satisfied:
|
||||
`{integer}: Deref`
|
||||
`<{integer} as Deref>::Target = _`
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
fn main() {
|
||||
let _result = &mut Some(42).as_deref_mut();
|
||||
//~^ ERROR no method named `as_deref_mut` found for enum `Option<{integer}>`
|
||||
//~^ ERROR the method
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
error[E0599]: no method named `as_deref_mut` found for enum `Option<{integer}>` in the current scope
|
||||
error[E0599]: the method `as_deref_mut` exists for enum `Option<{integer}>`, but its trait bounds were not satisfied
|
||||
--> $DIR/option-as_deref_mut.rs:2:33
|
||||
|
|
||||
LL | let _result = &mut Some(42).as_deref_mut();
|
||||
| ^^^^^^^^^^^^ method not found in `Option<{integer}>`
|
||||
| ^^^^^^^^^^^^ method cannot be called on `Option<{integer}>` due to unsatisfied trait bounds
|
||||
|
|
||||
= note: the method `as_deref_mut` exists but the following trait bounds were not satisfied:
|
||||
= note: the following trait bounds were not satisfied:
|
||||
`{integer}: DerefMut`
|
||||
`<{integer} as Deref>::Target = _`
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
fn main() {
|
||||
let _result = &Ok(42).as_deref();
|
||||
//~^ ERROR no method named `as_deref` found
|
||||
//~^ ERROR the method
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
error[E0599]: no method named `as_deref` found for enum `std::result::Result<{integer}, _>` in the current scope
|
||||
error[E0599]: the method `as_deref` exists for enum `std::result::Result<{integer}, _>`, but its trait bounds were not satisfied
|
||||
--> $DIR/result-as_deref.rs:2:27
|
||||
|
|
||||
LL | let _result = &Ok(42).as_deref();
|
||||
| ^^^^^^^^ help: there is an associated function with a similar name: `as_ref`
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= note: the method `as_deref` exists but the following trait bounds were not satisfied:
|
||||
= note: the following trait bounds were not satisfied:
|
||||
`{integer}: Deref`
|
||||
`<{integer} as Deref>::Target = _`
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
fn main() {
|
||||
let _result = &mut Ok(42).as_deref_mut();
|
||||
//~^ ERROR no method named `as_deref_mut` found
|
||||
//~^ ERROR the method
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
error[E0599]: no method named `as_deref_mut` found for enum `std::result::Result<{integer}, _>` in the current scope
|
||||
error[E0599]: the method `as_deref_mut` exists for enum `std::result::Result<{integer}, _>`, but its trait bounds were not satisfied
|
||||
--> $DIR/result-as_deref_mut.rs:2:31
|
||||
|
|
||||
LL | let _result = &mut Ok(42).as_deref_mut();
|
||||
| ^^^^^^^^^^^^ method not found in `std::result::Result<{integer}, _>`
|
||||
| ^^^^^^^^^^^^ method cannot be called on `std::result::Result<{integer}, _>` due to unsatisfied trait bounds
|
||||
|
|
||||
= note: the method `as_deref_mut` exists but the following trait bounds were not satisfied:
|
||||
= note: the following trait bounds were not satisfied:
|
||||
`{integer}: DerefMut`
|
||||
`<{integer} as Deref>::Target = _`
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ impl<'a> X for fn(&'a ()) {
|
|||
}
|
||||
|
||||
fn g() {
|
||||
let x = <fn (&())>::make_g(); //~ ERROR no function or associated item
|
||||
let x = <fn (&())>::make_g(); //~ ERROR the function
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
error[E0599]: no function or associated item named `make_g` found for fn pointer `for<'r> fn(&'r ())` in the current scope
|
||||
error[E0599]: the function or associated item `make_g` exists for fn pointer `for<'r> fn(&'r ())`, but its trait bounds were not satisfied
|
||||
--> $DIR/issue-57362-2.rs:22:25
|
||||
|
|
||||
LL | let x = <fn (&())>::make_g();
|
||||
| ^^^^^^ function or associated item not found in `for<'r> fn(&'r ())`
|
||||
| ^^^^^^ function or associated item cannot be called on `for<'r> fn(&'r ())` due to unsatisfied trait bounds
|
||||
|
|
||||
= note: the method `make_g` exists but the following trait bounds were not satisfied:
|
||||
= note: the following trait bounds were not satisfied:
|
||||
`for<'r> fn(&'r ()): X`
|
||||
= help: items from traits can only be used if the trait is implemented and in scope
|
||||
note: `X` defines an item `make_g`, perhaps you need to implement it
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use issue_69725::Struct;
|
|||
|
||||
fn crash<A>() {
|
||||
let _ = Struct::<A>::new().clone();
|
||||
//~^ ERROR: no method named `clone` found
|
||||
//~^ ERROR: the method
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
error[E0599]: no method named `clone` found for struct `Struct<A>` in the current scope
|
||||
error[E0599]: the method `clone` exists for struct `Struct<A>`, but its trait bounds were not satisfied
|
||||
--> $DIR/issue-69725.rs:7:32
|
||||
|
|
||||
LL | let _ = Struct::<A>::new().clone();
|
||||
| ^^^^^ method not found in `Struct<A>`
|
||||
| ^^^^^ method cannot be called on `Struct<A>` due to unsatisfied trait bounds
|
||||
|
|
||||
::: $DIR/auxiliary/issue-69725.rs:2:1
|
||||
|
|
||||
|
|
@ -17,7 +17,7 @@ LL | fn clone(&self) -> Self;
|
|||
| the method is available for `Arc<Struct<A>>` here
|
||||
| the method is available for `Rc<Struct<A>>` here
|
||||
|
|
||||
= note: the method `clone` exists but the following trait bounds were not satisfied:
|
||||
= note: the following trait bounds were not satisfied:
|
||||
`A: Clone`
|
||||
which is required by `Struct<A>: Clone`
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue