Skip to content

Commit bdc083a

Browse files
compiler: Directly use rustc_abi in hir_{analysis,typeck}
1 parent c055207 commit bdc083a

File tree

19 files changed

+58
-56
lines changed

19 files changed

+58
-56
lines changed

compiler/rustc_hir_analysis/src/check/check.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use super::compare_impl_item::{check_type_bounds, compare_impl_method, compare_i
3737
use super::*;
3838
use crate::check::intrinsicck::InlineAsmCtxt;
3939

40-
pub fn check_abi(tcx: TyCtxt<'_>, span: Span, abi: Abi) {
40+
pub fn check_abi(tcx: TyCtxt<'_>, span: Span, abi: ExternAbi) {
4141
if !tcx.sess.target.is_abi_supported(abi) {
4242
struct_span_code_err!(
4343
tcx.dcx(),
@@ -49,7 +49,7 @@ pub fn check_abi(tcx: TyCtxt<'_>, span: Span, abi: Abi) {
4949
}
5050
}
5151

52-
pub fn check_abi_fn_ptr(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: Abi) {
52+
pub fn check_abi_fn_ptr(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: ExternAbi) {
5353
if !tcx.sess.target.is_abi_supported(abi) {
5454
tcx.node_span_lint(UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS, hir_id, span, |lint| {
5555
lint.primary_message(format!(
@@ -628,7 +628,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
628628
def_id,
629629
tcx.def_ident_span(def_id).unwrap(),
630630
i.name,
631-
Abi::Rust,
631+
ExternAbi::Rust,
632632
)
633633
}
634634
// Everything else is checked entirely within check_item_body
@@ -699,7 +699,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
699699
check_abi(tcx, it.span, abi);
700700

701701
match abi {
702-
Abi::RustIntrinsic => {
702+
ExternAbi::RustIntrinsic => {
703703
for item in items {
704704
intrinsic::check_intrinsic_type(
705705
tcx,

compiler/rustc_hir_analysis/src/check/entry.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::ops::Not;
22

3+
use rustc_abi::ExternAbi;
34
use rustc_hir as hir;
45
use rustc_hir::Node;
56
use rustc_infer::infer::TyCtxtInferExt;
@@ -9,7 +10,6 @@ use rustc_session::config::EntryFnType;
910
use rustc_span::Span;
1011
use rustc_span::def_id::{CRATE_DEF_ID, DefId, LocalDefId};
1112
use rustc_span::symbol::sym;
12-
use rustc_target::spec::abi::Abi;
1313
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
1414
use rustc_trait_selection::traits::{self, ObligationCause, ObligationCauseCode};
1515

@@ -158,7 +158,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
158158
expected_return_type,
159159
false,
160160
hir::Safety::Safe,
161-
Abi::Rust,
161+
ExternAbi::Rust,
162162
));
163163

164164
if check_function_signature(
@@ -254,7 +254,7 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: DefId) {
254254
tcx.types.isize,
255255
false,
256256
hir::Safety::Safe,
257-
Abi::Rust,
257+
ExternAbi::Rust,
258258
));
259259

260260
let _ = check_function_signature(

compiler/rustc_hir_analysis/src/check/intrinsic.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Type-checking for the rust-intrinsic and platform-intrinsic
22
//! intrinsics that the compiler exposes.
33
4+
use rustc_abi::ExternAbi;
45
use rustc_errors::codes::*;
56
use rustc_errors::{DiagMessage, struct_span_code_err};
67
use rustc_hir as hir;
@@ -10,7 +11,6 @@ use rustc_middle::ty::{self, Ty, TyCtxt};
1011
use rustc_span::def_id::LocalDefId;
1112
use rustc_span::symbol::sym;
1213
use rustc_span::{Span, Symbol};
13-
use rustc_target::spec::abi::Abi;
1414

1515
use crate::check::check_function_signature;
1616
use crate::errors::{
@@ -163,7 +163,7 @@ pub fn check_intrinsic_type(
163163
intrinsic_id: LocalDefId,
164164
span: Span,
165165
intrinsic_name: Symbol,
166-
abi: Abi,
166+
abi: ExternAbi,
167167
) {
168168
let generics = tcx.generics_of(intrinsic_id);
169169
let param = |n| {
@@ -533,14 +533,14 @@ pub fn check_intrinsic_type(
533533
tcx.types.unit,
534534
false,
535535
hir::Safety::Safe,
536-
Abi::Rust,
536+
ExternAbi::Rust,
537537
));
538538
let catch_fn_ty = ty::Binder::dummy(tcx.mk_fn_sig(
539539
[mut_u8, mut_u8],
540540
tcx.types.unit,
541541
false,
542542
hir::Safety::Safe,
543-
Abi::Rust,
543+
ExternAbi::Rust,
544544
));
545545
(
546546
0,

compiler/rustc_hir_analysis/src/check/mod.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub mod wfcheck;
7474
use std::num::NonZero;
7575

7676
pub use check::{check_abi, check_abi_fn_ptr};
77-
use rustc_abi::VariantIdx;
77+
use rustc_abi::{ExternAbi, VariantIdx};
7878
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
7979
use rustc_errors::{Diag, ErrorGuaranteed, pluralize, struct_span_code_err};
8080
use rustc_hir::def_id::{DefId, LocalDefId};
@@ -91,7 +91,6 @@ use rustc_session::parse::feature_err;
9191
use rustc_span::def_id::CRATE_DEF_ID;
9292
use rustc_span::symbol::{Ident, kw, sym};
9393
use rustc_span::{BytePos, DUMMY_SP, Span, Symbol};
94-
use rustc_target::spec::abi::Abi;
9594
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
9695
use rustc_trait_selection::error_reporting::infer::ObligationCauseExt as _;
9796
use rustc_trait_selection::error_reporting::traits::suggestions::ReturnsVisitor;
@@ -142,8 +141,8 @@ fn get_owner_return_paths(
142141
/// Forbid defining intrinsics in Rust code,
143142
/// as they must always be defined by the compiler.
144143
// FIXME: Move this to a more appropriate place.
145-
pub fn forbid_intrinsic_abi(tcx: TyCtxt<'_>, sp: Span, abi: Abi) {
146-
if let Abi::RustIntrinsic = abi {
144+
pub fn forbid_intrinsic_abi(tcx: TyCtxt<'_>, sp: Span, abi: ExternAbi) {
145+
if let ExternAbi::RustIntrinsic = abi {
147146
tcx.dcx().span_err(sp, "intrinsic must be in `extern \"rust-intrinsic\" { ... }` block");
148147
}
149148
}

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::cell::LazyCell;
22
use std::ops::{ControlFlow, Deref};
33

44
use hir::intravisit::{self, Visitor};
5+
use rustc_abi::ExternAbi;
56
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
67
use rustc_errors::codes::*;
78
use rustc_errors::{Applicability, ErrorGuaranteed, pluralize, struct_span_code_err};
@@ -23,7 +24,6 @@ use rustc_middle::{bug, span_bug};
2324
use rustc_session::parse::feature_err;
2425
use rustc_span::symbol::{Ident, sym};
2526
use rustc_span::{DUMMY_SP, Span};
26-
use rustc_target::spec::abi::Abi;
2727
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
2828
use rustc_trait_selection::regions::InferCtxtRegionExt;
2929
use rustc_trait_selection::traits::misc::{
@@ -1644,7 +1644,7 @@ fn check_fn_or_method<'tcx>(
16441644

16451645
check_where_clauses(wfcx, span, def_id);
16461646

1647-
if sig.abi == Abi::RustCall {
1647+
if sig.abi == ExternAbi::RustCall {
16481648
let span = tcx.def_span(def_id);
16491649
let has_implicit_self = hir_decl.implicit_self != hir::ImplicitSelfKind::None;
16501650
let mut inputs = sig.inputs().iter().skip(if has_implicit_self { 1 } else { 0 });

compiler/rustc_hir_analysis/src/collect.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use std::cell::Cell;
1818
use std::iter;
1919
use std::ops::Bound;
2020

21+
use rustc_abi::ExternAbi;
2122
use rustc_ast::Recovered;
2223
use rustc_data_structures::captures::Captures;
2324
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
@@ -38,7 +39,6 @@ use rustc_middle::ty::{self, AdtKind, Const, IsSuggestable, Ty, TyCtxt, TypingMo
3839
use rustc_middle::{bug, span_bug};
3940
use rustc_span::symbol::{Ident, Symbol, kw, sym};
4041
use rustc_span::{DUMMY_SP, Span};
41-
use rustc_target::spec::abi;
4242
use rustc_trait_selection::error_reporting::traits::suggestions::NextTypeParamName;
4343
use rustc_trait_selection::infer::InferCtxtExt;
4444
use rustc_trait_selection::traits::ObligationCtxt;
@@ -1361,7 +1361,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_, ty::PolyFn
13611361
(Bound::Unbounded, Bound::Unbounded) => hir::Safety::Safe,
13621362
_ => hir::Safety::Unsafe,
13631363
};
1364-
ty::Binder::dummy(tcx.mk_fn_sig(inputs, ty, false, safety, abi::Abi::Rust))
1364+
ty::Binder::dummy(tcx.mk_fn_sig(inputs, ty, false, safety, ExternAbi::Rust))
13651365
}
13661366

13671367
Expr(&hir::Expr { kind: hir::ExprKind::Closure { .. }, .. }) => {
@@ -1686,10 +1686,10 @@ fn compute_sig_of_foreign_fn_decl<'tcx>(
16861686
tcx: TyCtxt<'tcx>,
16871687
def_id: LocalDefId,
16881688
decl: &'tcx hir::FnDecl<'tcx>,
1689-
abi: abi::Abi,
1689+
abi: ExternAbi,
16901690
safety: hir::Safety,
16911691
) -> ty::PolyFnSig<'tcx> {
1692-
let safety = if abi == abi::Abi::RustIntrinsic {
1692+
let safety = if abi == ExternAbi::RustIntrinsic {
16931693
intrinsic_operation_unsafety(tcx, def_id)
16941694
} else {
16951695
safety
@@ -1700,7 +1700,7 @@ fn compute_sig_of_foreign_fn_decl<'tcx>(
17001700

17011701
// Feature gate SIMD types in FFI, since I am not sure that the
17021702
// ABIs are handled at all correctly. -huonw
1703-
if abi != abi::Abi::RustIntrinsic && !tcx.features().simd_ffi() {
1703+
if abi != ExternAbi::RustIntrinsic && !tcx.features().simd_ffi() {
17041704
let check = |hir_ty: &hir::Ty<'_>, ty: Ty<'_>| {
17051705
if ty.is_simd() {
17061706
let snip = tcx

compiler/rustc_hir_analysis/src/hir_ty_lowering/cmse.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
use rustc_abi::ExternAbi;
12
use rustc_errors::{DiagCtxtHandle, E0781, struct_span_code_err};
23
use rustc_hir::{self as hir, HirId};
34
use rustc_middle::bug;
45
use rustc_middle::ty::layout::LayoutError;
56
use rustc_middle::ty::{self, ParamEnv, TyCtxt};
6-
use rustc_target::spec::abi;
77

88
use crate::errors;
99

@@ -14,13 +14,13 @@ pub(crate) fn validate_cmse_abi<'tcx>(
1414
tcx: TyCtxt<'tcx>,
1515
dcx: DiagCtxtHandle<'_>,
1616
hir_id: HirId,
17-
abi: abi::Abi,
17+
abi: ExternAbi,
1818
fn_sig: ty::PolyFnSig<'tcx>,
1919
) {
2020
let abi_name = abi.name();
2121

2222
match abi {
23-
abi::Abi::CCmseNonSecureCall => {
23+
ExternAbi::CCmseNonSecureCall => {
2424
let hir_node = tcx.hir_node(hir_id);
2525
let hir::Node::Ty(hir::Ty {
2626
span: bare_fn_span,
@@ -78,7 +78,7 @@ pub(crate) fn validate_cmse_abi<'tcx>(
7878
}
7979
};
8080
}
81-
abi::Abi::CCmseNonSecureEntry => {
81+
ExternAbi::CCmseNonSecureEntry => {
8282
let hir_node = tcx.hir_node(hir_id);
8383
let Some(hir::FnSig { decl, span: fn_sig_span, .. }) = hir_node.fn_sig() else {
8484
// might happen when this ABI is used incorrectly. That will be handled elsewhere
@@ -195,17 +195,17 @@ fn is_valid_cmse_output<'tcx>(
195195
Ok(ret_ty == tcx.types.i64 || ret_ty == tcx.types.u64 || ret_ty == tcx.types.f64)
196196
}
197197

198-
fn should_emit_generic_error<'tcx>(abi: abi::Abi, layout_err: &'tcx LayoutError<'tcx>) -> bool {
198+
fn should_emit_generic_error<'tcx>(abi: ExternAbi, layout_err: &'tcx LayoutError<'tcx>) -> bool {
199199
use LayoutError::*;
200200

201201
match layout_err {
202202
Unknown(ty) => {
203203
match abi {
204-
abi::Abi::CCmseNonSecureCall => {
204+
ExternAbi::CCmseNonSecureCall => {
205205
// prevent double reporting of this error
206206
!ty.is_impl_trait()
207207
}
208-
abi::Abi::CCmseNonSecureEntry => true,
208+
ExternAbi::CCmseNonSecureEntry => true,
209209
_ => bug!("invalid ABI: {abi}"),
210210
}
211211
}

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ use rustc_session::lint::builtin::AMBIGUOUS_ASSOCIATED_ITEMS;
4747
use rustc_span::edit_distance::find_best_match_for_name;
4848
use rustc_span::symbol::{Ident, Symbol, kw};
4949
use rustc_span::{DUMMY_SP, Span};
50-
use rustc_target::spec::abi;
5150
use rustc_trait_selection::infer::InferCtxtExt;
5251
use rustc_trait_selection::traits::wf::object_region_bounds;
5352
use rustc_trait_selection::traits::{self, ObligationCtxt};
@@ -2353,7 +2352,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
23532352
&self,
23542353
hir_id: HirId,
23552354
safety: hir::Safety,
2356-
abi: abi::Abi,
2355+
abi: rustc_abi::ExternAbi,
23572356
decl: &hir::FnDecl<'tcx>,
23582357
generics: Option<&hir::Generics<'_>>,
23592358
hir_ty: Option<&hir::Ty<'_>>,

compiler/rustc_hir_analysis/src/lib.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ mod impl_wf_check;
9191
mod outlives;
9292
mod variance;
9393

94+
use rustc_abi::ExternAbi;
9495
use rustc_hir as hir;
9596
use rustc_hir::def::DefKind;
9697
use rustc_middle::middle;
@@ -100,19 +101,23 @@ use rustc_middle::ty::{self, Ty, TyCtxt};
100101
use rustc_session::parse::feature_err;
101102
use rustc_span::Span;
102103
use rustc_span::symbol::sym;
103-
use rustc_target::spec::abi::Abi;
104104
use rustc_trait_selection::traits;
105105

106106
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
107107

108-
fn require_c_abi_if_c_variadic(tcx: TyCtxt<'_>, decl: &hir::FnDecl<'_>, abi: Abi, span: Span) {
108+
fn require_c_abi_if_c_variadic(
109+
tcx: TyCtxt<'_>,
110+
decl: &hir::FnDecl<'_>,
111+
abi: ExternAbi,
112+
span: Span,
113+
) {
109114
const CONVENTIONS_UNSTABLE: &str =
110115
"`C`, `cdecl`, `system`, `aapcs`, `win64`, `sysv64` or `efiapi`";
111116
const CONVENTIONS_STABLE: &str = "`C` or `cdecl`";
112117
const UNSTABLE_EXPLAIN: &str =
113118
"using calling conventions other than `C` or `cdecl` for varargs functions is unstable";
114119

115-
if !decl.c_variadic || matches!(abi, Abi::C { .. } | Abi::Cdecl { .. }) {
120+
if !decl.c_variadic || matches!(abi, ExternAbi::C { .. } | ExternAbi::Cdecl { .. }) {
116121
return;
117122
}
118123

compiler/rustc_hir_typeck/src/callee.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use rustc_middle::{bug, span_bug};
1616
use rustc_span::Span;
1717
use rustc_span::def_id::LocalDefId;
1818
use rustc_span::symbol::{Ident, sym};
19-
use rustc_target::spec::abi;
2019
use rustc_trait_selection::error_reporting::traits::DefIdOrName;
2120
use rustc_trait_selection::infer::InferCtxtExt as _;
2221
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _;
@@ -509,7 +508,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
509508
def_id,
510509
);
511510

512-
if fn_sig.abi == abi::Abi::RustCall {
511+
if fn_sig.abi == rustc_abi::ExternAbi::RustCall {
513512
let sp = arg_exprs.last().map_or(call_expr.span, |expr| expr.span);
514513
if let Some(ty) = fn_sig.inputs().last().copied() {
515514
self.register_bound(

compiler/rustc_hir_typeck/src/check.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::cell::RefCell;
22

3+
use rustc_abi::ExternAbi;
34
use rustc_hir as hir;
45
use rustc_hir::def::DefKind;
56
use rustc_hir::intravisit::Visitor;
@@ -10,7 +11,6 @@ use rustc_infer::traits::WellFormedLoc;
1011
use rustc_middle::ty::{self, Binder, Ty, TyCtxt};
1112
use rustc_span::def_id::LocalDefId;
1213
use rustc_span::symbol::sym;
13-
use rustc_target::spec::abi::Abi;
1414
use rustc_trait_selection::traits::{ObligationCause, ObligationCauseCode};
1515
use tracing::{debug, instrument};
1616

@@ -211,7 +211,7 @@ fn check_panic_info_fn(tcx: TyCtxt<'_>, fn_id: LocalDefId, fn_sig: ty::FnSig<'_>
211211
ty::BoundVariableKind::Region(ty::BrAnon),
212212
]);
213213
let expected_sig = ty::Binder::bind_with_vars(
214-
tcx.mk_fn_sig([panic_info_ref_ty], tcx.types.never, false, fn_sig.safety, Abi::Rust),
214+
tcx.mk_fn_sig([panic_info_ref_ty], tcx.types.never, false, fn_sig.safety, ExternAbi::Rust),
215215
bounds,
216216
);
217217

@@ -234,7 +234,7 @@ fn check_lang_start_fn<'tcx>(tcx: TyCtxt<'tcx>, fn_sig: ty::FnSig<'tcx>, def_id:
234234
let generic_ty = Ty::new_param(tcx, fn_generic.index, fn_generic.name);
235235
let main_fn_ty = Ty::new_fn_ptr(
236236
tcx,
237-
Binder::dummy(tcx.mk_fn_sig([], generic_ty, false, hir::Safety::Safe, Abi::Rust)),
237+
Binder::dummy(tcx.mk_fn_sig([], generic_ty, false, hir::Safety::Safe, ExternAbi::Rust)),
238238
);
239239

240240
let expected_sig = ty::Binder::dummy(tcx.mk_fn_sig(
@@ -247,7 +247,7 @@ fn check_lang_start_fn<'tcx>(tcx: TyCtxt<'tcx>, fn_sig: ty::FnSig<'tcx>, def_id:
247247
tcx.types.isize,
248248
false,
249249
fn_sig.safety,
250-
Abi::Rust,
250+
ExternAbi::Rust,
251251
));
252252

253253
let _ = check_function_signature(

0 commit comments

Comments
 (0)