1
Fork 0

make experimental pattern typing features mutually exclusive

This aims to reduce the complexity needed in the boolean logic for telling which
rules we're using to type patterns. If we still want the functionality this
removes, we can re-add it later, after some cleanup to pattern typing.
This commit is contained in:
dianne 2024-12-23 01:59:32 -08:00
parent 1f81f90689
commit 550b0ad036
5 changed files with 16 additions and 184 deletions

View file

@ -718,7 +718,8 @@ impl Features {
/// Some features are not allowed to be used together at the same time, if /// Some features are not allowed to be used together at the same time, if
/// the two are present, produce an error. /// the two are present, produce an error.
/// pub const INCOMPATIBLE_FEATURES: &[(Symbol, Symbol)] = &[
/// Currently empty, but we will probably need this again in the future, // Experimental match ergonomics rulesets are incompatible with each other, to simplify the
/// so let's keep it in for now. // boolean logic required to tell which typing rules to use.
pub const INCOMPATIBLE_FEATURES: &[(Symbol, Symbol)] = &[]; (sym::ref_pat_eat_one_layer_2024, sym::ref_pat_eat_one_layer_2024_structural),
];

View file

@ -1,9 +1,9 @@
//@ run-pass //@ run-pass
//@ edition: 2021 //@ edition: 2021
//@ revisions: classic structural both //@ revisions: classic structural
#![allow(incomplete_features)] #![allow(incomplete_features)]
#![cfg_attr(any(classic, both), feature(ref_pat_eat_one_layer_2024))] #![cfg_attr(classic, feature(ref_pat_eat_one_layer_2024))]
#![cfg_attr(any(structural, both), feature(ref_pat_eat_one_layer_2024_structural))] #![cfg_attr(structural, feature(ref_pat_eat_one_layer_2024_structural))]
pub fn main() { pub fn main() {
if let &Some(Some(x)) = &Some(&mut Some(0)) { if let &Some(Some(x)) = &Some(&mut Some(0)) {

View file

@ -1,9 +1,9 @@
//@ run-pass //@ run-pass
//@ edition: 2024 //@ edition: 2024
//@ revisions: classic structural both //@ revisions: classic structural
#![allow(incomplete_features)] #![allow(incomplete_features)]
#![cfg_attr(any(classic, both), feature(ref_pat_eat_one_layer_2024))] #![cfg_attr(classic, feature(ref_pat_eat_one_layer_2024))]
#![cfg_attr(any(structural, both), feature(ref_pat_eat_one_layer_2024_structural))] #![cfg_attr(structural, feature(ref_pat_eat_one_layer_2024_structural))]
pub fn main() { pub fn main() {
if let Some(Some(&x)) = &Some(&Some(0)) { if let Some(Some(&x)) = &Some(&Some(0)) {
@ -54,11 +54,11 @@ pub fn main() {
if let Some(&Some(x)) = &mut Some(Some(0)) { if let Some(&Some(x)) = &mut Some(Some(0)) {
let _: u32 = x; let _: u32 = x;
} }
#[cfg(any(classic, both))] #[cfg(classic)]
if let Some(&mut x) = &mut Some(&0) { if let Some(&mut x) = &mut Some(&0) {
let _: &u32 = x; let _: &u32 = x;
} }
#[cfg(any(structural, both))] #[cfg(structural)]
if let Some(&mut x) = &Some(&mut 0) { if let Some(&mut x) = &Some(&mut 0) {
let _: &u32 = x; let _: &u32 = x;
} }

View file

@ -1,169 +0,0 @@
error[E0308]: mismatched types
--> $DIR/ref_pat_eat_one_layer_2024_fail.rs:8:17
|
LL | if let Some(&mut Some(&_)) = &Some(&Some(0)) {
| ^^^^^^^^^^^^^ --------------- this expression has type `&Option<&Option<{integer}>>`
| |
| types differ in mutability
|
= note: expected reference `&Option<{integer}>`
found mutable reference `&mut _`
error[E0308]: mismatched types
--> $DIR/ref_pat_eat_one_layer_2024_fail.rs:11:23
|
LL | if let Some(&Some(&mut _)) = &Some(&mut Some(0)) {
| ^^^^^^ ------------------- this expression has type `&Option<&mut Option<{integer}>>`
| |
| expected integer, found `&mut _`
|
= note: expected type `{integer}`
found mutable reference `&mut _`
error[E0308]: mismatched types
--> $DIR/ref_pat_eat_one_layer_2024_fail.rs:15:27
|
LL | let _: &mut u32 = x;
| -------- ^ types differ in mutability
| |
| expected due to this
|
= note: expected mutable reference `&mut u32`
found reference `&{integer}`
error[E0308]: mismatched types
--> $DIR/ref_pat_eat_one_layer_2024_fail.rs:18:23
|
LL | if let Some(&Some(&mut _)) = &mut Some(&Some(0)) {
| ^^^^^^ ------------------- this expression has type `&mut Option<&Option<{integer}>>`
| |
| expected integer, found `&mut _`
|
= note: expected type `{integer}`
found mutable reference `&mut _`
error[E0308]: mismatched types
--> $DIR/ref_pat_eat_one_layer_2024_fail.rs:21:29
|
LL | if let Some(&Some(Some((&mut _)))) = &Some(Some(&mut Some(0))) {
| ^^^^^^ ------------------------- this expression has type `&Option<Option<&mut Option<{integer}>>>`
| |
| expected integer, found `&mut _`
|
= note: expected type `{integer}`
found mutable reference `&mut _`
error[E0308]: mismatched types
--> $DIR/ref_pat_eat_one_layer_2024_fail.rs:24:17
|
LL | if let Some(&mut Some(x)) = &Some(Some(0)) {
| ^^^^^^^^^^^^ -------------- this expression has type `&Option<Option<{integer}>>`
| |
| expected `Option<{integer}>`, found `&mut _`
|
= note: expected enum `Option<{integer}>`
found mutable reference `&mut _`
error[E0308]: mismatched types
--> $DIR/ref_pat_eat_one_layer_2024_fail.rs:27:17
|
LL | if let Some(&mut Some(x)) = &Some(Some(0)) {
| ^^^^^^^^^^^^ -------------- this expression has type `&Option<Option<{integer}>>`
| |
| expected `Option<{integer}>`, found `&mut _`
|
= note: expected enum `Option<{integer}>`
found mutable reference `&mut _`
error[E0308]: mismatched types
--> $DIR/ref_pat_eat_one_layer_2024_fail.rs:31:9
|
LL | let &mut _ = &&0;
| ^^^^^^ --- this expression has type `&&{integer}`
| |
| types differ in mutability
|
= note: expected reference `&&{integer}`
found mutable reference `&mut _`
error[E0308]: mismatched types
--> $DIR/ref_pat_eat_one_layer_2024_fail.rs:34:9
|
LL | let &mut _ = &&&&&&&&&&&&&&&&&&&&&&&&&&&&0;
| ^^^^^^ ----------------------------- this expression has type `&&&&&&&&&&&&&&&&&&&&&&&&&&&&{integer}`
| |
| types differ in mutability
|
= note: expected reference `&&&&&&&&&&&&&&&&&&&&&&&&&&&&{integer}`
found mutable reference `&mut _`
error[E0308]: mismatched types
--> $DIR/ref_pat_eat_one_layer_2024_fail.rs:45:9
|
LL | let &mut _ = &&mut 0;
| ^^^^^^ ------- this expression has type `&&mut {integer}`
| |
| types differ in mutability
|
= note: expected reference `&&mut {integer}`
found mutable reference `&mut _`
error[E0308]: mismatched types
--> $DIR/ref_pat_eat_one_layer_2024_fail.rs:48:9
|
LL | let &mut _ = &&&&&&&&&&&&&&&&&&&&&&&&&&&&mut 0;
| ^^^^^^ --------------------------------- this expression has type `&&&&&&&&&&&&&&&&&&&&&&&&&&&&mut {integer}`
| |
| types differ in mutability
|
= note: expected reference `&&&&&&&&&&&&&&&&&&&&&&&&&&&&mut {integer}`
found mutable reference `&mut _`
error[E0308]: mismatched types
--> $DIR/ref_pat_eat_one_layer_2024_fail.rs:51:14
|
LL | let &mut &mut &mut &mut _ = &mut &&&&mut &&&mut &mut 0;
| ^^^^^^^^^^^^^^^^ -------------------------- this expression has type `&mut &&&&mut &&&mut &mut {integer}`
| |
| types differ in mutability
|
= note: expected reference `&&&&mut &&&mut &mut {integer}`
found mutable reference `&mut _`
error[E0658]: binding cannot be both mutable and by-reference
--> $DIR/ref_pat_eat_one_layer_2024_fail.rs:60:13
|
LL | let Foo(mut a) = &Foo(0);
| ^^^^
|
= 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]: binding cannot be both mutable and by-reference
--> $DIR/ref_pat_eat_one_layer_2024_fail.rs:64:13
|
LL | let Foo(mut a) = &mut Foo(0);
| ^^^^
|
= 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[E0277]: the trait bound `&_: main::Ref` is not satisfied
--> $DIR/ref_pat_eat_one_layer_2024_fail.rs:82:14
|
LL | let &_ = generic();
| ^^^^^^^^^ the trait `main::Ref` is not implemented for `&_`
|
= help: the trait `main::Ref` is implemented for `&'static mut [(); 0]`
note: required by a bound in `generic`
--> $DIR/ref_pat_eat_one_layer_2024_fail.rs:68:19
|
LL | fn generic<R: Ref>() -> R {
| ^^^ required by this bound in `generic`
error: aborting due to 15 previous errors
Some errors have detailed explanations: E0277, E0308, E0658.
For more information about an error, try `rustc --explain E0277`.

View file

@ -1,8 +1,8 @@
//@ edition: 2024 //@ edition: 2024
//@ revisions: classic structural both //@ revisions: classic structural
#![allow(incomplete_features)] #![allow(incomplete_features)]
#![cfg_attr(any(classic, both), feature(ref_pat_eat_one_layer_2024))] #![cfg_attr(classic, feature(ref_pat_eat_one_layer_2024))]
#![cfg_attr(any(structural, both), feature(ref_pat_eat_one_layer_2024_structural))] #![cfg_attr(structural, feature(ref_pat_eat_one_layer_2024_structural))]
pub fn main() { pub fn main() {
if let Some(&mut Some(&_)) = &Some(&Some(0)) { if let Some(&mut Some(&_)) = &Some(&Some(0)) {