Skip to content

Remove strict invariant node_type on hir_type during ty privacy visit#157883

Open
Shourya742 wants to merge 2 commits into
rust-lang:mainfrom
Shourya742:2026-06-14-remove-strict-invariant-ty-privacy-vist
Open

Remove strict invariant node_type on hir_type during ty privacy visit#157883
Shourya742 wants to merge 2 commits into
rust-lang:mainfrom
Shourya742:2026-06-14-remove-strict-invariant-ty-privacy-vist

Conversation

@Shourya742

@Shourya742 Shourya742 commented Jun 14, 2026

Copy link
Copy Markdown
Member

closes: #157772

r? @BoxyUwU

@rustbot rustbot added 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. labels Jun 14, 2026
Comment on lines +1184 to +1191
if let Some(ty) = self
.maybe_typeck_results
.unwrap_or_else(|| span_bug!(hir_ty.span, "`hir::Ty` outside of a body"))
.node_type_opt(hir_ty.hir_id)
{
return;
if self.visit(ty).is_break() {
return;
}

@Shourya742 Shourya742 Jun 14, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I am not fully sure this change is right, but this is how I am thinking about it. This used node_type before, so visit_ty was assuming every hir_ty would already have a type entry in TypeckResults. But the comment in writeback::visit_ty makes it sound like that is not always true on some error paths, since writeback may just not write a final type entry for that hir_ty. So based on that, I changed this visit_ty to handle missing type entries and just keep walking the type tree.

I hope the thought process is sane. And I am not breaking any invariant (like I am not seeing any test fail :P)

View changes since the review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we instead fix writeback to ensure we always have a type recorded, even on error paths?

@Shourya742 Shourya742 changed the title Remove strict invariant ty_type on hir_type during ty privacy visit Remove strict invariant node_type on hir_type during ty privacy visit Jun 14, 2026
if self.visit(ty).is_break() {
return;
}
}

@qaijuang qaijuang Jun 14, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe ?

Suggested change
}
if let Some(ty) = self
.maybe_typeck_results
.unwrap_or_else(|| span_bug!(hir_ty.span, "`hir::Ty` outside of a body"))
.node_type_opt(hir_ty.hir_id)
&& self.visit(ty).is_break() {
return;
}

View changes since the review

@Shourya742 Shourya742 Jun 14, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yup, but I am following the pattern how its written for other visit_* methods with node_type_opt. I initially wrote the same but changed to the current one following other sites. :P

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.

[ICE]: node_type: no type for node HirId

5 participants