Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore closures for some type lints #11504

Merged
merged 1 commit into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions clippy_lints/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ impl<'tcx> LateLintPass<'tcx> for Types {
fn check_fn(
&mut self,
cx: &LateContext<'_>,
_: FnKind<'_>,
fn_kind: FnKind<'_>,
decl: &FnDecl<'_>,
_: &Body<'_>,
_: Span,
Expand All @@ -340,6 +340,7 @@ impl<'tcx> LateLintPass<'tcx> for Types {
CheckTyContext {
is_in_trait_impl,
is_exported,
in_body: matches!(fn_kind, FnKind::Closure),
..CheckTyContext::default()
},
);
Expand Down Expand Up @@ -427,7 +428,7 @@ impl<'tcx> LateLintPass<'tcx> for Types {
cx,
ty,
CheckTyContext {
is_local: true,
in_body: true,
..CheckTyContext::default()
},
);
Expand Down Expand Up @@ -481,7 +482,7 @@ impl Types {
}

match hir_ty.kind {
TyKind::Path(ref qpath) if !context.is_local => {
TyKind::Path(ref qpath) if !context.in_body => {
let hir_id = hir_ty.hir_id;
let res = cx.qpath_res(qpath, hir_id);
if let Some(def_id) = res.opt_def_id() {
Expand Down Expand Up @@ -581,8 +582,8 @@ impl Types {
#[derive(Clone, Copy, Default)]
struct CheckTyContext {
is_in_trait_impl: bool,
/// `true` for types on local variables.
is_local: bool,
/// `true` for types on local variables and in closure signatures.
in_body: bool,
/// `true` for types that are part of the public API.
is_exported: bool,
is_nested_call: bool,
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/redundant_allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,9 @@ mod box_fat_ptr {
//~| NOTE: `Box<Box<DynSized>>` is already on the heap, `Rc<Box<Box<DynSized>>>` makes
}

// https://github.com/rust-lang/rust-clippy/issues/11417
fn type_in_closure() {
let _ = |_: &mut Box<Box<dyn ToString>>| {};
}

fn main() {}
5 changes: 5 additions & 0 deletions tests/ui/vec_box_sized.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,9 @@ mod inner_mod {
}
}

// https://github.com/rust-lang/rust-clippy/issues/11417
fn in_closure() {
let _ = |_: Vec<Box<dyn ToString>>| {};
}

fn main() {}
5 changes: 5 additions & 0 deletions tests/ui/vec_box_sized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,9 @@ mod inner_mod {
}
}

// https://github.com/rust-lang/rust-clippy/issues/11417
fn in_closure() {
let _ = |_: Vec<Box<dyn ToString>>| {};
}

fn main() {}