Skip to content
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

Do not suggest importing inaccessible items #88838

Merged
merged 2 commits into from
Oct 1, 2021

Conversation

FabianWolff
Copy link
Contributor

Fixes #88472. For this example:

mod a {
    struct Foo;
}

mod b {
    type Bar = Foo;
}

rustc currently emits:

error[E0412]: cannot find type `Foo` in this scope
 --> test.rs:6:16
  |
6 |     type Bar = Foo;
  |                ^^^ not found in this scope
  |
help: consider importing this struct
  |
6 |     use a::Foo;
  |

this is incorrect, as applying this suggestion leads to

error[E0603]: struct `Foo` is private
 --> test.rs:6:12
  |
6 |     use a::Foo;
  |            ^^^ private struct
  |
note: the struct `Foo` is defined here
 --> test.rs:2:5
  |
2 |     struct Foo;
  |     ^^^^^^^^^^^

With my changes, I get:

error[E0412]: cannot find type `Foo` in this scope
 --> test.rs:6:16
  |
6 |     type Bar = Foo;
  |                ^^^ not found in this scope
  |
  = note: this struct exists but is inaccessible:
          a::Foo

As for the wildcard mentioned in #88472, I would argue that the warning is actually correct, since the import is unused. I think the real issue is the wrong suggestion, which I have fixed here.

@rust-highfive
Copy link
Collaborator

r? @michaelwoerister

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 10, 2021
@apiraino apiraino added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Sep 13, 2021
@michaelwoerister
Copy link
Member

r? @JohnTitor (randomly picked someone from wg-diagnostics, feel free to re-assign)

@JohnTitor
Copy link
Member

Seems good but I'm not part of t-compiler, r? @estebank could you take a look?

@rust-highfive rust-highfive assigned estebank and unassigned JohnTitor Sep 15, 2021
Copy link
Contributor

@estebank estebank left a comment

Choose a reason for hiding this comment

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

I think the changes are an improvement already, but I have a few ideas on how we could improve them further. I'm r=me for the code changes as they are, but I would like to continue tweaking them so the output is nicer. Would you have time to make them perfect, @FabianWolff?

@FabianWolff
Copy link
Contributor Author

I think the changes are an improvement already, but I have a few ideas on how we could improve them further. I'm r=me for the code changes as they are, but I would like to continue tweaking them so the output is nicer. Would you have time to make them perfect, @FabianWolff?

Thanks for the review! Yes, I'll try to implement your suggestions (though I won't get around to it today).

@bors
Copy link
Contributor

bors commented Sep 17, 2021

☔ The latest upstream changes (presumably #89037) made this pull request unmergeable. Please resolve the merge conflicts.

@estebank
Copy link
Contributor

One last thing: if the DefId belongs to the local crate, we should maybe suggest making the item (and all its parents, if applicable) pub? Anyone experienced will not need it and figure things out just with even the current message in this PR, but I could envision anyone just starting asking themselves "ok, so what do I do? how do I make it accessible?". Of course, that is not necessarily needed for this PR, but we don't address it, could you file a follow up ticket to do that?

@FabianWolff
Copy link
Contributor Author

@estebank I have now implemented your suggestions! I did not get around to your proposal in #88838 (comment); instead, I have opened #89057 as a follow-up, as you have suggested (I might come back to it if I have time in the next few days).

@bors
Copy link
Contributor

bors commented Sep 26, 2021

☔ The latest upstream changes (presumably #89262) made this pull request unmergeable. Please resolve the merge conflicts.

Copy link
Contributor

@estebank estebank left a comment

Choose a reason for hiding this comment

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

r=me after rebasing

@crlf0710
Copy link
Member

I'm curious whether this will fix #88636 too

@estebank
Copy link
Contributor

@crlf0710 it's very likely it will, good catch!

@FabianWolff
Copy link
Contributor Author

@estebank Rebased & ready.

@estebank
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Sep 27, 2021

📌 Commit 750018e has been approved by estebank

@bors bors 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 27, 2021
@bors
Copy link
Contributor

bors commented Sep 28, 2021

⌛ Testing commit 750018e with merge 93468f041e3a0ab409c395d2cbf7a790e4c8ff8c...

@bors
Copy link
Contributor

bors commented Sep 28, 2021

💥 Test timed out

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Sep 28, 2021
@rust-log-analyzer
Copy link
Collaborator

A job failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@estebank
Copy link
Contributor

@bors retry

@bors bors 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 28, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 1, 2021
…arth

Rollup of 7 pull requests

Successful merges:

 - rust-lang#88838 (Do not suggest importing inaccessible items)
 - rust-lang#89251 (Detect when negative literal indices are used and suggest appropriate code)
 - rust-lang#89321 (Rebase resume argument projections during state transform)
 - rust-lang#89327 (Pick one possible lifetime in case there are multiple choices)
 - rust-lang#89344 (Cleanup lower_generics_mut and make span be the bound itself)
 - rust-lang#89397 (Update `llvm` submodule to fix function name mangling on x86 Windows)
 - rust-lang#89412 (Add regression test for issues rust-lang#88969 and rust-lang#89119 )

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 9593e61 into rust-lang:master Oct 1, 2021
@rustbot rustbot added this to the 1.57.0 milestone Oct 1, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 25, 2021
Do not mention a reexported item if it's private

Fixes rust-lang#90113
The _actual_ regression was introduced in rust-lang#73652, then rust-lang#88838 made it worse. This fixes the issue by not counting such an import as a candidate.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

Bad diagnostic when attemting to import private item via glob
10 participants