Skip to content

Commit

Permalink
Rollup merge of #136706 - workingjubilee:finish-up-rustc-abi-updates,…
Browse files Browse the repository at this point in the history
… r=compiler-errors

compiler: mostly-finish `rustc_abi` updates

This almost-finishes all the updates in the compiler to use `rustc_abi` and removes some of the reexports of `rustc_abi` items in `rustc_target` that were previously available.

r? ```@compiler-errors```
  • Loading branch information
workingjubilee authored Feb 9, 2025
2 parents 477be94 + b18bb0a commit fba8952
Show file tree
Hide file tree
Showing 20 changed files with 43 additions and 41 deletions.
2 changes: 1 addition & 1 deletion clippy_lints/src/casts/cast_possible_truncation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use clippy_utils::expr_or_init;
use clippy_utils::source::snippet;
use clippy_utils::sugg::Sugg;
use clippy_utils::ty::{get_discriminant_value, is_isize_or_usize};
use rustc_abi::IntegerType;
use rustc_errors::{Applicability, Diag};
use rustc_hir::def::{DefKind, Res};
use rustc_hir::{BinOpKind, Expr, ExprKind};
use rustc_lint::LateContext;
use rustc_middle::ty::{self, FloatTy, Ty};
use rustc_span::Span;
use rustc_target::abi::IntegerType;

use super::{CAST_ENUM_TRUNCATION, CAST_POSSIBLE_TRUNCATION, utils};

Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rustc_session::impl_lint_pass;
use rustc_span::Span;
use rustc_span::def_id::LocalDefId;
use rustc_span::symbol::kw;
use rustc_target::spec::abi::Abi;
use rustc_abi::ExternAbi;

pub struct BoxedLocal {
too_large_for_stack: u64,
Expand Down Expand Up @@ -73,7 +73,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
fn_def_id: LocalDefId,
) {
if let Some(header) = fn_kind.header() {
if header.abi != Abi::Rust {
if header.abi != ExternAbi::Rust {
return;
}
}
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/eta_reduction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use rustc_middle::ty::{
};
use rustc_session::declare_lint_pass;
use rustc_span::symbol::sym;
use rustc_target::spec::abi::Abi;
use rustc_abi::ExternAbi;
use rustc_trait_selection::error_reporting::InferCtxtErrorExt as _;

declare_clippy_lint! {
Expand Down Expand Up @@ -172,7 +172,7 @@ fn check_closure<'tcx>(cx: &LateContext<'tcx>, outer_receiver: Option<&Expr<'tcx
&& let output = typeck.expr_ty(body.value)
&& let ty::Tuple(tys) = *subs.type_at(1).kind()
{
cx.tcx.mk_fn_sig(tys, output, false, Safety::Safe, Abi::Rust)
cx.tcx.mk_fn_sig(tys, output, false, Safety::Safe, ExternAbi::Rust)
} else {
return;
}
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/excessive_bools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rustc_lint::{LateContext, LateLintPass};
use rustc_session::impl_lint_pass;
use rustc_span::Span;
use rustc_span::def_id::LocalDefId;
use rustc_target::spec::abi::Abi;
use rustc_abi::ExternAbi;

declare_clippy_lint! {
/// ### What it does
Expand Down Expand Up @@ -145,7 +145,7 @@ impl<'tcx> LateLintPass<'tcx> for ExcessiveBools {
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, trait_item: &'tcx TraitItem<'tcx>) {
// functions with a body are already checked by `check_fn`
if let TraitItemKind::Fn(fn_sig, TraitFn::Required(_)) = &trait_item.kind
&& fn_sig.header.abi == Abi::Rust
&& fn_sig.header.abi == ExternAbi::Rust
&& fn_sig.decl.inputs.len() as u64 > self.max_fn_params_bools
{
check_fn_decl(cx, fn_sig.decl, fn_sig.span, self.max_fn_params_bools);
Expand All @@ -162,7 +162,7 @@ impl<'tcx> LateLintPass<'tcx> for ExcessiveBools {
def_id: LocalDefId,
) {
if let Some(fn_header) = fn_kind.header()
&& fn_header.abi == Abi::Rust
&& fn_header.abi == ExternAbi::Rust
&& fn_decl.inputs.len() as u64 > self.max_fn_params_bools
&& get_parent_as_impl(cx.tcx, cx.tcx.local_def_id_to_hir_id(def_id))
.is_none_or(|impl_item| impl_item.of_trait.is_none())
Expand Down
8 changes: 4 additions & 4 deletions clippy_lints/src/functions/too_many_arguments.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rustc_hir::{self as hir, intravisit};
use rustc_lint::LateContext;
use rustc_span::Span;
use rustc_target::spec::abi::Abi;
use rustc_abi::ExternAbi;

use clippy_utils::diagnostics::span_lint;
use clippy_utils::is_trait_impl_item;
Expand All @@ -23,11 +23,11 @@ pub(super) fn check_fn(
intravisit::FnKind::Method(
_,
&hir::FnSig {
header: hir::FnHeader { abi: Abi::Rust, .. },
header: hir::FnHeader { abi: ExternAbi::Rust, .. },
..
},
)
| intravisit::FnKind::ItemFn(_, _, hir::FnHeader { abi: Abi::Rust, .. }) => check_arg_number(
| intravisit::FnKind::ItemFn(_, _, hir::FnHeader { abi: ExternAbi::Rust, .. }) => check_arg_number(
cx,
decl,
span.with_hi(decl.output.span().hi()),
Expand All @@ -41,7 +41,7 @@ pub(super) fn check_fn(
pub(super) fn check_trait_item(cx: &LateContext<'_>, item: &hir::TraitItem<'_>, too_many_arguments_threshold: u64) {
if let hir::TraitItemKind::Fn(ref sig, _) = item.kind {
// don't lint extern functions decls, it's not their fault
if sig.header.abi == Abi::Rust {
if sig.header.abi == ExternAbi::Rust {
check_arg_number(
cx,
sig.decl,
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/inherent_to_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rustc_hir::{GenericParamKind, ImplItem, ImplItemKind, LangItem};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::declare_lint_pass;
use rustc_span::sym;
use rustc_target::spec::abi::Abi;
use rustc_abi::ExternAbi;

declare_clippy_lint! {
/// ### What it does
Expand Down Expand Up @@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for InherentToString {
// #11201
&& let header = signature.header
&& header.is_safe()
&& header.abi == Abi::Rust
&& header.abi == ExternAbi::Rust
&& impl_item.ident.name == sym::to_string
&& let decl = signature.decl
&& decl.implicit_self.has_implicit_self()
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/large_futures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use clippy_config::Conf;
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::snippet;
use clippy_utils::ty::implements_trait;
use rustc_abi::Size;
use rustc_errors::Applicability;
use rustc_hir::{Expr, ExprKind, LangItem, MatchSource, QPath};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::impl_lint_pass;
use rustc_target::abi::Size;

declare_clippy_lint! {
/// ### What it does
Expand Down
3 changes: 2 additions & 1 deletion clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ use clippy_utils::msrvs::{self, Msrv};
use clippy_utils::ty::{contains_ty_adt_constructor_opaque, implements_trait, is_copy, is_type_diagnostic_item};
use clippy_utils::{contains_return, is_bool, is_trait_method, iter_input_pats, peel_blocks, return_ty};
pub use path_ends_with_ext::DEFAULT_ALLOWED_DOTFILES;
use rustc_abi::ExternAbi;
use rustc_data_structures::fx::FxHashSet;
use rustc_hir as hir;
use rustc_hir::{Expr, ExprKind, Node, Stmt, StmtKind, TraitItem, TraitItemKind};
Expand Down Expand Up @@ -5447,7 +5448,7 @@ const FN_HEADER: hir::FnHeader = hir::FnHeader {
safety: hir::HeaderSafety::Normal(hir::Safety::Safe),
constness: hir::Constness::NotConst,
asyncness: hir::IsAsync::NotAsync,
abi: rustc_target::spec::abi::Abi::Rust,
abi: ExternAbi::Rust,
};

struct ShouldImplTraitCase {
Expand Down
9 changes: 5 additions & 4 deletions clippy_lints/src/missing_const_for_fn.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

use clippy_config::Conf;
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::msrvs::{self, Msrv};
Expand All @@ -12,7 +13,7 @@ use rustc_middle::ty;
use rustc_session::impl_lint_pass;
use rustc_span::Span;
use rustc_span::def_id::LocalDefId;
use rustc_target::spec::abi::Abi;
use rustc_abi::ExternAbi;

declare_clippy_lint! {
/// ### What it does
Expand Down Expand Up @@ -183,11 +184,11 @@ fn already_const(header: hir::FnHeader) -> bool {
header.constness == Constness::Const
}

fn could_be_const_with_abi(msrv: &Msrv, abi: Abi) -> bool {
fn could_be_const_with_abi(msrv: &Msrv, abi: ExternAbi) -> bool {
match abi {
Abi::Rust => true,
ExternAbi::Rust => true,
// `const extern "C"` was stabilized after 1.62.0
Abi::C { unwind: false } => msrv.meets(msrvs::CONST_EXTERN_C_FN),
ExternAbi::C { unwind: false } => msrv.meets(msrvs::CONST_EXTERN_C_FN),
// Rest ABIs are still unstable and need the `const_extern_fn` feature enabled.
_ => msrv.meets(msrvs::CONST_EXTERN_FN),
}
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/needless_pass_by_ref_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use rustc_session::impl_lint_pass;
use rustc_span::Span;
use rustc_span::def_id::LocalDefId;
use rustc_span::symbol::kw;
use rustc_target::spec::abi::Abi;
use rustc_abi::ExternAbi;

declare_clippy_lint! {
/// ### What it does
Expand Down Expand Up @@ -149,7 +149,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> {
return;
}
let attrs = cx.tcx.hir().attrs(hir_id);
if header.abi != Abi::Rust || requires_exact_signature(attrs) {
if header.abi != ExternAbi::Rust || requires_exact_signature(attrs) {
return;
}
header.is_async()
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/needless_pass_by_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use rustc_session::declare_lint_pass;
use rustc_span::def_id::LocalDefId;
use rustc_span::symbol::kw;
use rustc_span::{Span, sym};
use rustc_target::spec::abi::Abi;
use rustc_abi::ExternAbi;
use rustc_trait_selection::traits;
use rustc_trait_selection::traits::misc::type_allowed_to_implement_copy;

Expand Down Expand Up @@ -89,7 +89,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
match kind {
FnKind::ItemFn(.., header) => {
let attrs = cx.tcx.hir().attrs(hir_id);
if header.abi != Abi::Rust || requires_exact_signature(attrs) {
if header.abi != ExternAbi::Rust || requires_exact_signature(attrs) {
return;
}
},
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/no_mangle_with_rust_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rustc_hir::{Item, ItemKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::declare_lint_pass;
use rustc_span::{BytePos, Pos};
use rustc_target::spec::abi::Abi;
use rustc_abi::ExternAbi;

declare_clippy_lint! {
/// ### What it does
Expand Down Expand Up @@ -46,7 +46,7 @@ impl<'tcx> LateLintPass<'tcx> for NoMangleWithRustAbi {
for attr in attrs {
if let Some(ident) = attr.ident()
&& ident.name == rustc_span::sym::no_mangle
&& fn_sig.header.abi == Abi::Rust
&& fn_sig.header.abi == ExternAbi::Rust
&& let Some((fn_attrs, _)) = fn_snippet.rsplit_once("fn")
&& !fn_attrs.contains("extern")
{
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/non_copy_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::is_in_const_context;
use clippy_utils::macros::macro_backtrace;
use clippy_utils::ty::{InteriorMut, implements_trait};
use rustc_abi::VariantIdx;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::DefId;
use rustc_hir::{
Expand All @@ -16,7 +17,6 @@ use rustc_middle::ty::adjustment::Adjust;
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_session::impl_lint_pass;
use rustc_span::{DUMMY_SP, Span, sym};
use rustc_target::abi::VariantIdx;

// FIXME: this is a correctness problem but there's no suitable
// warn-by-default category.
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/pass_by_ref_or_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use rustc_middle::ty::{self, RegionKind, TyCtxt};
use rustc_session::impl_lint_pass;
use rustc_span::def_id::LocalDefId;
use rustc_span::{Span, sym};
use rustc_target::spec::abi::Abi;
use rustc_abi::ExternAbi;

declare_clippy_lint! {
/// ### What it does
Expand Down Expand Up @@ -277,7 +277,7 @@ impl<'tcx> LateLintPass<'tcx> for PassByRefOrValue {
let hir_id = cx.tcx.local_def_id_to_hir_id(def_id);
match kind {
FnKind::ItemFn(.., header) => {
if header.abi != Abi::Rust {
if header.abi != ExternAbi::Rust {
return;
}
let attrs = cx.tcx.hir().attrs(hir_id);
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use rustc_middle::ty::{self, Binder, ClauseKind, ExistentialPredicate, List, Pre
use rustc_session::declare_lint_pass;
use rustc_span::symbol::Symbol;
use rustc_span::{Span, sym};
use rustc_target::spec::abi::Abi;
use rustc_abi::ExternAbi;
use rustc_trait_selection::infer::InferCtxtExt as _;
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _;
use std::{fmt, iter};
Expand Down Expand Up @@ -160,7 +160,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {

check_mut_from_ref(cx, sig, None);

if !matches!(sig.header.abi, Abi::Rust) {
if !matches!(sig.header.abi, ExternAbi::Rust) {
// Ignore `extern` functions with non-Rust calling conventions
return;
}
Expand Down Expand Up @@ -220,7 +220,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {

check_mut_from_ref(cx, sig, Some(body));

if !matches!(sig.header.abi, Abi::Rust) {
if !matches!(sig.header.abi, ExternAbi::Rust) {
// Ignore `extern` functions with non-Rust calling conventions
return;
}
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/types/type_complexity.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use clippy_utils::diagnostics::span_lint;
use rustc_abi::ExternAbi;
use rustc_hir::intravisit::{InferKind, Visitor, VisitorExt, walk_ty};
use rustc_hir::{self as hir, AmbigArg, GenericParamKind, TyKind};
use rustc_lint::LateContext;
use rustc_span::Span;
use rustc_target::spec::abi::Abi;

use super::TYPE_COMPLEXITY;

Expand Down Expand Up @@ -50,7 +50,7 @@ impl<'tcx> Visitor<'tcx> for TypeComplexityVisitor {
TyKind::Path(..) | TyKind::Slice(..) | TyKind::Tup(..) | TyKind::Array(..) => (10 * self.nest, 1),

// function types bring a lot of overhead
TyKind::BareFn(bare) if bare.abi == Abi::Rust => (50 * self.nest, 1),
TyKind::BareFn(bare) if bare.abi == ExternAbi::Rust => (50 * self.nest, 1),

TyKind::TraitObject(param_bounds, _) => {
let has_lifetime_parameters = param_bounds.iter().any(|bound| {
Expand Down
6 changes: 3 additions & 3 deletions clippy_utils/src/check_proc_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
//! code was written, and check if the span contains that text. Note this will only work correctly
//! if the span is not from a `macro_rules` based macro.
use rustc_abi::ExternAbi;
use rustc_ast::AttrStyle;
use rustc_ast::ast::{AttrKind, Attribute, IntTy, LitIntType, LitKind, StrStyle, TraitObjectSyntax, UintTy};
use rustc_ast::token::CommentKind;
Expand All @@ -26,7 +27,6 @@ use rustc_middle::ty::TyCtxt;
use rustc_session::Session;
use rustc_span::symbol::{Ident, kw};
use rustc_span::{Span, Symbol};
use rustc_target::spec::abi::Abi;

/// The search pattern to look for. Used by `span_matches_pat`
#[derive(Clone)]
Expand Down Expand Up @@ -233,7 +233,7 @@ fn fn_header_search_pat(header: FnHeader) -> Pat {
Pat::Str("const")
} else if header.is_unsafe() {
Pat::Str("unsafe")
} else if header.abi != Abi::Rust {
} else if header.abi != ExternAbi::Rust {
Pat::Str("extern")
} else {
Pat::MultiStr(&["fn", "extern"])
Expand Down Expand Up @@ -375,7 +375,7 @@ fn ty_search_pat(ty: &Ty<'_>) -> (Pat, Pat) {
TyKind::BareFn(bare_fn) => (
if bare_fn.safety.is_unsafe() {
Pat::Str("unsafe")
} else if bare_fn.abi != Abi::Rust {
} else if bare_fn.abi != ExternAbi::Rust {
Pat::Str("extern")
} else {
Pat::MultiStr(&["fn", "extern"])
Expand Down
2 changes: 1 addition & 1 deletion clippy_utils/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::sync::Arc;
use crate::source::{SpanRangeExt, walk_span_to_context};
use crate::{clip, is_direct_expn_of, sext, unsext};

use rustc_abi::Size;
use rustc_apfloat::Float;
use rustc_apfloat::ieee::{Half, Quad};
use rustc_ast::ast::{self, LitFloatType, LitKind};
Expand All @@ -25,7 +26,6 @@ use rustc_middle::{bug, mir, span_bug};
use rustc_span::def_id::DefId;
use rustc_span::symbol::Ident;
use rustc_span::{SyntaxContext, sym};
use rustc_target::abi::Size;
use std::cell::Cell;
use std::cmp::Ordering;
use std::hash::{Hash, Hasher};
Expand Down
4 changes: 2 additions & 2 deletions clippy_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

// FIXME: switch to something more ergonomic here, once available.
// (Currently there is no way to opt into sysroot crates without `extern crate`.)
extern crate rustc_abi;
extern crate rustc_ast;
extern crate rustc_ast_pretty;
extern crate rustc_attr_parsing;
Expand All @@ -48,7 +49,6 @@ extern crate rustc_middle;
extern crate rustc_mir_dataflow;
extern crate rustc_session;
extern crate rustc_span;
extern crate rustc_target;
extern crate rustc_trait_selection;
extern crate smallvec;

Expand Down Expand Up @@ -123,7 +123,7 @@ use rustc_span::hygiene::{ExpnKind, MacroKind};
use rustc_span::source_map::SourceMap;
use rustc_span::symbol::{Ident, Symbol, kw};
use rustc_span::{InnerSpan, Span, sym};
use rustc_target::abi::Integer;
use rustc_abi::Integer;
use visitors::{Visitable, for_each_unconsumed_temporary};

use crate::consts::{ConstEvalCtxt, Constant, mir_to_const};
Expand Down
Loading

0 comments on commit fba8952

Please sign in to comment.