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