Skip to content

Commit ff89cec

Browse files
author
Yuki Okushi
authored
Rollup merge of rust-lang#103788 - chenyukang:yukang/fix-ice-103783, r=compiler-errors
Fix ICE in checking transmutability of NaughtyLenArray Fixes rust-lang#103783
2 parents 5bf9d61 + 5556841 commit ff89cec

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

compiler/rustc_transmute/src/layout/tree.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ pub(crate) mod rustc {
284284
}
285285

286286
ty::Array(ty, len) => {
287-
let len = len.try_eval_usize(tcx, ParamEnv::reveal_all()).unwrap();
287+
let len =
288+
len.try_eval_usize(tcx, ParamEnv::reveal_all()).ok_or(Err::Unspecified)?;
288289
let elt = Tree::from_ty(*ty, tcx)?;
289290
Ok(std::iter::repeat(elt)
290291
.take(len as usize)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#![crate_type = "lib"]
2+
#![feature(transmutability)]
3+
#![allow(dead_code)]
4+
5+
mod assert {
6+
use std::mem::{Assume, BikeshedIntrinsicFrom};
7+
pub struct Context;
8+
9+
pub fn is_maybe_transmutable<Src, Dst>()
10+
where
11+
Dst: BikeshedIntrinsicFrom<
12+
Src,
13+
Context,
14+
{ Assume { alignment: true, lifetimes: true, safety: true, validity: true } },
15+
>,
16+
{
17+
}
18+
}
19+
20+
fn test() {
21+
type NaughtyLenArray = [u32; 3.14159]; //~ ERROR mismatched types
22+
type JustUnit = ();
23+
assert::is_maybe_transmutable::<JustUnit, NaughtyLenArray>();
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/issue-103783-array-length.rs:21:34
3+
|
4+
LL | type NaughtyLenArray = [u32; 3.14159];
5+
| ^^^^^^^ expected `usize`, found floating-point number
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)