Skip to content

Commit

Permalink
Rollup merge of rust-lang#103788 - chenyukang:yukang/fix-ice-103783, …
Browse files Browse the repository at this point in the history
…r=compiler-errors

Fix ICE in checking transmutability of NaughtyLenArray

Fixes rust-lang#103783
  • Loading branch information
Yuki Okushi authored Nov 1, 2022
2 parents 5bf9d61 + 5556841 commit ff89cec
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 ff89cec

Please sign in to comment.