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 the overflow issue for transmute_generic_consts #112520

Merged
merged 2 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 7 additions & 1 deletion compiler/rustc_hir_typeck/src/intrinsicck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

// Try to display a sensible error with as much information as possible.
let skeleton_string = |ty: Ty<'tcx>, sk| match sk {
Ok(SizeSkeleton::Known(size)) => format!("{} bits", size.bits()),
Ok(SizeSkeleton::Pointer { tail, .. }) => format!("pointer to `{tail}`"),
Ok(SizeSkeleton::Known(size)) => {
if let Some(v) = u128::from(size.bytes()).checked_mul(8) {
format!("{} bits", v)
} else {
format!("{} bytes", size.bytes())
}
}
Ok(SizeSkeleton::Generic(size)) => {
if let Some(size) = size.try_eval_target_usize(tcx, self.param_env) {
format!("{size} bytes")
Expand Down
7 changes: 7 additions & 0 deletions tests/ui/const-generics/issue-112505-overflow.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![feature(transmute_generic_consts)]

fn overflow(v: [[[u32; 8888888]; 9999999]; 777777777]) -> [[[u32; 9999999]; 777777777]; 239] {
unsafe { std::mem::transmute(v) } //~ ERROR cannot transmute between types of different sizes
}

fn main() { }
12 changes: 12 additions & 0 deletions tests/ui/const-generics/issue-112505-overflow.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> $DIR/issue-112505-overflow.rs:4:14
|
LL | unsafe { std::mem::transmute(v) }
| ^^^^^^^^^^^^^^^^^^^
|
= note: source type: `[[[u32; 8888888]; 9999999]; 777777777]` (values of the type `[[[u32; 8888888]; 9999999]; 777777777]` are too big for the current architecture)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[[[u32; 8888888]; 9999999]; 777777777] comes out 2 times, I think it may be too much for diagnostic.

= note: target type: `[[[u32; 9999999]; 777777777]; 239]` (59484438436515561504 bits)
chenyukang marked this conversation as resolved.
Show resolved Hide resolved

error: aborting due to previous error

For more information about this error, try `rustc --explain E0512`.