-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
fix incorrect suggestions in private import diagnostic #156244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
el-ev
wants to merge
6
commits into
rust-lang:main
Choose a base branch
from
el-ev:issue156060
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+294
−37
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a2c0e02
skip incorrect suggestion in nested imports
el-ev 05b97f7
address review comment
el-ev 1ad59ef
mark the suggestion as directly when it is
el-ev b7d22fd
refactor path construction
el-ev a28de9f
update tests
el-ev 6d5fc32
combine tests into one file
el-ev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
tests/ui/imports/private-import-nested-suggestion-156060.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // Regression test for #156060. | ||
|
el-ev marked this conversation as resolved.
|
||
|
|
||
| mod one { | ||
| pub struct One(); | ||
| } | ||
|
|
||
| mod two { | ||
| use crate::one::One; | ||
| pub struct Two(); | ||
| } | ||
|
|
||
| mod test { | ||
| use crate::two::{One, Two}; | ||
| //~^ ERROR struct import `One` is private [E0603] | ||
| } | ||
|
|
||
| fn main() {} | ||
20 changes: 20 additions & 0 deletions
20
tests/ui/imports/private-import-nested-suggestion-156060.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| error[E0603]: struct import `One` is private | ||
| --> $DIR/private-import-nested-suggestion-156060.rs:13:22 | ||
| | | ||
| LL | use crate::two::{One, Two}; | ||
| | ^^^ private struct import | ||
| | | ||
| note: the struct import `One` is defined here... | ||
| --> $DIR/private-import-nested-suggestion-156060.rs:8:9 | ||
| | | ||
| LL | use crate::one::One; | ||
| | ^^^^^^^^^^^^^^^ | ||
| note: ...and refers to the struct `One` which is defined here | ||
| --> $DIR/private-import-nested-suggestion-156060.rs:4:5 | ||
| | | ||
| LL | pub struct One(); | ||
| | ^^^^^^^^^^^^^^^^^ you could import this directly | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
||
| For more information about this error, try `rustc --explain E0603`. |
81 changes: 81 additions & 0 deletions
81
tests/ui/imports/private-import-suggestion-path-156244.edition_2015.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| error[E0603]: struct import `One` is private | ||
| --> $DIR/private-import-suggestion-path-156244.rs:17:12 | ||
| | | ||
| LL | use b::One; | ||
| | ^^^ private struct import | ||
| | | ||
| note: the struct import `One` is defined here... | ||
| --> $DIR/private-import-suggestion-path-156244.rs:12:20 | ||
| | | ||
| LL | use crate::a::{One, Two}; | ||
| | ^^^ | ||
| note: ...and refers to the struct `One` which is defined here | ||
| --> $DIR/private-import-suggestion-path-156244.rs:7:5 | ||
| | | ||
| LL | pub struct One; | ||
| | ^^^^^^^^^^^^^^^ you could import this directly | ||
| help: import `One` directly | ||
| | | ||
| LL - use b::One; | ||
| LL + use crate::a::One; | ||
| | | ||
|
|
||
| error[E0603]: struct import `One` is private | ||
| --> $DIR/private-import-suggestion-path-156244.rs:35:20 | ||
| | | ||
| LL | use crate::b::{One, Two}; | ||
| | ^^^ private struct import | ||
| | | ||
| note: the struct import `One` is defined here... | ||
| --> $DIR/private-import-suggestion-path-156244.rs:12:20 | ||
| | | ||
| LL | use crate::a::{One, Two}; | ||
| | ^^^ | ||
| note: ...and refers to the struct `One` which is defined here | ||
| --> $DIR/private-import-suggestion-path-156244.rs:7:5 | ||
| | | ||
| LL | pub struct One; | ||
| | ^^^^^^^^^^^^^^^ you could import this directly | ||
|
|
||
| error[E0603]: struct import `Two` is private | ||
| --> $DIR/private-import-suggestion-path-156244.rs:35:25 | ||
| | | ||
| LL | use crate::b::{One, Two}; | ||
| | ^^^ private struct import | ||
| | | ||
| note: the struct import `Two` is defined here... | ||
| --> $DIR/private-import-suggestion-path-156244.rs:12:25 | ||
| | | ||
| LL | use crate::a::{One, Two}; | ||
| | ^^^ | ||
| note: ...and refers to the struct `Two` which is defined here | ||
| --> $DIR/private-import-suggestion-path-156244.rs:8:5 | ||
| | | ||
| LL | pub struct Two; | ||
| | ^^^^^^^^^^^^^^^ you could import this directly | ||
|
|
||
| error[E0603]: module import `inner` is private | ||
| --> $DIR/private-import-suggestion-path-156244.rs:38:24 | ||
| | | ||
| LL | use crate::rename::inner::Item as Item1; | ||
| | ^^^^^ private module import | ||
| | | ||
| note: the module import `inner` is defined here... | ||
| --> $DIR/private-import-suggestion-path-156244.rs:31:9 | ||
| | | ||
| LL | use crate::outer::actual as inner; | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| note: ...and refers to the module `actual` which is defined here | ||
| --> $DIR/private-import-suggestion-path-156244.rs:25:5 | ||
| | | ||
| LL | pub mod actual { | ||
| | ^^^^^^^^^^^^^^ you could import this directly | ||
| help: consider importing this struct instead | ||
| | | ||
| LL - use crate::rename::inner::Item as Item1; | ||
| LL + use outer::actual::Item as Item1; | ||
| | | ||
|
|
||
| error: aborting due to 4 previous errors | ||
|
|
||
| For more information about this error, try `rustc --explain E0603`. |
81 changes: 81 additions & 0 deletions
81
tests/ui/imports/private-import-suggestion-path-156244.edition_2018.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| error[E0603]: struct import `One` is private | ||
| --> $DIR/private-import-suggestion-path-156244.rs:20:19 | ||
| | | ||
| LL | use crate::b::One; | ||
| | ^^^ private struct import | ||
| | | ||
| note: the struct import `One` is defined here... | ||
| --> $DIR/private-import-suggestion-path-156244.rs:12:20 | ||
| | | ||
| LL | use crate::a::{One, Two}; | ||
| | ^^^ | ||
| note: ...and refers to the struct `One` which is defined here | ||
| --> $DIR/private-import-suggestion-path-156244.rs:7:5 | ||
| | | ||
| LL | pub struct One; | ||
| | ^^^^^^^^^^^^^^^ you could import this directly | ||
| help: import `One` directly | ||
| | | ||
| LL - use crate::b::One; | ||
| LL + use crate::a::One; | ||
| | | ||
|
|
||
| error[E0603]: struct import `One` is private | ||
| --> $DIR/private-import-suggestion-path-156244.rs:35:20 | ||
| | | ||
| LL | use crate::b::{One, Two}; | ||
| | ^^^ private struct import | ||
| | | ||
| note: the struct import `One` is defined here... | ||
| --> $DIR/private-import-suggestion-path-156244.rs:12:20 | ||
| | | ||
| LL | use crate::a::{One, Two}; | ||
| | ^^^ | ||
| note: ...and refers to the struct `One` which is defined here | ||
| --> $DIR/private-import-suggestion-path-156244.rs:7:5 | ||
| | | ||
| LL | pub struct One; | ||
| | ^^^^^^^^^^^^^^^ you could import this directly | ||
|
|
||
| error[E0603]: struct import `Two` is private | ||
| --> $DIR/private-import-suggestion-path-156244.rs:35:25 | ||
| | | ||
| LL | use crate::b::{One, Two}; | ||
| | ^^^ private struct import | ||
| | | ||
| note: the struct import `Two` is defined here... | ||
| --> $DIR/private-import-suggestion-path-156244.rs:12:25 | ||
| | | ||
| LL | use crate::a::{One, Two}; | ||
| | ^^^ | ||
| note: ...and refers to the struct `Two` which is defined here | ||
| --> $DIR/private-import-suggestion-path-156244.rs:8:5 | ||
| | | ||
| LL | pub struct Two; | ||
| | ^^^^^^^^^^^^^^^ you could import this directly | ||
|
|
||
| error[E0603]: module import `inner` is private | ||
| --> $DIR/private-import-suggestion-path-156244.rs:38:24 | ||
| | | ||
| LL | use crate::rename::inner::Item as Item1; | ||
| | ^^^^^ private module import | ||
| | | ||
| note: the module import `inner` is defined here... | ||
| --> $DIR/private-import-suggestion-path-156244.rs:31:9 | ||
| | | ||
| LL | use crate::outer::actual as inner; | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| note: ...and refers to the module `actual` which is defined here | ||
| --> $DIR/private-import-suggestion-path-156244.rs:25:5 | ||
| | | ||
| LL | pub mod actual { | ||
| | ^^^^^^^^^^^^^^ you could import this directly | ||
| help: consider importing this struct instead | ||
| | | ||
| LL - use crate::rename::inner::Item as Item1; | ||
| LL + use crate::outer::actual::Item as Item1; | ||
| | | ||
|
|
||
| error: aborting due to 4 previous errors | ||
|
|
||
| For more information about this error, try `rustc --explain E0603`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // PR #156244 comment | ||
| //@ revisions: edition_2015 edition_2018 | ||
| //@[edition_2015] edition: 2015 | ||
| //@[edition_2018] edition: 2018 | ||
|
|
||
| mod a { | ||
| pub struct One; | ||
| pub struct Two; | ||
| } | ||
|
|
||
| mod b { | ||
| use crate::a::{One, Two}; | ||
| } | ||
|
|
||
| mod test { | ||
| #[cfg(edition_2015)] | ||
| use b::One; | ||
| //[edition_2015]~^ ERROR struct import `One` is private [E0603] | ||
| #[cfg(edition_2018)] | ||
| use crate::b::One; | ||
| //[edition_2018]~^ ERROR struct import `One` is private [E0603] | ||
| } | ||
|
|
||
| mod outer { | ||
| pub mod actual { | ||
| pub struct Item; | ||
| } | ||
| } | ||
|
|
||
| mod rename { | ||
| use crate::outer::actual as inner; | ||
| } | ||
|
|
||
| mod bad { | ||
| use crate::b::{One, Two}; | ||
| //~^ ERROR struct import `One` is private [E0603] | ||
| //~| ERROR struct import `Two` is private [E0603] | ||
| use crate::rename::inner::Item as Item1; | ||
| //~^ ERROR module import `inner` is private [E0603] | ||
| } | ||
|
|
||
| fn main() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.