Skip to content

Commit 0919d07

Browse files
Don't ICE when auto trait has assoc ty in old solver
1 parent 2ccafed commit 0919d07

File tree

6 files changed

+103
-23
lines changed

6 files changed

+103
-23
lines changed

compiler/rustc_trait_selection/src/traits/project.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,12 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
12021202
false
12031203
}
12041204
}
1205+
} else if tcx.trait_is_auto(trait_ref.def_id) {
1206+
tcx.dcx().span_delayed_bug(
1207+
tcx.def_span(obligation.predicate.def_id),
1208+
"associated types not allowed on auto traits",
1209+
);
1210+
false
12051211
} else {
12061212
bug!("unexpected builtin trait with associated type: {trait_ref:?}")
12071213
}

tests/crashes/117829-2.rs

-14
This file was deleted.

tests/crashes/117829.rs

-9
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
error[E0380]: auto traits cannot have associated items
2+
--> $DIR/assoc-ty.rs:10:10
3+
|
4+
LL | auto trait Trait {
5+
| ----- auto traits cannot have associated items
6+
LL |
7+
LL | type Output;
8+
| -----^^^^^^- help: remove these associated items
9+
10+
error[E0658]: auto traits are experimental and possibly buggy
11+
--> $DIR/assoc-ty.rs:8:1
12+
|
13+
LL | / auto trait Trait {
14+
LL | |
15+
LL | | type Output;
16+
LL | |
17+
LL | | }
18+
| |_^
19+
|
20+
= note: see issue #13231 <https://github.com/rust-lang/rust/issues/13231> for more information
21+
= help: add `#![feature(auto_traits)]` to the crate attributes to enable
22+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
23+
24+
error[E0308]: mismatched types
25+
--> $DIR/assoc-ty.rs:15:36
26+
|
27+
LL | let _: <() as Trait>::Output = ();
28+
| --------------------- ^^ expected associated type, found `()`
29+
| |
30+
| expected due to this
31+
|
32+
= note: expected associated type `<() as Trait>::Output`
33+
found unit type `()`
34+
= help: consider constraining the associated type `<() as Trait>::Output` to `()` or calling a method that returns `<() as Trait>::Output`
35+
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
36+
37+
error: aborting due to 3 previous errors
38+
39+
Some errors have detailed explanations: E0308, E0380, E0658.
40+
For more information about an error, try `rustc --explain E0308`.
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
error[E0380]: auto traits cannot have associated items
2+
--> $DIR/assoc-ty.rs:10:10
3+
|
4+
LL | auto trait Trait {
5+
| ----- auto traits cannot have associated items
6+
LL |
7+
LL | type Output;
8+
| -----^^^^^^- help: remove these associated items
9+
10+
error[E0658]: auto traits are experimental and possibly buggy
11+
--> $DIR/assoc-ty.rs:8:1
12+
|
13+
LL | / auto trait Trait {
14+
LL | |
15+
LL | | type Output;
16+
LL | |
17+
LL | | }
18+
| |_^
19+
|
20+
= note: see issue #13231 <https://github.com/rust-lang/rust/issues/13231> for more information
21+
= help: add `#![feature(auto_traits)]` to the crate attributes to enable
22+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
23+
24+
error[E0308]: mismatched types
25+
--> $DIR/assoc-ty.rs:15:36
26+
|
27+
LL | let _: <() as Trait>::Output = ();
28+
| --------------------- ^^ types differ
29+
| |
30+
| expected due to this
31+
|
32+
= note: expected associated type `<() as Trait>::Output`
33+
found unit type `()`
34+
= help: consider constraining the associated type `<() as Trait>::Output` to `()` or calling a method that returns `<() as Trait>::Output`
35+
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
36+
37+
error: aborting due to 3 previous errors
38+
39+
Some errors have detailed explanations: E0308, E0380, E0658.
40+
For more information about an error, try `rustc --explain E0308`.

tests/ui/auto-traits/assoc-ty.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@ revisions: current next
2+
//@[next] compile-flags: -Znext-solver
3+
//@ ignore-compare-mode-next-solver (explicit revisions)
4+
5+
// Tests that projection doesn't explode if we accidentally
6+
// put an associated type on an auto trait.
7+
8+
auto trait Trait {
9+
//~^ ERROR auto traits are experimental and possibly buggy
10+
type Output;
11+
//~^ ERROR auto traits cannot have associated items
12+
}
13+
14+
fn main() {
15+
let _: <() as Trait>::Output = ();
16+
//~^ ERROR mismatched types
17+
}

0 commit comments

Comments
 (0)