@@ -26,7 +26,7 @@ pub(crate) fn get_attrs_from_stmt(stmt: &ast::Stmt) -> &[ast::Attribute] {
2626
2727pub ( crate ) fn get_span_without_attrs ( stmt : & ast:: Stmt ) -> Span {
2828 match stmt. kind {
29- ast:: StmtKind :: Local ( ref local) => local. span ,
29+ ast:: StmtKind :: Let ( ref local) => local. span ,
3030 ast:: StmtKind :: Item ( ref item) => item. span ,
3131 ast:: StmtKind :: Expr ( ref expr) | ast:: StmtKind :: Semi ( ref expr) => expr. span ,
3232 ast:: StmtKind :: MacCall ( ref mac_stmt) => mac_stmt. mac . span ( ) ,
@@ -353,10 +353,18 @@ impl Rewrite for ast::Attribute {
353353
354354 // 1 = `[`
355355 let shape = shape. offset_left ( prefix. len ( ) + 1 ) ?;
356- Some (
357- meta. rewrite ( context, shape)
358- . map_or_else ( || snippet. to_owned ( ) , |rw| format ! ( "{}[{}]" , prefix, rw) ) ,
359- )
356+ Some ( meta. rewrite ( context, shape) . map_or_else (
357+ || snippet. to_owned ( ) ,
358+ |rw| match & self . kind {
359+ ast:: AttrKind :: Normal ( normal_attr) => match normal_attr. item . unsafety {
360+ // For #![feature(unsafe_attributes)]
361+ // See https://github.com/rust-lang/rust/issues/123757
362+ ast:: Safety :: Unsafe ( _) => format ! ( "{}[unsafe({})]" , prefix, rw) ,
363+ _ => format ! ( "{}[{}]" , prefix, rw) ,
364+ } ,
365+ _ => format ! ( "{}[{}]" , prefix, rw) ,
366+ } ,
367+ ) )
360368 } else {
361369 Some ( snippet. to_owned ( ) )
362370 }
0 commit comments