From af09bf9293ed89b93662bad02006bcabde587a16 Mon Sep 17 00:00:00 2001 From: Pramod Bisht Date: Sun, 9 Sep 2018 13:43:41 +0000 Subject: [PATCH] 53692: Addressed Estebank's Nits --- src/librustc_typeck/check/mod.rs | 12 +++++++----- src/test/ui/issue-53692.rs | 7 +++++++ src/test/ui/issue-53692.stderr | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 8f3300fac18..997fdb0df61 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -4726,13 +4726,15 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { if receiver.ends_with(&method_call) { None // do not suggest code that is already there (#53348) } else { - // methods defined will be overwrite `.clone()` - // if suggesion is present in `method_call_list` (#53692) + /* + methods defined in `method_call_list` will overwrite + `.clone()` in copy of `receiver` + */ let method_call_list = [".to_vec()", ".to_string()"]; - if receiver.ends_with("clone()") + if receiver.ends_with(".clone()") && method_call_list.contains(&method_call.as_str()){ - // needed to clone receiver, because we don't want other - // suggestion to get affect because of that + // created copy of `receiver` because we don't want other + // suggestion to get affected let mut new_receiver = receiver.clone(); let max_len = new_receiver.rfind(".").unwrap(); new_receiver.truncate(max_len); diff --git a/src/test/ui/issue-53692.rs b/src/test/ui/issue-53692.rs index 314362cf112..0b6cc36fa52 100644 --- a/src/test/ui/issue-53692.rs +++ b/src/test/ui/issue-53692.rs @@ -12,6 +12,13 @@ fn main() { let ref_items: &[i32] = &items; let items_clone: Vec = ref_items.clone(); + // in that case no suggestion will be triggered + let items_clone_2:Vec = items.clone(); + let s = "hi"; let string: String = s.clone(); + + // in that case no suggestion will be triggered + let s2 = "hi"; + let string_2: String = s2.to_string(); } diff --git a/src/test/ui/issue-53692.stderr b/src/test/ui/issue-53692.stderr index 1dc7621f1e4..9cd8a536155 100644 --- a/src/test/ui/issue-53692.stderr +++ b/src/test/ui/issue-53692.stderr @@ -11,7 +11,7 @@ LL | let items_clone: Vec = ref_items.clone(); found type `&[i32]` error[E0308]: mismatched types - --> $DIR/issue-53692.rs:16:30 + --> $DIR/issue-53692.rs:19:30 | LL | let string: String = s.clone(); | ^^^^^^^^^