Don't gate the feature twice
This commit is contained in:
parent
e274372689
commit
19e0c984d3
4 changed files with 31 additions and 51 deletions
|
@ -676,6 +676,19 @@ impl Pat {
|
||||||
});
|
});
|
||||||
could_be_never_pattern
|
could_be_never_pattern
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether this contains a `!` pattern. This in particular means that a feature gate error will
|
||||||
|
/// be raised if the feature is off. Used to avoid gating the feature twice.
|
||||||
|
pub fn contains_never_pattern(&self) -> bool {
|
||||||
|
let mut contains_never_pattern = false;
|
||||||
|
self.walk(&mut |pat| {
|
||||||
|
if matches!(pat.kind, PatKind::Never) {
|
||||||
|
contains_never_pattern = true;
|
||||||
|
}
|
||||||
|
true
|
||||||
|
});
|
||||||
|
contains_never_pattern
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A single field in a struct pattern.
|
/// A single field in a struct pattern.
|
||||||
|
|
|
@ -2920,7 +2920,10 @@ impl<'a> Parser<'a> {
|
||||||
arm_body = None;
|
arm_body = None;
|
||||||
this.expect_one_of(&[token::Comma], &[token::CloseDelim(Delimiter::Brace)]).map(
|
this.expect_one_of(&[token::Comma], &[token::CloseDelim(Delimiter::Brace)]).map(
|
||||||
|x| {
|
|x| {
|
||||||
|
// Don't gate twice
|
||||||
|
if !pat.contains_never_pattern() {
|
||||||
this.sess.gated_spans.gate(sym::never_patterns, pat.span);
|
this.sess.gated_spans.gate(sym::never_patterns, pat.span);
|
||||||
|
}
|
||||||
x
|
x
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -14,14 +14,12 @@ fn main() {
|
||||||
match *ptr {
|
match *ptr {
|
||||||
!
|
!
|
||||||
//~^ ERROR `!` patterns are experimental
|
//~^ ERROR `!` patterns are experimental
|
||||||
//~| ERROR `!` patterns are experimental
|
|
||||||
}
|
}
|
||||||
// Check that the gate operates even behind `cfg`.
|
// Check that the gate operates even behind `cfg`.
|
||||||
#[cfg(FALSE)]
|
#[cfg(FALSE)]
|
||||||
match *ptr {
|
match *ptr {
|
||||||
!
|
!
|
||||||
//~^ ERROR `!` patterns are experimental
|
//~^ ERROR `!` patterns are experimental
|
||||||
//~| ERROR `!` patterns are experimental
|
|
||||||
}
|
}
|
||||||
#[cfg(FALSE)]
|
#[cfg(FALSE)]
|
||||||
match *ptr {
|
match *ptr {
|
||||||
|
@ -51,14 +49,12 @@ fn main() {
|
||||||
match res {
|
match res {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(!),
|
Err(!),
|
||||||
//~^ ERROR `match` arm with no body
|
//~^ ERROR `!` patterns are experimental
|
||||||
//~| ERROR `!` patterns are experimental
|
|
||||||
}
|
}
|
||||||
match res {
|
match res {
|
||||||
Err(!) if false,
|
Err(!) if false,
|
||||||
//~^ ERROR `match` arm with no body
|
//~^ ERROR `!` patterns are experimental
|
||||||
//~| ERROR a guard on a never pattern will never be run
|
//~| ERROR a guard on a never pattern will never be run
|
||||||
//~| ERROR `!` patterns are experimental
|
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
error: unexpected `,` in pattern
|
error: unexpected `,` in pattern
|
||||||
--> $DIR/feature-gate-never_patterns.rs:36:16
|
--> $DIR/feature-gate-never_patterns.rs:34:16
|
||||||
|
|
|
|
||||||
LL | Some(_),
|
LL | Some(_),
|
||||||
| ^
|
| ^
|
||||||
|
@ -40,17 +40,7 @@ LL | !
|
||||||
= help: add `#![feature(never_patterns)]` to the crate attributes to enable
|
= help: add `#![feature(never_patterns)]` to the crate attributes to enable
|
||||||
|
|
||||||
error[E0658]: `!` patterns are experimental
|
error[E0658]: `!` patterns are experimental
|
||||||
--> $DIR/feature-gate-never_patterns.rs:15:13
|
--> $DIR/feature-gate-never_patterns.rs:21:13
|
||||||
|
|
|
||||||
LL | !
|
|
||||||
| ^
|
|
||||||
|
|
|
||||||
= note: see issue #118155 <https://github.com/rust-lang/rust/issues/118155> for more information
|
|
||||||
= help: add `#![feature(never_patterns)]` to the crate attributes to enable
|
|
||||||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
|
||||||
|
|
||||||
error[E0658]: `!` patterns are experimental
|
|
||||||
--> $DIR/feature-gate-never_patterns.rs:22:13
|
|
||||||
|
|
|
|
||||||
LL | !
|
LL | !
|
||||||
| ^
|
| ^
|
||||||
|
@ -59,17 +49,7 @@ LL | !
|
||||||
= help: add `#![feature(never_patterns)]` to the crate attributes to enable
|
= help: add `#![feature(never_patterns)]` to the crate attributes to enable
|
||||||
|
|
||||||
error[E0658]: `!` patterns are experimental
|
error[E0658]: `!` patterns are experimental
|
||||||
--> $DIR/feature-gate-never_patterns.rs:22:13
|
--> $DIR/feature-gate-never_patterns.rs:26:13
|
||||||
|
|
|
||||||
LL | !
|
|
||||||
| ^
|
|
||||||
|
|
|
||||||
= note: see issue #118155 <https://github.com/rust-lang/rust/issues/118155> for more information
|
|
||||||
= help: add `#![feature(never_patterns)]` to the crate attributes to enable
|
|
||||||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
|
||||||
|
|
||||||
error[E0658]: `!` patterns are experimental
|
|
||||||
--> $DIR/feature-gate-never_patterns.rs:28:13
|
|
||||||
|
|
|
|
||||||
LL | ! => {}
|
LL | ! => {}
|
||||||
| ^
|
| ^
|
||||||
|
@ -78,25 +58,25 @@ LL | ! => {}
|
||||||
= help: add `#![feature(never_patterns)]` to the crate attributes to enable
|
= help: add `#![feature(never_patterns)]` to the crate attributes to enable
|
||||||
|
|
||||||
error: `match` arm with no body
|
error: `match` arm with no body
|
||||||
--> $DIR/feature-gate-never_patterns.rs:41:9
|
--> $DIR/feature-gate-never_patterns.rs:39:9
|
||||||
|
|
|
|
||||||
LL | Some(_)
|
LL | Some(_)
|
||||||
| ^^^^^^^- help: add a body after the pattern: `=> todo!(),`
|
| ^^^^^^^- help: add a body after the pattern: `=> todo!(),`
|
||||||
|
|
||||||
error: `match` arm with no body
|
error: `match` arm with no body
|
||||||
--> $DIR/feature-gate-never_patterns.rs:46:9
|
--> $DIR/feature-gate-never_patterns.rs:44:9
|
||||||
|
|
|
|
||||||
LL | Some(_) if false,
|
LL | Some(_) if false,
|
||||||
| ^^^^^^^- help: add a body after the pattern: `=> todo!(),`
|
| ^^^^^^^- help: add a body after the pattern: `=> todo!(),`
|
||||||
|
|
||||||
error: `match` arm with no body
|
error: `match` arm with no body
|
||||||
--> $DIR/feature-gate-never_patterns.rs:48:9
|
--> $DIR/feature-gate-never_patterns.rs:46:9
|
||||||
|
|
|
|
||||||
LL | Some(_) if false
|
LL | Some(_) if false
|
||||||
| ^^^^^^^- help: add a body after the pattern: `=> todo!(),`
|
| ^^^^^^^- help: add a body after the pattern: `=> todo!(),`
|
||||||
|
|
||||||
error[E0658]: `!` patterns are experimental
|
error[E0658]: `!` patterns are experimental
|
||||||
--> $DIR/feature-gate-never_patterns.rs:53:13
|
--> $DIR/feature-gate-never_patterns.rs:51:13
|
||||||
|
|
|
|
||||||
LL | Err(!),
|
LL | Err(!),
|
||||||
| ^
|
| ^
|
||||||
|
@ -104,14 +84,8 @@ LL | Err(!),
|
||||||
= note: see issue #118155 <https://github.com/rust-lang/rust/issues/118155> for more information
|
= note: see issue #118155 <https://github.com/rust-lang/rust/issues/118155> for more information
|
||||||
= help: add `#![feature(never_patterns)]` to the crate attributes to enable
|
= help: add `#![feature(never_patterns)]` to the crate attributes to enable
|
||||||
|
|
||||||
error: `match` arm with no body
|
|
||||||
--> $DIR/feature-gate-never_patterns.rs:53:9
|
|
||||||
|
|
|
||||||
LL | Err(!),
|
|
||||||
| ^^^^^^- help: add a body after the pattern: `=> todo!(),`
|
|
||||||
|
|
||||||
error[E0658]: `!` patterns are experimental
|
error[E0658]: `!` patterns are experimental
|
||||||
--> $DIR/feature-gate-never_patterns.rs:58:13
|
--> $DIR/feature-gate-never_patterns.rs:55:13
|
||||||
|
|
|
|
||||||
LL | Err(!) if false,
|
LL | Err(!) if false,
|
||||||
| ^
|
| ^
|
||||||
|
@ -120,30 +94,24 @@ LL | Err(!) if false,
|
||||||
= help: add `#![feature(never_patterns)]` to the crate attributes to enable
|
= help: add `#![feature(never_patterns)]` to the crate attributes to enable
|
||||||
|
|
||||||
error: `match` arm with no body
|
error: `match` arm with no body
|
||||||
--> $DIR/feature-gate-never_patterns.rs:58:9
|
--> $DIR/feature-gate-never_patterns.rs:65:9
|
||||||
|
|
|
||||||
LL | Err(!) if false,
|
|
||||||
| ^^^^^^- help: add a body after the pattern: `=> todo!(),`
|
|
||||||
|
|
||||||
error: `match` arm with no body
|
|
||||||
--> $DIR/feature-gate-never_patterns.rs:69:9
|
|
||||||
|
|
|
|
||||||
LL | Some(_)
|
LL | Some(_)
|
||||||
| ^^^^^^^- help: add a body after the pattern: `=> todo!(),`
|
| ^^^^^^^- help: add a body after the pattern: `=> todo!(),`
|
||||||
|
|
||||||
error: `match` arm with no body
|
error: `match` arm with no body
|
||||||
--> $DIR/feature-gate-never_patterns.rs:75:9
|
--> $DIR/feature-gate-never_patterns.rs:71:9
|
||||||
|
|
|
|
||||||
LL | Some(_) if false
|
LL | Some(_) if false
|
||||||
| ^^^^^^^- help: add a body after the pattern: `=> todo!(),`
|
| ^^^^^^^- help: add a body after the pattern: `=> todo!(),`
|
||||||
|
|
||||||
error: a guard on a never pattern will never be run
|
error: a guard on a never pattern will never be run
|
||||||
--> $DIR/feature-gate-never_patterns.rs:58:19
|
--> $DIR/feature-gate-never_patterns.rs:55:19
|
||||||
|
|
|
|
||||||
LL | Err(!) if false,
|
LL | Err(!) if false,
|
||||||
| ^^^^^ help: remove this guard
|
| ^^^^^ help: remove this guard
|
||||||
|
|
||||||
error: aborting due to 18 previous errors
|
error: aborting due to 14 previous errors
|
||||||
|
|
||||||
Some errors have detailed explanations: E0408, E0658.
|
Some errors have detailed explanations: E0408, E0658.
|
||||||
For more information about an error, try `rustc --explain E0408`.
|
For more information about an error, try `rustc --explain E0408`.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue