Skip to content

Commit a1fdea2

Browse files
authored
Rollup merge of #100514 - compiler-errors:issue-100191, r=spastorino
Delay span bug when failing to normalize negative coherence impl subject due to other malformed impls Fixes #100191 r? ``@spastorino``
2 parents e369ec8 + c436930 commit a1fdea2

File tree

5 files changed

+66
-1
lines changed

5 files changed

+66
-1
lines changed

compiler/rustc_trait_selection/src/traits/coherence.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,13 @@ fn negative_impl<'cx, 'tcx>(
307307
tcx.impl_subject(impl1_def_id),
308308
) {
309309
Ok(s) => s,
310-
Err(err) => bug!("failed to fully normalize {:?}: {:?}", impl1_def_id, err),
310+
Err(err) => {
311+
tcx.sess.delay_span_bug(
312+
tcx.def_span(impl1_def_id),
313+
format!("failed to fully normalize {:?}: {:?}", impl1_def_id, err),
314+
);
315+
return false;
316+
}
311317
};
312318

313319
// Attempt to prove that impl2 applies, given all of the above.
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//~ ERROR overflow evaluating the requirement `T: Trait<_>`
2+
3+
#![feature(specialization, with_negative_coherence)]
4+
#![allow(incomplete_features)]
5+
6+
pub trait Trait<T> {}
7+
8+
default impl<T, U> Trait<T> for U {}
9+
10+
impl<T> Trait<<T as Iterator>::Item> for T {}
11+
12+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0275]: overflow evaluating the requirement `T: Trait<_>`
2+
|
3+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_100191_2`)
4+
note: required because of the requirements on the impl of `Trait<_>` for `T`
5+
--> $DIR/issue-100191-2.rs:8:20
6+
|
7+
LL | default impl<T, U> Trait<T> for U {}
8+
| ^^^^^^^^ ^
9+
= note: 128 redundant requirements hidden
10+
= note: required because of the requirements on the impl of `Trait<_>` for `T`
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0275`.

src/test/ui/coherence/issue-100191.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#![crate_type = "lib"]
2+
#![feature(specialization, with_negative_coherence)]
3+
#![allow(incomplete_features)]
4+
5+
trait X {}
6+
trait Y: X {}
7+
trait Z {
8+
type Assoc: Y;
9+
}
10+
struct A<T>(T);
11+
12+
impl<T> Y for T where T: X {}
13+
impl<T: X> Z for A<T> {
14+
type Assoc = T;
15+
}
16+
17+
// this impl is invalid, but causes an ICE anyway
18+
impl<T> From<<A<T> as Z>::Assoc> for T {}
19+
//~^ ERROR type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
20+
21+
fn main() {}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
2+
--> $DIR/issue-100191.rs:18:6
3+
|
4+
LL | impl<T> From<<A<T> as Z>::Assoc> for T {}
5+
| ^ type parameter `T` must be used as the type parameter for some local type
6+
|
7+
= note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local
8+
= note: only traits defined in the current crate can be implemented for a type parameter
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0210`.

0 commit comments

Comments
 (0)