Ignore closures for some type lints
This commit is contained in:
parent
b27fc10aa8
commit
a2a31a0a2f
@ -315,7 +315,7 @@ impl<'tcx> LateLintPass<'tcx> for Types {
|
|||||||
fn check_fn(
|
fn check_fn(
|
||||||
&mut self,
|
&mut self,
|
||||||
cx: &LateContext<'_>,
|
cx: &LateContext<'_>,
|
||||||
_: FnKind<'_>,
|
fn_kind: FnKind<'_>,
|
||||||
decl: &FnDecl<'_>,
|
decl: &FnDecl<'_>,
|
||||||
_: &Body<'_>,
|
_: &Body<'_>,
|
||||||
_: Span,
|
_: Span,
|
||||||
@ -340,6 +340,7 @@ fn check_fn(
|
|||||||
CheckTyContext {
|
CheckTyContext {
|
||||||
is_in_trait_impl,
|
is_in_trait_impl,
|
||||||
is_exported,
|
is_exported,
|
||||||
|
in_body: matches!(fn_kind, FnKind::Closure),
|
||||||
..CheckTyContext::default()
|
..CheckTyContext::default()
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -427,7 +428,7 @@ fn check_local(&mut self, cx: &LateContext<'_>, local: &Local<'_>) {
|
|||||||
cx,
|
cx,
|
||||||
ty,
|
ty,
|
||||||
CheckTyContext {
|
CheckTyContext {
|
||||||
is_local: true,
|
in_body: true,
|
||||||
..CheckTyContext::default()
|
..CheckTyContext::default()
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -481,7 +482,7 @@ fn check_ty(&mut self, cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, mut context:
|
|||||||
}
|
}
|
||||||
|
|
||||||
match hir_ty.kind {
|
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 hir_id = hir_ty.hir_id;
|
||||||
let res = cx.qpath_res(qpath, hir_id);
|
let res = cx.qpath_res(qpath, hir_id);
|
||||||
if let Some(def_id) = res.opt_def_id() {
|
if let Some(def_id) = res.opt_def_id() {
|
||||||
@ -581,8 +582,8 @@ fn is_type_change_allowed(&self, context: CheckTyContext) -> bool {
|
|||||||
#[derive(Clone, Copy, Default)]
|
#[derive(Clone, Copy, Default)]
|
||||||
struct CheckTyContext {
|
struct CheckTyContext {
|
||||||
is_in_trait_impl: bool,
|
is_in_trait_impl: bool,
|
||||||
/// `true` for types on local variables.
|
/// `true` for types on local variables and in closure signatures.
|
||||||
is_local: bool,
|
in_body: bool,
|
||||||
/// `true` for types that are part of the public API.
|
/// `true` for types that are part of the public API.
|
||||||
is_exported: bool,
|
is_exported: bool,
|
||||||
is_nested_call: bool,
|
is_nested_call: bool,
|
||||||
|
@ -159,4 +159,9 @@ pub fn test_rc_box_custom(_: Rc<Box<Box<DynSized>>>) {}
|
|||||||
//~| NOTE: `Box<Box<DynSized>>` is already on the heap, `Rc<Box<Box<DynSized>>>` makes
|
//~| 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() {}
|
fn main() {}
|
||||||
|
@ -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() {}
|
fn main() {}
|
||||||
|
@ -49,4 +49,9 @@ pub fn f() -> Vec<Box<S>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/rust-lang/rust-clippy/issues/11417
|
||||||
|
fn in_closure() {
|
||||||
|
let _ = |_: Vec<Box<dyn ToString>>| {};
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
Loading…
Reference in New Issue
Block a user