mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-23 20:04:21 +00:00
Support GATs for associated type arg parsing
This commit is contained in:
parent
a2f83c956e
commit
e7aa37c20a
6 changed files with 165 additions and 82 deletions
|
@ -27,6 +27,10 @@ pub(super) fn expr_path(p: &mut Parser) {
|
|||
path(p, Mode::Expr)
|
||||
}
|
||||
|
||||
pub(crate) fn type_path_for_qualifier(p: &mut Parser, qual: CompletedMarker) {
|
||||
path_for_qualifier(p, Mode::Type, qual)
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Eq, PartialEq)]
|
||||
enum Mode {
|
||||
Use,
|
||||
|
@ -37,7 +41,11 @@ enum Mode {
|
|||
fn path(p: &mut Parser, mode: Mode) {
|
||||
let path = p.start();
|
||||
path_segment(p, mode, true);
|
||||
let mut qual = path.complete(p, PATH);
|
||||
let qual = path.complete(p, PATH);
|
||||
path_for_qualifier(p, mode, qual)
|
||||
}
|
||||
|
||||
fn path_for_qualifier(p: &mut Parser, mode: Mode, mut qual: CompletedMarker) {
|
||||
loop {
|
||||
let use_tree = matches!(p.nth(2), T![*] | T!['{']);
|
||||
if p.at(T![::]) && !use_tree {
|
||||
|
|
|
@ -65,17 +65,51 @@ fn generic_arg(p: &mut Parser) {
|
|||
m.complete(p, LIFETIME_ARG);
|
||||
}
|
||||
// test associated_type_bounds
|
||||
// fn print_all<T: Iterator<Item: Display>>(printables: T) {}
|
||||
IDENT if p.nth(1) == T![:] && p.nth(2) != T![:] => {
|
||||
// fn print_all<T: Iterator<Item, Item::Item, Item: Display, Item<'a> = Item>>(printables: T) {}
|
||||
IDENT if [T![<], T![=], T![:]].contains(&p.nth(1)) => {
|
||||
let path_ty = p.start();
|
||||
let path = p.start();
|
||||
let path_seg = p.start();
|
||||
name_ref(p);
|
||||
type_params::bounds(p);
|
||||
m.complete(p, ASSOC_TYPE_ARG);
|
||||
}
|
||||
IDENT if p.nth(1) == T![=] => {
|
||||
name_ref(p);
|
||||
p.bump_any();
|
||||
types::type_(p);
|
||||
m.complete(p, ASSOC_TYPE_ARG);
|
||||
if p.current() == T![<] {
|
||||
opt_generic_arg_list(p, false);
|
||||
}
|
||||
match p.current() {
|
||||
// NameRef<...> =
|
||||
T![=] => {
|
||||
p.bump_any();
|
||||
types::type_(p);
|
||||
|
||||
path_seg.abandon(p);
|
||||
path.abandon(p);
|
||||
path_ty.abandon(p);
|
||||
m.complete(p, ASSOC_TYPE_ARG);
|
||||
}
|
||||
T![:] if p.nth(1) == T![:] => {
|
||||
// NameRef::, this is a path type
|
||||
path_seg.complete(p, PATH_SEGMENT);
|
||||
let qual = path.complete(p, PATH);
|
||||
paths::type_path_for_qualifier(p, qual);
|
||||
path_ty.complete(p, PATH_TYPE);
|
||||
m.complete(p, TYPE_ARG);
|
||||
}
|
||||
// NameRef<...>:
|
||||
T![:] => {
|
||||
type_params::bounds(p);
|
||||
|
||||
path_seg.abandon(p);
|
||||
path.abandon(p);
|
||||
path_ty.abandon(p);
|
||||
m.complete(p, ASSOC_TYPE_ARG);
|
||||
}
|
||||
// NameRef, this is a single segment path type
|
||||
_ => {
|
||||
path_seg.complete(p, PATH_SEGMENT);
|
||||
path.complete(p, PATH);
|
||||
path_ty.complete(p, PATH_TYPE);
|
||||
m.complete(p, TYPE_ARG);
|
||||
}
|
||||
}
|
||||
}
|
||||
T!['{'] => {
|
||||
expressions::block_expr(p);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue