Auto merge of #10894 - Centri3:type_repetition_in_bounds, r=blyxyas,xFrednet
[`type_repetition_in_bounds`]: Don't lint on derived code fixes #10504. changelog: [`type_repetition_in_bounds`]: Don't lint on derived code
This commit is contained in:
commit
903fe3b9f2
@ -1,6 +1,6 @@
|
||||
use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_sugg};
|
||||
use clippy_utils::source::{snippet, snippet_opt, snippet_with_applicability};
|
||||
use clippy_utils::{SpanlessEq, SpanlessHash};
|
||||
use clippy_utils::{is_from_proc_macro, SpanlessEq, SpanlessHash};
|
||||
use core::hash::{Hash, Hasher};
|
||||
use if_chain::if_chain;
|
||||
use itertools::Itertools;
|
||||
@ -260,7 +260,7 @@ impl Eq for SpanlessTy<'_, '_> {}
|
||||
SpanlessTy { ty: p.bounded_ty, cx },
|
||||
p.bounds.iter().collect::<Vec<_>>()
|
||||
);
|
||||
|
||||
if !is_from_proc_macro(cx, p.bounded_ty);
|
||||
then {
|
||||
let trait_bounds = v
|
||||
.iter()
|
||||
@ -342,7 +342,7 @@ fn check_trait_bound_duplication(cx: &LateContext<'_>, gen: &'_ Generics<'_>) {
|
||||
"this trait bound is already specified in the where clause",
|
||||
None,
|
||||
"consider removing this trait bound",
|
||||
);
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,8 +19,8 @@
|
||||
};
|
||||
use rustc_hir::{
|
||||
intravisit::FnKind, Block, BlockCheckMode, Body, Closure, Destination, Expr, ExprKind, FieldDef, FnHeader, HirId,
|
||||
Impl, ImplItem, ImplItemKind, IsAuto, Item, ItemKind, LoopSource, MatchSource, Node, QPath, TraitItem,
|
||||
TraitItemKind, UnOp, UnsafeSource, Unsafety, Variant, VariantData, YieldSource,
|
||||
Impl, ImplItem, ImplItemKind, IsAuto, Item, ItemKind, LoopSource, MatchSource, MutTy, Node, QPath, TraitItem,
|
||||
TraitItemKind, Ty, TyKind, UnOp, UnsafeSource, Unsafety, Variant, VariantData, YieldSource,
|
||||
};
|
||||
use rustc_lint::{LateContext, LintContext};
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
@ -319,6 +319,31 @@ fn attr_search_pat(attr: &Attribute) -> (Pat, Pat) {
|
||||
}
|
||||
}
|
||||
|
||||
fn ty_search_pat(ty: &Ty<'_>) -> (Pat, Pat) {
|
||||
match ty.kind {
|
||||
TyKind::Slice(..) | TyKind::Array(..) => (Pat::Str("["), Pat::Str("]")),
|
||||
TyKind::Ptr(MutTy { mutbl, ty }) => (
|
||||
if mutbl.is_mut() {
|
||||
Pat::Str("*const")
|
||||
} else {
|
||||
Pat::Str("*mut")
|
||||
},
|
||||
ty_search_pat(ty).1,
|
||||
),
|
||||
TyKind::Ref(_, MutTy { ty, .. }) => (Pat::Str("&"), ty_search_pat(ty).1),
|
||||
TyKind::BareFn(bare_fn) => (
|
||||
Pat::OwnedStr(format!("{}{} fn", bare_fn.unsafety.prefix_str(), bare_fn.abi.name())),
|
||||
ty_search_pat(ty).1,
|
||||
),
|
||||
TyKind::Never => (Pat::Str("!"), Pat::Str("")),
|
||||
TyKind::Tup(..) => (Pat::Str("("), Pat::Str(")")),
|
||||
TyKind::OpaqueDef(..) => (Pat::Str("impl"), Pat::Str("")),
|
||||
TyKind::Path(qpath) => qpath_search_pat(&qpath),
|
||||
// NOTE: This is missing `TraitObject`. It always return true then.
|
||||
_ => (Pat::Str(""), Pat::Str("")),
|
||||
}
|
||||
}
|
||||
|
||||
pub trait WithSearchPat {
|
||||
type Context: LintContext;
|
||||
fn search_pat(&self, cx: &Self::Context) -> (Pat, Pat);
|
||||
@ -345,6 +370,7 @@ fn span(&self) -> Span {
|
||||
impl_with_search_pat!(LateContext: ImplItem with impl_item_search_pat);
|
||||
impl_with_search_pat!(LateContext: FieldDef with field_def_search_pat);
|
||||
impl_with_search_pat!(LateContext: Variant with variant_search_pat);
|
||||
impl_with_search_pat!(LateContext: Ty with ty_search_pat);
|
||||
|
||||
impl<'cx> WithSearchPat for (&FnKind<'cx>, &Body<'cx>, HirId, Span) {
|
||||
type Context = LateContext<'cx>;
|
||||
|
@ -1,6 +1,7 @@
|
||||
#![deny(clippy::type_repetition_in_bounds)]
|
||||
#![allow(clippy::extra_unused_type_parameters)]
|
||||
|
||||
use serde::Deserialize;
|
||||
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
|
||||
|
||||
pub fn foo<T>(_t: T)
|
||||
@ -70,6 +71,20 @@ struct Bar<S>
|
||||
}
|
||||
}
|
||||
|
||||
// Extern macros shouldn't lint, again (see #10504)
|
||||
mod issue10504 {
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt::Debug;
|
||||
use std::hash::Hash;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[serde(bound(
|
||||
serialize = "T: Serialize + Hash + Eq",
|
||||
deserialize = "Box<T>: serde::de::DeserializeOwned + Hash + Eq"
|
||||
))]
|
||||
struct OpaqueParams<T: ?Sized + Debug>(std::marker::PhantomData<T>);
|
||||
}
|
||||
|
||||
// Issue #7360
|
||||
struct Foo<T, U>
|
||||
where
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: this type has already been used as a bound predicate
|
||||
--> $DIR/type_repetition_in_bounds.rs:9:5
|
||||
--> $DIR/type_repetition_in_bounds.rs:10:5
|
||||
|
|
||||
LL | T: Clone,
|
||||
| ^^^^^^^^
|
||||
@ -12,7 +12,7 @@ LL | #![deny(clippy::type_repetition_in_bounds)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this type has already been used as a bound predicate
|
||||
--> $DIR/type_repetition_in_bounds.rs:26:5
|
||||
--> $DIR/type_repetition_in_bounds.rs:27:5
|
||||
|
|
||||
LL | Self: Copy + Default + Ord,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -20,7 +20,7 @@ LL | Self: Copy + Default + Ord,
|
||||
= help: consider combining the bounds: `Self: Clone + Copy + Default + Ord`
|
||||
|
||||
error: this type has already been used as a bound predicate
|
||||
--> $DIR/type_repetition_in_bounds.rs:86:5
|
||||
--> $DIR/type_repetition_in_bounds.rs:101:5
|
||||
|
|
||||
LL | T: Clone,
|
||||
| ^^^^^^^^
|
||||
@ -28,7 +28,7 @@ LL | T: Clone,
|
||||
= help: consider combining the bounds: `T: ?Sized + Clone`
|
||||
|
||||
error: this type has already been used as a bound predicate
|
||||
--> $DIR/type_repetition_in_bounds.rs:91:5
|
||||
--> $DIR/type_repetition_in_bounds.rs:106:5
|
||||
|
|
||||
LL | T: ?Sized,
|
||||
| ^^^^^^^^^
|
||||
|
Loading…
Reference in New Issue
Block a user