Skip to content

Commit f5e6aa3

Browse files
authored
Rollup merge of rust-lang#115519 - compiler-errors:next-solver-assoc-ice, r=lcnr
Don't ICE on associated type projection without feature gate in new solver Self-explanatory, we should avoid ICEs when the feature gate is not enabled. Continue to ICE when the feature gate *is* enabled, though. Fixes rust-lang#115500
2 parents 6f180ea + 8c667fe commit f5e6aa3

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

compiler/rustc_trait_selection/src/solve/project_goals.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,21 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
244244
// Finally we construct the actual value of the associated type.
245245
let term = match assoc_def.item.kind {
246246
ty::AssocKind::Type => tcx.type_of(assoc_def.item.def_id).map_bound(|ty| ty.into()),
247-
ty::AssocKind::Const => bug!("associated const projection is not supported yet"),
247+
ty::AssocKind::Const => {
248+
if tcx.features().associated_const_equality {
249+
bug!("associated const projection is not supported yet")
250+
} else {
251+
ty::EarlyBinder::bind(
252+
ty::Const::new_error_with_message(
253+
tcx,
254+
tcx.type_of(assoc_def.item.def_id).instantiate_identity(),
255+
DUMMY_SP,
256+
"associated const projection is not supported yet",
257+
)
258+
.into(),
259+
)
260+
}
261+
}
248262
ty::AssocKind::Fn => unreachable!("we should never project to a fn"),
249263
};
250264

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// compile-flags: -Ztrait-solver=next-coherence
2+
3+
// Makes sure we don't ICE on associated const projection when the feature gate
4+
// is not enabled, since we should avoid encountering ICEs on stable if possible.
5+
6+
trait Bar {
7+
const ASSOC: usize;
8+
}
9+
impl Bar for () {
10+
const ASSOC: usize = 1;
11+
}
12+
13+
trait Foo {}
14+
impl Foo for () {}
15+
impl<T> Foo for T where T: Bar<ASSOC = 0> {}
16+
//~^ ERROR associated const equality is incomplete
17+
//~| ERROR conflicting implementations of trait `Foo` for type `()`
18+
19+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0658]: associated const equality is incomplete
2+
--> $DIR/dont-ice-on-assoc-projection.rs:15:32
3+
|
4+
LL | impl<T> Foo for T where T: Bar<ASSOC = 0> {}
5+
| ^^^^^^^^^
6+
|
7+
= note: see issue #92827 <https://github.com/rust-lang/rust/issues/92827> for more information
8+
= help: add `#![feature(associated_const_equality)]` to the crate attributes to enable
9+
10+
error[E0119]: conflicting implementations of trait `Foo` for type `()`
11+
--> $DIR/dont-ice-on-assoc-projection.rs:15:1
12+
|
13+
LL | impl Foo for () {}
14+
| --------------- first implementation here
15+
LL | impl<T> Foo for T where T: Bar<ASSOC = 0> {}
16+
| ^^^^^^^^^^^^^^^^^ conflicting implementation for `()`
17+
18+
error: aborting due to 2 previous errors
19+
20+
Some errors have detailed explanations: E0119, E0658.
21+
For more information about an error, try `rustc --explain E0119`.

0 commit comments

Comments
 (0)