Skip to content

Path remapping ICE from unnecessary_transmutes suggestion #140277

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

Closed
Wyvern opened this issue Apr 25, 2025 · 4 comments · Fixed by #140284
Closed

Path remapping ICE from unnecessary_transmutes suggestion #140277

Wyvern opened this issue Apr 25, 2025 · 4 comments · Fixed by #140284
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-path-remapping Area: path remapping, --remap-path-prefix, --remap-cwd-prefix, --remap-diagnostics-scope etc. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ L-unnecessary_transmutes Lint: unnecessary_transmutes T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Wyvern
Copy link

Wyvern commented Apr 25, 2025

thread 'rustc' panicked at compiler/rustc_mir_transform/src/check_unnecessary_transmutes.rs:92:65:
ok: SourceNotAvailable { filename: Real(Remapped { local_path: None, virtual_name: "index.crates.io-1949cf8c6b5b557f/zerocopy-0.8.24/src/macros.rs" }) }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: please make sure that you have updated to the latest nightly

note: rustc 1.88.0-nightly (d7ea436a0 2025-04-24) running on x86_64-apple-darwin

note: compiler flags: --crate-type lib -C embed-bitcode=no -Z unstable-options -Z remap-path-scope=all -C prefer-dynamic -C debug-assertions=off -C overflow-checks=on -C rpath -C strip=debuginfo -Z unstable-options -C prefer-dynamic -C target-cpu=native -Z tune-cpu=native -Z binary-dep-depinfo -Z checksum-hash-algorithm=blake3

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [mir_built] building MIR for `x86_64::sse2::<impl at index.crates.io-1949cf8c6b5b557f/ppv-lite86-0.2.21/src/x86_64/sse2.rs:887:1: 887:64>::to_scalars`
#1 [check_unsafety] unsafety-checking `x86_64::sse2::<impl at index.crates.io-1949cf8c6b5b557f/ppv-lite86-0.2.21/src/x86_64/sse2.rs:887:1: 887:64>::to_scalars`
... and 1 other queries... use `env RUST_BACKTRACE=1` to see the full query stack

thread 'rustc' panicked at compiler/rustc_mir_transform/src/check_unnecessary_transmutes.rs:92:65:
ok: SourceNotAvailable { filename: Real(Remapped { local_path: None, virtual_name: "index.crates.io-1949cf8c6b5b557f/zerocopy-0.8.24/src/macros.rs" }) }

error: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: please make sure that you have updated to the latest nightly

note: rustc 1.88.0-nightly (d7ea436a0 2025-04-24) running on x86_64-apple-darwin

note: compiler flags: --crate-type lib -C embed-bitcode=no -Z unstable-options -Z remap-path-scope=all -C prefer-dynamic -C debug-assertions=off -C overflow-checks=on -C rpath -C strip=debuginfo -Z unstable-options -C prefer-dynamic -C target-cpu=native -Z tune-cpu=native -Z binary-dep-depinfo -Z checksum-hash-algorithm=blake3

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [mir_built] building MIR for `x86_64::sse2::avx2::<impl at index.crates.io-1949cf8c6b5b557f/ppv-lite86-0.2.21/src/x86_64/sse2.rs:1683:5: 1683:58>::to_scalars`
#1 [check_unsafety] unsafety-checking `x86_64::sse2::avx2::<impl at index.crates.io-1949cf8c6b5b557f/ppv-lite86-0.2.21/src/x86_64/sse2.rs:1683:5: 1683:58>::to_scalars`
@Wyvern Wyvern added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 25, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 25, 2025
@DaniPopes
Copy link
Contributor

#136083 cc @bend-n

@bend-n
Copy link
Contributor

bend-n commented Apr 25, 2025

wait whats the repro?

@jieyouxu jieyouxu added the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Apr 25, 2025
@jieyouxu
Copy link
Member

@Wyvern can you provide a more self-contained / complete reproducer? It's hard to determine how to reproduce this ICE, since based on the backtrace we can only guess it involves zerocopy's macro + path remapping.

@jieyouxu jieyouxu added S-needs-repro Status: This issue has no reproduction and needs a reproduction to make progress. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example and removed E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example S-needs-repro Status: This issue has no reproduction and needs a reproduction to make progress. labels Apr 25, 2025
@jieyouxu
Copy link
Member

jieyouxu commented Apr 25, 2025

Nvm I synthesized a repro based on zerocopy's src/macros.rs (not minimal because I couldn't be bothered further trimming it down). The macro can probably be trimmed down a lot.

// transmute.rs
#[macro_export]
macro_rules! transmute {
    ($e:expr) => {{
        let e = $e;
        if false {
            todo!()
        } else {
            let u = unsafe {
                #[allow(clippy::missing_transmute_annotations)]
                unsafe { std::mem::transmute(e) }
            };
            u
        }
    }}
}
// foo.rs
#![crate_type = "rlib"]

fn bytes_at_home(x: [u8; 4]) -> u32 {
    unsafe { transmute::transmute!(x) }
}
$ rustc +nightly -Zunstable-options -Z remap-path-scope=all transmute.rs --crate-type=rlib --remap-path-prefix=/home/=/x
$ rustc +nightly foo.rs --extern transmute=libtransmute.rlib
thread 'rustc' panicked at compiler/rustc_mir_transform/src/check_unnecessary_transmutes.rs:92:65:
ok: SourceNotAvailable { filename: Real(Remapped { local_path: None, virtual_name: "/x/joe/repos/transmute.rs" }) }
stack backtrace:
[...]

@jieyouxu jieyouxu added A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` A-path-remapping Area: path remapping, --remap-path-prefix, --remap-cwd-prefix, --remap-diagnostics-scope etc. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Apr 25, 2025
@jieyouxu jieyouxu changed the title new ICE in latest nightly d7ea436a0 2025-04-24 Path remapping ICE from unnecessary_transmutes suggestion Apr 25, 2025
@jieyouxu jieyouxu added the L-unnecessary_transmutes Lint: unnecessary_transmutes label Apr 25, 2025
@jieyouxu jieyouxu removed the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Apr 25, 2025
@bors bors closed this as completed in 4323939 Apr 25, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Apr 25, 2025
Rollup merge of rust-lang#140284 - bend-n:fix-expectation-unmet, r=jieyouxu

remove expect() in `unnecessary_transmutes`

removes expect() from rust-lang#136083 and fixes rust-lang#140277
includes regression test

r? lcnr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-path-remapping Area: path remapping, --remap-path-prefix, --remap-cwd-prefix, --remap-diagnostics-scope etc. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ L-unnecessary_transmutes Lint: unnecessary_transmutes T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants