mirror of
https://github.com/servo/servo.git
synced 2025-06-15 03:44:30 +00:00
Auto merge of #6855 - pcwalton:more-rooting-soundness, r=Manishearth
plugins: Forbid trait casts of rooted objects. r? @Manishearth <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6855) <!-- Reviewable:end -->
This commit is contained in:
commit
fd211dcc92
1 changed files with 19 additions and 0 deletions
|
@ -153,6 +153,25 @@ impl LintPass for UnrootedPass {
|
|||
}
|
||||
}
|
||||
|
||||
/// Trait casts from #[must_root] types are not allowed
|
||||
fn check_expr(&mut self, cx: &Context, expr: &ast::Expr) {
|
||||
fn require_rooted(cx: &Context, in_new_function: bool, subexpr: &ast::Expr) {
|
||||
let ty = cx.tcx.expr_ty(&*subexpr);
|
||||
if is_unrooted_ty(cx, ty, in_new_function) {
|
||||
cx.span_lint(UNROOTED_MUST_ROOT,
|
||||
subexpr.span,
|
||||
&format!("Expression of type {:?} must be rooted", ty))
|
||||
}
|
||||
};
|
||||
|
||||
match expr.node {
|
||||
ast::ExprCast(ref subexpr, _) => require_rooted(cx, self.in_new_function, &*subexpr),
|
||||
_ => {
|
||||
// TODO(pcwalton): Check generics with a whitelist of allowed generics.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Partially copied from rustc::middle::lint::builtin
|
||||
// Catches `let` statements and assignments which store a #[must_root] value
|
||||
// Expressions which return out of blocks eventually end up in a `let` or assignment
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue