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:
bors-servo 2015-07-30 18:20:53 -06:00
commit fd211dcc92

View file

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