-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement a lint that highlights all moves larger than a configured limit #83519
Merged
bors
merged 5 commits into
rust-lang:master
from
oli-obk:assign_shrink_your_normal_code
Apr 24, 2021
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e9696c8
Implement a lint that highlights all moves larger than 1000 bytes
oli-obk a2f2179
Add an attribute to be able to configure the limit
oli-obk a46bc56
Tidy
oli-obk 6e988c0
Typo
oli-obk 85b1c67
Limit test to 64 bit systems to keep the sizes in the diagnostics stable
oli-obk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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,24 @@ | ||
#![deny(large_assignments)] | ||
#![feature(large_assignments)] | ||
#![move_size_limit = "1000"] | ||
// build-fail | ||
// only-x86_64 | ||
|
||
// edition:2018 | ||
|
||
fn main() { | ||
let x = async { //~ ERROR large_assignments | ||
let y = [0; 9999]; | ||
dbg!(y); | ||
thing(&y).await; | ||
dbg!(y); | ||
}; | ||
let z = (x, 42); //~ ERROR large_assignments | ||
//~^ ERROR large_assignments | ||
let a = z.0; //~ ERROR large_assignments | ||
let b = z.1; | ||
} | ||
|
||
async fn thing(y: &[u8]) { | ||
dbg!(y); | ||
} |
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:10: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:16:14 | ||
| | ||
LL | let z = (x, 42); | ||
| ^ value moved from here | ||
|
||
error: moving 10024 bytes | ||
--> $DIR/large_moves.rs:16:13 | ||
| | ||
LL | let z = (x, 42); | ||
| ^^^^^^^ value moved from here | ||
|
||
error: moving 10024 bytes | ||
--> $DIR/large_moves.rs:18: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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// check that `move_size_limit is feature-gated | ||
|
||
#![move_size_limit = "42"] //~ ERROR the `#[move_size_limit]` attribute is an experimental feature | ||
|
||
fn main() {} |
12 changes: 12 additions & 0 deletions
12
src/test/ui/feature-gates/feature-gate-large-assignments.stderr
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,12 @@ | ||
error[E0658]: the `#[move_size_limit]` attribute is an experimental feature | ||
--> $DIR/feature-gate-large-assignments.rs:3:1 | ||
| | ||
LL | #![move_size_limit = "42"] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #83518 <https://github.com/rust-lang/rust/issues/83518> for more information | ||
= help: add `#![feature(large_assignments)]` to the crate attributes to enable | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a particularly interesting instance of the problem (and perhaps a huge motivation for this lint).