From 6e09f2d9eb26b699e17d65824ee1e9c13d31ed1f Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 18 Sep 2022 16:54:40 -0700 Subject: [PATCH 1/2] Parse associated type on path with parenthesized generic arguments --- src/ty.rs | 14 +++++++++++++- tests/repo/mod.rs | 3 --- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/ty.rs b/src/ty.rs index 09ed8a91ca..5ee2476e67 100644 --- a/src/ty.rs +++ b/src/ty.rs @@ -825,15 +825,27 @@ pub mod parsing { #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] impl Parse for TypePath { fn parse(input: ParseStream) -> Result { - let (qself, mut path) = path::parsing::qpath(input, false)?; + let expr_style = false; + let (qself, mut path) = path::parsing::qpath(input, expr_style)?; if path.segments.last().unwrap().arguments.is_empty() && (input.peek(token::Paren) || input.peek(Token![::]) && input.peek3(token::Paren)) { input.parse::>()?; let args: ParenthesizedGenericArguments = input.parse()?; + let allow_associated_type = match &args.output { + ReturnType::Default => true, + ReturnType::Type(_, ty) => match **ty { + // TODO: probably some of the other kinds allow this too. + Type::Paren(_) => true, + _ => false, + }, + }; let parenthesized = PathArguments::Parenthesized(args); path.segments.last_mut().unwrap().arguments = parenthesized; + if allow_associated_type { + Path::parse_rest(input, &mut path, expr_style)?; + } } Ok(TypePath { qself, path }) diff --git a/tests/repo/mod.rs b/tests/repo/mod.rs index 494c63e113..5c29015865 100644 --- a/tests/repo/mod.rs +++ b/tests/repo/mod.rs @@ -14,9 +14,6 @@ const REVISION: &str = "98ad6a5519651af36e246c0335c964dd52c554ba"; #[rustfmt::skip] static EXCLUDE_FILES: &[&str] = &[ - // TODO: associated type of a path with parenthesized generic arguments - "src/tools/rust-analyzer/crates/parser/test_data/parser/inline/ok/0202_typepathfn_with_coloncolon.rs", - // TODO: trailing comma after variadic in extern fn signature "src/tools/rust-analyzer/crates/parser/test_data/parser/ok/0063_variadic_fun.rs", From 194c3d4011aab1f8a9f2eddd6726ace1ffc64fcf Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 18 Sep 2022 16:56:59 -0700 Subject: [PATCH 2/2] Insane syntax on feature="full" only --- src/ty.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/ty.rs b/src/ty.rs index 5ee2476e67..1fe0796068 100644 --- a/src/ty.rs +++ b/src/ty.rs @@ -833,14 +833,15 @@ pub mod parsing { { input.parse::>()?; let args: ParenthesizedGenericArguments = input.parse()?; - let allow_associated_type = match &args.output { - ReturnType::Default => true, - ReturnType::Type(_, ty) => match **ty { - // TODO: probably some of the other kinds allow this too. - Type::Paren(_) => true, - _ => false, - }, - }; + let allow_associated_type = cfg!(feature = "full") + && match &args.output { + ReturnType::Default => true, + ReturnType::Type(_, ty) => match **ty { + // TODO: probably some of the other kinds allow this too. + Type::Paren(_) => true, + _ => false, + }, + }; let parenthesized = PathArguments::Parenthesized(args); path.segments.last_mut().unwrap().arguments = parenthesized; if allow_associated_type {