mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-24 05:33:27 +00:00
Do not lint use_self on type parameters
This commit is contained in:
parent
d3c20c835f
commit
29b4b4c10d
4 changed files with 50 additions and 4 deletions
|
@ -386,7 +386,7 @@ fn should_lint_ty(hir_ty: &hir::Ty<'_>, ty: Ty<'_>, self_ty: Ty<'_>) -> bool {
|
||||||
if same_type_and_consts(ty, self_ty);
|
if same_type_and_consts(ty, self_ty);
|
||||||
if let TyKind::Path(QPath::Resolved(_, path)) = hir_ty.kind;
|
if let TyKind::Path(QPath::Resolved(_, path)) = hir_ty.kind;
|
||||||
then {
|
then {
|
||||||
!matches!(path.res, def::Res::SelfTy(..))
|
!matches!(path.res, Res::SelfTy(..) | Res::Def(DefKind::TyParam, _))
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
|
@ -492,3 +492,26 @@ mod issue7206 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mod self_is_ty_param {
|
||||||
|
trait Trait {
|
||||||
|
type Type;
|
||||||
|
type Hi;
|
||||||
|
|
||||||
|
fn test();
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<I> Trait for I
|
||||||
|
where
|
||||||
|
I: Iterator,
|
||||||
|
I::Item: Trait, // changing this to Self would require <Self as Iterator>
|
||||||
|
{
|
||||||
|
type Type = I;
|
||||||
|
type Hi = I::Item;
|
||||||
|
|
||||||
|
fn test() {
|
||||||
|
let _: I::Item;
|
||||||
|
let _: I; // this could lint, but is questionable
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -279,7 +279,7 @@ mod generics {
|
||||||
impl<T> Foo<T> {
|
impl<T> Foo<T> {
|
||||||
// `Self` is applicable here
|
// `Self` is applicable here
|
||||||
fn foo(value: T) -> Foo<T> {
|
fn foo(value: T) -> Foo<T> {
|
||||||
Foo { value }
|
Foo::<T> { value }
|
||||||
}
|
}
|
||||||
|
|
||||||
// `Cannot` use `Self` as a return type as the generic types are different
|
// `Cannot` use `Self` as a return type as the generic types are different
|
||||||
|
@ -492,3 +492,26 @@ mod issue7206 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mod self_is_ty_param {
|
||||||
|
trait Trait {
|
||||||
|
type Type;
|
||||||
|
type Hi;
|
||||||
|
|
||||||
|
fn test();
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<I> Trait for I
|
||||||
|
where
|
||||||
|
I: Iterator,
|
||||||
|
I::Item: Trait, // changing this to Self would require <Self as Iterator>
|
||||||
|
{
|
||||||
|
type Type = I;
|
||||||
|
type Hi = I::Item;
|
||||||
|
|
||||||
|
fn test() {
|
||||||
|
let _: I::Item;
|
||||||
|
let _: I; // this could lint, but is questionable
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -153,8 +153,8 @@ LL | fn foo(value: T) -> Foo<T> {
|
||||||
error: unnecessary structure name repetition
|
error: unnecessary structure name repetition
|
||||||
--> $DIR/use_self.rs:282:13
|
--> $DIR/use_self.rs:282:13
|
||||||
|
|
|
|
||||||
LL | Foo { value }
|
LL | Foo::<T> { value }
|
||||||
| ^^^ help: use the applicable keyword: `Self`
|
| ^^^^^^^^ help: use the applicable keyword: `Self`
|
||||||
|
|
||||||
error: unnecessary structure name repetition
|
error: unnecessary structure name repetition
|
||||||
--> $DIR/use_self.rs:454:13
|
--> $DIR/use_self.rs:454:13
|
||||||
|
|
Loading…
Reference in a new issue