Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse associated type on path with parenthesized generic arguments #1217

Merged
merged 2 commits into from Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/ty.rs
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
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