Skip to content

Commit 2dba9c8

Browse files
Walk into alias-eq nested goals even if normalization fails
1 parent 8c4db85 commit 2dba9c8

14 files changed

+81
-22
lines changed

compiler/rustc_trait_selection/src/solve/alias_relate.rs

+6
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
4848
rhs
4949
};
5050

51+
// Add a `make_canonical_response` probe step so that we treat this as
52+
// a candidate, even if `try_evaluate_added_goals` bails due to an error.
53+
// It's `Certainty::AMBIGUOUS` because this candidate is not "finished",
54+
// since equating the normalized terms will lead to additional constraints.
55+
self.inspect.make_canonical_response(Certainty::AMBIGUOUS);
56+
5157
// Apply the constraints.
5258
self.try_evaluate_added_goals()?;
5359
let lhs = self.resolve_vars_if_possible(lhs);

compiler/rustc_trait_selection/src/solve/fulfill.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,8 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
407407
polarity: ty::PredicatePolarity::Positive,
408408
}))
409409
}
410-
ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(_)) => {
411-
ChildMode::WellFormedObligation
412-
}
410+
ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(_))
411+
| ty::PredicateKind::AliasRelate(..) => ChildMode::PassThrough,
413412
_ => {
414413
return ControlFlow::Break(self.obligation.clone());
415414
}
@@ -443,7 +442,7 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
443442
(_, GoalSource::InstantiateHigherRanked) => {
444443
obligation = self.obligation.clone();
445444
}
446-
(ChildMode::WellFormedObligation, _) => {
445+
(ChildMode::PassThrough, _) => {
447446
obligation = make_obligation(self.obligation.cause.clone());
448447
}
449448
}
@@ -474,7 +473,7 @@ enum ChildMode<'tcx> {
474473
// Skip trying to derive an `ObligationCause` from this obligation, and
475474
// report *all* sub-obligations as if they came directly from the parent
476475
// obligation.
477-
WellFormedObligation,
476+
PassThrough,
478477
}
479478

480479
fn derive_cause<'tcx>(

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_infer::infer::{DefineOpaqueTypes, InferCtxt, InferOk};
1515
use rustc_macros::extension;
1616
use rustc_middle::traits::query::NoSolution;
1717
use rustc_middle::traits::solve::{inspect, QueryResult};
18-
use rustc_middle::traits::solve::{Certainty, Goal};
18+
use rustc_middle::traits::solve::{Certainty, Goal, MaybeCause};
1919
use rustc_middle::traits::ObligationCause;
2020
use rustc_middle::ty::{TyCtxt, TypeFoldable};
2121
use rustc_middle::{bug, ty};
@@ -291,7 +291,10 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
291291
steps.push(step)
292292
}
293293
inspect::ProbeStep::MakeCanonicalResponse { shallow_certainty: c } => {
294-
assert_eq!(shallow_certainty.replace(c), None);
294+
assert!(matches!(
295+
shallow_certainty.replace(c),
296+
None | Some(Certainty::Maybe(MaybeCause::Ambiguity))
297+
));
295298
}
296299
inspect::ProbeStep::NestedProbe(ref probe) => {
297300
match probe.kind {

tests/ui/coherence/indirect-impl-for-trait-obj-coherence.next.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0284]: type annotations needed: cannot satisfy `<dyn Object<U, Output = T> as Object<U>>::Output == T`
1+
error[E0284]: type annotations needed: cannot satisfy `<dyn Object<U, Output = T> as Object<U>>::Output normalizes-to _`
22
--> $DIR/indirect-impl-for-trait-obj-coherence.rs:25:41
33
|
44
LL | foo::<dyn Object<U, Output = T>, U>(x)
5-
| ^ cannot satisfy `<dyn Object<U, Output = T> as Object<U>>::Output == T`
5+
| ^ cannot satisfy `<dyn Object<U, Output = T> as Object<U>>::Output normalizes-to _`
66

77
error: aborting due to 1 previous error
88

tests/ui/coherence/indirect-impl-for-trait-obj-coherence.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn foo<T: ?Sized, U>(x: <T as Object<U>>::Output) -> U {
2323
#[allow(dead_code)]
2424
fn transmute<T, U>(x: T) -> U {
2525
foo::<dyn Object<U, Output = T>, U>(x)
26-
//[next]~^ ERROR type annotations needed: cannot satisfy `<dyn Object<U, Output = T> as Object<U>>::Output == T`
26+
//[next]~^ ERROR type annotations needed: cannot satisfy `<dyn Object<U, Output = T> as Object<U>>::Output normalizes-to _`
2727
}
2828

2929
fn main() {}

tests/ui/coherence/occurs-check/associated-type.next.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ LL | | for<'a> *const T: ToUnit<'a>,
1616
|
1717
= note: this behavior recently changed as a result of a bug fix; see rust-lang/rust#56105 for details
1818

19-
error[E0284]: type annotations needed: cannot satisfy `<for<'a> fn(&'a (), ()) as Overlap<for<'a> fn(&'a (), ())>>::Assoc == usize`
19+
error[E0284]: type annotations needed: cannot satisfy `<for<'a> fn(&'a (), ()) as Overlap<for<'a> fn(&'a (), ())>>::Assoc normalizes-to _`
2020
--> $DIR/associated-type.rs:44:59
2121
|
2222
LL | foo::<for<'a> fn(&'a (), ()), for<'a> fn(&'a (), ())>(3usize);
23-
| ^^^^^^ cannot satisfy `<for<'a> fn(&'a (), ()) as Overlap<for<'a> fn(&'a (), ())>>::Assoc == usize`
23+
| ^^^^^^ cannot satisfy `<for<'a> fn(&'a (), ()) as Overlap<for<'a> fn(&'a (), ())>>::Assoc normalizes-to _`
2424

2525
error: aborting due to 2 previous errors
2626

tests/ui/diagnostic_namespace/do_not_recommend/as_expression.next.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ LL | SelectInt.check("bar");
2525
= help: the trait `AsExpression<Text>` is implemented for `&str`
2626
= help: for that trait implementation, expected `Text`, found `Integer`
2727

28-
error[E0271]: type mismatch resolving `<&str as AsExpression<<SelectInt as Expression>::SqlType>>::Expression == _`
28+
error[E0271]: type mismatch resolving `<SelectInt as Expression>::SqlType == Text`
2929
--> $DIR/as_expression.rs:57:5
3030
|
3131
LL | SelectInt.check("bar");

tests/ui/traits/negative-bounds/opaque-type-unsatisfied-bound.rs

+1
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ fn weird1() -> impl !Sized + Sized {}
1818
//~^ ERROR type mismatch resolving `impl !Sized + Sized == ()`
1919
fn weird2() -> impl !Sized {}
2020
//~^ ERROR type mismatch resolving `impl !Sized == ()`
21+
//~| ERROR the size for values of type `impl !Sized` cannot be known at compilation time

tests/ui/traits/negative-bounds/opaque-type-unsatisfied-bound.stderr

+10-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ error[E0271]: type mismatch resolving `impl !Sized == ()`
1616
LL | fn weird2() -> impl !Sized {}
1717
| ^^^^^^^^^^^ types differ
1818

19+
error[E0277]: the size for values of type `impl !Sized` cannot be known at compilation time
20+
--> $DIR/opaque-type-unsatisfied-bound.rs:19:16
21+
|
22+
LL | fn weird2() -> impl !Sized {}
23+
| ^^^^^^^^^^^ doesn't have a size known at compile-time
24+
|
25+
= help: the trait `Sized` is not implemented for `impl !Sized`
26+
= note: the return type of a function must have a statically known size
27+
1928
error[E0277]: the trait bound `impl !Trait: Trait` is not satisfied
2029
--> $DIR/opaque-type-unsatisfied-bound.rs:12:13
2130
|
@@ -30,7 +39,7 @@ note: required by a bound in `consume`
3039
LL | fn consume(_: impl Trait) {}
3140
| ^^^^^ required by this bound in `consume`
3241

33-
error: aborting due to 4 previous errors
42+
error: aborting due to 5 previous errors
3443

3544
Some errors have detailed explanations: E0271, E0277.
3645
For more information about an error, try `rustc --explain E0271`.

tests/ui/traits/next-solver/canonical/const-region-infer-to-static-in-binder.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0284]: type annotations needed: cannot satisfy `{ || {} } == _`
1+
error[E0284]: type annotations needed: cannot satisfy `X::{constant#0} normalizes-to _`
22
--> $DIR/const-region-infer-to-static-in-binder.rs:4:10
33
|
44
LL | struct X<const FN: fn() = { || {} }>;
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot satisfy `{ || {} } == _`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot satisfy `X::{constant#0} normalizes-to _`
66

77
error: using function pointers as const generic parameters is forbidden
88
--> $DIR/const-region-infer-to-static-in-binder.rs:4:20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
trait Trait {
2+
type Assoc;
3+
}
4+
5+
fn test_poly<T>() {
6+
let x: <T as Trait>::Assoc = ();
7+
//~^ ERROR the trait bound `T: Trait` is not satisfied
8+
}
9+
10+
fn test() {
11+
let x: <i32 as Trait>::Assoc = ();
12+
//~^ ERROR the trait bound `i32: Trait` is not satisfied
13+
}
14+
15+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error[E0277]: the trait bound `T: Trait` is not satisfied
2+
--> $DIR/projection-trait-ref.rs:6:13
3+
|
4+
LL | let x: <T as Trait>::Assoc = ();
5+
| ^ the trait `Trait` is not implemented for `T`
6+
|
7+
help: consider restricting type parameter `T`
8+
|
9+
LL | fn test_poly<T: Trait>() {
10+
| +++++++
11+
12+
error[E0277]: the trait bound `i32: Trait` is not satisfied
13+
--> $DIR/projection-trait-ref.rs:11:13
14+
|
15+
LL | let x: <i32 as Trait>::Assoc = ();
16+
| ^^^ the trait `Trait` is not implemented for `i32`
17+
|
18+
help: this trait has no implementations, consider adding one
19+
--> $DIR/projection-trait-ref.rs:1:1
20+
|
21+
LL | trait Trait {
22+
| ^^^^^^^^^^^
23+
24+
error: aborting due to 2 previous errors
25+
26+
For more information about this error, try `rustc --explain E0277`.

tests/ui/traits/next-solver/specialization-transmute.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ LL | #![feature(specialization)]
1010

1111
error: cannot normalize `<T as Default>::Id: '_`
1212

13-
error[E0284]: type annotations needed: cannot satisfy `<T as Default>::Id == _`
13+
error[E0284]: type annotations needed: cannot satisfy `<T as Default>::Id normalizes-to _`
1414
--> $DIR/specialization-transmute.rs:15:23
1515
|
1616
LL | fn intu(&self) -> &Self::Id {
17-
| ^^^^^^^^^ cannot satisfy `<T as Default>::Id == _`
17+
| ^^^^^^^^^ cannot satisfy `<T as Default>::Id normalizes-to _`
1818

19-
error[E0284]: type annotations needed: cannot satisfy `T <: <T as Default>::Id`
19+
error[E0284]: type annotations needed: cannot satisfy `<T as Default>::Id normalizes-to T`
2020
--> $DIR/specialization-transmute.rs:17:9
2121
|
2222
LL | self
23-
| ^^^^ cannot satisfy `T <: <T as Default>::Id`
23+
| ^^^^ cannot satisfy `<T as Default>::Id normalizes-to T`
2424

2525
error[E0284]: type annotations needed: cannot satisfy `<u8 as Default>::Id == Option<NonZero<u8>>`
2626
--> $DIR/specialization-transmute.rs:28:13

tests/ui/type-alias-impl-trait/issue-84660-unsoundness.next.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
error[E0284]: type annotations needed: cannot satisfy `<Out as Trait<Bar, In>>::Out == ()`
1+
error[E0284]: type annotations needed: cannot satisfy `Bar == _`
22
--> $DIR/issue-84660-unsoundness.rs:22:37
33
|
44
LL | fn convert(_i: In) -> Self::Out {
55
| _____________________________________^
66
LL | |
77
LL | | unreachable!();
88
LL | | }
9-
| |_____^ cannot satisfy `<Out as Trait<Bar, In>>::Out == ()`
9+
| |_____^ cannot satisfy `Bar == _`
1010

1111
error[E0119]: conflicting implementations of trait `Trait<Bar, _>`
1212
--> $DIR/issue-84660-unsoundness.rs:28:1

0 commit comments

Comments
 (0)