Rollup merge of #140716 - Urgau:improve-remap_scope-tests, r=jieyouxu

Improve `-Zremap-path-scope` tests with dependency

This PR greatly improves our coverage of `-Zremap-path-scope` for diagnostic paths and macros with dependencies.

r? `@jieyouxu` (since we talked about it)

try-job: x86_64-msvc-1
This commit is contained in:
Matthias Krüger
2025-05-08 20:22:20 +02:00
committed by GitHub
27 changed files with 292 additions and 9 deletions
@@ -0,0 +1,11 @@
//@ compile-flags: --remap-path-prefix={{src-base}}=remapped
//@ compile-flags: -Zremap-path-scope=debuginfo
#[macro_export]
macro_rules! my_file {
() => { file!() }
}
pub fn file() -> &'static str {
file!()
}
+11
View File
@@ -0,0 +1,11 @@
//@ compile-flags: --remap-path-prefix={{src-base}}=remapped
//@ compile-flags: -Zremap-path-scope=diagnostics
#[macro_export]
macro_rules! my_file {
() => { file!() }
}
pub fn file() -> &'static str {
file!()
}
+11
View File
@@ -0,0 +1,11 @@
//@ compile-flags: --remap-path-prefix={{src-base}}=remapped
//@ compile-flags: -Zremap-path-scope=macro
#[macro_export]
macro_rules! my_file {
() => { file!() }
}
pub fn file() -> &'static str {
file!()
}
+8
View File
@@ -0,0 +1,8 @@
#[macro_export]
macro_rules! my_file {
() => { file!() }
}
pub fn file() -> &'static str {
file!()
}
@@ -0,0 +1,4 @@
//@ compile-flags: --remap-path-prefix={{src-base}}=remapped
//@ compile-flags: -Zremap-path-scope=debuginfo
pub trait Trait: std::fmt::Display {}
+4
View File
@@ -0,0 +1,4 @@
//@ compile-flags: --remap-path-prefix={{src-base}}=remapped
//@ compile-flags: -Zremap-path-scope=diagnostics
pub trait Trait: std::fmt::Display {}
+4
View File
@@ -0,0 +1,4 @@
//@ compile-flags: --remap-path-prefix={{src-base}}=remapped
//@ compile-flags: -Zremap-path-scope=macro
pub trait Trait: std::fmt::Display {}
+1
View File
@@ -0,0 +1 @@
pub trait Trait: std::fmt::Display {}
@@ -0,0 +1,17 @@
error[E0277]: `A` doesn't implement `std::fmt::Display`
--> remapped/errors/remap-path-prefix-diagnostics.rs:LL:COL
|
LL | impl r#trait::Trait for A {}
| ^ `A` cannot be formatted with the default formatter
|
= help: the trait `std::fmt::Display` is not implemented for `A`
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
note: required by a bound in `Trait`
--> $DIR/auxiliary/trait.rs:LL:COL
|
LL | pub trait Trait: std::fmt::Display {}
| ^^^^^^^^^^^^^^^^^ required by this bound in `Trait`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0277`.
@@ -0,0 +1,17 @@
error[E0277]: `A` doesn't implement `std::fmt::Display`
--> $DIR/remap-path-prefix-diagnostics.rs:LL:COL
|
LL | impl r#trait::Trait for A {}
| ^ `A` cannot be formatted with the default formatter
|
= help: the trait `std::fmt::Display` is not implemented for `A`
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
note: required by a bound in `Trait`
--> $DIR/auxiliary/trait-debuginfo.rs:LL:COL
|
LL | pub trait Trait: std::fmt::Display {}
| ^^^^^^^^^^^^^^^^^ required by this bound in `Trait`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0277`.
@@ -0,0 +1,17 @@
error[E0277]: `A` doesn't implement `std::fmt::Display`
--> $DIR/remap-path-prefix-diagnostics.rs:LL:COL
|
LL | impl r#trait::Trait for A {}
| ^ `A` cannot be formatted with the default formatter
|
= help: the trait `std::fmt::Display` is not implemented for `A`
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
note: required by a bound in `Trait`
--> $DIR/auxiliary/trait-diag.rs:LL:COL
|
LL | pub trait Trait: std::fmt::Display {}
| ^^^^^^^^^^^^^^^^^ required by this bound in `Trait`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0277`.
@@ -0,0 +1,17 @@
error[E0277]: `A` doesn't implement `std::fmt::Display`
--> $DIR/remap-path-prefix-diagnostics.rs:LL:COL
|
LL | impl r#trait::Trait for A {}
| ^ `A` cannot be formatted with the default formatter
|
= help: the trait `std::fmt::Display` is not implemented for `A`
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
note: required by a bound in `Trait`
--> $DIR/auxiliary/trait-macro.rs:LL:COL
|
LL | pub trait Trait: std::fmt::Display {}
| ^^^^^^^^^^^^^^^^^ required by this bound in `Trait`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0277`.
@@ -0,0 +1,57 @@
// This test exercises `-Zremap-path-scope`, diagnostics printing paths and dependency.
//
// We test different combinations with/without remap in deps, with/without remap in this
// crate but always in deps and always here but never in deps.
//@ revisions: with-diag-in-deps with-macro-in-deps with-debuginfo-in-deps
//@ revisions: only-diag-in-deps only-macro-in-deps only-debuginfo-in-deps
//@ revisions: not-diag-in-deps
//@[with-diag-in-deps] compile-flags: --remap-path-prefix={{src-base}}=remapped
//@[with-macro-in-deps] compile-flags: --remap-path-prefix={{src-base}}=remapped
//@[with-debuginfo-in-deps] compile-flags: --remap-path-prefix={{src-base}}=remapped
//@[not-diag-in-deps] compile-flags: --remap-path-prefix={{src-base}}=remapped
//@[with-diag-in-deps] compile-flags: -Zremap-path-scope=diagnostics
//@[with-macro-in-deps] compile-flags: -Zremap-path-scope=macro
//@[with-debuginfo-in-deps] compile-flags: -Zremap-path-scope=debuginfo
//@[not-diag-in-deps] compile-flags: -Zremap-path-scope=diagnostics
//@[with-diag-in-deps] aux-build:trait-diag.rs
//@[with-macro-in-deps] aux-build:trait-macro.rs
//@[with-debuginfo-in-deps] aux-build:trait-debuginfo.rs
//@[only-diag-in-deps] aux-build:trait-diag.rs
//@[only-macro-in-deps] aux-build:trait-macro.rs
//@[only-debuginfo-in-deps] aux-build:trait-debuginfo.rs
//@[not-diag-in-deps] aux-build:trait.rs
// The $SRC_DIR*.rs:LL:COL normalisation doesn't kick in automatically
// as the remapped revision will not begin with $SRC_DIR_REAL,
// so we have to do it ourselves.
//@ normalize-stderr: ".rs:\d+:\d+" -> ".rs:LL:COL"
#[cfg(any(with_diag_in_deps, only_diag_in_deps))]
extern crate trait_diag as r#trait;
#[cfg(any(with_macro_in_deps, only_macro_in_deps))]
extern crate trait_macro as r#trait;
#[cfg(any(with_debuginfo_in_deps, only_debuginfo_in_deps))]
extern crate trait_debuginfo as r#trait;
#[cfg(not_diag_in_deps)]
extern crate r#trait as r#trait;
struct A;
impl r#trait::Trait for A {}
//[with-macro-in-deps]~^ ERROR `A` doesn't implement `std::fmt::Display`
//[with-debuginfo-in-deps]~^^ ERROR `A` doesn't implement `std::fmt::Display`
//[only-diag-in-deps]~^^^ ERROR `A` doesn't implement `std::fmt::Display`
//[only-macro-in-deps]~^^^^ ERROR `A` doesn't implement `std::fmt::Display`
//[only-debuginfo-in-deps]~^^^^^ ERROR `A` doesn't implement `std::fmt::Display`
//[with-diag-in-deps]~? ERROR `A` doesn't implement `std::fmt::Display`
//[not-diag-in-deps]~? ERROR `A` doesn't implement `std::fmt::Display`
fn main() {}
@@ -0,0 +1,17 @@
error[E0277]: `A` doesn't implement `std::fmt::Display`
--> $DIR/remap-path-prefix-diagnostics.rs:LL:COL
|
LL | impl r#trait::Trait for A {}
| ^ `A` cannot be formatted with the default formatter
|
= help: the trait `std::fmt::Display` is not implemented for `A`
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
note: required by a bound in `Trait`
--> $DIR/auxiliary/trait-debuginfo.rs:LL:COL
|
LL | pub trait Trait: std::fmt::Display {}
| ^^^^^^^^^^^^^^^^^ required by this bound in `Trait`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0277`.
@@ -0,0 +1,17 @@
error[E0277]: `A` doesn't implement `std::fmt::Display`
--> remapped/errors/remap-path-prefix-diagnostics.rs:LL:COL
|
LL | impl r#trait::Trait for A {}
| ^ `A` cannot be formatted with the default formatter
|
= help: the trait `std::fmt::Display` is not implemented for `A`
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
note: required by a bound in `Trait`
--> remapped/errors/auxiliary/trait-diag.rs:LL:COL
|
LL | pub trait Trait: std::fmt::Display {}
| ^^^^^^^^^^^^^^^^^ required by this bound in `Trait`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0277`.
@@ -0,0 +1,17 @@
error[E0277]: `A` doesn't implement `std::fmt::Display`
--> $DIR/remap-path-prefix-diagnostics.rs:LL:COL
|
LL | impl r#trait::Trait for A {}
| ^ `A` cannot be formatted with the default formatter
|
= help: the trait `std::fmt::Display` is not implemented for `A`
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
note: required by a bound in `Trait`
--> $DIR/auxiliary/trait-macro.rs:LL:COL
|
LL | pub trait Trait: std::fmt::Display {}
| ^^^^^^^^^^^^^^^^^ required by this bound in `Trait`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0277`.
@@ -1 +0,0 @@
remapped/errors/remap-path-prefix-macro.rs
@@ -0,0 +1,3 @@
file::my_file!() = remapped/errors/remap-path-prefix-macro.rs
file::file() = $DIR/auxiliary/file.rs
file!() = remapped/errors/remap-path-prefix-macro.rs
@@ -0,0 +1,3 @@
file::my_file!() = $DIR/remap-path-prefix-macro.rs
file::file() = $DIR/auxiliary/file-debuginfo.rs
file!() = $DIR/remap-path-prefix-macro.rs
@@ -0,0 +1,3 @@
file::my_file!() = $DIR/remap-path-prefix-macro.rs
file::file() = $DIR/auxiliary/file-diag.rs
file!() = $DIR/remap-path-prefix-macro.rs
@@ -0,0 +1,3 @@
file::my_file!() = $DIR/remap-path-prefix-macro.rs
file::file() = remapped/errors/auxiliary/file-macro.rs
file!() = $DIR/remap-path-prefix-macro.rs
+41 -6
View File
@@ -1,12 +1,47 @@
// This test exercises `-Zremap-path-scope`, macros (like file!()) and dependency.
//
// We test different combinations with/without remap in deps, with/without remap in
// this crate but always in deps and always here but never in deps.
//@ run-pass
//@ check-run-results
//@ revisions: normal with-macro-scope without-macro-scope
//@ compile-flags: --remap-path-prefix={{src-base}}=remapped
//@ [with-macro-scope]compile-flags: -Zremap-path-scope=macro,diagnostics
//@ [without-macro-scope]compile-flags: -Zremap-path-scope=diagnostics
// no-remap-src-base: Manually remap, so the remapped path remains in .stderr file.
//@ revisions: with-diag-in-deps with-macro-in-deps with-debuginfo-in-deps
//@ revisions: only-diag-in-deps only-macro-in-deps only-debuginfo-in-deps
//@ revisions: not-macro-in-deps
//@[with-diag-in-deps] compile-flags: --remap-path-prefix={{src-base}}=remapped
//@[with-macro-in-deps] compile-flags: --remap-path-prefix={{src-base}}=remapped
//@[with-debuginfo-in-deps] compile-flags: --remap-path-prefix={{src-base}}=remapped
//@[not-macro-in-deps] compile-flags: --remap-path-prefix={{src-base}}=remapped
//@[with-diag-in-deps] compile-flags: -Zremap-path-scope=diagnostics
//@[with-macro-in-deps] compile-flags: -Zremap-path-scope=macro
//@[with-debuginfo-in-deps] compile-flags: -Zremap-path-scope=debuginfo
//@[not-macro-in-deps] compile-flags: -Zremap-path-scope=macro
//@[with-diag-in-deps] aux-build:file-diag.rs
//@[with-macro-in-deps] aux-build:file-macro.rs
//@[with-debuginfo-in-deps] aux-build:file-debuginfo.rs
//@[only-diag-in-deps] aux-build:file-diag.rs
//@[only-macro-in-deps] aux-build:file-macro.rs
//@[only-debuginfo-in-deps] aux-build:file-debuginfo.rs
//@[not-macro-in-deps] aux-build:file.rs
#[cfg(any(with_diag_in_deps, only_diag_in_deps))]
extern crate file_diag as file;
#[cfg(any(with_macro_in_deps, only_macro_in_deps))]
extern crate file_macro as file;
#[cfg(any(with_debuginfo_in_deps, only_debuginfo_in_deps))]
extern crate file_debuginfo as file;
#[cfg(not_macro_in_deps)]
extern crate file;
fn main() {
println!("{}", file!());
println!("file::my_file!() = {}", file::my_file!());
println!("file::file() = {}", file::file());
println!("file!() = {}", file!());
}
@@ -0,0 +1,3 @@
file::my_file!() = $DIR/remap-path-prefix-macro.rs
file::file() = $DIR/auxiliary/file-debuginfo.rs
file!() = $DIR/remap-path-prefix-macro.rs
@@ -0,0 +1,3 @@
file::my_file!() = $DIR/remap-path-prefix-macro.rs
file::file() = $DIR/auxiliary/file-diag.rs
file!() = $DIR/remap-path-prefix-macro.rs
@@ -0,0 +1,3 @@
file::my_file!() = remapped/errors/remap-path-prefix-macro.rs
file::file() = remapped/errors/auxiliary/file-macro.rs
file!() = remapped/errors/remap-path-prefix-macro.rs
@@ -1 +0,0 @@
remapped/errors/remap-path-prefix-macro.rs
@@ -1 +0,0 @@
$DIR/remap-path-prefix-macro.rs