Skip to content

Commit 3476528

Browse files
committed
Fix test failure
1 parent 82f1bbc commit 3476528

File tree

5 files changed

+49
-33
lines changed

5 files changed

+49
-33
lines changed

clippy_lints/src/static_items_large_align.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ declare_clippy_lint! {
3535
/// let b = Box::new(Aligned(0)); // Good
3636
/// println!("{:#x}", Box::into_raw(b) as usize);
3737
/// }
38+
/// ```
3839
#[clippy::version = "1.61.0"]
3940
pub STATIC_ITEMS_LARGE_ALIGN,
4041
pedantic,

src/docs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ docs! {
465465
"skip_while_next",
466466
"slow_vector_initialization",
467467
"stable_sort_primitive",
468+
"static_items_large_align",
468469
"std_instead_of_alloc",
469470
"std_instead_of_core",
470471
"str_to_string",

src/docs/static_items_large_align.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
### What it does
2+
Check for usage of static items which have type alignment larger than page size.
3+
4+
### Why is this bad?
5+
Due to some known unsound issues, the type alignment may not be fulfilled.
6+
For more information, see:
7+
<https://github.com/rust-lang/rust/issues/70022> and
8+
<https://github.com/rust-lang/rust/issues/70143>.
9+
10+
### Example
11+
```
12+
#[repr(align(0x100000))]
13+
struct Aligned(u8);
14+
15+
static X: Aligned = Aligned(0); // Bad
16+
17+
fn main() {
18+
let x = Aligned(0); // Good
19+
println!("{:#x}", &x as *const _ as usize);
20+
println!("{:#x}", &X as *const _ as usize);
21+
let b = Box::new(Aligned(0)); // Good
22+
println!("{:#x}", Box::into_raw(b) as usize);
23+
}
24+
```

tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ error: error reading Clippy's configuration file `$DIR/clippy.toml`: unknown fie
2727
max-suggested-slice-pattern-length
2828
max-trait-bounds
2929
msrv
30+
page-size
3031
pass-by-value-size-limit
3132
single-char-binding-names-threshold
3233
standard-macro-braces

tests/ui/static_items_large_align.stderr

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ note: struct `Aligned` has alignment 0x100000, which is larger than 0x1000,
1212
--> $DIR/static_items_large_align.rs:7:1
1313
|
1414
LL | struct Aligned(u8);
15-
| ^^^^^^^^^^^^^^^^^^^
15+
| ^^^^^^^^^^^^^^
1616

1717
error: this static item (itself or its subfield) has a type alignment,
1818
which is larger than page size and may not be fulfilled,
@@ -32,7 +32,7 @@ note: struct `Aligned` has alignment 0x100000, which is larger than 0x1000,
3232
--> $DIR/static_items_large_align.rs:7:1
3333
|
3434
LL | struct Aligned(u8);
35-
| ^^^^^^^^^^^^^^^^^^^
35+
| ^^^^^^^^^^^^^^
3636

3737
error: this static item (itself or its subfield) has a type alignment,
3838
which is larger than page size and may not be fulfilled,
@@ -46,13 +46,13 @@ note: struct `AlignedPtr` contains an inner type with large alignment
4646
--> $DIR/static_items_large_align.rs:18:1
4747
|
4848
LL | struct AlignedPtr(*const Aligned);
49-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
49+
| ^^^^^^^^^^^^^^^^^
5050
note: struct `Aligned` has alignment 0x100000, which is larger than 0x1000,
5151
if you know what you are doing, config the default page size clippy uses in clippy.toml
5252
--> $DIR/static_items_large_align.rs:7:1
5353
|
5454
LL | struct Aligned(u8);
55-
| ^^^^^^^^^^^^^^^^^^^
55+
| ^^^^^^^^^^^^^^
5656

5757
error: this static item (itself or its subfield) has a type alignment,
5858
which is larger than page size and may not be fulfilled,
@@ -65,17 +65,14 @@ LL | static XW: AlignedWrapper = AlignedWrapper { f: 0, g: Aligned(0) };
6565
note: struct `AlignedWrapper` contains an inner type with large alignment
6666
--> $DIR/static_items_large_align.rs:9:1
6767
|
68-
LL | / struct AlignedWrapper {
69-
LL | | f: u8,
70-
LL | | g: Aligned,
71-
LL | | }
72-
| |_^
68+
LL | struct AlignedWrapper {
69+
| ^^^^^^^^^^^^^^^^^^^^^
7370
note: struct `Aligned` has alignment 0x100000, which is larger than 0x1000,
7471
if you know what you are doing, config the default page size clippy uses in clippy.toml
7572
--> $DIR/static_items_large_align.rs:7:1
7673
|
7774
LL | struct Aligned(u8);
78-
| ^^^^^^^^^^^^^^^^^^^
75+
| ^^^^^^^^^^^^^^
7976

8077
error: this static item (itself or its subfield) has a type alignment,
8178
which is larger than page size and may not be fulfilled,
@@ -95,7 +92,7 @@ note: struct `Aligned` has alignment 0x100000, which is larger than 0x1000,
9592
--> $DIR/static_items_large_align.rs:7:1
9693
|
9794
LL | struct Aligned(u8);
98-
| ^^^^^^^^^^^^^^^^^^^
95+
| ^^^^^^^^^^^^^^
9996

10097
error: this static item (itself or its subfield) has a type alignment,
10198
which is larger than page size and may not be fulfilled,
@@ -115,7 +112,7 @@ note: struct `Aligned` has alignment 0x100000, which is larger than 0x1000,
115112
--> $DIR/static_items_large_align.rs:7:1
116113
|
117114
LL | struct Aligned(u8);
118-
| ^^^^^^^^^^^^^^^^^^^
115+
| ^^^^^^^^^^^^^^
119116

120117
error: this static item (itself or its subfield) has a type alignment,
121118
which is larger than page size and may not be fulfilled,
@@ -128,16 +125,14 @@ LL | static XE: AlignedEnum = AlignedEnum::A(Aligned(0));
128125
note: enum `AlignedEnum` contains an inner type with large alignment
129126
--> $DIR/static_items_large_align.rs:14:1
130127
|
131-
LL | / enum AlignedEnum {
132-
LL | | A(Aligned),
133-
LL | | }
134-
| |_^
128+
LL | enum AlignedEnum {
129+
| ^^^^^^^^^^^^^^^^
135130
note: struct `Aligned` has alignment 0x100000, which is larger than 0x1000,
136131
if you know what you are doing, config the default page size clippy uses in clippy.toml
137132
--> $DIR/static_items_large_align.rs:7:1
138133
|
139134
LL | struct Aligned(u8);
140-
| ^^^^^^^^^^^^^^^^^^^
135+
| ^^^^^^^^^^^^^^
141136

142137
error: this static item (itself or its subfield) has a type alignment,
143138
which is larger than page size and may not be fulfilled,
@@ -154,13 +149,13 @@ note: struct `AlignedGeneric` with substitutions [
154149
--> $DIR/static_items_large_align.rs:22:1
155150
|
156151
LL | struct AlignedGeneric<T>(T);
157-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
152+
| ^^^^^^^^^^^^^^^^^^^^^^^^
158153
note: struct `Aligned` has alignment 0x100000, which is larger than 0x1000,
159154
if you know what you are doing, config the default page size clippy uses in clippy.toml
160155
--> $DIR/static_items_large_align.rs:7:1
161156
|
162157
LL | struct Aligned(u8);
163-
| ^^^^^^^^^^^^^^^^^^^
158+
| ^^^^^^^^^^^^^^
164159

165160
error: this static item (itself or its subfield) has a type alignment,
166161
which is larger than page size and may not be fulfilled,
@@ -177,21 +172,18 @@ note: struct `AlignedGeneric` with substitutions [
177172
--> $DIR/static_items_large_align.rs:22:1
178173
|
179174
LL | struct AlignedGeneric<T>(T);
180-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
175+
| ^^^^^^^^^^^^^^^^^^^^^^^^
181176
note: struct `AlignedWrapper` contains an inner type with large alignment
182177
--> $DIR/static_items_large_align.rs:9:1
183178
|
184-
LL | / struct AlignedWrapper {
185-
LL | | f: u8,
186-
LL | | g: Aligned,
187-
LL | | }
188-
| |_^
179+
LL | struct AlignedWrapper {
180+
| ^^^^^^^^^^^^^^^^^^^^^
189181
note: struct `Aligned` has alignment 0x100000, which is larger than 0x1000,
190182
if you know what you are doing, config the default page size clippy uses in clippy.toml
191183
--> $DIR/static_items_large_align.rs:7:1
192184
|
193185
LL | struct Aligned(u8);
194-
| ^^^^^^^^^^^^^^^^^^^
186+
| ^^^^^^^^^^^^^^
195187

196188
error: this static item (itself or its subfield) has a type alignment,
197189
which is larger than page size and may not be fulfilled,
@@ -211,25 +203,22 @@ note: struct `AGWithArgs` with substitutions [
211203
contains an inner type with large alignment
212204
--> $DIR/static_items_large_align.rs:63:1
213205
|
214-
LL | / struct AGWithArgs<A, B> {
215-
LL | | not_aligned: FnPtr<A>,
216-
LL | | aligned: AGAlias<B>,
217-
LL | | }
218-
| |_^
206+
LL | struct AGWithArgs<A, B> {
207+
| ^^^^^^^^^^^^^^^^^^^^^^^
219208
note: struct `AG` with substitutions [
220209
AlignedB,
221210
],
222211
contains an inner type with large alignment
223212
--> $DIR/static_items_large_align.rs:59:1
224213
|
225214
LL | struct AG<T>(T);
226-
| ^^^^^^^^^^^^^^^^
215+
| ^^^^^^^^^^^^
227216
note: struct `AlignedB` has alignment 0x100000, which is larger than 0x1000,
228217
if you know what you are doing, config the default page size clippy uses in clippy.toml
229218
--> $DIR/static_items_large_align.rs:55:1
230219
|
231220
LL | struct AlignedB(u8);
232-
| ^^^^^^^^^^^^^^^^^^^^
221+
| ^^^^^^^^^^^^^^^
233222

234223
error: aborting due to 10 previous errors
235224

0 commit comments

Comments
 (0)