Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 0590d71

Browse files
committed
Rename Unsafe to Safety
1 parent 2701a41 commit 0590d71

17 files changed

+57
-62
lines changed

clippy_lints/src/derive.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_errors::Applicability;
55
use rustc_hir::def_id::DefId;
66
use rustc_hir::intravisit::{walk_expr, walk_fn, walk_item, FnKind, Visitor};
77
use rustc_hir::{
8-
self as hir, BlockCheckMode, BodyId, Expr, ExprKind, FnDecl, Impl, Item, ItemKind, UnsafeSource, Unsafety,
8+
self as hir, BlockCheckMode, BodyId, Expr, ExprKind, FnDecl, Safety, Impl, Item, ItemKind, UnsafeSource,
99
};
1010
use rustc_lint::{LateContext, LateLintPass};
1111
use rustc_middle::hir::nested_filter;
@@ -415,7 +415,7 @@ impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> {
415415
}
416416

417417
if let Some(header) = kind.header()
418-
&& header.unsafety == Unsafety::Unsafe
418+
&& header.safety == Safety::Unsafe
419419
{
420420
self.has_unsafe = true;
421421
}

clippy_lints/src/doc/missing_headers.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::{span_lint, span_lint_and_note};
22
use clippy_utils::ty::{implements_trait, is_type_diagnostic_item};
33
use clippy_utils::{is_doc_hidden, return_ty};
4-
use rustc_hir::{BodyId, FnSig, OwnerId, Unsafety};
4+
use rustc_hir::{BodyId, FnSig, OwnerId, Safety};
55
use rustc_lint::LateContext;
66
use rustc_middle::ty;
77
use rustc_span::{sym, Span};
@@ -33,14 +33,14 @@ pub fn check(
3333
}
3434

3535
let span = cx.tcx.def_span(owner_id);
36-
match (headers.safety, sig.header.unsafety) {
37-
(false, Unsafety::Unsafe) => span_lint(
36+
match (headers.safety, sig.header.safety) {
37+
(false, Safety::Unsafe) => span_lint(
3838
cx,
3939
MISSING_SAFETY_DOC,
4040
span,
4141
"unsafe function's docs miss `# Safety` section",
4242
),
43-
(true, Unsafety::Normal) => span_lint(
43+
(true, Safety::Safe) => span_lint(
4444
cx,
4545
UNNECESSARY_SAFETY_DOC,
4646
span,

clippy_lints/src/doc/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use pulldown_cmark::{BrokenLink, CodeBlockKind, CowStr, Options};
1212
use rustc_ast::ast::Attribute;
1313
use rustc_data_structures::fx::FxHashSet;
1414
use rustc_hir::intravisit::{self, Visitor};
15-
use rustc_hir::{AnonConst, Expr, ImplItemKind, ItemKind, Node, TraitItemKind, Unsafety};
15+
use rustc_hir::{AnonConst, Expr, ImplItemKind, ItemKind, Node, Safety, TraitItemKind};
1616
use rustc_lint::{LateContext, LateLintPass, LintContext};
1717
use rustc_middle::hir::nested_filter;
1818
use rustc_middle::lint::in_external_macro;
@@ -415,13 +415,13 @@ impl<'tcx> LateLintPass<'tcx> for Documentation {
415415
}
416416
},
417417
ItemKind::Trait(_, unsafety, ..) => match (headers.safety, unsafety) {
418-
(false, Unsafety::Unsafe) => span_lint(
418+
(false, Safety::Unsafe) => span_lint(
419419
cx,
420420
MISSING_SAFETY_DOC,
421421
cx.tcx.def_span(item.owner_id),
422422
"docs for unsafe trait missing `# Safety` section",
423423
),
424-
(true, Unsafety::Normal) => span_lint(
424+
(true, Safety::Safe) => span_lint(
425425
cx,
426426
UNNECESSARY_SAFETY_DOC,
427427
cx.tcx.def_span(item.owner_id),

clippy_lints/src/eta_reduction.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use clippy_utils::ty::type_diagnostic_name;
55
use clippy_utils::usage::{local_used_after_expr, local_used_in};
66
use clippy_utils::{get_path_from_caller_to_method_type, is_adjusted, path_to_local, path_to_local_id};
77
use rustc_errors::Applicability;
8-
use rustc_hir::{BindingMode, Expr, ExprKind, FnRetTy, Param, PatKind, QPath, TyKind, Unsafety};
8+
use rustc_hir::{BindingMode, Expr, ExprKind, FnRetTy, Param, PatKind, QPath, Safety, TyKind};
99
use rustc_infer::infer::TyCtxtInferExt;
1010
use rustc_lint::{LateContext, LateLintPass};
1111
use rustc_middle::ty::{
@@ -146,15 +146,15 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction {
146146
ty::FnPtr(sig) => sig.skip_binder(),
147147
ty::Closure(_, subs) => cx
148148
.tcx
149-
.signature_unclosure(subs.as_closure().sig(), Unsafety::Normal)
149+
.signature_unclosure(subs.as_closure().sig(), Safety::Safe)
150150
.skip_binder(),
151151
_ => {
152152
if typeck.type_dependent_def_id(body.value.hir_id).is_some()
153153
&& let subs = typeck.node_args(body.value.hir_id)
154154
&& let output = typeck.expr_ty(body.value)
155155
&& let ty::Tuple(tys) = *subs.type_at(1).kind()
156156
{
157-
cx.tcx.mk_fn_sig(tys, output, false, Unsafety::Normal, Abi::Rust)
157+
cx.tcx.mk_fn_sig(tys, output, false, Safety::Safe, Abi::Rust)
158158
} else {
159159
return;
160160
}
@@ -241,11 +241,9 @@ fn check_inputs(
241241
}
242242

243243
fn check_sig<'tcx>(cx: &LateContext<'tcx>, closure: ClosureArgs<'tcx>, call_sig: FnSig<'_>) -> bool {
244-
call_sig.unsafety == Unsafety::Normal
244+
call_sig.safety == Safety::Safe
245245
&& !has_late_bound_to_non_late_bound_regions(
246-
cx.tcx
247-
.signature_unclosure(closure.sig(), Unsafety::Normal)
248-
.skip_binder(),
246+
cx.tcx.signature_unclosure(closure.sig(), Safety::Safe).skip_binder(),
249247
call_sig,
250248
)
251249
}

clippy_lints/src/functions/misnamed_getters.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_then;
22
use clippy_utils::source::snippet;
33
use rustc_errors::Applicability;
44
use rustc_hir::intravisit::FnKind;
5-
use rustc_hir::{Body, ExprKind, FnDecl, ImplicitSelfKind, Unsafety};
5+
use rustc_hir::{Body, ExprKind, FnDecl, Safety, ImplicitSelfKind};
66
use rustc_lint::LateContext;
77
use rustc_middle::ty;
88
use rustc_span::Span;
@@ -34,7 +34,7 @@ pub fn check_fn(cx: &LateContext<'_>, kind: FnKind<'_>, decl: &FnDecl<'_>, body:
3434
ImplicitSelfKind::None => return,
3535
};
3636

37-
let name = if sig.header.unsafety == Unsafety::Unsafe {
37+
let name = if sig.header.safety == Safety::Unsafe {
3838
name.strip_suffix("_unchecked").unwrap_or(name)
3939
} else {
4040
name

clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,30 @@ pub(super) fn check_fn<'tcx>(
1919
body: &'tcx hir::Body<'tcx>,
2020
def_id: LocalDefId,
2121
) {
22-
let unsafety = match kind {
23-
intravisit::FnKind::ItemFn(_, _, hir::FnHeader { unsafety, .. }) => unsafety,
24-
intravisit::FnKind::Method(_, sig) => sig.header.unsafety,
22+
let safety = match kind {
23+
intravisit::FnKind::ItemFn(_, _, hir::FnHeader { safety, .. }) => safety,
24+
intravisit::FnKind::Method(_, sig) => sig.header.safety,
2525
intravisit::FnKind::Closure => return,
2626
};
2727

28-
check_raw_ptr(cx, unsafety, decl, body, def_id);
28+
check_raw_ptr(cx, safety, decl, body, def_id);
2929
}
3030

3131
pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) {
3232
if let hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(eid)) = item.kind {
3333
let body = cx.tcx.hir().body(eid);
34-
check_raw_ptr(cx, sig.header.unsafety, sig.decl, body, item.owner_id.def_id);
34+
check_raw_ptr(cx, sig.header.safety, sig.decl, body, item.owner_id.def_id);
3535
}
3636
}
3737

3838
fn check_raw_ptr<'tcx>(
3939
cx: &LateContext<'tcx>,
40-
unsafety: hir::Unsafety,
40+
safety: hir::Safety,
4141
decl: &'tcx hir::FnDecl<'tcx>,
4242
body: &'tcx hir::Body<'tcx>,
4343
def_id: LocalDefId,
4444
) {
45-
if unsafety == hir::Unsafety::Normal && cx.effective_visibilities.is_exported(def_id) {
45+
if safety == hir::Safety::Safe && cx.effective_visibilities.is_exported(def_id) {
4646
let raw_ptrs = iter_input_pats(decl, body)
4747
.filter_map(|arg| raw_ptr_arg(cx, arg))
4848
.collect::<HirIdSet>();
@@ -58,7 +58,7 @@ fn check_raw_ptr<'tcx>(
5858
},
5959
hir::ExprKind::MethodCall(_, recv, args, _) => {
6060
let def_id = typeck.type_dependent_def_id(e.hir_id).unwrap();
61-
if cx.tcx.fn_sig(def_id).skip_binder().skip_binder().unsafety == hir::Unsafety::Unsafe {
61+
if cx.tcx.fn_sig(def_id).skip_binder().skip_binder().safety == hir::Safety::Unsafe {
6262
check_arg(cx, &raw_ptrs, recv);
6363
for arg in args {
6464
check_arg(cx, &raw_ptrs, arg);

clippy_lints/src/inherent_to_string.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::span_lint_and_help;
22
use clippy_utils::ty::{implements_trait, is_type_lang_item};
33
use clippy_utils::{return_ty, trait_ref_of_method};
4-
use rustc_hir::{GenericParamKind, ImplItem, ImplItemKind, LangItem, Unsafety};
4+
use rustc_hir::{GenericParamKind, ImplItem, ImplItemKind, LangItem, Safety};
55
use rustc_lint::{LateContext, LateLintPass};
66
use rustc_session::declare_lint_pass;
77
use rustc_span::sym;
@@ -99,7 +99,7 @@ impl<'tcx> LateLintPass<'tcx> for InherentToString {
9999
if let ImplItemKind::Fn(ref signature, _) = impl_item.kind
100100
// #11201
101101
&& let header = signature.header
102-
&& header.unsafety == Unsafety::Normal
102+
&& header.safety == Safety::Safe
103103
&& header.abi == Abi::Rust
104104
&& impl_item.ident.name == sym::to_string
105105
&& let decl = signature.decl

clippy_lints/src/methods/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5038,7 +5038,7 @@ fn lint_binary_expr_with_method_call(cx: &LateContext<'_>, info: &mut BinaryExpr
50385038
}
50395039

50405040
const FN_HEADER: hir::FnHeader = hir::FnHeader {
5041-
unsafety: hir::Unsafety::Normal,
5041+
safety: hir::Safety::Safe,
50425042
constness: hir::Constness::NotConst,
50435043
asyncness: hir::IsAsync::NotAsync,
50445044
abi: rustc_target::spec::abi::Abi::Rust,
@@ -5214,7 +5214,5 @@ impl OutType {
52145214
}
52155215

52165216
fn fn_header_equals(expected: hir::FnHeader, actual: hir::FnHeader) -> bool {
5217-
expected.constness == actual.constness
5218-
&& expected.unsafety == actual.unsafety
5219-
&& expected.asyncness == actual.asyncness
5217+
expected.constness == actual.constness && expected.safety == actual.safety && expected.asyncness == actual.asyncness
52205218
}

clippy_lints/src/multiple_unsafe_ops_per_block.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_then;
22
use clippy_utils::visitors::{for_each_expr_with_closures, Descend, Visitable};
33
use core::ops::ControlFlow::Continue;
44
use hir::def::{DefKind, Res};
5-
use hir::{BlockCheckMode, ExprKind, QPath, UnOp, Unsafety};
5+
use hir::{BlockCheckMode, ExprKind, Safety, QPath, UnOp};
66
use rustc_ast::Mutability;
77
use rustc_hir as hir;
88
use rustc_lint::{LateContext, LateLintPass};
@@ -133,7 +133,7 @@ fn collect_unsafe_exprs<'tcx>(
133133
ty::FnPtr(sig) => sig,
134134
_ => return Continue(Descend::Yes),
135135
};
136-
if sig.unsafety() == Unsafety::Unsafe {
136+
if sig.safety() == Safety::Unsafe {
137137
unsafe_ops.push(("unsafe function call occurs here", expr.span));
138138
}
139139
},
@@ -144,7 +144,7 @@ fn collect_unsafe_exprs<'tcx>(
144144
.type_dependent_def_id(expr.hir_id)
145145
.map(|def_id| cx.tcx.fn_sig(def_id))
146146
{
147-
if sig.skip_binder().unsafety() == Unsafety::Unsafe {
147+
if sig.skip_binder().safety() == Safety::Unsafe {
148148
unsafe_ops.push(("unsafe method call occurs here", expr.span));
149149
}
150150
}

clippy_lints/src/new_without_default.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault {
7575
if let hir::ImplItemKind::Fn(ref sig, _) = impl_item.kind {
7676
let name = impl_item.ident.name;
7777
let id = impl_item.owner_id;
78-
if sig.header.unsafety == hir::Unsafety::Unsafe {
78+
if sig.header.safety == hir::Safety::Unsafe {
7979
// can't be implemented for unsafe new
8080
return;
8181
}

0 commit comments

Comments
 (0)