Skip to content

Commit 410e283

Browse files
committed
fix #71363 test by adding -Z translate-remapped-path-to-local-path=no
The test relies on library/std/src/error.rs not corresponding to a local path, but remapping might still find the related local file of a remapped path. To fix the test, this adds a new -Z flag to disable finding the corresponding local path of a remapped path.
1 parent 6609c67 commit 410e283

File tree

5 files changed

+22
-8
lines changed

5 files changed

+22
-8
lines changed

compiler/rustc_interface/src/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,7 @@ fn test_debugging_options_tracking_hash() {
790790
tracked!(thinlto, Some(true));
791791
tracked!(thir_unsafeck, true);
792792
tracked!(tls_model, Some(TlsModel::GeneralDynamic));
793+
tracked!(translate_remapped_path_to_local_path, false);
793794
tracked!(trap_unreachable, Some(false));
794795
tracked!(treat_err_as_bug, NonZeroUsize::new(1));
795796
tracked!(tune_cpu, Some(String::from("abc")));

compiler/rustc_metadata/src/rmeta/decoder.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1486,6 +1486,8 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
14861486
.filter(|_| {
14871487
// Only spend time on further checks if we have what to translate *to*.
14881488
sess.opts.real_rust_source_base_dir.is_some()
1489+
// Some tests need the translation to be always skipped.
1490+
&& sess.opts.debugging_opts.translate_remapped_path_to_local_path
14891491
})
14901492
.filter(|virtual_dir| {
14911493
// Don't translate away `/rustc/$hash` if we're still remapping to it,

compiler/rustc_session/src/options.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1546,6 +1546,8 @@ options! {
15461546
"choose the TLS model to use (`rustc --print tls-models` for details)"),
15471547
trace_macros: bool = (false, parse_bool, [UNTRACKED],
15481548
"for every macro invocation, print its name and arguments (default: no)"),
1549+
translate_remapped_path_to_local_path: bool = (true, parse_bool, [TRACKED],
1550+
"translate remapped paths into local paths when possible (default: yes)"),
15491551
trap_unreachable: Option<bool> = (None, parse_opt_bool, [TRACKED],
15501552
"generate trap instructions for unreachable intrinsics (default: use target setting, usually yes)"),
15511553
treat_err_as_bug: Option<NonZeroUsize> = (None, parse_treat_err_as_bug, [TRACKED],

src/test/ui/span/issue-71363.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1-
// compile-flags: -Z simulate-remapped-rust-src-base=/rustc/xyz -Z ui-testing=no
2-
// only-x86_64-unknown-linux-gnu
3-
//---^ Limiting target as the above unstable flags don't play well on some environment.
1+
// compile-flags: -Z simulate-remapped-rust-src-base=/rustc/xyz -Z translate-remapped-path-to-local-path=no -Z ui-testing=no
42

53
struct MyError;
64
impl std::error::Error for MyError {}
75
//~^ ERROR: `MyError` doesn't implement `std::fmt::Display`
86
//~| ERROR: `MyError` doesn't implement `Debug`
97

108
fn main() {}
9+
10+
// This test relies on library/std/src/error.rs *not* being included in the error message, so that
11+
// we can test whether a file not included in the error message affects it (more specifically
12+
// whether the line number of the excluded file affects the indentation of the other line numbers).
13+
//
14+
// To test this we're simulating a remap of the rust src base (so that library/std/src/error.rs
15+
// does not point to a local file) *and* we're disabling the code to try mapping a remapped path to
16+
// a local file (which would defeat the purpose of the former flag).
17+
//
18+
// Note that this comment is at the bottom of the file intentionally, as we need the line number of
19+
// the impl to be lower than 10.

src/test/ui/span/issue-71363.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
error[E0277]: `MyError` doesn't implement `std::fmt::Display`
2-
--> $DIR/issue-71363.rs:6:6
2+
--> $DIR/issue-71363.rs:4:6
33
|
4-
6 | impl std::error::Error for MyError {}
4+
4 | impl std::error::Error for MyError {}
55
| ^^^^^^^^^^^^^^^^^ `MyError` cannot be formatted with the default formatter
66
|
77
= help: the trait `std::fmt::Display` is not implemented for `MyError`
88
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
99
note: required by a bound in `std::error::Error`
1010

1111
error[E0277]: `MyError` doesn't implement `Debug`
12-
--> $DIR/issue-71363.rs:6:6
12+
--> $DIR/issue-71363.rs:4:6
1313
|
14-
6 | impl std::error::Error for MyError {}
14+
4 | impl std::error::Error for MyError {}
1515
| ^^^^^^^^^^^^^^^^^ `MyError` cannot be formatted using `{:?}`
1616
|
1717
= help: the trait `Debug` is not implemented for `MyError`
1818
= note: add `#[derive(Debug)]` to `MyError` or manually `impl Debug for MyError`
1919
note: required by a bound in `std::error::Error`
2020
help: consider annotating `MyError` with `#[derive(Debug)]`
2121
|
22-
5 | #[derive(Debug)]
22+
3 | #[derive(Debug)]
2323
|
2424

2525
error: aborting due to 2 previous errors

0 commit comments

Comments
 (0)