Only compute is_freeze
for layout-constrained ADTs
Places are usually shallow and quick to visit. By contrast, computing `is_freeze` can be much costlier, involving inference and trait solving. Making sure to call `is_freeze` only when necessary should be beneficial for performance in most cases.
This commit is contained in:
parent
e3b1c12bec
commit
2b169ccc96
1 changed files with 16 additions and 18 deletions
|
@ -456,27 +456,25 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
|
||||||
return; // we have already visited everything by now
|
return; // we have already visited everything by now
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ExprKind::Borrow { borrow_kind, arg } => match borrow_kind {
|
ExprKind::Borrow { borrow_kind, arg } => {
|
||||||
BorrowKind::Shallow | BorrowKind::Shared | BorrowKind::Unique => {
|
let mut visitor = LayoutConstrainedPlaceVisitor::new(self.thir, self.tcx);
|
||||||
|
visit::walk_expr(&mut visitor, expr);
|
||||||
|
if visitor.found {
|
||||||
|
match borrow_kind {
|
||||||
|
BorrowKind::Shallow | BorrowKind::Shared | BorrowKind::Unique
|
||||||
if !self.thir[arg]
|
if !self.thir[arg]
|
||||||
.ty
|
.ty
|
||||||
.is_freeze(self.tcx.at(self.thir[arg].span), self.param_env)
|
.is_freeze(self.tcx.at(self.thir[arg].span), self.param_env) =>
|
||||||
{
|
{
|
||||||
let mut visitor = LayoutConstrainedPlaceVisitor::new(self.thir, self.tcx);
|
self.requires_unsafe(expr.span, BorrowOfLayoutConstrainedField)
|
||||||
visit::walk_expr(&mut visitor, expr);
|
|
||||||
if visitor.found {
|
|
||||||
self.requires_unsafe(expr.span, BorrowOfLayoutConstrainedField);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
BorrowKind::Mut { .. } => {
|
BorrowKind::Mut { .. } => {
|
||||||
let mut visitor = LayoutConstrainedPlaceVisitor::new(self.thir, self.tcx);
|
self.requires_unsafe(expr.span, MutationOfLayoutConstrainedField)
|
||||||
visit::walk_expr(&mut visitor, expr);
|
}
|
||||||
if visitor.found {
|
BorrowKind::Shallow | BorrowKind::Shared | BorrowKind::Unique => {}
|
||||||
self.requires_unsafe(expr.span, MutationOfLayoutConstrainedField);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
visit::walk_expr(self, expr);
|
visit::walk_expr(self, expr);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue