From fc0c37082ef78e38aec6b7a2ec54f3643fafbc72 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Wed, 19 Jan 2022 16:31:18 -0800 Subject: [PATCH 1/2] Fix static async closure keyword order --- src/expr.rs | 12 ++++-------- tests/repo/mod.rs | 4 ---- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/expr.rs b/src/expr.rs index d9319ddd96..28fb3de11b 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -403,8 +403,8 @@ ast_struct! { #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))] pub struct ExprClosure #full { pub attrs: Vec, - pub asyncness: Option, pub movability: Option, + pub asyncness: Option, pub capture: Option, pub or1_token: Token![|], pub inputs: Punctuated, @@ -2397,12 +2397,8 @@ pub(crate) mod parsing { #[cfg(feature = "full")] fn expr_closure(input: ParseStream, allow_struct: AllowStruct) -> Result { + let movability: Option = input.parse()?; let asyncness: Option = input.parse()?; - let movability: Option = if asyncness.is_none() { - input.parse()? - } else { - None - }; let capture: Option = input.parse()?; let or1_token: Token![|] = input.parse()?; @@ -2440,8 +2436,8 @@ pub(crate) mod parsing { Ok(ExprClosure { attrs: Vec::new(), - asyncness, movability, + asyncness, capture, or1_token, inputs, @@ -3223,8 +3219,8 @@ pub(crate) mod printing { impl ToTokens for ExprClosure { fn to_tokens(&self, tokens: &mut TokenStream) { outer_attrs_to_tokens(&self.attrs, tokens); - self.asyncness.to_tokens(tokens); self.movability.to_tokens(tokens); + self.asyncness.to_tokens(tokens); self.capture.to_tokens(tokens); self.or1_token.to_tokens(tokens); self.inputs.to_tokens(tokens); diff --git a/tests/repo/mod.rs b/tests/repo/mod.rs index 16ff09f32a..ef84445fb6 100644 --- a/tests/repo/mod.rs +++ b/tests/repo/mod.rs @@ -22,10 +22,6 @@ static EXCLUDE: &[&str] = &[ "src/test/ui/rfc-2497-if-let-chains/issue-90722.rs", "src/test/ui/rfc-2497-if-let-chains/then-else-blocks.rs", - // TODO: static async closure keyword order - "src/tools/rustfmt/tests/source/async_block.rs", - "src/tools/rustfmt/tests/target/async_block.rs", - // TODO: impl ~const T {} // https://github.com/dtolnay/syn/issues/1051 "src/test/ui/rfc-2632-const-trait-impl/syntax.rs", From 5aeec41f38624ea65359985e1817103ae279792e Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Wed, 19 Jan 2022 16:46:06 -0800 Subject: [PATCH 2/2] Update generated code for ExprClosure field order --- src/gen/clone.rs | 2 +- src/gen/debug.rs | 2 +- src/gen/eq.rs | 4 ++-- src/gen/fold.rs | 2 +- src/gen/hash.rs | 2 +- src/gen/visit.rs | 4 ++-- src/gen/visit_mut.rs | 4 ++-- syn.json | 8 ++++---- tests/debug/gen.rs | 24 ++++++++++++------------ 9 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/gen/clone.rs b/src/gen/clone.rs index 2d56a56ca3..1c8814d679 100644 --- a/src/gen/clone.rs +++ b/src/gen/clone.rs @@ -412,8 +412,8 @@ impl Clone for ExprClosure { fn clone(&self) -> Self { ExprClosure { attrs: self.attrs.clone(), - asyncness: self.asyncness.clone(), movability: self.movability.clone(), + asyncness: self.asyncness.clone(), capture: self.capture.clone(), or1_token: self.or1_token.clone(), inputs: self.inputs.clone(), diff --git a/src/gen/debug.rs b/src/gen/debug.rs index 3efa2788fe..11e197eac2 100644 --- a/src/gen/debug.rs +++ b/src/gen/debug.rs @@ -726,8 +726,8 @@ impl Debug for ExprClosure { fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { let mut formatter = formatter.debug_struct("ExprClosure"); formatter.field("attrs", &self.attrs); - formatter.field("asyncness", &self.asyncness); formatter.field("movability", &self.movability); + formatter.field("asyncness", &self.asyncness); formatter.field("capture", &self.capture); formatter.field("or1_token", &self.or1_token); formatter.field("inputs", &self.inputs); diff --git a/src/gen/eq.rs b/src/gen/eq.rs index 533b9be8db..40fed0b890 100644 --- a/src/gen/eq.rs +++ b/src/gen/eq.rs @@ -422,8 +422,8 @@ impl Eq for ExprClosure {} #[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))] impl PartialEq for ExprClosure { fn eq(&self, other: &Self) -> bool { - self.attrs == other.attrs && self.asyncness == other.asyncness - && self.movability == other.movability && self.capture == other.capture + self.attrs == other.attrs && self.movability == other.movability + && self.asyncness == other.asyncness && self.capture == other.capture && self.inputs == other.inputs && self.output == other.output && self.body == other.body } diff --git a/src/gen/fold.rs b/src/gen/fold.rs index b1ee11e0e5..7916a620e6 100644 --- a/src/gen/fold.rs +++ b/src/gen/fold.rs @@ -1269,9 +1269,9 @@ where { ExprClosure { attrs: FoldHelper::lift(node.attrs, |it| f.fold_attribute(it)), - asyncness: (node.asyncness).map(|it| Token![async](tokens_helper(f, &it.span))), movability: (node.movability) .map(|it| Token![static](tokens_helper(f, &it.span))), + asyncness: (node.asyncness).map(|it| Token![async](tokens_helper(f, &it.span))), capture: (node.capture).map(|it| Token![move](tokens_helper(f, &it.span))), or1_token: Token![|](tokens_helper(f, &node.or1_token.spans)), inputs: FoldHelper::lift(node.inputs, |it| f.fold_pat(it)), diff --git a/src/gen/hash.rs b/src/gen/hash.rs index 3e347ce1ea..686ed86566 100644 --- a/src/gen/hash.rs +++ b/src/gen/hash.rs @@ -641,8 +641,8 @@ impl Hash for ExprClosure { H: Hasher, { self.attrs.hash(state); - self.asyncness.hash(state); self.movability.hash(state); + self.asyncness.hash(state); self.capture.hash(state); self.inputs.hash(state); self.output.hash(state); diff --git a/src/gen/visit.rs b/src/gen/visit.rs index 563da4f4b9..d84e43102b 100644 --- a/src/gen/visit.rs +++ b/src/gen/visit.rs @@ -1373,10 +1373,10 @@ where for it in &node.attrs { v.visit_attribute(it); } - if let Some(it) = &node.asyncness { + if let Some(it) = &node.movability { tokens_helper(v, &it.span); } - if let Some(it) = &node.movability { + if let Some(it) = &node.asyncness { tokens_helper(v, &it.span); } if let Some(it) = &node.capture { diff --git a/src/gen/visit_mut.rs b/src/gen/visit_mut.rs index 2fae407e9b..51e10b6056 100644 --- a/src/gen/visit_mut.rs +++ b/src/gen/visit_mut.rs @@ -1374,10 +1374,10 @@ where for it in &mut node.attrs { v.visit_attribute_mut(it); } - if let Some(it) = &mut node.asyncness { + if let Some(it) = &mut node.movability { tokens_helper(v, &mut it.span); } - if let Some(it) = &mut node.movability { + if let Some(it) = &mut node.asyncness { tokens_helper(v, &mut it.span); } if let Some(it) = &mut node.capture { diff --git a/syn.json b/syn.json index 02741c8c8d..f9acc2d0ae 100644 --- a/syn.json +++ b/syn.json @@ -1087,14 +1087,14 @@ "syn": "Attribute" } }, - "asyncness": { + "movability": { "option": { - "token": "Async" + "token": "Static" } }, - "movability": { + "asyncness": { "option": { - "token": "Static" + "token": "Async" } }, "capture": { diff --git a/tests/debug/gen.rs b/tests/debug/gen.rs index 0715ba483d..a49ee6c92f 100644 --- a/tests/debug/gen.rs +++ b/tests/debug/gen.rs @@ -591,29 +591,29 @@ impl Debug for Lite { if !_val.attrs.is_empty() { formatter.field("attrs", Lite(&_val.attrs)); } - if let Some(val) = &_val.asyncness { + if let Some(val) = &_val.movability { #[derive(RefCast)] #[repr(transparent)] - struct Print(syn::token::Async); + struct Print(syn::token::Static); impl Debug for Print { fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { formatter.write_str("Some")?; Ok(()) } } - formatter.field("asyncness", Print::ref_cast(val)); + formatter.field("movability", Print::ref_cast(val)); } - if let Some(val) = &_val.movability { + if let Some(val) = &_val.asyncness { #[derive(RefCast)] #[repr(transparent)] - struct Print(syn::token::Static); + struct Print(syn::token::Async); impl Debug for Print { fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { formatter.write_str("Some")?; Ok(()) } } - formatter.field("movability", Print::ref_cast(val)); + formatter.field("asyncness", Print::ref_cast(val)); } if let Some(val) = &_val.capture { #[derive(RefCast)] @@ -1294,29 +1294,29 @@ impl Debug for Lite { if !_val.attrs.is_empty() { formatter.field("attrs", Lite(&_val.attrs)); } - if let Some(val) = &_val.asyncness { + if let Some(val) = &_val.movability { #[derive(RefCast)] #[repr(transparent)] - struct Print(syn::token::Async); + struct Print(syn::token::Static); impl Debug for Print { fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { formatter.write_str("Some")?; Ok(()) } } - formatter.field("asyncness", Print::ref_cast(val)); + formatter.field("movability", Print::ref_cast(val)); } - if let Some(val) = &_val.movability { + if let Some(val) = &_val.asyncness { #[derive(RefCast)] #[repr(transparent)] - struct Print(syn::token::Static); + struct Print(syn::token::Async); impl Debug for Print { fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { formatter.write_str("Some")?; Ok(()) } } - formatter.field("movability", Print::ref_cast(val)); + formatter.field("asyncness", Print::ref_cast(val)); } if let Some(val) = &_val.capture { #[derive(RefCast)]