format #![feature(unsafe_attributes)]
Our diff-check job was failing in part due to removing `unsafe` from any `#[unsafe(attributes)]`. To prevent that I added a quick implementation for this.
This commit is contained in:
parent
8e80f8aa3a
commit
8abbcad938
16
src/attr.rs
16
src/attr.rs
@ -353,10 +353,18 @@ fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String>
|
||||
|
||||
// 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())
|
||||
}
|
||||
|
34
tests/target/unsafe_attributes.rs
Normal file
34
tests/target/unsafe_attributes.rs
Normal file
@ -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})]
|
Loading…
Reference in New Issue
Block a user