Add regression test for Location::caller() in consts across crates
This commit is contained in:
parent
b1eb21bb85
commit
8b035e473a
3 changed files with 154 additions and 0 deletions
21
tests/run-make/remap-path-prefix-consts/location-caller.rs
Normal file
21
tests/run-make/remap-path-prefix-consts/location-caller.rs
Normal file
|
|
@ -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; _]
|
||||
}
|
||||
114
tests/run-make/remap-path-prefix-consts/rmake.rs
Normal file
114
tests/run-make/remap-path-prefix-consts/rmake.rs
Normal file
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
19
tests/run-make/remap-path-prefix-consts/runner.rs
Normal file
19
tests/run-make/remap-path-prefix-consts/runner.rs
Normal file
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue