Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't ICE when auto trait has assoc ty in old solver #128160

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions compiler/rustc_trait_selection/src/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,12 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
false
}
}
} else if tcx.trait_is_auto(trait_ref.def_id) {
tcx.dcx().span_delayed_bug(
tcx.def_span(obligation.predicate.def_id),
"associated types not allowed on auto traits",
);
false
} else {
bug!("unexpected builtin trait with associated type: {trait_ref:?}")
}
Expand Down
14 changes: 0 additions & 14 deletions tests/crashes/117829-2.rs

This file was deleted.

9 changes: 0 additions & 9 deletions tests/crashes/117829.rs

This file was deleted.

40 changes: 40 additions & 0 deletions tests/ui/auto-traits/assoc-ty.current.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
error[E0380]: auto traits cannot have associated items
--> $DIR/assoc-ty.rs:10:10
|
LL | auto trait Trait {
| ----- auto traits cannot have associated items
LL |
LL | type Output;
| -----^^^^^^- help: remove these associated items

error[E0658]: auto traits are experimental and possibly buggy
--> $DIR/assoc-ty.rs:8:1
|
LL | / auto trait Trait {
LL | |
LL | | type Output;
LL | |
LL | | }
| |_^
|
= note: see issue #13231 <https://github.com/rust-lang/rust/issues/13231> for more information
= help: add `#![feature(auto_traits)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0308]: mismatched types
--> $DIR/assoc-ty.rs:15:36
|
LL | let _: <() as Trait>::Output = ();
| --------------------- ^^ expected associated type, found `()`
| |
| expected due to this
|
= note: expected associated type `<() as Trait>::Output`
found unit type `()`
= help: consider constraining the associated type `<() as Trait>::Output` to `()` or calling a method that returns `<() as Trait>::Output`
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0308, E0380, E0658.
For more information about an error, try `rustc --explain E0308`.
40 changes: 40 additions & 0 deletions tests/ui/auto-traits/assoc-ty.next.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
error[E0380]: auto traits cannot have associated items
--> $DIR/assoc-ty.rs:10:10
|
LL | auto trait Trait {
| ----- auto traits cannot have associated items
LL |
LL | type Output;
| -----^^^^^^- help: remove these associated items

error[E0658]: auto traits are experimental and possibly buggy
--> $DIR/assoc-ty.rs:8:1
|
LL | / auto trait Trait {
LL | |
LL | | type Output;
LL | |
LL | | }
| |_^
|
= note: see issue #13231 <https://github.com/rust-lang/rust/issues/13231> for more information
= help: add `#![feature(auto_traits)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0308]: mismatched types
--> $DIR/assoc-ty.rs:15:36
|
LL | let _: <() as Trait>::Output = ();
| --------------------- ^^ types differ
| |
| expected due to this
|
= note: expected associated type `<() as Trait>::Output`
found unit type `()`
= help: consider constraining the associated type `<() as Trait>::Output` to `()` or calling a method that returns `<() as Trait>::Output`
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0308, E0380, E0658.
For more information about an error, try `rustc --explain E0308`.
17 changes: 17 additions & 0 deletions tests/ui/auto-traits/assoc-ty.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//@ revisions: current next
//@[next] compile-flags: -Znext-solver
//@ ignore-compare-mode-next-solver (explicit revisions)

// Tests that projection doesn't explode if we accidentally
// put an associated type on an auto trait.

auto trait Trait {
//~^ ERROR auto traits are experimental and possibly buggy
type Output;
//~^ ERROR auto traits cannot have associated items
}

fn main() {
let _: <() as Trait>::Output = ();
//~^ ERROR mismatched types
}
Loading