@@ -10,46 +10,45 @@ use rustc_span::symbol::Ident;
1010use crate :: { LateContext , LateLintPass , LintContext } ;
1111
1212declare_lint ! {
13- /// The `redundant_sizedness_bound ` lint detects redundant sizedness bounds applied to type parameters that are already
14- /// otherwise implied.
13+ /// The `redundant_sizedness_bounds ` lint detects redundant sizedness bounds
14+ /// applied to type parameters that are already otherwise implied.
1515 ///
1616 /// ### Example
1717 ///
1818 /// ```rust
19- /// #![feature(sized_hierarchy)]
20- /// use std::marker::MetaSized;
2119 /// // `T` must be `Sized` due to the bound `Clone`, thus `?Sized` is redundant.
2220 /// 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) {}
2523 /// ```
2624 ///
2725 /// {{produces}}
2826 ///
2927 /// ### Explanation
3028 ///
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`,
30+ /// are redundant and can be misleading. This lint notifies the user of
31+ /// these redundant bounds.
32+ pub REDUNDANT_SIZEDNESS_BOUNDS ,
3433 Warn ,
3534 "a sizedness bound that is redundant due to another bound"
3635}
37- declare_lint_pass ! ( RedundantSizednessBound => [ REDUNDANT_SIZEDNESS_BOUND ] ) ;
36+ declare_lint_pass ! ( RedundantSizednessBounds => [ REDUNDANT_SIZEDNESS_BOUNDS ] ) ;
3837
3938struct Bound < ' tcx > {
40- /// The [`DefId`] of the type parameter the bound refers to
39+ /// The [`DefId`] of the type parameter the bound refers to.
4140 param : DefId ,
42- /// Identifier of type parameter
41+ /// Identifier of type parameter.
4342 ident : Ident ,
44- /// A reference to the trait bound applied to the parameter
43+ /// A reference to the trait bound applied to the parameter.
4544 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.
4746 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.
4948 bound_pos : usize ,
5049}
5150
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.
5352fn type_param_bounds < ' tcx > ( generics : & ' tcx Generics < ' tcx > ) -> impl Iterator < Item = Bound < ' tcx > > {
5453 generics
5554 . predicates
@@ -80,7 +79,7 @@ fn type_param_bounds<'tcx>(generics: &'tcx Generics<'tcx>) -> impl Iterator<Item
8079}
8180
8281/// 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.
8483fn path_to_bound (
8584 cx : & LateContext < ' _ > ,
8685 trait_bound : & PolyTraitRef < ' _ > ,
@@ -115,8 +114,8 @@ fn path_to_bound(
115114 search ( cx, & mut path, target) . then_some ( path)
116115}
117116
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 (
120119 redundant_bound : DefId ,
121120 redundant_bound_polarity : BoundPolarity ,
122121 implicit_bound : DefId ,
@@ -142,7 +141,7 @@ fn check_redundant_sizedness_bound(
142141 _ => "" ,
143142 } ;
144143 cx. span_lint (
145- REDUNDANT_SIZEDNESS_BOUND ,
144+ REDUNDANT_SIZEDNESS_BOUNDS ,
146145 redundant_sized_bound. trait_bound . span ,
147146 |diag| {
148147 let redundant_bound_str = cx. tcx . def_path_str ( redundant_bound) ;
@@ -188,7 +187,7 @@ fn check_redundant_sizedness_bound(
188187 false
189188}
190189
191- impl LateLintPass < ' _ > for RedundantSizednessBound {
190+ impl LateLintPass < ' _ > for RedundantSizednessBounds {
192191 fn check_generics ( & mut self , cx : & LateContext < ' _ > , generics : & Generics < ' _ > ) {
193192 let Some ( sized_trait) = cx. tcx . lang_items ( ) . sized_trait ( ) else {
194193 return ;
@@ -200,7 +199,7 @@ impl LateLintPass<'_> for RedundantSizednessBound {
200199 return ;
201200 } ;
202201
203- if check_redundant_sizedness_bound (
202+ if check_redundant_sizedness_bounds (
204203 sized_trait,
205204 BoundPolarity :: Maybe ( Default :: default ( ) ) ,
206205 sized_trait,
@@ -209,7 +208,7 @@ impl LateLintPass<'_> for RedundantSizednessBound {
209208 ) {
210209 return ;
211210 }
212- if check_redundant_sizedness_bound (
211+ if check_redundant_sizedness_bounds (
213212 meta_sized_trait,
214213 BoundPolarity :: Positive ,
215214 sized_trait,
@@ -218,7 +217,7 @@ impl LateLintPass<'_> for RedundantSizednessBound {
218217 ) {
219218 return ;
220219 }
221- if check_redundant_sizedness_bound (
220+ if check_redundant_sizedness_bounds (
222221 pointee_sized_trait,
223222 BoundPolarity :: Positive ,
224223 sized_trait,
@@ -227,7 +226,7 @@ impl LateLintPass<'_> for RedundantSizednessBound {
227226 ) {
228227 return ;
229228 }
230- if check_redundant_sizedness_bound (
229+ if check_redundant_sizedness_bounds (
231230 pointee_sized_trait,
232231 BoundPolarity :: Positive ,
233232 meta_sized_trait,
0 commit comments