From 3afa4446e5f88c94b3f8b8fcf96b18bc783476ec Mon Sep 17 00:00:00 2001 From: trevyn <230691+trevyn@users.noreply.github.com> Date: Tue, 28 Nov 2023 14:05:59 +0400 Subject: [PATCH 1/4] Extend `inline_attribute_width` to more AST types --- src/expr.rs | 18 +++++++++++++++++- src/items.rs | 23 +++++++++++++++++++++-- tests/source/issue-3343.rs | 25 +++++++++++++++++++++++++ tests/target/issue-3343.rs | 20 ++++++++++++++++++++ 4 files changed, 83 insertions(+), 3 deletions(-) diff --git a/src/expr.rs b/src/expr.rs index acde8809329..4e03e8de476 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -416,7 +416,23 @@ pub(crate) fn format_expr( attrs.last().map_or(expr.span.lo(), |attr| attr.span.hi()), expr.span.lo(), ); - combine_strs_with_missing_comments(context, &attrs_str, &expr_str, span, shape, false) + + let allow_extend = if attrs.len() == 1 { + let line_len = attrs_str.len() + 1 + expr_str.len(); + !attrs.first().unwrap().is_doc_comment() + && context.config.inline_attribute_width() >= line_len + } else { + false + }; + + combine_strs_with_missing_comments( + context, + &attrs_str, + &expr_str, + span, + shape, + allow_extend, + ) }) } diff --git a/src/items.rs b/src/items.rs index d6488ffd141..765dee28981 100644 --- a/src/items.rs +++ b/src/items.rs @@ -1869,7 +1869,17 @@ pub(crate) fn rewrite_struct_field( let prefix = rewrite_struct_field_prefix(context, field)?; let attrs_str = field.attrs.rewrite(context, shape)?; - let attrs_extendable = field.ident.is_none() && is_attributes_extendable(&attrs_str); + + let allow_extend = if field.attrs.len() == 1 { + let line_len = attrs_str.len() + 1 + prefix.len(); + !field.attrs.first().unwrap().is_doc_comment() + && context.config.inline_attribute_width() >= line_len + } else { + false + }; + + let attrs_extendable = + (field.ident.is_none() && is_attributes_extendable(&attrs_str)) || allow_extend; let missing_span = if field.attrs.is_empty() { mk_sp(field.span.lo(), field.span.lo()) } else { @@ -3375,13 +3385,22 @@ impl Rewrite for ast::ForeignItem { } else { mk_sp(self.attrs[self.attrs.len() - 1].span.hi(), self.span.lo()) }; + + let allow_extend = if self.attrs.len() == 1 { + let line_len = attrs_str.len() + 1 + item_str.len(); + !self.attrs.first().unwrap().is_doc_comment() + && context.config.inline_attribute_width() >= line_len + } else { + false + }; + combine_strs_with_missing_comments( context, &attrs_str, &item_str, missing_span, shape, - false, + allow_extend, ) } } diff --git a/tests/source/issue-3343.rs b/tests/source/issue-3343.rs index 5670b04f5d6..c2ba9a4aba5 100644 --- a/tests/source/issue-3343.rs +++ b/tests/source/issue-3343.rs @@ -15,6 +15,31 @@ extern crate len_is_50_; #[cfg(feature = "alloc")] extern crate len_is_51__; +// https://github.com/rust-lang/rustfmt/issues/3343#issuecomment-589945611 +extern "C" { + #[no_mangle] + fn foo(); +} + +fn main() { + #[cfg(feature = "alloc")] + foo(); + #[cfg(feature = "alloc")] + { + foo(); + } + { + #[cfg(feature = "alloc")] + foo(); + } +} + +// https://github.com/rust-lang/rustfmt/pull/5538#issuecomment-1272367684 +struct EventConfigWidget { + #[widget] + menu_delay: Spinner, +} + /// this is a comment to test is_sugared_doc property use core::convert; diff --git a/tests/target/issue-3343.rs b/tests/target/issue-3343.rs index d0497758e66..acd5e026901 100644 --- a/tests/target/issue-3343.rs +++ b/tests/target/issue-3343.rs @@ -12,6 +12,26 @@ use total_len_is::_51___; #[cfg(feature = "alloc")] extern crate len_is_51__; +// https://github.com/rust-lang/rustfmt/issues/3343#issuecomment-589945611 +extern "C" { + #[no_mangle] fn foo(); +} + +fn main() { + #[cfg(feature = "alloc")] foo(); + #[cfg(feature = "alloc")] { + foo(); + } + { + #[cfg(feature = "alloc")] foo(); + } +} + +// https://github.com/rust-lang/rustfmt/pull/5538#issuecomment-1272367684 +struct EventConfigWidget { + #[widget] menu_delay: Spinner, +} + /// this is a comment to test is_sugared_doc property use core::convert; From b647dab1893e372799bdc6df87ab6b9f2ccd6b2d Mon Sep 17 00:00:00 2001 From: trevyn <230691+trevyn@users.noreply.github.com> Date: Sat, 17 Feb 2024 16:23:10 -0800 Subject: [PATCH 2/4] refactor & add more tests --- src/expr.rs | 16 ++--- src/imports.rs | 11 +--- src/items.rs | 33 ++++------ src/utils.rs | 19 ++++++ .../inline_attribute_width/50.rs} | 61 ++++++++++++++++++- .../inline_attribute_width/50.rs} | 59 +++++++++++++++++- 6 files changed, 155 insertions(+), 44 deletions(-) rename tests/source/{issue-3343.rs => configs/inline_attribute_width/50.rs} (61%) rename tests/target/{issue-3343.rs => configs/inline_attribute_width/50.rs} (58%) diff --git a/src/expr.rs b/src/expr.rs index 347ca4bf21e..9674c19d30a 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -29,11 +29,7 @@ use crate::spanned::Spanned; use crate::stmt; use crate::string::{rewrite_string, StringFormat}; use crate::types::{rewrite_path, PathContext}; -use crate::utils::{ - colon_spaces, contains_skip, count_newlines, filtered_str_fits, first_line_ends_with, - inner_attributes, last_line_extendable, last_line_width, mk_sp, outer_attributes, - semicolon_for_expr, unicode_str_width, wrap_str, -}; +use crate::utils::*; use crate::vertical::rewrite_with_alignment; use crate::visitor::FmtVisitor; @@ -417,13 +413,9 @@ pub(crate) fn format_expr( expr.span.lo(), ); - let allow_extend = if attrs.len() == 1 { - let line_len = attrs_str.len() + 1 + expr_str.len(); - !attrs.first().unwrap().is_doc_comment() - && context.config.inline_attribute_width() >= line_len - } else { - false - }; + // +1 = ";" + let allow_extend = + extend_inline_attr(&expr.attrs, shape, &attrs_str, expr_str.len() + 1, context); combine_strs_with_missing_comments( context, diff --git a/src/imports.rs b/src/imports.rs index 05195553c08..1e45019085d 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -23,7 +23,7 @@ use crate::rewrite::{Rewrite, RewriteContext}; use crate::shape::Shape; use crate::source_map::SpanUtils; use crate::spanned::Spanned; -use crate::utils::{is_same_visibility, mk_sp, rewrite_ident}; +use crate::utils::{extend_inline_attr, is_same_visibility, mk_sp, rewrite_ident}; use crate::visitor::FmtVisitor; /// Returns a name imported by a `use` declaration. @@ -351,13 +351,8 @@ impl UseTree { let hi = self.span.lo(); let span = mk_sp(lo, hi); - let allow_extend = if attrs.len() == 1 { - let line_len = attr_str.len() + 1 + use_str.len(); - !attrs.first().unwrap().is_doc_comment() - && context.config.inline_attribute_width() >= line_len - } else { - false - }; + let allow_extend = + extend_inline_attr(attrs, shape, &attr_str, use_str.len(), context); combine_strs_with_missing_comments( context, diff --git a/src/items.rs b/src/items.rs index 1b5c33fe5f3..e3016c7ea28 100644 --- a/src/items.rs +++ b/src/items.rs @@ -1877,14 +1877,16 @@ pub(crate) fn rewrite_struct_field( let prefix = rewrite_struct_field_prefix(context, field)?; let attrs_str = field.attrs.rewrite(context, shape)?; + let ty_str = field.ty.rewrite(context, shape)?; - let allow_extend = if field.attrs.len() == 1 { - let line_len = attrs_str.len() + 1 + prefix.len(); - !field.attrs.first().unwrap().is_doc_comment() - && context.config.inline_attribute_width() >= line_len - } else { - false - }; + let allow_extend = extend_inline_attr( + &field.attrs, + shape, + &attrs_str, + // +1 = " ", +1 = "," + prefix.len() + 1 + ty_str.len() + 1, + context, + ); let attrs_extendable = (field.ident.is_none() && is_attributes_extendable(&attrs_str)) || allow_extend; @@ -3394,13 +3396,8 @@ impl Rewrite for ast::ForeignItem { mk_sp(self.attrs[self.attrs.len() - 1].span.hi(), self.span.lo()) }; - let allow_extend = if self.attrs.len() == 1 { - let line_len = attrs_str.len() + 1 + item_str.len(); - !self.attrs.first().unwrap().is_doc_comment() - && context.config.inline_attribute_width() >= line_len - } else { - false - }; + let allow_extend = + extend_inline_attr(&self.attrs, shape, &attrs_str, item_str.len(), context); combine_strs_with_missing_comments( context, @@ -3429,13 +3426,7 @@ fn rewrite_attrs( mk_sp(attrs[attrs.len() - 1].span.hi(), item.span.lo()) }; - let allow_extend = if attrs.len() == 1 { - let line_len = attrs_str.len() + 1 + item_str.len(); - !attrs.first().unwrap().is_doc_comment() - && context.config.inline_attribute_width() >= line_len - } else { - false - }; + let allow_extend = extend_inline_attr(&item.attrs, shape, &attrs_str, item_str.len(), context); combine_strs_with_missing_comments( context, diff --git a/src/utils.rs b/src/utils.rs index 642b6603b1e..50f07bac52e 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -691,6 +691,25 @@ pub(crate) fn unicode_str_width(s: &str) -> usize { s.width() } +/// Determine if we could place a single attribute on the same line as the rewritten AST node. +pub(crate) fn extend_inline_attr( + attrs: &[ast::Attribute], + shape: Shape, + attrs_str: &str, + rewrite_len: usize, + context: &RewriteContext<'_>, +) -> bool { + if attrs.len() > 1 { + return false; + } + + attrs.first().is_some_and(|attr| { + // +1 = " " + let line_len = shape.indent.width() + attrs_str.len() + 1 + rewrite_len; + !attr.is_doc_comment() && context.config.inline_attribute_width() >= line_len + }) +} + #[cfg(test)] mod test { use super::*; diff --git a/tests/source/issue-3343.rs b/tests/source/configs/inline_attribute_width/50.rs similarity index 61% rename from tests/source/issue-3343.rs rename to tests/source/configs/inline_attribute_width/50.rs index c2ba9a4aba5..8dc2e3b98e7 100644 --- a/tests/source/issue-3343.rs +++ b/tests/source/configs/inline_attribute_width/50.rs @@ -9,6 +9,26 @@ use total_len_is::_50__; #[cfg(feature = "alloc")] use total_len_is::_51___; +#[cfg(feature = "alloc")] +// c +use d; + +#[cfg(feature = "alloc")] +// comment +use total_len_is::_50__; + +#[cfg(feature = "alloc")] +// comment +use total_len_is::_51___; + +fn foo() { + #[cfg(feature = "alloc")] + use total_len::_50_; + + #[cfg(feature = "alloc")] + use total_len::_51__; +} + #[cfg(feature = "alloc")] extern crate len_is_50_; @@ -21,9 +41,32 @@ extern "C" { fn foo(); } +extern "C" { + #[no_mangle] + fn total_len_is_49___________(); +} + +extern "C" { + #[no_mangle] + fn total_len_is_50____________(); +} + +extern "C" { + #[no_mangle] + fn total_len_is_51_____________(); +} + fn main() { #[cfg(feature = "alloc")] - foo(); + ["total_len_is_50"]; + #[cfg(feature = "alloc")] + ["total_len_is_51_"]; + #[cfg(feature = "alloc")] + total_len_is_50__(); + #[cfg(feature = "alloc")] + total_len_is_51___(); + #[cfg(feature = "alloc")] + total_len_is_52____(); #[cfg(feature = "alloc")] { foo(); @@ -40,6 +83,22 @@ struct EventConfigWidget { menu_delay: Spinner, } +struct foo { + #[x] + #[y] + z: bool, +} + +struct foo { + #[widget] + len_is_50____________________: bool, +} + +struct foo { + #[widget] + len_is_51_____________________: bool, +} + /// this is a comment to test is_sugared_doc property use core::convert; diff --git a/tests/target/issue-3343.rs b/tests/target/configs/inline_attribute_width/50.rs similarity index 58% rename from tests/target/issue-3343.rs rename to tests/target/configs/inline_attribute_width/50.rs index acd5e026901..3490a75af27 100644 --- a/tests/target/issue-3343.rs +++ b/tests/target/configs/inline_attribute_width/50.rs @@ -7,6 +7,25 @@ #[cfg(feature = "alloc")] use total_len_is::_51___; +#[cfg(feature = "alloc")] +// c +use d; + +#[cfg(feature = "alloc")] +// comment +use total_len_is::_50__; + +#[cfg(feature = "alloc")] +// comment +use total_len_is::_51___; + +fn foo() { + #[cfg(feature = "alloc")] use total_len::_50_; + + #[cfg(feature = "alloc")] + use total_len::_51__; +} + #[cfg(feature = "alloc")] extern crate len_is_50_; #[cfg(feature = "alloc")] @@ -17,9 +36,30 @@ extern "C" { #[no_mangle] fn foo(); } +extern "C" { + #[no_mangle] fn total_len_is_49___________(); +} + +extern "C" { + #[no_mangle] fn total_len_is_50____________(); +} + +extern "C" { + #[no_mangle] + fn total_len_is_51_____________(); +} + fn main() { - #[cfg(feature = "alloc")] foo(); - #[cfg(feature = "alloc")] { + #[cfg(feature = "alloc")] ["total_len_is_50"]; + #[cfg(feature = "alloc")] + ["total_len_is_51_"]; + #[cfg(feature = "alloc")] total_len_is_50__(); + #[cfg(feature = "alloc")] + total_len_is_51___(); + #[cfg(feature = "alloc")] + total_len_is_52____(); + #[cfg(feature = "alloc")] + { foo(); } { @@ -32,6 +72,21 @@ struct EventConfigWidget { #[widget] menu_delay: Spinner, } +struct foo { + #[x] + #[y] + z: bool, +} + +struct foo { + #[widget] len_is_50____________________: bool, +} + +struct foo { + #[widget] + len_is_51_____________________: bool, +} + /// this is a comment to test is_sugared_doc property use core::convert; From 73519c8564553bd317f83e34d3242a20db51287e Mon Sep 17 00:00:00 2001 From: trevyn <230691+trevyn@users.noreply.github.com> Date: Fri, 5 Jul 2024 10:06:06 +0300 Subject: [PATCH 3/4] use rewrite_result --- src/items.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/items.rs b/src/items.rs index 24c228f777e..954469e8628 100644 --- a/src/items.rs +++ b/src/items.rs @@ -1884,7 +1884,7 @@ pub(crate) fn rewrite_struct_field( let prefix = rewrite_struct_field_prefix(context, field)?; let attrs_str = field.attrs.rewrite_result(context, shape)?; - let ty_str = field.ty.rewrite(context, shape)?; + let ty_str = field.ty.rewrite_result(context, shape)?; let allow_extend = extend_inline_attr( &field.attrs, From 0121bb6d37f1a851cedce8a2ef1e9e6a6fdd7751 Mon Sep 17 00:00:00 2001 From: trevyn <230691+trevyn@users.noreply.github.com> Date: Fri, 5 Jul 2024 13:07:24 +0300 Subject: [PATCH 4/4] add expression tests --- src/expr.rs | 3 +- .../configs/inline_attribute_width/50.rs | 201 ++++++++++++++++++ .../configs/inline_attribute_width/50.rs | 183 ++++++++++++++++ 3 files changed, 386 insertions(+), 1 deletion(-) diff --git a/src/expr.rs b/src/expr.rs index f56f471af2f..4c7c0e6ba7f 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -424,7 +424,8 @@ pub(crate) fn format_expr( // +1 = ";" let allow_extend = - extend_inline_attr(&expr.attrs, shape, &attrs_str, expr_str.len() + 1, context); + extend_inline_attr(&expr.attrs, shape, &attrs_str, expr_str.len() + 1, context) + && expr_type == ExprType::Statement; combine_strs_with_missing_comments( context, diff --git a/tests/source/configs/inline_attribute_width/50.rs b/tests/source/configs/inline_attribute_width/50.rs index 8dc2e3b98e7..d07d0f56d79 100644 --- a/tests/source/configs/inline_attribute_width/50.rs +++ b/tests/source/configs/inline_attribute_width/50.rs @@ -1,4 +1,5 @@ // rustfmt-inline_attribute_width: 50 +// rustfmt-edition: 2021 #[cfg(feature = "alloc")] use core::slice; @@ -129,3 +130,203 @@ use total_len_is_::_51______; ) )))] use core::slice; + +fn foo() { + // Literal expression + #[cfg(feature = "len_is_50_____________")] + 42; + #[cfg(feature = "len_is_51______________")] + 42; + + // Path expression + #[cfg(feature = "len_is_50__")] + some_variable; + #[cfg(feature = "len_is_51___")] + some_variable; + + // Block expression + #[cfg(feature = "len_is_50_______________")] + { + let x = 2; + }; + #[cfg(feature = "len_is_51________________")] + { + let x = 2; + }; + + // Operator expression + #[cfg(feature = "len_is_50__________")] + 1 + 2; + #[cfg(feature = "len_is_51___________")] + 1 + 2; + + // Tuple expression + #[cfg(feature = "len_is_50")] + (1, "two", 3.0); + #[cfg(feature = "len_is_51_")] + (1, "two", 3.0); + + // Array expression + #[cfg(feature = "len_is_50______")] + [1, 2, 3]; + #[cfg(feature = "len_is_51_______")] + [1, 2, 3]; + + // Struct expression + #[cfg(feature = "len_is_50_____")] + S { f: 1 }; + #[cfg(feature = "len_is_51______")] + S { f: 1 }; + + #[cfg(feature = "len_is_50______")] + MyStruct { + field1: 1, + field2: 1, + }; + #[cfg(feature = "len_is_51_______")] + MyStruct { + field1: 1, + field2: 1, + }; + + // Enum variant expression + #[cfg(feature = "len_is_50")] + MyEnum::Variant; + #[cfg(feature = "len_is_51_")] + MyEnum::Variant; + + // Call expression + #[cfg(feature = "len_is_50")] + some_function(); + #[cfg(feature = "len_is_51_")] + some_function(); + + // Method call expression + #[cfg(feature = "len_is_50")] + object.method(); + #[cfg(feature = "len_is_51_")] + object.method(); + + // Field access expression + #[cfg(feature = "len_is_50")] + my_struct.field; + #[cfg(feature = "len_is_51_")] + my_struct.field; + + // Tuple indexing expression + #[cfg(feature = "len_is_50_____")] + my_tuple.0; + #[cfg(feature = "len_is_51______")] + my_tuple.0; + + // Indexing expression + #[cfg(feature = "len_is_50____")] + my_array[0]; + #[cfg(feature = "len_is_51_____")] + my_array[0]; + + // Range expression + #[cfg(feature = "len_is_50___________")] + 1..5; + #[cfg(feature = "len_is_51____________")] + 1..5; + + // If expression + #[cfg(feature = "len_is_50__")] + if condition { + 1 + }; + #[cfg(feature = "len_is_51___")] + if condition { + 1 + }; + + // Loop expression + #[cfg(feature = "len_is_50__________")] + loop { + break; + } + #[cfg(feature = "len_is_51___________")] + loop { + break; + } + + // While expression + #[cfg(feature = "len_is_50____")] + while cond { + break; + } + #[cfg(feature = "len_is_51_____")] + while cond { + break; + } + + // For expression + #[cfg(feature = "len_is_50")] + for i in 0..10 { + break; + } + #[cfg(feature = "len_is_51_")] + for i in 0..10 { + break; + } + + // Match expression + #[cfg(feature = "len_is_50___")] + match value { + Pattern1 => 1, + _ => 2, + }; + #[cfg(feature = "len_is_51____")] + match value { + Pattern1 => 1, + _ => 2, + }; + + // Return expression + #[cfg(feature = "len_is_50_________")] + return; + #[cfg(feature = "len_is_51__________")] + return; + + // Break expression + #[cfg(feature = "len_is_50__________")] + break; + #[cfg(feature = "len_is_51___________")] + break; + + // Continue expression + #[cfg(feature = "len_is_50_______")] + continue; + #[cfg(feature = "len_is_51________")] + continue; + + // Closure expression + #[cfg(feature = "len_is_50______")] + |x| x + 1; + #[cfg(feature = "len_is_51_______")] + |x| x + 1; + + // Async block expression + #[cfg(feature = "len_is_50_________")] + async { + #[cfg(feature = "len_50__")] + future.await; + #[cfg(feature = "len_51___")] + future.await; + }; + + #[cfg(feature = "len_is_51__________")] + async { + #[cfg(feature = "len_50__")] + future.await; + #[cfg(feature = "len_51___")] + future.await; + }; + + // Try expression + #[cfg(feature = "len_is_50___")] + some_result?; + #[cfg(feature = "len_is_51____")] + some_result?; +} diff --git a/tests/target/configs/inline_attribute_width/50.rs b/tests/target/configs/inline_attribute_width/50.rs index 3490a75af27..f69f99172ff 100644 --- a/tests/target/configs/inline_attribute_width/50.rs +++ b/tests/target/configs/inline_attribute_width/50.rs @@ -1,4 +1,5 @@ // rustfmt-inline_attribute_width: 50 +// rustfmt-edition: 2021 #[cfg(feature = "alloc")] use core::slice; @@ -117,3 +118,185 @@ use total_len_is_::_51______; ) )))] use core::slice; + +fn foo() { + // Literal expression + #[cfg(feature = "len_is_50_____________")] 42; + #[cfg(feature = "len_is_51______________")] + 42; + + // Path expression + #[cfg(feature = "len_is_50__")] some_variable; + #[cfg(feature = "len_is_51___")] + some_variable; + + // Block expression + #[cfg(feature = "len_is_50_______________")] + { + let x = 2; + }; + #[cfg(feature = "len_is_51________________")] + { + let x = 2; + }; + + // Operator expression + #[cfg(feature = "len_is_50__________")] + 1 + 2; + #[cfg(feature = "len_is_51___________")] + 1 + 2; + + // Tuple expression + #[cfg(feature = "len_is_50")] (1, "two", 3.0); + #[cfg(feature = "len_is_51_")] + (1, "two", 3.0); + + // Array expression + #[cfg(feature = "len_is_50______")] [1, 2, 3]; + #[cfg(feature = "len_is_51_______")] + [1, 2, 3]; + + // Struct expression + #[cfg(feature = "len_is_50_____")] S { f: 1 }; + #[cfg(feature = "len_is_51______")] + S { f: 1 }; + + #[cfg(feature = "len_is_50______")] + MyStruct { + field1: 1, + field2: 1, + }; + #[cfg(feature = "len_is_51_______")] + MyStruct { + field1: 1, + field2: 1, + }; + + // Enum variant expression + #[cfg(feature = "len_is_50")] MyEnum::Variant; + #[cfg(feature = "len_is_51_")] + MyEnum::Variant; + + // Call expression + #[cfg(feature = "len_is_50")] some_function(); + #[cfg(feature = "len_is_51_")] + some_function(); + + // Method call expression + #[cfg(feature = "len_is_50")] object.method(); + #[cfg(feature = "len_is_51_")] + object.method(); + + // Field access expression + #[cfg(feature = "len_is_50")] my_struct.field; + #[cfg(feature = "len_is_51_")] + my_struct.field; + + // Tuple indexing expression + #[cfg(feature = "len_is_50_____")] my_tuple.0; + #[cfg(feature = "len_is_51______")] + my_tuple.0; + + // Indexing expression + #[cfg(feature = "len_is_50____")] my_array[0]; + #[cfg(feature = "len_is_51_____")] + my_array[0]; + + // Range expression + #[cfg(feature = "len_is_50___________")] + 1..5; + #[cfg(feature = "len_is_51____________")] + 1..5; + + // If expression + #[cfg(feature = "len_is_50__")] + if condition { + 1 + }; + #[cfg(feature = "len_is_51___")] + if condition { + 1 + }; + + // Loop expression + #[cfg(feature = "len_is_50__________")] + loop { + break; + } + #[cfg(feature = "len_is_51___________")] + loop { + break; + } + + // While expression + #[cfg(feature = "len_is_50____")] + while cond { + break; + } + #[cfg(feature = "len_is_51_____")] + while cond { + break; + } + + // For expression + #[cfg(feature = "len_is_50")] + for i in 0..10 { + break; + } + #[cfg(feature = "len_is_51_")] + for i in 0..10 { + break; + } + + // Match expression + #[cfg(feature = "len_is_50___")] + match value { + Pattern1 => 1, + _ => 2, + }; + #[cfg(feature = "len_is_51____")] + match value { + Pattern1 => 1, + _ => 2, + }; + + // Return expression + #[cfg(feature = "len_is_50_________")] return; + #[cfg(feature = "len_is_51__________")] + return; + + // Break expression + #[cfg(feature = "len_is_50__________")] break; + #[cfg(feature = "len_is_51___________")] + break; + + // Continue expression + #[cfg(feature = "len_is_50_______")] continue; + #[cfg(feature = "len_is_51________")] + continue; + + // Closure expression + #[cfg(feature = "len_is_50______")] |x| x + 1; + #[cfg(feature = "len_is_51_______")] + |x| x + 1; + + // Async block expression + #[cfg(feature = "len_is_50_________")] + async { + #[cfg(feature = "len_50__")] future.await; + #[cfg(feature = "len_51___")] + future.await; + }; + + #[cfg(feature = "len_is_51__________")] + async { + #[cfg(feature = "len_50__")] future.await; + #[cfg(feature = "len_51___")] + future.await; + }; + + // Try expression + #[cfg(feature = "len_is_50___")] some_result?; + #[cfg(feature = "len_is_51____")] + some_result?; +}