Skip to content

Commit 1a0200e

Browse files
committed
large_assignments: Add copy variant of Box, Rc, Arc check
1 parent d4f6f9e commit 1a0200e

File tree

4 files changed

+63
-3
lines changed

4 files changed

+63
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#![deny(large_assignments)]
2+
#![feature(large_assignments)]
3+
#![move_size_limit = "1000"]
4+
// build-fail
5+
// only-x86_64
6+
7+
// edition:2018
8+
// compile-flags: -Zmir-opt-level=1
9+
10+
use std::{sync::Arc, rc::Rc};
11+
12+
fn main() {
13+
let data = [0; 9999];
14+
15+
// Looking at --emit mir, we can see that all parameters below are passed by
16+
// copy. But it requires at least mir-opt-level=1.
17+
let _ = Arc::new(data); // OK!
18+
let _ = Box::new(data); // OK!
19+
let _ = Rc::new(data); // OK!
20+
let _ = NotBox::new(data); //~ ERROR large_assignments
21+
}
22+
23+
struct NotBox {
24+
data: [u8; 9999],
25+
}
26+
27+
impl NotBox {
28+
fn new(data: [u8; 9999]) -> Self {
29+
Self { //~ ERROR large_assignments
30+
data,
31+
}
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error: moving 9999 bytes
2+
--> $DIR/copy_into_box_rc_arc.rs:20:25
3+
|
4+
LL | let _ = NotBox::new(data);
5+
| ^^^^ value moved from here
6+
|
7+
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
8+
note: the lint level is defined here
9+
--> $DIR/copy_into_box_rc_arc.rs:1:9
10+
|
11+
LL | #![deny(large_assignments)]
12+
| ^^^^^^^^^^^^^^^^^
13+
14+
error: moving 9999 bytes
15+
--> $DIR/copy_into_box_rc_arc.rs:29:9
16+
|
17+
LL | / Self {
18+
LL | | data,
19+
LL | | }
20+
| |_________^ value moved from here
21+
|
22+
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
23+
24+
error: aborting due to 2 previous errors
25+

tests/ui/lint/large_assignments/box_rc_arc_allowed.rs renamed to tests/ui/lint/large_assignments/move_into_box_rc_arc.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use std::{sync::Arc, rc::Rc};
1111

1212
fn main() {
13+
// Looking at --emit mir, we can see that all parameters below are passed
14+
// with by move.
1315
let _ = Arc::new([0; 9999]); // OK!
1416
let _ = Box::new([0; 9999]); // OK!
1517
let _ = Rc::new([0; 9999]); // OK!

tests/ui/lint/large_assignments/box_rc_arc_allowed.stderr renamed to tests/ui/lint/large_assignments/move_into_box_rc_arc.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
error: moving 9999 bytes
2-
--> $DIR/box_rc_arc_allowed.rs:16:25
2+
--> $DIR/move_into_box_rc_arc.rs:18:25
33
|
44
LL | let _ = NotBox::new([0; 9999]);
55
| ^^^^^^^^^ value moved from here
66
|
77
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
88
note: the lint level is defined here
9-
--> $DIR/box_rc_arc_allowed.rs:1:9
9+
--> $DIR/move_into_box_rc_arc.rs:1:9
1010
|
1111
LL | #![deny(large_assignments)]
1212
| ^^^^^^^^^^^^^^^^^
1313

1414
error: moving 9999 bytes
15-
--> $DIR/box_rc_arc_allowed.rs:26:13
15+
--> $DIR/move_into_box_rc_arc.rs:28:13
1616
|
1717
LL | data,
1818
| ^^^^ value moved from here

0 commit comments

Comments
 (0)