Rename Unsafe to Safety
This commit is contained in:
parent
2701a4175f
commit
0590d71ce2
17 changed files with 57 additions and 62 deletions
|
|
@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_then;
|
|||
use clippy_utils::source::snippet;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::intravisit::FnKind;
|
||||
use rustc_hir::{Body, ExprKind, FnDecl, ImplicitSelfKind, Unsafety};
|
||||
use rustc_hir::{Body, ExprKind, FnDecl, Safety, ImplicitSelfKind};
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_middle::ty;
|
||||
use rustc_span::Span;
|
||||
|
|
@ -34,7 +34,7 @@ pub fn check_fn(cx: &LateContext<'_>, kind: FnKind<'_>, decl: &FnDecl<'_>, body:
|
|||
ImplicitSelfKind::None => return,
|
||||
};
|
||||
|
||||
let name = if sig.header.unsafety == Unsafety::Unsafe {
|
||||
let name = if sig.header.safety == Safety::Unsafe {
|
||||
name.strip_suffix("_unchecked").unwrap_or(name)
|
||||
} else {
|
||||
name
|
||||
|
|
|
|||
|
|
@ -19,30 +19,30 @@ pub(super) fn check_fn<'tcx>(
|
|||
body: &'tcx hir::Body<'tcx>,
|
||||
def_id: LocalDefId,
|
||||
) {
|
||||
let unsafety = match kind {
|
||||
intravisit::FnKind::ItemFn(_, _, hir::FnHeader { unsafety, .. }) => unsafety,
|
||||
intravisit::FnKind::Method(_, sig) => sig.header.unsafety,
|
||||
let safety = match kind {
|
||||
intravisit::FnKind::ItemFn(_, _, hir::FnHeader { safety, .. }) => safety,
|
||||
intravisit::FnKind::Method(_, sig) => sig.header.safety,
|
||||
intravisit::FnKind::Closure => return,
|
||||
};
|
||||
|
||||
check_raw_ptr(cx, unsafety, decl, body, def_id);
|
||||
check_raw_ptr(cx, safety, decl, body, def_id);
|
||||
}
|
||||
|
||||
pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) {
|
||||
if let hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(eid)) = item.kind {
|
||||
let body = cx.tcx.hir().body(eid);
|
||||
check_raw_ptr(cx, sig.header.unsafety, sig.decl, body, item.owner_id.def_id);
|
||||
check_raw_ptr(cx, sig.header.safety, sig.decl, body, item.owner_id.def_id);
|
||||
}
|
||||
}
|
||||
|
||||
fn check_raw_ptr<'tcx>(
|
||||
cx: &LateContext<'tcx>,
|
||||
unsafety: hir::Unsafety,
|
||||
safety: hir::Safety,
|
||||
decl: &'tcx hir::FnDecl<'tcx>,
|
||||
body: &'tcx hir::Body<'tcx>,
|
||||
def_id: LocalDefId,
|
||||
) {
|
||||
if unsafety == hir::Unsafety::Normal && cx.effective_visibilities.is_exported(def_id) {
|
||||
if safety == hir::Safety::Safe && cx.effective_visibilities.is_exported(def_id) {
|
||||
let raw_ptrs = iter_input_pats(decl, body)
|
||||
.filter_map(|arg| raw_ptr_arg(cx, arg))
|
||||
.collect::<HirIdSet>();
|
||||
|
|
@ -58,7 +58,7 @@ fn check_raw_ptr<'tcx>(
|
|||
},
|
||||
hir::ExprKind::MethodCall(_, recv, args, _) => {
|
||||
let def_id = typeck.type_dependent_def_id(e.hir_id).unwrap();
|
||||
if cx.tcx.fn_sig(def_id).skip_binder().skip_binder().unsafety == hir::Unsafety::Unsafe {
|
||||
if cx.tcx.fn_sig(def_id).skip_binder().skip_binder().safety == hir::Safety::Unsafe {
|
||||
check_arg(cx, &raw_ptrs, recv);
|
||||
for arg in args {
|
||||
check_arg(cx, &raw_ptrs, arg);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue