Suggest dereferncing when possible in E0277, fix #87437

This commit is contained in:
Esteban Kuber 2022-03-26 23:01:29 +00:00
parent ac8cbbd200
commit 883b93c7b7
7 changed files with 121 additions and 41 deletions

View file

@ -5,7 +5,7 @@ LL | let _errors = TcpListener::bind(&bad);
| ----------------- ^^^^
| | |
| | the trait `ToSocketAddrs` is not implemented for `NoToSocketAddrs`
| | help: consider adding dereference here: `&*bad`
| | help: consider dereferencing here: `&*bad`
| required by a bound introduced by this call
|
= note: required because of the requirements on the impl of `ToSocketAddrs` for `&NoToSocketAddrs`

View file

@ -5,7 +5,7 @@ LL | takes_type_parameter(&string); // Error
| -------------------- ^^^^^^^
| | |
| | the trait `SomeTrait` is not implemented for `&String`
| | help: consider adding dereference here: `&*string`
| | help: consider dereferencing here: `&*string`
| required by a bound introduced by this call
|
note: required by a bound in `takes_type_parameter`

View file

@ -5,7 +5,7 @@ LL | foo(&baz);
| --- ^^^^
| | |
| | the trait `Happy` is not implemented for `&Baz`
| | help: consider adding dereference here: `&***baz`
| | help: consider dereferencing here: `&***baz`
| required by a bound introduced by this call
|
note: required by a bound in `foo`

View file

@ -0,0 +1,14 @@
// run-rustfix
fn get_vowel_count(string: &str) -> usize {
string
.chars()
.filter(|c| "aeiou".contains(*c))
//~^ ERROR expected a `Fn<(char,)>` closure, found `char`
.count()
}
fn main() {
let _ = get_vowel_count("asdf");
}

View file

@ -0,0 +1,14 @@
// run-rustfix
fn get_vowel_count(string: &str) -> usize {
string
.chars()
.filter(|c| "aeiou".contains(c))
//~^ ERROR expected a `Fn<(char,)>` closure, found `char`
.count()
}
fn main() {
let _ = get_vowel_count("asdf");
}

View file

@ -0,0 +1,24 @@
error[E0277]: expected a `Fn<(char,)>` closure, found `char`
--> $DIR/root-obligation.rs:6:38
|
LL | .filter(|c| "aeiou".contains(c))
| -------- ^ expected an `Fn<(char,)>` closure, found `char`
| |
| required by a bound introduced by this call
|
= help: the trait `Fn<(char,)>` is not implemented for `char`
= note: required because of the requirements on the impl of `FnOnce<(char,)>` for `&char`
= note: required because of the requirements on the impl of `Pattern<'_>` for `&char`
note: required by a bound in `core::str::<impl str>::contains`
--> $SRC_DIR/core/src/str/mod.rs:LL:COL
|
LL | pub fn contains<'a, P: Pattern<'a>>(&'a self, pat: P) -> bool {
| ^^^^^^^^^^^ required by this bound in `core::str::<impl str>::contains`
help: consider dereferencing here
|
LL | .filter(|c| "aeiou".contains(*c))
| +
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.