-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix #104961, Add parentheses properly for borrowing suggestion
- Loading branch information
1 parent
a00e24d
commit 8f736a4
Showing
4 changed files
with
104 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// run-rustfix | ||
|
||
fn foo(x: &str) -> bool { | ||
x.starts_with(&("hi".to_string() + " you")) | ||
//~^ ERROR expected a `FnMut<(char,)>` closure, found `String` | ||
} | ||
|
||
fn foo2(x: &str) -> bool { | ||
x.starts_with(&"hi".to_string()) | ||
//~^ ERROR expected a `FnMut<(char,)>` closure, found `String` | ||
} | ||
|
||
fn main() { | ||
foo("hi you"); | ||
foo2("hi"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// run-rustfix | ||
|
||
fn foo(x: &str) -> bool { | ||
x.starts_with("hi".to_string() + " you") | ||
//~^ ERROR expected a `FnMut<(char,)>` closure, found `String` | ||
} | ||
|
||
fn foo2(x: &str) -> bool { | ||
x.starts_with("hi".to_string()) | ||
//~^ ERROR expected a `FnMut<(char,)>` closure, found `String` | ||
} | ||
|
||
fn main() { | ||
foo("hi you"); | ||
foo2("hi"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
error[E0277]: expected a `FnMut<(char,)>` closure, found `String` | ||
--> $DIR/issue-104961.rs:4:19 | ||
| | ||
LL | x.starts_with("hi".to_string() + " you") | ||
| ----------- ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Pattern<'_>` is not implemented for `String` | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
= note: the trait bound `String: Pattern<'_>` is not satisfied | ||
= note: required for `String` to implement `Pattern<'_>` | ||
note: required by a bound in `core::str::<impl str>::starts_with` | ||
--> $SRC_DIR/core/src/str/mod.rs:LL:COL | ||
help: consider borrowing here | ||
| | ||
LL | x.starts_with(&("hi".to_string() + " you")) | ||
| ++ + | ||
|
||
error[E0277]: expected a `FnMut<(char,)>` closure, found `String` | ||
--> $DIR/issue-104961.rs:9:19 | ||
| | ||
LL | x.starts_with("hi".to_string()) | ||
| ----------- ^^^^^^^^^^^^^^^^ the trait `Pattern<'_>` is not implemented for `String` | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
= note: the trait bound `String: Pattern<'_>` is not satisfied | ||
= note: required for `String` to implement `Pattern<'_>` | ||
note: required by a bound in `core::str::<impl str>::starts_with` | ||
--> $SRC_DIR/core/src/str/mod.rs:LL:COL | ||
help: consider borrowing here | ||
| | ||
LL | x.starts_with(&"hi".to_string()) | ||
| + | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0277`. |