Skip to content

Commit a0d1a66

Browse files
committed
Auto merge of #149709 - Urgau:overhaul-filenames, r=davidtwco
Overhaul filename handling for cross-compiler consistency This PR overhauls the way we handle filenames in the compiler and `rmeta` in order to achieve achieve cross-compiler consistency (ie. having the same path no matter if the filename was created in the current compiler session or is coming from `rmeta`). This is required as some parts of the compiler rely on consistent paths for the soundness of generated code (see rust-lang/rust#148328). In order to achieved consistency multiple steps are being taken by this PR: - by making `RealFileName` immutable - by only having `SourceMap::to_real_filename` create `RealFileName` - currently `RealFileName` can be created from any `Path` and are remapped afterwards, which creates consistency issue - by also making `RealFileName` holds it's working directory, embeddable name and the remapped scopes - this removes the need for a `Session`, to know the current(!) scopes and cwd, which is invalid as they may not be equal to the scopes used when creating the filename In order for `SourceMap::to_real_filename` to know which scopes to apply `FilePathMapping` now takes the current remapping scopes to apply, which makes `FileNameDisplayPreference` and company useless and are removed. This PR is split-up in multiple commits (unfortunately not atomic), but should help review the changes. Unblocks rust-lang/rust#147611 Fixes rust-lang/rust#148328
2 parents 0f0b2a7 + b30c7c2 commit a0d1a66

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

clippy_lints/src/module_style.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub struct ModStyle {
8181

8282
impl EarlyLintPass for ModStyle {
8383
fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &ast::Crate) {
84-
self.working_dir = cx.sess().opts.working_dir.local_path().map(Path::to_path_buf);
84+
self.working_dir = cx.sess().source_map().working_dir().local_path().map(Path::to_path_buf);
8585
}
8686

8787
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &ast::Item) {

clippy_utils/src/source.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_middle::ty::TyCtxt;
1313
use rustc_session::Session;
1414
use rustc_span::source_map::{SourceMap, original_sp};
1515
use rustc_span::{
16-
BytePos, DUMMY_SP, DesugaringKind, FileNameDisplayPreference, Pos, RelativeBytePos, SourceFile, SourceFileAndLine,
16+
BytePos, DUMMY_SP, DesugaringKind, Pos, RelativeBytePos, SourceFile, SourceFileAndLine,
1717
Span, SpanData, SyntaxContext, hygiene,
1818
};
1919
use std::borrow::Cow;
@@ -268,7 +268,7 @@ fn map_range(
268268
debug_assert!(
269269
range.start <= text.len() && range.end <= text.len(),
270270
"Range `{range:?}` is outside the source file (file `{}`, length `{}`)",
271-
src.sf.name.display(FileNameDisplayPreference::Local),
271+
src.sf.name.prefer_local_unconditionally(),
272272
text.len(),
273273
);
274274
debug_assert!(range.start <= range.end, "Range `{range:?}` has overlapping bounds");

0 commit comments

Comments
 (0)