Skip to content

Commit 3702ab1

Browse files
Use fulfillment, not evaluate, during method probe
1 parent 105672d commit 3702ab1

22 files changed

+245
-410
lines changed

compiler/rustc_hir_typeck/src/demand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
894894
[candidate] => format!(
895895
"the method of the same name on {} `{}`",
896896
match candidate.kind {
897-
probe::CandidateKind::InherentImplCandidate(..) => "the inherent impl for",
897+
probe::CandidateKind::InherentImplCandidate(_) => "the inherent impl for",
898898
_ => "trait",
899899
},
900900
self.tcx.def_path_str(candidate.item.container_id(self.tcx))

compiler/rustc_hir_typeck/src/method/probe.rs

+124-295
Large diffs are not rendered by default.

compiler/rustc_trait_selection/src/traits/engine.rs

+13
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,19 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> {
129129
.map(|infer_ok| self.register_infer_ok_obligations(infer_ok))
130130
}
131131

132+
pub fn eq_no_opaques<T: ToTrace<'tcx>>(
133+
&self,
134+
cause: &ObligationCause<'tcx>,
135+
param_env: ty::ParamEnv<'tcx>,
136+
expected: T,
137+
actual: T,
138+
) -> Result<(), TypeError<'tcx>> {
139+
self.infcx
140+
.at(cause, param_env)
141+
.eq(DefineOpaqueTypes::No, expected, actual)
142+
.map(|infer_ok| self.register_infer_ok_obligations(infer_ok))
143+
}
144+
132145
/// Checks whether `expected` is a subtype of `actual`: `expected <: actual`.
133146
pub fn sub<T: ToTrace<'tcx>>(
134147
&self,

tests/ui/derives/issue-91550.stderr

+4-23
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@ error[E0599]: the method `insert` exists for struct `HashSet<Value>`, but its tr
22
--> $DIR/issue-91550.rs:8:8
33
|
44
LL | struct Value(u32);
5-
| ------------ doesn't satisfy `Value: Eq`, `Value: Hash` or `Value: PartialEq`
5+
| ------------ doesn't satisfy `Value: Eq` or `Value: Hash`
66
...
77
LL | hs.insert(Value(0));
88
| ^^^^^^
99
|
1010
= note: the following trait bounds were not satisfied:
1111
`Value: Eq`
12-
`Value: PartialEq`
13-
which is required by `Value: Eq`
1412
`Value: Hash`
1513
help: consider annotating `Value` with `#[derive(Eq, Hash, PartialEq)]`
1614
|
@@ -22,7 +20,7 @@ error[E0599]: the method `use_eq` exists for struct `Object<NoDerives>`, but its
2220
--> $DIR/issue-91550.rs:26:9
2321
|
2422
LL | pub struct NoDerives;
25-
| -------------------- doesn't satisfy `NoDerives: Eq` or `NoDerives: PartialEq`
23+
| -------------------- doesn't satisfy `NoDerives: Eq`
2624
LL |
2725
LL | struct Object<T>(T);
2826
| ---------------- method `use_eq` not found for this struct
@@ -37,9 +35,6 @@ LL | impl<T: Eq> Object<T> {
3735
| ^^ ---------
3836
| |
3937
| unsatisfied trait bound introduced here
40-
= note: the following trait bounds were not satisfied:
41-
`NoDerives: PartialEq`
42-
which is required by `NoDerives: Eq`
4338
help: consider annotating `NoDerives` with `#[derive(Eq, PartialEq)]`
4439
|
4540
LL + #[derive(Eq, PartialEq)]
@@ -50,7 +45,7 @@ error[E0599]: the method `use_ord` exists for struct `Object<NoDerives>`, but it
5045
--> $DIR/issue-91550.rs:27:9
5146
|
5247
LL | pub struct NoDerives;
53-
| -------------------- doesn't satisfy `NoDerives: Eq`, `NoDerives: Ord`, `NoDerives: PartialEq` or `NoDerives: PartialOrd`
48+
| -------------------- doesn't satisfy `NoDerives: Ord`
5449
LL |
5550
LL | struct Object<T>(T);
5651
| ---------------- method `use_ord` not found for this struct
@@ -65,13 +60,6 @@ LL | impl<T: Ord> Object<T> {
6560
| ^^^ ---------
6661
| |
6762
| unsatisfied trait bound introduced here
68-
= note: the following trait bounds were not satisfied:
69-
`NoDerives: PartialOrd`
70-
which is required by `NoDerives: Ord`
71-
`NoDerives: PartialEq`
72-
which is required by `NoDerives: Ord`
73-
`NoDerives: Eq`
74-
which is required by `NoDerives: Ord`
7563
help: consider annotating `NoDerives` with `#[derive(Eq, Ord, PartialEq, PartialOrd)]`
7664
|
7765
LL + #[derive(Eq, Ord, PartialEq, PartialOrd)]
@@ -82,7 +70,7 @@ error[E0599]: the method `use_ord_and_partial_ord` exists for struct `Object<NoD
8270
--> $DIR/issue-91550.rs:28:9
8371
|
8472
LL | pub struct NoDerives;
85-
| -------------------- doesn't satisfy `NoDerives: Eq`, `NoDerives: Ord`, `NoDerives: PartialEq` or `NoDerives: PartialOrd`
73+
| -------------------- doesn't satisfy `NoDerives: Ord` or `NoDerives: PartialOrd`
8674
LL |
8775
LL | struct Object<T>(T);
8876
| ---------------- method `use_ord_and_partial_ord` not found for this struct
@@ -100,13 +88,6 @@ LL | impl<T: Ord + PartialOrd> Object<T> {
10088
| | |
10189
| | unsatisfied trait bound introduced here
10290
| unsatisfied trait bound introduced here
103-
= note: the following trait bounds were not satisfied:
104-
`NoDerives: PartialEq`
105-
which is required by `NoDerives: Ord`
106-
`NoDerives: Eq`
107-
which is required by `NoDerives: Ord`
108-
`NoDerives: PartialEq`
109-
which is required by `NoDerives: PartialOrd`
11091
help: consider annotating `NoDerives` with `#[derive(Eq, Ord, PartialEq, PartialOrd)]`
11192
|
11293
LL + #[derive(Eq, Ord, PartialEq, PartialOrd)]

tests/ui/generic-associated-types/issue-119942-unsatisified-gat-bound-during-assoc-ty-selection.stderr

+3-10
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,15 @@ help: consider relaxing the implicit `Sized` restriction
1515
LL | type Pointer<T>: Deref<Target = T> + ?Sized;
1616
| ++++++++
1717

18-
error[E0599]: the size for values of type `Node<i32, RcFamily>` cannot be known at compilation time
18+
error[E0599]: the variant or associated item `new` exists for enum `Node<i32, RcFamily>`, but its trait bounds were not satisfied
1919
--> $DIR/issue-119942-unsatisified-gat-bound-during-assoc-ty-selection.rs:31:35
2020
|
2121
LL | enum Node<T, P: PointerFamily> {
22-
| ------------------------------ variant or associated item `new` not found for this enum because it doesn't satisfy `Node<i32, RcFamily>: Sized`
22+
| ------------------------------ variant or associated item `new` not found for this enum
2323
...
2424
LL | let mut list = RcNode::<i32>::new();
25-
| ^^^ doesn't have a size known at compile-time
25+
| ^^^ variant or associated item cannot be called on `Node<i32, RcFamily>` due to unsatisfied trait bounds
2626
|
27-
note: trait bound `Node<i32, RcFamily>: Sized` was not satisfied
28-
--> $DIR/issue-119942-unsatisified-gat-bound-during-assoc-ty-selection.rs:4:18
29-
|
30-
LL | type Pointer<T>: Deref<Target = T>;
31-
| ------- ^ unsatisfied trait bound introduced here
3227
note: trait bound `(dyn Deref<Target = Node<i32, RcFamily>> + 'static): Sized` was not satisfied
3328
--> $DIR/issue-119942-unsatisified-gat-bound-during-assoc-ty-selection.rs:23:29
3429
|
@@ -37,8 +32,6 @@ LL | impl<T, P: PointerFamily> Node<T, P>
3732
LL | where
3833
LL | P::Pointer<Node<T, P>>: Sized,
3934
| ^^^^^ unsatisfied trait bound introduced here
40-
note: the trait `Sized` must be implemented
41-
--> $SRC_DIR/core/src/marker.rs:LL:COL
4235

4336
error: aborting due to 2 previous errors
4437

tests/ui/higher-ranked/trait-bounds/issue-30786.stderr

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ error[E0599]: the method `filterx` exists for struct `Map<Repeat, {closure@issue
22
--> $DIR/issue-30786.rs:120:22
33
|
44
LL | pub struct Map<S, F> {
5-
| -------------------- method `filterx` not found for this struct because it doesn't satisfy `_: StreamExt`
5+
| -------------------- method `filterx` not found for this struct
66
...
77
LL | let filter = map.filterx(|x: &_| true);
88
| ^^^^^^^ method cannot be called on `Map<Repeat, {[email protected]:119:27}>` due to unsatisfied trait bounds
99
|
1010
note: the following trait bounds were not satisfied:
1111
`&'a mut &Map<Repeat, {closure@$DIR/issue-30786.rs:119:27: 119:34}>: Stream`
1212
`&'a mut &mut Map<Repeat, {closure@$DIR/issue-30786.rs:119:27: 119:34}>: Stream`
13-
`&'a mut Map<Repeat, {closure@$DIR/issue-30786.rs:119:27: 119:34}>: Stream`
1413
--> $DIR/issue-30786.rs:98:50
1514
|
1615
LL | impl<T> StreamExt for T where for<'a> &'a mut T: Stream {}
@@ -26,15 +25,14 @@ error[E0599]: the method `countx` exists for struct `Filter<Map<Repeat, fn(&u64)
2625
--> $DIR/issue-30786.rs:132:24
2726
|
2827
LL | pub struct Filter<S, F> {
29-
| ----------------------- method `countx` not found for this struct because it doesn't satisfy `_: StreamExt`
28+
| ----------------------- method `countx` not found for this struct
3029
...
3130
LL | let count = filter.countx();
3231
| ^^^^^^ method cannot be called due to unsatisfied trait bounds
3332
|
3433
note: the following trait bounds were not satisfied:
3534
`&'a mut &Filter<Map<Repeat, for<'a> fn(&'a u64) -> &'a u64 {identity::<u64>}>, {closure@$DIR/issue-30786.rs:131:30: 131:37}>: Stream`
3635
`&'a mut &mut Filter<Map<Repeat, for<'a> fn(&'a u64) -> &'a u64 {identity::<u64>}>, {closure@$DIR/issue-30786.rs:131:30: 131:37}>: Stream`
37-
`&'a mut Filter<Map<Repeat, for<'a> fn(&'a u64) -> &'a u64 {identity::<u64>}>, {closure@$DIR/issue-30786.rs:131:30: 131:37}>: Stream`
3836
--> $DIR/issue-30786.rs:98:50
3937
|
4038
LL | impl<T> StreamExt for T where for<'a> &'a mut T: Stream {}

tests/ui/impl-trait/issues/issue-62742.stderr

+30-20
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
1-
error[E0277]: the trait bound `RawImpl<_>: Raw<_>` is not satisfied
2-
--> $DIR/issue-62742.rs:4:5
1+
error[E0599]: the function or associated item `foo` exists for struct `SafeImpl<_, RawImpl<_>>`, but its trait bounds were not satisfied
2+
--> $DIR/issue-62742.rs:4:16
33
|
44
LL | WrongImpl::foo(0i32);
5-
| ^^^^^^^^^^^^^^^^^^^^ the trait `Raw<_>` is not implemented for `RawImpl<_>`
5+
| ^^^ function or associated item cannot be called on `SafeImpl<_, RawImpl<_>>` due to unsatisfied trait bounds
6+
...
7+
LL | pub struct RawImpl<T>(PhantomData<T>);
8+
| --------------------- doesn't satisfy `RawImpl<_>: Raw<_>`
9+
...
10+
LL | pub struct SafeImpl<T: ?Sized, A: Raw<T>>(PhantomData<(A, T)>);
11+
| ----------------------------------------- function or associated item `foo` not found for this struct
612
|
7-
= help: the trait `Raw<[_]>` is implemented for `RawImpl<_>`
8-
note: required by a bound in `SafeImpl::<T, A>::foo`
13+
note: trait bound `RawImpl<_>: Raw<_>` was not satisfied
914
--> $DIR/issue-62742.rs:29:20
1015
|
1116
LL | impl<T: ?Sized, A: Raw<T>> SafeImpl<T, A> {
12-
| ^^^^^^ required by this bound in `SafeImpl::<T, A>::foo`
13-
LL | pub fn foo(value: A::Value) {}
14-
| --- required by a bound in this associated function
15-
16-
error[E0277]: the trait bound `RawImpl<_>: Raw<_>` is not satisfied
17-
--> $DIR/issue-62742.rs:4:5
18-
|
19-
LL | WrongImpl::foo(0i32);
20-
| ^^^^^^^^^ the trait `Raw<_>` is not implemented for `RawImpl<_>`
21-
|
22-
= help: the trait `Raw<[_]>` is implemented for `RawImpl<_>`
23-
note: required by a bound in `SafeImpl`
24-
--> $DIR/issue-62742.rs:27:35
17+
| ^^^^^^ --------------
18+
| |
19+
| unsatisfied trait bound introduced here
20+
note: the trait `Raw` must be implemented
21+
--> $DIR/issue-62742.rs:13:1
2522
|
26-
LL | pub struct SafeImpl<T: ?Sized, A: Raw<T>>(PhantomData<(A, T)>);
27-
| ^^^^^^ required by this bound in `SafeImpl`
23+
LL | pub trait Raw<T: ?Sized> {
24+
| ^^^^^^^^^^^^^^^^^^^^^^^^
2825

2926
error[E0599]: the function or associated item `foo` exists for struct `SafeImpl<(), RawImpl<()>>`, but its trait bounds were not satisfied
3027
--> $DIR/issue-62742.rs:7:22
@@ -51,6 +48,19 @@ note: the trait `Raw` must be implemented
5148
LL | pub trait Raw<T: ?Sized> {
5249
| ^^^^^^^^^^^^^^^^^^^^^^^^
5350

51+
error[E0277]: the trait bound `RawImpl<_>: Raw<_>` is not satisfied
52+
--> $DIR/issue-62742.rs:4:5
53+
|
54+
LL | WrongImpl::foo(0i32);
55+
| ^^^^^^^^^ the trait `Raw<_>` is not implemented for `RawImpl<_>`
56+
|
57+
= help: the trait `Raw<[_]>` is implemented for `RawImpl<_>`
58+
note: required by a bound in `SafeImpl`
59+
--> $DIR/issue-62742.rs:27:35
60+
|
61+
LL | pub struct SafeImpl<T: ?Sized, A: Raw<T>>(PhantomData<(A, T)>);
62+
| ^^^^^^ required by this bound in `SafeImpl`
63+
5464
error[E0277]: the trait bound `RawImpl<()>: Raw<()>` is not satisfied
5565
--> $DIR/issue-62742.rs:7:5
5666
|
+24-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,29 @@
1-
error[E0275]: overflow assigning `_` to `Option<_>`
2-
--> $DIR/issue-84073.rs:32:22
1+
error[E0599]: the method `when` exists for struct `RaceBuilder<_, Never<_>>`, but its trait bounds were not satisfied
2+
--> $DIR/issue-84073.rs:32:27
33
|
4+
LL | pub struct Never<T>(PhantomData<T>);
5+
| ------------------- doesn't satisfy `Never<_>: StatefulFuture<Option<_>>`
6+
...
7+
LL | pub struct RaceBuilder<F, S> {
8+
| ---------------------------- method `when` not found for this struct
9+
...
410
LL | Race::new(|race| race.when());
5-
| ^^^^
11+
| ^^^^ method cannot be called on `RaceBuilder<_, Never<_>>` due to unsatisfied trait bounds
12+
|
13+
note: trait bound `Never<_>: StatefulFuture<Option<_>>` was not satisfied
14+
--> $DIR/issue-84073.rs:14:8
15+
|
16+
LL | impl<T, F> RaceBuilder<T, F>
17+
| -----------------
18+
LL | where
19+
LL | F: StatefulFuture<Option<T>>,
20+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound introduced here
21+
note: the trait `StatefulFuture` must be implemented
22+
--> $DIR/issue-84073.rs:3:1
23+
|
24+
LL | pub trait StatefulFuture<S> {}
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
626

727
error: aborting due to 1 previous error
828

9-
For more information about this error, try `rustc --explain E0275`.
29+
For more information about this error, try `rustc --explain E0599`.

tests/ui/issues/issue-50264-inner-deref-trait/option-as_deref.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ LL | let _result = &Some(42).as_deref();
66
|
77
= note: the following trait bounds were not satisfied:
88
`{integer}: Deref`
9+
which is required by `<{integer} as Deref>::Target = _`
910

1011
error: aborting due to 1 previous error
1112

tests/ui/issues/issue-50264-inner-deref-trait/option-as_deref_mut.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ LL | let _result = &mut Some(42).as_deref_mut();
66
|
77
= note: the following trait bounds were not satisfied:
88
`{integer}: Deref`
9+
which is required by `<{integer} as Deref>::Target = _`
910

1011
error: aborting due to 1 previous error
1112

tests/ui/issues/issue-50264-inner-deref-trait/result-as_deref.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ LL | let _result = &Ok(42).as_deref();
66
|
77
= note: the following trait bounds were not satisfied:
88
`{integer}: Deref`
9+
which is required by `<{integer} as Deref>::Target = _`
910

1011
error: aborting due to 1 previous error
1112

tests/ui/issues/issue-50264-inner-deref-trait/result-as_deref_mut.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ LL | let _result = &mut Ok(42).as_deref_mut();
66
|
77
= note: the following trait bounds were not satisfied:
88
`{integer}: Deref`
9+
which is required by `<{integer} as Deref>::Target = _`
910

1011
error: aborting due to 1 previous error
1112

tests/ui/issues/issue-57362-2.stderr

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
error[E0599]: the function or associated item `make_g` exists for fn pointer `fn(&())`, but its trait bounds were not satisfied
1+
error[E0599]: no function or associated item named `make_g` found for fn pointer `for<'a> fn(&'a ())` in the current scope
22
--> $DIR/issue-57362-2.rs:22:25
33
|
44
LL | let x = <fn (&())>::make_g();
5-
| ^^^^^^ function or associated item cannot be called on `fn(&())` due to unsatisfied trait bounds
5+
| ^^^^^^ function or associated item not found in `fn(&())`
66
|
7-
= note: the following trait bounds were not satisfied:
8-
`for<'a> fn(&'a ()): X`
97
= help: items from traits can only be used if the trait is implemented and in scope
108
note: `X` defines an item `make_g`, perhaps you need to implement it
119
--> $DIR/issue-57362-2.rs:8:1

tests/ui/mismatched_types/issue-36053-2.stderr

+6-4
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@ error[E0599]: the method `count` exists for struct `Filter<Fuse<Once<&str>>, {cl
2121
LL | once::<&str>("str").fuse().filter(|a: &str| true).count();
2222
| --------- ^^^^^ method cannot be called due to unsatisfied trait bounds
2323
| |
24-
| doesn't satisfy `<_ as FnOnce<(&&str,)>>::Output = bool` or `_: FnMut<(&&str,)>`
24+
| doesn't satisfy `_: FnMut<(&&str,)>` or `_: FnOnce<(&&str,)>`
2525
|
2626
= note: the following trait bounds were not satisfied:
27-
`<{closure@$DIR/issue-36053-2.rs:7:39: 7:48} as FnOnce<(&&str,)>>::Output = bool`
28-
which is required by `Filter<Fuse<std::iter::Once<&str>>, {closure@$DIR/issue-36053-2.rs:7:39: 7:48}>: Iterator`
2927
`{closure@$DIR/issue-36053-2.rs:7:39: 7:48}: FnMut<(&&str,)>`
3028
which is required by `Filter<Fuse<std::iter::Once<&str>>, {closure@$DIR/issue-36053-2.rs:7:39: 7:48}>: Iterator`
31-
`Filter<Fuse<std::iter::Once<&str>>, {closure@$DIR/issue-36053-2.rs:7:39: 7:48}>: Iterator`
29+
`{closure@$DIR/issue-36053-2.rs:7:39: 7:48}: FnOnce<(&&str,)>`
30+
which is required by `Filter<Fuse<std::iter::Once<&str>>, {closure@$DIR/issue-36053-2.rs:7:39: 7:48}>: Iterator`
31+
`{closure@$DIR/issue-36053-2.rs:7:39: 7:48}: FnMut<(&&str,)>`
32+
which is required by `&mut Filter<Fuse<std::iter::Once<&str>>, {closure@$DIR/issue-36053-2.rs:7:39: 7:48}>: Iterator`
33+
`{closure@$DIR/issue-36053-2.rs:7:39: 7:48}: FnOnce<(&&str,)>`
3234
which is required by `&mut Filter<Fuse<std::iter::Once<&str>>, {closure@$DIR/issue-36053-2.rs:7:39: 7:48}>: Iterator`
3335

3436
error: aborting due to 2 previous errors

tests/ui/missing-trait-bounds/issue-35677.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ LL | this.is_subset(other)
66
|
77
= note: the following trait bounds were not satisfied:
88
`T: Eq`
9-
`T: PartialEq`
10-
which is required by `T: Eq`
119
`T: Hash`
1210
help: consider restricting the type parameters to satisfy the trait bounds
1311
|

tests/ui/nll/issue-57642-higher-ranked-subtype.stderr

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
error[E0599]: the function or associated item `make_g` exists for fn pointer `fn(&())`, but its trait bounds were not satisfied
1+
error[E0599]: no function or associated item named `make_g` found for fn pointer `for<'a> fn(&'a ())` in the current scope
22
--> $DIR/issue-57642-higher-ranked-subtype.rs:31:25
33
|
44
LL | let x = <fn (&())>::make_g();
5-
| ^^^^^^ function or associated item cannot be called on `fn(&())` due to unsatisfied trait bounds
5+
| ^^^^^^ function or associated item not found in `fn(&())`
66
|
7-
= note: the following trait bounds were not satisfied:
8-
`for<'a> fn(&'a ()): X`
97
= help: items from traits can only be used if the trait is implemented and in scope
108
note: `X` defines an item `make_g`, perhaps you need to implement it
119
--> $DIR/issue-57642-higher-ranked-subtype.rs:4:1

0 commit comments

Comments
 (0)