Skip to content

Commit 289208b

Browse files
committed
Auto merge of rust-lang#14203 - shilangyu:fix/angled-path-segments, r=lnicola
fix: Add check for extra path segments after a fully qualified one `type A = <()>;` is parsed just fine by rust-analyzer, but then rejected by rustc: ``` error: expected `::`, found `;` --> x.rs:7:14 | 7 | type A = <()>; | ^ expected `::` ``` Fixed by adding a lookahead for the `::` token after fully-qualified path segments.
2 parents 9a4efb4 + 44e47fe commit 289208b

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

crates/hir-def/src/macro_expansion_tests/mbe/regression.rs

+1
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,7 @@ macro_rules! rgb_color {
827827
/* parse error: expected type */
828828
/* parse error: expected R_PAREN */
829829
/* parse error: expected R_ANGLE */
830+
/* parse error: expected `::` */
830831
/* parse error: expected COMMA */
831832
/* parse error: expected R_ANGLE */
832833
/* parse error: expected SEMICOLON */

crates/parser/src/grammar/paths.rs

+6
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ fn path_segment(p: &mut Parser<'_>, mode: Mode, first: bool) {
7777
// type X = <A as B>::Output;
7878
// fn foo() { <usize as Default>::default(); }
7979
if first && p.eat(T![<]) {
80+
// test_err angled_path_without_qual
81+
// type X = <()>;
82+
// type Y = <A as B>;
8083
types::type_(p);
8184
if p.eat(T![as]) {
8285
if is_use_path_start(p) {
@@ -86,6 +89,9 @@ fn path_segment(p: &mut Parser<'_>, mode: Mode, first: bool) {
8689
}
8790
}
8891
p.expect(T![>]);
92+
if !p.at(T![::]) {
93+
p.error("expected `::`");
94+
}
8995
} else {
9096
let empty = if first {
9197
p.eat(T![::]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
SOURCE_FILE
2+
TYPE_ALIAS
3+
TYPE_KW "type"
4+
WHITESPACE " "
5+
NAME
6+
IDENT "X"
7+
WHITESPACE " "
8+
EQ "="
9+
WHITESPACE " "
10+
PATH_TYPE
11+
PATH
12+
PATH_SEGMENT
13+
L_ANGLE "<"
14+
TUPLE_TYPE
15+
L_PAREN "("
16+
R_PAREN ")"
17+
R_ANGLE ">"
18+
SEMICOLON ";"
19+
WHITESPACE "\n"
20+
TYPE_ALIAS
21+
TYPE_KW "type"
22+
WHITESPACE " "
23+
NAME
24+
IDENT "Y"
25+
WHITESPACE " "
26+
EQ "="
27+
WHITESPACE " "
28+
PATH_TYPE
29+
PATH
30+
PATH_SEGMENT
31+
L_ANGLE "<"
32+
PATH_TYPE
33+
PATH
34+
PATH_SEGMENT
35+
NAME_REF
36+
IDENT "A"
37+
WHITESPACE " "
38+
AS_KW "as"
39+
WHITESPACE " "
40+
PATH_TYPE
41+
PATH
42+
PATH_SEGMENT
43+
NAME_REF
44+
IDENT "B"
45+
R_ANGLE ">"
46+
SEMICOLON ";"
47+
WHITESPACE "\n"
48+
error 13: expected `::`
49+
error 32: expected `::`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
type X = <()>;
2+
type Y = <A as B>;

0 commit comments

Comments
 (0)