bug!() on const inference variable in opaque type
Add some tests to verify that this case is never hit
This commit is contained in:
parent
a59b7eabe6
commit
850e3e6d4d
@ -907,7 +907,15 @@ fn fixup_opaque_types<'tcx, T>(tcx: TyCtxt<'tcx>, val: &T) -> T where T: TypeFol
|
||||
},
|
||||
GenericArgKind::Const(old_const) => {
|
||||
if let ConstValue::Infer(_) = old_const.val {
|
||||
self.tcx.mk_param_from_def(param)
|
||||
// This should never happen - we currently do not support
|
||||
// 'const projections', e.g.:
|
||||
// `impl<T: SomeTrait> MyTrait for T where <T as SomeTrait>::MyConst == 25`
|
||||
// which should be the only way for us to end up with a const inference
|
||||
// variable after projection. If Rust ever gains support for this kind
|
||||
// of projection, this should *probably* be changed to
|
||||
// `self.tcx.mk_param_from_def(param)`
|
||||
bug!("Found infer const: `{:?}` in opaque type: {:?}",
|
||||
old_const, ty);
|
||||
} else {
|
||||
old_param.fold_with(self)
|
||||
}
|
||||
|
36
src/test/ui/type-alias-impl-trait/assoc-type-const.rs
Normal file
36
src/test/ui/type-alias-impl-trait/assoc-type-const.rs
Normal file
@ -0,0 +1,36 @@
|
||||
// Tests that we properly detect defining usages when using
|
||||
// const generics in an associated opaque type
|
||||
// check-pass
|
||||
|
||||
#![feature(type_alias_impl_trait)]
|
||||
#![feature(const_generics)]
|
||||
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
|
||||
|
||||
trait UnwrapItemsExt<const C: usize> {
|
||||
type Iter;
|
||||
fn unwrap_items(self) -> Self::Iter;
|
||||
}
|
||||
|
||||
struct MyStruct<const C: usize> {}
|
||||
|
||||
trait MyTrait<'a, const C: usize> {
|
||||
type MyItem;
|
||||
const MY_CONST: usize;
|
||||
}
|
||||
|
||||
impl<'a, const C: usize> MyTrait<'a, {C}> for MyStruct<{C}> {
|
||||
type MyItem = u8;
|
||||
const MY_CONST: usize = C;
|
||||
}
|
||||
|
||||
impl<'a, I, const C: usize> UnwrapItemsExt<{C}> for I
|
||||
where
|
||||
{
|
||||
type Iter = impl MyTrait<'a, {C}>;
|
||||
|
||||
fn unwrap_items(self) -> Self::Iter {
|
||||
MyStruct::<{C}> {}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
@ -0,0 +1,8 @@
|
||||
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
|
||||
--> $DIR/assoc-type-const.rs:6:12
|
||||
|
|
||||
LL | #![feature(const_generics)]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
|
28
src/test/ui/type-alias-impl-trait/assoc-type-lifetime.rs
Normal file
28
src/test/ui/type-alias-impl-trait/assoc-type-lifetime.rs
Normal file
@ -0,0 +1,28 @@
|
||||
// Tests that we still detect defining usages when
|
||||
// lifetimes are used in an associated opaque type
|
||||
// check-pass
|
||||
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
trait UnwrapItemsExt {
|
||||
type Iter;
|
||||
fn unwrap_items(self) -> Self::Iter;
|
||||
}
|
||||
|
||||
struct MyStruct {}
|
||||
|
||||
trait MyTrait<'a> {}
|
||||
|
||||
impl<'a> MyTrait<'a> for MyStruct {}
|
||||
|
||||
impl<'a, I> UnwrapItemsExt for I
|
||||
where
|
||||
{
|
||||
type Iter = impl MyTrait<'a>;
|
||||
|
||||
fn unwrap_items(self) -> Self::Iter {
|
||||
MyStruct {}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
Loading…
x
Reference in New Issue
Block a user