Skip to content

Commit 24f42c6

Browse files
committed
Extends tests
- Extends the test to include tests covering the lint's soon to be extended functionality. - Adds `//@ run-rustfix` to test and creates corresponding .fixed file.
1 parent f13041f commit 24f42c6

File tree

3 files changed

+292
-82
lines changed

3 files changed

+292
-82
lines changed
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
//@ run-rustfix
2+
#![deny(redundant_sizedness_bound)]
3+
#![feature(sized_hierarchy)]
4+
#![allow(unused)]
5+
use std::marker::{MetaSized, PointeeSized};
6+
7+
fn directly<T: Sized>(t: &T) {}
8+
//~^ ERROR redundant_sizedness_bound
9+
10+
trait A: Sized {}
11+
trait B: A {}
12+
13+
fn depth_1<T: A>(t: &T) {}
14+
//~^ ERROR redundant_sizedness_bound
15+
fn depth_2<T: B>(t: &T) {}
16+
//~^ ERROR redundant_sizedness_bound
17+
18+
// We only need to show one
19+
fn multiple_paths<T: A + B>(t: &T) {}
20+
//~^ ERROR redundant_sizedness_bound
21+
22+
fn in_where<T>(t: &T)
23+
where
24+
T: Sized,
25+
//~^ ERROR redundant_sizedness_bound
26+
{
27+
}
28+
29+
fn mixed_1<T: Sized>(t: &T)
30+
//~^ ERROR redundant_sizedness_bound
31+
{
32+
}
33+
34+
fn mixed_2<T>(t: &T)
35+
//~^ ERROR redundant_sizedness_bound
36+
where
37+
T: Sized,
38+
{
39+
}
40+
41+
fn mixed_3<T>(t: &T)
42+
where
43+
T: Sized,
44+
//~^ ERROR redundant_sizedness_bound
45+
{
46+
}
47+
48+
struct Struct<T: Sized>(T);
49+
//~^ ERROR redundant_sizedness_bound
50+
51+
impl<T: Sized> Struct<T> {
52+
//~^ ERROR redundant_sizedness_bound
53+
fn method<U: Sized>(&self) {}
54+
//~^ ERROR redundant_sizedness_bound
55+
}
56+
57+
enum Enum<T: Sized + 'static> {
58+
//~^ ERROR redundant_sizedness_bound
59+
Variant(&'static T),
60+
}
61+
62+
union Union<'a, T: Sized> {
63+
//~^ ERROR redundant_sizedness_bound
64+
a: &'a T,
65+
}
66+
67+
trait Trait<T: Sized> {
68+
//~^ ERROR redundant_sizedness_bound
69+
fn trait_method<U: Sized>() {}
70+
//~^ ERROR redundant_sizedness_bound
71+
72+
type GAT<U: Sized>;
73+
//~^ ERROR redundant_sizedness_bound
74+
75+
type Assoc: Sized + ?Sized; // False negative
76+
}
77+
78+
trait SecondInTrait: Send + Sized {}
79+
fn second_in_trait<T: SecondInTrait>() {}
80+
//~^ ERROR redundant_sizedness_bound
81+
82+
fn impl_trait(_: &(impl Sized)) {}
83+
//~^ ERROR redundant_sizedness_bound
84+
85+
trait GenericTrait<T>: Sized {}
86+
fn in_generic_trait<T: GenericTrait<U>, U>() {}
87+
//~^ ERROR redundant_sizedness_bound
88+
89+
mod larger_graph {
90+
// C1 C2 Sized
91+
// \ /\ /
92+
// B1 B2
93+
// \ /
94+
// A1
95+
96+
trait C1 {}
97+
trait C2 {}
98+
trait B1: C1 + C2 {}
99+
trait B2: C2 + Sized {}
100+
trait A1: B1 + B2 {}
101+
102+
fn larger_graph<T: A1>() {}
103+
//~^ ERROR redundant_sizedness_bound
104+
}
105+
106+
trait S1: Sized {}
107+
fn meta_sized<T: S1>() {}
108+
//~^ ERROR redundant_sizedness_bound
109+
fn pointee_sized<T: S1>() {}
110+
//~^ ERROR redundant_sizedness_bound
111+
trait M1: MetaSized {}
112+
fn pointee_metasized<T: M1>() {}
113+
//~^ ERROR redundant_sizedness_bound
114+
115+
// Should not lint
116+
117+
fn sized<T: Sized>() {}
118+
fn maybe_sized<T: ?Sized>() {}
119+
120+
struct SeparateBounds<T: ?Sized>(T);
121+
impl<T: Sized> SeparateBounds<T> {}
122+
123+
trait P {}
124+
trait Q: P {}
125+
126+
fn ok_depth_1<T: P + ?Sized>() {}
127+
fn ok_depth_2<T: Q + ?Sized>() {}
128+
129+
//external! {
130+
// fn in_macro<T: Clone + ?Sized>(t: &T) {}
131+
132+
// fn with_local_clone<T: $Clone + ?Sized>(t: &T) {}
133+
//}
134+
135+
#[derive(Clone)]
136+
struct InDerive<T: ?Sized> {
137+
t: T,
138+
}
139+
140+
struct Refined<T: ?Sized>(T);
141+
impl<T: Sized> Refined<T> {}
142+
143+
fn main() {}

tests/ui/lint/lint-redundant-sizedness-bound.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
//@ run-rustfix
12
#![deny(redundant_sizedness_bound)]
3+
#![feature(sized_hierarchy)]
4+
#![allow(unused)]
5+
use std::marker::{MetaSized, PointeeSized};
26

37
fn directly<T: Sized + ?Sized>(t: &T) {}
48
//~^ ERROR redundant_sizedness_bound
@@ -102,6 +106,15 @@ mod larger_graph {
102106
//~^ ERROR redundant_sizedness_bound
103107
}
104108

109+
trait S1: Sized {}
110+
fn meta_sized<T: MetaSized + S1>() {}
111+
//~^ ERROR redundant_sizedness_bound
112+
fn pointee_sized<T: PointeeSized + S1>() {}
113+
//~^ ERROR redundant_sizedness_bound
114+
trait M1: MetaSized {}
115+
fn pointee_metasized<T: PointeeSized + M1>() {}
116+
//~^ ERROR redundant_sizedness_bound
117+
105118
// Should not lint
106119

107120
fn sized<T: Sized>() {}

0 commit comments

Comments
 (0)