Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize destructuring_assignment #90521

Merged
merged 1 commit into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,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 @@ -2620,7 +2619,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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`.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(destructuring_assignment)]

fn main() {
let mut x = &0;
let mut y = &0;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// run-pass

#![feature(destructuring_assignment)]

fn main() {
let (mut a, mut b);
[a, b] = [0, 1];
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// run-pass

#![feature(destructuring_assignment)]
struct Struct<S, T> {
a: S,
b: T,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(destructuring_assignment)]
struct Struct<S, T> {
a: S,
b: T,
Expand Down
Loading