Skip to content

Commit 66f91da

Browse files
committed
Applies changes suggested by reviewers
1 parent d846194 commit 66f91da

File tree

11 files changed

+132
-133
lines changed

11 files changed

+132
-133
lines changed

compiler/rustc_lint/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ mod passes;
7171
mod precedence;
7272
mod ptr_nulls;
7373
mod redundant_semicolon;
74-
mod redundant_sizedness_bound;
74+
mod redundant_sizedness_bounds;
7575
mod reference_casting;
7676
mod shadowed_into_iter;
7777
mod static_mut_refs;
@@ -112,7 +112,7 @@ use pass_by_value::*;
112112
use precedence::*;
113113
use ptr_nulls::*;
114114
use redundant_semicolon::*;
115-
use redundant_sizedness_bound::RedundantSizednessBound;
115+
use redundant_sizedness_bounds::RedundantSizednessBounds;
116116
use reference_casting::*;
117117
use rustc_hir::def_id::LocalModDefId;
118118
use rustc_middle::query::Providers;
@@ -248,7 +248,7 @@ late_lint_methods!(
248248
UnqualifiedLocalImports: UnqualifiedLocalImports,
249249
CheckTransmutes: CheckTransmutes,
250250
LifetimeSyntax: LifetimeSyntax,
251-
RedundantSizednessBound: RedundantSizednessBound,
251+
RedundantSizednessBounds: RedundantSizednessBounds,
252252
]
253253
]
254254
);

compiler/rustc_lint/src/redundant_sizedness_bound.rs renamed to compiler/rustc_lint/src/redundant_sizedness_bounds.rs

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,46 +10,45 @@ use rustc_span::symbol::Ident;
1010
use crate::{LateContext, LateLintPass, LintContext};
1111

1212
declare_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

3938
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.
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.
5352
fn 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.
8483
fn 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,

src/tools/clippy/clippy_lints/src/deprecated_lints.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ declare_with_version! { RENAMED(RENAMED_VERSION) = [
139139
#[clippy::version = "1.80.0"]
140140
("clippy::mismatched_target_os", "unexpected_cfgs"),
141141
#[clippy::version = "1.91.0"]
142-
("clippy::needless_maybe_sized", "redundant_sizedness_bound"),
142+
("clippy::needless_maybe_sized", "redundant_sizedness_bounds"),
143143
#[clippy::version = ""]
144144
("clippy::new_without_default_derive", "clippy::new_without_default"),
145145
#[clippy::version = ""]

src/tools/clippy/tests/ui-toml/type_repetition_in_bounds/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![allow(redundant_sizedness_bound)]
1+
#![allow(redundant_sizedness_bounds)]
22
#![warn(clippy::type_repetition_in_bounds)]
33

44
fn f<T>()

src/tools/clippy/tests/ui/rename.fixed

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
#![allow(clippy::overly_complex_bool_expr)]
4343
#![allow(unexpected_cfgs)]
4444
#![allow(enum_intrinsics_non_enums)]
45-
#![allow(redundant_sizedness_bound)]
45+
#![allow(redundant_sizedness_bounds)]
4646
#![allow(clippy::new_without_default)]
4747
#![allow(clippy::bind_instead_of_map)]
4848
#![allow(clippy::expect_used)]
@@ -110,7 +110,7 @@
110110
#![warn(unexpected_cfgs)] //~ ERROR: lint `clippy::maybe_misused_cfg`
111111
#![warn(enum_intrinsics_non_enums)] //~ ERROR: lint `clippy::mem_discriminant_non_enum`
112112
#![warn(unexpected_cfgs)] //~ ERROR: lint `clippy::mismatched_target_os`
113-
#![warn(redundant_sizedness_bound)] //~ ERROR: lint `clippy::needless_maybe_sized`
113+
#![warn(redundant_sizedness_bounds)] //~ ERROR: lint `clippy::needless_maybe_sized`
114114
#![warn(clippy::new_without_default)] //~ ERROR: lint `clippy::new_without_default_derive`
115115
#![warn(clippy::bind_instead_of_map)] //~ ERROR: lint `clippy::option_and_then_some`
116116
#![warn(clippy::expect_used)] //~ ERROR: lint `clippy::option_expect_used`

src/tools/clippy/tests/ui/rename.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
#![allow(clippy::overly_complex_bool_expr)]
4343
#![allow(unexpected_cfgs)]
4444
#![allow(enum_intrinsics_non_enums)]
45-
#![allow(redundant_sizedness_bound)]
45+
#![allow(redundant_sizedness_bounds)]
4646
#![allow(clippy::new_without_default)]
4747
#![allow(clippy::bind_instead_of_map)]
4848
#![allow(clippy::expect_used)]

src/tools/clippy/tests/ui/rename.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,11 @@ error: lint `clippy::mismatched_target_os` has been renamed to `unexpected_cfgs`
265265
LL | #![warn(clippy::mismatched_target_os)]
266266
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unexpected_cfgs`
267267

268-
error: lint `clippy::needless_maybe_sized` has been renamed to `redundant_sizedness_bound`
268+
error: lint `clippy::needless_maybe_sized` has been renamed to `redundant_sizedness_bounds`
269269
--> tests/ui/rename.rs:113:9
270270
|
271271
LL | #![warn(clippy::needless_maybe_sized)]
272-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `redundant_sizedness_bound`
272+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `redundant_sizedness_bounds`
273273

274274
error: lint `clippy::new_without_default_derive` has been renamed to `clippy::new_without_default`
275275
--> tests/ui/rename.rs:114:9

src/tools/clippy/tests/ui/type_repetition_in_bounds.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![allow(
33
clippy::extra_unused_type_parameters,
44
clippy::multiple_bound_locations,
5-
redundant_sizedness_bound
5+
redundant_sizedness_bounds
66
)]
77

88
use serde::Deserialize;

tests/ui/lint/lint-redundant-sizedness-bound.fixed renamed to tests/ui/lint/lint-redundant-sizedness-bounds.fixed

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
//@ run-rustfix
2-
#![deny(redundant_sizedness_bound)]
2+
#![deny(redundant_sizedness_bounds)]
33
#![feature(sized_hierarchy)]
44
#![allow(unused)]
55
use std::marker::{MetaSized, PointeeSized};
66

77
fn directly<T: Sized>(t: &T) {}
8-
//~^ ERROR redundant_sizedness_bound
8+
//~^ ERROR redundant_sizedness_bounds
99

1010
trait A: Sized {}
1111
trait B: A {}
1212

1313
fn depth_1<T: A>(t: &T) {}
14-
//~^ ERROR redundant_sizedness_bound
14+
//~^ ERROR redundant_sizedness_bounds
1515
fn depth_2<T: B>(t: &T) {}
16-
//~^ ERROR redundant_sizedness_bound
16+
//~^ ERROR redundant_sizedness_bounds
1717

1818
// We only need to show one
1919
fn multiple_paths<T: A + B>(t: &T) {}
20-
//~^ ERROR redundant_sizedness_bound
20+
//~^ ERROR redundant_sizedness_bounds
2121

2222
fn in_where<T>(t: &T)
2323
where
2424
T: Sized,
25-
//~^ ERROR redundant_sizedness_bound
25+
//~^ ERROR redundant_sizedness_bounds
2626
{
2727
}
2828

2929
fn mixed_1<T: Sized>(t: &T)
30-
//~^ ERROR redundant_sizedness_bound
30+
//~^ ERROR redundant_sizedness_bounds
3131
{
3232
}
3333

3434
fn mixed_2<T>(t: &T)
35-
//~^ ERROR redundant_sizedness_bound
35+
//~^ ERROR redundant_sizedness_bounds
3636
where
3737
T: Sized,
3838
{
@@ -41,50 +41,50 @@ where
4141
fn mixed_3<T>(t: &T)
4242
where
4343
T: Sized,
44-
//~^ ERROR redundant_sizedness_bound
44+
//~^ ERROR redundant_sizedness_bounds
4545
{
4646
}
4747

4848
struct Struct<T: Sized>(T);
49-
//~^ ERROR redundant_sizedness_bound
49+
//~^ ERROR redundant_sizedness_bounds
5050

5151
impl<T: Sized> Struct<T> {
52-
//~^ ERROR redundant_sizedness_bound
52+
//~^ ERROR redundant_sizedness_bounds
5353
fn method<U: Sized>(&self) {}
54-
//~^ ERROR redundant_sizedness_bound
54+
//~^ ERROR redundant_sizedness_bounds
5555
}
5656

5757
enum Enum<T: Sized + 'static> {
58-
//~^ ERROR redundant_sizedness_bound
58+
//~^ ERROR redundant_sizedness_bounds
5959
Variant(&'static T),
6060
}
6161

6262
union Union<'a, T: Sized> {
63-
//~^ ERROR redundant_sizedness_bound
63+
//~^ ERROR redundant_sizedness_bounds
6464
a: &'a T,
6565
}
6666

6767
trait Trait<T: Sized> {
68-
//~^ ERROR redundant_sizedness_bound
68+
//~^ ERROR redundant_sizedness_bounds
6969
fn trait_method<U: Sized>() {}
70-
//~^ ERROR redundant_sizedness_bound
70+
//~^ ERROR redundant_sizedness_bounds
7171

7272
type GAT<U: Sized>;
73-
//~^ ERROR redundant_sizedness_bound
73+
//~^ ERROR redundant_sizedness_bounds
7474

7575
type Assoc: Sized + ?Sized; // False negative
7676
}
7777

7878
trait SecondInTrait: Send + Sized {}
7979
fn second_in_trait<T: SecondInTrait>() {}
80-
//~^ ERROR redundant_sizedness_bound
80+
//~^ ERROR redundant_sizedness_bounds
8181

8282
fn impl_trait(_: &(impl Sized)) {}
83-
//~^ ERROR redundant_sizedness_bound
83+
//~^ ERROR redundant_sizedness_bounds
8484

8585
trait GenericTrait<T>: Sized {}
8686
fn in_generic_trait<T: GenericTrait<U>, U>() {}
87-
//~^ ERROR redundant_sizedness_bound
87+
//~^ ERROR redundant_sizedness_bounds
8888

8989
mod larger_graph {
9090
// C1 C2 Sized
@@ -100,17 +100,17 @@ mod larger_graph {
100100
trait A1: B1 + B2 {}
101101

102102
fn larger_graph<T: A1>() {}
103-
//~^ ERROR redundant_sizedness_bound
103+
//~^ ERROR redundant_sizedness_bounds
104104
}
105105

106106
trait S1: Sized {}
107107
fn meta_sized<T: S1>() {}
108-
//~^ ERROR redundant_sizedness_bound
108+
//~^ ERROR redundant_sizedness_bounds
109109
fn pointee_sized<T: S1>() {}
110-
//~^ ERROR redundant_sizedness_bound
110+
//~^ ERROR redundant_sizedness_bounds
111111
trait M1: MetaSized {}
112112
fn pointee_metasized<T: M1>() {}
113-
//~^ ERROR redundant_sizedness_bound
113+
//~^ ERROR redundant_sizedness_bounds
114114

115115
// Should not lint
116116

0 commit comments

Comments
 (0)