Skip to content

Commit 99e2d07

Browse files
authored
Unrolled build for rust-lang#125688
Rollup merge of rust-lang#125688 - compiler-errors:alias-reporting, r=lcnr Walk into alias-eq nested goals even if normalization fails Somewhat broken due to the fact that we don't handle aliases well, nor do we handle ambiguities well. Still want to put up this incremental piece, since it improves type errors for projections whose trait refs are not satisfied. r? lcnr
2 parents f6b4b71 + 44040a0 commit 99e2d07

23 files changed

+114
-40
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

+6-5
Original file line numberDiff line numberDiff line change
@@ -460,9 +460,10 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
460460
polarity: ty::PredicatePolarity::Positive,
461461
}))
462462
}
463-
ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(_)) => {
464-
ChildMode::WellFormedObligation
465-
}
463+
ty::PredicateKind::Clause(
464+
ty::ClauseKind::WellFormed(_) | ty::ClauseKind::Projection(..),
465+
)
466+
| ty::PredicateKind::AliasRelate(..) => ChildMode::PassThrough,
466467
_ => {
467468
return ControlFlow::Break(self.obligation.clone());
468469
}
@@ -496,7 +497,7 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
496497
(_, GoalSource::InstantiateHigherRanked) => {
497498
obligation = self.obligation.clone();
498499
}
499-
(ChildMode::WellFormedObligation, _) => {
500+
(ChildMode::PassThrough, _) => {
500501
obligation = make_obligation(self.obligation.cause.clone());
501502
}
502503
}
@@ -527,7 +528,7 @@ enum ChildMode<'tcx> {
527528
// Skip trying to derive an `ObligationCause` from this obligation, and
528529
// report *all* sub-obligations as if they came directly from the parent
529530
// obligation.
530-
WellFormedObligation,
531+
PassThrough,
531532
}
532533

533534
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 {

compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs

+16
Original file line numberDiff line numberDiff line change
@@ -2705,6 +2705,22 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
27052705
),
27062706
);
27072707
}
2708+
2709+
ty::PredicateKind::NormalizesTo(ty::NormalizesTo { alias, term })
2710+
if term.is_infer() =>
2711+
{
2712+
if let Some(e) = self.tainted_by_errors() {
2713+
return e;
2714+
}
2715+
struct_span_code_err!(
2716+
self.dcx(),
2717+
span,
2718+
E0284,
2719+
"type annotations needed: cannot normalize `{alias}`",
2720+
)
2721+
.with_span_label(span, format!("cannot normalize `{alias}`"))
2722+
}
2723+
27082724
_ => {
27092725
if let Some(e) = self.tainted_by_errors() {
27102726
return e;

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 normalize `<dyn Object<U, Output = T> as Object<U>>::Output`
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 normalize `<dyn Object<U, Output = T> as Object<U>>::Output`
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 normalize `<dyn Object<U, Output = T> as Object<U>>::Output`
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 normalize `<for<'a> fn(&'a (), ()) as Overlap<for<'a> fn(&'a (), ())>>::Assoc`
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 normalize `<for<'a> fn(&'a (), ()) as Overlap<for<'a> fn(&'a (), ())>>::Assoc`
2424

2525
error: aborting due to 2 previous errors
2626

tests/ui/coherence/occurs-check/associated-type.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ fn foo<T: Overlap<U>, U>(x: T::Assoc) -> T::Assoc {
4242

4343
fn main() {
4444
foo::<for<'a> fn(&'a (), ()), for<'a> fn(&'a (), ())>(3usize);
45-
//[next]~^ ERROR: cannot satisfy
45+
//[next]~^ ERROR: cannot normalize
4646
}

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/higher-ranked/trait-bounds/rigid-equate-projections-in-higher-ranked-fn-signature.next.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0284]: type annotations needed: cannot satisfy `for<'a> <_ as Trait<'a>>::Assoc <: <T as Trait<'_>>::Assoc`
1+
error[E0284]: type annotations needed: cannot satisfy `for<'a> <_ as Trait<'a>>::Assoc normalizes-to <T as Trait<'_>>::Assoc`
22
--> $DIR/rigid-equate-projections-in-higher-ranked-fn-signature.rs:27:50
33
|
44
LL | let _: for<'a> fn(<_ as Trait<'a>>::Assoc) = foo::<T>();
5-
| ^^^^^^^^^^ cannot satisfy `for<'a> <_ as Trait<'a>>::Assoc <: <T as Trait<'_>>::Assoc`
5+
| ^^^^^^^^^^ cannot satisfy `for<'a> <_ as Trait<'a>>::Assoc normalizes-to <T as Trait<'_>>::Assoc`
66

77
error: aborting due to 1 previous error
88

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 normalize `X::{constant#0}`
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 normalize `X::{constant#0}`
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,17 @@
1+
//@ compile-flags: -Znext-solver
2+
3+
trait Trait {
4+
type Assoc;
5+
}
6+
7+
fn test_poly<T>() {
8+
let x: <T as Trait>::Assoc = ();
9+
//~^ ERROR the trait bound `T: Trait` is not satisfied
10+
}
11+
12+
fn test() {
13+
let x: <i32 as Trait>::Assoc = ();
14+
//~^ ERROR the trait bound `i32: Trait` is not satisfied
15+
}
16+
17+
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:8:12
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:13:12
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:3: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/env-shadows-impls/param-candidate-shadows-project.stderr

+1-6
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,8 @@ error[E0271]: type mismatch resolving `<T as Foo>::Assoc == i32`
22
--> $DIR/param-candidate-shadows-project.rs:27:19
33
|
44
LL | require_bar::<T>();
5-
| ^ type mismatch resolving `<T as Foo>::Assoc == i32`
5+
| ^ types differ
66
|
7-
note: types differ
8-
--> $DIR/param-candidate-shadows-project.rs:10:18
9-
|
10-
LL | type Assoc = i32;
11-
| ^^^
127
note: required for `T` to implement `Bar`
138
--> $DIR/param-candidate-shadows-project.rs:13:9
149
|

tests/ui/traits/next-solver/normalize/two-projection-param-candidates-are-ambiguous.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn needs_bar<T: Bar>() {}
2424

2525
fn foo<T: Foo<Assoc = i32> + Foo<Assoc = u32>>() {
2626
needs_bar::<T>();
27-
//~^ ERROR type annotations needed: cannot satisfy `<T as Foo>::Assoc == i32`
27+
//~^ ERROR type annotations needed: cannot normalize
2828
}
2929

3030
fn main() {}

tests/ui/traits/next-solver/normalize/two-projection-param-candidates-are-ambiguous.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0284]: type annotations needed: cannot satisfy `<T as Foo>::Assoc == i32`
1+
error[E0284]: type annotations needed: cannot normalize `<T as Foo>::Assoc`
22
--> $DIR/two-projection-param-candidates-are-ambiguous.rs:26:17
33
|
44
LL | needs_bar::<T>();
5-
| ^ cannot satisfy `<T as Foo>::Assoc == i32`
5+
| ^ cannot normalize `<T as Foo>::Assoc`
66
|
77
note: required for `T` to implement `Bar`
88
--> $DIR/two-projection-param-candidates-are-ambiguous.rs:21:9

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ 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 normalize `<T as Default>::Id`
1414
--> $DIR/specialization-transmute.rs:15:23
1515
|
1616
LL | fn intu(&self) -> &Self::Id {
17-
| ^^^^^^^^^ cannot satisfy `<T as Default>::Id == _`
17+
| ^^^^^^^^^ cannot normalize `<T as Default>::Id`
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

25-
error[E0284]: type annotations needed: cannot satisfy `<u8 as Default>::Id == Option<NonZero<u8>>`
25+
error[E0284]: type annotations needed: cannot satisfy `<u8 as Default>::Id normalizes-to Option<NonZero<u8>>`
2626
--> $DIR/specialization-transmute.rs:28:13
2727
|
2828
LL | let s = transmute::<u8, Option<NonZero<u8>>>(0);
29-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot satisfy `<u8 as Default>::Id == Option<NonZero<u8>>`
29+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot satisfy `<u8 as Default>::Id normalizes-to Option<NonZero<u8>>`
3030
|
3131
note: required by a bound in `transmute`
3232
--> $DIR/specialization-transmute.rs:21:25

tests/ui/traits/next-solver/specialization-unconstrained.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ fn test<T: Default<Id = U>, U>() {}
1818

1919
fn main() {
2020
test::<u32, ()>();
21-
//~^ ERROR cannot satisfy `<u32 as Default>::Id == ()`
21+
//~^ ERROR cannot satisfy `<u32 as Default>::Id normalizes-to ()`
2222
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ LL | #![feature(specialization)]
88
= help: consider using `min_specialization` instead, which is more stable and complete
99
= note: `#[warn(incomplete_features)]` on by default
1010

11-
error[E0284]: type annotations needed: cannot satisfy `<u32 as Default>::Id == ()`
11+
error[E0284]: type annotations needed: cannot satisfy `<u32 as Default>::Id normalizes-to ()`
1212
--> $DIR/specialization-unconstrained.rs:20:5
1313
|
1414
LL | test::<u32, ()>();
15-
| ^^^^^^^^^^^^^^^^^ cannot satisfy `<u32 as Default>::Id == ()`
15+
| ^^^^^^^^^^^^^^^^^ cannot satisfy `<u32 as Default>::Id normalizes-to ()`
1616
|
1717
note: required by a bound in `test`
1818
--> $DIR/specialization-unconstrained.rs:17:20

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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 {
@@ -7,7 +7,7 @@ LL | |
77
LL | |
88
LL | | unreachable!();
99
LL | | }
10-
| |_____^ cannot satisfy `<Out as Trait<Bar, In>>::Out == ()`
10+
| |_____^ cannot satisfy `Bar == _`
1111

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

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ trait Trait<T, In> {
2020
impl<In, Out> Trait<Bar, In> for Out {
2121
type Out = Out;
2222
fn convert(_i: In) -> Self::Out {
23-
//[next]~^ ERROR: cannot satisfy `<Out as Trait<Bar, In>>::Out == ()`
23+
//[next]~^ ERROR: cannot satisfy `Bar == _`
2424
//[current]~^^ ERROR: item does not constrain `Bar::{opaque#0}`, but has it in its signature
2525
unreachable!();
2626
}

0 commit comments

Comments
 (0)