Building with optimizations can skip monomorphizing some types, making errors disappear
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
This program (original example due to @scottmcm) errors in debug builds but compiles successfully in release builds:
#![crate_type = "lib"]
#[unsafe(no_mangle)]
pub fn f() {
g::<u16>();
}
pub fn g<T>() -> std::mem::MaybeUninit<[T; 1 << 62]> {
std::mem::MaybeUninit::uninit()
}
The debug build error is:
error: values of the type `[u16; 4611686018427387904]` are too big for the target architecture
--> src/lib.rs:8:1
|
8 | pub fn g<T>() -> std::mem::MaybeUninit<[T; 1 << 62]> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
In a release build, we're optimizing away this function call so the bad type never reaches codegen.
Related issues: #157047, https://github.com/rust-lang/rust/issues/122828.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the example in src/lib.rs with both debug and release builds, confirming that the invalid array type is diagnosed only without optimizations. Trace the compiler's monomorphization and code-generation handling for the optimized-away call; done when the invalid type cannot evade the required diagnostic in release builds.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100