Skip to content

Commit dec3078

Browse files
committed
Enable large_assignments lint by default with 4096 byte limit
But only in the nightly compiler.
1 parent f06b7c5 commit dec3078

File tree

11 files changed

+191
-18
lines changed

11 files changed

+191
-18
lines changed

compiler/rustc_middle/src/middle/limits.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,15 @@ pub fn provide(providers: &mut Providers) {
2525
tcx.hir().krate_attrs(),
2626
tcx.sess,
2727
sym::move_size_limit,
28-
tcx.sess.opts.unstable_opts.move_size_limit.unwrap_or(0),
28+
// The check is enabled by default in nightly compilers without
29+
// needing `#![feature(large_assignments)]` with a limit of 4096
30+
// bytes. But if the user wants to use adjust `#![move_size_limit]`,
31+
// then `#![feature(large_assignments)]` is needed.
32+
tcx.sess.opts.unstable_opts.move_size_limit.unwrap_or(if tcx.sess.is_nightly_build() {
33+
4096
34+
} else {
35+
0
36+
}),
2937
),
3038
type_length_limit: get_limit(
3139
tcx.hir().krate_attrs(),

tests/ui/async-await/large_moves.attribute.stderr

+49-1
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,60 @@ LL | let _ = NotBox::new([0; 9999]);
2828
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
2929

3030
error: moving 9999 bytes
31+
--> $DIR/large_moves.rs:63:13
32+
|
33+
LL | data,
34+
| ^^^^ value moved from here
35+
|
36+
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
37+
38+
error: moving 1500 bytes
39+
--> $DIR/large_moves.rs:37:13
40+
|
41+
LL | let _ = NotBox::new([0; 1500]);
42+
| ^^^^^^^^^^^^^^^^^^^^^^ value moved from here
43+
|
44+
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
45+
46+
error: moving 2500 bytes
3147
--> $DIR/large_moves.rs:41:13
3248
|
49+
LL | let _ = NotBox::new([0; 2500]);
50+
| ^^^^^^^^^^^^^^^^^^^^^^ value moved from here
51+
|
52+
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
53+
54+
error: moving 5000 bytes
55+
--> $DIR/large_moves.rs:47:13
56+
|
57+
LL | let _ = NotBox::new([0; 5000]);
58+
| ^^^^^^^^^^^^^^^^^^^^^^ value moved from here
59+
|
60+
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
61+
62+
error: moving 1500 bytes
63+
--> $DIR/large_moves.rs:63:13
64+
|
65+
LL | data,
66+
| ^^^^ value moved from here
67+
|
68+
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
69+
70+
error: moving 2500 bytes
71+
--> $DIR/large_moves.rs:63:13
72+
|
73+
LL | data,
74+
| ^^^^ value moved from here
75+
|
76+
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
77+
78+
error: moving 5000 bytes
79+
--> $DIR/large_moves.rs:63:13
80+
|
3381
LL | data,
3482
| ^^^^ value moved from here
3583
|
3684
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
3785

38-
error: aborting due to 4 previous errors
86+
error: aborting due to 10 previous errors
3987

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
error: moving 10024 bytes
2+
--> $DIR/large_moves.rs:21:14
3+
|
4+
LL | let z = (x, 42);
5+
| ^ value moved from here
6+
|
7+
= note: The current maximum size is 4096, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
8+
note: the lint level is defined here
9+
--> $DIR/large_moves.rs:1:9
10+
|
11+
LL | #![deny(large_assignments)]
12+
| ^^^^^^^^^^^^^^^^^
13+
14+
error: moving 10024 bytes
15+
--> $DIR/large_moves.rs:22:13
16+
|
17+
LL | let a = z.0;
18+
| ^^^ value moved from here
19+
|
20+
= note: The current maximum size is 4096, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
21+
22+
error: moving 9999 bytes
23+
--> $DIR/large_moves.rs:27:13
24+
|
25+
LL | let _ = NotBox::new([0; 9999]);
26+
| ^^^^^^^^^^^^^^^^^^^^^^ value moved from here
27+
|
28+
= note: The current maximum size is 4096, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
29+
30+
error: moving 9999 bytes
31+
--> $DIR/large_moves.rs:63:13
32+
|
33+
LL | data,
34+
| ^^^^ value moved from here
35+
|
36+
= note: The current maximum size is 4096, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
37+
38+
error: moving 5000 bytes
39+
--> $DIR/large_moves.rs:47:13
40+
|
41+
LL | let _ = NotBox::new([0; 5000]);
42+
| ^^^^^^^^^^^^^^^^^^^^^^ value moved from here
43+
|
44+
= note: The current maximum size is 4096, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
45+
46+
error: moving 5000 bytes
47+
--> $DIR/large_moves.rs:63:13
48+
|
49+
LL | data,
50+
| ^^^^ value moved from here
51+
|
52+
= note: The current maximum size is 4096, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
53+
54+
error: aborting due to 6 previous errors
55+

tests/ui/async-await/large_moves.option.stderr

+37-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: moving 10024 bytes
44
LL | let z = (x, 42);
55
| ^ value moved from here
66
|
7-
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
7+
= note: The current maximum size is 2000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
88
note: the lint level is defined here
99
--> $DIR/large_moves.rs:1:9
1010
|
@@ -17,23 +17,55 @@ error: moving 10024 bytes
1717
LL | let a = z.0;
1818
| ^^^ value moved from here
1919
|
20-
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
20+
= note: The current maximum size is 2000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
2121

2222
error: moving 9999 bytes
2323
--> $DIR/large_moves.rs:27:13
2424
|
2525
LL | let _ = NotBox::new([0; 9999]);
2626
| ^^^^^^^^^^^^^^^^^^^^^^ value moved from here
2727
|
28-
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
28+
= note: The current maximum size is 2000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
2929

3030
error: moving 9999 bytes
31+
--> $DIR/large_moves.rs:63:13
32+
|
33+
LL | data,
34+
| ^^^^ value moved from here
35+
|
36+
= note: The current maximum size is 2000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
37+
38+
error: moving 2500 bytes
3139
--> $DIR/large_moves.rs:41:13
3240
|
41+
LL | let _ = NotBox::new([0; 2500]);
42+
| ^^^^^^^^^^^^^^^^^^^^^^ value moved from here
43+
|
44+
= note: The current maximum size is 2000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
45+
46+
error: moving 5000 bytes
47+
--> $DIR/large_moves.rs:47:13
48+
|
49+
LL | let _ = NotBox::new([0; 5000]);
50+
| ^^^^^^^^^^^^^^^^^^^^^^ value moved from here
51+
|
52+
= note: The current maximum size is 2000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
53+
54+
error: moving 2500 bytes
55+
--> $DIR/large_moves.rs:63:13
56+
|
57+
LL | data,
58+
| ^^^^ value moved from here
59+
|
60+
= note: The current maximum size is 2000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
61+
62+
error: moving 5000 bytes
63+
--> $DIR/large_moves.rs:63:13
64+
|
3365
LL | data,
3466
| ^^^^ value moved from here
3567
|
36-
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
68+
= note: The current maximum size is 2000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
3769

38-
error: aborting due to 4 previous errors
70+
error: aborting due to 8 previous errors
3971

tests/ui/async-await/large_moves.rs

+35-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#![deny(large_assignments)]
2-
#![feature(large_assignments)]
2+
#![cfg_attr(attribute, feature(large_assignments))]
33
#![cfg_attr(attribute, move_size_limit = "1000")]
44
// build-fail
55
// only-x86_64
6-
// revisions: attribute option
7-
// [option]compile-flags: -Zmove-size-limit=1000
6+
// revisions: attribute option nothing
7+
// [option]compile-flags: -Zmove-size-limit=2000
88

99
// edition:2018
1010
// compile-flags: -Zmir-opt-level=0
@@ -25,20 +25,48 @@ fn main() {
2525
let _ = Box::new([0; 9999]); // OK!
2626
let _ = Rc::new([0; 9999]); // OK!
2727
let _ = NotBox::new([0; 9999]); //~ ERROR large_assignments
28+
default_limits();
29+
}
30+
31+
fn default_limits() {
32+
// Moving 500 bytes is OK in all revisions
33+
let _ = NotBox::new([0; 500]);
34+
35+
// Moving 1500 bytes should fail only with the `attribute` revision because
36+
// its limit is 1000 bytes
37+
let _ = NotBox::new([0; 1500]); //[attribute]~ ERROR large_assignments
38+
39+
// Moving 2500 bytes should fail with both `attribute` and `option` since
40+
// their limits are 1000 and 2000 respectively.
41+
let _ = NotBox::new([0; 2500]);
42+
//[attribute]~^ ERROR large_assignments
43+
//[option]~^^ ERROR large_assignments
44+
45+
// With a nightly compiler the default limit is 4096. So 5000 should fail
46+
// for all revisions
47+
let _ = NotBox::new([0; 5000]); //~ ERROR large_assignments
2848
}
2949

3050
async fn thing(y: &[u8]) {
3151
dbg!(y);
3252
}
3353

34-
struct NotBox {
35-
data: [u8; 9999],
54+
struct NotBox<const N: usize> {
55+
data: [u8; N],
3656
}
3757

38-
impl NotBox {
39-
fn new(data: [u8; 9999]) -> Self {
58+
impl<const N: usize> NotBox<N> {
59+
fn new(data: [u8; N]) -> Self {
60+
// FIXME: Each different instantiation of this generic type (with
61+
// different N) results in a unique error message. Deduplicate somehow.
4062
Self {
4163
data, //~ ERROR large_assignments
64+
//[nothing]~^ ERROR large_assignments
65+
//[option]~| ERROR large_assignments
66+
//[option]~| ERROR large_assignments
67+
//[attribute]~| ERROR large_assignments
68+
//[attribute]~| ERROR large_assignments
69+
//[attribute]~| ERROR large_assignments
4270
}
4371
}
4472
}

tests/ui/limits/huge-array.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(large_assignments)]
12
// build-fail
23

34
fn generic<T: Copy>(t: T) {

tests/ui/limits/huge-array.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: values of the type `[[u8; 1518599999]; 1518600000]` are too big for the current architecture
2-
--> $DIR/huge-array.rs:4:9
2+
--> $DIR/huge-array.rs:5:9
33
|
44
LL | let s: [T; 1518600000] = [t; 1518600000];
55
| ^

tests/ui/print_type_sizes/async.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// build-pass
44
// ignore-pass
55

6-
#![allow(dropping_copy_types)]
6+
#![allow(dropping_copy_types, large_assignments)]
77

88
async fn wait() {}
99

tests/ui/print_type_sizes/generator.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// build-pass
33
// ignore-pass
44

5+
#![allow(large_assignments)]
56
#![feature(generators, generator_trait)]
67

78
use std::ops::Generator;

tests/ui/print_type_sizes/generator.stdout

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
print-type-size type: `[generator@$DIR/generator.rs:10:5: 10:14]`: 8193 bytes, alignment: 1 bytes
1+
print-type-size type: `[generator@$DIR/generator.rs:11:5: 11:14]`: 8193 bytes, alignment: 1 bytes
22
print-type-size discriminant: 1 bytes
33
print-type-size variant `Unresumed`: 8192 bytes
44
print-type-size upvar `.array`: 8192 bytes

tests/ui/structs-enums/align-struct.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-pass
2-
#![allow(dead_code, unused_allocation)]
2+
#![allow(dead_code, unused_allocation, large_assignments)]
33

44
use std::mem;
55

0 commit comments

Comments
 (0)