Skip to content

Commit 97bdbd9

Browse files
committed
Rename Unsafe to Safety
1 parent 05a2db7 commit 97bdbd9

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

src/items.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ fn allow_single_line_let_else_block(result: &str, block: &ast::Block) -> bool {
247247
#[allow(dead_code)]
248248
#[derive(Debug)]
249249
struct Item<'a> {
250-
unsafety: ast::Unsafe,
250+
safety: ast::Safety,
251251
abi: Cow<'static, str>,
252252
vis: Option<&'a ast::Visibility>,
253253
body: Vec<BodyElement<'a>>,
@@ -257,7 +257,7 @@ struct Item<'a> {
257257
impl<'a> Item<'a> {
258258
fn from_foreign_mod(fm: &'a ast::ForeignMod, span: Span, config: &Config) -> Item<'a> {
259259
Item {
260-
unsafety: fm.unsafety,
260+
safety: fm.safety,
261261
abi: format_extern(
262262
ast::Extern::from_abi(fm.abi, DUMMY_SP),
263263
config.force_explicit_abi(),
@@ -290,7 +290,7 @@ pub(crate) struct FnSig<'a> {
290290
coroutine_kind: Cow<'a, Option<ast::CoroutineKind>>,
291291
constness: ast::Const,
292292
defaultness: ast::Defaultness,
293-
unsafety: ast::Unsafe,
293+
safety: ast::Safety,
294294
visibility: &'a ast::Visibility,
295295
}
296296

@@ -301,7 +301,7 @@ impl<'a> FnSig<'a> {
301301
visibility: &'a ast::Visibility,
302302
) -> FnSig<'a> {
303303
FnSig {
304-
unsafety: method_sig.header.unsafety,
304+
safety: method_sig.header.safety,
305305
coroutine_kind: Cow::Borrowed(&method_sig.header.coroutine_kind),
306306
constness: method_sig.header.constness,
307307
defaultness: ast::Defaultness::Final,
@@ -330,7 +330,7 @@ impl<'a> FnSig<'a> {
330330
constness: fn_sig.header.constness,
331331
coroutine_kind: Cow::Borrowed(&fn_sig.header.coroutine_kind),
332332
defaultness,
333-
unsafety: fn_sig.header.unsafety,
333+
safety: fn_sig.header.safety,
334334
visibility: vis,
335335
},
336336
_ => unreachable!(),
@@ -345,7 +345,7 @@ impl<'a> FnSig<'a> {
345345
result.push_str(format_constness(self.constness));
346346
self.coroutine_kind
347347
.map(|coroutine_kind| result.push_str(format_coro(&coroutine_kind)));
348-
result.push_str(format_unsafety(self.unsafety));
348+
result.push_str(format_safety(self.safety));
349349
result.push_str(&format_extern(
350350
self.ext,
351351
context.config.force_explicit_abi(),
@@ -356,7 +356,7 @@ impl<'a> FnSig<'a> {
356356

357357
impl<'a> FmtVisitor<'a> {
358358
fn format_item(&mut self, item: &Item<'_>) {
359-
self.buffer.push_str(format_unsafety(item.unsafety));
359+
self.buffer.push_str(format_safety(item.safety));
360360
self.buffer.push_str(&item.abi);
361361

362362
let snippet = self.snippet(item.span);
@@ -924,7 +924,7 @@ fn format_impl_ref_and_type(
924924
offset: Indent,
925925
) -> Option<String> {
926926
let ast::Impl {
927-
unsafety,
927+
safety,
928928
polarity,
929929
defaultness,
930930
constness,
@@ -937,7 +937,7 @@ fn format_impl_ref_and_type(
937937

938938
result.push_str(&format_visibility(context, &item.vis));
939939
result.push_str(format_defaultness(defaultness));
940-
result.push_str(format_unsafety(unsafety));
940+
result.push_str(format_safety(safety));
941941

942942
let shape = if context.config.version() == Version::Two {
943943
Shape::indented(offset + last_line_width(&result), context.config)
@@ -1137,7 +1137,7 @@ pub(crate) fn format_trait(
11371137
};
11381138
let ast::Trait {
11391139
is_auto,
1140-
unsafety,
1140+
safety,
11411141
ref generics,
11421142
ref bounds,
11431143
ref items,
@@ -1147,7 +1147,7 @@ pub(crate) fn format_trait(
11471147
let header = format!(
11481148
"{}{}{}trait ",
11491149
format_visibility(context, &item.vis),
1150-
format_unsafety(unsafety),
1150+
format_safety(safety),
11511151
format_auto(is_auto),
11521152
);
11531153
result.push_str(&header);

src/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ fn rewrite_bare_fn(
899899
result.push_str("> ");
900900
}
901901

902-
result.push_str(crate::utils::format_unsafety(bare_fn.unsafety));
902+
result.push_str(crate::utils::format_safety(bare_fn.safety));
903903

904904
result.push_str(&format_extern(
905905
bare_fn.ext,

src/utils.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ pub(crate) fn format_defaultness(defaultness: ast::Defaultness) -> &'static str
108108
}
109109

110110
#[inline]
111-
pub(crate) fn format_unsafety(unsafety: ast::Unsafe) -> &'static str {
111+
pub(crate) fn format_safety(unsafety: ast::Safety) -> &'static str {
112112
match unsafety {
113-
ast::Unsafe::Yes(..) => "unsafe ",
114-
ast::Unsafe::No => "",
113+
ast::Safety::Unsafe(..) => "unsafe ",
114+
ast::Safety::Default => "",
115115
}
116116
}
117117

src/visitor.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::source_map::{LineRangeUtils, SpanUtils};
2424
use crate::spanned::Spanned;
2525
use crate::stmt::Stmt;
2626
use crate::utils::{
27-
self, contains_skip, count_newlines, depr_skip_annotation, format_unsafety, inner_attributes,
27+
self, contains_skip, count_newlines, depr_skip_annotation, format_safety, inner_attributes,
2828
last_line_width, mk_sp, ptr_vec_to_ref_vec, rewrite_ident, starts_with_newline, stmt_expr,
2929
};
3030
use crate::{ErrorKind, FormatReport, FormattingError};
@@ -517,9 +517,9 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
517517
self.visit_enum(item.ident, &item.vis, def, generics, item.span);
518518
self.last_pos = source!(self, item.span).hi();
519519
}
520-
ast::ItemKind::Mod(unsafety, ref mod_kind) => {
520+
ast::ItemKind::Mod(safety, ref mod_kind) => {
521521
self.format_missing_with_indent(source!(self, item.span).lo());
522-
self.format_mod(mod_kind, unsafety, &item.vis, item.span, item.ident, attrs);
522+
self.format_mod(mod_kind, safety, &item.vis, item.span, item.ident, attrs);
523523
}
524524
ast::ItemKind::MacCall(ref mac) => {
525525
self.visit_mac(mac, Some(item.ident), MacroPosition::Item);
@@ -913,15 +913,15 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
913913
fn format_mod(
914914
&mut self,
915915
mod_kind: &ast::ModKind,
916-
unsafety: ast::Unsafe,
916+
safety: ast::Safety,
917917
vis: &ast::Visibility,
918918
s: Span,
919919
ident: symbol::Ident,
920920
attrs: &[ast::Attribute],
921921
) {
922922
let vis_str = utils::format_visibility(&self.get_context(), vis);
923923
self.push_str(&*vis_str);
924-
self.push_str(format_unsafety(unsafety));
924+
self.push_str(format_safety(safety));
925925
self.push_str("mod ");
926926
// Calling `to_owned()` to work around borrow checker.
927927
let ident_str = rewrite_ident(&self.get_context(), ident).to_owned();

0 commit comments

Comments
 (0)