mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 20:09:19 +00:00
Parse associated return type bounds
This commit is contained in:
parent
d7d8971203
commit
fa2340a4df
12 changed files with 361 additions and 5 deletions
|
@ -76,6 +76,29 @@ fn generic_arg(p: &mut Parser<'_>) -> bool {
|
|||
}
|
||||
}
|
||||
}
|
||||
IDENT if p.nth_at(1, T!['(']) => {
|
||||
let m = p.start();
|
||||
name_ref(p);
|
||||
params::param_list_fn_trait(p);
|
||||
if p.at(T![:]) && !p.at(T![::]) {
|
||||
// test associated_return_type_bounds
|
||||
// fn foo<T: Foo<foo(): Send, bar(i32): Send, baz(i32, i32): Send>>() {}
|
||||
generic_params::bounds(p);
|
||||
m.complete(p, ASSOC_TYPE_ARG);
|
||||
} else {
|
||||
// test bare_dyn_types_with_paren_as_generic_args
|
||||
// type A = S<Fn(i32)>;
|
||||
// type A = S<Fn(i32) + Send>;
|
||||
// type B = S<Fn(i32) -> i32>;
|
||||
// type C = S<Fn(i32) -> i32 + Send>;
|
||||
opt_ret_type(p);
|
||||
let m = m.complete(p, PATH_SEGMENT).precede(p).complete(p, PATH);
|
||||
let m = paths::type_path_for_qualifier(p, m);
|
||||
let m = m.precede(p).complete(p, PATH_TYPE);
|
||||
let m = types::opt_type_bounds_as_dyn_trait_type(p, m);
|
||||
m.precede(p).complete(p, TYPE_ARG);
|
||||
}
|
||||
}
|
||||
_ if p.at_ts(types::TYPE_FIRST) => type_arg(p),
|
||||
_ => return false,
|
||||
}
|
||||
|
|
|
@ -136,6 +136,7 @@ fn opt_path_type_args(p: &mut Parser<'_>, mode: Mode) {
|
|||
Mode::Type => {
|
||||
// test typepathfn_with_coloncolon
|
||||
// type F = Start::(Middle) -> (Middle)::End;
|
||||
// type GenericArg = S<Start(Middle)::End>;
|
||||
if p.at(T![::]) && p.nth_at(2, T!['(']) {
|
||||
p.bump(T![::]);
|
||||
}
|
||||
|
|
|
@ -337,13 +337,16 @@ pub(super) fn path_type_(p: &mut Parser<'_>, allow_bounds: bool) {
|
|||
|
||||
/// This turns a parsed PATH_TYPE or FOR_TYPE optionally into a DYN_TRAIT_TYPE
|
||||
/// with a TYPE_BOUND_LIST
|
||||
fn opt_type_bounds_as_dyn_trait_type(p: &mut Parser<'_>, type_marker: CompletedMarker) {
|
||||
pub(super) fn opt_type_bounds_as_dyn_trait_type(
|
||||
p: &mut Parser<'_>,
|
||||
type_marker: CompletedMarker,
|
||||
) -> CompletedMarker {
|
||||
assert!(matches!(
|
||||
type_marker.kind(),
|
||||
SyntaxKind::PATH_TYPE | SyntaxKind::FOR_TYPE | SyntaxKind::MACRO_TYPE
|
||||
));
|
||||
if !p.at(T![+]) {
|
||||
return;
|
||||
return type_marker;
|
||||
}
|
||||
|
||||
// First create a TYPE_BOUND from the completed PATH_TYPE
|
||||
|
@ -360,5 +363,5 @@ fn opt_type_bounds_as_dyn_trait_type(p: &mut Parser<'_>, type_marker: CompletedM
|
|||
let m = generic_params::bounds_without_colon_m(p, m);
|
||||
|
||||
// Finally precede everything with DYN_TRAIT_TYPE
|
||||
m.precede(p).complete(p, DYN_TRAIT_TYPE);
|
||||
m.precede(p).complete(p, DYN_TRAIT_TYPE)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue