Rollup merge of #103788 - chenyukang:yukang/fix-ice-103783, r=compiler-errors

Fix ICE in checking transmutability of NaughtyLenArray

Fixes #103783
This commit is contained in:
Yuki Okushi 2022-11-01 12:03:42 +09:00 committed by GitHub
commit ff89ceca1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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) => {
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)?;
Ok(std::iter::repeat(elt)
.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`.