forked from rust-lang/rust
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 ```
- Loading branch information
Showing
7 changed files
with
64 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/doc/unstable-book/src/compiler-flags/move-size-limit.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# `move_size_limit` | ||
|
||
-------------------- | ||
|
||
The `-Zmove-size-limit=N` compiler flag enables `large_assignments` lints which | ||
will warn when moving objects whose size exceeds `N` bytes. | ||
|
||
Lint warns only about moves in functions that participate in code generation. | ||
Consequently it will be ineffective for compiler invocatation that emit | ||
metadata only, i.e., `cargo check` like workflows. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
error: moving 10024 bytes | ||
--> $DIR/large_moves.rs:12:13 | ||
| | ||
LL | let x = async { | ||
| _____________^ | ||
LL | | let y = [0; 9999]; | ||
LL | | dbg!(y); | ||
LL | | thing(&y).await; | ||
LL | | dbg!(y); | ||
LL | | }; | ||
| |_____^ value moved from here | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/large_moves.rs:1:9 | ||
| | ||
LL | #![deny(large_assignments)] | ||
| ^^^^^^^^^^^^^^^^^ | ||
|
||
error: moving 10024 bytes | ||
--> $DIR/large_moves.rs:18:14 | ||
| | ||
LL | let z = (x, 42); | ||
| ^ value moved from here | ||
|
||
error: moving 10024 bytes | ||
--> $DIR/large_moves.rs:18:13 | ||
| | ||
LL | let z = (x, 42); | ||
| ^^^^^^^ value moved from here | ||
|
||
error: moving 10024 bytes | ||
--> $DIR/large_moves.rs:20:13 | ||
| | ||
LL | let a = z.0; | ||
| ^^^ value moved from here | ||
|
||
error: aborting due to 4 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters