Skip to content

Fix order-dependent visibility diagnostics#155948

Open
SynapLink wants to merge 1 commit intorust-lang:mainfrom
SynapLink:fix/pub-visibility-order
Open

Fix order-dependent visibility diagnostics#155948
SynapLink wants to merge 1 commit intorust-lang:mainfrom
SynapLink:fix/pub-visibility-order

Conversation

@SynapLink
Copy link
Copy Markdown
Contributor

@SynapLink SynapLink commented Apr 28, 2026

Fixes #40066.
Fixes #109657.
Delay visibility path diagnostics until module collection has finished, so paths to later non-ancestor modules report E0742 instead of an unresolved path error.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 28, 2026
@rust-log-analyzer

This comment has been minimized.

@SynapLink SynapLink force-pushed the fix/pub-visibility-order branch from bfb4b8a to 21b1458 Compare April 28, 2026 23:08
@SynapLink SynapLink marked this pull request as ready for review April 29, 2026 00:19
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 29, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Apr 29, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 29, 2026

r? @mu001999

rustbot has assigned @mu001999.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 20 candidates

@petrochenkov petrochenkov self-assigned this Apr 29, 2026
Comment thread compiler/rustc_resolve/src/build_reduced_graph.rs Outdated
Comment thread compiler/rustc_resolve/src/build_reduced_graph.rs Outdated
Comment thread compiler/rustc_resolve/src/build_reduced_graph.rs Outdated
Comment thread compiler/rustc_resolve/src/build_reduced_graph.rs Outdated
@petrochenkov petrochenkov 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-review Status: Awaiting review from the assignee but also interested parties. labels Apr 29, 2026
@SynapLink SynapLink force-pushed the fix/pub-visibility-order branch from 21b1458 to 4f56ffe Compare April 29, 2026 17:51
@SynapLink
Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 29, 2026
Comment thread compiler/rustc_resolve/src/build_reduced_graph.rs Outdated
@SynapLink SynapLink force-pushed the fix/pub-visibility-order branch from 4f56ffe to 843b87b Compare April 30, 2026 07:20

fn report_delayed_vis_resolution_errors(&mut self) {
for DelayedVisResolutionError { vis, parent_scope, error } in
std::mem::take(&mut self.delayed_vis_resolution_errors)
Copy link
Copy Markdown
Contributor

@petrochenkov petrochenkov Apr 30, 2026

Choose a reason for hiding this comment

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

Suggested change
std::mem::take(&mut self.delayed_vis_resolution_errors)
mem::take(&mut self.delayed_vis_resolution_errors)

Nit: proper importing.

View changes since the review

std::mem::take(&mut self.delayed_vis_resolution_errors)
{
match self.try_resolve_visibility(parent_scope, &vis, VisResolutionMode::Finalize) {
Ok(_) => {
Copy link
Copy Markdown
Contributor

@petrochenkov petrochenkov Apr 30, 2026

Choose a reason for hiding this comment

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

Suggested change
Ok(_) => {
Ok(_) => self.report_vis_error(error),

Nit: shorter formatting.

View changes since the review

Res::Def(self.r.tcx.def_kind(def_id), def_id)
}
impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
fn visibility_path_segments(
Copy link
Copy Markdown
Contributor

@petrochenkov petrochenkov Apr 30, 2026

Choose a reason for hiding this comment

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

This method is no longer necessary, could you inline it back to its place?

View changes since the review

}

fn try_resolve_visibility<'ast>(
pub(crate) fn try_resolve_visibility(
Copy link
Copy Markdown
Contributor

@petrochenkov petrochenkov Apr 30, 2026

Choose a reason for hiding this comment

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

There's an existing impl<'ra, 'tcx> Resolver<'ra, 'tcx> { ... } block above, you could put this function there.

View changes since the review

finalize: bool,
) -> Result<Visibility, VisResolutionError<'ast>> {
let parent_scope = &self.parent_scope;
parent_scope: ParentScope<'ra>,
Copy link
Copy Markdown
Contributor

@petrochenkov petrochenkov Apr 30, 2026

Choose a reason for hiding this comment

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

Suggested change
parent_scope: ParentScope<'ra>,
parent_scope: &ParentScope<'ra>,

View changes since the review

if finalize {
self.r.record_partial_res(id, PartialRes::new(res));
if matches!(mode, VisResolutionMode::FinalizeAndRecord) {
self.record_partial_res(id, PartialRes::new(res));
Copy link
Copy Markdown
Contributor

@petrochenkov petrochenkov Apr 30, 2026

Choose a reason for hiding this comment

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

Was VisResolutionMode introduced to avoid calling record_partial_res twice?
I don't think we need it, it would be better to call record_partial_res only if we are returning Ok instead.

View changes since the review

@petrochenkov petrochenkov 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-review Status: Awaiting review from the assignee but also interested parties. labels Apr 30, 2026
@SynapLink SynapLink force-pushed the fix/pub-visibility-order branch from 843b87b to f7c62f5 Compare April 30, 2026 18:52
@SynapLink
Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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.

unexpected behavior of pub(in other_module) Error on bad pub(path) depends on module ordering

5 participants