Skip to content

Commit e4d816e

Browse files
committed
add tests for ICE: 'broken MIR: bad assignment: NoSolution' on trait with default method and no impls
Fixes rust-lang#109869
1 parent e800b99 commit e4d816e

6 files changed

+103
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// ICE 'broken MIR: bad assignment: NoSolution'
2+
// on trait with default method and no impls
3+
// issue: rust-lang/rust#109869
4+
5+
type Spanned<T> = (T, ());
6+
7+
trait Span<T> {}
8+
9+
impl<T> Span<T> for (T, ()) {}
10+
11+
impl<F, T: From<F>> From<Spanned<F>> for dyn Span<T>
12+
where
13+
Self: Sized
14+
{
15+
fn from((from, ()): Spanned<F>) -> Self {
16+
(T::from(from), ())
17+
//~^ ERROR mismatched types
18+
}
19+
}
20+
21+
pub fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/ice-trait-with-default-method-but-no-impl-broken-mir-109869-1.rs:16:9
3+
|
4+
LL | fn from((from, ()): Spanned<F>) -> Self {
5+
| ---- expected `(dyn Span<T> + 'static)` because of return type
6+
LL | (T::from(from), ())
7+
| ^^^^^^^^^^^^^^^^^^^ expected `dyn Span`, found `(T, ())`
8+
|
9+
= note: expected trait object `(dyn Span<T> + 'static)`
10+
found tuple `(T, ())`
11+
= help: `(T, ())` implements `Span` so you could box the found value and coerce it to the trait object `Box<dyn Span>`, you will have to change the expected type as well
12+
help: call `Into::into` on this expression to convert `(T, ())` into `(dyn Span<T> + 'static)`
13+
|
14+
LL | (T::from(from), ()).into()
15+
| +++++++
16+
17+
error: aborting due to 1 previous error
18+
19+
For more information about this error, try `rustc --explain E0308`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// ICE 'broken MIR: bad assignment: NoSolution'
2+
// on trait with default method and no impls
3+
// issue: rust-lang/rust#109869
4+
5+
trait Empty<T> {}
6+
7+
impl<T> Default for dyn Empty<T>
8+
where
9+
Self: Sized,
10+
{
11+
fn default() -> Self {
12+
()
13+
//~^ ERROR mismatched types
14+
}
15+
}
16+
17+
pub fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/ice-trait-with-default-method-but-no-impl-broken-mir-109869-2.rs:12:9
3+
|
4+
LL | fn default() -> Self {
5+
| ---- expected `(dyn Empty<T> + 'static)` because of return type
6+
LL | ()
7+
| ^^ expected `dyn Empty`, found `()`
8+
|
9+
= note: expected trait object `(dyn Empty<T> + 'static)`
10+
found unit type `()`
11+
12+
error: aborting due to 1 previous error
13+
14+
For more information about this error, try `rustc --explain E0308`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// ICE 'broken MIR: bad assignment: NoSolution'
2+
// on trait with default method and no impls
3+
// issue: rust-lang/rust#109869
4+
5+
#![feature(trivial_bounds)]
6+
trait Empty {}
7+
8+
impl Default for dyn Empty
9+
where
10+
Self: Sized,
11+
{
12+
fn default() -> Self {
13+
()
14+
//~^ ERROR mismatched types
15+
}
16+
}
17+
18+
pub fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/ice-trait-with-default-method-but-no-impl-broken-mir-109869-trivial-bounds.rs:13:9
3+
|
4+
LL | fn default() -> Self {
5+
| ---- expected `(dyn Empty + 'static)` because of return type
6+
LL | ()
7+
| ^^ expected `dyn Empty`, found `()`
8+
|
9+
= note: expected trait object `(dyn Empty + 'static)`
10+
found unit type `()`
11+
12+
error: aborting due to 1 previous error
13+
14+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)