Skip to content

Commit dfa355b

Browse files
bors[bot]Veykril
andauthored
Merge #10588
10588: internal: Parse const trait bounds r=Veykril a=Veykril Fixes #10582 bors r+ Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2 parents e77fc48 + b219a4c commit dfa355b

File tree

8 files changed

+45
-19
lines changed

8 files changed

+45
-19
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ miniz_oxide.opt-level = 3
1919

2020
[profile.release]
2121
incremental = true
22-
debug = 0 # Set this to 1 or 2 to get more useful backtraces in debugger.
22+
# Set this to 1 or 2 to get more useful backtraces in debugger.
23+
debug = 0
2324

2425
[patch.'crates-io']
2526
# rowan = { path = "../rowan" }

crates/parser/src/grammar/generic_params.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ fn lifetime_bounds(p: &mut Parser) {
100100
}
101101

102102
// test type_param_bounds
103-
// struct S<T: 'a + ?Sized + (Copy)>;
103+
// struct S<T: 'a + ?Sized + (Copy) + ~const Drop>;
104104
pub(super) fn bounds(p: &mut Parser) {
105105
assert!(p.at(T![:]));
106106
p.bump(T![:]);
@@ -124,14 +124,24 @@ pub(super) fn bounds_without_colon_m(p: &mut Parser, marker: Marker) -> Complete
124124
fn type_bound(p: &mut Parser) -> bool {
125125
let m = p.start();
126126
let has_paren = p.eat(T!['(']);
127-
p.eat(T![?]);
128127
match p.current() {
129128
LIFETIME_IDENT => lifetime(p),
130129
T![for] => types::for_type(p, false),
131-
_ if paths::is_use_path_start(p) => types::path_type_(p, false),
132-
_ => {
133-
m.abandon(p);
134-
return false;
130+
current => {
131+
match current {
132+
T![?] => p.bump_any(),
133+
T![~] => {
134+
p.bump_any();
135+
p.expect(T![const]);
136+
}
137+
_ => (),
138+
}
139+
if paths::is_use_path_start(p) {
140+
types::path_type_(p, false);
141+
} else {
142+
m.abandon(p);
143+
return false;
144+
}
135145
}
136146
}
137147
if has_paren {

crates/syntax/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ rayon = "1"
2929
expect-test = "1.2.0-pre.1"
3030
proc-macro2 = "1.0.8"
3131
quote = "1.0.2"
32-
ungrammar = "=1.14.8"
32+
ungrammar = "=1.14.9"
3333

3434
test_utils = { path = "../test_utils" }
3535
sourcegen = { path = "../sourcegen" }

crates/syntax/src/ast/generated/nodes.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,8 @@ pub struct TypeBound {
12711271
impl TypeBound {
12721272
pub fn lifetime(&self) -> Option<Lifetime> { support::child(&self.syntax) }
12731273
pub fn question_mark_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![?]) }
1274+
pub fn tilde_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![~]) }
1275+
pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) }
12741276
pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
12751277
}
12761278

crates/syntax/src/tests/sourcegen_ast.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ impl Field {
536536
"?" => "question_mark",
537537
"," => "comma",
538538
"|" => "pipe",
539+
"~" => "tilde",
539540
_ => name,
540541
};
541542
format_ident!("{}_token", name)

crates/syntax/test_data/parser/inline/ok/0007_type_param_bounds.rast

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
SOURCE_FILE@0..35
2-
STRUCT@0..34
1+
SOURCE_FILE@0..49
2+
STRUCT@0..48
33
STRUCT_KW@0..6 "struct"
44
WHITESPACE@6..7 " "
55
NAME@7..8
66
IDENT@7..8 "S"
7-
GENERIC_PARAM_LIST@8..33
7+
GENERIC_PARAM_LIST@8..47
88
L_ANGLE@8..9 "<"
9-
TYPE_PARAM@9..32
9+
TYPE_PARAM@9..46
1010
NAME@9..10
1111
IDENT@9..10 "T"
1212
COLON@10..11 ":"
1313
WHITESPACE@11..12 " "
14-
TYPE_BOUND_LIST@12..32
14+
TYPE_BOUND_LIST@12..46
1515
TYPE_BOUND@12..14
1616
LIFETIME@12..14
1717
LIFETIME_IDENT@12..14 "'a"
@@ -36,6 +36,18 @@ SOURCE_FILE@0..35
3636
NAME_REF@27..31
3737
IDENT@27..31 "Copy"
3838
R_PAREN@31..32 ")"
39-
R_ANGLE@32..33 ">"
40-
SEMICOLON@33..34 ";"
41-
WHITESPACE@34..35 "\n"
39+
WHITESPACE@32..33 " "
40+
PLUS@33..34 "+"
41+
WHITESPACE@34..35 " "
42+
TYPE_BOUND@35..46
43+
TILDE@35..36 "~"
44+
CONST_KW@36..41 "const"
45+
WHITESPACE@41..42 " "
46+
PATH_TYPE@42..46
47+
PATH@42..46
48+
PATH_SEGMENT@42..46
49+
NAME_REF@42..46
50+
IDENT@42..46 "Drop"
51+
R_ANGLE@46..47 ">"
52+
SEMICOLON@47..48 ";"
53+
WHITESPACE@48..49 "\n"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
struct S<T: 'a + ?Sized + (Copy)>;
1+
struct S<T: 'a + ?Sized + (Copy) + ~const Drop>;

0 commit comments

Comments
 (0)