Skip to content

vis note for no pub reexports glob import - #115993

Merged
bors merged 1 commit into
rust-lang:masterfrom
bvanjoi:fix-115966
Dec 1, 2023
Merged

vis note for no pub reexports glob import#115993
bors merged 1 commit into
rust-lang:masterfrom
bvanjoi:fix-115966

Conversation

@bvanjoi

Copy link
Copy Markdown
Contributor

Fixes#115966

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

r? @petrochenkov

@rustbotrustbot 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
Comment threadcompiler/rustc_resolve/src/imports.rs Outdated
@bors

This comment was marked as resolved.

@petrochenkov

Copy link
Copy Markdown
Contributor

Minimized reproduction:

mod m {pub(crate)typeA = u8;}pubuse m::*;// warning: glob import doesn't reexport anything because no candidate is public enoughfnmain(){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
Copy Markdown
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

petrochenkov commented Oct 7, 2023

Copy link
Copy Markdown
Contributor

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

petrochenkov commented Oct 7, 2023

Copy link
Copy Markdown
Contributor

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

@rustbotrustbot 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
Copy Markdown
ContributorAuthor

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
Copy Markdown
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
Fixesrust-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
Fixesrust-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
Fixesrust-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
Fixesrust-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
Fixesrust-lang#116032
An easy fix. r? `@petrochenkov`
(Discovered this issue while reviewing rust-lang#115993.)
@bvanjoi

Copy link
Copy Markdown
ContributorAuthor

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

Comment threadtests/ui/imports/no-reexports-but-used.rs Outdated
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
Fixesrust-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
bvanjoiforce-pushed the fix-115966 branch 2 times, most recently from 96e0a95 to 6521251CompareNovember 5, 2023 09:50
@rustbotrustbot 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
bvanjoiforce-pushed the fix-115966 branch 2 times, most recently from 3f52b4c to 244dd83CompareNovember 30, 2023 15:10
@bvanjoi

Copy link
Copy Markdown
ContributorAuthor

ci is green.

@rustbot ready

@rustbotrustbot 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
Comment threadcompiler/rustc_middle/src/ty/mod.rs Outdated
Comment threadtests/ui/privacy/private-variant-reexport.stderr
Comment threadcompiler/rustc_privacy/src/lib.rs Outdated
Comment threadcompiler/rustc_lint_defs/src/lib.rs Outdated
@petrochenkovpetrochenkov 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
Comment threadcompiler/rustc_resolve/src/imports.rs Outdated
@rust-log-analyzer

This comment has been minimized.

@bvanjoi

Copy link
Copy Markdown
ContributorAuthor

@rustbot ready

@rustbotrustbot 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
Copy Markdown
Contributor

@bors r+

@bors

bors commented Dec 1, 2023

Copy link
Copy Markdown
Collaborator

📌 Commit d0941f9 has been approved by petrochenkov

It is now in the queue for this repository.

@borsbors 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

bors commented Dec 1, 2023

Copy link
Copy Markdown
Collaborator

⌛ Testing commit d0941f9 with merge 64d7e0d...

@bors

bors commented Dec 1, 2023

Copy link
Copy Markdown
Collaborator

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

@borsbors added the merged-by-bors This PR was explicitly merged by bors. label Dec 1, 2023
@bors
bors merged commit 64d7e0d into rust-lang:masterDec 1, 2023
@rustbotrustbot added this to the 1.76.0 milestone Dec 1, 2023
@rust-timer

Copy link
Copy Markdown
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.

meanrangecount
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
Fixesrust-lang#116032
An easy fix. r? `@petrochenkov`
(Discovered this issue while reviewing rust-lang#115993.)
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-borsThis PR was explicitly merged by bors.S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant 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

@bvanjoi@bors@petrochenkov@rust-log-analyzer@rust-timer@rustbot