Skip to content

Commit b116480

Browse files
veluca93jhpratt
andcommitted
Implement the unsafe-fields RFC.
Co-Authored-By: Jacob Pratt <[email protected]>
1 parent 224ced5 commit b116480

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

src/items.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1916,15 +1916,15 @@ pub(crate) fn rewrite_struct_field_prefix(
19161916
field: &ast::FieldDef,
19171917
) -> RewriteResult {
19181918
let vis = format_visibility(context, &field.vis);
1919+
let safety = format_safety(field.safety);
19191920
let type_annotation_spacing = type_annotation_spacing(context.config);
19201921
Ok(match field.ident {
19211922
Some(name) => format!(
1922-
"{}{}{}:",
1923-
vis,
1923+
"{vis}{safety}{}{}:",
19241924
rewrite_ident(context, name),
19251925
type_annotation_spacing.0
19261926
),
1927-
None => vis.to_string(),
1927+
None => format!("{vis}{safety}"),
19281928
})
19291929
}
19301930

tests/source/unsafe-field.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
struct Foo {
2+
unsafe
3+
field: (),
4+
}
5+
6+
enum Bar {
7+
Variant {
8+
unsafe
9+
field: (),
10+
},
11+
}
12+
13+
union Baz {
14+
unsafe
15+
field: (),
16+
}

tests/target/unsafe-field.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
struct Foo {
2+
unsafe field: (),
3+
}
4+
5+
enum Bar {
6+
Variant { unsafe field: () },
7+
}
8+
9+
union Baz {
10+
unsafe field: (),
11+
}

0 commit comments

Comments
 (0)