From 2a9e9fbd21df38dda22ad6683d2524842d16160b Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Wed, 23 Oct 2024 13:56:19 -0700 Subject: [PATCH] Parse self captures: `impl Sized + use` --- src/generics.rs | 21 ++++++++++++--------- tests/repo/mod.rs | 3 --- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/generics.rs b/src/generics.rs index 746184826f..1e8fccf039 100644 --- a/src/generics.rs +++ b/src/generics.rs @@ -1046,13 +1046,16 @@ pub(crate) mod parsing { let mut params = Punctuated::new(); loop { let lookahead = input.lookahead1(); - params.push_value(if lookahead.peek(Lifetime) || lookahead.peek(Ident) { - input.parse::()? - } else if lookahead.peek(Token![>]) { - break; - } else { - return Err(lookahead.error()); - }); + params.push_value( + if lookahead.peek(Lifetime) || lookahead.peek(Ident) || input.peek(Token![Self]) + { + input.parse::()? + } else if lookahead.peek(Token![>]) { + break; + } else { + return Err(lookahead.error()); + }, + ); let lookahead = input.lookahead1(); params.push_punct(if lookahead.peek(Token![,]) { input.parse::()? @@ -1079,8 +1082,8 @@ pub(crate) mod parsing { let lookahead = input.lookahead1(); if lookahead.peek(Lifetime) { input.parse().map(CapturedParam::Lifetime) - } else if lookahead.peek(Ident) { - input.parse().map(CapturedParam::Ident) + } else if lookahead.peek(Ident) || input.peek(Token![Self]) { + input.call(Ident::parse_any).map(CapturedParam::Ident) } else { Err(lookahead.error()) } diff --git a/tests/repo/mod.rs b/tests/repo/mod.rs index 93f0c32eac..96f039cb35 100644 --- a/tests/repo/mod.rs +++ b/tests/repo/mod.rs @@ -19,9 +19,6 @@ const REVISION: &str = "86d69c705a552236a622eee3fdea94bf13c5f102"; #[rustfmt::skip] static EXCLUDE_FILES: &[&str] = &[ - // TODO: self capture: `impl Sized + use` - "tests/ui/impl-trait/precise-capturing/self-capture.rs", - // TODO: non-lifetime binders: `where for<'a, T> &'a Struct: Trait` // https://github.com/dtolnay/syn/issues/1435 "src/tools/rustfmt/tests/source/issue_5721.rs",