Rollup merge of #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 #115500
This commit is contained in:
commit
f5e6aa3c4a
@ -244,7 +244,21 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
|
|||||||
// Finally we construct the actual value of the associated type.
|
// Finally we construct the actual value of the associated type.
|
||||||
let term = match assoc_def.item.kind {
|
let term = match assoc_def.item.kind {
|
||||||
ty::AssocKind::Type => tcx.type_of(assoc_def.item.def_id).map_bound(|ty| ty.into()),
|
ty::AssocKind::Type => tcx.type_of(assoc_def.item.def_id).map_bound(|ty| ty.into()),
|
||||||
ty::AssocKind::Const => bug!("associated const projection is not supported yet"),
|
ty::AssocKind::Const => {
|
||||||
|
if tcx.features().associated_const_equality {
|
||||||
|
bug!("associated const projection is not supported yet")
|
||||||
|
} else {
|
||||||
|
ty::EarlyBinder::bind(
|
||||||
|
ty::Const::new_error_with_message(
|
||||||
|
tcx,
|
||||||
|
tcx.type_of(assoc_def.item.def_id).instantiate_identity(),
|
||||||
|
DUMMY_SP,
|
||||||
|
"associated const projection is not supported yet",
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
ty::AssocKind::Fn => unreachable!("we should never project to a fn"),
|
ty::AssocKind::Fn => unreachable!("we should never project to a fn"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
19
tests/ui/traits/new-solver/dont-ice-on-assoc-projection.rs
Normal file
19
tests/ui/traits/new-solver/dont-ice-on-assoc-projection.rs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// compile-flags: -Ztrait-solver=next-coherence
|
||||||
|
|
||||||
|
// Makes sure we don't ICE on associated const projection when the feature gate
|
||||||
|
// is not enabled, since we should avoid encountering ICEs on stable if possible.
|
||||||
|
|
||||||
|
trait Bar {
|
||||||
|
const ASSOC: usize;
|
||||||
|
}
|
||||||
|
impl Bar for () {
|
||||||
|
const ASSOC: usize = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
trait Foo {}
|
||||||
|
impl Foo for () {}
|
||||||
|
impl<T> Foo for T where T: Bar<ASSOC = 0> {}
|
||||||
|
//~^ ERROR associated const equality is incomplete
|
||||||
|
//~| ERROR conflicting implementations of trait `Foo` for type `()`
|
||||||
|
|
||||||
|
fn main() {}
|
@ -0,0 +1,21 @@
|
|||||||
|
error[E0658]: associated const equality is incomplete
|
||||||
|
--> $DIR/dont-ice-on-assoc-projection.rs:15:32
|
||||||
|
|
|
||||||
|
LL | impl<T> Foo for T where T: Bar<ASSOC = 0> {}
|
||||||
|
| ^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: see issue #92827 <https://github.com/rust-lang/rust/issues/92827> for more information
|
||||||
|
= help: add `#![feature(associated_const_equality)]` to the crate attributes to enable
|
||||||
|
|
||||||
|
error[E0119]: conflicting implementations of trait `Foo` for type `()`
|
||||||
|
--> $DIR/dont-ice-on-assoc-projection.rs:15:1
|
||||||
|
|
|
||||||
|
LL | impl Foo for () {}
|
||||||
|
| --------------- first implementation here
|
||||||
|
LL | impl<T> Foo for T where T: Bar<ASSOC = 0> {}
|
||||||
|
| ^^^^^^^^^^^^^^^^^ conflicting implementation for `()`
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
Some errors have detailed explanations: E0119, E0658.
|
||||||
|
For more information about an error, try `rustc --explain E0119`.
|
Loading…
x
Reference in New Issue
Block a user