Fix relative paths in private import suggestions#157524
Conversation
|
rustbot has assigned @ShoyuVanilla. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
will do a rebase rq |
c128242 to
97aa4c9
Compare
This comment has been minimized.
This comment has been minimized.
|
It seems like @ShoyuVanilla is tight on schedule, safe to @rustbot reroll |
| None | ||
| }; | ||
|
|
||
| if let Some(module_path) = module_path { |
There was a problem hiding this comment.
Could this be simplified with module_path.map(..)?
| // Reuse the existing relative shortening policy. The fields above | ||
| // other than `did` and `path` are not used by this helper. | ||
| self.shorten_candidate_path(&mut suggestion, parent_scope.module); |
There was a problem hiding this comment.
This feels like a temporary workaround 😅 Could you extract the path shortening part from shorten_candidate_path into a new method?
There was a problem hiding this comment.
Could you make this into a new test file with //@ run-rustfix? I think that would make the purpose of this test clearer.
There was a problem hiding this comment.
Done. Moved the root super case to tests/ui/imports/private-import-suggestion-relative-rustfix.rs
There was a problem hiding this comment.
I mean, I think leaving this test as-is before this PR and moving the added lines into a new one would be nice
3e420b6 to
49a5aa3
Compare
There was a problem hiding this comment.
We have lots of tests that runs rustfix but don't name them with the postfix -rustfix 😄 Could you rename this file without it and make the name just explain what this test is for?
There was a problem hiding this comment.
I mean, I think leaving this test as-is before this PR and moving the added lines into a new one would be nice
I tried for both cases, but neither is compatible with rustfix. The private ancestor intentionally still errors after rustfix runs and external alias produces |
49a5aa3 to
57821f8
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
c0bee86 to
a9bbba1
Compare
This comment has been minimized.
This comment has been minimized.
a9bbba1 to
9a0a4bf
Compare
Ah, right. I got confused. Sorry 😅 Those cases aren't the cases that can be fixed with the suggested imports |
This comment has been minimized.
This comment has been minimized.
will rebase rq |
9a0a4bf to
db1ab0b
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. |
|
@rustbot ready |
|
@bors r+ rollup |
…ve-path, r=ShoyuVanilla Fix relative paths in private import suggestions Resolves rust-lang#157455. The private import diagnostic was reusing `import.module_path` for the "import directly" help. That path is relative to the module where the import was written, so a relative import can be suggested from the wrong place. For the issue repro, this suggested: ```rust use super::public::hi; ``` from the crate root. The suggestion should be: ```rust use public::hi; ``` For relative local imports, this PR rebuilds the help from the resolved module path and only emits it if the item and every module segment are accessible from the failing use site. Additionally, this covers the private-ancestor case from rust-lang#157455 (comment), where suggesting a direct path would still be invalid. Finally, it maintains an external-alias case as a guardrail to ensure `super::s::mem` is not treated like a local module path.
…ve-path, r=ShoyuVanilla Fix relative paths in private import suggestions Resolves rust-lang#157455. The private import diagnostic was reusing `import.module_path` for the "import directly" help. That path is relative to the module where the import was written, so a relative import can be suggested from the wrong place. For the issue repro, this suggested: ```rust use super::public::hi; ``` from the crate root. The suggestion should be: ```rust use public::hi; ``` For relative local imports, this PR rebuilds the help from the resolved module path and only emits it if the item and every module segment are accessible from the failing use site. Additionally, this covers the private-ancestor case from rust-lang#157455 (comment), where suggesting a direct path would still be invalid. Finally, it maintains an external-alias case as a guardrail to ensure `super::s::mem` is not treated like a local module path.
Rollup of 11 pull requests Successful merges: - #159210 (`rust-analyzer` subtree update) - #158655 (Fix coroutine MIR saved local remapping) - #159205 (bootstrap: Replace `ShouldRun::crates` with `crate_or_deps_filtered`) - #159208 (Fix `attr_on_non_tail_expr` typo) - #157524 (Fix relative paths in private import suggestions) - #158325 (Document NonNull layout guarantees) - #158882 (enable `do_not_recommend` attr for method call errors in current solver) - #158982 (Pretty-print MIR user types too.) - #159069 (Add codegen test for constant returns after local use) - #159163 (rustc_target: Add acquire-release to implied features of v8) - #159201 (borrowck: Represent 'best blame constraint' as index into `Vec<OutlivesConstraint>`)
View all comments
Resolves #157455.
The private import diagnostic was reusing
import.module_pathfor the "import directly" help. That path is relative to the module where the import was written, so a relative import can be suggested from the wrong place.For the issue repro, this suggested:
from the crate root. The suggestion should be:
For relative local imports, this PR rebuilds the help from the resolved module path and only emits it if the item and every module segment are accessible from the failing use site. Additionally, this covers the private-ancestor case from #157455 (comment), where suggesting a direct path would still be invalid. Finally, it maintains an external-alias case as a guardrail to ensure
super::s::memis not treated like a local module path.