Skip to content

Commit 2341c7d

Browse files
committed
Un-remap rustc-dev component paths
1 parent 810d99e commit 2341c7d

File tree

8 files changed

+107
-0
lines changed

8 files changed

+107
-0
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,6 +1759,17 @@ impl<'a> CrateMetadataRef<'a> {
17591759
&mut name,
17601760
);
17611761

1762+
// If this file is under $sysroot/lib/rustlib/rustc-src/
1763+
// and the user wish to simulate remapping with -Z simulate-remapped-rust-src-base,
1764+
// then we change `name` to a similar state as if the rust was bootstrapped
1765+
// with `remap-debuginfo = true`.
1766+
try_to_translate_real_to_virtual(
1767+
option_env!("CFG_VIRTUAL_RUSTC_DEV_SOURCE_BASE_DIR"),
1768+
&sess.opts.real_rustc_dev_source_base_dir,
1769+
"compiler",
1770+
&mut name,
1771+
);
1772+
17621773
// If this file's path has been remapped to `/rustc/$hash`,
17631774
// we might be able to reverse that.
17641775
//
@@ -1770,6 +1781,17 @@ impl<'a> CrateMetadataRef<'a> {
17701781
&mut name,
17711782
);
17721783

1784+
// If this file's path has been remapped to `/rustc-dev/$hash`,
1785+
// we might be able to reverse that.
1786+
//
1787+
// NOTE: if you update this, you might need to also update bootstrap's code for generating
1788+
// the `rustc-dev` component in `Src::run` in `src/bootstrap/dist.rs`.
1789+
try_to_translate_virtual_to_real(
1790+
option_env!("CFG_VIRTUAL_RUSTC_DEV_SOURCE_BASE_DIR"),
1791+
&sess.opts.real_rustc_dev_source_base_dir,
1792+
&mut name,
1793+
);
1794+
17731795
let local_version = sess.source_map().new_imported_source_file(
17741796
name,
17751797
src_hash,

compiler/rustc_session/src/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,6 +1364,7 @@ impl Default for Options {
13641364
cli_forced_local_thinlto_off: false,
13651365
remap_path_prefix: Vec::new(),
13661366
real_rust_source_base_dir: None,
1367+
real_rustc_dev_source_base_dir: None,
13671368
edition: DEFAULT_EDITION,
13681369
json_artifact_notifications: false,
13691370
json_unused_externs: JsonUnusedExterns::No,
@@ -2713,6 +2714,10 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
27132714
// This is the location used by the `rust-src` `rustup` component.
27142715
real_source_base_dir("lib/rustlib/src/rust", "library/std/src/lib.rs");
27152716

2717+
let real_rustc_dev_source_base_dir =
2718+
// This is the location used by the `rustc-dev` `rustup` component.
2719+
real_source_base_dir("lib/rustlib/rustc-src/rust", "compiler/rustc/src/main.rs");
2720+
27162721
let mut search_paths = vec![];
27172722
for s in &matches.opt_strs("L") {
27182723
search_paths.push(SearchPath::from_cli_opt(
@@ -2766,6 +2771,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
27662771
cli_forced_local_thinlto_off: disable_local_thinlto,
27672772
remap_path_prefix,
27682773
real_rust_source_base_dir,
2774+
real_rustc_dev_source_base_dir,
27692775
edition,
27702776
json_artifact_notifications,
27712777
json_unused_externs,

compiler/rustc_session/src/options.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,15 @@ top_level_options!(
397397
/// (the `rust.remap-debuginfo` option in `bootstrap.toml`).
398398
real_rust_source_base_dir: Option<PathBuf> [TRACKED_NO_CRATE_HASH],
399399

400+
/// Base directory containing the `compiler/` directory for the rustc sources.
401+
/// Right now it's always `$sysroot/lib/rustlib/rustc-src/rust`
402+
/// (i.e. the `rustup` `rustc-dev` component).
403+
///
404+
/// This directory is what the virtual `/rustc-dev/$hash` is translated back to,
405+
/// if Rust was built with path remapping to `/rustc/$hash` enabled
406+
/// (the `rust.remap-debuginfo` option in `bootstrap.toml`).
407+
real_rustc_dev_source_base_dir: Option<PathBuf> [TRACKED_NO_CRATE_HASH],
408+
400409
edition: Edition [TRACKED],
401410

402411
/// `true` if we're emitting JSON blobs about each artifact produced

src/doc/rustc-dev-guide/src/tests/ui.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ Compiletest makes the following replacements on the compiler output:
113113
- The base directory where the test's output goes is replaced with
114114
`$TEST_BUILD_DIR`. This only comes up in a few rare circumstances. Example:
115115
`/path/to/rust/build/x86_64-unknown-linux-gnu/test/ui`
116+
- The real directory to the standard library source is replaced with `$SRC_DIR_REAL`.
117+
- The real directory to the compiler source is replaced with `$COMPILER_DIR_REAL`.
116118
- Tabs are replaced with `\t`.
117119
- Backslashes (`\`) are converted to forward slashes (`/`) within paths (using a
118120
heuristic). This helps normalize differences with Windows-style paths.

src/tools/compiletest/src/runtest.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2371,6 +2371,12 @@ impl<'test> TestCx<'test> {
23712371
let rust_src_dir = rust_src_dir.read_link_utf8().unwrap_or(rust_src_dir.to_path_buf());
23722372
normalize_path(&rust_src_dir.join("library"), "$SRC_DIR_REAL");
23732373

2374+
// Real paths into the compiler
2375+
let rustc_src_dir = &self.config.sysroot_base.join("lib/rustlib/rustc-src/rust");
2376+
rustc_src_dir.try_exists().expect(&*format!("{} should exists", rustc_src_dir));
2377+
let rustc_src_dir = rustc_src_dir.read_link_utf8().unwrap_or(rustc_src_dir.to_path_buf());
2378+
normalize_path(&rustc_src_dir.join("compiler"), "$COMPILER_DIR_REAL");
2379+
23742380
// eg.
23752381
// /home/user/rust/build/x86_64-unknown-linux-gnu/test/ui/<test_dir>/$name.$revision.$mode/
23762382
normalize_path(&self.output_base_dir(), "$TEST_BUILD_DIR");
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0277]: the trait bound `NotAValidResultType: VisitorResult` is not satisfied
2+
--> $DIR/rustc-dev-remap.rs:LL:COL
3+
|
4+
LL | type Result = NotAValidResultType;
5+
| ^^^^^^^^^^^^^^^^^^^ the trait `VisitorResult` is not implemented for `NotAValidResultType`
6+
|
7+
= help: the following other types implement trait `VisitorResult`:
8+
()
9+
ControlFlow<T>
10+
note: required by a bound in `rustc_ast::visit::Visitor::Result`
11+
--> /rustc-dev/xyz/compiler/rustc_ast/src/visit.rs:LL:COL
12+
13+
error: aborting due to 1 previous error
14+
15+
For more information about this error, try `rustc --explain E0277`.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0277]: the trait bound `NotAValidResultType: VisitorResult` is not satisfied
2+
--> $DIR/rustc-dev-remap.rs:LL:COL
3+
|
4+
LL | type Result = NotAValidResultType;
5+
| ^^^^^^^^^^^^^^^^^^^ the trait `VisitorResult` is not implemented for `NotAValidResultType`
6+
|
7+
= help: the following other types implement trait `VisitorResult`:
8+
()
9+
ControlFlow<T>
10+
note: required by a bound in `rustc_ast::visit::Visitor::Result`
11+
--> $COMPILER_DIR_REAL/rustc_ast/src/visit.rs:LL:COL
12+
|
13+
LL | type Result: VisitorResult = ();
14+
| ^^^^^^^^^^^^^ required by this bound in `Visitor::Result`
15+
16+
error: aborting due to 1 previous error
17+
18+
For more information about this error, try `rustc --explain E0277`.

tests/ui-fulldeps/rustc-dev-remap.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//@ check-fail
2+
//
3+
//@ ignore-cross-compile
4+
//@ ignore-remote
5+
//
6+
//@ revisions: only-remap remap-unremap
7+
//@ compile-flags: -Z simulate-remapped-rust-src-base=/rustc-dev/xyz
8+
//@ [remap-unremap]compile-flags: -Ztranslate-remapped-path-to-local-path=yes
9+
10+
// The $SRC_DIR*.rs:LL:COL normalisation doesn't kick in automatically
11+
// as the remapped revision will begin with $COMPILER_DIR_REAL,
12+
// so we have to do it ourselves.
13+
//@ normalize-stderr: ".rs:\d+:\d+" -> ".rs:LL:COL"
14+
15+
#![feature(rustc_private)]
16+
17+
extern crate rustc_ast;
18+
19+
use rustc_ast::visit::Visitor;
20+
21+
struct MyStruct;
22+
struct NotAValidResultType;
23+
24+
impl Visitor<'_> for MyStruct {
25+
type Result = NotAValidResultType;
26+
//~^ ERROR the trait bound `NotAValidResultType: VisitorResult` is not satisfied
27+
}
28+
29+
fn main() {}

0 commit comments

Comments
 (0)