diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2015-11-28 21:29:08 -0800 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2015-11-30 10:53:32 -0800 |
commit | 962c06e9dae7a3b72ff8f776d9f569a996293acd (patch) | |
tree | da9b5adea9a1e38de1a4e0b197d5a6b84f297f33 /components/plugins/lints/unrooted_must_root.rs | |
parent | 2d164f2bebb63aa35269a4c3355beea3bbdcff01 (diff) | |
download | servo-962c06e9dae7a3b72ff8f776d9f569a996293acd.tar.gz servo-962c06e9dae7a3b72ff8f776d9f569a996293acd.zip |
Fix false positive in unrooted_must_root lint.
Encountered in #8725.
Diffstat (limited to 'components/plugins/lints/unrooted_must_root.rs')
-rw-r--r-- | components/plugins/lints/unrooted_must_root.rs | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/components/plugins/lints/unrooted_must_root.rs b/components/plugins/lints/unrooted_must_root.rs index 2c8a09e2a31..c64f127e094 100644 --- a/components/plugins/lints/unrooted_must_root.rs +++ b/components/plugins/lints/unrooted_must_root.rs @@ -4,6 +4,7 @@ use rustc::front::map as ast_map; use rustc::lint::{LateContext, LintPass, LintArray, LateLintPass, LintContext}; +use rustc::middle::pat_util::pat_is_binding; use rustc::middle::ty; use rustc_front::hir; use rustc_front::intravisit as visit; @@ -206,11 +207,13 @@ impl<'a, 'b: 'a, 'tcx: 'a+'b> visit::Visitor<'a> for FnDefVisitor<'a, 'b, 'tcx> let cx = self.cx; if let hir::PatIdent(hir::BindByValue(_), _, _) = pat.node { - let ty = cx.tcx.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)) + if pat_is_binding(&cx.tcx.def_map.borrow(), pat) { + let ty = cx.tcx.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)) + } } } |