Skip to content

Commit 9f87deb

Browse files
committed
Auto merge of #115684 - Enselic:large_assignments-default, r=<try>
Set default `move_size_limit` to 4kB for `large_assignments` lint on nightly Only enable it by default in the nightly compiler. The limit can be changed on a per-crate basis with: #![feature(large_assignments)] #![move_size_limit = "8192"] or with -Zmove-size-limit=8192 Does the _"enable the lint by default with a 4k threshold"_ step in #83518. TODO: - [ ] Figure out how to write a test that tests that the stable compiler still has a default move_size_limit of 0. I suspect it is easy once you know the trick, but I haven't been able to figure out the trick yet. - [ ] I found a bug where the lint is duplicated unnecessarily when generic instantiations are involved. See FIXME in the test. We should file an issue about it so we don't forget it. Or at least write a row in the tracking issue. - [ ] The compiler seems very slow after this change. Might be tricky to fix.. r? `@oli-obk` who is E-mentor.
2 parents 7d1e416 + 84f8c26 commit 9f87deb

File tree

27 files changed

+213
-20
lines changed

27 files changed

+213
-20
lines changed

compiler/rustc_interface/src/passes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,7 @@ pub fn create_global_ctxt<'tcx>(
716716

717717
sess.time("setup_global_ctxt", || {
718718
gcx_cell.get_or_init(move || {
719+
#[allow(large_assignments)]
719720
TyCtxt::create_global_ctxt(
720721
sess,
721722
crate_types,

compiler/rustc_interface/src/queries.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ pub struct Queries<'tcx> {
9191

9292
impl<'tcx> Queries<'tcx> {
9393
pub fn new(compiler: &'tcx Compiler) -> Queries<'tcx> {
94+
#[allow(large_assignments)]
9495
Queries {
9596
compiler,
9697
gcx_cell: OnceLock::new(),

compiler/rustc_interface/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![allow(rustc::bad_opt_access)]
1+
#![allow(rustc::bad_opt_access, large_assignments)]
22
use crate::interface::parse_cfgspecs;
33

44
use rustc_data_structures::fx::FxHashSet;

compiler/rustc_interface/src/util.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ pub fn create_session(
128128
sess.parse_sess.config = cfg;
129129
sess.parse_sess.check_config = check_cfg;
130130

131+
#[allow(large_assignments)]
131132
(sess, codegen_backend)
132133
}
133134

compiler/rustc_middle/src/middle/limits.rs

Lines changed: 9 additions & 1 deletion
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(),

compiler/rustc_middle/src/ty/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,7 @@ impl<'tcx> TyCtxt<'tcx> {
711711
let common_lifetimes = CommonLifetimes::new(&interners);
712712
let common_consts = CommonConsts::new(&interners, &common_types);
713713

714+
#[allow(large_assignments)]
714715
GlobalCtxt {
715716
sess: s,
716717
crate_types,

compiler/rustc_query_impl/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ pub fn query_system<'tcx>(
209209
on_disk_cache: Option<OnDiskCache<'tcx>>,
210210
incremental: bool,
211211
) -> QuerySystem<'tcx> {
212+
#[allow(large_assignments)]
212213
QuerySystem {
213214
states: Default::default(),
214215
arenas: Default::default(),

compiler/rustc_session/src/session.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1318,7 +1318,7 @@ fn default_emitter(
13181318
}
13191319

13201320
// JUSTIFICATION: literally session construction
1321-
#[allow(rustc::bad_opt_access)]
1321+
#[allow(rustc::bad_opt_access, large_assignments)]
13221322
pub fn build_session(
13231323
handler: &EarlyErrorHandler,
13241324
sopts: config::Options,

compiler/rustc_target/src/spec/apple/tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(large_assignments)]
2+
13
use crate::spec::{
24
aarch64_apple_darwin, aarch64_apple_ios_sim, aarch64_apple_watchos_sim, i686_apple_darwin,
35
x86_64_apple_darwin, x86_64_apple_ios, x86_64_apple_tvos, x86_64_apple_watchos_sim,

library/alloc/benches/vec_deque.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(large_assignments)]
2+
13
use core::iter::Iterator;
24
use std::{
35
collections::{vec_deque, VecDeque},

library/alloc/src/boxed.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,7 @@ impl<T, A: Allocator> Box<mem::MaybeUninit<T>, A> {
837837
///
838838
/// ```
839839
/// #![feature(new_uninit)]
840+
/// #![allow(large_assignments)]
840841
///
841842
/// let big_box = Box::<[usize; 1024]>::new_uninit();
842843
///

library/core/benches/array.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(large_assignments)]
2+
13
use test::black_box;
24
use test::Bencher;
35

library/core/benches/iter.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(large_assignments)]
2+
13
use core::borrow::Borrow;
24
use core::iter::*;
35
use core::mem;

library/core/src/cell.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,6 +2042,7 @@ impl<T> UnsafeCell<T> {
20422042
#[rustc_const_stable(feature = "const_unsafe_cell_new", since = "1.32.0")]
20432043
#[inline(always)]
20442044
pub const fn new(value: T) -> UnsafeCell<T> {
2045+
#[allow(large_assignments)]
20452046
UnsafeCell { value }
20462047
}
20472048

library/core/src/convert/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,7 @@ where
713713
/// <code>[From]&lt;T&gt; for U</code> chooses to do.
714714
#[inline]
715715
fn into(self) -> U {
716+
#[allow(large_assignments)]
716717
U::from(self)
717718
}
718719
}

library/core/src/hint.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ pub fn spin_loop() {
290290
#[stable(feature = "bench_black_box", since = "1.66.0")]
291291
#[rustc_const_unstable(feature = "const_black_box", issue = "none")]
292292
pub const fn black_box<T>(dummy: T) -> T {
293+
#[allow(large_assignments)]
293294
crate::intrinsics::black_box(dummy)
294295
}
295296

library/core/src/mem/maybe_uninit.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ use crate::slice;
9797
/// unnecessary moves.
9898
///
9999
/// ```
100+
/// ##![allow(large_assignments)]
100101
/// use std::mem::MaybeUninit;
101102
///
102103
/// unsafe fn make_vec(out: *mut Vec<i32>) {
@@ -117,6 +118,7 @@ use crate::slice;
117118
/// `MaybeUninit<T>` can be used to initialize a large array element-by-element:
118119
///
119120
/// ```
121+
/// ##![allow(large_assignments)]
120122
/// use std::mem::{self, MaybeUninit};
121123
///
122124
/// let data = {
@@ -145,6 +147,7 @@ use crate::slice;
145147
/// be found in low-level datastructures.
146148
///
147149
/// ```
150+
/// ##![allow(large_assignments)]
148151
/// use std::mem::MaybeUninit;
149152
///
150153
/// // Create an uninitialized array of `MaybeUninit`. The `assume_init` is

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

Lines changed: 49 additions & 1 deletion
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

Lines changed: 55 additions & 0 deletions
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

Lines changed: 37 additions & 5 deletions
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

0 commit comments

Comments
 (0)