Skip to content

Commit 058e7d0

Browse files
authored
Merge pull request #1772 from dtolnay/selfcapture
Parse self captures: `impl Sized + use<Self>`
2 parents e478e03 + 2a9e9fb commit 058e7d0

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/generics.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,13 +1046,16 @@ pub(crate) mod parsing {
10461046
let mut params = Punctuated::new();
10471047
loop {
10481048
let lookahead = input.lookahead1();
1049-
params.push_value(if lookahead.peek(Lifetime) || lookahead.peek(Ident) {
1050-
input.parse::<CapturedParam>()?
1051-
} else if lookahead.peek(Token![>]) {
1052-
break;
1053-
} else {
1054-
return Err(lookahead.error());
1055-
});
1049+
params.push_value(
1050+
if lookahead.peek(Lifetime) || lookahead.peek(Ident) || input.peek(Token![Self])
1051+
{
1052+
input.parse::<CapturedParam>()?
1053+
} else if lookahead.peek(Token![>]) {
1054+
break;
1055+
} else {
1056+
return Err(lookahead.error());
1057+
},
1058+
);
10561059
let lookahead = input.lookahead1();
10571060
params.push_punct(if lookahead.peek(Token![,]) {
10581061
input.parse::<Token![,]>()?
@@ -1079,8 +1082,8 @@ pub(crate) mod parsing {
10791082
let lookahead = input.lookahead1();
10801083
if lookahead.peek(Lifetime) {
10811084
input.parse().map(CapturedParam::Lifetime)
1082-
} else if lookahead.peek(Ident) {
1083-
input.parse().map(CapturedParam::Ident)
1085+
} else if lookahead.peek(Ident) || input.peek(Token![Self]) {
1086+
input.call(Ident::parse_any).map(CapturedParam::Ident)
10841087
} else {
10851088
Err(lookahead.error())
10861089
}

tests/repo/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ const REVISION: &str = "86d69c705a552236a622eee3fdea94bf13c5f102";
1919

2020
#[rustfmt::skip]
2121
static EXCLUDE_FILES: &[&str] = &[
22-
// TODO: self capture: `impl Sized + use<Self>`
23-
"tests/ui/impl-trait/precise-capturing/self-capture.rs",
24-
2522
// TODO: non-lifetime binders: `where for<'a, T> &'a Struct<T>: Trait`
2623
// https://github.com/dtolnay/syn/issues/1435
2724
"src/tools/rustfmt/tests/source/issue_5721.rs",

0 commit comments

Comments
 (0)