Skip to content

Commit c9139bd

Browse files
committed
Auto merge of #12867 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: none
2 parents da4b212 + 280ed2b commit c9139bd

40 files changed

+169
-154
lines changed

clippy_dev/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(lazy_cell)]
21
#![feature(let_chains)]
32
#![feature(rustc_private)]
43
#![cfg_attr(feature = "deny-warnings", deny(warnings))]

clippy_lints/src/derive.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ 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, Impl, Item, ItemKind, Safety, UnsafeSource,
99
};
1010
use rustc_lint::{LateContext, LateLintPass};
1111
use rustc_middle::hir::nested_filter;
1212
use rustc_middle::traits::Reveal;
1313
use rustc_middle::ty::{
14-
self, ClauseKind, GenericArgKind, GenericParamDefKind, ParamEnv, ToPredicate, TraitPredicate, Ty, TyCtxt,
14+
self, ClauseKind, GenericArgKind, GenericParamDefKind, ParamEnv, TraitPredicate, Ty, TyCtxt, Upcast,
1515
};
1616
use rustc_session::declare_lint_pass;
1717
use rustc_span::def_id::LocalDefId;
@@ -419,7 +419,7 @@ impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> {
419419
}
420420

421421
if let Some(header) = kind.header()
422-
&& header.unsafety == Unsafety::Unsafe
422+
&& header.safety == Safety::Unsafe
423423
{
424424
self.has_unsafe = true;
425425
}
@@ -514,7 +514,7 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) ->
514514
trait_ref: ty::TraitRef::new(tcx, eq_trait_id, [tcx.mk_param_from_def(param)]),
515515
polarity: ty::PredicatePolarity::Positive,
516516
})
517-
.to_predicate(tcx)
517+
.upcast(tcx)
518518
}),
519519
)),
520520
Reveal::UserFacing,

clippy_lints/src/doc/missing_headers.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::{DocHeaders, MISSING_ERRORS_DOC, MISSING_PANICS_DOC, MISSING_SAFETY_D
22
use clippy_utils::diagnostics::{span_lint, span_lint_and_note};
33
use clippy_utils::ty::{implements_trait, is_type_diagnostic_item};
44
use clippy_utils::{is_doc_hidden, return_ty};
5-
use rustc_hir::{BodyId, FnSig, OwnerId, Unsafety};
5+
use rustc_hir::{BodyId, FnSig, OwnerId, Safety};
66
use rustc_lint::LateContext;
77
use rustc_middle::ty;
88
use rustc_span::{sym, Span};
@@ -32,14 +32,14 @@ pub fn check(
3232
}
3333

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

clippy_lints/src/doc/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use pulldown_cmark::{BrokenLink, CodeBlockKind, CowStr, Options};
1313
use rustc_ast::ast::Attribute;
1414
use rustc_data_structures::fx::FxHashSet;
1515
use rustc_hir::intravisit::{self, Visitor};
16-
use rustc_hir::{AnonConst, Expr, ImplItemKind, ItemKind, Node, TraitItemKind, Unsafety};
16+
use rustc_hir::{AnonConst, Expr, ImplItemKind, ItemKind, Node, Safety, TraitItemKind};
1717
use rustc_lint::{LateContext, LateLintPass, LintContext};
1818
use rustc_middle::hir::nested_filter;
1919
use rustc_middle::lint::in_external_macro;
@@ -474,13 +474,13 @@ impl<'tcx> LateLintPass<'tcx> for Documentation {
474474
}
475475
},
476476
ItemKind::Trait(_, unsafety, ..) => match (headers.safety, unsafety) {
477-
(false, Unsafety::Unsafe) => span_lint(
477+
(false, Safety::Unsafe) => span_lint(
478478
cx,
479479
MISSING_SAFETY_DOC,
480480
cx.tcx.def_span(item.owner_id),
481481
"docs for unsafe trait missing `# Safety` section",
482482
),
483-
(true, Unsafety::Normal) => span_lint(
483+
(true, Safety::Safe) => span_lint(
484484
cx,
485485
UNNECESSARY_SAFETY_DOC,
486486
cx.tcx.def_span(item.owner_id),

clippy_lints/src/eta_reduction.rs

+5-7
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

+2-2
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, ImplicitSelfKind, Safety};
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

+8-8
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

+2-2
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/iter_without_into_iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ impl {self_ty_without_ref} {{
225225
&& let ImplItemKind::Fn(sig, _) = item.kind
226226
&& let FnRetTy::Return(ret) = sig.decl.output
227227
&& is_nameable_in_impl_trait(ret)
228-
&& cx.tcx.generics_of(item_did).own_params.is_empty()
228+
&& cx.tcx.generics_of(item_did).is_own_empty()
229229
&& sig.decl.implicit_self == expected_implicit_self
230230
&& sig.decl.inputs.len() == 1
231231
&& let Some(imp) = get_parent_as_impl(cx.tcx, item.hir_id())

clippy_lints/src/methods/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -5052,7 +5052,7 @@ fn lint_binary_expr_with_method_call(cx: &LateContext<'_>, info: &mut BinaryExpr
50525052
}
50535053

50545054
const FN_HEADER: hir::FnHeader = hir::FnHeader {
5055-
unsafety: hir::Unsafety::Normal,
5055+
safety: hir::Safety::Safe,
50565056
constness: hir::Constness::NotConst,
50575057
asyncness: hir::IsAsync::NotAsync,
50585058
abi: rustc_target::spec::abi::Abi::Rust,
@@ -5228,7 +5228,5 @@ impl OutType {
52285228
}
52295229

52305230
fn fn_header_equals(expected: hir::FnHeader, actual: hir::FnHeader) -> bool {
5231-
expected.constness == actual.constness
5232-
&& expected.unsafety == actual.unsafety
5233-
&& expected.asyncness == actual.asyncness
5231+
expected.constness == actual.constness && expected.safety == actual.safety && expected.asyncness == actual.asyncness
52345232
}

clippy_lints/src/methods/needless_collect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ pub(super) fn check<'tcx>(
127127
}
128128
}
129129

130-
/// checks for for collecting into a (generic) method or function argument
130+
/// checks for collecting into a (generic) method or function argument
131131
/// taking an `IntoIterator`
132132
fn check_collect_into_intoiterator<'tcx>(
133133
cx: &LateContext<'tcx>,

clippy_lints/src/multiple_unsafe_ops_per_block.rs

+3-3
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, QPath, Safety, 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

+1-1
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
}

clippy_lints/src/ptr.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_hir::hir_id::{HirId, HirIdMap};
1212
use rustc_hir::intravisit::{walk_expr, Visitor};
1313
use rustc_hir::{
1414
self as hir, AnonConst, BinOpKind, BindingMode, Body, Expr, ExprKind, FnRetTy, FnSig, GenericArg, ImplItemKind,
15-
ItemKind, Lifetime, Mutability, Node, Param, PatKind, QPath, TraitFn, TraitItem, TraitItemKind, TyKind, Unsafety,
15+
ItemKind, Lifetime, Mutability, Node, Param, PatKind, QPath, Safety, TraitFn, TraitItem, TraitItemKind, TyKind,
1616
};
1717
use rustc_infer::infer::TyCtxtInferExt;
1818
use rustc_infer::traits::{Obligation, ObligationCause};
@@ -460,13 +460,19 @@ fn check_fn_args<'cx, 'tcx: 'cx>(
460460
}
461461
None
462462
}) {
463-
if !lifetime.is_anonymous()
463+
if let LifetimeName::Param(param_def_id) = lifetime.res
464+
&& !lifetime.is_anonymous()
464465
&& fn_sig
465466
.output()
466467
.walk()
467468
.filter_map(|arg| {
468469
arg.as_region().and_then(|lifetime| match lifetime.kind() {
469-
ty::ReEarlyParam(r) => Some(r.def_id),
470+
ty::ReEarlyParam(r) => Some(
471+
cx.tcx
472+
.generics_of(cx.tcx.parent(param_def_id.to_def_id()))
473+
.region_param(r, cx.tcx)
474+
.def_id,
475+
),
470476
ty::ReBound(_, r) => r.kind.get_id(),
471477
ty::ReLateParam(r) => r.bound_region.get_id(),
472478
ty::ReStatic
@@ -476,14 +482,7 @@ fn check_fn_args<'cx, 'tcx: 'cx>(
476482
| ty::ReError(_) => None,
477483
})
478484
})
479-
.any(|def_id| {
480-
matches!(
481-
lifetime.res,
482-
LifetimeName::Param(param_def_id) if def_id
483-
.as_local()
484-
.is_some_and(|def_id| def_id == param_def_id),
485-
)
486-
})
485+
.any(|def_id| def_id.as_local().is_some_and(|def_id| def_id == param_def_id))
487486
{
488487
// `&Cow<'a, T>` when the return type uses 'a is okay
489488
return None;
@@ -542,7 +541,7 @@ fn check_mut_from_ref<'tcx>(cx: &LateContext<'tcx>, sig: &FnSig<'_>, body: Optio
542541
if let Some(args) = args
543542
&& !args.is_empty()
544543
&& body.map_or(true, |body| {
545-
sig.header.unsafety == Unsafety::Unsafe || contains_unsafe_block(cx, body.value)
544+
sig.header.safety == Safety::Unsafe || contains_unsafe_block(cx, body.value)
546545
})
547546
{
548547
span_lint_and_then(

clippy_lints/src/transmute/transmute_undefined_repr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ fn reduce_ty<'tcx>(cx: &LateContext<'tcx>, mut ty: Ty<'tcx>) -> ReducedTy<'tcx>
278278
ty = sized_ty;
279279
continue;
280280
}
281-
if def.repr().inhibit_struct_field_reordering_opt() {
281+
if def.repr().inhibit_struct_field_reordering() {
282282
ReducedTy::OrderedFields(Some(sized_ty))
283283
} else {
284284
ReducedTy::UnorderedFields(ty)

clippy_lints/src/undocumented_unsafe_blocks.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks {
199199
let item_has_safety_comment = item_has_safety_comment(cx, item);
200200
match (&item.kind, item_has_safety_comment) {
201201
// lint unsafe impl without safety comment
202-
(ItemKind::Impl(impl_), HasSafetyComment::No) if impl_.unsafety == hir::Unsafety::Unsafe => {
202+
(ItemKind::Impl(impl_), HasSafetyComment::No) if impl_.safety == hir::Safety::Unsafe => {
203203
if !is_lint_allowed(cx, UNDOCUMENTED_UNSAFE_BLOCKS, item.hir_id())
204204
&& !is_unsafe_from_proc_macro(cx, item.span)
205205
{
@@ -221,7 +221,7 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks {
221221
}
222222
},
223223
// lint safe impl with unnecessary safety comment
224-
(ItemKind::Impl(impl_), HasSafetyComment::Yes(pos)) if impl_.unsafety == hir::Unsafety::Normal => {
224+
(ItemKind::Impl(impl_), HasSafetyComment::Yes(pos)) if impl_.safety == hir::Safety::Safe => {
225225
if !is_lint_allowed(cx, UNNECESSARY_SAFETY_COMMENT, item.hir_id()) {
226226
let (span, help_span) = mk_spans(pos);
227227

0 commit comments

Comments
 (0)