diff --git a/tests/run-make/remap-path-prefix-consts/location-caller.rs b/tests/run-make/remap-path-prefix-consts/location-caller.rs new file mode 100644 index 000000000000..70685e032e4a --- /dev/null +++ b/tests/run-make/remap-path-prefix-consts/location-caller.rs @@ -0,0 +1,21 @@ +// Reproducer from https://github.com/rust-lang/rust/issues/148328#issuecomment-3473688412 +#[inline(always)] +pub const fn the_path() -> &'static str { + std::panic::Location::caller().file() +} + +#[inline(never)] +pub fn the_path2() -> &'static str { + const { std::panic::Location::caller().file() } +} + +// Reproducer from https://github.com/rust-lang/rust/issues/148328#issuecomment-3473761194 +pub const fn the_path_len() -> usize { + std::panic::Location::caller().file().len() +} + +pub type Array = [u8; the_path_len()]; + +pub fn the_zeroed_path_len_array() -> Array { + [0; _] +} diff --git a/tests/run-make/remap-path-prefix-consts/rmake.rs b/tests/run-make/remap-path-prefix-consts/rmake.rs new file mode 100644 index 000000000000..02a75aa02278 --- /dev/null +++ b/tests/run-make/remap-path-prefix-consts/rmake.rs @@ -0,0 +1,114 @@ +//@ needs-target-std + +use run_make_support::{bin_name, cwd, run, rustc}; + +fn main() { + // No remapping - relative paths + { + let runner_bin = bin_name("runner-no-remap-rel-paths"); + + let mut location_caller = rustc(); + location_caller.crate_type("lib").input("location-caller.rs"); + location_caller.run(); + + let mut runner = rustc(); + runner.crate_type("bin").input("runner.rs").output(&runner_bin); + runner.run(); + + run(&runner_bin); + } + + // No remapping - absolute paths + { + let runner_bin = bin_name("runner-no-remap-abs-paths"); + + let mut location_caller = rustc(); + location_caller.crate_type("lib").input(cwd().join("location-caller.rs")); + location_caller.run(); + + let mut runner = rustc(); + runner.crate_type("bin").input(cwd().join("runner.rs")).output(&runner_bin); + runner.run(); + + run(&runner_bin); + } + + // No remapping - mixed paths + { + let runner_bin = bin_name("runner-no-remap-mixed-paths"); + + let mut location_caller = rustc(); + location_caller.crate_type("lib").input(cwd().join("location-caller.rs")); + location_caller.run(); + + let mut runner = rustc(); + runner.crate_type("bin").input("runner.rs").output(&runner_bin); + runner.run(); + + run(&runner_bin); + } + + // Remapping current working directory + { + let runner_bin = bin_name("runner-remap-cwd"); + + let mut location_caller = rustc(); + location_caller + .crate_type("lib") + .remap_path_prefix(cwd(), "/remapped") + .input(cwd().join("location-caller.rs")); + location_caller.run(); + + let mut runner = rustc(); + runner + .crate_type("bin") + .remap_path_prefix(cwd(), "/remapped") + .input(cwd().join("runner.rs")) + .output(&runner_bin); + runner.run(); + + run(&runner_bin); + } + + // Remapping current working directory - only in the dependency + { + let runner_bin = bin_name("runner-remap-cwd-only-dep"); + + let mut location_caller = rustc(); + location_caller + .crate_type("lib") + .remap_path_prefix(cwd(), "/remapped") + .input(cwd().join("location-caller.rs")); + location_caller.run(); + + let mut runner = rustc(); + runner.crate_type("bin").input(cwd().join("runner.rs")).output(&runner_bin); + runner.run(); + + run(&runner_bin); + } + + // Remapping current working directory - different scopes + { + let runner_bin = bin_name("runner-remap-cwd-diff-scope"); + + let mut location_caller = rustc(); + location_caller + .crate_type("lib") + .remap_path_prefix(cwd(), "/remapped") + .arg("-Zremap-path-scope=object") + .input(cwd().join("location-caller.rs")); + location_caller.run(); + + let mut runner = rustc(); + runner + .crate_type("bin") + .remap_path_prefix(cwd(), "/remapped") + .arg("-Zremap-path-scope=diagnostics") + .input(cwd().join("runner.rs")) + .output(&runner_bin); + runner.run(); + + run(&runner_bin); + } +} diff --git a/tests/run-make/remap-path-prefix-consts/runner.rs b/tests/run-make/remap-path-prefix-consts/runner.rs new file mode 100644 index 000000000000..d67dbe3b398a --- /dev/null +++ b/tests/run-make/remap-path-prefix-consts/runner.rs @@ -0,0 +1,19 @@ +// Verifies that the paths are the same and consistent between this crate and location_caller crate. +// +// https://github.com/rust-lang/rust/issues/148328 + +extern crate location_caller; + +fn main() { + { + // Assert both paths are the same + let the_path = location_caller::the_path(); + let the_path2 = location_caller::the_path2(); + assert_eq!(the_path, the_path2); + } + + { + // Let's make sure we don't read OOB memory + println!("{:?}", location_caller::the_zeroed_path_len_array()); + } +}