53692: Addressed Estebank's Nits

This commit is contained in:
Pramod Bisht 2018-09-09 13:43:41 +00:00
parent a673203ec8
commit af09bf9293
3 changed files with 15 additions and 6 deletions

View File

@ -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);

View File

@ -12,6 +12,13 @@ fn main() {
let ref_items: &[i32] = &items;
let items_clone: Vec<i32> = ref_items.clone();
// in that case no suggestion will be triggered
let items_clone_2:Vec<i32> = 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();
}

View File

@ -11,7 +11,7 @@ LL | let items_clone: Vec<i32> = 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();
| ^^^^^^^^^