@@ -10,46 +10,45 @@ use rustc_span::symbol::Ident;
10
10
use crate :: { LateContext , LateLintPass , LintContext } ;
11
11
12
12
declare_lint ! {
13
- /// The `redundant_sizedness_bound ` lint detects redundant sizedness bounds applied to type parameters that are already
13
+ /// The `redundant_sizedness_bounds ` lint detects redundant sizedness bounds applied to type parameters that are already
14
14
/// otherwise implied.
15
15
///
16
16
/// ### Example
17
17
///
18
18
/// ```rust
19
- /// #![feature(sized_hierarchy)]
20
- /// use std::marker::MetaSized;
21
19
/// // `T` must be `Sized` due to the bound `Clone`, thus `?Sized` is redundant.
22
20
/// fn f<T: Clone + ?Sized>(t: &T) {}
23
- /// // `T` is `Sized` due to `Clone ` bound, thereby implying `MetaSized` and making the explicit `MetaSized ` bound redundant.
24
- /// fn g<T: MetaSized + Clone >(t: &T) {}
21
+ /// // `T` is `Sized` due to `Default ` bound, thus the explicit `Sized ` bound is redundant.
22
+ /// fn g<T: Default + Sized >(t: &T) {}
25
23
/// ```
26
24
///
27
25
/// {{produces}}
28
26
///
29
27
/// ### Explanation
30
28
///
31
- /// Sizedness bounds that have no effect as another bound implies a greater degree of sizedness are potentially misleading
32
- /// This lint notifies the user of such redundant bounds.
33
- pub REDUNDANT_SIZEDNESS_BOUND ,
29
+ /// Sizedness bounds that have no effect as another bound implies `Sized` can be misleading or
30
+ /// at the very least redundant.
31
+ /// This lint notifies the user of said redundant bounds.
32
+ pub REDUNDANT_SIZEDNESS_BOUNDS ,
34
33
Warn ,
35
34
"a sizedness bound that is redundant due to another bound"
36
35
}
37
- declare_lint_pass ! ( RedundantSizednessBound => [ REDUNDANT_SIZEDNESS_BOUND ] ) ;
36
+ declare_lint_pass ! ( RedundantSizednessBounds => [ REDUNDANT_SIZEDNESS_BOUNDS ] ) ;
38
37
39
38
struct Bound < ' tcx > {
40
- /// The [`DefId`] of the type parameter the bound refers to
39
+ /// The [`DefId`] of the type parameter the bound refers to.
41
40
param : DefId ,
42
- /// Identifier of type parameter
41
+ /// Identifier of type parameter.
43
42
ident : Ident ,
44
- /// A reference to the trait bound applied to the parameter
43
+ /// A reference to the trait bound applied to the parameter.
45
44
trait_bound : & ' tcx PolyTraitRef < ' tcx > ,
46
- /// The index of the predicate within the generics predicate list
45
+ /// The index of the predicate within the generics predicate list.
47
46
predicate_pos : usize ,
48
- /// Position of the bound in the bounds list of a predicate
47
+ /// Position of the bound in the bounds list of a predicate.
49
48
bound_pos : usize ,
50
49
}
51
50
52
- /// Finds all of the [`Bound`]s that refer to a type parameter and are not from a macro expansion
51
+ /// Finds all of the [`Bound`]s that refer to a type parameter and are not from a macro expansion.
53
52
fn type_param_bounds < ' tcx > ( generics : & ' tcx Generics < ' tcx > ) -> impl Iterator < Item = Bound < ' tcx > > {
54
53
generics
55
54
. predicates
@@ -80,7 +79,7 @@ fn type_param_bounds<'tcx>(generics: &'tcx Generics<'tcx>) -> impl Iterator<Item
80
79
}
81
80
82
81
/// Searches the supertraits of the trait referred to by `trait_bound` recursively, returning the
83
- /// path taken to find the `target` bound if one is found
82
+ /// path taken to find the `target` bound if one is found.
84
83
fn path_to_bound (
85
84
cx : & LateContext < ' _ > ,
86
85
trait_bound : & PolyTraitRef < ' _ > ,
@@ -115,8 +114,8 @@ fn path_to_bound(
115
114
search ( cx, & mut path, target) . then_some ( path)
116
115
}
117
116
118
- // Checks if there exists a bound `redundant_bound` that is already implied by `implicit_bound`
119
- fn check_redundant_sizedness_bound (
117
+ // Checks if there exists a bound `redundant_bound` that is already implied by `implicit_bound`.
118
+ fn check_redundant_sizedness_bounds (
120
119
redundant_bound : DefId ,
121
120
redundant_bound_polarity : BoundPolarity ,
122
121
implicit_bound : DefId ,
@@ -142,7 +141,7 @@ fn check_redundant_sizedness_bound(
142
141
_ => "" ,
143
142
} ;
144
143
cx. span_lint (
145
- REDUNDANT_SIZEDNESS_BOUND ,
144
+ REDUNDANT_SIZEDNESS_BOUNDS ,
146
145
redundant_sized_bound. trait_bound . span ,
147
146
|diag| {
148
147
let redundant_bound_str = cx. tcx . def_path_str ( redundant_bound) ;
@@ -188,7 +187,7 @@ fn check_redundant_sizedness_bound(
188
187
false
189
188
}
190
189
191
- impl LateLintPass < ' _ > for RedundantSizednessBound {
190
+ impl LateLintPass < ' _ > for RedundantSizednessBounds {
192
191
fn check_generics ( & mut self , cx : & LateContext < ' _ > , generics : & Generics < ' _ > ) {
193
192
let Some ( sized_trait) = cx. tcx . lang_items ( ) . sized_trait ( ) else {
194
193
return ;
@@ -200,7 +199,7 @@ impl LateLintPass<'_> for RedundantSizednessBound {
200
199
return ;
201
200
} ;
202
201
203
- if check_redundant_sizedness_bound (
202
+ if check_redundant_sizedness_bounds (
204
203
sized_trait,
205
204
BoundPolarity :: Maybe ( Default :: default ( ) ) ,
206
205
sized_trait,
@@ -209,7 +208,7 @@ impl LateLintPass<'_> for RedundantSizednessBound {
209
208
) {
210
209
return ;
211
210
}
212
- if check_redundant_sizedness_bound (
211
+ if check_redundant_sizedness_bounds (
213
212
meta_sized_trait,
214
213
BoundPolarity :: Positive ,
215
214
sized_trait,
@@ -218,7 +217,7 @@ impl LateLintPass<'_> for RedundantSizednessBound {
218
217
) {
219
218
return ;
220
219
}
221
- if check_redundant_sizedness_bound (
220
+ if check_redundant_sizedness_bounds (
222
221
pointee_sized_trait,
223
222
BoundPolarity :: Positive ,
224
223
sized_trait,
@@ -227,7 +226,7 @@ impl LateLintPass<'_> for RedundantSizednessBound {
227
226
) {
228
227
return ;
229
228
}
230
- if check_redundant_sizedness_bound (
229
+ if check_redundant_sizedness_bounds (
231
230
pointee_sized_trait,
232
231
BoundPolarity :: Positive ,
233
232
meta_sized_trait,
0 commit comments