Correct suggestion when dereferencing enough, calling a function
This commit is contained in:
parent
ac45a83ad5
commit
6d1ccbf466
@ -248,7 +248,6 @@ fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind) {
|
||||
let expr = self.cx.tcx.hir().expect_expr(cmt.hir_id);
|
||||
let arg_ty_kind = self.cx.typeck_results().expr_ty(expr).kind();
|
||||
|
||||
// Note: this should always be true, as `find` only gives us a reference which are not mutable
|
||||
if matches!(arg_ty_kind, ty::Ref(_, _, Mutability::Not)) {
|
||||
let start_span = Span::new(self.next_pos, span.lo(), span.ctxt());
|
||||
let start_snip =
|
||||
@ -261,10 +260,10 @@ fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind) {
|
||||
};
|
||||
self.suggestion_start.push_str(&ident_sugg);
|
||||
self.next_pos = span.hi();
|
||||
return;
|
||||
} else {
|
||||
self.applicability = Applicability::Unspecified;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,10 +102,17 @@ mod issue7392 {
|
||||
*x == 9
|
||||
}
|
||||
|
||||
fn simple_fn(x: u32) -> bool {
|
||||
x == 78
|
||||
}
|
||||
|
||||
fn more_projections() {
|
||||
let x = 19;
|
||||
let ppx: &u32 = &x;
|
||||
let _ = ![ppx].iter().any(|ppp_x: &&u32| please(ppp_x));
|
||||
let _ = ![String::from("Hey hey")].iter().any(|s| s.len() == 2);
|
||||
|
||||
let v = vec![3, 2, 1, 0];
|
||||
let _ = !v.iter().any(|x| simple_fn(*x));
|
||||
}
|
||||
}
|
||||
|
@ -106,10 +106,17 @@ fn please(x: &u32) -> bool {
|
||||
*x == 9
|
||||
}
|
||||
|
||||
fn simple_fn(x: u32) -> bool {
|
||||
x == 78
|
||||
}
|
||||
|
||||
fn more_projections() {
|
||||
let x = 19;
|
||||
let ppx: &u32 = &x;
|
||||
let _ = [ppx].iter().find(|ppp_x: &&&u32| please(**ppp_x)).is_none();
|
||||
let _ = [String::from("Hey hey")].iter().find(|s| s.len() == 2).is_none();
|
||||
|
||||
let v = vec![3, 2, 1, 0];
|
||||
let _ = v.iter().find(|x| simple_fn(**x)).is_none();
|
||||
}
|
||||
}
|
||||
|
@ -170,16 +170,22 @@ LL | let _ = vfoo.iter().find(|sub| sub[1..4].len() == 3).is_none();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!vfoo.iter().any(|sub| sub[1..4].len() == 3)`
|
||||
|
||||
error: called `is_none()` after searching an `Iterator` with `find`
|
||||
--> $DIR/search_is_some_fixable_none.rs:112:17
|
||||
--> $DIR/search_is_some_fixable_none.rs:116:17
|
||||
|
|
||||
LL | let _ = [ppx].iter().find(|ppp_x: &&&u32| please(**ppp_x)).is_none();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `![ppx].iter().any(|ppp_x: &&u32| please(ppp_x))`
|
||||
|
||||
error: called `is_none()` after searching an `Iterator` with `find`
|
||||
--> $DIR/search_is_some_fixable_none.rs:113:17
|
||||
--> $DIR/search_is_some_fixable_none.rs:117:17
|
||||
|
|
||||
LL | let _ = [String::from("Hey hey")].iter().find(|s| s.len() == 2).is_none();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `![String::from("Hey hey")].iter().any(|s| s.len() == 2)`
|
||||
|
||||
error: aborting due to 28 previous errors
|
||||
error: called `is_none()` after searching an `Iterator` with `find`
|
||||
--> $DIR/search_is_some_fixable_none.rs:120:17
|
||||
|
|
||||
LL | let _ = v.iter().find(|x| simple_fn(**x)).is_none();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!v.iter().any(|x| simple_fn(*x))`
|
||||
|
||||
error: aborting due to 29 previous errors
|
||||
|
||||
|
@ -103,10 +103,17 @@ mod issue7392 {
|
||||
*x == 9
|
||||
}
|
||||
|
||||
fn simple_fn(x: u32) -> bool {
|
||||
x == 78
|
||||
}
|
||||
|
||||
fn more_projections() {
|
||||
let x = 19;
|
||||
let ppx: &u32 = &x;
|
||||
let _ = [ppx].iter().any(|ppp_x: &&u32| please(ppp_x));
|
||||
let _ = [String::from("Hey hey")].iter().any(|s| s.len() == 2);
|
||||
|
||||
let v = vec![3, 2, 1, 0];
|
||||
let _ = v.iter().any(|x| simple_fn(*x));
|
||||
}
|
||||
}
|
||||
|
@ -105,10 +105,17 @@ fn please(x: &u32) -> bool {
|
||||
*x == 9
|
||||
}
|
||||
|
||||
fn simple_fn(x: u32) -> bool {
|
||||
x == 78
|
||||
}
|
||||
|
||||
fn more_projections() {
|
||||
let x = 19;
|
||||
let ppx: &u32 = &x;
|
||||
let _ = [ppx].iter().find(|ppp_x: &&&u32| please(**ppp_x)).is_some();
|
||||
let _ = [String::from("Hey hey")].iter().find(|s| s.len() == 2).is_some();
|
||||
|
||||
let v = vec![3, 2, 1, 0];
|
||||
let _ = v.iter().find(|x| simple_fn(**x)).is_some();
|
||||
}
|
||||
}
|
||||
|
@ -161,16 +161,22 @@ LL | let _ = vfoo.iter().find(|sub| sub[1..4].len() == 3).is_some();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|sub| sub[1..4].len() == 3)`
|
||||
|
||||
error: called `is_some()` after searching an `Iterator` with `find`
|
||||
--> $DIR/search_is_some_fixable_some.rs:111:30
|
||||
--> $DIR/search_is_some_fixable_some.rs:115:30
|
||||
|
|
||||
LL | let _ = [ppx].iter().find(|ppp_x: &&&u32| please(**ppp_x)).is_some();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|ppp_x: &&u32| please(ppp_x))`
|
||||
|
||||
error: called `is_some()` after searching an `Iterator` with `find`
|
||||
--> $DIR/search_is_some_fixable_some.rs:112:50
|
||||
--> $DIR/search_is_some_fixable_some.rs:116:50
|
||||
|
|
||||
LL | let _ = [String::from("Hey hey")].iter().find(|s| s.len() == 2).is_some();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|s| s.len() == 2)`
|
||||
|
||||
error: aborting due to 28 previous errors
|
||||
error: called `is_some()` after searching an `Iterator` with `find`
|
||||
--> $DIR/search_is_some_fixable_some.rs:119:26
|
||||
|
|
||||
LL | let _ = v.iter().find(|x| simple_fn(**x)).is_some();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| simple_fn(*x))`
|
||||
|
||||
error: aborting due to 29 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user