Skip to content

Commit 99a6474

Browse files
authored
Rollup merge of rust-lang#86450 - tmiasko:move-size-limit, r=pnkfelix
Add flag to configure `large_assignments` lint The `large_assignments` lints detects moves over specified limit. The limit is configured through `move_size_limit = "N"` attribute placed at the root of a crate. When attribute is absent, the lint is disabled. Make it possible to enable the lint without making any changes to the source code, through a new flag `-Zmove-size-limit=N`. For example, to detect moves exceeding 1023 bytes in a cargo crate, including all dependencies one could use: ``` $ env RUSTFLAGS=-Zmove-size-limit=1024 cargo build -vv ``` Lint tracking issue rust-lang#83518.
2 parents 998cfe5 + 9792179 commit 99a6474

File tree

7 files changed

+64
-6
lines changed

7 files changed

+64
-6
lines changed

compiler/rustc_interface/src/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,7 @@ fn test_debugging_options_tracking_hash() {
735735
tracked!(merge_functions, Some(MergeFunctions::Disabled));
736736
tracked!(mir_emit_retag, true);
737737
tracked!(mir_opt_level, Some(4));
738+
tracked!(move_size_limit, Some(4096));
738739
tracked!(mutable_noalias, Some(true));
739740
tracked!(new_llvm_pass_manager, Some(true));
740741
tracked!(no_generate_arange_section, true);

compiler/rustc_middle/src/middle/limits.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ use std::num::IntErrorKind;
2121
pub fn provide(providers: &mut ty::query::Providers) {
2222
providers.limits = |tcx, ()| Limits {
2323
recursion_limit: get_recursion_limit(tcx.hir().krate_attrs(), tcx.sess),
24-
move_size_limit: get_limit(tcx.hir().krate_attrs(), tcx.sess, sym::move_size_limit, 0),
24+
move_size_limit: get_limit(
25+
tcx.hir().krate_attrs(),
26+
tcx.sess,
27+
sym::move_size_limit,
28+
tcx.sess.opts.debugging_opts.move_size_limit.unwrap_or(0),
29+
),
2530
type_length_limit: get_limit(
2631
tcx.hir().krate_attrs(),
2732
tcx.sess,

compiler/rustc_session/src/options.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,8 @@ options! {
11481148
(default: no)"),
11491149
mir_opt_level: Option<usize> = (None, parse_opt_number, [TRACKED],
11501150
"MIR optimization level (0-4; default: 1 in non optimized builds and 2 in optimized builds)"),
1151+
move_size_limit: Option<usize> = (None, parse_opt_number, [TRACKED],
1152+
"the size at which the `large_assignments` lint starts to be emitted"),
11511153
mutable_noalias: Option<bool> = (None, parse_opt_bool, [TRACKED],
11521154
"emit noalias metadata for mutable references (default: yes for LLVM >= 12, otherwise no)"),
11531155
new_llvm_pass_manager: Option<bool> = (None, parse_opt_bool, [TRACKED],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# `move_size_limit`
2+
3+
--------------------
4+
5+
The `-Zmove-size-limit=N` compiler flag enables `large_assignments` lints which
6+
will warn when moving objects whose size exceeds `N` bytes.
7+
8+
Lint warns only about moves in functions that participate in code generation.
9+
Consequently it will be ineffective for compiler invocatation that emit
10+
metadata only, i.e., `cargo check` like workflows.

src/test/ui/async-await/large_moves.stderr renamed to src/test/ui/async-await/large_moves.attribute.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: moving 10024 bytes
2-
--> $DIR/large_moves.rs:10:13
2+
--> $DIR/large_moves.rs:12:13
33
|
44
LL | let x = async {
55
| _____________^
@@ -17,19 +17,19 @@ LL | #![deny(large_assignments)]
1717
| ^^^^^^^^^^^^^^^^^
1818

1919
error: moving 10024 bytes
20-
--> $DIR/large_moves.rs:16:14
20+
--> $DIR/large_moves.rs:18:14
2121
|
2222
LL | let z = (x, 42);
2323
| ^ value moved from here
2424

2525
error: moving 10024 bytes
26-
--> $DIR/large_moves.rs:16:13
26+
--> $DIR/large_moves.rs:18:13
2727
|
2828
LL | let z = (x, 42);
2929
| ^^^^^^^ value moved from here
3030

3131
error: moving 10024 bytes
32-
--> $DIR/large_moves.rs:18:13
32+
--> $DIR/large_moves.rs:20:13
3333
|
3434
LL | let a = z.0;
3535
| ^^^ value moved from here
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
error: moving 10024 bytes
2+
--> $DIR/large_moves.rs:12:13
3+
|
4+
LL | let x = async {
5+
| _____________^
6+
LL | | let y = [0; 9999];
7+
LL | | dbg!(y);
8+
LL | | thing(&y).await;
9+
LL | | dbg!(y);
10+
LL | | };
11+
| |_____^ value moved from here
12+
|
13+
note: the lint level is defined here
14+
--> $DIR/large_moves.rs:1:9
15+
|
16+
LL | #![deny(large_assignments)]
17+
| ^^^^^^^^^^^^^^^^^
18+
19+
error: moving 10024 bytes
20+
--> $DIR/large_moves.rs:18:14
21+
|
22+
LL | let z = (x, 42);
23+
| ^ value moved from here
24+
25+
error: moving 10024 bytes
26+
--> $DIR/large_moves.rs:18:13
27+
|
28+
LL | let z = (x, 42);
29+
| ^^^^^^^ value moved from here
30+
31+
error: moving 10024 bytes
32+
--> $DIR/large_moves.rs:20:13
33+
|
34+
LL | let a = z.0;
35+
| ^^^ value moved from here
36+
37+
error: aborting due to 4 previous errors
38+

src/test/ui/async-await/large_moves.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#![deny(large_assignments)]
22
#![feature(large_assignments)]
3-
#![move_size_limit = "1000"]
3+
#![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
68

79
// edition:2018
810

0 commit comments

Comments
 (0)