Auto merge of #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 #49733
This commit is contained in:
commit
ff23e48c30
@ -596,8 +596,7 @@ fn ident_difference_expr_with_base_location(
|
||||
| (MethodCall(_), MethodCall(_))
|
||||
| (Call(_, _), Call(_, _))
|
||||
| (ConstBlock(_), ConstBlock(_))
|
||||
| (Array(_), Array(_))
|
||||
| (Box(_), Box(_)) => {
|
||||
| (Array(_), Array(_)) => {
|
||||
// keep going
|
||||
},
|
||||
_ => {
|
||||
|
@ -143,7 +143,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool {
|
||||
(Paren(l), _) => eq_expr(l, r),
|
||||
(_, Paren(r)) => eq_expr(l, r),
|
||||
(Err, Err) => true,
|
||||
(Box(l), Box(r)) | (Try(l), Try(r)) | (Await(l), Await(r)) => eq_expr(l, r),
|
||||
(Try(l), Try(r)) | (Await(l), Await(r)) => eq_expr(l, r),
|
||||
(Array(l), Array(r)) => over(l, r, |l, r| eq_expr(l, r)),
|
||||
(Tup(l), Tup(r)) => over(l, r, |l, r| eq_expr(l, r)),
|
||||
(Repeat(le, ls), Repeat(re, rs)) => eq_expr(le, re) && eq_expr(&ls.value, &rs.value),
|
||||
|
@ -188,7 +188,6 @@ impl<'a> Sugg<'a> {
|
||||
match expr.kind {
|
||||
_ if expr.span.ctxt() != ctxt => Sugg::NonParen(snippet_with_context(cx, expr.span, ctxt, default, app).0),
|
||||
ast::ExprKind::AddrOf(..)
|
||||
| ast::ExprKind::Box(..)
|
||||
| ast::ExprKind::Closure { .. }
|
||||
| ast::ExprKind::If(..)
|
||||
| ast::ExprKind::Let(..)
|
||||
|
@ -1,4 +1,3 @@
|
||||
#![feature(box_syntax)]
|
||||
#![feature(lint_reasons)]
|
||||
#![allow(
|
||||
clippy::borrowed_box,
|
||||
@ -34,7 +33,7 @@ fn ok_box_trait(boxed_trait: &Box<dyn Z>) {
|
||||
}
|
||||
|
||||
fn warn_call() {
|
||||
let x = box A;
|
||||
let x = Box::new(A);
|
||||
x.foo();
|
||||
}
|
||||
|
||||
@ -43,41 +42,41 @@ fn warn_arg(x: Box<A>) {
|
||||
}
|
||||
|
||||
fn nowarn_closure_arg() {
|
||||
let x = Some(box A);
|
||||
let x = Some(Box::new(A));
|
||||
x.map_or((), |x| take_ref(&x));
|
||||
}
|
||||
|
||||
fn warn_rename_call() {
|
||||
let x = box A;
|
||||
let x = Box::new(A);
|
||||
|
||||
let y = x;
|
||||
y.foo(); // via autoderef
|
||||
}
|
||||
|
||||
fn warn_notuse() {
|
||||
let bz = box A;
|
||||
let bz = Box::new(A);
|
||||
}
|
||||
|
||||
fn warn_pass() {
|
||||
let bz = box A;
|
||||
let bz = Box::new(A);
|
||||
take_ref(&bz); // via deref coercion
|
||||
}
|
||||
|
||||
fn nowarn_return() -> Box<A> {
|
||||
box A // moved out, "escapes"
|
||||
Box::new(A) // moved out, "escapes"
|
||||
}
|
||||
|
||||
fn nowarn_move() {
|
||||
let bx = box A;
|
||||
let bx = Box::new(A);
|
||||
drop(bx) // moved in, "escapes"
|
||||
}
|
||||
fn nowarn_call() {
|
||||
let bx = box A;
|
||||
let bx = Box::new(A);
|
||||
bx.clone(); // method only available to Box, not via autoderef
|
||||
}
|
||||
|
||||
fn nowarn_pass() {
|
||||
let bx = box A;
|
||||
let bx = Box::new(A);
|
||||
take_box(&bx); // fn needs &Box
|
||||
}
|
||||
|
||||
@ -86,30 +85,20 @@ fn take_ref(x: &A) {}
|
||||
|
||||
fn nowarn_ref_take() {
|
||||
// false positive, should actually warn
|
||||
let x = box A;
|
||||
let x = Box::new(A);
|
||||
let y = &x;
|
||||
take_box(y);
|
||||
}
|
||||
|
||||
fn nowarn_match() {
|
||||
let x = box A; // moved into a match
|
||||
let x = Box::new(A); // moved into a match
|
||||
match x {
|
||||
y => drop(y),
|
||||
}
|
||||
}
|
||||
|
||||
fn warn_match() {
|
||||
let x = box A;
|
||||
match &x {
|
||||
// not moved
|
||||
y => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn nowarn_large_array() {
|
||||
// should not warn, is large array
|
||||
// and should not be on stack
|
||||
let x = box [1; 10000];
|
||||
let x = Box::new(A);
|
||||
match &x {
|
||||
// not moved
|
||||
y => (),
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: local variable doesn't need to be boxed here
|
||||
--> $DIR/boxed_local.rs:41:13
|
||||
--> $DIR/boxed_local.rs:40:13
|
||||
|
|
||||
LL | fn warn_arg(x: Box<A>) {
|
||||
| ^
|
||||
@ -7,19 +7,19 @@ LL | fn warn_arg(x: Box<A>) {
|
||||
= note: `-D clippy::boxed-local` implied by `-D warnings`
|
||||
|
||||
error: local variable doesn't need to be boxed here
|
||||
--> $DIR/boxed_local.rs:132:12
|
||||
--> $DIR/boxed_local.rs:121:12
|
||||
|
|
||||
LL | pub fn new(_needs_name: Box<PeekableSeekable<&()>>) -> () {}
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: local variable doesn't need to be boxed here
|
||||
--> $DIR/boxed_local.rs:196:44
|
||||
--> $DIR/boxed_local.rs:185:44
|
||||
|
|
||||
LL | fn default_impl_x(self: Box<Self>, x: Box<u32>) -> u32 {
|
||||
| ^
|
||||
|
||||
error: local variable doesn't need to be boxed here
|
||||
--> $DIR/boxed_local.rs:203:16
|
||||
--> $DIR/boxed_local.rs:192:16
|
||||
|
|
||||
LL | fn foo(x: Box<u32>) {}
|
||||
| ^
|
||||
|
@ -1,4 +1,4 @@
|
||||
#![feature(box_syntax, fn_traits, unboxed_closures)]
|
||||
#![feature(fn_traits, unboxed_closures)]
|
||||
#![warn(clippy::no_effect_underscore_binding)]
|
||||
#![allow(dead_code, path_statements)]
|
||||
#![allow(clippy::deref_addrof, clippy::redundant_field_names, clippy::uninlined_format_args)]
|
||||
@ -102,7 +102,6 @@ fn main() {
|
||||
*&42;
|
||||
&6;
|
||||
(5, 6, 7);
|
||||
box 42;
|
||||
..;
|
||||
5..;
|
||||
..5;
|
||||
|
@ -81,83 +81,77 @@ LL | (5, 6, 7);
|
||||
error: statement with no effect
|
||||
--> $DIR/no_effect.rs:105:5
|
||||
|
|
||||
LL | box 42;
|
||||
| ^^^^^^^
|
||||
|
||||
error: statement with no effect
|
||||
--> $DIR/no_effect.rs:106:5
|
||||
|
|
||||
LL | ..;
|
||||
| ^^^
|
||||
|
||||
error: statement with no effect
|
||||
--> $DIR/no_effect.rs:107:5
|
||||
--> $DIR/no_effect.rs:106:5
|
||||
|
|
||||
LL | 5..;
|
||||
| ^^^^
|
||||
|
||||
error: statement with no effect
|
||||
--> $DIR/no_effect.rs:108:5
|
||||
--> $DIR/no_effect.rs:107:5
|
||||
|
|
||||
LL | ..5;
|
||||
| ^^^^
|
||||
|
||||
error: statement with no effect
|
||||
--> $DIR/no_effect.rs:109:5
|
||||
--> $DIR/no_effect.rs:108:5
|
||||
|
|
||||
LL | 5..6;
|
||||
| ^^^^^
|
||||
|
||||
error: statement with no effect
|
||||
--> $DIR/no_effect.rs:110:5
|
||||
--> $DIR/no_effect.rs:109:5
|
||||
|
|
||||
LL | 5..=6;
|
||||
| ^^^^^^
|
||||
|
||||
error: statement with no effect
|
||||
--> $DIR/no_effect.rs:111:5
|
||||
--> $DIR/no_effect.rs:110:5
|
||||
|
|
||||
LL | [42, 55];
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: statement with no effect
|
||||
--> $DIR/no_effect.rs:112:5
|
||||
--> $DIR/no_effect.rs:111:5
|
||||
|
|
||||
LL | [42, 55][1];
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: statement with no effect
|
||||
--> $DIR/no_effect.rs:113:5
|
||||
--> $DIR/no_effect.rs:112:5
|
||||
|
|
||||
LL | (42, 55).1;
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: statement with no effect
|
||||
--> $DIR/no_effect.rs:114:5
|
||||
--> $DIR/no_effect.rs:113:5
|
||||
|
|
||||
LL | [42; 55];
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: statement with no effect
|
||||
--> $DIR/no_effect.rs:115:5
|
||||
--> $DIR/no_effect.rs:114:5
|
||||
|
|
||||
LL | [42; 55][13];
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: statement with no effect
|
||||
--> $DIR/no_effect.rs:117:5
|
||||
--> $DIR/no_effect.rs:116:5
|
||||
|
|
||||
LL | || x += 5;
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: statement with no effect
|
||||
--> $DIR/no_effect.rs:119:5
|
||||
--> $DIR/no_effect.rs:118:5
|
||||
|
|
||||
LL | FooString { s: s };
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: binding to `_` prefixed variable with no side-effect
|
||||
--> $DIR/no_effect.rs:120:5
|
||||
--> $DIR/no_effect.rs:119:5
|
||||
|
|
||||
LL | let _unused = 1;
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
@ -165,22 +159,22 @@ LL | let _unused = 1;
|
||||
= note: `-D clippy::no-effect-underscore-binding` implied by `-D warnings`
|
||||
|
||||
error: binding to `_` prefixed variable with no side-effect
|
||||
--> $DIR/no_effect.rs:121:5
|
||||
--> $DIR/no_effect.rs:120:5
|
||||
|
|
||||
LL | let _penguin = || println!("Some helpful closure");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: binding to `_` prefixed variable with no side-effect
|
||||
--> $DIR/no_effect.rs:122:5
|
||||
--> $DIR/no_effect.rs:121:5
|
||||
|
|
||||
LL | let _duck = Struct { field: 0 };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: binding to `_` prefixed variable with no side-effect
|
||||
--> $DIR/no_effect.rs:123:5
|
||||
--> $DIR/no_effect.rs:122:5
|
||||
|
|
||||
LL | let _cat = [2, 4, 6, 8][2];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 30 previous errors
|
||||
error: aborting due to 29 previous errors
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
// run-rustfix
|
||||
|
||||
#![feature(box_syntax)]
|
||||
#![allow(clippy::deref_addrof, dead_code, unused, clippy::no_effect)]
|
||||
#![warn(clippy::unnecessary_operation)]
|
||||
|
||||
@ -59,7 +58,6 @@ fn main() {
|
||||
5;6;get_number();
|
||||
get_number();
|
||||
get_number();
|
||||
get_number();
|
||||
5;get_number();
|
||||
42;get_number();
|
||||
assert!([42, 55].len() > get_usize());
|
||||
|
@ -1,6 +1,5 @@
|
||||
// run-rustfix
|
||||
|
||||
#![feature(box_syntax)]
|
||||
#![allow(clippy::deref_addrof, dead_code, unused, clippy::no_effect)]
|
||||
#![warn(clippy::unnecessary_operation)]
|
||||
|
||||
@ -57,7 +56,6 @@ fn main() {
|
||||
*&get_number();
|
||||
&get_number();
|
||||
(5, 6, get_number());
|
||||
box get_number();
|
||||
get_number()..;
|
||||
..get_number();
|
||||
5..get_number();
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: unnecessary operation
|
||||
--> $DIR/unnecessary_operation.rs:51:5
|
||||
--> $DIR/unnecessary_operation.rs:50:5
|
||||
|
|
||||
LL | Tuple(get_number());
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();`
|
||||
@ -7,109 +7,103 @@ LL | Tuple(get_number());
|
||||
= note: `-D clippy::unnecessary-operation` implied by `-D warnings`
|
||||
|
||||
error: unnecessary operation
|
||||
--> $DIR/unnecessary_operation.rs:52:5
|
||||
--> $DIR/unnecessary_operation.rs:51:5
|
||||
|
|
||||
LL | Struct { field: get_number() };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();`
|
||||
|
||||
error: unnecessary operation
|
||||
--> $DIR/unnecessary_operation.rs:53:5
|
||||
--> $DIR/unnecessary_operation.rs:52:5
|
||||
|
|
||||
LL | Struct { ..get_struct() };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_struct();`
|
||||
|
||||
error: unnecessary operation
|
||||
--> $DIR/unnecessary_operation.rs:54:5
|
||||
--> $DIR/unnecessary_operation.rs:53:5
|
||||
|
|
||||
LL | Enum::Tuple(get_number());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();`
|
||||
|
||||
error: unnecessary operation
|
||||
--> $DIR/unnecessary_operation.rs:55:5
|
||||
--> $DIR/unnecessary_operation.rs:54:5
|
||||
|
|
||||
LL | Enum::Struct { field: get_number() };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();`
|
||||
|
||||
error: unnecessary operation
|
||||
--> $DIR/unnecessary_operation.rs:56:5
|
||||
--> $DIR/unnecessary_operation.rs:55:5
|
||||
|
|
||||
LL | 5 + get_number();
|
||||
| ^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `5;get_number();`
|
||||
|
||||
error: unnecessary operation
|
||||
--> $DIR/unnecessary_operation.rs:57:5
|
||||
--> $DIR/unnecessary_operation.rs:56:5
|
||||
|
|
||||
LL | *&get_number();
|
||||
| ^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();`
|
||||
|
||||
error: unnecessary operation
|
||||
--> $DIR/unnecessary_operation.rs:58:5
|
||||
--> $DIR/unnecessary_operation.rs:57:5
|
||||
|
|
||||
LL | &get_number();
|
||||
| ^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();`
|
||||
|
||||
error: unnecessary operation
|
||||
--> $DIR/unnecessary_operation.rs:59:5
|
||||
--> $DIR/unnecessary_operation.rs:58:5
|
||||
|
|
||||
LL | (5, 6, get_number());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `5;6;get_number();`
|
||||
|
||||
error: unnecessary operation
|
||||
--> $DIR/unnecessary_operation.rs:60:5
|
||||
|
|
||||
LL | box get_number();
|
||||
| ^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();`
|
||||
|
||||
error: unnecessary operation
|
||||
--> $DIR/unnecessary_operation.rs:61:5
|
||||
--> $DIR/unnecessary_operation.rs:59:5
|
||||
|
|
||||
LL | get_number()..;
|
||||
| ^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();`
|
||||
|
||||
error: unnecessary operation
|
||||
--> $DIR/unnecessary_operation.rs:62:5
|
||||
--> $DIR/unnecessary_operation.rs:60:5
|
||||
|
|
||||
LL | ..get_number();
|
||||
| ^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();`
|
||||
|
||||
error: unnecessary operation
|
||||
--> $DIR/unnecessary_operation.rs:63:5
|
||||
--> $DIR/unnecessary_operation.rs:61:5
|
||||
|
|
||||
LL | 5..get_number();
|
||||
| ^^^^^^^^^^^^^^^^ help: statement can be reduced to: `5;get_number();`
|
||||
|
||||
error: unnecessary operation
|
||||
--> $DIR/unnecessary_operation.rs:64:5
|
||||
--> $DIR/unnecessary_operation.rs:62:5
|
||||
|
|
||||
LL | [42, get_number()];
|
||||
| ^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `42;get_number();`
|
||||
|
||||
error: unnecessary operation
|
||||
--> $DIR/unnecessary_operation.rs:65:5
|
||||
--> $DIR/unnecessary_operation.rs:63:5
|
||||
|
|
||||
LL | [42, 55][get_usize()];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: statement can be written as: `assert!([42, 55].len() > get_usize());`
|
||||
|
||||
error: unnecessary operation
|
||||
--> $DIR/unnecessary_operation.rs:66:5
|
||||
--> $DIR/unnecessary_operation.rs:64:5
|
||||
|
|
||||
LL | (42, get_number()).1;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `42;get_number();`
|
||||
|
||||
error: unnecessary operation
|
||||
--> $DIR/unnecessary_operation.rs:67:5
|
||||
--> $DIR/unnecessary_operation.rs:65:5
|
||||
|
|
||||
LL | [get_number(); 55];
|
||||
| ^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();`
|
||||
|
||||
error: unnecessary operation
|
||||
--> $DIR/unnecessary_operation.rs:68:5
|
||||
--> $DIR/unnecessary_operation.rs:66:5
|
||||
|
|
||||
LL | [42; 55][get_usize()];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: statement can be written as: `assert!([42; 55].len() > get_usize());`
|
||||
|
||||
error: unnecessary operation
|
||||
--> $DIR/unnecessary_operation.rs:69:5
|
||||
--> $DIR/unnecessary_operation.rs:67:5
|
||||
|
|
||||
LL | / {
|
||||
LL | | get_number()
|
||||
@ -117,12 +111,12 @@ LL | | };
|
||||
| |______^ help: statement can be reduced to: `get_number();`
|
||||
|
||||
error: unnecessary operation
|
||||
--> $DIR/unnecessary_operation.rs:72:5
|
||||
--> $DIR/unnecessary_operation.rs:70:5
|
||||
|
|
||||
LL | / FooString {
|
||||
LL | | s: String::from("blah"),
|
||||
LL | | };
|
||||
| |______^ help: statement can be reduced to: `String::from("blah");`
|
||||
|
||||
error: aborting due to 20 previous errors
|
||||
error: aborting due to 19 previous errors
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user