Rollup merge of #83519 - oli-obk:assign_shrink_your_normal_code, r=pnkfelix
Implement a lint that highlights all moves larger than a configured limit Tracking issue: #83518 [MCP 420](https://github.com/rust-lang/compiler-team/issues/420) still ~blazing~ in progress r? ```@pnkfelix``` The main open issue I see with this minimal impl of the feature is that the lint is immediately "stable" (so it can be named on stable), even if it is never executed on stable. I don't think we have the concept of unstable lint names or hiding lint names without an active feature gate, so that would be a bigger change.
This commit is contained in:
commit
e109aa3613
13 changed files with 218 additions and 21 deletions
24
src/test/ui/async-await/large_moves.rs
Normal file
24
src/test/ui/async-await/large_moves.rs
Normal file
|
|
@ -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);
|
||||
}
|
||||
38
src/test/ui/async-await/large_moves.stderr
Normal file
38
src/test/ui/async-await/large_moves.stderr
Normal file
|
|
@ -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
|
||||
|
||||
|
|
@ -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() {}
|
||||
|
|
@ -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`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue