-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-codegenArea: Code generationArea: Code generationC-bugCategory: This is a bug.Category: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-criticalCritical priorityCritical priority
Description
Array created using repeat expression [i128::MIN; 1]
and returned from a function actually returns [0i128; 1]
.
Interestingly the problem does not happen when using the list syntax [i128::MIN]
to create the array.
I tried this code:
fn main() {
fn min_array_ok() -> [i128; 1] {
[i128::MIN]
}
assert_eq!(min_array_ok(), [-170141183460469231731687303715884105728i128]);
fn min_array_nok() -> [i128; 1] {
[i128::MIN; 1]
}
assert_eq!(min_array_nok(), [-170141183460469231731687303715884105728i128]); // panic!
}
I expected to see this happen: the second assert_eq
should pass
Instead, this happened: the second assert_eq
fails screaming that
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `[0]`,
right: `[-170141183460469231731687303715884105728]`', src/main.rs:10:5
Meta
Problem exists on stable, beta and nightly
rustc --version --verbose
:
rustc 1.63.0 (4b91a6ea7 2022-08-08)
binary: rustc
commit-hash: 4b91a6ea7258a947e59c6522cd5898e7c0a6a88f
commit-date: 2022-08-08
host: x86_64-unknown-linux-gnu
release: 1.63.0
LLVM version: 14.0.5
Backtrace
0: rust_begin_unwind
at /rustc/289279de116707f28cf9c18e4bbb8c6ec84ad75b/library/std/src/panicking.rs:584:5
1: core::panicking::panic_fmt
at /rustc/289279de116707f28cf9c18e4bbb8c6ec84ad75b/library/core/src/panicking.rs:142:14
2: core::panicking::assert_failed_inner
3: core::panicking::assert_failed
at /rustc/289279de116707f28cf9c18e4bbb8c6ec84ad75b/library/core/src/panicking.rs:181:5
4: playground::main
at ./[src/main.rs:10](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#):5
5: core::ops::function::FnOnce::call_once
at /rustc/289279de116707f28cf9c18e4bbb8c6ec84ad75b/library/core/src/ops/function.rs:248:5
Metadata
Metadata
Assignees
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-codegenArea: Code generationArea: Code generationC-bugCategory: This is a bug.Category: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-criticalCritical priorityCritical priority