Implement the unsafe-fields RFC.
Co-Authored-By: Jacob Pratt <jacob@jhpratt.dev>
This commit is contained in:
parent
75703c1a78
commit
9022bb2d6f
38 changed files with 793 additions and 85 deletions
|
|
@ -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}"),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
16
src/tools/rustfmt/tests/source/unsafe-field.rs
Normal file
16
src/tools/rustfmt/tests/source/unsafe-field.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
struct Foo {
|
||||
unsafe
|
||||
field: (),
|
||||
}
|
||||
|
||||
enum Bar {
|
||||
Variant {
|
||||
unsafe
|
||||
field: (),
|
||||
},
|
||||
}
|
||||
|
||||
union Baz {
|
||||
unsafe
|
||||
field: (),
|
||||
}
|
||||
11
src/tools/rustfmt/tests/target/unsafe-field.rs
Normal file
11
src/tools/rustfmt/tests/target/unsafe-field.rs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
struct Foo {
|
||||
unsafe field: (),
|
||||
}
|
||||
|
||||
enum Bar {
|
||||
Variant { unsafe field: () },
|
||||
}
|
||||
|
||||
union Baz {
|
||||
unsafe field: (),
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue