When suggesting to borrow, remove useless clones
This commit is contained in:
parent
0e4a56b4b0
commit
bdb05a84f3
3 changed files with 24 additions and 0 deletions
|
@ -425,6 +425,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// If this expression had a clone call, when suggesting borrowing, we
|
||||||
|
// want to suggest removing it
|
||||||
|
let sugg_expr = sugg_expr.trim_end_matches(".clone()");
|
||||||
return Some(match mutability {
|
return Some(match mutability {
|
||||||
hir::Mutability::MutMutable => (
|
hir::Mutability::MutMutable => (
|
||||||
sp,
|
sp,
|
||||||
|
|
6
src/test/ui/issues/issue-61106.rs
Normal file
6
src/test/ui/issues/issue-61106.rs
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
fn main() {
|
||||||
|
let x = String::new();
|
||||||
|
foo(x.clone()); //~ ERROR mismatched types
|
||||||
|
}
|
||||||
|
|
||||||
|
fn foo(_: &str) {}
|
15
src/test/ui/issues/issue-61106.stderr
Normal file
15
src/test/ui/issues/issue-61106.stderr
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
error[E0308]: mismatched types
|
||||||
|
--> $DIR/issue-61106.rs:3:9
|
||||||
|
|
|
||||||
|
LL | foo(x.clone());
|
||||||
|
| ^^^^^^^^^
|
||||||
|
| |
|
||||||
|
| expected &str, found struct `std::string::String`
|
||||||
|
| help: consider borrowing here: `&x`
|
||||||
|
|
|
||||||
|
= note: expected type `&str`
|
||||||
|
found type `std::string::String`
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0308`.
|
Loading…
Reference in a new issue