Skip to content

Commit 9bc85e8

Browse files
committed
Parse super let syntax (#1889)
1 parent 5ece7e1 commit 9bc85e8

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

src/gen/clone.rs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/gen/fold.rs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/stmt.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ ast_struct! {
4242
#[cfg_attr(docsrs, doc(cfg(feature = "full")))]
4343
pub struct Local {
4444
pub attrs: Vec<Attribute>,
45+
pub super_token: Option<Token![super]>,
4546
pub let_token: Token![let],
4647
pub pat: Pat,
4748
pub init: Option<LocalInit>,
@@ -217,7 +218,9 @@ pub(crate) mod parsing {
217218
}
218219
}
219220

220-
if input.peek(Token![let]) && !input.peek(token::Group) {
221+
if (input.peek(Token![let]) || input.peek(Token![super]) && input.peek2(Token![let]))
222+
&& !input.peek(token::Group)
223+
{
221224
stmt_local(input, attrs).map(Stmt::Local)
222225
} else if input.peek(Token![pub])
223226
|| input.peek(Token![crate]) && !input.peek2(Token![::])
@@ -281,6 +284,12 @@ pub(crate) mod parsing {
281284
}
282285

283286
fn stmt_local(input: ParseStream, attrs: Vec<Attribute>) -> Result<Local> {
287+
let super_token: Option<Token![super]> = if input.peek(Token![super]) {
288+
Some(input.parse()?)
289+
} else {
290+
None
291+
};
292+
284293
let let_token: Token![let] = input.parse()?;
285294

286295
let mut pat = Pat::parse_single(input)?;
@@ -324,6 +333,7 @@ pub(crate) mod parsing {
324333

325334
Ok(Local {
326335
attrs,
336+
super_token,
327337
let_token,
328338
pat,
329339
init,
@@ -449,6 +459,9 @@ pub(crate) mod printing {
449459
impl ToTokens for Local {
450460
fn to_tokens(&self, tokens: &mut TokenStream) {
451461
expr::printing::outer_attrs_to_tokens(&self.attrs, tokens);
462+
if let Some(super_token) = &self.super_token {
463+
super_token.to_tokens(tokens);
464+
}
452465
self.let_token.to_tokens(tokens);
453466
self.pat.to_tokens(tokens);
454467
if let Some(init) = &self.init {

tests/repo/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,6 @@ static EXCLUDE_FILES: &[&str] = &[
237237
// https://github.com/dtolnay/syn/issues/1705
238238
"src/tools/rustfmt/tests/target/cfg_attribute_in_where.rs",
239239

240-
// TODO: super let
241-
// https://github.com/dtolnay/syn/issues/1889
242-
"src/tools/rust-analyzer/crates/parser/test_data/parser/inline/ok/let_stmt.rs",
243-
244240
// TODO: "ergonomic clones": `f(obj.use)`, `thread::spawn(use || f(obj))`, `async use`
245241
// https://github.com/dtolnay/syn/issues/1802
246242
"tests/codegen-llvm/ergonomic-clones/closure.rs",

0 commit comments

Comments
 (0)