Skip to content

Commit 1a775b3

Browse files
authored
Rollup merge of rust-lang#62981 - estebank:issue-62843, r=Centril
Add note suggesting to borrow a String argument to find Fix rust-lang#62843.
2 parents f87f3db + 3ab6026 commit 1a775b3

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

src/libcore/ops/function.rs

+4
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ pub trait Fn<Args> : FnMut<Args> {
137137
#[rustc_paren_sugar]
138138
#[rustc_on_unimplemented(
139139
on(Args="()", note="wrap the `{Self}` in a closure with no arguments: `|| {{ /* code */ }}"),
140+
on(
141+
all(Args="(char,)", _Self="std::string::String"),
142+
note="borrowing the `{Self}` might fix the problem"
143+
),
140144
message="expected a `{FnMut}<{Args}>` closure, found `{Self}`",
141145
label="expected an `FnMut<{Args}>` closure, found `{Self}`",
142146
)]
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn main() {
2+
let line = String::from("abc");
3+
let pattern = String::from("bc");
4+
println!("{:?}", line.find(pattern)); //~ ERROR E0277
5+
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0277]: expected a `std::ops::FnMut<(char,)>` closure, found `std::string::String`
2+
--> $DIR/issue-62843.rs:4:27
3+
|
4+
LL | println!("{:?}", line.find(pattern));
5+
| ^^^^ expected an `FnMut<(char,)>` closure, found `std::string::String`
6+
|
7+
= help: the trait `std::ops::FnMut<(char,)>` is not implemented for `std::string::String`
8+
= note: borrowing the `std::string::String` might fix the problem
9+
= note: required because of the requirements on the impl of `std::str::pattern::Pattern<'_>` for `std::string::String`
10+
11+
error: aborting due to previous error
12+
13+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)