Fix inline const pattern unsafety checking in THIR
THIR unsafety checking was getting a cycle of function unsafety checking -> building THIR for the function -> evaluating pattern inline constants in the function -> building MIR for the inline constant -> checking unsafety of functions (so that THIR can be stolen) This is fixed by not stealing THIR when generating MIR but instead when unsafety checking. This leaves an issue with pattern inline constants not being unsafety checked because they are evaluated away when generating THIR. To fix that we now represent inline constants in THIR patterns and visit them in THIR unsafety checking.
This commit is contained in:
parent
e7bdc5f9f8
commit
5cc83fd4a5
24 changed files with 239 additions and 50 deletions
|
@ -636,7 +636,8 @@ impl<'tcx> Pat<'tcx> {
|
|||
Wild | Range(..) | Binding { subpattern: None, .. } | Constant { .. } | Error(_) => {}
|
||||
AscribeUserType { subpattern, .. }
|
||||
| Binding { subpattern: Some(subpattern), .. }
|
||||
| Deref { subpattern } => subpattern.walk_(it),
|
||||
| Deref { subpattern }
|
||||
| InlineConstant { subpattern, .. } => subpattern.walk_(it),
|
||||
Leaf { subpatterns } | Variant { subpatterns, .. } => {
|
||||
subpatterns.iter().for_each(|field| field.pattern.walk_(it))
|
||||
}
|
||||
|
@ -764,6 +765,11 @@ pub enum PatKind<'tcx> {
|
|||
value: mir::Const<'tcx>,
|
||||
},
|
||||
|
||||
InlineConstant {
|
||||
value: mir::UnevaluatedConst<'tcx>,
|
||||
subpattern: Box<Pat<'tcx>>,
|
||||
},
|
||||
|
||||
Range(Box<PatRange<'tcx>>),
|
||||
|
||||
/// Matches against a slice, checking the length and extracting elements.
|
||||
|
@ -924,6 +930,9 @@ impl<'tcx> fmt::Display for Pat<'tcx> {
|
|||
write!(f, "{subpattern}")
|
||||
}
|
||||
PatKind::Constant { value } => write!(f, "{value}"),
|
||||
PatKind::InlineConstant { value: _, ref subpattern } => {
|
||||
write!(f, "{} (from inline const)", subpattern)
|
||||
}
|
||||
PatKind::Range(box PatRange { lo, hi, end }) => {
|
||||
write!(f, "{lo}")?;
|
||||
write!(f, "{end}")?;
|
||||
|
|
|
@ -233,16 +233,17 @@ pub fn walk_pat<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, pat: &Pat<'
|
|||
}
|
||||
}
|
||||
Constant { value: _ } => {}
|
||||
InlineConstant { value: _, subpattern } => visitor.visit_pat(subpattern),
|
||||
Range(_) => {}
|
||||
Slice { prefix, slice, suffix } | Array { prefix, slice, suffix } => {
|
||||
for subpattern in prefix.iter() {
|
||||
visitor.visit_pat(&subpattern);
|
||||
visitor.visit_pat(subpattern);
|
||||
}
|
||||
if let Some(pat) = slice {
|
||||
visitor.visit_pat(&pat);
|
||||
visitor.visit_pat(pat);
|
||||
}
|
||||
for subpattern in suffix.iter() {
|
||||
visitor.visit_pat(&subpattern);
|
||||
visitor.visit_pat(subpattern);
|
||||
}
|
||||
}
|
||||
Or { pats } => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue