Skip to content

Commit

Permalink
Rollup merge of rust-lang#90521 - jhpratt:stabilize-destructuring_ass…
Browse files Browse the repository at this point in the history
…ignment, r=jackh726,pnkfelix

Stabilize `destructuring_assignment`

Closes rust-lang#71126

- [Stabilization report](rust-lang#71126 (comment))
- [Completed FCP](rust-lang#71126 (comment))

`@rustbot` label +F-destructuring-assignment +T-lang
Also needs +relnotes but I don't have permission to add that tag.
  • Loading branch information
matthiaskrgr committed Dec 14, 2021
2 parents a2d25b4 + a3d1edb commit 672f836
Show file tree
Hide file tree
Showing 48 changed files with 62 additions and 370 deletions.
19 changes: 0 additions & 19 deletions compiler/rustc_ast_lowering/src/expr.rs
Expand Up @@ -9,7 +9,6 @@ use rustc_errors::struct_span_err;
use rustc_hir as hir;
use rustc_hir::def::Res;
use rustc_hir::definitions::DefPathData;
use rustc_session::parse::feature_err;
use rustc_span::hygiene::ExpnId;
use rustc_span::source_map::{respan, DesugaringKind, Span, Spanned};
use rustc_span::symbol::{sym, Ident, Symbol};
Expand Down Expand Up @@ -930,24 +929,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
self.lower_span(eq_sign_span),
);
}
if !self.sess.features_untracked().destructuring_assignment {
let mut err = feature_err(
&self.sess.parse_sess,
sym::destructuring_assignment,
eq_sign_span,
"destructuring assignments are unstable",
);
err.span_label(lhs.span, "cannot assign to this expression");
if self.is_in_loop_condition {
err.span_suggestion_verbose(
lhs.span.shrink_to_lo(),
"you might have meant to use pattern destructuring",
"let ".to_string(),
rustc_errors::Applicability::MachineApplicable,
);
}
err.emit();
}

let mut assignments = vec![];

Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Expand Up @@ -724,11 +724,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
gate_all!(half_open_range_patterns, "half-open range patterns are unstable");
gate_all!(inline_const, "inline-const is experimental");
gate_all!(inline_const_pat, "inline-const in pattern position is experimental");
if sess.parse_sess.span_diagnostic.err_count() == 0 {
// Errors for `destructuring_assignment` can get quite noisy, especially where `_` is
// involved, so we only emit errors where there are no other parsing errors.
gate_all!(destructuring_assignment, "destructuring assignments are unstable");
}

// All uses of `gate_all!` below this point were added in #65742,
// and subsequently disabled (with the non-early gating readded).
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/lib.rs
@@ -1,6 +1,6 @@
#![feature(crate_visibility_modifier)]
#![feature(decl_macro)]
#![feature(destructuring_assignment)]
#![cfg_attr(bootstrap, feature(destructuring_assignment))]
#![feature(if_let_guard)]
#![feature(iter_zip)]
#![feature(let_else)]
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/accepted.rs
Expand Up @@ -114,6 +114,8 @@ declare_features! (
(accepted, default_type_params, "1.0.0", None, None),
/// Allows `#[deprecated]` attribute.
(accepted, deprecated, "1.9.0", Some(29935), None),
/// Allows the use of destructuring assignments.
(accepted, destructuring_assignment, "1.59.0", Some(71126), None),
/// Allows `#[doc(alias = "...")]`.
(accepted, doc_alias, "1.48.0", Some(50146), None),
/// Allows `..` in tuple (struct) patterns.
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/active.rs
Expand Up @@ -356,8 +356,6 @@ declare_features! (
(active, default_type_parameter_fallback, "1.3.0", Some(27336), None),
/// Allows `#[derive(Default)]` and `#[default]` on enums.
(active, derive_default_enum, "1.56.0", Some(86985), None),
/// Allows the use of destructuring assignments.
(active, destructuring_assignment, "1.49.0", Some(71126), None),
/// Tells rustdoc to automatically generate `#[doc(cfg(...))]`.
(active, doc_auto_cfg, "1.58.0", Some(43781), None),
/// Allows `#[doc(cfg(...))]`.
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_parse/src/parser/expr.rs
Expand Up @@ -1265,7 +1265,6 @@ impl<'a> Parser<'a> {
} else if self.eat_keyword(kw::Let) {
self.parse_let_expr(attrs)
} else if self.eat_keyword(kw::Underscore) {
self.sess.gated_spans.gate(sym::destructuring_assignment, self.prev_token.span);
Ok(self.mk_expr(self.prev_token.span, ExprKind::Underscore, attrs))
} else if !self.unclosed_delims.is_empty() && self.check(&token::Semi) {
// Don't complain about bare semicolons after unclosed braces
Expand Down Expand Up @@ -2588,7 +2587,6 @@ impl<'a> Parser<'a> {
let exp_span = self.prev_token.span;
// We permit `.. }` on the left-hand side of a destructuring assignment.
if self.check(&token::CloseDelim(close_delim)) {
self.sess.gated_spans.gate(sym::destructuring_assignment, self.prev_token.span);
base = ast::StructRest::Rest(self.prev_token.span.shrink_to_hi());
break;
}
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_typeck/src/check/expr.rs
Expand Up @@ -877,11 +877,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
"let ".to_string(),
Applicability::MachineApplicable,
);
if !self.sess().features_untracked().destructuring_assignment {
// We already emit an E0658 with a suggestion for `while let`, this is
// redundant output.
err.delay_as_bug();
}
break;
}
hir::Node::Item(_)
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/lib.rs
Expand Up @@ -137,7 +137,7 @@
#![feature(cfg_target_has_atomic)]
#![feature(const_fn_trait_bound)]
#![feature(const_trait_impl)]
#![feature(destructuring_assignment)]
#![cfg_attr(bootstrap, feature(destructuring_assignment))]
#![feature(dropck_eyepatch)]
#![feature(exclusive_range_pattern)]
#![feature(fundamental)]
Expand Down
@@ -1,6 +1,5 @@
// check-pass

#![feature(destructuring_assignment)]
#![feature(more_qualified_paths)]

enum E { V() }
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/cross/cross-file-errors/main.rs
Expand Up @@ -4,5 +4,4 @@ mod underscore;
fn main() {
underscore!();
//~^ ERROR `_` can only be used on the left-hand side of an assignment
//~| ERROR destructuring assignments are unstable
}
18 changes: 1 addition & 17 deletions src/test/ui/cross/cross-file-errors/main.stderr
@@ -1,18 +1,3 @@
error[E0658]: destructuring assignments are unstable
--> $DIR/underscore.rs:8:9
|
LL | _
| ^
|
::: $DIR/main.rs:5:5
|
LL | underscore!();
| ------------- in this macro invocation
|
= note: see issue #71126 <https://github.com/rust-lang/rust/issues/71126> for more information
= help: add `#![feature(destructuring_assignment)]` to the crate attributes to enable
= note: this error originates in the macro `underscore` (in Nightly builds, run with -Z macro-backtrace for more info)

error: in expressions, `_` can only be used on the left-hand side of an assignment
--> $DIR/underscore.rs:8:9
|
Expand All @@ -26,6 +11,5 @@ LL | underscore!();
|
= note: this error originates in the macro `underscore` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 2 previous errors
error: aborting due to previous error

For more information about this error, try `rustc --explain E0658`.
7 changes: 2 additions & 5 deletions src/test/ui/destructuring-assignment/bad-expr-lhs.rs
@@ -1,12 +1,9 @@
fn main() {
1 = 2; //~ ERROR invalid left-hand side of assignment
1 += 2; //~ ERROR invalid left-hand side of assignment
(1, 2) = (3, 4); //~ ERROR destructuring assignments are unstable
(1, 2) = (3, 4);
//~^ ERROR invalid left-hand side of assignment
//~| ERROR invalid left-hand side of assignment
//~| ERROR invalid left-hand side of assignment

let (a, b) = (1, 2);
(a, b) = (3, 4); //~ ERROR destructuring assignments are unstable

None = Some(3); //~ ERROR invalid left-hand side of assignment
}
28 changes: 3 additions & 25 deletions src/test/ui/destructuring-assignment/bad-expr-lhs.stderr
@@ -1,25 +1,3 @@
error[E0658]: destructuring assignments are unstable
--> $DIR/bad-expr-lhs.rs:4:12
|
LL | (1, 2) = (3, 4);
| ------ ^
| |
| cannot assign to this expression
|
= note: see issue #71126 <https://github.com/rust-lang/rust/issues/71126> for more information
= help: add `#![feature(destructuring_assignment)]` to the crate attributes to enable

error[E0658]: destructuring assignments are unstable
--> $DIR/bad-expr-lhs.rs:9:12
|
LL | (a, b) = (3, 4);
| ------ ^
| |
| cannot assign to this expression
|
= note: see issue #71126 <https://github.com/rust-lang/rust/issues/71126> for more information
= help: add `#![feature(destructuring_assignment)]` to the crate attributes to enable

error[E0070]: invalid left-hand side of assignment
--> $DIR/bad-expr-lhs.rs:2:7
|
Expand Down Expand Up @@ -53,14 +31,14 @@ LL | (1, 2) = (3, 4);
| cannot assign to this expression

error[E0070]: invalid left-hand side of assignment
--> $DIR/bad-expr-lhs.rs:11:10
--> $DIR/bad-expr-lhs.rs:8:10
|
LL | None = Some(3);
| ---- ^
| |
| cannot assign to this expression

error: aborting due to 7 previous errors
error: aborting due to 5 previous errors

Some errors have detailed explanations: E0067, E0070, E0658.
Some errors have detailed explanations: E0067, E0070.
For more information about an error, try `rustc --explain E0067`.
@@ -1,5 +1,3 @@
#![feature(destructuring_assignment)]

fn main() {
let mut x = &0;
let mut y = &0;
Expand Down
@@ -1,5 +1,5 @@
error[E0308]: mismatched types
--> $DIR/default-match-bindings-forbidden.rs:6:5
--> $DIR/default-match-bindings-forbidden.rs:4:5
|
LL | (x, y) = &(1, 2);
| ^^^^^^ ------- this expression has type `&({integer}, {integer})`
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/destructuring-assignment/drop-order.rs
Expand Up @@ -2,7 +2,6 @@

//! Test that let bindings and destructuring assignments have consistent drop orders

#![feature(destructuring_assignment)]
#![allow(unused_variables, unused_assignments)]

use std::cell::RefCell;
Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/destructuring-assignment/nested_destructure.rs
@@ -1,7 +1,5 @@
// run-pass

#![feature(destructuring_assignment)]

struct Struct<S, T> {
a: S,
b: T,
Expand Down
11 changes: 3 additions & 8 deletions src/test/ui/destructuring-assignment/note-unsupported.rs
Expand Up @@ -3,25 +3,20 @@ struct S { x: u8, y: u8 }
fn main() {
let (a, b) = (1, 2);

(a, b) = (3, 4); //~ ERROR destructuring assignments are unstable
(a, b) = (3, 4);
(a, b) += (3, 4); //~ ERROR invalid left-hand side of assignment
//~| ERROR binary assignment operation `+=` cannot be applied

[a, b] = [3, 4]; //~ ERROR destructuring assignments are unstable
[a, b] = [3, 4];
[a, b] += [3, 4]; //~ ERROR invalid left-hand side of assignment
//~| ERROR binary assignment operation `+=` cannot be applied

let s = S { x: 3, y: 4 };

S { x: a, y: b } = s; //~ ERROR destructuring assignments are unstable
S { x: a, y: b } = s;
S { x: a, y: b } += s; //~ ERROR invalid left-hand side of assignment
//~| ERROR binary assignment operation `+=` cannot be applied

S { x: a, ..s } = S { x: 3, y: 4 };
//~^ ERROR functional record updates are not allowed in destructuring assignments
//~| ERROR destructuring assignments are unstable

let c = 3;

((a, b), c) = ((3, 4), 5); //~ ERROR destructuring assignments are unstable
}
59 changes: 2 additions & 57 deletions src/test/ui/destructuring-assignment/note-unsupported.stderr
@@ -1,64 +1,9 @@
error[E0658]: destructuring assignments are unstable
--> $DIR/note-unsupported.rs:6:12
|
LL | (a, b) = (3, 4);
| ------ ^
| |
| cannot assign to this expression
|
= note: see issue #71126 <https://github.com/rust-lang/rust/issues/71126> for more information
= help: add `#![feature(destructuring_assignment)]` to the crate attributes to enable

error[E0658]: destructuring assignments are unstable
--> $DIR/note-unsupported.rs:10:12
|
LL | [a, b] = [3, 4];
| ------ ^
| |
| cannot assign to this expression
|
= note: see issue #71126 <https://github.com/rust-lang/rust/issues/71126> for more information
= help: add `#![feature(destructuring_assignment)]` to the crate attributes to enable

error[E0658]: destructuring assignments are unstable
--> $DIR/note-unsupported.rs:16:22
|
LL | S { x: a, y: b } = s;
| ---------------- ^
| |
| cannot assign to this expression
|
= note: see issue #71126 <https://github.com/rust-lang/rust/issues/71126> for more information
= help: add `#![feature(destructuring_assignment)]` to the crate attributes to enable

error[E0658]: destructuring assignments are unstable
--> $DIR/note-unsupported.rs:20:21
|
LL | S { x: a, ..s } = S { x: 3, y: 4 };
| --------------- ^
| |
| cannot assign to this expression
|
= note: see issue #71126 <https://github.com/rust-lang/rust/issues/71126> for more information
= help: add `#![feature(destructuring_assignment)]` to the crate attributes to enable

error: functional record updates are not allowed in destructuring assignments
--> $DIR/note-unsupported.rs:20:17
|
LL | S { x: a, ..s } = S { x: 3, y: 4 };
| ^ help: consider removing the trailing pattern

error[E0658]: destructuring assignments are unstable
--> $DIR/note-unsupported.rs:26:17
|
LL | ((a, b), c) = ((3, 4), 5);
| ----------- ^
| |
| cannot assign to this expression
|
= note: see issue #71126 <https://github.com/rust-lang/rust/issues/71126> for more information
= help: add `#![feature(destructuring_assignment)]` to the crate attributes to enable

error[E0368]: binary assignment operation `+=` cannot be applied to type `({integer}, {integer})`
--> $DIR/note-unsupported.rs:7:5
|
Expand Down Expand Up @@ -124,7 +69,7 @@ LL | S { x: a, y: b } += s;
| |
| cannot assign to this expression

error: aborting due to 12 previous errors
error: aborting due to 7 previous errors

Some errors have detailed explanations: E0067, E0368, E0658.
Some errors have detailed explanations: E0067, E0368.
For more information about an error, try `rustc --explain E0067`.
2 changes: 0 additions & 2 deletions src/test/ui/destructuring-assignment/slice_destructure.rs
@@ -1,7 +1,5 @@
// run-pass

#![feature(destructuring_assignment)]

fn main() {
let (mut a, mut b);
[a, b] = [0, 1];
Expand Down
@@ -1,5 +1,3 @@
#![feature(destructuring_assignment)]

fn main() {
let (mut a, mut b);
[a, .., b, ..] = [0, 1]; //~ ERROR `..` can only be used once per slice pattern
Expand Down
@@ -1,19 +1,19 @@
error: `..` can only be used once per slice pattern
--> $DIR/slice_destructure_fail.rs:5:14
--> $DIR/slice_destructure_fail.rs:3:14
|
LL | [a, .., b, ..] = [0, 1];
| -- ^^ can only be used once per slice pattern
| |
| previously used here

error[E0527]: pattern requires 3 elements but array has 2
--> $DIR/slice_destructure_fail.rs:6:3
--> $DIR/slice_destructure_fail.rs:4:3
|
LL | [a, a, b] = [1, 2];
| ^^^^^^^^^ expected 2 elements

error[E0527]: pattern requires 1 element but array has 2
--> $DIR/slice_destructure_fail.rs:7:3
--> $DIR/slice_destructure_fail.rs:5:3
|
LL | [_] = [1, 2];
| ^^^ expected 2 elements
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/destructuring-assignment/struct_destructure.rs
@@ -1,6 +1,5 @@
// run-pass

#![feature(destructuring_assignment)]
struct Struct<S, T> {
a: S,
b: T,
Expand Down
@@ -1,4 +1,3 @@
#![feature(destructuring_assignment)]
struct Struct<S, T> {
a: S,
b: T,
Expand Down

0 comments on commit 672f836

Please sign in to comment.