From e92bf84a535b77c65127fadc2b82d762cff8ab66 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sat, 22 Aug 2015 08:57:05 +0200 Subject: [PATCH] ptr_arg: fix panic when pattern type is not in tcx --- src/ptr_arg.rs | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/ptr_arg.rs b/src/ptr_arg.rs index f0a0592f5e2..2d09fcbcca9 100644 --- a/src/ptr_arg.rs +++ b/src/ptr_arg.rs @@ -45,20 +45,18 @@ 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 match_type(cx, ty, &VEC_PATH) { - span_lint(cx, PTR_ARG, arg.ty.span, - "writing `&Vec<_>` instead of `&[_]` involves one more reference \ - and cannot be used with non-Vec-based slices. Consider changing \ - the type to `&[...]`"); - } else if match_type(cx, ty, &STRING_PATH) { - span_lint(cx, PTR_ARG, arg.ty.span, - "writing `&String` instead of `&str` involves a new object \ - where a slice will do. Consider changing the type to `&str`"); + 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 \ + and cannot be used with non-Vec-based slices. Consider changing \ + the type to `&[...]`"); + } else if match_type(cx, ty, &STRING_PATH) { + span_lint(cx, PTR_ARG, arg.ty.span, + "writing `&String` instead of `&str` involves a new object \ + where a slice will do. Consider changing the type to `&str`"); + } } } }