aboutsummaryrefslogtreecommitdiffstats
path: root/components/script_plugins/unrooted_must_root.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2017-08-15 07:31:04 -0500
committerGitHub <noreply@github.com>2017-08-15 07:31:04 -0500
commit7d9b82b9efa7b10a2e34d93df5ac535d99518f7a (patch)
tree6f19f8562d57258c06ee21ee2bdbd85f9ae2cb64 /components/script_plugins/unrooted_must_root.rs
parent41fb10c58995781d595a233afae0758427ad5cc5 (diff)
parentb5a4b8d6a09a71bd3a4ff4ae68e7a9639f9dcaad (diff)
downloadservo-7d9b82b9efa7b10a2e34d93df5ac535d99518f7a.tar.gz
servo-7d9b82b9efa7b10a2e34d93df5ac535d99518f7a.zip
Auto merge of #18046 - servo:rustup, r=emilio
Upgrade to rustc 1.21.0-nightly (13d94d5fa 2017-08-10) <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18046) <!-- Reviewable:end -->
Diffstat (limited to 'components/script_plugins/unrooted_must_root.rs')
-rw-r--r--components/script_plugins/unrooted_must_root.rs22
1 files changed, 15 insertions, 7 deletions
diff --git a/components/script_plugins/unrooted_must_root.rs b/components/script_plugins/unrooted_must_root.rs
index 5dbd2b1a3bd..f3f5e60ab62 100644
--- a/components/script_plugins/unrooted_must_root.rs
+++ b/components/script_plugins/unrooted_must_root.rs
@@ -182,7 +182,7 @@ impl<'a, 'b, 'tcx> visit::Visitor<'tcx> for FnDefVisitor<'a, 'b, 'tcx> {
}
match expr.node {
- /// Trait casts from #[must_root] types are not allowed
+ // Trait casts from #[must_root] types are not allowed
hir::ExprCast(ref subexpr, _) => require_rooted(cx, self.in_new_function, &*subexpr),
// This catches assignments... the main point of this would be to catch mutable
// references to `JS<T>`.
@@ -206,13 +206,21 @@ impl<'a, 'b, 'tcx> visit::Visitor<'tcx> for FnDefVisitor<'a, 'b, 'tcx> {
fn visit_pat(&mut self, pat: &'tcx hir::Pat) {
let cx = self.cx;
- if let hir::PatKind::Binding(hir::BindingMode::BindByValue(_), _, _, _) = pat.node {
- let ty = cx.tables.pat_ty(pat);
- if is_unrooted_ty(cx, ty, self.in_new_function) {
- cx.span_lint(UNROOTED_MUST_ROOT,
- pat.span,
- &format!("Expression of type {:?} must be rooted", ty))
+ // We want to detect pattern bindings that move a value onto the stack.
+ // When "default binding modes" https://github.com/rust-lang/rust/issues/42640
+ // are implemented, the `Unannotated` case could cause false-positives.
+ // These should be fixable by adding an explicit `ref`.
+ match pat.node {
+ hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, _, _, _) |
+ hir::PatKind::Binding(hir::BindingAnnotation::Mutable, _, _, _) => {
+ let ty = cx.tables.pat_ty(pat);
+ if is_unrooted_ty(cx, ty, self.in_new_function) {
+ cx.span_lint(UNROOTED_MUST_ROOT,
+ pat.span,
+ &format!("Expression of type {:?} must be rooted", ty))
+ }
}
+ _ => {}
}
visit::walk_pat(self, pat);