ptr_arg: fix panic when pattern type is not in tcx

This commit is contained in:
Georg Brandl 2015-08-22 08:57:05 +02:00
parent e1a4248e68
commit e92bf84a53

View File

@ -45,11 +45,8 @@ impl LintPass for PtrArg {
fn check_fn(cx: &Context, decl: &FnDecl) {
for arg in &decl.inputs {
if arg.ty.node == TyInfer { // "self" arguments
continue;
}
let ref sty = cx.tcx.pat_ty(&*arg.pat).sty;
if let &ty::TyRef(_, ty::TypeAndMut { ty, mutbl: MutImmutable }) = sty {
if let Some(pat_ty) = cx.tcx.pat_ty_opt(&*arg.pat) {
if let ty::TyRef(_, ty::TypeAndMut { ty, mutbl: MutImmutable }) = pat_ty.sty {
if match_type(cx, ty, &VEC_PATH) {
span_lint(cx, PTR_ARG, arg.ty.span,
"writing `&Vec<_>` instead of `&[_]` involves one more reference \
@ -63,3 +60,4 @@ fn check_fn(cx: &Context, decl: &FnDecl) {
}
}
}
}