Implement the unsafe-fields RFC.

Co-Authored-By: Jacob Pratt <jacob@jhpratt.dev>
This commit is contained in:
Luca Versari 2024-10-27 01:35:33 +02:00
parent 75703c1a78
commit 9022bb2d6f
38 changed files with 793 additions and 85 deletions

View file

@ -1916,15 +1916,15 @@ pub(crate) fn rewrite_struct_field_prefix(
field: &ast::FieldDef,
) -> RewriteResult {
let vis = format_visibility(context, &field.vis);
let safety = format_safety(field.safety);
let type_annotation_spacing = type_annotation_spacing(context.config);
Ok(match field.ident {
Some(name) => format!(
"{}{}{}:",
vis,
"{vis}{safety}{}{}:",
rewrite_ident(context, name),
type_annotation_spacing.0
),
None => vis.to_string(),
None => format!("{vis}{safety}"),
})
}

View file

@ -0,0 +1,16 @@
struct Foo {
unsafe
field: (),
}
enum Bar {
Variant {
unsafe
field: (),
},
}
union Baz {
unsafe
field: (),
}

View file

@ -0,0 +1,11 @@
struct Foo {
unsafe field: (),
}
enum Bar {
Variant { unsafe field: () },
}
union Baz {
unsafe field: (),
}