Skip to content

Commit 665a876

Browse files
committed
pre-expansion gate exclusive_range_pattern
1 parent 2aff6b3 commit 665a876

File tree

8 files changed

+33
-28
lines changed

8 files changed

+33
-28
lines changed

src/libsyntax/feature_gate/check.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ use super::accepted::ACCEPTED_FEATURES;
33
use super::removed::{REMOVED_FEATURES, STABLE_REMOVED_FEATURES};
44
use super::builtin_attrs::{AttributeGate, BUILTIN_ATTRIBUTE_MAP};
55

6-
use crate::ast::{self, NodeId, PatKind, RangeEnd, VariantData};
6+
use crate::ast::{self, NodeId, PatKind, VariantData};
77
use crate::attr::{self, check_builtin_attribute};
8-
use crate::source_map::Spanned;
98
use crate::edition::{ALL_EDITIONS, Edition};
109
use crate::visit::{self, FnKind, Visitor};
1110
use crate::parse::token;
@@ -529,10 +528,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
529528
}
530529
}
531530
}
532-
PatKind::Range(_, _, Spanned { node: RangeEnd::Excluded, .. }) => {
533-
gate_feature_post!(&self, exclusive_range_pattern, pattern.span,
534-
"exclusive range pattern syntax is experimental");
535-
}
536531
_ => {}
537532
}
538533
visit::walk_pat(self, pattern)
@@ -815,6 +810,7 @@ pub fn check_crate(krate: &ast::Crate,
815810
gate_all!(const_generics, "const generics are unstable");
816811
gate_all!(decl_macro, "`macro` is experimental");
817812
gate_all!(box_patterns, "box pattern syntax is experimental");
813+
gate_all!(exclusive_range_pattern, "exclusive range pattern syntax is experimental");
818814

819815
visit::walk_crate(&mut visitor, krate);
820816
}

src/libsyntax/parse/parser/pat.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,11 @@ impl<'a> Parser<'a> {
611611
Ok(PatKind::Mac(mac))
612612
}
613613

614+
fn excluded_range_end(&self, span: Span) -> RangeEnd {
615+
self.sess.gated_spans.exclusive_range_pattern.borrow_mut().push(span);
616+
RangeEnd::Excluded
617+
}
618+
614619
/// Parse a range pattern `$path $form $end?` where `$form = ".." | "..." | "..=" ;`.
615620
/// The `$path` has already been parsed and the next token is the `$form`.
616621
fn parse_pat_range_starting_with_path(
@@ -620,7 +625,7 @@ impl<'a> Parser<'a> {
620625
path: Path
621626
) -> PResult<'a, PatKind> {
622627
let (end_kind, form) = match self.token.kind {
623-
token::DotDot => (RangeEnd::Excluded, ".."),
628+
token::DotDot => (self.excluded_range_end(self.token.span), ".."),
624629
token::DotDotDot => (RangeEnd::Included(RangeSyntax::DotDotDot), "..."),
625630
token::DotDotEq => (RangeEnd::Included(RangeSyntax::DotDotEq), "..="),
626631
_ => panic!("can only parse `..`/`...`/`..=` for ranges (checked above)"),
@@ -643,7 +648,7 @@ impl<'a> Parser<'a> {
643648
} else if self.eat(&token::DotDotEq) {
644649
(RangeEnd::Included(RangeSyntax::DotDotEq), "..=")
645650
} else if self.eat(&token::DotDot) {
646-
(RangeEnd::Excluded, "..")
651+
(self.excluded_range_end(op_span), "..")
647652
} else {
648653
panic!("impossible case: we already matched on a range-operator token")
649654
};

src/libsyntax/sess.rs

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ crate struct GatedSpans {
4242
pub decl_macro: Lock<Vec<Span>>,
4343
/// Spans collected for gating `box_patterns`, e.g. `box 0`.
4444
pub box_patterns: Lock<Vec<Span>>,
45+
/// Spans collected for gating `exclusive_range_pattern`, e.g. `0..2`.
46+
pub exclusive_range_pattern: Lock<Vec<Span>>,
4547
}
4648

4749
/// Info about a parsing session.
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
pub fn main() {
1+
#[cfg(FALSE)]
2+
fn foo() {
23
match 22 {
34
0 .. 3 => {} //~ ERROR exclusive range pattern syntax is experimental
5+
PATH .. 3 => {} //~ ERROR exclusive range pattern syntax is experimental
46
_ => {}
57
}
68
}
9+
10+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
error[E0658]: exclusive range pattern syntax is experimental
2-
--> $DIR/feature-gate-exclusive-range-pattern.rs:3:9
2+
--> $DIR/feature-gate-exclusive-range-pattern.rs:4:11
33
|
44
LL | 0 .. 3 => {}
5-
| ^^^^^^
5+
| ^^
66
|
77
= note: for more information, see https://github.com/rust-lang/rust/issues/37854
88
= help: add `#![feature(exclusive_range_pattern)]` to the crate attributes to enable
99

10-
error: aborting due to previous error
10+
error[E0658]: exclusive range pattern syntax is experimental
11+
--> $DIR/feature-gate-exclusive-range-pattern.rs:5:14
12+
|
13+
LL | PATH .. 3 => {}
14+
| ^^
15+
|
16+
= note: for more information, see https://github.com/rust-lang/rust/issues/37854
17+
= help: add `#![feature(exclusive_range_pattern)]` to the crate attributes to enable
18+
19+
error: aborting due to 2 previous errors
1120

1221
For more information about this error, try `rustc --explain E0658`.

src/test/ui/parser/pat-tuple-4.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ fn main() {
44
match 0 {
55
(.. PAT) => {}
66
//~^ ERROR `..X` range patterns are not supported
7-
//~| ERROR exclusive range pattern syntax is experimental
87
}
98
}
109

src/test/ui/parser/pat-tuple-4.stderr

+3-13
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,15 @@ error: `..X` range patterns are not supported
44
LL | (.. PAT) => {}
55
| ^^^^^^ help: try using the minimum value for the type: `MIN..PAT`
66

7-
error[E0658]: exclusive range pattern syntax is experimental
8-
--> $DIR/pat-tuple-4.rs:5:10
9-
|
10-
LL | (.. PAT) => {}
11-
| ^^^^^^
12-
|
13-
= note: for more information, see https://github.com/rust-lang/rust/issues/37854
14-
= help: add `#![feature(exclusive_range_pattern)]` to the crate attributes to enable
15-
167
error[E0308]: mismatched types
17-
--> $DIR/pat-tuple-4.rs:11:30
8+
--> $DIR/pat-tuple-4.rs:10:30
189
|
1910
LL | const RECOVERY_WITNESS: () = 0;
2011
| ^ expected (), found integer
2112
|
2213
= note: expected type `()`
2314
found type `{integer}`
2415

25-
error: aborting due to 3 previous errors
16+
error: aborting due to 2 previous errors
2617

27-
Some errors have detailed explanations: E0308, E0658.
28-
For more information about an error, try `rustc --explain E0308`.
18+
For more information about this error, try `rustc --explain E0308`.

src/test/ui/parser/pat-tuple-5.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ LL | (PAT ..) => {}
55
| ^^^^^^ help: try using the maximum value for the type: `PAT..MAX`
66

77
error[E0658]: exclusive range pattern syntax is experimental
8-
--> $DIR/pat-tuple-5.rs:5:10
8+
--> $DIR/pat-tuple-5.rs:5:14
99
|
1010
LL | (PAT ..) => {}
11-
| ^^^^^^
11+
| ^^
1212
|
1313
= note: for more information, see https://github.com/rust-lang/rust/issues/37854
1414
= help: add `#![feature(exclusive_range_pattern)]` to the crate attributes to enable

0 commit comments

Comments
 (0)