Skip to content

Commit 950efff

Browse files
bors[bot]lf-
andauthored
Merge #9780
9780: Support exclusive_range_pattern r=matklad a=lf- Fix #9779 Co-authored-by: Jade <software@lfcode.ca>
2 parents ec75384 + 775670e commit 950efff

File tree

12 files changed

+105
-41
lines changed

12 files changed

+105
-41
lines changed

crates/hir/src/semantics/source_to_def.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
//! The `GetDeclaredType` takes `Syntax` as input, and returns `Symbol` as
5252
//! output. First, it retrieves a `Symbol` for parent `Syntax`:
5353
//!
54-
//! * https://sourceroslyn.io/#Microsoft.CodeAnalysis.CSharp/Compilation/SyntaxTreeSemanticModel.cs,1423
54+
//! * <https://sourceroslyn.io/#Microsoft.CodeAnalysis.CSharp/Compilation/SyntaxTreeSemanticModel.cs,1423>
5555
//!
5656
//! Then, it iterates parent symbol's children, looking for one which has the
5757
//! same text span as the original node:

crates/hir_ty/src/diagnostics/match_check/deconstruct_pat.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@
3939
//!
4040
//! Splitting is implemented in the [`Constructor::split`] function. We don't do splitting for
4141
//! or-patterns; instead we just try the alternatives one-by-one. For details on splitting
42-
//! wildcards, see [`SplitWildcard`]; for integer ranges, see [`SplitIntRange`]; for slices, see
43-
//! [`SplitVarLenSlice`].
42+
//! wildcards, see [`SplitWildcard`]; for integer ranges, see [`SplitIntRange`].
4443
4544
use std::{
4645
cmp::{max, min},

crates/ide_db/src/helpers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ pub fn visit_file_defs(
120120
///
121121
/// Note that, by default, rust-analyzer tests **do not** include core or std
122122
/// libraries. If you are writing tests for functionality using [`FamousDefs`],
123-
/// you'd want to include [minicore](test_utils::MiniCore) declaration at the
124-
/// start of your tests:
123+
/// you'd want to include minicore (see `test_utils::MiniCore`) declaration at
124+
/// the start of your tests:
125125
///
126126
/// ```
127127
/// //- minicore: iterator, ord, derive

crates/parser/src/grammar.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
//! each submodule starts with `use super::*` import and exports
77
//! "public" productions via `pub(super)`.
88
//!
9-
//! See docs for `Parser` to learn about API, available to the grammar,
10-
//! and see docs for `Event` to learn how this actually manages to
11-
//! produce parse trees.
9+
//! See docs for [`Parser`](super::parser::Parser) to learn about API,
10+
//! available to the grammar, and see docs for [`Event`](super::event::Event)
11+
//! to learn how this actually manages to produce parse trees.
1212
//!
1313
//! Code in this module also contains inline tests, which start with
1414
//! `// test name-of-the-test` comment and look like this:

crates/parser/src/grammar/patterns.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,26 @@ fn pattern_single_r(p: &mut Parser, recovery_set: TokenSet) {
6565
// match 92 {
6666
// 0 ... 100 => (),
6767
// 101 ..= 200 => (),
68-
// 200 .. 301=> (),
68+
// 200 .. 301 => (),
69+
// 302 .. => (),
6970
// }
7071
// }
72+
73+
// FIXME: support half_open_range_patterns (`..=2`),
74+
// exclusive_range_pattern (`..5`) with missing lhs
7175
for &range_op in [T![...], T![..=], T![..]].iter() {
7276
if p.at(range_op) {
7377
let m = lhs.precede(p);
7478
p.bump(range_op);
75-
atom_pat(p, recovery_set);
79+
80+
// `0 .. =>` or `let 0 .. =`
81+
// ^ ^
82+
if p.at(T![=]) {
83+
// test half_open_range_pat
84+
// fn f() { let 0 .. = 1u32; }
85+
} else {
86+
atom_pat(p, recovery_set);
87+
}
7688
m.complete(p, RANGE_PAT);
7789
return;
7890
}
@@ -84,7 +96,7 @@ const PAT_RECOVERY_SET: TokenSet =
8496
TokenSet::new(&[T![let], T![if], T![while], T![loop], T![match], T![')'], T![,], T![=]]);
8597

8698
fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> {
87-
let m = match p.nth(0) {
99+
let m = match p.current() {
88100
T![box] => box_pat(p),
89101
T![ref] | T![mut] => ident_pat(p, true),
90102
T![const] => const_block_pat(p),

crates/parser/src/lib.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
//! The Rust parser.
22
//!
33
//! The parser doesn't know about concrete representation of tokens and syntax
4-
//! trees. Abstract `TokenSource` and `TreeSink` traits are used instead. As a
5-
//! consequence, this crates does not contain a lexer.
4+
//! trees. Abstract [`TokenSource`] and [`TreeSink`] traits are used instead.
5+
//! As a consequence, this crate does not contain a lexer.
66
//!
7-
//! The `Parser` struct from the `parser` module is a cursor into the sequence
8-
//! of tokens. Parsing routines use `Parser` to inspect current state and
9-
//! advance the parsing.
7+
//! The [`Parser`] struct from the [`parser`] module is a cursor into the
8+
//! sequence of tokens. Parsing routines use [`Parser`] to inspect current
9+
//! state and advance the parsing.
1010
//!
11-
//! The actual parsing happens in the `grammar` module.
11+
//! The actual parsing happens in the [`grammar`] module.
1212
//!
13-
//! Tests for this crate live in `syntax` crate.
13+
//! Tests for this crate live in the `syntax` crate.
14+
//!
15+
//! [`Parser`]: crate::parser::Parser
1416
17+
#![allow(rustdoc::private_intra_doc_links)]
1518
#[macro_use]
1619
mod token_set;
1720
#[macro_use]

crates/parser/src/parser.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::{
1414
/// `Parser` struct provides the low-level API for
1515
/// navigating through the stream of tokens and
1616
/// constructing the parse tree. The actual parsing
17-
/// happens in the `grammar` module.
17+
/// happens in the [`grammar`](super::grammar) module.
1818
///
1919
/// However, the result of this `Parser` is not a real
2020
/// tree, but rather a flat stream of events of the form
@@ -262,7 +262,7 @@ impl<'t> Parser<'t> {
262262
}
263263
}
264264

265-
/// See `Parser::start`.
265+
/// See [`Parser::start`].
266266
pub(crate) struct Marker {
267267
pos: u32,
268268
bomb: DropBomb,
@@ -320,7 +320,8 @@ impl CompletedMarker {
320320
/// node `A`, then complete it, and then after parsing the
321321
/// whole `A`, decide that it should have started some node
322322
/// `B` before starting `A`. `precede` allows to do exactly
323-
/// that. See also docs about `forward_parent` in `Event::Start`.
323+
/// that. See also docs about
324+
/// [`Event::Start::forward_parent`](crate::event::Event::Start::forward_parent).
324325
///
325326
/// Given completed events `[START, FINISH]` and its corresponding
326327
/// `CompletedMarker(pos: 0, _)`.

crates/syntax/src/ast/node_ext.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,12 @@ pub enum AttrKind {
197197
}
198198

199199
impl AttrKind {
200-
/// Returns `true` if the attr_kind is [`Inner`].
200+
/// Returns `true` if the attr_kind is [`Inner`](Self::Inner).
201201
pub fn is_inner(&self) -> bool {
202202
matches!(self, Self::Inner)
203203
}
204204

205-
/// Returns `true` if the attr_kind is [`Outer`].
205+
/// Returns `true` if the attr_kind is [`Outer`](Self::Outer).
206206
pub fn is_outer(&self) -> bool {
207207
matches!(self, Self::Outer)
208208
}

crates/syntax/test_data/parser/inline/ok/0058_range_pat.rast

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
SOURCE_FILE@0..112
2-
FN@0..111
1+
SOURCE_FILE@0..135
2+
FN@0..134
33
FN_KW@0..2 "fn"
44
WHITESPACE@2..3 " "
55
NAME@3..7
@@ -8,16 +8,16 @@ SOURCE_FILE@0..112
88
L_PAREN@7..8 "("
99
R_PAREN@8..9 ")"
1010
WHITESPACE@9..10 " "
11-
BLOCK_EXPR@10..111
11+
BLOCK_EXPR@10..134
1212
L_CURLY@10..11 "{"
1313
WHITESPACE@11..16 "\n "
14-
MATCH_EXPR@16..109
14+
MATCH_EXPR@16..132
1515
MATCH_KW@16..21 "match"
1616
WHITESPACE@21..22 " "
1717
LITERAL@22..24
1818
INT_NUMBER@22..24 "92"
1919
WHITESPACE@24..25 " "
20-
MATCH_ARM_LIST@25..109
20+
MATCH_ARM_LIST@25..132
2121
L_CURLY@25..26 "{"
2222
WHITESPACE@26..35 "\n "
2323
MATCH_ARM@35..51
@@ -58,7 +58,7 @@ SOURCE_FILE@0..112
5858
R_PAREN@76..77 ")"
5959
COMMA@77..78 ","
6060
WHITESPACE@78..87 "\n "
61-
MATCH_ARM@87..103
61+
MATCH_ARM@87..104
6262
RANGE_PAT@87..97
6363
LITERAL_PAT@87..90
6464
LITERAL@87..90
@@ -69,14 +69,30 @@ SOURCE_FILE@0..112
6969
LITERAL_PAT@94..97
7070
LITERAL@94..97
7171
INT_NUMBER@94..97 "301"
72-
FAT_ARROW@97..99 "=>"
73-
WHITESPACE@99..100 " "
74-
TUPLE_EXPR@100..102
75-
L_PAREN@100..101 "("
76-
R_PAREN@101..102 ")"
77-
COMMA@102..103 ","
78-
WHITESPACE@103..108 "\n "
79-
R_CURLY@108..109 "}"
80-
WHITESPACE@109..110 "\n"
81-
R_CURLY@110..111 "}"
82-
WHITESPACE@111..112 "\n"
72+
WHITESPACE@97..98 " "
73+
FAT_ARROW@98..100 "=>"
74+
WHITESPACE@100..101 " "
75+
TUPLE_EXPR@101..103
76+
L_PAREN@101..102 "("
77+
R_PAREN@102..103 ")"
78+
COMMA@103..104 ","
79+
WHITESPACE@104..113 "\n "
80+
MATCH_ARM@113..126
81+
RANGE_PAT@113..119
82+
LITERAL_PAT@113..116
83+
LITERAL@113..116
84+
INT_NUMBER@113..116 "302"
85+
WHITESPACE@116..117 " "
86+
DOT2@117..119 ".."
87+
WHITESPACE@119..120 " "
88+
FAT_ARROW@120..122 "=>"
89+
WHITESPACE@122..123 " "
90+
TUPLE_EXPR@123..125
91+
L_PAREN@123..124 "("
92+
R_PAREN@124..125 ")"
93+
COMMA@125..126 ","
94+
WHITESPACE@126..131 "\n "
95+
R_CURLY@131..132 "}"
96+
WHITESPACE@132..133 "\n"
97+
R_CURLY@133..134 "}"
98+
WHITESPACE@134..135 "\n"

crates/syntax/test_data/parser/inline/ok/0058_range_pat.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ fn main() {
22
match 92 {
33
0 ... 100 => (),
44
101 ..= 200 => (),
5-
200 .. 301=> (),
5+
200 .. 301 => (),
6+
302 .. => (),
67
}
78
}

0 commit comments

Comments
 (0)