mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-02 02:46:06 +00:00
ptr_arg: fix panic when pattern type is not in tcx
This commit is contained in:
parent
e1a4248e68
commit
e92bf84a53
@ -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`");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user