Skip to content

Commit 2a3fd50

Browse files
Don't suggest field method if it's just missing some bounds
1 parent 4df6cbe commit 2a3fd50

File tree

4 files changed

+5
-17
lines changed

4 files changed

+5
-17
lines changed

compiler/rustc_typeck/src/check/method/suggest.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10001000
label_span_not_found(&mut err);
10011001
}
10021002

1003-
self.check_for_field_method(&mut err, source, span, actual, item_name);
1003+
// Don't suggest (for example) `expr.field.method()` if `expr.method()`
1004+
// doesn't exist due to unsatisfied predicates.
1005+
if unsatisfied_predicates.is_empty() {
1006+
self.check_for_field_method(&mut err, source, span, actual, item_name);
1007+
}
10041008

10051009
self.check_for_unwrap_self(&mut err, source, span, actual, item_name);
10061010

src/test/ui/hrtb/issue-30786.stderr

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ note: the following trait bounds were not satisfied:
1818
|
1919
LL | impl<T> StreamExt for T where for<'a> &'a mut T: Stream {}
2020
| --------- - ^^^^^^ unsatisfied trait bound introduced here
21-
help: one of the expressions' fields has a method of the same name
22-
|
23-
LL | let filter = map.stream.filterx(|x: &_| true);
24-
| +++++++
2521

2622
error[E0599]: the method `countx` exists for struct `Filter<Map<Repeat, for<'r> fn(&'r u64) -> &'r u64 {identity::<u64>}>, [closure@$DIR/issue-30786.rs:129:30: 129:37]>`, but its trait bounds were not satisfied
2723
--> $DIR/issue-30786.rs:130:24
@@ -43,10 +39,6 @@ note: the following trait bounds were not satisfied:
4339
|
4440
LL | impl<T> StreamExt for T where for<'a> &'a mut T: Stream {}
4541
| --------- - ^^^^^^ unsatisfied trait bound introduced here
46-
help: one of the expressions' fields has a method of the same name
47-
|
48-
LL | let count = filter.stream.countx();
49-
| +++++++
5042

5143
error: aborting due to 2 previous errors
5244

src/test/ui/union/union-derive-clone.mirunsafeck.stderr

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ help: consider annotating `CloneNoCopy` with `#[derive(Clone, Copy)]`
4242
|
4343
LL | #[derive(Clone, Copy)]
4444
|
45-
help: one of the expressions' fields has a method of the same name
46-
|
47-
LL | let w = u.a.clone();
48-
| ++
4945

5046
error: aborting due to 2 previous errors
5147

src/test/ui/union/union-derive-clone.thirunsafeck.stderr

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ help: consider annotating `CloneNoCopy` with `#[derive(Clone, Copy)]`
4242
|
4343
LL | #[derive(Clone, Copy)]
4444
|
45-
help: one of the expressions' fields has a method of the same name
46-
|
47-
LL | let w = u.a.clone();
48-
| ++
4945

5046
error: aborting due to 2 previous errors
5147

0 commit comments

Comments
 (0)