Skip to content

Commit b206ca0

Browse files
committed
Auto merge of rust-lang#140716 - Urgau:improve-remap_scope-tests, r=<try>
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
2 parents 1973872 + f959039 commit b206ca0

27 files changed

+292
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//@ compile-flags: --remap-path-prefix={{src-base}}=remapped
2+
//@ compile-flags: -Zremap-path-scope=debuginfo
3+
4+
#[macro_export]
5+
macro_rules! my_file {
6+
() => { file!() }
7+
}
8+
9+
pub fn file() -> &'static str {
10+
file!()
11+
}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//@ compile-flags: --remap-path-prefix={{src-base}}=remapped
2+
//@ compile-flags: -Zremap-path-scope=diagnostics
3+
4+
#[macro_export]
5+
macro_rules! my_file {
6+
() => { file!() }
7+
}
8+
9+
pub fn file() -> &'static str {
10+
file!()
11+
}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//@ compile-flags: --remap-path-prefix={{src-base}}=remapped
2+
//@ compile-flags: -Zremap-path-scope=macro
3+
4+
#[macro_export]
5+
macro_rules! my_file {
6+
() => { file!() }
7+
}
8+
9+
pub fn file() -> &'static str {
10+
file!()
11+
}

tests/ui/errors/auxiliary/file.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#[macro_export]
2+
macro_rules! my_file {
3+
() => { file!() }
4+
}
5+
6+
pub fn file() -> &'static str {
7+
file!()
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//@ compile-flags: --remap-path-prefix={{src-base}}=remapped
2+
//@ compile-flags: -Zremap-path-scope=debuginfo
3+
4+
pub trait Trait: std::fmt::Display {}
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//@ compile-flags: --remap-path-prefix={{src-base}}=remapped
2+
//@ compile-flags: -Zremap-path-scope=diagnostics
3+
4+
pub trait Trait: std::fmt::Display {}
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//@ compile-flags: --remap-path-prefix={{src-base}}=remapped
2+
//@ compile-flags: -Zremap-path-scope=macro
3+
4+
pub trait Trait: std::fmt::Display {}

tests/ui/errors/auxiliary/trait.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub trait Trait: std::fmt::Display {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0277]: `A` doesn't implement `std::fmt::Display`
2+
--> remapped/errors/remap-path-prefix-diagnostics.rs:LL:COL
3+
|
4+
LL | impl r#trait::Trait for A {}
5+
| ^ `A` cannot be formatted with the default formatter
6+
|
7+
= help: the trait `std::fmt::Display` is not implemented for `A`
8+
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
9+
note: required by a bound in `Trait`
10+
--> $DIR/auxiliary/trait.rs:LL:COL
11+
|
12+
LL | pub trait Trait: std::fmt::Display {}
13+
| ^^^^^^^^^^^^^^^^^ required by this bound in `Trait`
14+
15+
error: aborting due to 1 previous error
16+
17+
For more information about this error, try `rustc --explain E0277`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0277]: `A` doesn't implement `std::fmt::Display`
2+
--> $DIR/remap-path-prefix-diagnostics.rs:LL:COL
3+
|
4+
LL | impl r#trait::Trait for A {}
5+
| ^ `A` cannot be formatted with the default formatter
6+
|
7+
= help: the trait `std::fmt::Display` is not implemented for `A`
8+
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
9+
note: required by a bound in `Trait`
10+
--> $DIR/auxiliary/trait-debuginfo.rs:LL:COL
11+
|
12+
LL | pub trait Trait: std::fmt::Display {}
13+
| ^^^^^^^^^^^^^^^^^ required by this bound in `Trait`
14+
15+
error: aborting due to 1 previous error
16+
17+
For more information about this error, try `rustc --explain E0277`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0277]: `A` doesn't implement `std::fmt::Display`
2+
--> $DIR/remap-path-prefix-diagnostics.rs:LL:COL
3+
|
4+
LL | impl r#trait::Trait for A {}
5+
| ^ `A` cannot be formatted with the default formatter
6+
|
7+
= help: the trait `std::fmt::Display` is not implemented for `A`
8+
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
9+
note: required by a bound in `Trait`
10+
--> $DIR/auxiliary/trait-diag.rs:LL:COL
11+
|
12+
LL | pub trait Trait: std::fmt::Display {}
13+
| ^^^^^^^^^^^^^^^^^ required by this bound in `Trait`
14+
15+
error: aborting due to 1 previous error
16+
17+
For more information about this error, try `rustc --explain E0277`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0277]: `A` doesn't implement `std::fmt::Display`
2+
--> $DIR/remap-path-prefix-diagnostics.rs:LL:COL
3+
|
4+
LL | impl r#trait::Trait for A {}
5+
| ^ `A` cannot be formatted with the default formatter
6+
|
7+
= help: the trait `std::fmt::Display` is not implemented for `A`
8+
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
9+
note: required by a bound in `Trait`
10+
--> $DIR/auxiliary/trait-macro.rs:LL:COL
11+
|
12+
LL | pub trait Trait: std::fmt::Display {}
13+
| ^^^^^^^^^^^^^^^^^ required by this bound in `Trait`
14+
15+
error: aborting due to 1 previous error
16+
17+
For more information about this error, try `rustc --explain E0277`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// This test exercises `-Zremap-path-scope`, diagnostics printing paths and dependency.
2+
//
3+
// We test different combinations with/without remap in deps, with/without remap in this
4+
// crate but always in deps and always here but never in deps.
5+
6+
//@ revisions: with-diag-in-deps with-macro-in-deps with-debuginfo-in-deps
7+
//@ revisions: only-diag-in-deps only-macro-in-deps only-debuginfo-in-deps
8+
//@ revisions: not-diag-in-deps
9+
10+
//@[with-diag-in-deps] compile-flags: --remap-path-prefix={{src-base}}=remapped
11+
//@[with-macro-in-deps] compile-flags: --remap-path-prefix={{src-base}}=remapped
12+
//@[with-debuginfo-in-deps] compile-flags: --remap-path-prefix={{src-base}}=remapped
13+
//@[not-diag-in-deps] compile-flags: --remap-path-prefix={{src-base}}=remapped
14+
15+
//@[with-diag-in-deps] compile-flags: -Zremap-path-scope=diagnostics
16+
//@[with-macro-in-deps] compile-flags: -Zremap-path-scope=macro
17+
//@[with-debuginfo-in-deps] compile-flags: -Zremap-path-scope=debuginfo
18+
//@[not-diag-in-deps] compile-flags: -Zremap-path-scope=diagnostics
19+
20+
//@[with-diag-in-deps] aux-build:trait-diag.rs
21+
//@[with-macro-in-deps] aux-build:trait-macro.rs
22+
//@[with-debuginfo-in-deps] aux-build:trait-debuginfo.rs
23+
//@[only-diag-in-deps] aux-build:trait-diag.rs
24+
//@[only-macro-in-deps] aux-build:trait-macro.rs
25+
//@[only-debuginfo-in-deps] aux-build:trait-debuginfo.rs
26+
//@[not-diag-in-deps] aux-build:trait.rs
27+
28+
// The $SRC_DIR*.rs:LL:COL normalisation doesn't kick in automatically
29+
// as the remapped revision will not begin with $SRC_DIR_REAL,
30+
// so we have to do it ourselves.
31+
//@ normalize-stderr: ".rs:\d+:\d+" -> ".rs:LL:COL"
32+
33+
#[cfg(any(with_diag_in_deps, only_diag_in_deps))]
34+
extern crate trait_diag as r#trait;
35+
36+
#[cfg(any(with_macro_in_deps, only_macro_in_deps))]
37+
extern crate trait_macro as r#trait;
38+
39+
#[cfg(any(with_debuginfo_in_deps, only_debuginfo_in_deps))]
40+
extern crate trait_debuginfo as r#trait;
41+
42+
#[cfg(not_diag_in_deps)]
43+
extern crate r#trait as r#trait;
44+
45+
struct A;
46+
47+
impl r#trait::Trait for A {}
48+
//[with-macro-in-deps]~^ ERROR `A` doesn't implement `std::fmt::Display`
49+
//[with-debuginfo-in-deps]~^^ ERROR `A` doesn't implement `std::fmt::Display`
50+
//[only-diag-in-deps]~^^^ ERROR `A` doesn't implement `std::fmt::Display`
51+
//[only-macro-in-deps]~^^^^ ERROR `A` doesn't implement `std::fmt::Display`
52+
//[only-debuginfo-in-deps]~^^^^^ ERROR `A` doesn't implement `std::fmt::Display`
53+
54+
//[with-diag-in-deps]~? ERROR `A` doesn't implement `std::fmt::Display`
55+
//[not-diag-in-deps]~? ERROR `A` doesn't implement `std::fmt::Display`
56+
57+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0277]: `A` doesn't implement `std::fmt::Display`
2+
--> $DIR/remap-path-prefix-diagnostics.rs:LL:COL
3+
|
4+
LL | impl r#trait::Trait for A {}
5+
| ^ `A` cannot be formatted with the default formatter
6+
|
7+
= help: the trait `std::fmt::Display` is not implemented for `A`
8+
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
9+
note: required by a bound in `Trait`
10+
--> $DIR/auxiliary/trait-debuginfo.rs:LL:COL
11+
|
12+
LL | pub trait Trait: std::fmt::Display {}
13+
| ^^^^^^^^^^^^^^^^^ required by this bound in `Trait`
14+
15+
error: aborting due to 1 previous error
16+
17+
For more information about this error, try `rustc --explain E0277`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0277]: `A` doesn't implement `std::fmt::Display`
2+
--> remapped/errors/remap-path-prefix-diagnostics.rs:LL:COL
3+
|
4+
LL | impl r#trait::Trait for A {}
5+
| ^ `A` cannot be formatted with the default formatter
6+
|
7+
= help: the trait `std::fmt::Display` is not implemented for `A`
8+
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
9+
note: required by a bound in `Trait`
10+
--> remapped/errors/auxiliary/trait-diag.rs:LL:COL
11+
|
12+
LL | pub trait Trait: std::fmt::Display {}
13+
| ^^^^^^^^^^^^^^^^^ required by this bound in `Trait`
14+
15+
error: aborting due to 1 previous error
16+
17+
For more information about this error, try `rustc --explain E0277`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0277]: `A` doesn't implement `std::fmt::Display`
2+
--> $DIR/remap-path-prefix-diagnostics.rs:LL:COL
3+
|
4+
LL | impl r#trait::Trait for A {}
5+
| ^ `A` cannot be formatted with the default formatter
6+
|
7+
= help: the trait `std::fmt::Display` is not implemented for `A`
8+
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
9+
note: required by a bound in `Trait`
10+
--> $DIR/auxiliary/trait-macro.rs:LL:COL
11+
|
12+
LL | pub trait Trait: std::fmt::Display {}
13+
| ^^^^^^^^^^^^^^^^^ required by this bound in `Trait`
14+
15+
error: aborting due to 1 previous error
16+
17+
For more information about this error, try `rustc --explain E0277`.

tests/ui/errors/remap-path-prefix-macro.normal.run.stdout

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
file::my_file!() = remapped/errors/remap-path-prefix-macro.rs
2+
file::file() = $DIR/auxiliary/file.rs
3+
file!() = remapped/errors/remap-path-prefix-macro.rs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
file::my_file!() = $DIR/remap-path-prefix-macro.rs
2+
file::file() = $DIR/auxiliary/file-debuginfo.rs
3+
file!() = $DIR/remap-path-prefix-macro.rs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
file::my_file!() = $DIR/remap-path-prefix-macro.rs
2+
file::file() = $DIR/auxiliary/file-diag.rs
3+
file!() = $DIR/remap-path-prefix-macro.rs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
file::my_file!() = $DIR/remap-path-prefix-macro.rs
2+
file::file() = remapped/errors/auxiliary/file-macro.rs
3+
file!() = $DIR/remap-path-prefix-macro.rs
+41-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,47 @@
1+
// This test exercises `-Zremap-path-scope`, macros (like file!()) and dependency.
2+
//
3+
// We test different combinations with/without remap in deps, with/without remap in
4+
// this crate but always in deps and always here but never in deps.
5+
16
//@ run-pass
27
//@ check-run-results
38

4-
//@ revisions: normal with-macro-scope without-macro-scope
5-
//@ compile-flags: --remap-path-prefix={{src-base}}=remapped
6-
//@ [with-macro-scope]compile-flags: -Zremap-path-scope=macro,diagnostics
7-
//@ [without-macro-scope]compile-flags: -Zremap-path-scope=diagnostics
8-
// no-remap-src-base: Manually remap, so the remapped path remains in .stderr file.
9+
//@ revisions: with-diag-in-deps with-macro-in-deps with-debuginfo-in-deps
10+
//@ revisions: only-diag-in-deps only-macro-in-deps only-debuginfo-in-deps
11+
//@ revisions: not-macro-in-deps
12+
13+
//@[with-diag-in-deps] compile-flags: --remap-path-prefix={{src-base}}=remapped
14+
//@[with-macro-in-deps] compile-flags: --remap-path-prefix={{src-base}}=remapped
15+
//@[with-debuginfo-in-deps] compile-flags: --remap-path-prefix={{src-base}}=remapped
16+
//@[not-macro-in-deps] compile-flags: --remap-path-prefix={{src-base}}=remapped
17+
18+
//@[with-diag-in-deps] compile-flags: -Zremap-path-scope=diagnostics
19+
//@[with-macro-in-deps] compile-flags: -Zremap-path-scope=macro
20+
//@[with-debuginfo-in-deps] compile-flags: -Zremap-path-scope=debuginfo
21+
//@[not-macro-in-deps] compile-flags: -Zremap-path-scope=macro
22+
23+
//@[with-diag-in-deps] aux-build:file-diag.rs
24+
//@[with-macro-in-deps] aux-build:file-macro.rs
25+
//@[with-debuginfo-in-deps] aux-build:file-debuginfo.rs
26+
//@[only-diag-in-deps] aux-build:file-diag.rs
27+
//@[only-macro-in-deps] aux-build:file-macro.rs
28+
//@[only-debuginfo-in-deps] aux-build:file-debuginfo.rs
29+
//@[not-macro-in-deps] aux-build:file.rs
30+
31+
#[cfg(any(with_diag_in_deps, only_diag_in_deps))]
32+
extern crate file_diag as file;
33+
34+
#[cfg(any(with_macro_in_deps, only_macro_in_deps))]
35+
extern crate file_macro as file;
36+
37+
#[cfg(any(with_debuginfo_in_deps, only_debuginfo_in_deps))]
38+
extern crate file_debuginfo as file;
39+
40+
#[cfg(not_macro_in_deps)]
41+
extern crate file;
942

1043
fn main() {
11-
println!("{}", file!());
44+
println!("file::my_file!() = {}", file::my_file!());
45+
println!("file::file() = {}", file::file());
46+
println!("file!() = {}", file!());
1247
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
file::my_file!() = $DIR/remap-path-prefix-macro.rs
2+
file::file() = $DIR/auxiliary/file-debuginfo.rs
3+
file!() = $DIR/remap-path-prefix-macro.rs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
file::my_file!() = $DIR/remap-path-prefix-macro.rs
2+
file::file() = $DIR/auxiliary/file-diag.rs
3+
file!() = $DIR/remap-path-prefix-macro.rs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
file::my_file!() = remapped/errors/remap-path-prefix-macro.rs
2+
file::file() = remapped/errors/auxiliary/file-macro.rs
3+
file!() = remapped/errors/remap-path-prefix-macro.rs

tests/ui/errors/remap-path-prefix-macro.with-macro-scope.run.stdout

-1
This file was deleted.

tests/ui/errors/remap-path-prefix-macro.without-macro-scope.run.stdout

-1
This file was deleted.

0 commit comments

Comments
 (0)