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>
@arferreira

Copy link
Copy Markdown
Contributor Author

@rustbot ready

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

estebank commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

@bors r+

@rust-bors

rust-bors Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 0da8bd3 has been approved by estebank

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 1, 2026
Zalathar added a commit to Zalathar/rust that referenced this pull request Sep 2, 2026
…ths, r=estebank

Normalize .. and . in diagnostic file paths

Fixes rust-lang#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 rust-lang#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 rust-lang#68654.

r? @estebank
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 2, 2026
…ths, r=estebank

Normalize .. and . in diagnostic file paths

Fixes rust-lang#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 rust-lang#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 rust-lang#68654.

r? @estebank
Zalathar added a commit to Zalathar/rust that referenced this pull request Sep 2, 2026
…ths, r=estebank

Normalize .. and . in diagnostic file paths

Fixes rust-lang#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 rust-lang#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 rust-lang#68654.

r? @estebank
Zalathar added a commit to Zalathar/rust that referenced this pull request Sep 2, 2026
…ths, r=estebank

Normalize .. and . in diagnostic file paths

Fixes rust-lang#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 rust-lang#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 rust-lang#68654.

r? @estebank
@Zalathar

Zalathar commented Sep 2, 2026

Copy link
Copy Markdown
Member

Checking if this causes a failure seen in rollup in x86_64-mingw-1: #162184 (comment)

@bors try jobs=x86_64-mingw-1

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Sep 2, 2026
Normalize .. and . in diagnostic file paths


try-job: x86_64-mingw-1
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 2, 2026
…ths, r=estebank

Normalize .. and . in diagnostic file paths

Fixes rust-lang#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 rust-lang#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 rust-lang#68654.

r? @estebank
@rust-bors rust-bors Bot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Sep 2, 2026
@rust-bors

rust-bors Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

💔 Test for a161d50 failed: CI. Failed job:

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. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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 ( /../ )

7 participants