ptr_arg: honor allow
attr on arguments
This commit is contained in:
parent
c41916d9bd
commit
a1824e187c
@ -2,7 +2,7 @@
|
||||
|
||||
use crate::utils::ptr::get_spans;
|
||||
use crate::utils::{
|
||||
is_type_diagnostic_item, match_qpath, match_type, paths, snippet_opt, span_lint, span_lint_and_sugg,
|
||||
is_allowed, is_type_diagnostic_item, match_qpath, match_type, paths, snippet_opt, span_lint, span_lint_and_sugg,
|
||||
span_lint_and_then, walk_ptrs_hir_ty,
|
||||
};
|
||||
use if_chain::if_chain;
|
||||
@ -150,8 +150,16 @@ fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl<'_>, fn_id: HirId, opt_body_
|
||||
let fn_def_id = cx.tcx.hir().local_def_id(fn_id);
|
||||
let sig = cx.tcx.fn_sig(fn_def_id);
|
||||
let fn_ty = sig.skip_binder();
|
||||
let body = opt_body_id.map(|id| cx.tcx.hir().body(id));
|
||||
|
||||
for (idx, (arg, ty)) in decl.inputs.iter().zip(fn_ty.inputs()).enumerate() {
|
||||
// Honor the allow attribute on parameters. See issue 5644.
|
||||
if let Some(body) = &body {
|
||||
if is_allowed(cx, PTR_ARG, body.params[idx].hir_id) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if let ty::Ref(_, ty, Mutability::Not) = ty.kind {
|
||||
if is_type_diagnostic_item(cx, ty, sym!(vec_type)) {
|
||||
let mut ty_snippet = None;
|
||||
|
@ -530,7 +530,7 @@ fn suggest_item_with_attr<D: Display + ?Sized>(
|
||||
|
||||
/// Suggest to add an item before another.
|
||||
///
|
||||
/// The item should not be indented (expect for inner indentation).
|
||||
/// The item should not be indented (except for inner indentation).
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
|
@ -71,7 +71,6 @@ fn false_positive_capacity_too(x: &String) -> String {
|
||||
#[allow(dead_code)]
|
||||
fn test_cow_with_ref(c: &Cow<[i32]>) {}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn test_cow(c: Cow<[i32]>) {
|
||||
let _c = c;
|
||||
}
|
||||
@ -84,3 +83,34 @@ trait Foo2 {
|
||||
impl Foo2 for String {
|
||||
fn do_string(&self) {}
|
||||
}
|
||||
|
||||
// Check that the allow attribute on parameters is honored
|
||||
mod issue_5644 {
|
||||
use std::borrow::Cow;
|
||||
|
||||
fn allowed(
|
||||
#[allow(clippy::ptr_arg)] _v: &Vec<u32>,
|
||||
#[allow(clippy::ptr_arg)] _s: &String,
|
||||
#[allow(clippy::ptr_arg)] _c: &Cow<[i32]>,
|
||||
) {
|
||||
}
|
||||
|
||||
struct S {}
|
||||
impl S {
|
||||
fn allowed(
|
||||
#[allow(clippy::ptr_arg)] _v: &Vec<u32>,
|
||||
#[allow(clippy::ptr_arg)] _s: &String,
|
||||
#[allow(clippy::ptr_arg)] _c: &Cow<[i32]>,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
trait T {
|
||||
fn allowed(
|
||||
#[allow(clippy::ptr_arg)] _v: &Vec<u32>,
|
||||
#[allow(clippy::ptr_arg)] _s: &String,
|
||||
#[allow(clippy::ptr_arg)] _c: &Cow<[i32]>,
|
||||
) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user