Feature gate

This commit is contained in:
Jules Bertholet 2024-03-26 01:23:26 -04:00
parent e0da13f25f
commit 528d45af18
No known key found for this signature in database
GPG Key ID: 32034DAFC38C1BFC
9 changed files with 76 additions and 9 deletions

View File

@ -565,6 +565,7 @@ macro_rules! gate_all {
gate_all!(unnamed_fields, "unnamed fields are not yet fully implemented"); gate_all!(unnamed_fields, "unnamed fields are not yet fully implemented");
gate_all!(fn_delegation, "functions delegation is not yet fully implemented"); gate_all!(fn_delegation, "functions delegation is not yet fully implemented");
gate_all!(postfix_match, "postfix match is experimental"); gate_all!(postfix_match, "postfix match is experimental");
gate_all!(mut_ref, "mutable by-reference bindings are experimental");
if !visitor.features.never_patterns { if !visitor.features.never_patterns {
if let Some(spans) = spans.get(&sym::never_patterns) { if let Some(spans) = spans.get(&sym::never_patterns) {

View File

@ -529,6 +529,8 @@ pub fn internal(&self, feature: Symbol) -> bool {
(unstable, more_qualified_paths, "1.54.0", Some(86935)), (unstable, more_qualified_paths, "1.54.0", Some(86935)),
/// Allows the `#[must_not_suspend]` attribute. /// Allows the `#[must_not_suspend]` attribute.
(unstable, must_not_suspend, "1.57.0", Some(83310)), (unstable, must_not_suspend, "1.57.0", Some(83310)),
/// Allows `mut ref` and `mut ref mut` identifier patterns.
(incomplete, mut_ref, "CURRENT_RUSTC_VERSION", Some(123076)),
/// Allows using `#[naked]` on functions. /// Allows using `#[naked]` on functions.
(unstable, naked_functions, "1.9.0", Some(90957)), (unstable, naked_functions, "1.9.0", Some(90957)),
/// Allows specifying the as-needed link modifier /// Allows specifying the as-needed link modifier

View File

@ -779,6 +779,10 @@ fn parse_pat_ident_mut(&mut self) -> PResult<'a, PatKind> {
self.ban_mut_general_pat(mut_span, &pat, changed_any_binding); self.ban_mut_general_pat(mut_span, &pat, changed_any_binding);
} }
if matches!(pat.kind, PatKind::Ident(BindingAnnotation(ByRef::Yes(_), Mutability::Mut), ..))
{
self.psess.gated_spans.gate(sym::mut_ref, pat.span);
}
Ok(pat.into_inner().kind) Ok(pat.into_inner().kind)
} }

View File

@ -1185,6 +1185,7 @@
multiple_supertrait_upcastable, multiple_supertrait_upcastable,
must_not_suspend, must_not_suspend,
must_use, must_use,
mut_ref,
naked, naked,
naked_functions, naked_functions,
name, name,

View File

@ -0,0 +1,13 @@
fn main() {
let mut ref x = 10; //~ ERROR [E0658]
x = &11;
let ref mut y = 12;
*y = 13;
let mut ref mut z = 14; //~ ERROR [E0658]
z = &mut 15;
#[cfg(FALSE)]
let mut ref x = 10; //~ ERROR [E0658]
#[cfg(FALSE)]
let mut ref mut y = 10; //~ ERROR [E0658]
}

View File

@ -0,0 +1,43 @@
error[E0658]: mutable by-reference bindings are experimental
--> $DIR/feature-gate-mut-ref.rs:2:17
|
LL | let mut ref x = 10;
| ^
|
= note: see issue #123076 <https://github.com/rust-lang/rust/issues/123076> for more information
= help: add `#![feature(mut_ref)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
error[E0658]: mutable by-reference bindings are experimental
--> $DIR/feature-gate-mut-ref.rs:6:21
|
LL | let mut ref mut z = 14;
| ^
|
= note: see issue #123076 <https://github.com/rust-lang/rust/issues/123076> for more information
= help: add `#![feature(mut_ref)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
error[E0658]: mutable by-reference bindings are experimental
--> $DIR/feature-gate-mut-ref.rs:10:17
|
LL | let mut ref x = 10;
| ^
|
= note: see issue #123076 <https://github.com/rust-lang/rust/issues/123076> for more information
= help: add `#![feature(mut_ref)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
error[E0658]: mutable by-reference bindings are experimental
--> $DIR/feature-gate-mut-ref.rs:12:21
|
LL | let mut ref mut y = 10;
| ^
|
= note: see issue #123076 <https://github.com/rust-lang/rust/issues/123076> for more information
= help: add `#![feature(mut_ref)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0658`.

View File

@ -1,5 +1,6 @@
//@ check-pass //@ check-pass
#![allow(incomplete_features)]
#![feature(mut_ref)]
fn main() { fn main() {
let mut ref x = 10; let mut ref x = 10;
x = &11; x = &11;

View File

@ -1,4 +1,6 @@
//@ edition: 2021 //@ edition: 2021
#![allow(incomplete_features)]
#![feature(mut_ref)]
struct Foo(u8); struct Foo(u8);

View File

@ -1,5 +1,5 @@
error[E0384]: cannot assign twice to immutable variable `a` error[E0384]: cannot assign twice to immutable variable `a`
--> $DIR/mut-ref-mut-2021.rs:7:5 --> $DIR/mut-ref-mut-2021.rs:9:5
| |
LL | let Foo(a) = Foo(0); LL | let Foo(a) = Foo(0);
| - | -
@ -10,7 +10,7 @@ LL | a = 42;
| ^^^^^^ cannot assign twice to immutable variable | ^^^^^^ cannot assign twice to immutable variable
error[E0384]: cannot assign twice to immutable variable `a` error[E0384]: cannot assign twice to immutable variable `a`
--> $DIR/mut-ref-mut-2021.rs:13:5 --> $DIR/mut-ref-mut-2021.rs:15:5
| |
LL | let Foo(ref a) = Foo(0); LL | let Foo(ref a) = Foo(0);
| ----- first assignment to `a` | ----- first assignment to `a`
@ -18,7 +18,7 @@ LL | a = &42;
| ^^^^^^^ cannot assign twice to immutable variable | ^^^^^^^ cannot assign twice to immutable variable
error[E0384]: cannot assign twice to immutable variable `a` error[E0384]: cannot assign twice to immutable variable `a`
--> $DIR/mut-ref-mut-2021.rs:19:5 --> $DIR/mut-ref-mut-2021.rs:21:5
| |
LL | let Foo(ref mut a) = Foo(0); LL | let Foo(ref mut a) = Foo(0);
| --------- first assignment to `a` | --------- first assignment to `a`
@ -26,7 +26,7 @@ LL | a = &mut 42;
| ^^^^^^^^^^^ cannot assign twice to immutable variable | ^^^^^^^^^^^ cannot assign twice to immutable variable
error[E0384]: cannot assign twice to immutable variable `a` error[E0384]: cannot assign twice to immutable variable `a`
--> $DIR/mut-ref-mut-2021.rs:25:5 --> $DIR/mut-ref-mut-2021.rs:27:5
| |
LL | let Foo(a) = &Foo(0); LL | let Foo(a) = &Foo(0);
| - first assignment to `a` | - first assignment to `a`
@ -34,7 +34,7 @@ LL | a = &42;
| ^^^^^^^ cannot assign twice to immutable variable | ^^^^^^^ cannot assign twice to immutable variable
error[E0384]: cannot assign twice to immutable variable `a` error[E0384]: cannot assign twice to immutable variable `a`
--> $DIR/mut-ref-mut-2021.rs:31:5 --> $DIR/mut-ref-mut-2021.rs:33:5
| |
LL | let Foo(ref a) = &Foo(0); LL | let Foo(ref a) = &Foo(0);
| ----- first assignment to `a` | ----- first assignment to `a`
@ -42,7 +42,7 @@ LL | a = &42;
| ^^^^^^^ cannot assign twice to immutable variable | ^^^^^^^ cannot assign twice to immutable variable
error[E0384]: cannot assign twice to immutable variable `a` error[E0384]: cannot assign twice to immutable variable `a`
--> $DIR/mut-ref-mut-2021.rs:37:5 --> $DIR/mut-ref-mut-2021.rs:39:5
| |
LL | let Foo(a) = &mut Foo(0); LL | let Foo(a) = &mut Foo(0);
| - first assignment to `a` | - first assignment to `a`
@ -50,7 +50,7 @@ LL | a = &mut 42;
| ^^^^^^^^^^^ cannot assign twice to immutable variable | ^^^^^^^^^^^ cannot assign twice to immutable variable
error[E0384]: cannot assign twice to immutable variable `a` error[E0384]: cannot assign twice to immutable variable `a`
--> $DIR/mut-ref-mut-2021.rs:43:5 --> $DIR/mut-ref-mut-2021.rs:45:5
| |
LL | let Foo(ref a) = &mut Foo(0); LL | let Foo(ref a) = &mut Foo(0);
| ----- first assignment to `a` | ----- first assignment to `a`
@ -58,7 +58,7 @@ LL | a = &42;
| ^^^^^^^ cannot assign twice to immutable variable | ^^^^^^^ cannot assign twice to immutable variable
error[E0384]: cannot assign twice to immutable variable `a` error[E0384]: cannot assign twice to immutable variable `a`
--> $DIR/mut-ref-mut-2021.rs:49:5 --> $DIR/mut-ref-mut-2021.rs:51:5
| |
LL | let Foo(ref mut a) = &mut Foo(0); LL | let Foo(ref mut a) = &mut Foo(0);
| --------- first assignment to `a` | --------- first assignment to `a`