diff --git a/src/gen/clone.rs b/src/gen/clone.rs index be2b698422..1ee6ad0188 100644 --- a/src/gen/clone.rs +++ b/src/gen/clone.rs @@ -1389,6 +1389,7 @@ impl Clone for crate::Local { fn clone(&self) -> Self { crate::Local { attrs: self.attrs.clone(), + super_token: self.super_token.clone(), let_token: self.let_token.clone(), pat: self.pat.clone(), init: self.init.clone(), diff --git a/src/gen/fold.rs b/src/gen/fold.rs index 1f0afd3191..ce3fd81c7a 100644 --- a/src/gen/fold.rs +++ b/src/gen/fold.rs @@ -2796,6 +2796,7 @@ where { crate::Local { attrs: f.fold_attributes(node.attrs), + super_token: node.super_token, let_token: node.let_token, pat: f.fold_pat(node.pat), init: (node.init).map(|it| f.fold_local_init(it)), diff --git a/src/stmt.rs b/src/stmt.rs index 970bc13dc2..e3fb92d6cb 100644 --- a/src/stmt.rs +++ b/src/stmt.rs @@ -42,6 +42,7 @@ ast_struct! { #[cfg_attr(docsrs, doc(cfg(feature = "full")))] pub struct Local { pub attrs: Vec, + pub super_token: Option, pub let_token: Token![let], pub pat: Pat, pub init: Option, @@ -217,7 +218,9 @@ pub(crate) mod parsing { } } - if input.peek(Token![let]) && !input.peek(token::Group) { + if (input.peek(Token![let]) || input.peek(Token![super]) && input.peek2(Token![let])) + && !input.peek(token::Group) + { stmt_local(input, attrs).map(Stmt::Local) } else if input.peek(Token![pub]) || input.peek(Token![crate]) && !input.peek2(Token![::]) @@ -281,6 +284,12 @@ pub(crate) mod parsing { } fn stmt_local(input: ParseStream, attrs: Vec) -> Result { + let super_token: Option = if input.peek(Token![super]) { + Some(input.parse()?) + } else { + None + }; + let let_token: Token![let] = input.parse()?; let mut pat = Pat::parse_single(input)?; @@ -324,6 +333,7 @@ pub(crate) mod parsing { Ok(Local { attrs, + super_token, let_token, pat, init, @@ -449,6 +459,9 @@ pub(crate) mod printing { impl ToTokens for Local { fn to_tokens(&self, tokens: &mut TokenStream) { expr::printing::outer_attrs_to_tokens(&self.attrs, tokens); + if let Some(super_token) = &self.super_token { + super_token.to_tokens(tokens); + } self.let_token.to_tokens(tokens); self.pat.to_tokens(tokens); if let Some(init) = &self.init { diff --git a/tests/repo/mod.rs b/tests/repo/mod.rs index 8cbb83bf8e..d988d1bdd0 100644 --- a/tests/repo/mod.rs +++ b/tests/repo/mod.rs @@ -237,10 +237,6 @@ static EXCLUDE_FILES: &[&str] = &[ // https://github.com/dtolnay/syn/issues/1705 "src/tools/rustfmt/tests/target/cfg_attribute_in_where.rs", - // TODO: super let - // https://github.com/dtolnay/syn/issues/1889 - "src/tools/rust-analyzer/crates/parser/test_data/parser/inline/ok/let_stmt.rs", - // TODO: "ergonomic clones": `f(obj.use)`, `thread::spawn(use || f(obj))`, `async use` // https://github.com/dtolnay/syn/issues/1802 "tests/codegen-llvm/ergonomic-clones/closure.rs",