fix #103783, fix ICE checking transmutability of NaughtyLenArray

This commit is contained in:
yukang 2022-10-30 01:32:04 +08:00
parent 126dbdc9c7
commit 55568419ac
3 changed files with 35 additions and 1 deletions

View File

@ -284,7 +284,8 @@ pub fn from_ty(ty: Ty<'tcx>, tcx: TyCtxt<'tcx>) -> Result<Self, Err> {
} }
ty::Array(ty, len) => { ty::Array(ty, len) => {
let len = len.try_eval_usize(tcx, ParamEnv::reveal_all()).unwrap(); let len =
len.try_eval_usize(tcx, ParamEnv::reveal_all()).ok_or(Err::Unspecified)?;
let elt = Tree::from_ty(*ty, tcx)?; let elt = Tree::from_ty(*ty, tcx)?;
Ok(std::iter::repeat(elt) Ok(std::iter::repeat(elt)
.take(len as usize) .take(len as usize)

View File

@ -0,0 +1,24 @@
#![crate_type = "lib"]
#![feature(transmutability)]
#![allow(dead_code)]
mod assert {
use std::mem::{Assume, BikeshedIntrinsicFrom};
pub struct Context;
pub fn is_maybe_transmutable<Src, Dst>()
where
Dst: BikeshedIntrinsicFrom<
Src,
Context,
{ Assume { alignment: true, lifetimes: true, safety: true, validity: true } },
>,
{
}
}
fn test() {
type NaughtyLenArray = [u32; 3.14159]; //~ ERROR mismatched types
type JustUnit = ();
assert::is_maybe_transmutable::<JustUnit, NaughtyLenArray>();
}

View File

@ -0,0 +1,9 @@
error[E0308]: mismatched types
--> $DIR/issue-103783-array-length.rs:21:34
|
LL | type NaughtyLenArray = [u32; 3.14159];
| ^^^^^^^ expected `usize`, found floating-point number
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.