Skip to content

Commit 157d936

Browse files
committed
Stop normalizing so many different prefixes
Previously, we would normalize *all* of - the absolute path to the repository checkout - the /rustc/$sha for stage1 (if `remap-debuginfo` was enabled) - the /rustc/$sha for download-rustc - the sysroot for download-rustc Now, we consistently only normalize /rustc/FAKE_PREFIX. Not only is this much simpler, but it also avoids ongoing maintenance for download-rustc and makes it much less likely that tests break by accident. - Change `tests/ui/track-diagnostics/track6.rs` to use a relative path instead of an absolute one. I am not actually sure why `track_caller` works here, but it does seem to work 🤷 - Pass `-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX` to all suites, not just UI. In particular, mir-opt tests emit /rustc/ paths in their output.
1 parent eb9da7b commit 157d936

File tree

4 files changed

+20
-34
lines changed

4 files changed

+20
-34
lines changed

compiler/rustc_session/src/parse.rs

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ impl SymbolGallery {
8484

8585
/// Construct a diagnostic for a language feature error due to the given `span`.
8686
/// The `feature`'s `Symbol` is the one you used in `active.rs` and `rustc_span::symbols`.
87+
#[track_caller]
8788
pub fn feature_err(
8889
sess: &ParseSess,
8990
feature: Symbol,

src/bootstrap/test.rs

-4
Original file line numberDiff line numberDiff line change
@@ -1753,10 +1753,6 @@ note: if you're sure you want to do this, please open an issue as to why. In the
17531753
cmd.arg("--git-hash");
17541754
}
17551755

1756-
if let Some(commit) = builder.config.download_rustc_commit() {
1757-
cmd.env("FAKE_DOWNLOAD_RUSTC_PREFIX", format!("/rustc/{commit}"));
1758-
}
1759-
17601756
builder.ci_env.force_coloring_in_ci(&mut cmd);
17611757

17621758
builder.info(&format!(

src/tools/compiletest/src/runtest.rs

+18-29
Original file line numberDiff line numberDiff line change
@@ -1939,6 +1939,17 @@ impl<'test> TestCx<'test> {
19391939
// Use a single thread for efficiency and a deterministic error message order
19401940
rustc.arg("-Zthreads=1");
19411941

1942+
// Hide libstd sources from ui tests to make sure we generate the stderr
1943+
// output that users will see.
1944+
// Without this, we may be producing good diagnostics in-tree but users
1945+
// will not see half the information.
1946+
//
1947+
// This also has the benefit of more effectively normalizing output between different
1948+
// compilers, so that we don't have to know the `/rustc/$sha` output to normalize after the
1949+
// fact.
1950+
rustc.arg("-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX");
1951+
rustc.arg("-Ztranslate-remapped-path-to-local-path=no");
1952+
19421953
// Optionally prevent default --sysroot if specified in test compile-flags.
19431954
if !self.props.compile_flags.iter().any(|flag| flag.starts_with("--sysroot")) {
19441955
// In stage 0, make sure we use `stage0-sysroot` instead of the bootstrap sysroot.
@@ -2014,13 +2025,6 @@ impl<'test> TestCx<'test> {
20142025
rustc.arg("-Ccodegen-units=1");
20152026
// Hide line numbers to reduce churn
20162027
rustc.arg("-Zui-testing");
2017-
// Hide libstd sources from ui tests to make sure we generate the stderr
2018-
// output that users will see.
2019-
// Without this, we may be producing good diagnostics in-tree but users
2020-
// will not see half the information.
2021-
rustc.arg("-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX");
2022-
rustc.arg("-Ztranslate-remapped-path-to-local-path=no");
2023-
20242028
rustc.arg("-Zdeduplicate-diagnostics=no");
20252029
// FIXME: use this for other modes too, for perf?
20262030
rustc.arg("-Cstrip=debuginfo");
@@ -3729,28 +3733,13 @@ impl<'test> TestCx<'test> {
37293733
normalize_path(&remapped_parent_dir, "$DIR");
37303734
}
37313735

3732-
let source_bases = &[
3733-
// Source base on the current filesystem (calculated as parent of `tests/$suite`):
3734-
Some(self.config.src_base.parent().unwrap().parent().unwrap().into()),
3735-
// Source base on the sysroot (from the src components downloaded by `download-rustc`):
3736-
Some(self.config.sysroot_base.join("lib").join("rustlib").join("src").join("rust")),
3737-
// Virtual `/rustc/$sha` remapped paths (if `remap-debuginfo` is enabled):
3738-
option_env!("CFG_VIRTUAL_RUST_SOURCE_BASE_DIR").map(PathBuf::from),
3739-
// Virtual `/rustc/$sha` coming from download-rustc:
3740-
std::env::var_os("FAKE_DOWNLOAD_RUSTC_PREFIX").map(PathBuf::from),
3741-
// Tests using -Zsimulate-remapped-rust-src-base should use this fake path
3742-
Some("/rustc/FAKE_PREFIX".into()),
3743-
];
3744-
for base_dir in source_bases {
3745-
if let Some(base_dir) = base_dir {
3746-
// Paths into the libstd/libcore
3747-
normalize_path(&base_dir.join("library"), "$SRC_DIR");
3748-
// `ui-fulldeps` tests can show paths to the compiler source when testing macros from
3749-
// `rustc_macros`
3750-
// eg. /home/user/rust/compiler
3751-
normalize_path(&base_dir.join("compiler"), "$COMPILER_DIR");
3752-
}
3753-
}
3736+
let base_dir = Path::new("/rustc/FAKE_PREFIX");
3737+
// Paths into the libstd/libcore
3738+
normalize_path(&base_dir.join("library"), "$SRC_DIR");
3739+
// `ui-fulldeps` tests can show paths to the compiler source when testing macros from
3740+
// `rustc_macros`
3741+
// eg. /home/user/rust/compiler
3742+
normalize_path(&base_dir.join("compiler"), "$COMPILER_DIR");
37543743

37553744
// Paths into the build directory
37563745
let test_build_dir = &self.config.build_base;

tests/ui/track-diagnostics/track6.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ error[E0658]: specialization is unstable
33
|
44
LL | default fn bar() {}
55
| ^^^^^^^^^^^^^^^^^^^
6-
-Ztrack-diagnostics: created at $COMPILER_DIR/rustc_session/src/parse.rs:LL:CC
6+
-Ztrack-diagnostics: created at compiler/rustc_ast_passes/src/feature_gate.rs:LL:CC
77
|
88
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
99
= help: add `#![feature(specialization)]` to the crate attributes to enable

0 commit comments

Comments
 (0)