mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
fix: Don't create empty path nodes
This commit is contained in:
parent
b6fc9c14ac
commit
caba872f88
6 changed files with 26 additions and 24 deletions
|
@ -242,7 +242,7 @@ fn opt_visibility(p: &mut Parser<'_>, in_tuple_field: bool) -> bool {
|
|||
// struct MyStruct(pub ());
|
||||
if !(in_tuple_field && matches!(p.nth(1), T![ident] | T![')'])) {
|
||||
p.bump(T!['(']);
|
||||
paths::use_path(p);
|
||||
paths::vis_path(p);
|
||||
p.expect(T![')']);
|
||||
}
|
||||
}
|
||||
|
@ -252,7 +252,7 @@ fn opt_visibility(p: &mut Parser<'_>, in_tuple_field: bool) -> bool {
|
|||
T![in] => {
|
||||
p.bump(T!['(']);
|
||||
p.bump(T![in]);
|
||||
paths::use_path(p);
|
||||
paths::vis_path(p);
|
||||
p.expect(T![')']);
|
||||
}
|
||||
_ => {}
|
||||
|
|
|
@ -168,10 +168,10 @@ pub(super) fn const_arg_expr(p: &mut Parser<'_>) {
|
|||
expressions::literal(p);
|
||||
lm.complete(p, PREFIX_EXPR);
|
||||
}
|
||||
_ if paths::is_use_path_start(p) => {
|
||||
_ if paths::is_path_start(p) => {
|
||||
// This shouldn't be hit by `const_arg`
|
||||
let lm = p.start();
|
||||
paths::use_path(p);
|
||||
paths::expr_path(p);
|
||||
lm.complete(p, PATH_EXPR);
|
||||
}
|
||||
_ => {
|
||||
|
|
|
@ -19,6 +19,10 @@ pub(super) fn use_path(p: &mut Parser<'_>) {
|
|||
path(p, Mode::Use);
|
||||
}
|
||||
|
||||
pub(super) fn vis_path(p: &mut Parser<'_>) {
|
||||
path(p, Mode::Vis);
|
||||
}
|
||||
|
||||
pub(super) fn attr_path(p: &mut Parser<'_>) {
|
||||
path(p, Mode::Attr);
|
||||
}
|
||||
|
@ -44,13 +48,17 @@ enum Mode {
|
|||
Attr,
|
||||
Type,
|
||||
Expr,
|
||||
Vis,
|
||||
}
|
||||
|
||||
fn path(p: &mut Parser<'_>, mode: Mode) {
|
||||
fn path(p: &mut Parser<'_>, mode: Mode) -> Option<CompletedMarker> {
|
||||
let path = p.start();
|
||||
path_segment(p, mode, true);
|
||||
if path_segment(p, mode, true).is_none() {
|
||||
path.abandon(p);
|
||||
return None;
|
||||
}
|
||||
let qual = path.complete(p, PATH);
|
||||
path_for_qualifier(p, mode, qual);
|
||||
Some(path_for_qualifier(p, mode, qual))
|
||||
}
|
||||
|
||||
fn path_for_qualifier(
|
||||
|
@ -76,7 +84,7 @@ const EXPR_PATH_SEGMENT_RECOVERY_SET: TokenSet =
|
|||
items::ITEM_RECOVERY_SET.union(TokenSet::new(&[T![')'], T![,], T![let]]));
|
||||
const TYPE_PATH_SEGMENT_RECOVERY_SET: TokenSet = types::TYPE_RECOVERY_SET;
|
||||
|
||||
fn path_segment(p: &mut Parser<'_>, mode: Mode, first: bool) {
|
||||
fn path_segment(p: &mut Parser<'_>, mode: Mode, first: bool) -> Option<CompletedMarker> {
|
||||
let m = p.start();
|
||||
// test qual_paths
|
||||
// type X = <A as B>::Output;
|
||||
|
@ -117,6 +125,7 @@ fn path_segment(p: &mut Parser<'_>, mode: Mode, first: bool) {
|
|||
Mode::Attr => {
|
||||
items::ITEM_RECOVERY_SET.union(TokenSet::new(&[T![']'], T![=], T![#]]))
|
||||
}
|
||||
Mode::Vis => items::ITEM_RECOVERY_SET.union(TokenSet::new(&[T![')']])),
|
||||
Mode::Type => TYPE_PATH_SEGMENT_RECOVERY_SET,
|
||||
Mode::Expr => EXPR_PATH_SEGMENT_RECOVERY_SET,
|
||||
};
|
||||
|
@ -125,17 +134,17 @@ fn path_segment(p: &mut Parser<'_>, mode: Mode, first: bool) {
|
|||
// test_err empty_segment
|
||||
// use crate::;
|
||||
m.abandon(p);
|
||||
return;
|
||||
return None;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
m.complete(p, PATH_SEGMENT);
|
||||
Some(m.complete(p, PATH_SEGMENT))
|
||||
}
|
||||
|
||||
fn opt_path_type_args(p: &mut Parser<'_>, mode: Mode) {
|
||||
match mode {
|
||||
Mode::Use | Mode::Attr => {}
|
||||
Mode::Use | Mode::Attr | Mode::Vis => {}
|
||||
Mode::Type => {
|
||||
// test typepathfn_with_coloncolon
|
||||
// type F = Start::(Middle) -> (Middle)::End;
|
||||
|
|
|
@ -327,10 +327,10 @@ impl Marker {
|
|||
self.bomb.defuse();
|
||||
let idx = self.pos as usize;
|
||||
if idx == p.events.len() - 1 {
|
||||
match p.events.pop() {
|
||||
Some(Event::Start { kind: TOMBSTONE, forward_parent: None }) => (),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
assert!(matches!(
|
||||
p.events.pop(),
|
||||
Some(Event::Start { kind: TOMBSTONE, forward_parent: None })
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,10 +3,7 @@ SOURCE_FILE
|
|||
VISIBILITY
|
||||
PUB_KW "pub"
|
||||
L_PAREN "("
|
||||
PATH
|
||||
PATH_SEGMENT
|
||||
ERROR
|
||||
R_PAREN ")"
|
||||
R_PAREN ")"
|
||||
WHITESPACE " "
|
||||
STRUCT_KW "struct"
|
||||
WHITESPACE " "
|
||||
|
@ -15,4 +12,3 @@ SOURCE_FILE
|
|||
SEMICOLON ";"
|
||||
WHITESPACE "\n"
|
||||
error 4: expected identifier
|
||||
error 5: expected R_PAREN
|
||||
|
|
|
@ -4,7 +4,6 @@ SOURCE_FILE
|
|||
BANG "!"
|
||||
L_BRACK "["
|
||||
META
|
||||
PATH
|
||||
R_BRACK "]"
|
||||
WHITESPACE "\n"
|
||||
ATTR
|
||||
|
@ -55,7 +54,6 @@ SOURCE_FILE
|
|||
L_BRACK "["
|
||||
META
|
||||
UNSAFE_KW "unsafe"
|
||||
PATH
|
||||
R_BRACK "]"
|
||||
WHITESPACE "\n"
|
||||
ATTR
|
||||
|
@ -65,7 +63,6 @@ SOURCE_FILE
|
|||
META
|
||||
UNSAFE_KW "unsafe"
|
||||
WHITESPACE " "
|
||||
PATH
|
||||
EQ "="
|
||||
R_BRACK "]"
|
||||
WHITESPACE "\n"
|
||||
|
@ -80,7 +77,7 @@ error 41: expected L_PAREN
|
|||
error 41: expected identifier
|
||||
error 41: expected R_PAREN
|
||||
error 52: expected L_PAREN
|
||||
error 53: expected identifier
|
||||
error 52: expected identifier
|
||||
error 54: expected expression
|
||||
error 54: expected expression
|
||||
error 54: expected R_PAREN
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue