Skip to content

Commit f008553

Browse files
better error message for normalizes-to ambiguities
1 parent 5d3b87f commit f008553

File tree

7 files changed

+26
-10
lines changed

7 files changed

+26
-10
lines changed

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

+16
Original file line numberDiff line numberDiff line change
@@ -2700,6 +2700,22 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
27002700
),
27012701
);
27022702
}
2703+
2704+
ty::PredicateKind::NormalizesTo(ty::NormalizesTo { alias, term })
2705+
if term.is_infer() =>
2706+
{
2707+
if let Some(e) = self.tainted_by_errors() {
2708+
return e;
2709+
}
2710+
struct_span_code_err!(
2711+
self.dcx(),
2712+
span,
2713+
E0284,
2714+
"type annotations needed: cannot normalize `{alias}`",
2715+
)
2716+
.with_span_label(span, format!("cannot normalize `{alias}`"))
2717+
}
2718+
27032719
_ => {
27042720
if let Some(e) = self.tainted_by_errors() {
27052721
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 normalizes-to _`
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 normalizes-to _`
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 normalizes-to _`
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 normalizes-to _`
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 normalizes-to _`
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/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 `X::{constant#0} normalizes-to _`
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 `X::{constant#0} normalizes-to _`
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

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ 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 normalizes-to _`
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 normalizes-to _`
17+
| ^^^^^^^^^ cannot normalize `<T as Default>::Id`
1818

1919
error[E0284]: type annotations needed: cannot satisfy `<T as Default>::Id normalizes-to T`
2020
--> $DIR/specialization-transmute.rs:17:9

0 commit comments

Comments
 (0)