Skip to content

Commit

Permalink
fix #103783, fix ICE checking transmutability of NaughtyLenArray
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Oct 29, 2022
1 parent 126dbdc commit 5556841
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/rustc_transmute/src/layout/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ pub(crate) mod rustc {
}

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)
Expand Down
24 changes: 24 additions & 0 deletions src/test/ui/transmutability/arrays/issue-103783-array-length.rs
Original file line number Diff line number Diff line change
@@ -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>();
}
Original file line number Diff line number Diff line change
@@ -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`.

0 comments on commit 5556841

Please sign in to comment.