Merge from rustc
This commit is contained in:
commit
3460853a45
340 changed files with 5382 additions and 2301 deletions
|
|
@ -1 +1 @@
|
|||
Subproject commit 4de0094ac78743d2c8ff682489e35c8a7cafe8e4
|
||||
Subproject commit 0de7f2ec6c39d68022e6b97a39559d2f4dbf3930
|
||||
|
|
@ -5,13 +5,13 @@ use rustc_errors::Applicability;
|
|||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::intravisit::{walk_expr, walk_fn, walk_item, FnKind, Visitor};
|
||||
use rustc_hir::{
|
||||
self as hir, BlockCheckMode, BodyId, Expr, ExprKind, FnDecl, Impl, Item, ItemKind, UnsafeSource, Unsafety,
|
||||
self as hir, BlockCheckMode, BodyId, Expr, ExprKind, FnDecl, Safety, Impl, Item, ItemKind, UnsafeSource,
|
||||
};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::hir::nested_filter;
|
||||
use rustc_middle::traits::Reveal;
|
||||
use rustc_middle::ty::{
|
||||
self, ClauseKind, GenericArgKind, GenericParamDefKind, ParamEnv, ToPredicate, TraitPredicate, Ty, TyCtxt,
|
||||
self, ClauseKind, GenericArgKind, GenericParamDefKind, ParamEnv, Upcast, TraitPredicate, Ty, TyCtxt,
|
||||
};
|
||||
use rustc_session::declare_lint_pass;
|
||||
use rustc_span::def_id::LocalDefId;
|
||||
|
|
@ -415,7 +415,7 @@ impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> {
|
|||
}
|
||||
|
||||
if let Some(header) = kind.header()
|
||||
&& header.unsafety == Unsafety::Unsafe
|
||||
&& header.safety == Safety::Unsafe
|
||||
{
|
||||
self.has_unsafe = true;
|
||||
}
|
||||
|
|
@ -503,7 +503,7 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) ->
|
|||
trait_ref: ty::TraitRef::new(tcx, eq_trait_id, [tcx.mk_param_from_def(param)]),
|
||||
polarity: ty::PredicatePolarity::Positive,
|
||||
})
|
||||
.to_predicate(tcx)
|
||||
.upcast(tcx)
|
||||
}),
|
||||
)),
|
||||
Reveal::UserFacing,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use clippy_utils::diagnostics::{span_lint, span_lint_and_note};
|
||||
use clippy_utils::ty::{implements_trait, is_type_diagnostic_item};
|
||||
use clippy_utils::{is_doc_hidden, return_ty};
|
||||
use rustc_hir::{BodyId, FnSig, OwnerId, Unsafety};
|
||||
use rustc_hir::{BodyId, FnSig, OwnerId, Safety};
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_middle::ty;
|
||||
use rustc_span::{sym, Span};
|
||||
|
|
@ -33,14 +33,14 @@ pub fn check(
|
|||
}
|
||||
|
||||
let span = cx.tcx.def_span(owner_id);
|
||||
match (headers.safety, sig.header.unsafety) {
|
||||
(false, Unsafety::Unsafe) => span_lint(
|
||||
match (headers.safety, sig.header.safety) {
|
||||
(false, Safety::Unsafe) => span_lint(
|
||||
cx,
|
||||
MISSING_SAFETY_DOC,
|
||||
span,
|
||||
"unsafe function's docs miss `# Safety` section",
|
||||
),
|
||||
(true, Unsafety::Normal) => span_lint(
|
||||
(true, Safety::Safe) => span_lint(
|
||||
cx,
|
||||
UNNECESSARY_SAFETY_DOC,
|
||||
span,
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use pulldown_cmark::{BrokenLink, CodeBlockKind, CowStr, Options};
|
|||
use rustc_ast::ast::Attribute;
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_hir::intravisit::{self, Visitor};
|
||||
use rustc_hir::{AnonConst, Expr, ImplItemKind, ItemKind, Node, TraitItemKind, Unsafety};
|
||||
use rustc_hir::{AnonConst, Expr, ImplItemKind, ItemKind, Node, Safety, TraitItemKind};
|
||||
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||
use rustc_middle::hir::nested_filter;
|
||||
use rustc_middle::lint::in_external_macro;
|
||||
|
|
@ -415,13 +415,13 @@ impl<'tcx> LateLintPass<'tcx> for Documentation {
|
|||
}
|
||||
},
|
||||
ItemKind::Trait(_, unsafety, ..) => match (headers.safety, unsafety) {
|
||||
(false, Unsafety::Unsafe) => span_lint(
|
||||
(false, Safety::Unsafe) => span_lint(
|
||||
cx,
|
||||
MISSING_SAFETY_DOC,
|
||||
cx.tcx.def_span(item.owner_id),
|
||||
"docs for unsafe trait missing `# Safety` section",
|
||||
),
|
||||
(true, Unsafety::Normal) => span_lint(
|
||||
(true, Safety::Safe) => span_lint(
|
||||
cx,
|
||||
UNNECESSARY_SAFETY_DOC,
|
||||
cx.tcx.def_span(item.owner_id),
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use clippy_utils::ty::type_diagnostic_name;
|
|||
use clippy_utils::usage::{local_used_after_expr, local_used_in};
|
||||
use clippy_utils::{get_path_from_caller_to_method_type, is_adjusted, path_to_local, path_to_local_id};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::{BindingMode, Expr, ExprKind, FnRetTy, Param, PatKind, QPath, TyKind, Unsafety};
|
||||
use rustc_hir::{BindingMode, Expr, ExprKind, FnRetTy, Param, PatKind, QPath, Safety, TyKind};
|
||||
use rustc_infer::infer::TyCtxtInferExt;
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::ty::{
|
||||
|
|
@ -146,7 +146,7 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction {
|
|||
ty::FnPtr(sig) => sig.skip_binder(),
|
||||
ty::Closure(_, subs) => cx
|
||||
.tcx
|
||||
.signature_unclosure(subs.as_closure().sig(), Unsafety::Normal)
|
||||
.signature_unclosure(subs.as_closure().sig(), Safety::Safe)
|
||||
.skip_binder(),
|
||||
_ => {
|
||||
if typeck.type_dependent_def_id(body.value.hir_id).is_some()
|
||||
|
|
@ -154,7 +154,7 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction {
|
|||
&& let output = typeck.expr_ty(body.value)
|
||||
&& let ty::Tuple(tys) = *subs.type_at(1).kind()
|
||||
{
|
||||
cx.tcx.mk_fn_sig(tys, output, false, Unsafety::Normal, Abi::Rust)
|
||||
cx.tcx.mk_fn_sig(tys, output, false, Safety::Safe, Abi::Rust)
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
|
@ -241,11 +241,9 @@ fn check_inputs(
|
|||
}
|
||||
|
||||
fn check_sig<'tcx>(cx: &LateContext<'tcx>, closure: ClosureArgs<'tcx>, call_sig: FnSig<'_>) -> bool {
|
||||
call_sig.unsafety == Unsafety::Normal
|
||||
call_sig.safety == Safety::Safe
|
||||
&& !has_late_bound_to_non_late_bound_regions(
|
||||
cx.tcx
|
||||
.signature_unclosure(closure.sig(), Unsafety::Normal)
|
||||
.skip_binder(),
|
||||
cx.tcx.signature_unclosure(closure.sig(), Safety::Safe).skip_binder(),
|
||||
call_sig,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use clippy_utils::diagnostics::span_lint_and_help;
|
||||
use clippy_utils::ty::{implements_trait, is_type_lang_item};
|
||||
use clippy_utils::{return_ty, trait_ref_of_method};
|
||||
use rustc_hir::{GenericParamKind, ImplItem, ImplItemKind, LangItem, Unsafety};
|
||||
use rustc_hir::{GenericParamKind, ImplItem, ImplItemKind, LangItem, Safety};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_session::declare_lint_pass;
|
||||
use rustc_span::sym;
|
||||
|
|
@ -99,7 +99,7 @@ impl<'tcx> LateLintPass<'tcx> for InherentToString {
|
|||
if let ImplItemKind::Fn(ref signature, _) = impl_item.kind
|
||||
// #11201
|
||||
&& let header = signature.header
|
||||
&& header.unsafety == Unsafety::Normal
|
||||
&& header.safety == Safety::Safe
|
||||
&& header.abi == Abi::Rust
|
||||
&& impl_item.ident.name == sym::to_string
|
||||
&& let decl = signature.decl
|
||||
|
|
|
|||
|
|
@ -5038,7 +5038,7 @@ fn lint_binary_expr_with_method_call(cx: &LateContext<'_>, info: &mut BinaryExpr
|
|||
}
|
||||
|
||||
const FN_HEADER: hir::FnHeader = hir::FnHeader {
|
||||
unsafety: hir::Unsafety::Normal,
|
||||
safety: hir::Safety::Safe,
|
||||
constness: hir::Constness::NotConst,
|
||||
asyncness: hir::IsAsync::NotAsync,
|
||||
abi: rustc_target::spec::abi::Abi::Rust,
|
||||
|
|
@ -5214,7 +5214,5 @@ impl OutType {
|
|||
}
|
||||
|
||||
fn fn_header_equals(expected: hir::FnHeader, actual: hir::FnHeader) -> bool {
|
||||
expected.constness == actual.constness
|
||||
&& expected.unsafety == actual.unsafety
|
||||
&& expected.asyncness == actual.asyncness
|
||||
expected.constness == actual.constness && expected.safety == actual.safety && expected.asyncness == actual.asyncness
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_then;
|
|||
use clippy_utils::visitors::{for_each_expr_with_closures, Descend, Visitable};
|
||||
use core::ops::ControlFlow::Continue;
|
||||
use hir::def::{DefKind, Res};
|
||||
use hir::{BlockCheckMode, ExprKind, QPath, UnOp, Unsafety};
|
||||
use hir::{BlockCheckMode, ExprKind, Safety, QPath, UnOp};
|
||||
use rustc_ast::Mutability;
|
||||
use rustc_hir as hir;
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
|
|
@ -133,7 +133,7 @@ fn collect_unsafe_exprs<'tcx>(
|
|||
ty::FnPtr(sig) => sig,
|
||||
_ => return Continue(Descend::Yes),
|
||||
};
|
||||
if sig.unsafety() == Unsafety::Unsafe {
|
||||
if sig.safety() == Safety::Unsafe {
|
||||
unsafe_ops.push(("unsafe function call occurs here", expr.span));
|
||||
}
|
||||
},
|
||||
|
|
@ -144,7 +144,7 @@ fn collect_unsafe_exprs<'tcx>(
|
|||
.type_dependent_def_id(expr.hir_id)
|
||||
.map(|def_id| cx.tcx.fn_sig(def_id))
|
||||
{
|
||||
if sig.skip_binder().unsafety() == Unsafety::Unsafe {
|
||||
if sig.skip_binder().safety() == Safety::Unsafe {
|
||||
unsafe_ops.push(("unsafe method call occurs here", expr.span));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault {
|
|||
if let hir::ImplItemKind::Fn(ref sig, _) = impl_item.kind {
|
||||
let name = impl_item.ident.name;
|
||||
let id = impl_item.owner_id;
|
||||
if sig.header.unsafety == hir::Unsafety::Unsafe {
|
||||
if sig.header.safety == hir::Safety::Unsafe {
|
||||
// can't be implemented for unsafe new
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use rustc_hir::hir_id::{HirId, HirIdMap};
|
|||
use rustc_hir::intravisit::{walk_expr, Visitor};
|
||||
use rustc_hir::{
|
||||
self as hir, AnonConst, BinOpKind, BindingMode, Body, Expr, ExprKind, FnRetTy, FnSig, GenericArg, ImplItemKind,
|
||||
ItemKind, Lifetime, Mutability, Node, Param, PatKind, QPath, TraitFn, TraitItem, TraitItemKind, TyKind, Unsafety,
|
||||
ItemKind, Lifetime, Mutability, Node, Param, PatKind, QPath, Safety, TraitFn, TraitItem, TraitItemKind, TyKind,
|
||||
};
|
||||
use rustc_infer::infer::TyCtxtInferExt;
|
||||
use rustc_infer::traits::{Obligation, ObligationCause};
|
||||
|
|
@ -542,7 +542,7 @@ fn check_mut_from_ref<'tcx>(cx: &LateContext<'tcx>, sig: &FnSig<'_>, body: Optio
|
|||
if let Some(args) = args
|
||||
&& !args.is_empty()
|
||||
&& body.map_or(true, |body| {
|
||||
sig.header.unsafety == Unsafety::Unsafe || contains_unsafe_block(cx, body.value)
|
||||
sig.header.safety == Safety::Unsafe || contains_unsafe_block(cx, body.value)
|
||||
})
|
||||
{
|
||||
span_lint_and_then(
|
||||
|
|
|
|||
|
|
@ -200,7 +200,7 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks {
|
|||
let item_has_safety_comment = item_has_safety_comment(cx, item);
|
||||
match (&item.kind, item_has_safety_comment) {
|
||||
// lint unsafe impl without safety comment
|
||||
(ItemKind::Impl(impl_), HasSafetyComment::No) if impl_.unsafety == hir::Unsafety::Unsafe => {
|
||||
(ItemKind::Impl(impl_), HasSafetyComment::No) if impl_.safety == hir::Safety::Unsafe => {
|
||||
if !is_lint_allowed(cx, UNDOCUMENTED_UNSAFE_BLOCKS, item.hir_id())
|
||||
&& !is_unsafe_from_proc_macro(cx, item.span)
|
||||
{
|
||||
|
|
@ -222,7 +222,7 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks {
|
|||
}
|
||||
},
|
||||
// lint safe impl with unnecessary safety comment
|
||||
(ItemKind::Impl(impl_), HasSafetyComment::Yes(pos)) if impl_.unsafety == hir::Unsafety::Normal => {
|
||||
(ItemKind::Impl(impl_), HasSafetyComment::Yes(pos)) if impl_.safety == hir::Safety::Safe => {
|
||||
if !is_lint_allowed(cx, UNNECESSARY_SAFETY_COMMENT, item.hir_id()) {
|
||||
let (span, help_span) = mk_spans(pos);
|
||||
|
||||
|
|
|
|||
|
|
@ -386,21 +386,21 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool {
|
|||
(
|
||||
Trait(box ast::Trait {
|
||||
is_auto: la,
|
||||
unsafety: lu,
|
||||
safety: lu,
|
||||
generics: lg,
|
||||
bounds: lb,
|
||||
items: li,
|
||||
}),
|
||||
Trait(box ast::Trait {
|
||||
is_auto: ra,
|
||||
unsafety: ru,
|
||||
safety: ru,
|
||||
generics: rg,
|
||||
bounds: rb,
|
||||
items: ri,
|
||||
}),
|
||||
) => {
|
||||
la == ra
|
||||
&& matches!(lu, Unsafe::No) == matches!(ru, Unsafe::No)
|
||||
&& matches!(lu, Safety::Default) == matches!(ru, Safety::Default)
|
||||
&& eq_generics(lg, rg)
|
||||
&& over(lb, rb, eq_generic_bound)
|
||||
&& over(li, ri, |l, r| eq_item(l, r, eq_assoc_item_kind))
|
||||
|
|
@ -408,7 +408,7 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool {
|
|||
(TraitAlias(lg, lb), TraitAlias(rg, rb)) => eq_generics(lg, rg) && over(lb, rb, eq_generic_bound),
|
||||
(
|
||||
Impl(box ast::Impl {
|
||||
unsafety: lu,
|
||||
safety: lu,
|
||||
polarity: lp,
|
||||
defaultness: ld,
|
||||
constness: lc,
|
||||
|
|
@ -418,7 +418,7 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool {
|
|||
items: li,
|
||||
}),
|
||||
Impl(box ast::Impl {
|
||||
unsafety: ru,
|
||||
safety: ru,
|
||||
polarity: rp,
|
||||
defaultness: rd,
|
||||
constness: rc,
|
||||
|
|
@ -428,7 +428,7 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool {
|
|||
items: ri,
|
||||
}),
|
||||
) => {
|
||||
matches!(lu, Unsafe::No) == matches!(ru, Unsafe::No)
|
||||
matches!(lu, Safety::Default) == matches!(ru, Safety::Default)
|
||||
&& matches!(lp, ImplPolarity::Positive) == matches!(rp, ImplPolarity::Positive)
|
||||
&& eq_defaultness(*ld, *rd)
|
||||
&& matches!(lc, ast::Const::No) == matches!(rc, ast::Const::No)
|
||||
|
|
@ -605,7 +605,7 @@ fn eq_opt_coroutine_kind(l: Option<CoroutineKind>, r: Option<CoroutineKind>) ->
|
|||
}
|
||||
|
||||
pub fn eq_fn_header(l: &FnHeader, r: &FnHeader) -> bool {
|
||||
matches!(l.unsafety, Unsafe::No) == matches!(r.unsafety, Unsafe::No)
|
||||
matches!(l.safety, Safety::Default) == matches!(r.safety, Safety::Default)
|
||||
&& eq_opt_coroutine_kind(l.coroutine_kind, r.coroutine_kind)
|
||||
&& matches!(l.constness, Const::No) == matches!(r.constness, Const::No)
|
||||
&& eq_ext(&l.ext, &r.ext)
|
||||
|
|
@ -712,7 +712,7 @@ pub fn eq_ty(l: &Ty, r: &Ty) -> bool {
|
|||
both(ll, rl, |l, r| eq_id(l.ident, r.ident)) && l.mutbl == r.mutbl && eq_ty(&l.ty, &r.ty)
|
||||
},
|
||||
(BareFn(l), BareFn(r)) => {
|
||||
l.unsafety == r.unsafety
|
||||
l.safety == r.safety
|
||||
&& eq_ext(&l.ext, &r.ext)
|
||||
&& over(&l.generic_params, &r.generic_params, eq_generic_param)
|
||||
&& eq_fn_decl(&l.decl, &r.decl)
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ use rustc_ast::AttrStyle;
|
|||
use rustc_hir::intravisit::FnKind;
|
||||
use rustc_hir::{
|
||||
Block, BlockCheckMode, Body, Closure, Destination, Expr, ExprKind, FieldDef, FnHeader, FnRetTy, HirId, Impl,
|
||||
ImplItem, ImplItemKind, IsAuto, Item, ItemKind, LoopSource, MatchSource, MutTy, Node, QPath, TraitItem,
|
||||
TraitItemKind, Ty, TyKind, UnOp, UnsafeSource, Unsafety, Variant, VariantData, YieldSource,
|
||||
ImplItem, ImplItemKind, IsAuto, Item, ItemKind, LoopSource, MatchSource, MutTy, Node, QPath, Safety, TraitItem,
|
||||
TraitItemKind, Ty, TyKind, UnOp, UnsafeSource, Variant, VariantData, YieldSource,
|
||||
};
|
||||
use rustc_lint::{LateContext, LintContext};
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
|
|
@ -207,10 +207,9 @@ fn item_search_pat(item: &Item<'_>) -> (Pat, Pat) {
|
|||
ItemKind::Struct(VariantData::Struct { .. }, _) => (Pat::Str("struct"), Pat::Str("}")),
|
||||
ItemKind::Struct(..) => (Pat::Str("struct"), Pat::Str(";")),
|
||||
ItemKind::Union(..) => (Pat::Str("union"), Pat::Str("}")),
|
||||
ItemKind::Trait(_, Unsafety::Unsafe, ..)
|
||||
ItemKind::Trait(_, Safety::Unsafe, ..)
|
||||
| ItemKind::Impl(Impl {
|
||||
unsafety: Unsafety::Unsafe,
|
||||
..
|
||||
safety: Safety::Unsafe, ..
|
||||
}) => (Pat::Str("unsafe"), Pat::Str("}")),
|
||||
ItemKind::Trait(IsAuto::Yes, ..) => (Pat::Str("auto"), Pat::Str("}")),
|
||||
ItemKind::Trait(..) => (Pat::Str("trait"), Pat::Str("}")),
|
||||
|
|
@ -323,7 +322,7 @@ fn ty_search_pat(ty: &Ty<'_>) -> (Pat, Pat) {
|
|||
TyKind::Ptr(MutTy { ty, .. }) => (Pat::Str("*"), ty_search_pat(ty).1),
|
||||
TyKind::Ref(_, MutTy { ty, .. }) => (Pat::Str("&"), ty_search_pat(ty).1),
|
||||
TyKind::BareFn(bare_fn) => (
|
||||
if bare_fn.unsafety == Unsafety::Unsafe {
|
||||
if bare_fn.safety == Safety::Unsafe {
|
||||
Pat::Str("unsafe")
|
||||
} else if bare_fn.abi != Abi::Rust {
|
||||
Pat::Str("extern")
|
||||
|
|
|
|||
|
|
@ -1082,7 +1082,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
|
|||
mut_ty.mutbl.hash(&mut self.s);
|
||||
},
|
||||
TyKind::BareFn(bfn) => {
|
||||
bfn.unsafety.hash(&mut self.s);
|
||||
bfn.safety.hash(&mut self.s);
|
||||
bfn.abi.hash(&mut self.s);
|
||||
for arg in bfn.decl.inputs {
|
||||
self.hash_ty(arg);
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
|||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::{Expr, FnDecl, LangItem, TyKind, Unsafety};
|
||||
use rustc_hir::{Expr, FnDecl, Safety, LangItem, TyKind};
|
||||
use rustc_infer::infer::TyCtxtInferExt;
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_middle::mir::interpret::Scalar;
|
||||
|
|
@ -18,7 +18,7 @@ use rustc_middle::traits::EvaluationResult;
|
|||
use rustc_middle::ty::layout::ValidityRequirement;
|
||||
use rustc_middle::ty::{
|
||||
self, AdtDef, AliasTy, AssocKind, Binder, BoundRegion, FnSig, GenericArg, GenericArgKind, GenericArgsRef,
|
||||
GenericParamDefKind, IntTy, ParamEnv, Region, RegionKind, ToPredicate, TraitRef, Ty, TyCtxt,
|
||||
GenericParamDefKind, IntTy, ParamEnv, Region, RegionKind, Upcast, TraitRef, Ty, TyCtxt,
|
||||
TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, UintTy, VariantDef, VariantDiscr,
|
||||
};
|
||||
use rustc_span::symbol::Ident;
|
||||
|
|
@ -311,7 +311,7 @@ pub fn implements_trait_with_env_from_iter<'tcx>(
|
|||
cause: ObligationCause::dummy(),
|
||||
param_env,
|
||||
recursion_depth: 0,
|
||||
predicate: Binder::dummy(trait_ref).to_predicate(tcx),
|
||||
predicate: trait_ref.upcast(tcx),
|
||||
};
|
||||
infcx
|
||||
.evaluate_obligation(&obligation)
|
||||
|
|
@ -562,7 +562,7 @@ pub fn peel_mid_ty_refs_is_mutable(ty: Ty<'_>) -> (Ty<'_>, usize, Mutability) {
|
|||
/// Returns `true` if the given type is an `unsafe` function.
|
||||
pub fn type_is_unsafe_function<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
|
||||
match ty.kind() {
|
||||
ty::FnDef(..) | ty::FnPtr(_) => ty.fn_sig(cx.tcx).unsafety() == Unsafety::Unsafe,
|
||||
ty::FnDef(..) | ty::FnPtr(_) => ty.fn_sig(cx.tcx).safety() == Safety::Unsafe,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use rustc_hir::def::{CtorKind, DefKind, Res};
|
|||
use rustc_hir::intravisit::{self, walk_block, walk_expr, Visitor};
|
||||
use rustc_hir::{
|
||||
AnonConst, Arm, Block, BlockCheckMode, Body, BodyId, Expr, ExprKind, HirId, ItemId, ItemKind, LetExpr, Pat, QPath,
|
||||
Stmt, UnOp, UnsafeSource, Unsafety,
|
||||
Safety, Stmt, UnOp, UnsafeSource,
|
||||
};
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_middle::hir::nested_filter;
|
||||
|
|
@ -421,16 +421,16 @@ pub fn is_expr_unsafe<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> bool {
|
|||
.typeck_results()
|
||||
.type_dependent_def_id(e.hir_id)
|
||||
.map_or(false, |id| {
|
||||
self.cx.tcx.fn_sig(id).skip_binder().unsafety() == Unsafety::Unsafe
|
||||
self.cx.tcx.fn_sig(id).skip_binder().safety() == Safety::Unsafe
|
||||
}) =>
|
||||
{
|
||||
self.is_unsafe = true;
|
||||
},
|
||||
ExprKind::Call(func, _) => match *self.cx.typeck_results().expr_ty(func).peel_refs().kind() {
|
||||
ty::FnDef(id, _) if self.cx.tcx.fn_sig(id).skip_binder().unsafety() == Unsafety::Unsafe => {
|
||||
ty::FnDef(id, _) if self.cx.tcx.fn_sig(id).skip_binder().safety() == Safety::Unsafe => {
|
||||
self.is_unsafe = true;
|
||||
},
|
||||
ty::FnPtr(sig) if sig.unsafety() == Unsafety::Unsafe => self.is_unsafe = true,
|
||||
ty::FnPtr(sig) if sig.safety() == Safety::Unsafe => self.is_unsafe = true,
|
||||
_ => walk_expr(self, e),
|
||||
},
|
||||
ExprKind::Path(ref p)
|
||||
|
|
@ -452,7 +452,7 @@ pub fn is_expr_unsafe<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> bool {
|
|||
}
|
||||
fn visit_nested_item(&mut self, id: ItemId) {
|
||||
if let ItemKind::Impl(i) = &self.cx.tcx.hir().item(id).kind {
|
||||
self.is_unsafe = i.unsafety == Unsafety::Unsafe;
|
||||
self.is_unsafe = i.safety == Safety::Unsafe;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,6 +64,12 @@ impl Rustc {
|
|||
self
|
||||
}
|
||||
|
||||
/// Specify a specific optimization level.
|
||||
pub fn opt_level(&mut self, option: &str) -> &mut Self {
|
||||
self.cmd.arg(format!("-Copt-level={option}"));
|
||||
self
|
||||
}
|
||||
|
||||
/// Specify type(s) of output files to generate.
|
||||
pub fn emit(&mut self, kinds: &str) -> &mut Self {
|
||||
self.cmd.arg(format!("--emit={kinds}"));
|
||||
|
|
|
|||
|
|
@ -247,7 +247,7 @@ fn allow_single_line_let_else_block(result: &str, block: &ast::Block) -> bool {
|
|||
#[allow(dead_code)]
|
||||
#[derive(Debug)]
|
||||
struct Item<'a> {
|
||||
unsafety: ast::Unsafe,
|
||||
safety: ast::Safety,
|
||||
abi: Cow<'static, str>,
|
||||
vis: Option<&'a ast::Visibility>,
|
||||
body: Vec<BodyElement<'a>>,
|
||||
|
|
@ -257,7 +257,7 @@ struct Item<'a> {
|
|||
impl<'a> Item<'a> {
|
||||
fn from_foreign_mod(fm: &'a ast::ForeignMod, span: Span, config: &Config) -> Item<'a> {
|
||||
Item {
|
||||
unsafety: fm.unsafety,
|
||||
safety: fm.safety,
|
||||
abi: format_extern(
|
||||
ast::Extern::from_abi(fm.abi, DUMMY_SP),
|
||||
config.force_explicit_abi(),
|
||||
|
|
@ -290,7 +290,7 @@ pub(crate) struct FnSig<'a> {
|
|||
coroutine_kind: Cow<'a, Option<ast::CoroutineKind>>,
|
||||
constness: ast::Const,
|
||||
defaultness: ast::Defaultness,
|
||||
unsafety: ast::Unsafe,
|
||||
safety: ast::Safety,
|
||||
visibility: &'a ast::Visibility,
|
||||
}
|
||||
|
||||
|
|
@ -301,7 +301,7 @@ impl<'a> FnSig<'a> {
|
|||
visibility: &'a ast::Visibility,
|
||||
) -> FnSig<'a> {
|
||||
FnSig {
|
||||
unsafety: method_sig.header.unsafety,
|
||||
safety: method_sig.header.safety,
|
||||
coroutine_kind: Cow::Borrowed(&method_sig.header.coroutine_kind),
|
||||
constness: method_sig.header.constness,
|
||||
defaultness: ast::Defaultness::Final,
|
||||
|
|
@ -330,7 +330,7 @@ impl<'a> FnSig<'a> {
|
|||
constness: fn_sig.header.constness,
|
||||
coroutine_kind: Cow::Borrowed(&fn_sig.header.coroutine_kind),
|
||||
defaultness,
|
||||
unsafety: fn_sig.header.unsafety,
|
||||
safety: fn_sig.header.safety,
|
||||
visibility: vis,
|
||||
},
|
||||
_ => unreachable!(),
|
||||
|
|
@ -345,7 +345,7 @@ impl<'a> FnSig<'a> {
|
|||
result.push_str(format_constness(self.constness));
|
||||
self.coroutine_kind
|
||||
.map(|coroutine_kind| result.push_str(format_coro(&coroutine_kind)));
|
||||
result.push_str(format_unsafety(self.unsafety));
|
||||
result.push_str(format_safety(self.safety));
|
||||
result.push_str(&format_extern(
|
||||
self.ext,
|
||||
context.config.force_explicit_abi(),
|
||||
|
|
@ -356,7 +356,7 @@ impl<'a> FnSig<'a> {
|
|||
|
||||
impl<'a> FmtVisitor<'a> {
|
||||
fn format_item(&mut self, item: &Item<'_>) {
|
||||
self.buffer.push_str(format_unsafety(item.unsafety));
|
||||
self.buffer.push_str(format_safety(item.safety));
|
||||
self.buffer.push_str(&item.abi);
|
||||
|
||||
let snippet = self.snippet(item.span);
|
||||
|
|
@ -924,7 +924,7 @@ fn format_impl_ref_and_type(
|
|||
offset: Indent,
|
||||
) -> Option<String> {
|
||||
let ast::Impl {
|
||||
unsafety,
|
||||
safety,
|
||||
polarity,
|
||||
defaultness,
|
||||
constness,
|
||||
|
|
@ -937,7 +937,7 @@ fn format_impl_ref_and_type(
|
|||
|
||||
result.push_str(&format_visibility(context, &item.vis));
|
||||
result.push_str(format_defaultness(defaultness));
|
||||
result.push_str(format_unsafety(unsafety));
|
||||
result.push_str(format_safety(safety));
|
||||
|
||||
let shape = if context.config.version() == Version::Two {
|
||||
Shape::indented(offset + last_line_width(&result), context.config)
|
||||
|
|
@ -1137,7 +1137,7 @@ pub(crate) fn format_trait(
|
|||
};
|
||||
let ast::Trait {
|
||||
is_auto,
|
||||
unsafety,
|
||||
safety,
|
||||
ref generics,
|
||||
ref bounds,
|
||||
ref items,
|
||||
|
|
@ -1147,7 +1147,7 @@ pub(crate) fn format_trait(
|
|||
let header = format!(
|
||||
"{}{}{}trait ",
|
||||
format_visibility(context, &item.vis),
|
||||
format_unsafety(unsafety),
|
||||
format_safety(safety),
|
||||
format_auto(is_auto),
|
||||
);
|
||||
result.push_str(&header);
|
||||
|
|
|
|||
|
|
@ -899,7 +899,7 @@ fn rewrite_bare_fn(
|
|||
result.push_str("> ");
|
||||
}
|
||||
|
||||
result.push_str(crate::utils::format_unsafety(bare_fn.unsafety));
|
||||
result.push_str(crate::utils::format_safety(bare_fn.safety));
|
||||
|
||||
result.push_str(&format_extern(
|
||||
bare_fn.ext,
|
||||
|
|
|
|||
|
|
@ -108,10 +108,10 @@ pub(crate) fn format_defaultness(defaultness: ast::Defaultness) -> &'static str
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn format_unsafety(unsafety: ast::Unsafe) -> &'static str {
|
||||
pub(crate) fn format_safety(unsafety: ast::Safety) -> &'static str {
|
||||
match unsafety {
|
||||
ast::Unsafe::Yes(..) => "unsafe ",
|
||||
ast::Unsafe::No => "",
|
||||
ast::Safety::Unsafe(..) => "unsafe ",
|
||||
ast::Safety::Default => "",
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ use crate::source_map::{LineRangeUtils, SpanUtils};
|
|||
use crate::spanned::Spanned;
|
||||
use crate::stmt::Stmt;
|
||||
use crate::utils::{
|
||||
self, contains_skip, count_newlines, depr_skip_annotation, format_unsafety, inner_attributes,
|
||||
self, contains_skip, count_newlines, depr_skip_annotation, format_safety, inner_attributes,
|
||||
last_line_width, mk_sp, ptr_vec_to_ref_vec, rewrite_ident, starts_with_newline, stmt_expr,
|
||||
};
|
||||
use crate::{ErrorKind, FormatReport, FormattingError};
|
||||
|
|
@ -517,9 +517,9 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
|
|||
self.visit_enum(item.ident, &item.vis, def, generics, item.span);
|
||||
self.last_pos = source!(self, item.span).hi();
|
||||
}
|
||||
ast::ItemKind::Mod(unsafety, ref mod_kind) => {
|
||||
ast::ItemKind::Mod(safety, ref mod_kind) => {
|
||||
self.format_missing_with_indent(source!(self, item.span).lo());
|
||||
self.format_mod(mod_kind, unsafety, &item.vis, item.span, item.ident, attrs);
|
||||
self.format_mod(mod_kind, safety, &item.vis, item.span, item.ident, attrs);
|
||||
}
|
||||
ast::ItemKind::MacCall(ref mac) => {
|
||||
self.visit_mac(mac, Some(item.ident), MacroPosition::Item);
|
||||
|
|
@ -913,7 +913,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
|
|||
fn format_mod(
|
||||
&mut self,
|
||||
mod_kind: &ast::ModKind,
|
||||
unsafety: ast::Unsafe,
|
||||
safety: ast::Safety,
|
||||
vis: &ast::Visibility,
|
||||
s: Span,
|
||||
ident: symbol::Ident,
|
||||
|
|
@ -921,7 +921,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
|
|||
) {
|
||||
let vis_str = utils::format_visibility(&self.get_context(), vis);
|
||||
self.push_str(&*vis_str);
|
||||
self.push_str(format_unsafety(unsafety));
|
||||
self.push_str(format_safety(safety));
|
||||
self.push_str("mod ");
|
||||
// Calling `to_owned()` to work around borrow checker.
|
||||
let ident_str = rewrite_ident(&self.get_context(), ident).to_owned();
|
||||
|
|
|
|||
|
|
@ -103,7 +103,6 @@ run-make/issue-25581/Makefile
|
|||
run-make/issue-26006/Makefile
|
||||
run-make/issue-26092/Makefile
|
||||
run-make/issue-28595/Makefile
|
||||
run-make/issue-28766/Makefile
|
||||
run-make/issue-30063/Makefile
|
||||
run-make/issue-33329/Makefile
|
||||
run-make/issue-35164/Makefile
|
||||
|
|
@ -128,7 +127,6 @@ run-make/issue-85401-static-mir/Makefile
|
|||
run-make/issue-85441/Makefile
|
||||
run-make/issue-88756-default-output/Makefile
|
||||
run-make/issue-97463-abi-param-passing/Makefile
|
||||
run-make/issue64319/Makefile
|
||||
run-make/jobserver-error/Makefile
|
||||
run-make/libs-through-symlinks/Makefile
|
||||
run-make/libtest-json/Makefile
|
||||
|
|
@ -236,10 +234,8 @@ run-make/rlib-format-packed-bundled-libs/Makefile
|
|||
run-make/rmeta-preferred/Makefile
|
||||
run-make/rustc-macro-dep-files/Makefile
|
||||
run-make/rustdoc-io-error/Makefile
|
||||
run-make/rustdoc-scrape-examples-invalid-expr/Makefile
|
||||
run-make/rustdoc-scrape-examples-macros/Makefile
|
||||
run-make/rustdoc-scrape-examples-multiple/Makefile
|
||||
run-make/rustdoc-scrape-examples-remap/Makefile
|
||||
run-make/rustdoc-scrape-examples-test/Makefile
|
||||
run-make/rustdoc-scrape-examples-whitespace/Makefile
|
||||
run-make/rustdoc-verify-output-files/Makefile
|
||||
|
|
@ -264,7 +260,6 @@ run-make/stable-symbol-names/Makefile
|
|||
run-make/static-dylib-by-default/Makefile
|
||||
run-make/static-extern-type/Makefile
|
||||
run-make/static-pie/Makefile
|
||||
run-make/static-unwinding/Makefile
|
||||
run-make/staticlib-blank-lib/Makefile
|
||||
run-make/staticlib-dylib-linkage/Makefile
|
||||
run-make/std-core-cycle/Makefile
|
||||
|
|
|
|||
|
|
@ -2915,7 +2915,6 @@ ui/macros/issue-95267.rs
|
|||
ui/macros/issue-95533.rs
|
||||
ui/macros/issue-98466-allow.rs
|
||||
ui/macros/issue-98466.rs
|
||||
ui/macros/issue-98790.rs
|
||||
ui/macros/issue-99261.rs
|
||||
ui/macros/issue-99265.rs
|
||||
ui/macros/issue-99907.rs
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ const EXTENSION_EXCEPTION_PATHS: &[&str] = &[
|
|||
"tests/ui/macros/not-utf8.bin", // testing including data with the include macros
|
||||
"tests/ui/macros/syntax-extension-source-utils-files/includeme.fragment", // more include
|
||||
"tests/ui/proc-macro/auxiliary/included-file.txt", // more include
|
||||
"tests/ui/unpretty/auxiliary/data.txt", // more include
|
||||
"tests/ui/invalid/foo.natvis.xml", // sample debugger visualizer
|
||||
"tests/ui/sanitizer/dataflow-abilist.txt", // dataflow sanitizer ABI list file
|
||||
"tests/ui/shell-argfiles/shell-argfiles.args", // passing args via a file
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue