Skip to content

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

Merged
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
calvinrp:fix/effective-vis-glob-ambiguity
Jul 14, 2026
Merged

resolve: fix effective visibilities for items in ambiguous glob sets#159039
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
calvinrp:fix/effective-vis-glob-ambiguity

Conversation

@calvinrp

@calvinrp calvinrp commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

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 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
Comment thread tests/ui/imports/ambiguous-import-visibility-globglob-mir.rs Outdated
@rust-bors

rust-bors Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

💔 Test for 9cdbad9 failed: CI. Failed job:

@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job x86_64-gnu-llvm-21-3 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)

running 468 tests
##[error]The runner has received a shutdown signal. This can happen when the runner service is stopped, or a manually started runner is canceled.
..
Session terminated, killing shell......::group::Clock drift check
  local time: ..Mon Jul 13 18:27:20 UTC 2026
  network time: ...................................................Mon, 13 Jul 2026 18:27:20 GMT
.::endgroup::
............................ 87/468
.................................................. ...killed.
##[error]The operation was canceled.
Cleaning up orphan processes

@JonathanBrouwer

Copy link
Copy Markdown
Contributor

@bors try jobs=x86_64-gnu-llvm-21-3
@bors retry

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jul 13, 2026
…<try>

resolve: fix effective visibilities for items in ambiguous glob sets


try-job: x86_64-gnu-llvm-21-3
@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 13, 2026
@rust-bors

rust-bors Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 1554fd0 (1554fd0a2c5b0b87b39fb5e249754632728f16ba)
Base parent: 225e91c (225e91c03da22cd4b9792b83c1cfc97967101614)

jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 14, 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 14, 2026
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))
@rust-bors

rust-bors Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

⌛ Testing commit 159b9a0 with merge efe31f2...

Workflow: https://github.com/rust-lang/rust/actions/runs/29304935407

rust-bors Bot pushed a commit that referenced this pull request Jul 14, 2026
…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
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 14, 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
@jhpratt

jhpratt commented Jul 14, 2026

Copy link
Copy Markdown
Member

@bors yield

Yielding to encompassing rollup

@rust-bors

rust-bors Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Auto build was cancelled. Cancelled workflows:

The next pull request likely to be tested is #159262.

rust-bors Bot pushed a commit that referenced this pull request Jul 14, 2026
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))
@rust-bors

rust-bors Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

⌛ Testing commit 159b9a0 with merge 2354c2d...

Workflow: https://github.com/rust-lang/rust/actions/runs/29305537191

rust-bors Bot pushed a commit that referenced this pull request Jul 14, 2026
…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
@jhpratt

jhpratt commented Jul 14, 2026

Copy link
Copy Markdown
Member

again

@bors yield

@rust-bors

rust-bors Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Auto build was cancelled. Cancelled workflows:

The next pull request likely to be tested is #159263.

rust-bors Bot pushed a commit that referenced this pull request Jul 14, 2026
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))
@rust-bors rust-bors Bot merged commit 86ad394 into rust-lang:main Jul 14, 2026
14 of 15 checks passed
rust-timer added a commit that referenced this pull request Jul 14, 2026
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
@rustbot rustbot added this to the 1.99.0 milestone Jul 14, 2026
rust-bors Bot pushed a commit that referenced this pull request Jul 14, 2026
[stable] 1.97.1 release

This backports:

* #159106
* #159047

Currently not approved:

* #159039 - thread is trending towards a decline of backport
rust-bors Bot pushed a commit that referenced this pull request Jul 14, 2026
[stable] 1.97.1 release

This backports:

* #159106
* #159047

Currently not approved:

* #159039 - thread is trending towards a decline of backport
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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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

10 participants