Skip to content

Commit 998cfe5

Browse files
committed
Auto merge of #85305 - MarcusDunn:master, r=pnkfelix
Stabilize bindings_after_at attempting to stabilze bindings_after_at [#65490](#65490), im pretty new to the whole thing so any pointers are greatly appreciated.
2 parents 7d6bf86 + c2af4cb commit 998cfe5

File tree

56 files changed

+228
-335
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+228
-335
lines changed

compiler/rustc_ast_passes/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//!
55
//! The crate also contains other misc AST visitors, e.g. `node_count` and `show_span`.
66
7-
#![feature(bindings_after_at)]
7+
#![cfg_attr(bootstrap, feature(bindings_after_at))]
88
#![feature(iter_is_partitioned)]
99
#![feature(box_patterns)]
1010
#![recursion_limit = "256"]

compiler/rustc_feature/src/accepted.rs

+3
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@ declare_features! (
287287
(accepted, const_fn_unsize, "1.54.0", Some(64992), None),
288288
/// Allows `impl Trait` with multiple unrelated lifetimes.
289289
(accepted, member_constraints, "1.54.0", Some(61997), None),
290+
/// Allows bindings in the subpattern of a binding pattern.
291+
/// For example, you can write `x @ Some(y)`.
292+
(accepted, bindings_after_at, "1.54.0", Some(65490), None),
290293

291294
// -------------------------------------------------------------------------
292295
// feature-group-end: accepted features

compiler/rustc_feature/src/active.rs

-4
Original file line numberDiff line numberDiff line change
@@ -526,10 +526,6 @@ declare_features! (
526526
/// Allows using `&mut` in constant functions.
527527
(active, const_mut_refs, "1.41.0", Some(57349), None),
528528

529-
/// Allows bindings in the subpattern of a binding pattern.
530-
/// For example, you can write `x @ Some(y)`.
531-
(active, bindings_after_at, "1.41.0", Some(65490), None),
532-
533529
/// Allows `impl const Trait for T` syntax.
534530
(active, const_trait_impl, "1.42.0", Some(67792), None),
535531

compiler/rustc_mir/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Rust MIR: a lowered representation of Rust.
88
#![feature(in_band_lifetimes)]
99
#![feature(array_windows)]
1010
#![feature(assert_matches)]
11-
#![feature(bindings_after_at)]
11+
#![cfg_attr(bootstrap, feature(bindings_after_at))]
1212
#![feature(bool_to_option)]
1313
#![feature(box_patterns)]
1414
#![feature(box_syntax)]

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

+1-48
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ use rustc_middle::thir::PatKind;
1616
use rustc_middle::ty::{self, Ty, TyCtxt};
1717
use rustc_session::lint::builtin::BINDINGS_WITH_VARIANT_NAME;
1818
use rustc_session::lint::builtin::{IRREFUTABLE_LET_PATTERNS, UNREACHABLE_PATTERNS};
19-
use rustc_session::parse::feature_err;
2019
use rustc_session::Session;
21-
use rustc_span::{sym, Span};
20+
use rustc_span::Span;
2221
use std::slice;
2322

2423
crate fn check_match(tcx: TyCtxt<'_>, def_id: DefId) {
@@ -115,9 +114,6 @@ impl PatCtxt<'_, '_> {
115114
impl<'tcx> MatchVisitor<'_, 'tcx> {
116115
fn check_patterns(&mut self, pat: &Pat<'_>) {
117116
pat.walk_always(|pat| check_borrow_conflicts_in_at_patterns(self, pat));
118-
if !self.tcx.features().bindings_after_at {
119-
check_legality_of_bindings_in_at_patterns(self, pat);
120-
}
121117
check_for_bindings_named_same_as_variants(self, pat);
122118
}
123119

@@ -732,46 +728,3 @@ fn check_borrow_conflicts_in_at_patterns(cx: &MatchVisitor<'_, '_>, pat: &Pat<'_
732728
err.emit();
733729
}
734730
}
735-
736-
/// Forbids bindings in `@` patterns. This used to be is necessary for memory safety,
737-
/// because of the way rvalues were handled in the borrow check. (See issue #14587.)
738-
fn check_legality_of_bindings_in_at_patterns(cx: &MatchVisitor<'_, '_>, pat: &Pat<'_>) {
739-
AtBindingPatternVisitor { cx, bindings_allowed: true }.visit_pat(pat);
740-
741-
struct AtBindingPatternVisitor<'a, 'b, 'tcx> {
742-
cx: &'a MatchVisitor<'b, 'tcx>,
743-
bindings_allowed: bool,
744-
}
745-
746-
impl<'v> Visitor<'v> for AtBindingPatternVisitor<'_, '_, '_> {
747-
type Map = intravisit::ErasedMap<'v>;
748-
749-
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
750-
NestedVisitorMap::None
751-
}
752-
753-
fn visit_pat(&mut self, pat: &Pat<'_>) {
754-
match pat.kind {
755-
hir::PatKind::Binding(.., ref subpat) => {
756-
if !self.bindings_allowed {
757-
feature_err(
758-
&self.cx.tcx.sess.parse_sess,
759-
sym::bindings_after_at,
760-
pat.span,
761-
"pattern bindings after an `@` are unstable",
762-
)
763-
.emit();
764-
}
765-
766-
if subpat.is_some() {
767-
let bindings_were_allowed = self.bindings_allowed;
768-
self.bindings_allowed = false;
769-
intravisit::walk_pat(self, pat);
770-
self.bindings_allowed = bindings_were_allowed;
771-
}
772-
}
773-
_ => intravisit::walk_pat(self, pat),
774-
}
775-
}
776-
}
777-
}

compiler/rustc_parse/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
#![feature(array_windows)]
44
#![feature(crate_visibility_modifier)]
5-
#![feature(bindings_after_at)]
5+
#![cfg_attr(bootstrap, feature(bindings_after_at))]
66
#![feature(box_syntax)]
77
#![feature(box_patterns)]
88
#![recursion_limit = "256"]

compiler/rustc_typeck/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ This API is completely unstable and subject to change.
5656
*/
5757

5858
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
59-
#![feature(bindings_after_at)]
59+
#![cfg_attr(bootstrap, feature(bindings_after_at))]
6060
#![feature(bool_to_option)]
6161
#![feature(box_syntax)]
6262
#![feature(crate_visibility_modifier)]

library/alloc/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
#![feature(allow_internal_unstable)]
8686
#![feature(arbitrary_self_types)]
8787
#![feature(async_stream)]
88+
#![cfg_attr(bootstrap, feature(bindings_after_at))]
8889
#![feature(box_patterns)]
8990
#![feature(box_syntax)]
9091
#![feature(cfg_sanitize)]
@@ -145,7 +146,6 @@
145146
#![feature(associated_type_bounds)]
146147
#![feature(slice_group_by)]
147148
#![feature(decl_macro)]
148-
#![feature(bindings_after_at)]
149149
// Allow testing this library
150150

151151
#[cfg(test)]

src/etc/pre-commit.sh

100755100644
File mode changed.

src/test/ui/borrowck/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// Tests using a combination of pattern features has the expected borrow checking behavior
2-
#![feature(bindings_after_at)]
32
#![feature(box_patterns)]
43

54
enum Test {

src/test/ui/borrowck/bindings-after-at-or-patterns-slice-patterns-box-patterns.stderr

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: cannot borrow value as mutable because it is also borrowed as immutable
2-
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:37:9
2+
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:36:9
33
|
44
LL | ref foo @ [.., ref mut bar] => (),
55
| -------^^^^^^^^-----------^
@@ -8,7 +8,7 @@ LL | ref foo @ [.., ref mut bar] => (),
88
| immutable borrow, by `foo`, occurs here
99

1010
error: cannot borrow value as mutable because it is also borrowed as immutable
11-
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:121:9
11+
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:120:9
1212
|
1313
LL | ref foo @ Some(box ref mut s) => (),
1414
| -------^^^^^^^^^^^^---------^
@@ -17,7 +17,7 @@ LL | ref foo @ Some(box ref mut s) => (),
1717
| immutable borrow, by `foo`, occurs here
1818

1919
error[E0382]: borrow of moved value: `x`
20-
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:19:5
20+
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:18:5
2121
|
2222
LL | fn bindings_after_at_slice_patterns_move_binding(x: [String; 4]) {
2323
| - move occurs because `x` has type `[String; 4]`, which does not implement the `Copy` trait
@@ -29,7 +29,7 @@ LL | &x;
2929
| ^^ value borrowed here after move
3030

3131
error[E0502]: cannot borrow `x` as immutable because it is also borrowed as mutable
32-
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:29:5
32+
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:28:5
3333
|
3434
LL | ref mut foo @ [.., _] => Some(foo),
3535
| --------------------- mutable borrow occurs here
@@ -41,7 +41,7 @@ LL | drop(r);
4141
| - mutable borrow later used here
4242

4343
error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable
44-
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:51:5
44+
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:50:5
4545
|
4646
LL | [ref foo @ .., ref bar] => Some(foo),
4747
| ------------ immutable borrow occurs here
@@ -53,7 +53,7 @@ LL | drop(r);
5353
| - immutable borrow later used here
5454

5555
error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable
56-
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:63:5
56+
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:62:5
5757
|
5858
LL | ref foo @ [.., ref bar] => Some(foo),
5959
| ----------------------- immutable borrow occurs here
@@ -65,7 +65,7 @@ LL | drop(r);
6565
| - immutable borrow later used here
6666

6767
error[E0382]: borrow of moved value: `x`
68-
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:77:5
68+
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:76:5
6969
|
7070
LL | fn bindings_after_at_or_patterns_move(x: Option<Test>) {
7171
| - move occurs because `x` has type `Option<Test>`, which does not implement the `Copy` trait
@@ -80,7 +80,7 @@ LL | &x;
8080
| ^^ value borrowed here after move
8181

8282
error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable
83-
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:87:5
83+
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:86:5
8484
|
8585
LL | ref foo @ Some(Test::Foo | Test::Bar) => Some(foo),
8686
| ------------------------------------- immutable borrow occurs here
@@ -92,7 +92,7 @@ LL | drop(r);
9292
| - immutable borrow later used here
9393

9494
error[E0502]: cannot borrow `x` as immutable because it is also borrowed as mutable
95-
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:99:5
95+
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:98:5
9696
|
9797
LL | ref mut foo @ Some(Test::Foo | Test::Bar) => Some(foo),
9898
| ----------------------------------------- mutable borrow occurs here
@@ -104,7 +104,7 @@ LL | drop(r);
104104
| - mutable borrow later used here
105105

106106
error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable
107-
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:113:5
107+
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:112:5
108108
|
109109
LL | ref foo @ Some(box ref s) => Some(foo),
110110
| ------------------------- immutable borrow occurs here
@@ -116,7 +116,7 @@ LL | drop(r);
116116
| - immutable borrow later used here
117117

118118
error[E0382]: borrow of moved value: `x`
119-
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:135:5
119+
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:134:5
120120
|
121121
LL | fn bindings_after_at_slice_patterns_or_patterns_moves(x: [Option<Test>; 4]) {
122122
| - move occurs because `x` has type `[Option<Test>; 4]`, which does not implement the `Copy` trait
@@ -131,7 +131,7 @@ LL | &x;
131131
| ^^ value borrowed here after move
132132

133133
error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable
134-
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:145:5
134+
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:144:5
135135
|
136136
LL | ref a @ [ref b @ .., Some(Test::Foo | Test::Bar)] => Some(a),
137137
| ------------------------------------------------- immutable borrow occurs here
@@ -143,7 +143,7 @@ LL | drop(r);
143143
| - immutable borrow later used here
144144

145145
error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable
146-
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:157:5
146+
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:156:5
147147
|
148148
LL | ref a @ [ref b @ .., Some(Test::Foo | Test::Bar)] => Some(b),
149149
| ---------- immutable borrow occurs here
@@ -155,7 +155,7 @@ LL | drop(r);
155155
| - immutable borrow later used here
156156

157157
error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable
158-
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:171:5
158+
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:170:5
159159
|
160160
LL | [_, ref a @ Some(box ref b), ..] => Some(a),
161161
| ----------------------- immutable borrow occurs here
@@ -167,7 +167,7 @@ LL | drop(r);
167167
| - immutable borrow later used here
168168

169169
error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable
170-
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:187:5
170+
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:186:5
171171
|
172172
LL | [_, ref a @ Some(box Test::Foo | box Test::Bar), ..] => Some(a),
173173
| ------------------------------------------- immutable borrow occurs here
@@ -179,7 +179,7 @@ LL | drop(r);
179179
| - immutable borrow later used here
180180

181181
error[E0502]: cannot borrow `x` as immutable because it is also borrowed as mutable
182-
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:201:5
182+
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:200:5
183183
|
184184
LL | [_, ref mut a @ Some(box Test::Foo | box Test::Bar), ..] => Some(a),
185185
| ----------------------------------------------- mutable borrow occurs here
@@ -191,7 +191,7 @@ LL | drop(r);
191191
| - mutable borrow later used here
192192

193193
error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable
194-
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:215:5
194+
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:214:5
195195
|
196196
LL | ref a @ [_, ref b @ Some(box Test::Foo | box Test::Bar), ..] => Some(a),
197197
| ------------------------------------------------------------ immutable borrow occurs here

src/test/ui/drop/dynamic-drop.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// ignore-wasm32-bare compiled with panic=abort by default
33

44
#![feature(generators, generator_trait)]
5-
#![feature(bindings_after_at)]
65

76
#![allow(unused_assignments)]
87
#![allow(unused_variables)]

src/test/ui/pattern/bindings-after-at/bind-by-copy.rs

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
// Test copy
44

5-
#![feature(bindings_after_at)]
6-
75
struct A { a: i32, b: i32 }
86
struct B { a: i32, b: C }
97
struct D { a: i32, d: C }

src/test/ui/pattern/bindings-after-at/bind-by-move-neither-can-live-while-the-other-survives-1.rs

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// It checks that you cannot use an AND-pattern (`binding @ pat`)
33
// where one side is by-ref and the other is by-move.
44

5-
#![feature(bindings_after_at)]
6-
75
struct X {
86
x: (),
97
}

src/test/ui/pattern/bindings-after-at/bind-by-move-neither-can-live-while-the-other-survives-1.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: cannot move out of value because it is borrowed
2-
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:14:14
2+
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:12:14
33
|
44
LL | Some(ref _y @ _z) => {}
55
| ------^^^--
@@ -8,7 +8,7 @@ LL | Some(ref _y @ _z) => {}
88
| value borrowed, by `_y`, here
99

1010
error: borrow of moved value
11-
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:21:14
11+
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:19:14
1212
|
1313
LL | Some(_z @ ref _y) => {}
1414
| --^^^------
@@ -18,7 +18,7 @@ LL | Some(_z @ ref _y) => {}
1818
| move occurs because `_z` has type `X` which does not implement the `Copy` trait
1919

2020
error: cannot move out of value because it is borrowed
21-
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:28:14
21+
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:26:14
2222
|
2323
LL | Some(ref mut _y @ _z) => {}
2424
| ----------^^^--
@@ -27,7 +27,7 @@ LL | Some(ref mut _y @ _z) => {}
2727
| value borrowed, by `_y`, here
2828

2929
error: borrow of moved value
30-
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:35:14
30+
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:33:14
3131
|
3232
LL | Some(_z @ ref mut _y) => {}
3333
| --^^^----------
@@ -37,7 +37,7 @@ LL | Some(_z @ ref mut _y) => {}
3737
| move occurs because `_z` has type `X` which does not implement the `Copy` trait
3838

3939
error[E0382]: borrow of moved value
40-
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:14:14
40+
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:12:14
4141
|
4242
LL | Some(ref _y @ _z) => {}
4343
| ^^^^^^^^^--
@@ -52,7 +52,7 @@ LL | Some(ref _y @ ref _z) => {}
5252
| ^^^
5353

5454
error[E0382]: borrow of moved value
55-
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:28:14
55+
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:26:14
5656
|
5757
LL | Some(ref mut _y @ _z) => {}
5858
| ^^^^^^^^^^^^^--

src/test/ui/pattern/bindings-after-at/bind-by-move-no-subbindings-fun-param.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// See issue #12534.
22

3-
#![feature(bindings_after_at)]
4-
53
fn main() {}
64

75
struct A(Box<u8>);

src/test/ui/pattern/bindings-after-at/bind-by-move-no-subbindings-fun-param.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0382]: use of partially moved value
2-
--> $DIR/bind-by-move-no-subbindings-fun-param.rs:9:6
2+
--> $DIR/bind-by-move-no-subbindings-fun-param.rs:7:6
33
|
44
LL | fn f(a @ A(u): A) -> Box<u8> {
55
| ^^^^^^-^

src/test/ui/pattern/bindings-after-at/borrowck-move-and-move.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// Test that moving on both sides of an `@` pattern is not allowed.
22

3-
#![feature(bindings_after_at)]
4-
53
fn main() {
64
struct U; // Not copy!
75

0 commit comments

Comments
 (0)