-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
resolve: Extend ambiguous_import_visibilities deprecation lint to glob-vs-glob ambiguities
#154149
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
petrochenkov
wants to merge
2
commits into
rust-lang:main
Choose a base branch
from
petrochenkov:globvisglob
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.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
|
|
@@ -182,6 +182,10 @@ impl<'a, 'ra, 'tcx> EffectiveVisibilitiesVisitor<'a, 'ra, 'tcx> { | |
| parent_id.level(), | ||
| tcx, | ||
| ); | ||
| if let Some(max_vis_decl) = decl.ambiguity_vis_max.get() { | ||
| // Avoid the most visible import in an ambiguous glob set being reported as unused. | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a fix for #152004. |
||
| self.update_import(max_vis_decl, parent_id); | ||
| } | ||
| } | ||
|
|
||
| fn update_def( | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -346,7 +346,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { | |
| ambiguity: CmCell::new(None), | ||
| warn_ambiguity: CmCell::new(false), | ||
| span: import.span, | ||
| vis: CmCell::new(vis), | ||
| initial_vis: vis, | ||
| ambiguity_vis_max: CmCell::new(None), | ||
| ambiguity_vis_min: CmCell::new(None), | ||
| expansion: import.parent_scope.expansion, | ||
| parent_module: Some(import.parent_scope.module), | ||
| }) | ||
|
|
@@ -371,8 +373,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { | |
| // - A glob decl is overwritten by its clone after setting ambiguity in it. | ||
| // FIXME: avoid this by removing `warn_ambiguity`, or by triggering glob re-fetch | ||
| // with the same decl in some way. | ||
| // - A glob decl is overwritten by a glob decl with larger visibility. | ||
| // FIXME: avoid this by updating this visibility in place. | ||
| // - A glob decl is overwritten by a glob decl re-fetching an | ||
| // overwritten decl from other module (the recursive case). | ||
| // Here we are detecting all such re-fetches and overwrite old decls | ||
|
|
@@ -386,8 +386,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { | |
| // FIXME: reenable the asserts when `warn_ambiguity` is removed (#149195). | ||
| // assert_ne!(old_deep_decl, deep_decl); | ||
| // assert!(old_deep_decl.is_glob_import()); | ||
| // FIXME: reenable the assert when visibility is updated in place. | ||
| // assert!(!deep_decl.is_glob_import()); | ||
| assert!(!deep_decl.is_glob_import()); | ||
| if old_glob_decl.ambiguity.get().is_some() && glob_decl.ambiguity.get().is_none() { | ||
| // Do not lose glob ambiguities when re-fetching the glob. | ||
| glob_decl.ambiguity.set_unchecked(old_glob_decl.ambiguity.get()); | ||
|
|
@@ -407,11 +406,20 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { | |
| // FIXME: remove this when `warn_ambiguity` is removed (#149195). | ||
| self.arenas.alloc_decl((*old_glob_decl).clone()) | ||
| } | ||
| } else if !old_glob_decl.vis().is_at_least(glob_decl.vis(), self.tcx) { | ||
| // We are glob-importing the same item but with greater visibility. | ||
| // FIXME: Update visibility in place, but without regressions | ||
| // (#152004, #151124, #152347). | ||
| glob_decl | ||
| } else if let old_vis = old_glob_decl.vis() | ||
| && let vis = glob_decl.vis() | ||
| && old_vis != vis | ||
| { | ||
| // We are glob-importing the same item but with a different visibility. | ||
| if vis.is_at_least(old_vis, self.tcx) { | ||
| old_glob_decl.ambiguity_vis_max.set_unchecked(Some(glob_decl)); | ||
| } else if let old_min_vis = old_glob_decl.min_vis() | ||
| && old_min_vis != vis | ||
| && old_min_vis.is_at_least(vis, self.tcx) | ||
| { | ||
| old_glob_decl.ambiguity_vis_min.set_unchecked(Some(glob_decl)); | ||
| } | ||
| old_glob_decl | ||
| } else if glob_decl.is_ambiguity_recursive() && !old_glob_decl.is_ambiguity_recursive() { | ||
| // Overwriting a non-ambiguous glob import with an ambiguous glob import. | ||
| old_glob_decl.ambiguity.set_unchecked(Some(glob_decl)); | ||
|
|
@@ -510,11 +518,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { | |
| .resolution_or_default(module, key, orig_ident_span) | ||
| .borrow_mut_unchecked(); | ||
| let old_decl = resolution.binding(); | ||
| let old_vis = old_decl.map(|d| d.vis()); | ||
|
|
||
| let t = f(self, resolution); | ||
|
|
||
| if let Some(binding) = resolution.binding() | ||
| && old_decl != Some(binding) | ||
| && (old_decl != Some(binding) || old_vis != Some(binding.vis())) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And this is a fix for #152347. |
||
| { | ||
| (binding, t, warn_ambiguity || old_decl.is_some()) | ||
| } else { | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| mod m { | ||
| pub struct S {} | ||
| } | ||
|
|
||
| mod min_vis_first { | ||
| use crate::m::*; | ||
| pub(crate) use crate::m::*; | ||
| pub use crate::m::*; | ||
|
|
||
| pub use self::S as S1; | ||
| //~^ ERROR ambiguous import visibility | ||
| //~| WARN this was previously accepted | ||
| pub(crate) use self::S as S2; | ||
| //~^ ERROR ambiguous import visibility | ||
| //~| WARN this was previously accepted | ||
| use self::S as S3; // OK | ||
| } | ||
|
|
||
| mod mid_vis_first { | ||
| pub(crate) use crate::m::*; | ||
| use crate::m::*; | ||
| pub use crate::m::*; | ||
|
|
||
| pub use self::S as S1; | ||
| //~^ ERROR ambiguous import visibility | ||
| //~| WARN this was previously accepted | ||
| pub(crate) use self::S as S2; | ||
| //~^ ERROR ambiguous import visibility | ||
| //~| WARN this was previously accepted | ||
| use self::S as S3; // OK | ||
| } | ||
|
|
||
| mod max_vis_first { | ||
| pub use crate::m::*; | ||
| use crate::m::*; | ||
| pub(crate) use crate::m::*; | ||
|
|
||
| pub use self::S as S1; | ||
| //~^ ERROR ambiguous import visibility | ||
| //~| WARN this was previously accepted | ||
| pub(crate) use self::S as S2; | ||
| //~^ ERROR ambiguous import visibility | ||
| //~| WARN this was previously accepted | ||
| use self::S as S3; // OK | ||
| } | ||
|
|
||
| fn main() {} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a fix for #151124.