large_assignments: Add copy variant of Box, Rc, Arc check
This commit is contained in:
parent
d4f6f9ee6a
commit
1a0200ebc0
33
tests/ui/lint/large_assignments/copy_into_box_rc_arc.rs
Normal file
33
tests/ui/lint/large_assignments/copy_into_box_rc_arc.rs
Normal 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,
|
||||
}
|
||||
}
|
||||
}
|
25
tests/ui/lint/large_assignments/copy_into_box_rc_arc.stderr
Normal file
25
tests/ui/lint/large_assignments/copy_into_box_rc_arc.stderr
Normal 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
|
||||
|
@ -10,6 +10,8 @@
|
||||
use std::{sync::Arc, rc::Rc};
|
||||
|
||||
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 _ = Box::new([0; 9999]); // OK!
|
||||
let _ = Rc::new([0; 9999]); // OK!
|
@ -1,18 +1,18 @@
|
||||
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]);
|
||||
| ^^^^^^^^^ 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/box_rc_arc_allowed.rs:1:9
|
||||
--> $DIR/move_into_box_rc_arc.rs:1:9
|
||||
|
|
||||
LL | #![deny(large_assignments)]
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: moving 9999 bytes
|
||||
--> $DIR/box_rc_arc_allowed.rs:26:13
|
||||
--> $DIR/move_into_box_rc_arc.rs:28:13
|
||||
|
|
||||
LL | data,
|
||||
| ^^^^ value moved from here
|
Loading…
x
Reference in New Issue
Block a user