Skip to content

Commit

Permalink
Rollup merge of rust-lang#128160 - compiler-errors:auto, r=jackh726
Browse files Browse the repository at this point in the history
Don't ICE when auto trait has assoc ty in old solver

Kinda a pointless change to make, but it's observable w/o the feature gate, so let's just fix it. I reintroduced this ICE when I removed the "auto impl" kind from `ImplSource` in rust-lang#112687.

Fixes rust-lang#117829
Fixes rust-lang#127746
  • Loading branch information
matthiaskrgr authored Jul 25, 2024
2 parents 40557c8 + 0919d07 commit 1fda084
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 23 deletions.
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
}

0 comments on commit 1fda084

Please sign in to comment.