Skip to content

Commit

Permalink
Merge pull request #1217 from dtolnay/typepathfnwithcoloncolon
Browse files Browse the repository at this point in the history
Parse associated type on path with parenthesized generic arguments
  • Loading branch information
dtolnay authored Sep 19, 2022
2 parents 15c0075 + 194c3d4 commit ba6cd8e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
15 changes: 14 additions & 1 deletion src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -825,15 +825,28 @@ pub mod parsing {
#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for TypePath {
fn parse(input: ParseStream) -> Result<Self> {
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::<Option<Token![::]>>()?;
let args: ParenthesizedGenericArguments = input.parse()?;
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 {
Path::parse_rest(input, &mut path, expr_style)?;
}
}

Ok(TypePath { qself, path })
Expand Down
3 changes: 0 additions & 3 deletions tests/repo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",

Expand Down

0 comments on commit ba6cd8e

Please sign in to comment.