Rustup to rustc 1.16.0-nightly (468227129 2017-01-03): Recover patterns from arguments

This commit is contained in:
Manish Goregaokar 2017-01-04 13:46:41 -08:00
parent a262e3bb0b
commit e02fac4896
9 changed files with 46 additions and 36 deletions

View file

@ -6,7 +6,7 @@ use std::collections::HashSet;
use syntax::ast;
use syntax::abi::Abi;
use syntax::codemap::Span;
use utils::{span_lint, type_is_unsafe_function};
use utils::{span_lint, type_is_unsafe_function, iter_input_pats};
/// **What it does:** Checks for functions with too many parameters.
///
@ -102,7 +102,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions {
}
}
self.check_raw_ptr(cx, unsafety, decl, &body.value, nodeid);
self.check_raw_ptr(cx, unsafety, decl, &body, nodeid);
}
fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::TraitItem) {
@ -113,8 +113,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions {
}
if let hir::TraitMethod::Provided(eid) = eid {
let expr = cx.tcx.map.body(eid).value;
self.check_raw_ptr(cx, sig.unsafety, &sig.decl, &expr, item.id);
let body = cx.tcx.map.body(eid);
self.check_raw_ptr(cx, sig.unsafety, &sig.decl, &body, item.id);
}
}
}
@ -136,11 +136,14 @@ impl<'a, 'tcx> Functions {
cx: &LateContext<'a, 'tcx>,
unsafety: hir::Unsafety,
decl: &'tcx hir::FnDecl,
expr: &'tcx hir::Expr,
body: &'tcx hir::Body,
nodeid: ast::NodeId
) {
let expr = &body.value;
if unsafety == hir::Unsafety::Normal && cx.access_levels.is_exported(nodeid) {
let raw_ptrs = decl.inputs.iter().filter_map(|arg| raw_ptr_arg(cx, arg)).collect::<HashSet<_>>();
let raw_ptrs = iter_input_pats(&decl, body).zip(decl.inputs.iter())
.filter_map(|(arg, ty)| raw_ptr_arg(arg, ty))
.collect::<HashSet<_>>();
if !raw_ptrs.is_empty() {
let mut v = DerefVisitor {
@ -154,8 +157,8 @@ impl<'a, 'tcx> Functions {
}
}
fn raw_ptr_arg(cx: &LateContext, arg: &hir::Arg) -> Option<hir::def_id::DefId> {
if let (&hir::PatKind::Binding(_, def_id, _, _), &hir::TyPtr(_)) = (&arg.pat.node, &cx.tcx.map.get(arg.id)) {
fn raw_ptr_arg(arg: &hir::Arg, ty: &hir::Ty) -> Option<hir::def_id::DefId> {
if let (&hir::PatKind::Binding(_, def_id, _, _), hir::TyPtr(_)) = (&arg.pat.node, ty.node) {
Some(def_id)
} else {
None