Skip to content

Improve -Zremap-path-scope tests with dependency #140716

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

Merged
merged 2 commits into from
May 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions tests/ui/errors/auxiliary/file-debuginfo.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 11 additions & 0 deletions tests/ui/errors/auxiliary/file-diag.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 11 additions & 0 deletions tests/ui/errors/auxiliary/file-macro.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 8 additions & 0 deletions tests/ui/errors/auxiliary/file.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#[macro_export]
macro_rules! my_file {
() => { file!() }
}

pub fn file() -> &'static str {
file!()
}
4 changes: 4 additions & 0 deletions tests/ui/errors/auxiliary/trait-debuginfo.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 4 additions & 0 deletions tests/ui/errors/auxiliary/trait-diag.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 4 additions & 0 deletions tests/ui/errors/auxiliary/trait-macro.rs
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions tests/ui/errors/auxiliary/trait.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub trait Trait: std::fmt::Display {}
Original file line number Diff line number Diff line change
@@ -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`.
Original file line number Diff line number Diff line change
@@ -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`.
Original file line number Diff line number Diff line change
@@ -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`.
Original file line number Diff line number Diff line change
@@ -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`.
57 changes: 57 additions & 0 deletions tests/ui/errors/remap-path-prefix-diagnostics.rs
Original file line number Diff line number Diff line change
@@ -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() {}
Original file line number Diff line number Diff line change
@@ -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`.
Original file line number Diff line number Diff line change
@@ -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`.
Original file line number Diff line number Diff line change
@@ -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 change: 0 additions & 1 deletion tests/ui/errors/remap-path-prefix-macro.normal.run.stdout

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
47 changes: 41 additions & 6 deletions tests/ui/errors/remap-path-prefix-macro.rs
Original file line number Diff line number Diff line change
@@ -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!());
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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

This file was deleted.

This file was deleted.

Loading