resolve: fix effective visibilities for items in ambiguous glob sets#159039
resolve: fix effective visibilities for items in ambiguous glob sets#159039calvinrp wants to merge 2 commits into
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
| // a private facade, lost its exported effective visibility. The defining crate then | ||
| // skipped encoding its optimized MIR (and warned dead_code) while name resolution still | ||
| // exported the item and it remained `cross_crate_inlinable`, so downstream crates failed | ||
| // with "missing optimized MIR". The dead_code half is checked by `#![deny(dead_code)]` |
There was a problem hiding this comment.
Is this accurate, there is no #![deny(dead_code)] in the auxiliary crate or in this test? There is one in the -reachable test though, so maybe that meant to say the dead code half is checked by that other test?
There was a problem hiding this comment.
Good catch — the comment was inaccurate: there is no #![deny(dead_code)] in this test or its auxiliary crate. The dead-code half of the regression is pinned by the sibling ambiguous-import-visibility-globglob-reachable.rs test (its #![deny(dead_code)] plus the effective-visibility assertions make the pre-fix spurious dead_code fail there); this test pins only the missing-MIR half. Fixed the comment in 159b9a0 to point at the sibling test. I kept deny(dead_code) out of this test's aux crate deliberately — pre-fix it would fail the aux build and mask the missing-MIR failure mode this test exists to pin.
…uwer Rollup of 12 pull requests Successful merges: - #157690 (codegen_ssa: pack small const aggregates into immediate stores) - #159005 (Use `as_lang_item` instead of repeatedly matching) - #156735 (Move NativeLib::filename to the rmeta-link archive member) - #157153 (allow `Allocator`s to be used as `#[global_allocator]`s) - #158767 (merge DefKind::InlineConst into AnonConst) - #159039 (resolve: fix effective visibilities for items in ambiguous glob sets) - #158732 (Apply MCP 1003 and move diagnostics.rs into its own module) - #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)
…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
|
This pull request was unapproved. This PR was contained in a rollup (#159104), which was closed. |
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