Skip to content

Commit ff23e48

Browse files
committed
Auto merge of rust-lang#108471 - clubby789:unbox-the-syntax, r=Nilstrieb,est31
Remove `box_syntax` r? `@Nilstrieb` This removes the feature `box_syntax`, which allows the use of `box <expr>` to create a Box, and finalises removing use of the feature from the compiler. `box_patterns` (allowing the use of `box <pat>` in a pattern) is unaffected. It also removes `ast::ExprKind::Box` - the only way to create a 'box' expression now is with the rustc-internal `#[rustc_box]` attribute. As a temporary measure to help users move away, `box <expr>` now parses the inner expression, and emits a `MachineApplicable` lint to replace it with `Box::new` Closes rust-lang#49733
2 parents e07c6b4 + 15f2423 commit ff23e48

10 files changed

+55
-85
lines changed

clippy_lints/src/suspicious_operation_groupings.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,7 @@ fn ident_difference_expr_with_base_location(
596596
| (MethodCall(_), MethodCall(_))
597597
| (Call(_, _), Call(_, _))
598598
| (ConstBlock(_), ConstBlock(_))
599-
| (Array(_), Array(_))
600-
| (Box(_), Box(_)) => {
599+
| (Array(_), Array(_)) => {
601600
// keep going
602601
},
603602
_ => {

clippy_utils/src/ast_utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool {
143143
(Paren(l), _) => eq_expr(l, r),
144144
(_, Paren(r)) => eq_expr(l, r),
145145
(Err, Err) => true,
146-
(Box(l), Box(r)) | (Try(l), Try(r)) | (Await(l), Await(r)) => eq_expr(l, r),
146+
(Try(l), Try(r)) | (Await(l), Await(r)) => eq_expr(l, r),
147147
(Array(l), Array(r)) => over(l, r, |l, r| eq_expr(l, r)),
148148
(Tup(l), Tup(r)) => over(l, r, |l, r| eq_expr(l, r)),
149149
(Repeat(le, ls), Repeat(re, rs)) => eq_expr(le, re) && eq_expr(&ls.value, &rs.value),

clippy_utils/src/sugg.rs

-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ impl<'a> Sugg<'a> {
188188
match expr.kind {
189189
_ if expr.span.ctxt() != ctxt => Sugg::NonParen(snippet_with_context(cx, expr.span, ctxt, default, app).0),
190190
ast::ExprKind::AddrOf(..)
191-
| ast::ExprKind::Box(..)
192191
| ast::ExprKind::Closure { .. }
193192
| ast::ExprKind::If(..)
194193
| ast::ExprKind::Let(..)

tests/ui/boxed_local.rs

+12-23
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(box_syntax)]
21
#![feature(lint_reasons)]
32
#![allow(
43
clippy::borrowed_box,
@@ -34,7 +33,7 @@ fn ok_box_trait(boxed_trait: &Box<dyn Z>) {
3433
}
3534

3635
fn warn_call() {
37-
let x = box A;
36+
let x = Box::new(A);
3837
x.foo();
3938
}
4039

@@ -43,41 +42,41 @@ fn warn_arg(x: Box<A>) {
4342
}
4443

4544
fn nowarn_closure_arg() {
46-
let x = Some(box A);
45+
let x = Some(Box::new(A));
4746
x.map_or((), |x| take_ref(&x));
4847
}
4948

5049
fn warn_rename_call() {
51-
let x = box A;
50+
let x = Box::new(A);
5251

5352
let y = x;
5453
y.foo(); // via autoderef
5554
}
5655

5756
fn warn_notuse() {
58-
let bz = box A;
57+
let bz = Box::new(A);
5958
}
6059

6160
fn warn_pass() {
62-
let bz = box A;
61+
let bz = Box::new(A);
6362
take_ref(&bz); // via deref coercion
6463
}
6564

6665
fn nowarn_return() -> Box<A> {
67-
box A // moved out, "escapes"
66+
Box::new(A) // moved out, "escapes"
6867
}
6968

7069
fn nowarn_move() {
71-
let bx = box A;
70+
let bx = Box::new(A);
7271
drop(bx) // moved in, "escapes"
7372
}
7473
fn nowarn_call() {
75-
let bx = box A;
74+
let bx = Box::new(A);
7675
bx.clone(); // method only available to Box, not via autoderef
7776
}
7877

7978
fn nowarn_pass() {
80-
let bx = box A;
79+
let bx = Box::new(A);
8180
take_box(&bx); // fn needs &Box
8281
}
8382

@@ -86,30 +85,20 @@ fn take_ref(x: &A) {}
8685

8786
fn nowarn_ref_take() {
8887
// false positive, should actually warn
89-
let x = box A;
88+
let x = Box::new(A);
9089
let y = &x;
9190
take_box(y);
9291
}
9392

9493
fn nowarn_match() {
95-
let x = box A; // moved into a match
94+
let x = Box::new(A); // moved into a match
9695
match x {
9796
y => drop(y),
9897
}
9998
}
10099

101100
fn warn_match() {
102-
let x = box A;
103-
match &x {
104-
// not moved
105-
y => (),
106-
}
107-
}
108-
109-
fn nowarn_large_array() {
110-
// should not warn, is large array
111-
// and should not be on stack
112-
let x = box [1; 10000];
101+
let x = Box::new(A);
113102
match &x {
114103
// not moved
115104
y => (),

tests/ui/boxed_local.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
error: local variable doesn't need to be boxed here
2-
--> $DIR/boxed_local.rs:41:13
2+
--> $DIR/boxed_local.rs:40:13
33
|
44
LL | fn warn_arg(x: Box<A>) {
55
| ^
66
|
77
= note: `-D clippy::boxed-local` implied by `-D warnings`
88

99
error: local variable doesn't need to be boxed here
10-
--> $DIR/boxed_local.rs:132:12
10+
--> $DIR/boxed_local.rs:121:12
1111
|
1212
LL | pub fn new(_needs_name: Box<PeekableSeekable<&()>>) -> () {}
1313
| ^^^^^^^^^^^
1414

1515
error: local variable doesn't need to be boxed here
16-
--> $DIR/boxed_local.rs:196:44
16+
--> $DIR/boxed_local.rs:185:44
1717
|
1818
LL | fn default_impl_x(self: Box<Self>, x: Box<u32>) -> u32 {
1919
| ^
2020

2121
error: local variable doesn't need to be boxed here
22-
--> $DIR/boxed_local.rs:203:16
22+
--> $DIR/boxed_local.rs:192:16
2323
|
2424
LL | fn foo(x: Box<u32>) {}
2525
| ^

tests/ui/no_effect.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(box_syntax, fn_traits, unboxed_closures)]
1+
#![feature(fn_traits, unboxed_closures)]
22
#![warn(clippy::no_effect_underscore_binding)]
33
#![allow(dead_code, path_statements)]
44
#![allow(clippy::deref_addrof, clippy::redundant_field_names, clippy::uninlined_format_args)]
@@ -102,7 +102,6 @@ fn main() {
102102
*&42;
103103
&6;
104104
(5, 6, 7);
105-
box 42;
106105
..;
107106
5..;
108107
..5;

tests/ui/no_effect.stderr

+16-22
Original file line numberDiff line numberDiff line change
@@ -81,106 +81,100 @@ LL | (5, 6, 7);
8181
error: statement with no effect
8282
--> $DIR/no_effect.rs:105:5
8383
|
84-
LL | box 42;
85-
| ^^^^^^^
86-
87-
error: statement with no effect
88-
--> $DIR/no_effect.rs:106:5
89-
|
9084
LL | ..;
9185
| ^^^
9286

9387
error: statement with no effect
94-
--> $DIR/no_effect.rs:107:5
88+
--> $DIR/no_effect.rs:106:5
9589
|
9690
LL | 5..;
9791
| ^^^^
9892

9993
error: statement with no effect
100-
--> $DIR/no_effect.rs:108:5
94+
--> $DIR/no_effect.rs:107:5
10195
|
10296
LL | ..5;
10397
| ^^^^
10498

10599
error: statement with no effect
106-
--> $DIR/no_effect.rs:109:5
100+
--> $DIR/no_effect.rs:108:5
107101
|
108102
LL | 5..6;
109103
| ^^^^^
110104

111105
error: statement with no effect
112-
--> $DIR/no_effect.rs:110:5
106+
--> $DIR/no_effect.rs:109:5
113107
|
114108
LL | 5..=6;
115109
| ^^^^^^
116110

117111
error: statement with no effect
118-
--> $DIR/no_effect.rs:111:5
112+
--> $DIR/no_effect.rs:110:5
119113
|
120114
LL | [42, 55];
121115
| ^^^^^^^^^
122116

123117
error: statement with no effect
124-
--> $DIR/no_effect.rs:112:5
118+
--> $DIR/no_effect.rs:111:5
125119
|
126120
LL | [42, 55][1];
127121
| ^^^^^^^^^^^^
128122

129123
error: statement with no effect
130-
--> $DIR/no_effect.rs:113:5
124+
--> $DIR/no_effect.rs:112:5
131125
|
132126
LL | (42, 55).1;
133127
| ^^^^^^^^^^^
134128

135129
error: statement with no effect
136-
--> $DIR/no_effect.rs:114:5
130+
--> $DIR/no_effect.rs:113:5
137131
|
138132
LL | [42; 55];
139133
| ^^^^^^^^^
140134

141135
error: statement with no effect
142-
--> $DIR/no_effect.rs:115:5
136+
--> $DIR/no_effect.rs:114:5
143137
|
144138
LL | [42; 55][13];
145139
| ^^^^^^^^^^^^^
146140

147141
error: statement with no effect
148-
--> $DIR/no_effect.rs:117:5
142+
--> $DIR/no_effect.rs:116:5
149143
|
150144
LL | || x += 5;
151145
| ^^^^^^^^^^
152146

153147
error: statement with no effect
154-
--> $DIR/no_effect.rs:119:5
148+
--> $DIR/no_effect.rs:118:5
155149
|
156150
LL | FooString { s: s };
157151
| ^^^^^^^^^^^^^^^^^^^
158152

159153
error: binding to `_` prefixed variable with no side-effect
160-
--> $DIR/no_effect.rs:120:5
154+
--> $DIR/no_effect.rs:119:5
161155
|
162156
LL | let _unused = 1;
163157
| ^^^^^^^^^^^^^^^^
164158
|
165159
= note: `-D clippy::no-effect-underscore-binding` implied by `-D warnings`
166160

167161
error: binding to `_` prefixed variable with no side-effect
168-
--> $DIR/no_effect.rs:121:5
162+
--> $DIR/no_effect.rs:120:5
169163
|
170164
LL | let _penguin = || println!("Some helpful closure");
171165
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
172166

173167
error: binding to `_` prefixed variable with no side-effect
174-
--> $DIR/no_effect.rs:122:5
168+
--> $DIR/no_effect.rs:121:5
175169
|
176170
LL | let _duck = Struct { field: 0 };
177171
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
178172

179173
error: binding to `_` prefixed variable with no side-effect
180-
--> $DIR/no_effect.rs:123:5
174+
--> $DIR/no_effect.rs:122:5
181175
|
182176
LL | let _cat = [2, 4, 6, 8][2];
183177
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
184178

185-
error: aborting due to 30 previous errors
179+
error: aborting due to 29 previous errors
186180

tests/ui/unnecessary_operation.fixed

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// run-rustfix
22

3-
#![feature(box_syntax)]
43
#![allow(clippy::deref_addrof, dead_code, unused, clippy::no_effect)]
54
#![warn(clippy::unnecessary_operation)]
65

@@ -59,7 +58,6 @@ fn main() {
5958
5;6;get_number();
6059
get_number();
6160
get_number();
62-
get_number();
6361
5;get_number();
6462
42;get_number();
6563
assert!([42, 55].len() > get_usize());

tests/ui/unnecessary_operation.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// run-rustfix
22

3-
#![feature(box_syntax)]
43
#![allow(clippy::deref_addrof, dead_code, unused, clippy::no_effect)]
54
#![warn(clippy::unnecessary_operation)]
65

@@ -57,7 +56,6 @@ fn main() {
5756
*&get_number();
5857
&get_number();
5958
(5, 6, get_number());
60-
box get_number();
6159
get_number()..;
6260
..get_number();
6361
5..get_number();

0 commit comments

Comments
 (0)