mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
methods with type params
This commit is contained in:
parent
1e1e2e83c4
commit
ed96926df7
@ -35,7 +35,7 @@ struct Restrictions {
|
|||||||
|
|
||||||
enum Op {
|
enum Op {
|
||||||
Simple,
|
Simple,
|
||||||
Composite(SyntaxKind, u8)
|
Composite(SyntaxKind, u8),
|
||||||
}
|
}
|
||||||
|
|
||||||
// test expr_binding_power
|
// test expr_binding_power
|
||||||
@ -52,16 +52,16 @@ enum Op {
|
|||||||
// }
|
// }
|
||||||
fn current_op(p: &Parser) -> (u8, Op) {
|
fn current_op(p: &Parser) -> (u8, Op) {
|
||||||
if p.at_compound2(L_ANGLE, EQ) {
|
if p.at_compound2(L_ANGLE, EQ) {
|
||||||
return (2, Op::Composite(LTEQ, 2))
|
return (2, Op::Composite(LTEQ, 2));
|
||||||
}
|
}
|
||||||
if p.at_compound2(R_ANGLE, EQ) {
|
if p.at_compound2(R_ANGLE, EQ) {
|
||||||
return (2, Op::Composite(GTEQ, 2))
|
return (2, Op::Composite(GTEQ, 2));
|
||||||
}
|
}
|
||||||
if p.at_compound2(PLUS, EQ) {
|
if p.at_compound2(PLUS, EQ) {
|
||||||
return (1, Op::Composite(PLUSEQ, 2))
|
return (1, Op::Composite(PLUSEQ, 2));
|
||||||
}
|
}
|
||||||
if p.at_compound2(MINUS, EQ) {
|
if p.at_compound2(MINUS, EQ) {
|
||||||
return (1, Op::Composite(MINUSEQ, 2))
|
return (1, Op::Composite(MINUSEQ, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
let bp = match p.current() {
|
let bp = match p.current() {
|
||||||
@ -90,7 +90,7 @@ fn expr_bp(p: &mut Parser, r: Restrictions, bp: u8) {
|
|||||||
Op::Simple => p.bump(),
|
Op::Simple => p.bump(),
|
||||||
Op::Composite(kind, n) => {
|
Op::Composite(kind, n) => {
|
||||||
p.bump_compound(kind, n);
|
p.bump_compound(kind, n);
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
lhs = bin_expr(p, r, lhs, op_bp);
|
lhs = bin_expr(p, r, lhs, op_bp);
|
||||||
}
|
}
|
||||||
@ -115,8 +115,7 @@ fn unary_expr(p: &mut Parser, r: Restrictions) -> Option<CompletedMarker> {
|
|||||||
p.bump();
|
p.bump();
|
||||||
p.eat(MUT_KW);
|
p.eat(MUT_KW);
|
||||||
REF_EXPR
|
REF_EXPR
|
||||||
|
}
|
||||||
},
|
|
||||||
// test deref_expr
|
// test deref_expr
|
||||||
// fn foo() {
|
// fn foo() {
|
||||||
// **&1;
|
// **&1;
|
||||||
@ -125,7 +124,7 @@ fn unary_expr(p: &mut Parser, r: Restrictions) -> Option<CompletedMarker> {
|
|||||||
m = p.start();
|
m = p.start();
|
||||||
p.bump();
|
p.bump();
|
||||||
DEREF_EXPR
|
DEREF_EXPR
|
||||||
},
|
}
|
||||||
// test not_expr
|
// test not_expr
|
||||||
// fn foo() {
|
// fn foo() {
|
||||||
// !!true;
|
// !!true;
|
||||||
@ -134,10 +133,10 @@ fn unary_expr(p: &mut Parser, r: Restrictions) -> Option<CompletedMarker> {
|
|||||||
m = p.start();
|
m = p.start();
|
||||||
p.bump();
|
p.bump();
|
||||||
NOT_EXPR
|
NOT_EXPR
|
||||||
},
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let lhs = atom::atom_expr(p, r)?;
|
let lhs = atom::atom_expr(p, r)?;
|
||||||
return Some(postfix_expr(p, lhs))
|
return Some(postfix_expr(p, lhs));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
unary_expr(p, r);
|
unary_expr(p, r);
|
||||||
@ -148,7 +147,7 @@ fn postfix_expr(p: &mut Parser, mut lhs: CompletedMarker) -> CompletedMarker {
|
|||||||
loop {
|
loop {
|
||||||
lhs = match p.current() {
|
lhs = match p.current() {
|
||||||
L_PAREN => call_expr(p, lhs),
|
L_PAREN => call_expr(p, lhs),
|
||||||
DOT if p.nth(1) == IDENT => if p.nth(2) == L_PAREN {
|
DOT if p.nth(1) == IDENT => if p.nth(2) == L_PAREN || p.nth(2) == COLONCOLON {
|
||||||
method_call_expr(p, lhs)
|
method_call_expr(p, lhs)
|
||||||
} else {
|
} else {
|
||||||
field_expr(p, lhs)
|
field_expr(p, lhs)
|
||||||
@ -176,13 +175,17 @@ fn call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
|
|||||||
// test method_call_expr
|
// test method_call_expr
|
||||||
// fn foo() {
|
// fn foo() {
|
||||||
// x.foo();
|
// x.foo();
|
||||||
// y.bar(1, 2,);
|
// y.bar::<T>(1, 2,);
|
||||||
// }
|
// }
|
||||||
fn method_call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
|
fn method_call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
|
||||||
assert!(p.at(DOT) && p.nth(1) == IDENT && p.nth(2) == L_PAREN);
|
assert!(
|
||||||
|
p.at(DOT) && p.nth(1) == IDENT
|
||||||
|
&& (p.nth(2) == L_PAREN || p.nth(2) == COLONCOLON)
|
||||||
|
);
|
||||||
let m = lhs.precede(p);
|
let m = lhs.precede(p);
|
||||||
p.bump();
|
p.bump();
|
||||||
name_ref(p);
|
name_ref(p);
|
||||||
|
type_args::type_arg_list(p, true);
|
||||||
arg_list(p);
|
arg_list(p);
|
||||||
m.complete(p, METHOD_CALL_EXPR)
|
m.complete(p, METHOD_CALL_EXPR)
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use {yellow::GreenNode, TextUnit};
|
use {yellow::GreenNode, TextUnit};
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
fn foo() {
|
fn foo() {
|
||||||
x.foo();
|
x.foo();
|
||||||
y.bar(1, 2,);
|
y.bar::<T>(1, 2,);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
FILE@[0; 44)
|
FILE@[0; 49)
|
||||||
FN_ITEM@[0; 44)
|
FN_ITEM@[0; 49)
|
||||||
FN_KW@[0; 2)
|
FN_KW@[0; 2)
|
||||||
NAME@[2; 6)
|
NAME@[2; 6)
|
||||||
WHITESPACE@[2; 3)
|
WHITESPACE@[2; 3)
|
||||||
@ -8,7 +8,7 @@ FILE@[0; 44)
|
|||||||
L_PAREN@[6; 7)
|
L_PAREN@[6; 7)
|
||||||
R_PAREN@[7; 8)
|
R_PAREN@[7; 8)
|
||||||
WHITESPACE@[8; 9)
|
WHITESPACE@[8; 9)
|
||||||
BLOCK_EXPR@[9; 44)
|
BLOCK_EXPR@[9; 49)
|
||||||
L_CURLY@[9; 10)
|
L_CURLY@[9; 10)
|
||||||
EXPR_STMT@[10; 28)
|
EXPR_STMT@[10; 28)
|
||||||
METHOD_CALL_EXPR@[10; 22)
|
METHOD_CALL_EXPR@[10; 22)
|
||||||
@ -26,8 +26,8 @@ FILE@[0; 44)
|
|||||||
R_PAREN@[21; 22)
|
R_PAREN@[21; 22)
|
||||||
SEMI@[22; 23)
|
SEMI@[22; 23)
|
||||||
WHITESPACE@[23; 28)
|
WHITESPACE@[23; 28)
|
||||||
EXPR_STMT@[28; 42)
|
EXPR_STMT@[28; 47)
|
||||||
METHOD_CALL_EXPR@[28; 40)
|
METHOD_CALL_EXPR@[28; 45)
|
||||||
PATH_EXPR@[28; 29)
|
PATH_EXPR@[28; 29)
|
||||||
PATH@[28; 29)
|
PATH@[28; 29)
|
||||||
PATH_SEGMENT@[28; 29)
|
PATH_SEGMENT@[28; 29)
|
||||||
@ -36,17 +36,27 @@ FILE@[0; 44)
|
|||||||
DOT@[29; 30)
|
DOT@[29; 30)
|
||||||
NAME_REF@[30; 33)
|
NAME_REF@[30; 33)
|
||||||
IDENT@[30; 33) "bar"
|
IDENT@[30; 33) "bar"
|
||||||
ARG_LIST@[33; 40)
|
TYPE_ARG_LIST@[33; 38)
|
||||||
L_PAREN@[33; 34)
|
COLONCOLON@[33; 35)
|
||||||
LITERAL@[34; 35)
|
L_ANGLE@[35; 36)
|
||||||
INT_NUMBER@[34; 35) "1"
|
TYPE_ARG@[36; 37)
|
||||||
COMMA@[35; 36)
|
PATH_TYPE@[36; 37)
|
||||||
LITERAL@[36; 38)
|
PATH@[36; 37)
|
||||||
WHITESPACE@[36; 37)
|
PATH_SEGMENT@[36; 37)
|
||||||
INT_NUMBER@[37; 38) "2"
|
NAME_REF@[36; 37)
|
||||||
COMMA@[38; 39)
|
IDENT@[36; 37) "T"
|
||||||
R_PAREN@[39; 40)
|
R_ANGLE@[37; 38)
|
||||||
SEMI@[40; 41)
|
ARG_LIST@[38; 45)
|
||||||
WHITESPACE@[41; 42)
|
L_PAREN@[38; 39)
|
||||||
R_CURLY@[42; 43)
|
LITERAL@[39; 40)
|
||||||
WHITESPACE@[43; 44)
|
INT_NUMBER@[39; 40) "1"
|
||||||
|
COMMA@[40; 41)
|
||||||
|
LITERAL@[41; 43)
|
||||||
|
WHITESPACE@[41; 42)
|
||||||
|
INT_NUMBER@[42; 43) "2"
|
||||||
|
COMMA@[43; 44)
|
||||||
|
R_PAREN@[44; 45)
|
||||||
|
SEMI@[45; 46)
|
||||||
|
WHITESPACE@[46; 47)
|
||||||
|
R_CURLY@[47; 48)
|
||||||
|
WHITESPACE@[48; 49)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user