-
-
Notifications
You must be signed in to change notification settings - Fork 15k
Remove strict invariant node_type on hir_type during ty privacy visit #157883
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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; | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe ?
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||||||||||||||||||
|
|
||||||||||||||||||
| intravisit::walk_ty(self, hir_ty); | ||||||||||||||||||
|
|
||||||||||||||||||
| 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() {} |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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_typebefore, sovisit_tywas assuming everyhir_tywould already have a type entry inTypeckResults. But the comment inwriteback::visit_tymakes it sound like that is not always true on some error paths, since writeback may just not write a final type entry for thathir_ty. So based on that, I changed thisvisit_tyto 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
There was a problem hiding this comment.
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?