large_assignments: Add copy variant of Box, Rc, Arc check

This commit is contained in:
Martin Nordholts 2024-02-08 10:42:39 +01:00
parent d4f6f9ee6a
commit 1a0200ebc0
4 changed files with 63 additions and 3 deletions

View File

@ -0,0 +1,33 @@
#![deny(large_assignments)]
#![feature(large_assignments)]
#![move_size_limit = "1000"]
// build-fail
// only-x86_64
// edition:2018
// compile-flags: -Zmir-opt-level=1
use std::{sync::Arc, rc::Rc};
fn main() {
let data = [0; 9999];
// Looking at --emit mir, we can see that all parameters below are passed by
// copy. But it requires at least mir-opt-level=1.
let _ = Arc::new(data); // OK!
let _ = Box::new(data); // OK!
let _ = Rc::new(data); // OK!
let _ = NotBox::new(data); //~ ERROR large_assignments
}
struct NotBox {
data: [u8; 9999],
}
impl NotBox {
fn new(data: [u8; 9999]) -> Self {
Self { //~ ERROR large_assignments
data,
}
}
}

View File

@ -0,0 +1,25 @@
error: moving 9999 bytes
--> $DIR/copy_into_box_rc_arc.rs:20:25
|
LL | let _ = NotBox::new(data);
| ^^^^ value moved from here
|
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
note: the lint level is defined here
--> $DIR/copy_into_box_rc_arc.rs:1:9
|
LL | #![deny(large_assignments)]
| ^^^^^^^^^^^^^^^^^
error: moving 9999 bytes
--> $DIR/copy_into_box_rc_arc.rs:29:9
|
LL | / Self {
LL | | data,
LL | | }
| |_________^ value moved from here
|
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
error: aborting due to 2 previous errors

View File

@ -10,6 +10,8 @@
use std::{sync::Arc, rc::Rc}; use std::{sync::Arc, rc::Rc};
fn main() { fn main() {
// Looking at --emit mir, we can see that all parameters below are passed
// with by move.
let _ = Arc::new([0; 9999]); // OK! let _ = Arc::new([0; 9999]); // OK!
let _ = Box::new([0; 9999]); // OK! let _ = Box::new([0; 9999]); // OK!
let _ = Rc::new([0; 9999]); // OK! let _ = Rc::new([0; 9999]); // OK!

View File

@ -1,18 +1,18 @@
error: moving 9999 bytes error: moving 9999 bytes
--> $DIR/box_rc_arc_allowed.rs:16:25 --> $DIR/move_into_box_rc_arc.rs:18:25
| |
LL | let _ = NotBox::new([0; 9999]); LL | let _ = NotBox::new([0; 9999]);
| ^^^^^^^^^ value moved from here | ^^^^^^^^^ value moved from here
| |
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]` = note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
note: the lint level is defined here note: the lint level is defined here
--> $DIR/box_rc_arc_allowed.rs:1:9 --> $DIR/move_into_box_rc_arc.rs:1:9
| |
LL | #![deny(large_assignments)] LL | #![deny(large_assignments)]
| ^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^
error: moving 9999 bytes error: moving 9999 bytes
--> $DIR/box_rc_arc_allowed.rs:26:13 --> $DIR/move_into_box_rc_arc.rs:28:13
| |
LL | data, LL | data,
| ^^^^ value moved from here | ^^^^ value moved from here