diff options
| author | bors <bors@rust-lang.org> | 2023-09-15 09:34:13 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-09-15 09:34:13 +0000 |
| commit | 2c629cc137de1196a0a144e4f2cb778b1f64538b (patch) | |
| tree | f7c7d7b4a54bad20b0448e6bbb0e7889655e954b | |
| parent | 6734e96ba4f0872e1245665d8c7c85e56c61fd1f (diff) | |
| parent | a2a31a0a2fd356f681c78498719dea8aa2523190 (diff) | |
| download | rust-2c629cc137de1196a0a144e4f2cb778b1f64538b.tar.gz rust-2c629cc137de1196a0a144e4f2cb778b1f64538b.zip | |
Auto merge of #11504 - Alexendoo:type-lints-closures, r=xFrednet
Ignore closures for some type lints Fixes #11417 `hir_ty_to_ty` is used in a couple of the `!is_local` lints, which doesn't play nicely inside bodies changelog: none
| -rw-r--r-- | clippy_lints/src/types/mod.rs | 11 | ||||
| -rw-r--r-- | tests/ui/redundant_allocation.rs | 5 | ||||
| -rw-r--r-- | tests/ui/vec_box_sized.fixed | 5 | ||||
| -rw-r--r-- | tests/ui/vec_box_sized.rs | 5 |
4 files changed, 21 insertions, 5 deletions
diff --git a/clippy_lints/src/types/mod.rs b/clippy_lints/src/types/mod.rs index 79f9d45d597..71a4b3fba1b 100644 --- a/clippy_lints/src/types/mod.rs +++ b/clippy_lints/src/types/mod.rs @@ -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, @@ -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() }, ); @@ -427,7 +428,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { cx, ty, CheckTyContext { - is_local: true, + in_body: true, ..CheckTyContext::default() }, ); @@ -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() { @@ -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, diff --git a/tests/ui/redundant_allocation.rs b/tests/ui/redundant_allocation.rs index b3257c04f82..e70f8e71fae 100644 --- a/tests/ui/redundant_allocation.rs +++ b/tests/ui/redundant_allocation.rs @@ -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() {} diff --git a/tests/ui/vec_box_sized.fixed b/tests/ui/vec_box_sized.fixed index 4a5ef83856a..4363d2224af 100644 --- a/tests/ui/vec_box_sized.fixed +++ b/tests/ui/vec_box_sized.fixed @@ -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() {} diff --git a/tests/ui/vec_box_sized.rs b/tests/ui/vec_box_sized.rs index ea020405a30..f4e27fe4bd5 100644 --- a/tests/ui/vec_box_sized.rs +++ b/tests/ui/vec_box_sized.rs @@ -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() {} |
