Skip to content

Normalize .. and . in diagnostic file paths - #155569

Open
arferreira wants to merge 2 commits into
rust-lang:mainfrom
arferreira:normalize-diagnostic-paths
Open

Normalize .. and . in diagnostic file paths#155569
arferreira wants to merge 2 commits into
rust-lang:mainfrom
arferreira:normalize-diagnostic-paths

Conversation

@arferreira

@arferreira arferreira commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

Fixes #51349

Lexically normalize . and .. in file paths when rendering diagnostics, so errors show foo.rs instead of sub/../foo.rs. Normalization is scoped to the new FileNameDisplayPreference::Diagnostics variant used by SourceMap::filename_for_diagnostics; file!(), debuginfo, and remapped/local/short paths are unchanged.

Uses the unstable Path::normalize_lexically, canonicalize is avoided because it turns relative paths absolute, which broke the previous attempt in #83345. Paths that normalize_lexically rejects (leading escapes, net-negative ..) fall back to the raw path and don't occur in practice for the diagnostic paths this PR targets. Compiletest gains a $DIR/.. substitution so existing .stderr files that referenced auxiliary paths above $DIR keep matching.

Previous attempt was #68654.

r? @estebank

@rustbot

rustbot commented Apr 20, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in src/tools/compiletest

cc @jieyouxu

@rustbot rustbot added A-compiletest Area: The compiletest test runner A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 20, 2026
@rust-log-analyzer

This comment has been minimized.

@arferreira
arferreira force-pushed the normalize-diagnostic-paths branch from 72beb68 to e02a2f9 Compare April 20, 2026 17:46
Comment thread compiler/rustc_span/src/lib.rs Outdated
Comment thread compiler/rustc_span/src/lib.rs Outdated
@arferreira
arferreira force-pushed the normalize-diagnostic-paths branch 2 times, most recently from 7e7055d to b0cb45e Compare April 21, 2026 18:33
@rust-bors

This comment has been minimized.

@Urgau

Urgau commented Aug 13, 2026

Copy link
Copy Markdown
Member

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 13, 2026
@rustbot

rustbot commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@arferreira
arferreira force-pushed the normalize-diagnostic-paths branch from b0cb45e to dea80f7 Compare August 13, 2026 19:06
@rustbot

rustbot commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

FileNameDisplayPreference::Scope(scope) => self.path(scope).to_string_lossy(),
FileNameDisplayPreference::Diagnostics(scope) => {
let path = self.path(scope);
match path.normalize_lexically() {

@estebank estebank Aug 13, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only concern with lexical normalization is that it doesn't hit the disk and one can craft a volume where ./foo/../bar.rs doesn't map to ./bar.rs. That seems convoluted though.

Could we add support for --verbose to print the path without normalization?

View changes since the review

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's desirable, it would be possible to use something like same_file to test if both paths resolve to the same underlying file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can hit the disk here, these paths don't need to exist locally. --verbose should cover the cases where you'd want the raw path anyway.

@ChrisDenton

Copy link
Copy Markdown
Member

I would note that normalize_lexically is still very much a new API and there's currently some debate as to how it should be shaped. However, it should always be possible to do what's needed here so I'm not too concerned. I'm just bringing up that it may require a bit of churn.

Signed-off-by: arferreira <arfs.antonio@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-compiletest Area: The compiletest test runner A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

compiler error message shows the error path containing parent directory identifier ( /../ )

6 participants