Skip to content
Permalink
Browse files

When suggesting to borrow, remove useless clones

  • Loading branch information...
estebank committed May 25, 2019
1 parent 0e4a56b commit bdb05a84f3b9d0c7d39d2bbbe92d2695d33d79fc
Showing with 24 additions and 0 deletions.
  1. +3 −0 src/librustc_typeck/check/demand.rs
  2. +6 −0 src/test/ui/issues/issue-61106.rs
  3. +15 −0 src/test/ui/issues/issue-61106.stderr
@@ -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,
@@ -0,0 +1,6 @@
fn main() {
let x = String::new();
foo(x.clone()); //~ ERROR mismatched types
}

fn foo(_: &str) {}
@@ -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`.

0 comments on commit bdb05a8

Please sign in to comment.
You can’t perform that action at this time.