Skip to content

Commit 2795597

Browse files
authored
Unrolled build for rust-lang#126404
Rollup merge of rust-lang#126404 - compiler-errors:alias-relate-terms, r=lcnr Check that alias-relate terms are WF if reporting an error in alias-relate Check that each of the left/right term is WF when deriving a best error obligation for an alias-relate goal. This will make sure that given `<i32 as NotImplemented>::Assoc = ()` will drill down into `i32: NotImplemented` since we currently treat the projection as rigid. r? lcnr
2 parents 92af831 + 0562064 commit 2795597

12 files changed

+59
-168
lines changed

compiler/rustc_trait_selection/src/solve/fulfill.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,32 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
515515
self.with_derived_obligation(obligation, |this| nested_goal.visit_with(this))?;
516516
}
517517

518+
// alias-relate may fail because the lhs or rhs can't be normalized,
519+
// and therefore is treated as rigid.
520+
if let Some(ty::PredicateKind::AliasRelate(lhs, rhs, _)) = pred_kind.no_bound_vars() {
521+
if let Some(obligation) = goal
522+
.infcx()
523+
.visit_proof_tree_at_depth(
524+
goal.goal().with(goal.infcx().tcx, ty::ClauseKind::WellFormed(lhs.into())),
525+
goal.depth() + 1,
526+
self,
527+
)
528+
.break_value()
529+
{
530+
return ControlFlow::Break(obligation);
531+
} else if let Some(obligation) = goal
532+
.infcx()
533+
.visit_proof_tree_at_depth(
534+
goal.goal().with(goal.infcx().tcx, ty::ClauseKind::WellFormed(rhs.into())),
535+
goal.depth() + 1,
536+
self,
537+
)
538+
.break_value()
539+
{
540+
return ControlFlow::Break(obligation);
541+
}
542+
}
543+
518544
ControlFlow::Break(self.obligation.clone())
519545
}
520546
}

compiler/rustc_trait_selection/src/solve/inspect/analyse.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,10 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
278278
self.source
279279
}
280280

281+
pub fn depth(&self) -> usize {
282+
self.depth
283+
}
284+
281285
fn candidates_recur(
282286
&'a self,
283287
candidates: &mut Vec<InspectCandidate<'a, 'tcx>>,
@@ -435,9 +439,18 @@ impl<'tcx> InferCtxt<'tcx> {
435439
&self,
436440
goal: Goal<'tcx, ty::Predicate<'tcx>>,
437441
visitor: &mut V,
442+
) -> V::Result {
443+
self.visit_proof_tree_at_depth(goal, 0, visitor)
444+
}
445+
446+
fn visit_proof_tree_at_depth<V: ProofTreeVisitor<'tcx>>(
447+
&self,
448+
goal: Goal<'tcx, ty::Predicate<'tcx>>,
449+
depth: usize,
450+
visitor: &mut V,
438451
) -> V::Result {
439452
let (_, proof_tree) = self.evaluate_root_goal(goal, GenerateProofTree::Yes);
440453
let proof_tree = proof_tree.unwrap();
441-
visitor.visit_goal(&InspectGoal::new(self, 0, proof_tree, None, GoalSource::Misc))
454+
visitor.visit_goal(&InspectGoal::new(self, depth, proof_tree, None, GoalSource::Misc))
442455
}
443456
}

tests/ui/associated-types/defaults-unsound-62211-1.next.stderr

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,17 @@ help: consider further restricting `Self`
3131
LL | trait UncheckedCopy: Sized + AddAssign<&'static str> {
3232
| +++++++++++++++++++++++++
3333

34-
error[E0271]: type mismatch resolving `<Self as Deref>::Target == str`
35-
--> $DIR/defaults-unsound-62211-1.rs:24:96
36-
|
37-
LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + From<Self> + Display = Self;
38-
| ^^^^ types differ
39-
|
40-
note: required by a bound in `UncheckedCopy::Output`
41-
--> $DIR/defaults-unsound-62211-1.rs:24:31
42-
|
43-
LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + From<Self> + Display = Self;
44-
| ^^^^^^^^^^^^ required by this bound in `UncheckedCopy::Output`
45-
4634
error[E0277]: the trait bound `Self: Deref` is not satisfied
4735
--> $DIR/defaults-unsound-62211-1.rs:24:96
4836
|
4937
LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + From<Self> + Display = Self;
5038
| ^^^^ the trait `Deref` is not implemented for `Self`
5139
|
5240
note: required by a bound in `UncheckedCopy::Output`
53-
--> $DIR/defaults-unsound-62211-1.rs:24:25
41+
--> $DIR/defaults-unsound-62211-1.rs:24:31
5442
|
5543
LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + From<Self> + Display = Self;
56-
| ^^^^^^^^^^^^^^^^^^^ required by this bound in `UncheckedCopy::Output`
44+
| ^^^^^^^^^^^^ required by this bound in `UncheckedCopy::Output`
5745
help: consider further restricting `Self`
5846
|
5947
LL | trait UncheckedCopy: Sized + Deref {
@@ -75,7 +63,6 @@ help: consider further restricting `Self`
7563
LL | trait UncheckedCopy: Sized + Copy {
7664
| ++++++
7765

78-
error: aborting due to 5 previous errors
66+
error: aborting due to 4 previous errors
7967

80-
Some errors have detailed explanations: E0271, E0277.
81-
For more information about an error, try `rustc --explain E0271`.
68+
For more information about this error, try `rustc --explain E0277`.

tests/ui/associated-types/defaults-unsound-62211-1.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ trait UncheckedCopy: Sized {
2626
//~| ERROR the trait bound `Self: Deref` is not satisfied
2727
//~| ERROR cannot add-assign `&'static str` to `Self`
2828
//~| ERROR `Self` doesn't implement `std::fmt::Display`
29-
//[next]~| ERROR type mismatch resolving `<Self as Deref>::Target == str`
3029

3130
// We said the Output type was Copy, so we can Copy it freely!
3231
fn unchecked_copy(other: &Self::Output) -> Self::Output {

tests/ui/associated-types/defaults-unsound-62211-2.next.stderr

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,17 @@ help: consider further restricting `Self`
3131
LL | trait UncheckedCopy: Sized + AddAssign<&'static str> {
3232
| +++++++++++++++++++++++++
3333

34-
error[E0271]: type mismatch resolving `<Self as Deref>::Target == str`
35-
--> $DIR/defaults-unsound-62211-2.rs:24:96
36-
|
37-
LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + From<Self> + Display = Self;
38-
| ^^^^ types differ
39-
|
40-
note: required by a bound in `UncheckedCopy::Output`
41-
--> $DIR/defaults-unsound-62211-2.rs:24:31
42-
|
43-
LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + From<Self> + Display = Self;
44-
| ^^^^^^^^^^^^ required by this bound in `UncheckedCopy::Output`
45-
4634
error[E0277]: the trait bound `Self: Deref` is not satisfied
4735
--> $DIR/defaults-unsound-62211-2.rs:24:96
4836
|
4937
LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + From<Self> + Display = Self;
5038
| ^^^^ the trait `Deref` is not implemented for `Self`
5139
|
5240
note: required by a bound in `UncheckedCopy::Output`
53-
--> $DIR/defaults-unsound-62211-2.rs:24:25
41+
--> $DIR/defaults-unsound-62211-2.rs:24:31
5442
|
5543
LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + From<Self> + Display = Self;
56-
| ^^^^^^^^^^^^^^^^^^^ required by this bound in `UncheckedCopy::Output`
44+
| ^^^^^^^^^^^^ required by this bound in `UncheckedCopy::Output`
5745
help: consider further restricting `Self`
5846
|
5947
LL | trait UncheckedCopy: Sized + Deref {
@@ -75,7 +63,6 @@ help: consider further restricting `Self`
7563
LL | trait UncheckedCopy: Sized + Copy {
7664
| ++++++
7765

78-
error: aborting due to 5 previous errors
66+
error: aborting due to 4 previous errors
7967

80-
Some errors have detailed explanations: E0271, E0277.
81-
For more information about an error, try `rustc --explain E0271`.
68+
For more information about this error, try `rustc --explain E0277`.

tests/ui/associated-types/defaults-unsound-62211-2.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ trait UncheckedCopy: Sized {
2626
//~| ERROR the trait bound `Self: Deref` is not satisfied
2727
//~| ERROR cannot add-assign `&'static str` to `Self`
2828
//~| ERROR `Self` doesn't implement `std::fmt::Display`
29-
//[next]~| ERROR type mismatch resolving `<Self as Deref>::Target == str`
3029

3130
// We said the Output type was Copy, so we can Copy it freely!
3231
fn unchecked_copy(other: &Self::Output) -> Self::Output {
Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
error[E0271]: type mismatch resolving `<<T as SubEncoder>::ActualSize as Add>::Output == <T as SubEncoder>::ActualSize`
2-
--> $DIR/issue-54108.rs:23:17
3-
|
4-
LL | type Size = <Self as SubEncoder>::ActualSize;
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ types differ
6-
|
7-
note: required by a bound in `Encoder::Size`
8-
--> $DIR/issue-54108.rs:8:20
9-
|
10-
LL | type Size: Add<Output = Self::Size>;
11-
| ^^^^^^^^^^^^^^^^^^^ required by this bound in `Encoder::Size`
12-
131
error[E0277]: cannot add `<T as SubEncoder>::ActualSize` to `<T as SubEncoder>::ActualSize`
142
--> $DIR/issue-54108.rs:23:17
153
|
@@ -18,16 +6,15 @@ LL | type Size = <Self as SubEncoder>::ActualSize;
186
|
197
= help: the trait `Add` is not implemented for `<T as SubEncoder>::ActualSize`
208
note: required by a bound in `Encoder::Size`
21-
--> $DIR/issue-54108.rs:8:16
9+
--> $DIR/issue-54108.rs:8:20
2210
|
2311
LL | type Size: Add<Output = Self::Size>;
24-
| ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Encoder::Size`
12+
| ^^^^^^^^^^^^^^^^^^^ required by this bound in `Encoder::Size`
2513
help: consider further restricting the associated type
2614
|
2715
LL | T: SubEncoder, <T as SubEncoder>::ActualSize: Add
2816
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2917

30-
error: aborting due to 2 previous errors
18+
error: aborting due to 1 previous error
3119

32-
Some errors have detailed explanations: E0271, E0277.
33-
For more information about an error, try `rustc --explain E0271`.
20+
For more information about this error, try `rustc --explain E0277`.

tests/ui/associated-types/issue-54108.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ where
2222
{
2323
type Size = <Self as SubEncoder>::ActualSize;
2424
//~^ ERROR: cannot add `<T as SubEncoder>::ActualSize` to `<T as SubEncoder>::ActualSize`
25-
//[next]~| ERROR type mismatch resolving `<<T as SubEncoder>::ActualSize as Add>::Output == <T as SubEncoder>::ActualSize`
2625

2726
fn foo(&self) -> Self::Size {
2827
self.bar() + self.bar()

tests/ui/traits/next-solver/coroutine.fail.stderr

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ LL | needs_coroutine(
66
LL | #[coroutine]
77
LL | / || {
88
LL | |
9-
LL | |
10-
LL | |
119
LL | | yield ();
1210
LL | | },
1311
| |_________^ the trait `Coroutine<A>` is not implemented for `{coroutine@$DIR/coroutine.rs:20:9: 20:11}`
@@ -18,47 +16,6 @@ note: required by a bound in `needs_coroutine`
1816
LL | fn needs_coroutine(_: impl Coroutine<A, Yield = B, Return = C>) {}
1917
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `needs_coroutine`
2018

21-
error[E0271]: type mismatch resolving `<{coroutine@$DIR/coroutine.rs:20:9: 20:11} as Coroutine<A>>::Yield == B`
22-
--> $DIR/coroutine.rs:20:9
23-
|
24-
LL | needs_coroutine(
25-
| --------------- required by a bound introduced by this call
26-
LL | #[coroutine]
27-
LL | / || {
28-
LL | |
29-
LL | |
30-
LL | |
31-
LL | | yield ();
32-
LL | | },
33-
| |_________^ types differ
34-
|
35-
note: required by a bound in `needs_coroutine`
36-
--> $DIR/coroutine.rs:14:41
37-
|
38-
LL | fn needs_coroutine(_: impl Coroutine<A, Yield = B, Return = C>) {}
39-
| ^^^^^^^^^ required by this bound in `needs_coroutine`
40-
41-
error[E0271]: type mismatch resolving `<{coroutine@$DIR/coroutine.rs:20:9: 20:11} as Coroutine<A>>::Return == C`
42-
--> $DIR/coroutine.rs:20:9
43-
|
44-
LL | needs_coroutine(
45-
| --------------- required by a bound introduced by this call
46-
LL | #[coroutine]
47-
LL | / || {
48-
LL | |
49-
LL | |
50-
LL | |
51-
LL | | yield ();
52-
LL | | },
53-
| |_________^ types differ
54-
|
55-
note: required by a bound in `needs_coroutine`
56-
--> $DIR/coroutine.rs:14:52
57-
|
58-
LL | fn needs_coroutine(_: impl Coroutine<A, Yield = B, Return = C>) {}
59-
| ^^^^^^^^^^ required by this bound in `needs_coroutine`
60-
61-
error: aborting due to 3 previous errors
19+
error: aborting due to 1 previous error
6220

63-
Some errors have detailed explanations: E0271, E0277.
64-
For more information about an error, try `rustc --explain E0271`.
21+
For more information about this error, try `rustc --explain E0277`.

tests/ui/traits/next-solver/coroutine.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ fn main() {
1919
#[coroutine]
2020
|| {
2121
//[fail]~^ ERROR Coroutine<A>` is not satisfied
22-
//[fail]~| ERROR as Coroutine<A>>::Yield == B`
23-
//[fail]~| ERROR as Coroutine<A>>::Return == C`
2422
yield ();
2523
},
2624
);

tests/ui/traits/next-solver/fn-trait.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,10 @@ fn main() {
1919
require_fn(f as fn() -> i32);
2020
require_fn(f as unsafe fn() -> i32);
2121
//~^ ERROR: expected a `Fn()` closure, found `unsafe fn() -> i32`
22-
//~| ERROR: type mismatch resolving `<unsafe fn() -> i32 as FnOnce<()>>::Output == i32`
2322
require_fn(g);
2423
//~^ ERROR: expected a `Fn()` closure, found `extern "C" fn() -> i32 {g}`
25-
//~| ERROR: type mismatch resolving `<extern "C" fn() -> i32 {g} as FnOnce<()>>::Output == i32`
2624
require_fn(g as extern "C" fn() -> i32);
2725
//~^ ERROR: expected a `Fn()` closure, found `extern "C" fn() -> i32`
28-
//~| ERROR: type mismatch resolving `<extern "C" fn() -> i32 as FnOnce<()>>::Output == i32`
2926
require_fn(h);
3027
//~^ ERROR: expected a `Fn()` closure, found `unsafe fn() -> i32 {h}`
31-
//~| ERROR: type mismatch resolving `<unsafe fn() -> i32 {h} as FnOnce<()>>::Output == i32`
3228
}

tests/ui/traits/next-solver/fn-trait.stderr

Lines changed: 5 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,8 @@ note: required by a bound in `require_fn`
1515
LL | fn require_fn(_: impl Fn() -> i32) {}
1616
| ^^^^^^^^^^^ required by this bound in `require_fn`
1717

18-
error[E0271]: type mismatch resolving `<unsafe fn() -> i32 as FnOnce<()>>::Output == i32`
19-
--> $DIR/fn-trait.rs:20:16
20-
|
21-
LL | require_fn(f as unsafe fn() -> i32);
22-
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^ types differ
23-
| |
24-
| required by a bound introduced by this call
25-
|
26-
note: required by a bound in `require_fn`
27-
--> $DIR/fn-trait.rs:3:31
28-
|
29-
LL | fn require_fn(_: impl Fn() -> i32) {}
30-
| ^^^ required by this bound in `require_fn`
31-
3218
error[E0277]: expected a `Fn()` closure, found `extern "C" fn() -> i32 {g}`
33-
--> $DIR/fn-trait.rs:23:16
19+
--> $DIR/fn-trait.rs:22:16
3420
|
3521
LL | require_fn(g);
3622
| ---------- ^ expected an `Fn()` closure, found `extern "C" fn() -> i32 {g}`
@@ -45,22 +31,8 @@ note: required by a bound in `require_fn`
4531
LL | fn require_fn(_: impl Fn() -> i32) {}
4632
| ^^^^^^^^^^^ required by this bound in `require_fn`
4733

48-
error[E0271]: type mismatch resolving `<extern "C" fn() -> i32 {g} as FnOnce<()>>::Output == i32`
49-
--> $DIR/fn-trait.rs:23:16
50-
|
51-
LL | require_fn(g);
52-
| ---------- ^ types differ
53-
| |
54-
| required by a bound introduced by this call
55-
|
56-
note: required by a bound in `require_fn`
57-
--> $DIR/fn-trait.rs:3:31
58-
|
59-
LL | fn require_fn(_: impl Fn() -> i32) {}
60-
| ^^^ required by this bound in `require_fn`
61-
6234
error[E0277]: expected a `Fn()` closure, found `extern "C" fn() -> i32`
63-
--> $DIR/fn-trait.rs:26:16
35+
--> $DIR/fn-trait.rs:24:16
6436
|
6537
LL | require_fn(g as extern "C" fn() -> i32);
6638
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected an `Fn()` closure, found `extern "C" fn() -> i32`
@@ -75,22 +47,8 @@ note: required by a bound in `require_fn`
7547
LL | fn require_fn(_: impl Fn() -> i32) {}
7648
| ^^^^^^^^^^^ required by this bound in `require_fn`
7749

78-
error[E0271]: type mismatch resolving `<extern "C" fn() -> i32 as FnOnce<()>>::Output == i32`
79-
--> $DIR/fn-trait.rs:26:16
80-
|
81-
LL | require_fn(g as extern "C" fn() -> i32);
82-
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ types differ
83-
| |
84-
| required by a bound introduced by this call
85-
|
86-
note: required by a bound in `require_fn`
87-
--> $DIR/fn-trait.rs:3:31
88-
|
89-
LL | fn require_fn(_: impl Fn() -> i32) {}
90-
| ^^^ required by this bound in `require_fn`
91-
9250
error[E0277]: expected a `Fn()` closure, found `unsafe fn() -> i32 {h}`
93-
--> $DIR/fn-trait.rs:29:16
51+
--> $DIR/fn-trait.rs:26:16
9452
|
9553
LL | require_fn(h);
9654
| ---------- ^ call the function in a closure: `|| unsafe { /* code */ }`
@@ -106,21 +64,6 @@ note: required by a bound in `require_fn`
10664
LL | fn require_fn(_: impl Fn() -> i32) {}
10765
| ^^^^^^^^^^^ required by this bound in `require_fn`
10866

109-
error[E0271]: type mismatch resolving `<unsafe fn() -> i32 {h} as FnOnce<()>>::Output == i32`
110-
--> $DIR/fn-trait.rs:29:16
111-
|
112-
LL | require_fn(h);
113-
| ---------- ^ types differ
114-
| |
115-
| required by a bound introduced by this call
116-
|
117-
note: required by a bound in `require_fn`
118-
--> $DIR/fn-trait.rs:3:31
119-
|
120-
LL | fn require_fn(_: impl Fn() -> i32) {}
121-
| ^^^ required by this bound in `require_fn`
122-
123-
error: aborting due to 8 previous errors
67+
error: aborting due to 4 previous errors
12468

125-
Some errors have detailed explanations: E0271, E0277.
126-
For more information about an error, try `rustc --explain E0271`.
69+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)