Skip to content

Commit 9e27377

Browse files
committed
Auto merge of #127404 - compiler-errors:rpitit-entailment-false-positive, r=oli-obk
Don't try to label `ObligationCauseCode::CompareImplItem` for an RPITIT, since it has no name The old (current) trait solver has a limitation that when a where clause in param-env must be normalized using the same where clause, then we get spurious errors in `normalize_param_env_or_error`. I don't think there's an issue tracking it, but it's the root cause for many of the "fixed-by-next-solver" labeled issues. Specifically, these errors may occur when checking predicate entailment of the GAT that comes out of desugaring RPITITs. Since we use `ObligationCauseCode::CompareImplItem` for these predicates, we try calling `item_name` on an RPITIT which fails, since the RPITIT has no name. We simply suppress this logic when we're reporting a predicate entailment error for an RPITIT. RPITITs should never have predicate entailment errors, *by construction*, but they may due to this bug in the old solver. Addresses the ICE in #127331, though doesn't fix the underlying issue (which is fundamental to the old solver). r? types
2 parents 289deb9 + d6276b3 commit 9e27377

File tree

4 files changed

+228
-24
lines changed

4 files changed

+228
-24
lines changed

Diff for: compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+4
Original file line numberDiff line numberDiff line change
@@ -3472,6 +3472,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
34723472
)
34733473
});
34743474
}
3475+
// Suppress `compare_type_predicate_entailment` errors for RPITITs, since they
3476+
// should be implied by the parent method.
3477+
ObligationCauseCode::CompareImplItem { trait_item_def_id, .. }
3478+
if tcx.is_impl_trait_in_trait(trait_item_def_id) => {}
34753479
ObligationCauseCode::CompareImplItem { trait_item_def_id, kind, .. } => {
34763480
let item_name = tcx.item_name(trait_item_def_id);
34773481
let msg = format!(

Diff for: tests/crashes/125099.rs

-24
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
error[E0277]: the trait bound `F: MyFn<i32>` is not satisfied
2+
--> $DIR/false-positive-predicate-entailment-error.rs:36:5
3+
|
4+
LL | / fn autobatch<F>(self) -> impl Trait
5+
LL | |
6+
LL | |
7+
LL | |
8+
... |
9+
LL | | where
10+
LL | | F: Callback<Self::CallbackArg>,
11+
| |_______________________________________^ the trait `MyFn<i32>` is not implemented for `F`, which is required by `F: Callback<i32>`
12+
|
13+
note: required for `F` to implement `Callback<i32>`
14+
--> $DIR/false-positive-predicate-entailment-error.rs:14:21
15+
|
16+
LL | impl<A, F: MyFn<A>> Callback<A> for F {
17+
| ------- ^^^^^^^^^^^ ^
18+
| |
19+
| unsatisfied trait bound introduced here
20+
help: consider further restricting this bound
21+
|
22+
LL | F: Callback<Self::CallbackArg> + MyFn<i32>,
23+
| +++++++++++
24+
25+
error[E0277]: the trait bound `F: MyFn<i32>` is not satisfied
26+
--> $DIR/false-positive-predicate-entailment-error.rs:36:30
27+
|
28+
LL | fn autobatch<F>(self) -> impl Trait
29+
| ^^^^^^^^^^ the trait `MyFn<i32>` is not implemented for `F`, which is required by `F: Callback<i32>`
30+
|
31+
note: required for `F` to implement `Callback<i32>`
32+
--> $DIR/false-positive-predicate-entailment-error.rs:14:21
33+
|
34+
LL | impl<A, F: MyFn<A>> Callback<A> for F {
35+
| ------- ^^^^^^^^^^^ ^
36+
| |
37+
| unsatisfied trait bound introduced here
38+
note: required by a bound in `<Sender as ChannelSender>::autobatch`
39+
--> $DIR/false-positive-predicate-entailment-error.rs:43:12
40+
|
41+
LL | fn autobatch<F>(self) -> impl Trait
42+
| --------- required by a bound in this associated function
43+
...
44+
LL | F: Callback<Self::CallbackArg>,
45+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `<Sender as ChannelSender>::autobatch`
46+
help: consider further restricting this bound
47+
|
48+
LL | F: Callback<Self::CallbackArg> + MyFn<i32>,
49+
| +++++++++++
50+
51+
error[E0277]: the trait bound `F: MyFn<i32>` is not satisfied
52+
--> $DIR/false-positive-predicate-entailment-error.rs:36:5
53+
|
54+
LL | / fn autobatch<F>(self) -> impl Trait
55+
LL | |
56+
LL | |
57+
LL | |
58+
... |
59+
LL | | where
60+
LL | | F: Callback<Self::CallbackArg>,
61+
| |_______________________________________^ the trait `MyFn<i32>` is not implemented for `F`, which is required by `F: Callback<i32>`
62+
|
63+
note: required for `F` to implement `Callback<i32>`
64+
--> $DIR/false-positive-predicate-entailment-error.rs:14:21
65+
|
66+
LL | impl<A, F: MyFn<A>> Callback<A> for F {
67+
| ------- ^^^^^^^^^^^ ^
68+
| |
69+
| unsatisfied trait bound introduced here
70+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
71+
help: consider further restricting this bound
72+
|
73+
LL | F: Callback<Self::CallbackArg> + MyFn<i32>,
74+
| +++++++++++
75+
76+
error[E0277]: the trait bound `F: Callback<i32>` is not satisfied
77+
--> $DIR/false-positive-predicate-entailment-error.rs:43:12
78+
|
79+
LL | F: Callback<Self::CallbackArg>,
80+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `MyFn<i32>` is not implemented for `F`, which is required by `F: Callback<i32>`
81+
|
82+
note: required for `F` to implement `Callback<i32>`
83+
--> $DIR/false-positive-predicate-entailment-error.rs:14:21
84+
|
85+
LL | impl<A, F: MyFn<A>> Callback<A> for F {
86+
| ------- ^^^^^^^^^^^ ^
87+
| |
88+
| unsatisfied trait bound introduced here
89+
note: the requirement `F: Callback<i32>` appears on the `impl`'s method `autobatch` but not on the corresponding trait's method
90+
--> $DIR/false-positive-predicate-entailment-error.rs:25:8
91+
|
92+
LL | trait ChannelSender {
93+
| ------------- in this trait
94+
...
95+
LL | fn autobatch<F>(self) -> impl Trait
96+
| ^^^^^^^^^ this trait's method doesn't have the requirement `F: Callback<i32>`
97+
help: consider further restricting this bound
98+
|
99+
LL | F: Callback<Self::CallbackArg> + MyFn<i32>,
100+
| +++++++++++
101+
102+
error[E0277]: the trait bound `F: MyFn<i32>` is not satisfied
103+
--> $DIR/false-positive-predicate-entailment-error.rs:36:30
104+
|
105+
LL | fn autobatch<F>(self) -> impl Trait
106+
| ^^^^^^^^^^ the trait `MyFn<i32>` is not implemented for `F`, which is required by `F: Callback<i32>`
107+
|
108+
note: required for `F` to implement `Callback<i32>`
109+
--> $DIR/false-positive-predicate-entailment-error.rs:14:21
110+
|
111+
LL | impl<A, F: MyFn<A>> Callback<A> for F {
112+
| ------- ^^^^^^^^^^^ ^
113+
| |
114+
| unsatisfied trait bound introduced here
115+
116+
error[E0277]: the trait bound `F: Callback<i32>` is not satisfied
117+
--> $DIR/false-positive-predicate-entailment-error.rs:27:12
118+
|
119+
LL | F: Callback<Self::CallbackArg>;
120+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `MyFn<i32>` is not implemented for `F`, which is required by `F: Callback<i32>`
121+
|
122+
note: required for `F` to implement `Callback<i32>`
123+
--> $DIR/false-positive-predicate-entailment-error.rs:14:21
124+
|
125+
LL | impl<A, F: MyFn<A>> Callback<A> for F {
126+
| ------- ^^^^^^^^^^^ ^
127+
| |
128+
| unsatisfied trait bound introduced here
129+
130+
error[E0277]: the trait bound `F: MyFn<i32>` is not satisfied
131+
--> $DIR/false-positive-predicate-entailment-error.rs:36:5
132+
|
133+
LL | / fn autobatch<F>(self) -> impl Trait
134+
LL | |
135+
LL | |
136+
LL | |
137+
... |
138+
LL | | where
139+
LL | | F: Callback<Self::CallbackArg>,
140+
| |_______________________________________^ the trait `MyFn<i32>` is not implemented for `F`, which is required by `F: Callback<i32>`
141+
|
142+
note: required for `F` to implement `Callback<i32>`
143+
--> $DIR/false-positive-predicate-entailment-error.rs:14:21
144+
|
145+
LL | impl<A, F: MyFn<A>> Callback<A> for F {
146+
| ------- ^^^^^^^^^^^ ^
147+
| |
148+
| unsatisfied trait bound introduced here
149+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
150+
help: consider further restricting this bound
151+
|
152+
LL | F: Callback<Self::CallbackArg> + MyFn<i32>,
153+
| +++++++++++
154+
155+
error[E0277]: the trait bound `F: MyFn<i32>` is not satisfied
156+
--> $DIR/false-positive-predicate-entailment-error.rs:43:12
157+
|
158+
LL | F: Callback<Self::CallbackArg>,
159+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `MyFn<i32>` is not implemented for `F`
160+
|
161+
note: required by a bound in `Callback`
162+
--> $DIR/false-positive-predicate-entailment-error.rs:10:20
163+
|
164+
LL | trait Callback<A>: MyFn<A, Output = Self::Ret> {
165+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Callback`
166+
help: consider further restricting this bound
167+
|
168+
LL | F: Callback<Self::CallbackArg> + MyFn<i32>,
169+
| +++++++++++
170+
171+
error: aborting due to 8 previous errors
172+
173+
For more information about this error, try `rustc --explain E0277`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//@ revisions: current next
2+
//@ ignore-compare-mode-next-solver (explicit revisions)
3+
//@[next] compile-flags: -Znext-solver
4+
//@[next] check-pass
5+
6+
trait MyFn<T> {
7+
type Output;
8+
}
9+
10+
trait Callback<A>: MyFn<A, Output = Self::Ret> {
11+
type Ret;
12+
}
13+
14+
impl<A, F: MyFn<A>> Callback<A> for F {
15+
type Ret = F::Output;
16+
}
17+
18+
struct Thing;
19+
trait Trait {}
20+
impl Trait for Thing {}
21+
22+
trait ChannelSender {
23+
type CallbackArg;
24+
25+
fn autobatch<F>(self) -> impl Trait
26+
where
27+
F: Callback<Self::CallbackArg>;
28+
//[current]~^ ERROR the trait bound `F: Callback<i32>` is not satisfied
29+
}
30+
31+
struct Sender;
32+
33+
impl ChannelSender for Sender {
34+
type CallbackArg = i32;
35+
36+
fn autobatch<F>(self) -> impl Trait
37+
//[current]~^ ERROR the trait bound `F: MyFn<i32>` is not satisfied
38+
//[current]~| ERROR the trait bound `F: MyFn<i32>` is not satisfied
39+
//[current]~| ERROR the trait bound `F: MyFn<i32>` is not satisfied
40+
//[current]~| ERROR the trait bound `F: MyFn<i32>` is not satisfied
41+
//[current]~| ERROR the trait bound `F: MyFn<i32>` is not satisfied
42+
where
43+
F: Callback<Self::CallbackArg>,
44+
//[current]~^ ERROR the trait bound `F: Callback<i32>` is not satisfied
45+
//[current]~| ERROR the trait bound `F: MyFn<i32>` is not satisfied
46+
{
47+
Thing
48+
}
49+
}
50+
51+
fn main() {}

0 commit comments

Comments
 (0)