When suggesting to borrow, remove useless clones

This commit is contained in:
Esteban Küber 2019-05-24 18:24:20 -07:00
parent 0e4a56b4b0
commit bdb05a84f3
3 changed files with 24 additions and 0 deletions

View File

@ -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 {
hir::Mutability::MutMutable => (
sp,

View File

@ -0,0 +1,6 @@
fn main() {
let x = String::new();
foo(x.clone()); //~ ERROR mismatched types
}
fn foo(_: &str) {}

View 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`.