resolve: fix effective visibilities for items in ambiguous glob sets#159039
Conversation
|
Thanks for the pull request, and welcome! The Rust Project is excited to review your changes, and you should hear from @petrochenkov (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
This comment has been minimized.
This comment has been minimized.
Since PR 154149, when one item is glob-imported into a module twice with different visibilities, the first-arrived declaration stays in the resolution slot and the most visible declaration of the ambiguous glob set is only recorded in `ambiguity_vis_max`. `DeclData::vis()` returns the max, so name resolution, metadata reexports and `cross_crate_inlinable` export the item at the maximum visibility, but `set_bindings_effective_visibilities` walked only the slot-resident declaration's reexport chain. When the restricted route arrives first, the definition's effective visibility caps at the restricted visibility while the item is still exported: spurious dead_code, the item missing from reachable_set, should_encode_mir returning false, and downstream crates failing with "missing optimized MIR" (a 1.96.1 -> 1.97.0 stable-to-stable regression). Generalize the one-level `ambiguity_vis_max` update that PR 154149 added in `update_import` (to keep the most visible import from being reported as unused) into a walk of that declaration's whole reexport chain: extract the chain walk into `update_decl_chain` and recurse into `ambiguity_vis_max` at every hop, so the most visible declaration drives the effective visibility of everything on its route, including the final definition. Updates are monotone, so the dual walk is order-independent. The `ambiguous_import_visibilities` lint and the PR 156284 diagnostic suppression are untouched.
e84a2ff to
299a71d
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as resolved.
This comment was marked as resolved.
|
We can do this, because effective visibilities are not precise and can be conservative. |
…biguity, r=petrochenkov resolve: fix effective visibilities for items in ambiguous glob sets Fixes rust-lang#159038 (1.96.1 → 1.97.0 regression; details there). When an item is glob-imported twice at different visibilities, effective visibility was computed from whichever declaration arrived first, not the most visible one. An exported item could then get no MIR encoded, and downstream crates fail with ``missing optimized MIR``. Fix: also walk the most visible declaration's re-export chain (`update_decl_chain`, recursing into `ambiguity_vis_max`). Lint behavior unchanged. Two regression tests added; `tests/ui/{imports,privacy,resolve}` pass with every rust-lang#154149 / rust-lang#156284 test unmodified. @rustbot label +A-resolve +A-visibility +T-compiler +regression-from-stable-to-stable
…biguity, r=petrochenkov resolve: fix effective visibilities for items in ambiguous glob sets Fixes rust-lang#159038 (1.96.1 → 1.97.0 regression; details there). When an item is glob-imported twice at different visibilities, effective visibility was computed from whichever declaration arrived first, not the most visible one. An exported item could then get no MIR encoded, and downstream crates fail with ``missing optimized MIR``. Fix: also walk the most visible declaration's re-export chain (`update_decl_chain`, recursing into `ambiguity_vis_max`). Lint behavior unchanged. Two regression tests added; `tests/ui/{imports,privacy,resolve}` pass with every rust-lang#154149 / rust-lang#156284 test unmodified. @rustbot label +A-resolve +A-visibility +T-compiler +regression-from-stable-to-stable
…uwer Rollup of 10 pull requests Successful merges: - #157690 (codegen_ssa: pack small const aggregates into immediate stores) - #157706 (Deny `todo!()` in tidy) - #159005 (Use `as_lang_item` instead of repeatedly matching) - #156735 (Move NativeLib::filename to the rmeta-link archive member) - #159039 (resolve: fix effective visibilities for items in ambiguous glob sets) - #158930 (Reorganize `tests/ui/issues` [20/N]) - #158965 (Add codegen test for Result is_ok unwrap) - #158979 (Reorganize `tests/ui/issues` [21/N]) - #159050 (assert only opaques with sub unified hidden infer are non-rigid) - #159062 (Remove unused WEAK_ONLY_LANG_ITEMS static) Failed merges: - #158732 (Apply MCP 1003 and move diagnostics.rs into its own module)
…biguity, r=petrochenkov resolve: fix effective visibilities for items in ambiguous glob sets Fixes rust-lang#159038 (1.96.1 → 1.97.0 regression; details there). When an item is glob-imported twice at different visibilities, effective visibility was computed from whichever declaration arrived first, not the most visible one. An exported item could then get no MIR encoded, and downstream crates fail with ``missing optimized MIR``. Fix: also walk the most visible declaration's re-export chain (`update_decl_chain`, recursing into `ambiguity_vis_max`). Lint behavior unchanged. Two regression tests added; `tests/ui/{imports,privacy,resolve}` pass with every rust-lang#154149 / rust-lang#156284 test unmodified. @rustbot label +A-resolve +A-visibility +T-compiler +regression-from-stable-to-stable
|
💔 Test for 9cdbad9 failed: CI. Failed job:
|
|
The job Click to see the possible cause of the failure (guessed by this bot) |
This comment has been minimized.
This comment has been minimized.
…<try> resolve: fix effective visibilities for items in ambiguous glob sets try-job: x86_64-gnu-llvm-21-3
…biguity, r=petrochenkov resolve: fix effective visibilities for items in ambiguous glob sets Fixes rust-lang#159038 (1.96.1 → 1.97.0 regression; details there). When an item is glob-imported twice at different visibilities, effective visibility was computed from whichever declaration arrived first, not the most visible one. An exported item could then get no MIR encoded, and downstream crates fail with ``missing optimized MIR``. Fix: also walk the most visible declaration's re-export chain (`update_decl_chain`, recursing into `ambiguity_vis_max`). Lint behavior unchanged. Two regression tests added; `tests/ui/{imports,privacy,resolve}` pass with every rust-lang#154149 / rust-lang#156284 test unmodified. @rustbot label +A-resolve +A-visibility +T-compiler +regression-from-stable-to-stable
Rollup of 6 pull requests Successful merges: - #159039 (resolve: fix effective visibilities for items in ambiguous glob sets) - #156047 (Fix trait method resolution on an adjusted never type) - #159061 (Skip trivial cast lint for trait object upcasts) - #159241 (Update books) - #159248 (compiler: Remove `-Zmutable-noalias`) - #159250 (Rename `errors.rs` file to `diagnostics.rs` (13/N))
|
⌛ Testing commit 159b9a0 with merge efe31f2... Workflow: https://github.com/rust-lang/rust/actions/runs/29304935407 |
…petrochenkov resolve: fix effective visibilities for items in ambiguous glob sets Fixes #159038 (1.96.1 → 1.97.0 regression; details there). When an item is glob-imported twice at different visibilities, effective visibility was computed from whichever declaration arrived first, not the most visible one. An exported item could then get no MIR encoded, and downstream crates fail with ``missing optimized MIR``. Fix: also walk the most visible declaration's re-export chain (`update_decl_chain`, recursing into `ambiguity_vis_max`). Lint behavior unchanged. Two regression tests added; `tests/ui/{imports,privacy,resolve}` pass with every #154149 / #156284 test unmodified. @rustbot label +A-resolve +A-visibility +T-compiler +regression-from-stable-to-stable
…biguity, r=petrochenkov resolve: fix effective visibilities for items in ambiguous glob sets Fixes rust-lang#159038 (1.96.1 → 1.97.0 regression; details there). When an item is glob-imported twice at different visibilities, effective visibility was computed from whichever declaration arrived first, not the most visible one. An exported item could then get no MIR encoded, and downstream crates fail with ``missing optimized MIR``. Fix: also walk the most visible declaration's re-export chain (`update_decl_chain`, recursing into `ambiguity_vis_max`). Lint behavior unchanged. Two regression tests added; `tests/ui/{imports,privacy,resolve}` pass with every rust-lang#154149 / rust-lang#156284 test unmodified. @rustbot label +A-resolve +A-visibility +T-compiler +regression-from-stable-to-stable
|
@bors yield Yielding to encompassing rollup |
|
Auto build was cancelled. Cancelled workflows: The next pull request likely to be tested is #159262. |
Rollup of 6 pull requests Successful merges: - #159039 (resolve: fix effective visibilities for items in ambiguous glob sets) - #156047 (Fix trait method resolution on an adjusted never type) - #158981 (Fix where-bound suggestion with legacy const generics) - #159061 (Skip trivial cast lint for trait object upcasts) - #159248 (compiler: Remove `-Zmutable-noalias`) - #159250 (Rename `errors.rs` file to `diagnostics.rs` (13/N))
|
⌛ Testing commit 159b9a0 with merge 2354c2d... Workflow: https://github.com/rust-lang/rust/actions/runs/29305537191 |
…petrochenkov resolve: fix effective visibilities for items in ambiguous glob sets Fixes #159038 (1.96.1 → 1.97.0 regression; details there). When an item is glob-imported twice at different visibilities, effective visibility was computed from whichever declaration arrived first, not the most visible one. An exported item could then get no MIR encoded, and downstream crates fail with ``missing optimized MIR``. Fix: also walk the most visible declaration's re-export chain (`update_decl_chain`, recursing into `ambiguity_vis_max`). Lint behavior unchanged. Two regression tests added; `tests/ui/{imports,privacy,resolve}` pass with every #154149 / #156284 test unmodified. @rustbot label +A-resolve +A-visibility +T-compiler +regression-from-stable-to-stable
|
again @bors yield |
|
Auto build was cancelled. Cancelled workflows: The next pull request likely to be tested is #159263. |
Rollup of 6 pull requests Successful merges: - #159039 (resolve: fix effective visibilities for items in ambiguous glob sets) - #158981 (Fix where-bound suggestion with legacy const generics) - #159061 (Skip trivial cast lint for trait object upcasts) - #159241 (Update books) - #159248 (compiler: Remove `-Zmutable-noalias`) - #159250 (Rename `errors.rs` file to `diagnostics.rs` (13/N))
Rollup merge of #159039 - calvinrp:fix/effective-vis-glob-ambiguity, r=petrochenkov resolve: fix effective visibilities for items in ambiguous glob sets Fixes #159038 (1.96.1 → 1.97.0 regression; details there). When an item is glob-imported twice at different visibilities, effective visibility was computed from whichever declaration arrived first, not the most visible one. An exported item could then get no MIR encoded, and downstream crates fail with ``missing optimized MIR``. Fix: also walk the most visible declaration's re-export chain (`update_decl_chain`, recursing into `ambiguity_vis_max`). Lint behavior unchanged. Two regression tests added; `tests/ui/{imports,privacy,resolve}` pass with every #154149 / #156284 test unmodified. @rustbot label +A-resolve +A-visibility +T-compiler +regression-from-stable-to-stable
View all comments
Fixes #159038 (1.96.1 → 1.97.0 regression; details there).
When an item is glob-imported twice at different visibilities, effective visibility was computed from whichever declaration arrived first, not the most visible one. An exported item could then get no MIR encoded, and downstream crates fail with
missing optimized MIR.Fix: also walk the most visible declaration's re-export chain (
update_decl_chain, recursing intoambiguity_vis_max). Lint behavior unchanged. Two regression tests added;tests/ui/{imports,privacy,resolve}pass with every #154149 / #156284 test unmodified.@rustbot label +A-resolve +A-visibility +T-compiler +regression-from-stable-to-stable