From ee84ff9fe5f28de39792f1af195e17be34ca774c Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 16 Nov 2025 09:58:03 +0100 Subject: [PATCH 1/9] miri genmc: fix exit() handling --- .../rustc_const_eval/src/interpret/step.rs | 7 +- src/tools/miri/src/shims/foreign_items.rs | 2 +- src/tools/miri/tests/genmc/fail/shims/exit.rs | 9 ++ .../miri/tests/genmc/fail/shims/exit.stderr | 126 ++++++++++++++++++ 4 files changed, 141 insertions(+), 3 deletions(-) create mode 100644 src/tools/miri/tests/genmc/fail/shims/exit.rs create mode 100644 src/tools/miri/tests/genmc/fail/shims/exit.stderr diff --git a/compiler/rustc_const_eval/src/interpret/step.rs b/compiler/rustc_const_eval/src/interpret/step.rs index 88a1160947583..9a4b9786eb15a 100644 --- a/compiler/rustc_const_eval/src/interpret/step.rs +++ b/compiler/rustc_const_eval/src/interpret/step.rs @@ -561,8 +561,11 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { if fn_abi.can_unwind { unwind } else { mir::UnwindAction::Unreachable }, )?; // Sanity-check that `eval_fn_call` either pushed a new frame or - // did a jump to another block. - if self.frame_idx() == old_stack && self.frame().loc == old_loc { + // did a jump to another block. We disable the sanity check for functions that + // can't return, since Miri sometimes does have to keep the location the same + // for those (which is fine since execution will continue on a different thread). + if target.is_some() && self.frame_idx() == old_stack && self.frame().loc == old_loc + { span_bug!(terminator.source_info.span, "evaluating this call made no progress"); } } diff --git a/src/tools/miri/src/shims/foreign_items.rs b/src/tools/miri/src/shims/foreign_items.rs index 440388673e7d4..39b691bb97d7f 100644 --- a/src/tools/miri/src/shims/foreign_items.rs +++ b/src/tools/miri/src/shims/foreign_items.rs @@ -538,7 +538,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> { code, crate::concurrency::ExitType::ExitCalled, )?; - todo!(); // FIXME(genmc): Add a way to return here that is allowed to not do progress (can't use existing EmulateItemResult variants). + return interp_ok(EmulateItemResult::AlreadyJumped); } throw_machine_stop!(TerminationInfo::Exit { code, leak_check: false }); } diff --git a/src/tools/miri/tests/genmc/fail/shims/exit.rs b/src/tools/miri/tests/genmc/fail/shims/exit.rs new file mode 100644 index 0000000000000..4138f4e785bbf --- /dev/null +++ b/src/tools/miri/tests/genmc/fail/shims/exit.rs @@ -0,0 +1,9 @@ +//@ compile-flags: -Zmiri-genmc -Zmiri-disable-stacked-borrows + +fn main() { + std::thread::spawn(|| { + unsafe { std::hint::unreachable_unchecked() }; //~ERROR: entering unreachable code + }); + // If we exit immediately, we might entirely miss the UB in the other thread. + std::process::exit(0); +} diff --git a/src/tools/miri/tests/genmc/fail/shims/exit.stderr b/src/tools/miri/tests/genmc/fail/shims/exit.stderr new file mode 100644 index 0000000000000..dead5faaa514d --- /dev/null +++ b/src/tools/miri/tests/genmc/fail/shims/exit.stderr @@ -0,0 +1,126 @@ +Running GenMC Verification... +warning: GenMC currently does not model spurious failures of `compare_exchange_weak`. Miri with GenMC might miss bugs related to spurious failures. + --> RUSTLIB/std/src/thread/mod.rs:LL:CC + | +LL | match COUNTER.compare_exchange_weak(last, id, Ordering::Relaxed, Ordering::Relaxed) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ GenMC might miss possible behaviors of this code + | + = note: BACKTRACE: + = note: inside `std::thread::ThreadId::new` at RUSTLIB/std/src/thread/mod.rs:LL:CC + = note: inside closure at RUSTLIB/std/src/thread/current.rs:LL:CC + = note: inside `std::thread::current::id::get_or_init` at RUSTLIB/std/src/thread/current.rs:LL:CC + = note: inside `std::thread::current_id` at RUSTLIB/std/src/thread/current.rs:LL:CC + = note: inside `std::rt::init` at RUSTLIB/std/src/rt.rs:LL:CC + = note: inside closure at RUSTLIB/std/src/rt.rs:LL:CC + = note: inside `std::panicking::catch_unwind::do_call::<{closure@std::rt::lang_start_internal::{closure#0}}, isize>` at RUSTLIB/std/src/panicking.rs:LL:CC + = note: inside `std::panicking::catch_unwind::` at RUSTLIB/std/src/panicking.rs:LL:CC + = note: inside `std::panic::catch_unwind::<{closure@std::rt::lang_start_internal::{closure#0}}, isize>` at RUSTLIB/std/src/panic.rs:LL:CC + = note: inside `std::rt::lang_start_internal` at RUSTLIB/std/src/rt.rs:LL:CC + = note: inside `std::rt::lang_start::<()>` at RUSTLIB/std/src/rt.rs:LL:CC + +warning: GenMC currently does not model the failure ordering for `compare_exchange`. Due to success ordering 'Acquire', the failure ordering 'Relaxed' is treated like 'Acquire'. Miri with GenMC might miss bugs related to this memory access. + --> RUSTLIB/std/src/sys/sync/PLATFORM/futex.rs:LL:CC + | +LL | || self + | ________________^ +LL | | .state +LL | | .compare_exchange_weak(state, state + READ_LOCKED, Acquire, Relaxed) + | |____________________________________________________________________________________^ GenMC might miss possible behaviors of this code + | + = note: BACKTRACE: + = note: inside `std::sys::sync::PLATFORM::futex::RwLock::read` at RUSTLIB/std/src/sys/sync/PLATFORM/futex.rs:LL:CC + = note: inside `std::sync::RwLock::<()>::read` at RUSTLIB/std/src/sync/poison/rwlock.rs:LL:CC + = note: inside `std::sys::env::PLATFORM::env_read_lock` at RUSTLIB/std/src/sys/env/PLATFORM.rs:LL:CC + = note: inside closure at RUSTLIB/std/src/sys/env/PLATFORM.rs:LL:CC + = note: inside `std::sys::pal::PLATFORM::small_c_string::run_with_cstr_stack::>` at RUSTLIB/std/src/sys/pal/PLATFORM/small_c_string.rs:LL:CC + = note: inside `std::sys::pal::PLATFORM::small_c_string::run_with_cstr::>` at RUSTLIB/std/src/sys/pal/PLATFORM/small_c_string.rs:LL:CC + = note: inside `std::sys::env::PLATFORM::getenv` at RUSTLIB/std/src/sys/env/PLATFORM.rs:LL:CC + = note: inside `std::env::_var_os` at RUSTLIB/std/src/env.rs:LL:CC + = note: inside `std::env::var_os::<&str>` at RUSTLIB/std/src/env.rs:LL:CC + = note: inside closure at RUSTLIB/std/src/thread/mod.rs:LL:CC +note: inside `main` + --> tests/genmc/fail/shims/exit.rs:LL:CC + | +LL | / std::thread::spawn(|| { +LL | | unsafe { std::hint::unreachable_unchecked() }; +LL | | }); + | |______^ + +warning: GenMC currently does not model spurious failures of `compare_exchange_weak`. Miri with GenMC might miss bugs related to spurious failures. + --> RUSTLIB/std/src/sys/sync/PLATFORM/futex.rs:LL:CC + | +LL | || self + | ________________^ +LL | | .state +LL | | .compare_exchange_weak(state, state + READ_LOCKED, Acquire, Relaxed) + | |____________________________________________________________________________________^ GenMC might miss possible behaviors of this code + | + = note: BACKTRACE: + = note: inside `std::sys::sync::PLATFORM::futex::RwLock::read` at RUSTLIB/std/src/sys/sync/PLATFORM/futex.rs:LL:CC + = note: inside `std::sync::RwLock::<()>::read` at RUSTLIB/std/src/sync/poison/rwlock.rs:LL:CC + = note: inside `std::sys::env::PLATFORM::env_read_lock` at RUSTLIB/std/src/sys/env/PLATFORM.rs:LL:CC + = note: inside closure at RUSTLIB/std/src/sys/env/PLATFORM.rs:LL:CC + = note: inside `std::sys::pal::PLATFORM::small_c_string::run_with_cstr_stack::>` at RUSTLIB/std/src/sys/pal/PLATFORM/small_c_string.rs:LL:CC + = note: inside `std::sys::pal::PLATFORM::small_c_string::run_with_cstr::>` at RUSTLIB/std/src/sys/pal/PLATFORM/small_c_string.rs:LL:CC + = note: inside `std::sys::env::PLATFORM::getenv` at RUSTLIB/std/src/sys/env/PLATFORM.rs:LL:CC + = note: inside `std::env::_var_os` at RUSTLIB/std/src/env.rs:LL:CC + = note: inside `std::env::var_os::<&str>` at RUSTLIB/std/src/env.rs:LL:CC + = note: inside closure at RUSTLIB/std/src/thread/mod.rs:LL:CC +note: inside `main` + --> tests/genmc/fail/shims/exit.rs:LL:CC + | +LL | / std::thread::spawn(|| { +LL | | unsafe { std::hint::unreachable_unchecked() }; +LL | | }); + | |______^ + +warning: GenMC currently does not model spurious failures of `compare_exchange_weak`. Miri with GenMC might miss bugs related to spurious failures. + --> RUSTLIB/std/src/rt.rs:LL:CC + | +LL | / CLEANUP.call_once(|| unsafe { +LL | | // Flush stdout and disable buffering. +LL | | crate::io::cleanup(); +... | +LL | | }); + | |______^ GenMC might miss possible behaviors of this code + | + = note: BACKTRACE: + = note: inside `std::rt::cleanup` at RUSTLIB/std/src/rt.rs:LL:CC + = note: inside `std::process::exit` at RUSTLIB/std/src/process.rs:LL:CC +note: inside `main` + --> tests/genmc/fail/shims/exit.rs:LL:CC + | +LL | std::process::exit(0); + | ^^^^^^^^^^^^^^^^^^^^^ + +warning: GenMC currently does not model the failure ordering for `compare_exchange`. Due to success ordering 'Acquire', the failure ordering 'Relaxed' is treated like 'Acquire'. Miri with GenMC might miss bugs related to this memory access. + --> RUSTLIB/std/src/sys/exit_guard.rs:LL:CC + | +LL | match EXITING_THREAD_ID.compare_exchange(ptr::null_mut(), this_thread_id, Acquire, Relaxed) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ GenMC might miss possible behaviors of this code + | + = note: BACKTRACE: + = note: inside `std::sys::exit_guard::unique_thread_exit` at RUSTLIB/std/src/sys/exit_guard.rs:LL:CC + = note: inside `std::sys::pal::PLATFORM::os::exit` at RUSTLIB/std/src/sys/pal/PLATFORM/os.rs:LL:CC + = note: inside `std::process::exit` at RUSTLIB/std/src/process.rs:LL:CC +note: inside `main` + --> tests/genmc/fail/shims/exit.rs:LL:CC + | +LL | std::process::exit(0); + | ^^^^^^^^^^^^^^^^^^^^^ + +error: Undefined Behavior: entering unreachable code + --> tests/genmc/fail/shims/exit.rs:LL:CC + | +LL | unsafe { std::hint::unreachable_unchecked() }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Undefined Behavior occurred here + | + = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior + = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information + +note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace + +note: add `-Zmiri-genmc-print-genmc-output` to MIRIFLAGS to see the detailed GenMC error report + +error: aborting due to 1 previous error; 5 warnings emitted + From 783780c25312d0eb78511e33fa572a5c3feb8dfd Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 16 Nov 2025 09:57:33 +0100 Subject: [PATCH 2/9] miri tests can always rely on CARGO_BIN_EXE_miri --- src/bootstrap/src/core/build_steps/test.rs | 1 - src/tools/miri/tests/ui.rs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/test.rs b/src/bootstrap/src/core/build_steps/test.rs index d888e63275cda..fbdf0adc76ac2 100644 --- a/src/bootstrap/src/core/build_steps/test.rs +++ b/src/bootstrap/src/core/build_steps/test.rs @@ -679,7 +679,6 @@ impl Step for Miri { // miri tests need to know about the stage sysroot cargo.env("MIRI_SYSROOT", &miri_sysroot); cargo.env("MIRI_HOST_SYSROOT", &host_sysroot); - cargo.env("MIRI", &miri.tool_path); // Set the target. cargo.env("MIRI_TEST_TARGET", target.rustc_target_arg()); diff --git a/src/tools/miri/tests/ui.rs b/src/tools/miri/tests/ui.rs index 1f8d98a4d3392..b7f428ff01e09 100644 --- a/src/tools/miri/tests/ui.rs +++ b/src/tools/miri/tests/ui.rs @@ -27,7 +27,7 @@ enum Mode { } fn miri_path() -> PathBuf { - PathBuf::from(env::var("MIRI").unwrap_or_else(|_| env!("CARGO_BIN_EXE_miri").into())) + env!("CARGO_BIN_EXE_miri").into() } // Build the shared object file for testing native function calls. From 746acc47a1d068792faebd5d3a1b8ed2ac9f9ae8 Mon Sep 17 00:00:00 2001 From: Kjetil Kjeka Date: Tue, 4 Nov 2025 18:22:56 +0100 Subject: [PATCH 3/9] Nvptx: Use llbc as default linker --- compiler/rustc_target/src/spec/mod.rs | 5 ----- .../rustc_target/src/spec/targets/nvptx64_nvidia_cuda.rs | 4 +--- src/doc/rustc/src/platform-support/nvptx64-nvidia-cuda.md | 4 ++-- tests/assembly-llvm/nvptx-arch-default.rs | 2 +- tests/assembly-llvm/nvptx-arch-target-cpu.rs | 2 +- tests/assembly-llvm/nvptx-c-abi-arg-v7.rs | 2 +- tests/assembly-llvm/nvptx-c-abi-ret-v7.rs | 2 +- .../nvptx-kernel-abi/nvptx-kernel-args-abi-v7.rs | 2 +- tests/assembly-llvm/nvptx-safe-naming.rs | 2 +- 9 files changed, 9 insertions(+), 16 deletions(-) diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 3d500694c978b..b06339f594257 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -2956,11 +2956,6 @@ impl Target { matches!(self.linker_flavor, LinkerFlavor::Bpf), "`linker_flavor` must be `bpf` if and only if `arch` is `bpf`" ); - check_eq!( - self.arch == Arch::Nvptx64, - matches!(self.linker_flavor, LinkerFlavor::Ptx), - "`linker_flavor` must be `ptc` if and only if `arch` is `nvptx64`" - ); for args in [ &self.pre_link_args, diff --git a/compiler/rustc_target/src/spec/targets/nvptx64_nvidia_cuda.rs b/compiler/rustc_target/src/spec/targets/nvptx64_nvidia_cuda.rs index 35003c4d4dd67..be09681b1f35b 100644 --- a/compiler/rustc_target/src/spec/targets/nvptx64_nvidia_cuda.rs +++ b/compiler/rustc_target/src/spec/targets/nvptx64_nvidia_cuda.rs @@ -19,9 +19,7 @@ pub(crate) fn target() -> Target { options: TargetOptions { os: Os::Cuda, vendor: "nvidia".into(), - linker_flavor: LinkerFlavor::Ptx, - // The linker can be installed from `crates.io`. - linker: Some("rust-ptx-linker".into()), + linker_flavor: LinkerFlavor::Llbc, // With `ptx-linker` approach, it can be later overridden via link flags. cpu: "sm_30".into(), diff --git a/src/doc/rustc/src/platform-support/nvptx64-nvidia-cuda.md b/src/doc/rustc/src/platform-support/nvptx64-nvidia-cuda.md index 36598982481bf..0eb7e1d84bd0a 100644 --- a/src/doc/rustc/src/platform-support/nvptx64-nvidia-cuda.md +++ b/src/doc/rustc/src/platform-support/nvptx64-nvidia-cuda.md @@ -12,7 +12,7 @@ platform. ## Requirements -This target is `no_std` and will typically be built with crate-type `cdylib` and `-C linker-flavor=llbc`, which generates PTX. +This target is `no_std`, and uses the `llvm-bitcode-linker` by default. For PTX output, build with crate-type `cdylib`. The necessary components for this workflow are: - `rustup toolchain add nightly` @@ -38,7 +38,7 @@ While the compiler accepts `#[target_feature(enable = "ptx80", enable = "sm_89") A `no_std` crate containing one or more functions with `extern "ptx-kernel"` can be compiled to PTX using a command like the following. ```console -$ RUSTFLAGS='-Ctarget-cpu=sm_89' cargo +nightly rustc --target=nvptx64-nvidia-cuda -Zbuild-std=core --crate-type=cdylib -- -Clinker-flavor=llbc -Zunstable-options +$ RUSTFLAGS='-Ctarget-cpu=sm_89' cargo +nightly rustc --target=nvptx64-nvidia-cuda -Zbuild-std=core --crate-type=cdylib ``` Intrinsics in `core::arch::nvptx` may use `#[cfg(target_feature = "...")]`, thus it's necessary to use `-Zbuild-std=core` with appropriate `RUSTFLAGS`. The following components are needed for this workflow: diff --git a/tests/assembly-llvm/nvptx-arch-default.rs b/tests/assembly-llvm/nvptx-arch-default.rs index a621fd6dcb299..22b4a680e322c 100644 --- a/tests/assembly-llvm/nvptx-arch-default.rs +++ b/tests/assembly-llvm/nvptx-arch-default.rs @@ -1,5 +1,5 @@ //@ assembly-output: ptx-linker -//@ compile-flags: --crate-type cdylib -Z unstable-options -Clinker-flavor=llbc +//@ compile-flags: --crate-type cdylib //@ only-nvptx64 #![no_std] diff --git a/tests/assembly-llvm/nvptx-arch-target-cpu.rs b/tests/assembly-llvm/nvptx-arch-target-cpu.rs index 609ab297e636e..e02ad0d558a96 100644 --- a/tests/assembly-llvm/nvptx-arch-target-cpu.rs +++ b/tests/assembly-llvm/nvptx-arch-target-cpu.rs @@ -1,5 +1,5 @@ //@ assembly-output: ptx-linker -//@ compile-flags: --crate-type cdylib -C target-cpu=sm_50 -Z unstable-options -Clinker-flavor=llbc +//@ compile-flags: --crate-type cdylib -C target-cpu=sm_50 //@ only-nvptx64 #![no_std] diff --git a/tests/assembly-llvm/nvptx-c-abi-arg-v7.rs b/tests/assembly-llvm/nvptx-c-abi-arg-v7.rs index be98b167470a3..6f5ef792e9b34 100644 --- a/tests/assembly-llvm/nvptx-c-abi-arg-v7.rs +++ b/tests/assembly-llvm/nvptx-c-abi-arg-v7.rs @@ -1,5 +1,5 @@ //@ assembly-output: ptx-linker -//@ compile-flags: --crate-type cdylib -C target-cpu=sm_86 -Z unstable-options -Clinker-flavor=llbc +//@ compile-flags: --crate-type cdylib -C target-cpu=sm_86 //@ only-nvptx64 // The PTX ABI stability is tied to major versions of the PTX ISA diff --git a/tests/assembly-llvm/nvptx-c-abi-ret-v7.rs b/tests/assembly-llvm/nvptx-c-abi-ret-v7.rs index c68c71c872c2e..02ec9facee7a8 100644 --- a/tests/assembly-llvm/nvptx-c-abi-ret-v7.rs +++ b/tests/assembly-llvm/nvptx-c-abi-ret-v7.rs @@ -1,5 +1,5 @@ //@ assembly-output: ptx-linker -//@ compile-flags: --crate-type cdylib -C target-cpu=sm_86 -Z unstable-options -Clinker-flavor=llbc +//@ compile-flags: --crate-type cdylib -C target-cpu=sm_86 //@ only-nvptx64 // The PTX ABI stability is tied to major versions of the PTX ISA diff --git a/tests/assembly-llvm/nvptx-kernel-abi/nvptx-kernel-args-abi-v7.rs b/tests/assembly-llvm/nvptx-kernel-abi/nvptx-kernel-args-abi-v7.rs index f245b4460f2bf..00f6fe9332d94 100644 --- a/tests/assembly-llvm/nvptx-kernel-abi/nvptx-kernel-args-abi-v7.rs +++ b/tests/assembly-llvm/nvptx-kernel-abi/nvptx-kernel-args-abi-v7.rs @@ -1,5 +1,5 @@ //@ assembly-output: ptx-linker -//@ compile-flags: --crate-type cdylib -C target-cpu=sm_86 -Z unstable-options -Clinker-flavor=llbc +//@ compile-flags: --crate-type cdylib -C target-cpu=sm_86 //@ only-nvptx64 // The following ABI tests are made with nvcc 11.6 does. diff --git a/tests/assembly-llvm/nvptx-safe-naming.rs b/tests/assembly-llvm/nvptx-safe-naming.rs index c70c63b7ee7cc..85415b6ca5b5a 100644 --- a/tests/assembly-llvm/nvptx-safe-naming.rs +++ b/tests/assembly-llvm/nvptx-safe-naming.rs @@ -1,5 +1,5 @@ //@ assembly-output: ptx-linker -//@ compile-flags: --crate-type cdylib -Z unstable-options -Clinker-flavor=llbc +//@ compile-flags: --crate-type cdylib //@ only-nvptx64 //@ revisions: LLVM20 LLVM21 //@ [LLVM21] min-llvm-version: 21 From 81d86bf0ebe38897ba1c79cb9a340a1342e0f22a Mon Sep 17 00:00:00 2001 From: Urgau Date: Fri, 19 Dec 2025 22:03:57 +0100 Subject: [PATCH 4/9] Add regression test for remap-path-prefix handling in rustdoc for deps --- tests/rustdoc/auxiliary/remapped-paths.rs | 11 +++++++++++ tests/rustdoc/import-remapped-paths.rs | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 tests/rustdoc/auxiliary/remapped-paths.rs create mode 100644 tests/rustdoc/import-remapped-paths.rs diff --git a/tests/rustdoc/auxiliary/remapped-paths.rs b/tests/rustdoc/auxiliary/remapped-paths.rs new file mode 100644 index 0000000000000..f31d2d316f3aa --- /dev/null +++ b/tests/rustdoc/auxiliary/remapped-paths.rs @@ -0,0 +1,11 @@ +//@ compile-flags:-Zunstable-options --remap-path-prefix={{src-base}}= + +pub struct MyStruct { + field: u32, +} + +impl MyStruct { + pub fn new() -> MyStruct { + MyStruct { field: 3 } + } +} diff --git a/tests/rustdoc/import-remapped-paths.rs b/tests/rustdoc/import-remapped-paths.rs new file mode 100644 index 0000000000000..c90ef4df1c0f7 --- /dev/null +++ b/tests/rustdoc/import-remapped-paths.rs @@ -0,0 +1,20 @@ +// This is a regression for `--remap-path-prefix` in an auxiliary dependency. +// +// We want to make sure that we can still have the "Source" links to the dependency +// even if it's paths are remapped. +// +// See also rust-lang/rust#150100 + +//@ aux-build:remapped-paths.rs +//@ build-aux-docs + +#![crate_name = "foo"] + +extern crate remapped_paths; + +//@ has foo/struct.MyStruct.html +// FIXME: Doesn't work! +//@ has - '//a[@href="../src/remapped_paths/remapped-paths.rs.html#3"]' 'Source' +//@ has - '//a[@href="../src/remapped_paths/remapped-paths.rs.html#8"]' 'Source' + +pub use remapped_paths::MyStruct; From 811c241b3d873880fe9bd4b9b36b37a3cdf3f70d Mon Sep 17 00:00:00 2001 From: Urgau Date: Thu, 18 Dec 2025 23:37:51 +0100 Subject: [PATCH 5/9] Handle remapped paths correctly when generating "Source" links --- src/librustdoc/html/render/context.rs | 17 +++++++++++------ tests/rustdoc/import-remapped-paths.rs | 1 - 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs index ee71564a1417a..4d9e352595a1a 100644 --- a/src/librustdoc/html/render/context.rs +++ b/src/librustdoc/html/render/context.rs @@ -14,7 +14,7 @@ use rustc_hir::def_id::{DefIdMap, LOCAL_CRATE}; use rustc_middle::ty::TyCtxt; use rustc_session::Session; use rustc_span::edition::Edition; -use rustc_span::{BytePos, FileName, Symbol}; +use rustc_span::{BytePos, FileName, RemapPathScopeComponents, Symbol}; use tracing::info; use super::print_item::{full_path, print_item, print_item_path}; @@ -365,7 +365,10 @@ impl<'tcx> Context<'tcx> { // We can safely ignore synthetic `SourceFile`s. let file = match span.filename(self.sess()) { - FileName::Real(ref path) => path.local_path()?.to_path_buf(), + FileName::Real(ref path) => path + .local_path() + .unwrap_or(path.path(RemapPathScopeComponents::MACRO)) + .to_path_buf(), _ => return None, }; let file = &file; @@ -499,10 +502,12 @@ impl<'tcx> Context<'tcx> { } = options; let src_root = match krate.src(tcx) { - FileName::Real(ref p) => match p.local_path().map(|p| p.parent()).flatten() { - Some(p) => p.to_path_buf(), - None => PathBuf::new(), - }, + FileName::Real(ref p) => { + match p.local_path().unwrap_or(p.path(RemapPathScopeComponents::MACRO)).parent() { + Some(p) => p.to_path_buf(), + None => PathBuf::new(), + } + } _ => PathBuf::new(), }; // If user passed in `--playground-url` arg, we fill in crate name here diff --git a/tests/rustdoc/import-remapped-paths.rs b/tests/rustdoc/import-remapped-paths.rs index c90ef4df1c0f7..bce3d782b9c2e 100644 --- a/tests/rustdoc/import-remapped-paths.rs +++ b/tests/rustdoc/import-remapped-paths.rs @@ -13,7 +13,6 @@ extern crate remapped_paths; //@ has foo/struct.MyStruct.html -// FIXME: Doesn't work! //@ has - '//a[@href="../src/remapped_paths/remapped-paths.rs.html#3"]' 'Source' //@ has - '//a[@href="../src/remapped_paths/remapped-paths.rs.html#8"]' 'Source' From c039edd41416c209b6bcdfa02d152a8db64102ba Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 20 Dec 2025 00:32:56 +0100 Subject: [PATCH 6/9] Fix typo --- tests/rustdoc/import-remapped-paths.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/rustdoc/import-remapped-paths.rs b/tests/rustdoc/import-remapped-paths.rs index bce3d782b9c2e..9e7518f7c0170 100644 --- a/tests/rustdoc/import-remapped-paths.rs +++ b/tests/rustdoc/import-remapped-paths.rs @@ -1,7 +1,7 @@ // This is a regression for `--remap-path-prefix` in an auxiliary dependency. // // We want to make sure that we can still have the "Source" links to the dependency -// even if it's paths are remapped. +// even if its paths are remapped. // // See also rust-lang/rust#150100 From 572ca1eb748f14b29b240a5028d72908fc4517f9 Mon Sep 17 00:00:00 2001 From: Tsukasa OI Date: Fri, 19 Sep 2025 04:58:26 +0000 Subject: [PATCH 7/9] rustc_codegen_llvm: Split "Fixed in LLVM 20" cases ... in `update_target_reliable_float_cfg`, based on the actual changes. The AArch64 issue is fixed on LLVM 20.1.1 while the MIPS issue is fixed on LLVM 20.1.0 (the first LLVM 20 release). This commit distinguishes two separate cases. --- compiler/rustc_codegen_llvm/src/llvm_util.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index 2e1d0cfada5b5..adb1ac09a633a 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -364,11 +364,12 @@ fn update_target_reliable_float_cfg(sess: &Session, cfg: &mut TargetConfig) { let target_abi = &sess.target.options.abi; let target_pointer_width = sess.target.pointer_width; let version = get_version(); + let lt_20_1_0 = version < (20, 1, 0); let lt_20_1_1 = version < (20, 1, 1); let lt_21_0_0 = version < (21, 0, 0); cfg.has_reliable_f16 = match (target_arch, target_os) { - // LLVM crash without neon (fixed in llvm20) + // LLVM crash without neon (fixed in LLVM 20.1.1) (Arch::AArch64, _) if !cfg.target_features.iter().any(|f| f.as_str() == "neon") && lt_20_1_1 => { @@ -395,8 +396,8 @@ fn update_target_reliable_float_cfg(sess: &Session, cfg: &mut TargetConfig) { cfg.has_reliable_f128 = match (target_arch, target_os) { // Unsupported (Arch::Arm64EC, _) => false, - // Selection bug (fixed in llvm20) - (Arch::Mips64 | Arch::Mips64r6, _) if lt_20_1_1 => false, + // Selection bug (fixed in LLVM 20.1.0) + (Arch::Mips64 | Arch::Mips64r6, _) if lt_20_1_0 => false, // Selection bug . This issue is closed // but basic math still does not work. (Arch::Nvptx64, _) => false, From 28203e182f0d74577fee90d4fccd52fa98f72f07 Mon Sep 17 00:00:00 2001 From: Tsukasa OI Date: Fri, 19 Sep 2025 04:14:10 +0000 Subject: [PATCH 8/9] rustc_codegen_llvm: Simplify `update_target_reliable_float_cfg` This commit simplifies floating type handling through `update_target_reliable_float_cfg` based on several facts: 1. Major changes in behavior normally occurs only on the major LLVM upgrade. 2. The first release of LLVM 20.x.x is 20.1.0. Due to the first fact, we can normally ignore minor and patch releases of LLVM and we can remove obscure variables like `lt_xx_x_x` (still, there is a case where checking for patch version is required). The second fact is missed when the minimum LLVM version is raised to LLVM 20 and one "fixed in LLVM 20" case can be safely removed. --- compiler/rustc_codegen_llvm/src/llvm_util.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index adb1ac09a633a..a3b1de9c3878a 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -364,26 +364,25 @@ fn update_target_reliable_float_cfg(sess: &Session, cfg: &mut TargetConfig) { let target_abi = &sess.target.options.abi; let target_pointer_width = sess.target.pointer_width; let version = get_version(); - let lt_20_1_0 = version < (20, 1, 0); - let lt_20_1_1 = version < (20, 1, 1); - let lt_21_0_0 = version < (21, 0, 0); + let (major, _, _) = version; cfg.has_reliable_f16 = match (target_arch, target_os) { // LLVM crash without neon (fixed in LLVM 20.1.1) (Arch::AArch64, _) - if !cfg.target_features.iter().any(|f| f.as_str() == "neon") && lt_20_1_1 => + if !cfg.target_features.iter().any(|f| f.as_str() == "neon") + && version < (20, 1, 1) => { false } // Unsupported (Arch::Arm64EC, _) => false, // Selection failure (fixed in llvm21) - (Arch::S390x, _) if lt_21_0_0 => false, + (Arch::S390x, _) if major < 21 => false, // MinGW ABI bugs (Arch::X86_64, Os::Windows) if *target_env == Env::Gnu && *target_abi != Abi::Llvm => false, // Infinite recursion (Arch::CSky, _) => false, - (Arch::Hexagon, _) if lt_21_0_0 => false, // (fixed in llvm21) + (Arch::Hexagon, _) if major < 21 => false, // (fixed in llvm21) (Arch::PowerPC | Arch::PowerPC64, _) => false, (Arch::Sparc | Arch::Sparc64, _) => false, (Arch::Wasm32 | Arch::Wasm64, _) => false, @@ -397,7 +396,7 @@ fn update_target_reliable_float_cfg(sess: &Session, cfg: &mut TargetConfig) { // Unsupported (Arch::Arm64EC, _) => false, // Selection bug (fixed in LLVM 20.1.0) - (Arch::Mips64 | Arch::Mips64r6, _) if lt_20_1_0 => false, + (Arch::Mips64 | Arch::Mips64r6, _) if version < (20, 1, 0) => false, // Selection bug . This issue is closed // but basic math still does not work. (Arch::Nvptx64, _) => false, @@ -410,7 +409,7 @@ fn update_target_reliable_float_cfg(sess: &Session, cfg: &mut TargetConfig) { (Arch::Sparc, _) => false, // Stack alignment bug . NB: tests may // not fail if our compiler-builtins is linked. (fixed in llvm21) - (Arch::X86, _) if lt_21_0_0 => false, + (Arch::X86, _) if major < 21 => false, // MinGW ABI bugs (Arch::X86_64, Os::Windows) if *target_env == Env::Gnu && *target_abi != Abi::Llvm => false, // There are no known problems on other platforms, so the only requirement is that symbols From 42d9f099e0f703bf681ab5e5fa502193bab7ad9e Mon Sep 17 00:00:00 2001 From: Tsukasa OI Date: Fri, 19 Sep 2025 04:14:10 +0000 Subject: [PATCH 9/9] rustc_codegen_llvm: Reorder by arch in `update_target_reliable_float_cfg` This commit reorders certain match clauses in `update_target_reliable_float_cfg` by the architecture when there's no problems reordering it. --- compiler/rustc_codegen_llvm/src/llvm_util.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index a3b1de9c3878a..a5a8f8e6a25e8 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -393,6 +393,8 @@ fn update_target_reliable_float_cfg(sess: &Session, cfg: &mut TargetConfig) { }; cfg.has_reliable_f128 = match (target_arch, target_os) { + // Unsupported https://github.com/llvm/llvm-project/issues/121122 + (Arch::AmdGpu, _) => false, // Unsupported (Arch::Arm64EC, _) => false, // Selection bug (fixed in LLVM 20.1.0) @@ -400,8 +402,6 @@ fn update_target_reliable_float_cfg(sess: &Session, cfg: &mut TargetConfig) { // Selection bug . This issue is closed // but basic math still does not work. (Arch::Nvptx64, _) => false, - // Unsupported https://github.com/llvm/llvm-project/issues/121122 - (Arch::AmdGpu, _) => false, // ABI bugs et al. (full // list at ) (Arch::PowerPC | Arch::PowerPC64, _) => false,