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

vis note for no pub reexports glob import #115993

Merged
merged 1 commit into from
Dec 1, 2023
Merged

Conversation

bvanjoi
Copy link
Contributor

@bvanjoi bvanjoi commented Sep 20, 2023

Fixes #115966

Only trigger the unused_import lint when it's not being used.

r? @petrochenkov

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 20, 2023
@bors

This comment was marked as resolved.

@petrochenkov
Copy link
Contributor

Minimized reproduction:

mod m {
    pub(crate) type A = u8;
}

pub use m::*; // warning: glob import doesn't reexport anything because no candidate is public enough

fn main() {
    let _: A;
}

This warning uses a wrong model of glob import's behavior.
It assumes that everything smaller than the glob's nominal visibility (pub) is filtered away, while it's not actually filtered, just lowered in visibility.

@petrochenkov
Copy link
Contributor

This warning uses a wrong model of glob import's behavior.
It assumes that everything smaller than the glob's nominal visibility (pub) is filtered away, while it's not actually filtered, just lowered in visibility.

Sigh, turns out this was the right model of glob import's behavior, and for globs we produced the same error as for single imports in the same case.
But then it was changed into a lint in #65539, I need to re-read that thread.

@petrochenkov
Copy link
Contributor

petrochenkov commented Oct 7, 2023

On closer look, the lint currently works as expected, the change in this PR is not correct.

The only problem is that it is not really an unused imports lint.
The lint message can be extended to better reflect what this lint wants to say:

glob import doesn't reexport anything because no candidate is public enough

=>

glob import doesn't reexport anything with visibility `pub` because no imported item is public enough
NOTE: the most public imported item is `pub(crate)`
SUGGESTION: reduce the glob import's visibility or increase visibility of imported items

Let me check if there's any more appropriate category for lint than UNUSED_IMPORTS.

@petrochenkov
Copy link
Contributor

petrochenkov commented Oct 7, 2023

Yeah, besides introducing a new lint name, which I'm hesitant to do, the only plausible candidates are UNUSED_IMPORTS and maybe HIDDEN_GLOB_REEXPORTS and UNREACHABLE_PUB.

Let's keep it UNUSED_IMPORTS for now and just improve the message wording and suggestions.
@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 Oct 7, 2023
@bvanjoi
Copy link
Contributor Author

bvanjoi commented Oct 8, 2023

NOTE: the most public imported item is pub(crate)

We cannot obtain concrete information (such as pub(crate) or pub(super)) from ty::Visibility::Restricted, which implies that we need to store ast::Visibility into vis during the resolution process.

@petrochenkov
Copy link
Contributor

Printing whatever is available from ty::Visibility would be enogh.

@bors

This comment was marked as resolved.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 15, 2023
report `unused_import` for empty reexports even it is pub

Fixes rust-lang#116032

An easy fix. r? `@petrochenkov`

(Discovered this issue while reviewing rust-lang#115993.)
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 16, 2023
report `unused_import` for empty reexports even it is pub

Fixes rust-lang#116032

An easy fix. r? `@petrochenkov`

(Discovered this issue while reviewing rust-lang#115993.)
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 19, 2023
report `unused_import` for empty reexports even it is pub

Fixes rust-lang#116032

An easy fix. r? `@petrochenkov`

(Discovered this issue while reviewing rust-lang#115993.)
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 20, 2023
report `unused_import` for empty reexports even it is pub

Fixes rust-lang#116032

An easy fix. r? `@petrochenkov`

(Discovered this issue while reviewing rust-lang#115993.)
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 23, 2023
report `unused_import` for empty reexports even it is pub

Fixes rust-lang#116032

An easy fix. r? `@petrochenkov`

(Discovered this issue while reviewing rust-lang#115993.)
@bvanjoi
Copy link
Contributor Author

bvanjoi commented Oct 28, 2023

I have postponed this lint report until the privacy check in order to print the maximum visibility information.

flip1995 pushed a commit to flip1995/rust that referenced this pull request Nov 2, 2023
report `unused_import` for empty reexports even it is pub

Fixes rust-lang#116032

An easy fix. r? `@petrochenkov`

(Discovered this issue while reviewing rust-lang#115993.)
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bvanjoi bvanjoi force-pushed the fix-115966 branch 2 times, most recently from 96e0a95 to 6521251 Compare November 5, 2023 09:50
@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Nov 28, 2023
@bvanjoi bvanjoi force-pushed the fix-115966 branch 2 times, most recently from 3f52b4c to 244dd83 Compare November 30, 2023 15:10
@bvanjoi
Copy link
Contributor Author

bvanjoi commented Nov 30, 2023

ci is green.

@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 Nov 30, 2023
compiler/rustc_middle/src/ty/mod.rs Outdated Show resolved Hide resolved
compiler/rustc_privacy/src/lib.rs Outdated Show resolved Hide resolved
compiler/rustc_lint_defs/src/lib.rs Outdated Show resolved Hide resolved
@petrochenkov petrochenkov 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 Nov 30, 2023
@rust-log-analyzer

This comment has been minimized.

@bvanjoi
Copy link
Contributor Author

bvanjoi commented Dec 1, 2023

@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 Dec 1, 2023
@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Dec 1, 2023

📌 Commit d0941f9 has been approved by petrochenkov

It is now in the queue for this repository.

@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 Dec 1, 2023
@bors
Copy link
Contributor

bors commented Dec 1, 2023

⌛ Testing commit d0941f9 with merge 64d7e0d...

@bors
Copy link
Contributor

bors commented Dec 1, 2023

☀️ Test successful - checks-actions
Approved by: petrochenkov
Pushing 64d7e0d to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Dec 1, 2023
@bors bors merged commit 64d7e0d into rust-lang:master Dec 1, 2023
12 checks passed
@rustbot rustbot added this to the 1.76.0 milestone Dec 1, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (64d7e0d): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.8% [-1.8%, -1.8%] 1
Improvements ✅
(secondary)
-2.5% [-2.9%, -2.0%] 2
All ❌✅ (primary) -1.8% [-1.8%, -1.8%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 672.331s -> 672.427s (0.01%)
Artifact size: 313.37 MiB -> 313.37 MiB (0.00%)

calebcartwright pushed a commit to calebcartwright/rust that referenced this pull request Jun 22, 2024
report `unused_import` for empty reexports even it is pub

Fixes rust-lang#116032

An easy fix. r? `@petrochenkov`

(Discovered this issue while reviewing rust-lang#115993.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. 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.

False positive #[warn(unused_imports)] warning while glob importing macros defined in nested modules
6 participants