mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-15 09:27:25 +00:00
Auto merge of #5647 - ebroto:5644_allow_ptr_arg_in_arg_position, r=flip1995
ptr_arg: honor `allow` attribute on arguments The `intravisit::Visitor` impl for `LateContextAndPass` only takes into account the attributes of a function parameter inside the `check_param` method. `ptr_arg` starts its heuristics at `check_item` / `check_impl_item` / `check_trait_item`, so the `allow` is not taken into account automatically. changelog: ptr_arg: honor `allow` attribute on arguments Fixes #5644
This commit is contained in:
commit
2a6cfa7f05
3 changed files with 41 additions and 3 deletions
|
@ -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 @@ pub trait DiagnosticBuilderExt<'a, T: LintContext> {
|
|||
|
||||
/// 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 a new issue