Skip to content

resolve: fix effective visibilities for items in ambiguous glob sets#159039

Open
calvinrp wants to merge 2 commits into
rust-lang:mainfrom
calvinrp:fix/effective-vis-glob-ambiguity
Open

resolve: fix effective visibilities for items in ambiguous glob sets#159039
calvinrp wants to merge 2 commits into
rust-lang:mainfrom
calvinrp:fix/effective-vis-glob-ambiguity

Conversation

@calvinrp

@calvinrp calvinrp commented Jul 9, 2026

Copy link
Copy Markdown

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

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 9, 2026
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jul 9, 2026
@rustbot

rustbot commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

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 (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added A-resolve Area: Name/path resolution done by `rustc_resolve` specifically A-visibility Area: Visibility / privacy regression-from-stable-to-stable Performance or correctness regression from one stable version to another. labels Jul 9, 2026
@rustbot

This comment has been minimized.

@rustbot rustbot added the I-prioritize Issue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical} label Jul 9, 2026
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.
@calvinrp calvinrp force-pushed the fix/effective-vis-glob-ambiguity branch from e84a2ff to 299a71d Compare July 9, 2026 21:24
@theemathas theemathas removed regression-from-stable-to-stable Performance or correctness regression from one stable version to another. I-prioritize Issue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical} labels Jul 9, 2026
@workingjubilee

This comment was marked as outdated.

@calvinrp

This comment was marked as resolved.

@petrochenkov

petrochenkov commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

We can do this, because effective visibilities are not precise and can be conservative.
As it's seen from the diff we previously updated a single ambiguity_vis_max import to "exported", but we need to do it with the whole import chain, and that is what this PR does.
@bors r+

@rust-bors

rust-bors Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 299a71d has been approved by petrochenkov

It is now in the queue for this repository.

@rust-bors rust-bors Bot 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 Jul 10, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 10, 2026
…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
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 10, 2026
…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
rust-bors Bot pushed a commit that referenced this pull request Jul 10, 2026
…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)
@theemathas theemathas added beta-nominated Nominated for backporting to the compiler in the beta channel. stable-nominated Nominated for backporting to the compiler in the stable channel. labels Jul 10, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 10, 2026
…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)]`

@lqd lqd Jul 10, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

View changes since the review

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

rust-bors Bot pushed a commit that referenced this pull request Jul 10, 2026
…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)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 10, 2026
…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
@rust-bors rust-bors Bot 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 10, 2026
@rust-bors

rust-bors Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

⚠️ A new commit 159b9a0c557ed43c9be3d52a58b8cbf10fbc2f4f was pushed.

This pull request was unapproved.

This PR was contained in a rollup (#159104), which was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-resolve Area: Name/path resolution done by `rustc_resolve` specifically A-visibility Area: Visibility / privacy beta-nominated Nominated for backporting to the compiler in the beta channel. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. stable-nominated Nominated for backporting to the compiler in the stable channel. 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.

Regression 1.96.1 → 1.97.0: "missing optimized MIR" for pub fn glob-reexported alongside a restricted glob duplicate

6 participants