Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ICE in checking transmutability of NaughtyLenArray #103788

Merged
merged 1 commit into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`.