miri: correctly deal with ConstKind::Bound
This commit is contained in:
parent
255a4c58f5
commit
2a00dda902
5 changed files with 88 additions and 4 deletions
|
@ -549,7 +549,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
};
|
||||
// Early-return cases.
|
||||
let val_val = match val.val {
|
||||
ty::ConstKind::Param(_) => throw_inval!(TooGeneric),
|
||||
ty::ConstKind::Param(_) | ty::ConstKind::Bound(..) => throw_inval!(TooGeneric),
|
||||
ty::ConstKind::Error(_) => throw_inval!(TypeckError(ErrorReported)),
|
||||
ty::ConstKind::Unevaluated(def, substs, promoted) => {
|
||||
let instance = self.resolve(def.did, substs)?;
|
||||
|
@ -561,9 +561,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
// happening.
|
||||
return Ok(self.const_eval(GlobalId { instance, promoted }, val.ty)?);
|
||||
}
|
||||
ty::ConstKind::Infer(..)
|
||||
| ty::ConstKind::Bound(..)
|
||||
| ty::ConstKind::Placeholder(..) => {
|
||||
ty::ConstKind::Infer(..) | ty::ConstKind::Placeholder(..) => {
|
||||
span_bug!(self.cur_span(), "const_to_op: Unexpected ConstKind {:?}", val)
|
||||
}
|
||||
ty::ConstKind::Value(val_val) => val_val,
|
||||
|
|
20
src/test/ui/const-generics/issues/issue-73260.rs
Normal file
20
src/test/ui/const-generics/issues/issue-73260.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
// compile-flags: -Zsave-analysis
|
||||
|
||||
#![feature(const_generics)]
|
||||
#![allow(incomplete_features)]
|
||||
struct Arr<const N: usize>
|
||||
where Assert::<{N < usize::max_value() / 2}>: IsTrue, //~ ERROR constant expression
|
||||
{
|
||||
}
|
||||
|
||||
enum Assert<const CHECK: bool> {}
|
||||
|
||||
trait IsTrue {}
|
||||
|
||||
impl IsTrue for Assert<true> {}
|
||||
|
||||
fn main() {
|
||||
let x: Arr<{usize::max_value()}> = Arr {};
|
||||
//~^ ERROR mismatched types
|
||||
//~| ERROR mismatched types
|
||||
}
|
29
src/test/ui/const-generics/issues/issue-73260.stderr
Normal file
29
src/test/ui/const-generics/issues/issue-73260.stderr
Normal file
|
@ -0,0 +1,29 @@
|
|||
error: constant expression depends on a generic parameter
|
||||
--> $DIR/issue-73260.rs:6:47
|
||||
|
|
||||
LL | where Assert::<{N < usize::max_value() / 2}>: IsTrue,
|
||||
| ^^^^^^
|
||||
|
|
||||
= note: this may fail depending on what value the parameter takes
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-73260.rs:17:12
|
||||
|
|
||||
LL | let x: Arr<{usize::max_value()}> = Arr {};
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `false`, found `true`
|
||||
|
|
||||
= note: expected type `false`
|
||||
found type `true`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-73260.rs:17:40
|
||||
|
|
||||
LL | let x: Arr<{usize::max_value()}> = Arr {};
|
||||
| ^^^ expected `false`, found `true`
|
||||
|
|
||||
= note: expected type `false`
|
||||
found type `true`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
27
src/test/ui/const-generics/issues/issue-74634.rs
Normal file
27
src/test/ui/const-generics/issues/issue-74634.rs
Normal file
|
@ -0,0 +1,27 @@
|
|||
#![feature(const_generics)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
trait If<const COND: bool> {}
|
||||
impl If<true> for () {}
|
||||
|
||||
trait IsZero<const N: u8> {
|
||||
type Answer;
|
||||
}
|
||||
|
||||
struct True;
|
||||
struct False;
|
||||
|
||||
impl<const N: u8> IsZero<N> for ()
|
||||
where (): If<{N == 0}> { //~ERROR constant expression
|
||||
type Answer = True;
|
||||
}
|
||||
|
||||
trait Foobar<const N: u8> {}
|
||||
|
||||
impl<const N: u8> Foobar<N> for ()
|
||||
where (): IsZero<N, Answer = True> {}
|
||||
|
||||
impl<const N: u8> Foobar<N> for ()
|
||||
where (): IsZero<N, Answer = False> {}
|
||||
|
||||
fn main() {}
|
10
src/test/ui/const-generics/issues/issue-74634.stderr
Normal file
10
src/test/ui/const-generics/issues/issue-74634.stderr
Normal file
|
@ -0,0 +1,10 @@
|
|||
error: constant expression depends on a generic parameter
|
||||
--> $DIR/issue-74634.rs:15:11
|
||||
|
|
||||
LL | where (): If<{N == 0}> {
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
= note: this may fail depending on what value the parameter takes
|
||||
|
||||
error: aborting due to previous error
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue