Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions compiler/rustc_privacy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1181,15 +1181,14 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {

fn visit_ty(&mut self, hir_ty: &'tcx hir::Ty<'tcx, AmbigArg>) {
self.span = hir_ty.span;
if self
.visit(
self.maybe_typeck_results
.unwrap_or_else(|| span_bug!(hir_ty.span, "`hir::Ty` outside of a body"))
.node_type(hir_ty.hir_id),
)
.is_break()
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;
}
Comment on lines +1184 to +1191

@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?

}

@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


intravisit::walk_ty(self, hir_ty);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//@ check-pass
#![feature(min_generic_const_args, adt_const_params)]

// Regression test for an ICE in privacy checking while walking the `T` qself
// of `T::ASSOC` inside a tuple const argument.

fn takes_tuple<const N: ()>() {}

fn generic_caller<T, const N: u32>() {
takes_tuple::<{ (N, T::ASSOC) }>;
}

fn main() {}
Loading