diff options
| -rw-r--r-- | src/attr.rs | 16 | ||||
| -rw-r--r-- | tests/target/unsafe_attributes.rs | 34 |
2 files changed, 46 insertions, 4 deletions
diff --git a/src/attr.rs b/src/attr.rs index 83f59837d44..433b9256202 100644 --- a/src/attr.rs +++ b/src/attr.rs @@ -353,10 +353,18 @@ impl Rewrite for ast::Attribute { // 1 = `[` let shape = shape.offset_left(prefix.len() + 1)?; - Some( - meta.rewrite(context, shape) - .map_or_else(|| snippet.to_owned(), |rw| format!("{}[{}]", prefix, rw)), - ) + Some(meta.rewrite(context, shape).map_or_else( + || snippet.to_owned(), + |rw| match &self.kind { + ast::AttrKind::Normal(normal_attr) => match normal_attr.item.unsafety { + // For #![feature(unsafe_attributes)] + // See https://github.com/rust-lang/rust/issues/123757 + ast::Safety::Unsafe(_) => format!("{}[unsafe({})]", prefix, rw), + _ => format!("{}[{}]", prefix, rw), + }, + _ => format!("{}[{}]", prefix, rw), + }, + )) } else { Some(snippet.to_owned()) } diff --git a/tests/target/unsafe_attributes.rs b/tests/target/unsafe_attributes.rs new file mode 100644 index 00000000000..a05bedc751a --- /dev/null +++ b/tests/target/unsafe_attributes.rs @@ -0,0 +1,34 @@ +#![feature(unsafe_attributes)] +// https://github.com/rust-lang/rust/issues/123757 +// +#![simple_ident] +#![simple::path] +#![simple_ident_expr = ""] +#![simple::path::Expr = ""] +#![simple_ident_tt(a b c)] +#![simple_ident_tt[a b c]] +#![simple_ident_tt{a b c}] +#![simple::path::tt(a b c)] +#![simple::path::tt[a b c]] +#![simple::path::tt{a b c}] +#![unsafe(simple_ident)] +#![unsafe(simple::path)] +#![unsafe(simple_ident_expr = "")] +#![unsafe(simple::path::Expr = "")] +#![unsafe(simple_ident_tt(a b c))] +#![unsafe(simple_ident_tt[a b c])] +#![unsafe(simple_ident_tt{a b c})] +#![unsafe(simple::path::tt(a b c))] +#![unsafe(simple::path::tt[a b c])] +#![unsafe(simple::path::tt{a b c})] +// I don't think `safe` attributes are a thing, but adding these formatting cases here just in case +#![safe(simple_ident)] +#![safe(simple::path)] +#![safe(simple_ident_expr = "")] +#![safe(simple::path::Expr = "")] +#![safe(simple_ident_tt(a b c))] +#![safe(simple_ident_tt[a b c])] +#![safe(simple_ident_tt{a b c})] +#![safe(simple::path::tt(a b c))] +#![safe(simple::path::tt[a b c])] +#![safe(simple::path::tt{a b c})] |
