mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-14 17:07:26 +00:00
Auto merge of #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.
This commit is contained in:
commit
289208bc9f
4 changed files with 58 additions and 0 deletions
|
@ -827,6 +827,7 @@ macro_rules! rgb_color {
|
|||
/* parse error: expected type */
|
||||
/* parse error: expected R_PAREN */
|
||||
/* parse error: expected R_ANGLE */
|
||||
/* parse error: expected `::` */
|
||||
/* parse error: expected COMMA */
|
||||
/* parse error: expected R_ANGLE */
|
||||
/* parse error: expected SEMICOLON */
|
||||
|
|
|
@ -77,6 +77,9 @@ fn path_segment(p: &mut Parser<'_>, mode: Mode, first: bool) {
|
|||
// type X = <A as B>::Output;
|
||||
// fn foo() { <usize as Default>::default(); }
|
||||
if first && p.eat(T![<]) {
|
||||
// test_err angled_path_without_qual
|
||||
// type X = <()>;
|
||||
// type Y = <A as B>;
|
||||
types::type_(p);
|
||||
if p.eat(T![as]) {
|
||||
if is_use_path_start(p) {
|
||||
|
@ -86,6 +89,9 @@ fn path_segment(p: &mut Parser<'_>, mode: Mode, first: bool) {
|
|||
}
|
||||
}
|
||||
p.expect(T![>]);
|
||||
if !p.at(T![::]) {
|
||||
p.error("expected `::`");
|
||||
}
|
||||
} else {
|
||||
let empty = if first {
|
||||
p.eat(T![::]);
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
SOURCE_FILE
|
||||
TYPE_ALIAS
|
||||
TYPE_KW "type"
|
||||
WHITESPACE " "
|
||||
NAME
|
||||
IDENT "X"
|
||||
WHITESPACE " "
|
||||
EQ "="
|
||||
WHITESPACE " "
|
||||
PATH_TYPE
|
||||
PATH
|
||||
PATH_SEGMENT
|
||||
L_ANGLE "<"
|
||||
TUPLE_TYPE
|
||||
L_PAREN "("
|
||||
R_PAREN ")"
|
||||
R_ANGLE ">"
|
||||
SEMICOLON ";"
|
||||
WHITESPACE "\n"
|
||||
TYPE_ALIAS
|
||||
TYPE_KW "type"
|
||||
WHITESPACE " "
|
||||
NAME
|
||||
IDENT "Y"
|
||||
WHITESPACE " "
|
||||
EQ "="
|
||||
WHITESPACE " "
|
||||
PATH_TYPE
|
||||
PATH
|
||||
PATH_SEGMENT
|
||||
L_ANGLE "<"
|
||||
PATH_TYPE
|
||||
PATH
|
||||
PATH_SEGMENT
|
||||
NAME_REF
|
||||
IDENT "A"
|
||||
WHITESPACE " "
|
||||
AS_KW "as"
|
||||
WHITESPACE " "
|
||||
PATH_TYPE
|
||||
PATH
|
||||
PATH_SEGMENT
|
||||
NAME_REF
|
||||
IDENT "B"
|
||||
R_ANGLE ">"
|
||||
SEMICOLON ";"
|
||||
WHITESPACE "\n"
|
||||
error 13: expected `::`
|
||||
error 32: expected `::`
|
|
@ -0,0 +1,2 @@
|
|||
type X = <()>;
|
||||
type Y = <A as B>;
|
Loading…
Reference in a new issue