Normalize .. and . in diagnostic file paths - #155569
Conversation
|
Some changes occurred in src/tools/compiletest cc @jieyouxu |
This comment has been minimized.
This comment has been minimized.
72beb68 to
e02a2f9
Compare
7e7055d to
b0cb45e
Compare
This comment has been minimized.
This comment has been minimized.
|
@rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
b0cb45e to
dea80f7
Compare
|
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() { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
I would note that |
Signed-off-by: arferreira <arfs.antonio@gmail.com>
Fixes #51349
Lexically normalize
.and..in file paths when rendering diagnostics, so errors showfoo.rsinstead ofsub/../foo.rs. Normalization is scoped to the newFileNameDisplayPreference::Diagnosticsvariant used bySourceMap::filename_for_diagnostics;file!(), debuginfo, and remapped/local/short paths are unchanged.Uses the unstable
Path::normalize_lexically,canonicalizeis avoided because it turns relative paths absolute, which broke the previous attempt in #83345. Paths thatnormalize_lexicallyrejects (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.stderrfiles that referenced auxiliary paths above$DIRkeep matching.Previous attempt was #68654.
r? @estebank