Skip to content

Commit 5a40d36

Browse files
Rollup merge of #155562 - ChayimFriedman2:no-traits, r=nikomatsakis
Add a missing `GenericTypeVisitable`, and avoid having interner traits for `FnSigKind` and `Abi` r? types
2 parents cda4395 + dff9d08 commit 5a40d36

18 files changed

Lines changed: 104 additions & 150 deletions

File tree

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,8 +1085,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
10851085
}
10861086

10871087
// Build a new closure where the return type is an owned value, instead of a ref.
1088-
let fn_sig_kind =
1089-
FnSigKind::default().set_safe(true).set_c_variadic(liberated_sig.c_variadic());
1088+
let fn_sig_kind = FnSigKind::default()
1089+
.set_safety(hir::Safety::Safe)
1090+
.set_c_variadic(liberated_sig.c_variadic());
10901091
let closure_sig_as_fn_ptr_ty = Ty::new_fn_ptr(
10911092
tcx,
10921093
ty::Binder::dummy(tcx.mk_fn_sig(

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3590,7 +3590,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
35903590

35913591
let fn_sig_kind = FnSigKind::default()
35923592
.set_abi(abi)
3593-
.set_safe(safety.is_safe())
3593+
.set_safety(safety)
35943594
.set_c_variadic(decl.fn_decl_kind.c_variadic());
35953595
let fn_ty = tcx.mk_fn_sig(input_tys, output_ty, fn_sig_kind);
35963596
let fn_ptr_ty = ty::Binder::bind_with_vars(fn_ty, bound_vars);

compiler/rustc_hir_typeck/src/closure.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
723723
let bound_sig = expected_sig.sig.map_bound(|sig| {
724724
let fn_sig_kind = FnSigKind::default()
725725
.set_abi(ExternAbi::RustCall)
726-
.set_safe(true)
726+
.set_safety(hir::Safety::Safe)
727727
.set_c_variadic(sig.c_variadic());
728728
self.tcx.mk_fn_sig(sig.inputs().iter().cloned(), sig.output(), fn_sig_kind)
729729
});
@@ -860,7 +860,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
860860

861861
let fn_sig_kind = FnSigKind::default()
862862
.set_abi(ExternAbi::RustCall)
863-
.set_safe(true)
863+
.set_safety(hir::Safety::Safe)
864864
.set_c_variadic(expected_sigs.liberated_sig.c_variadic());
865865
expected_sigs.liberated_sig =
866866
self.tcx.mk_fn_sig(inputs, supplied_output_ty, fn_sig_kind);
@@ -935,7 +935,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
935935

936936
let fn_sig_kind = FnSigKind::default()
937937
.set_abi(ExternAbi::RustCall)
938-
.set_safe(true)
938+
.set_safety(hir::Safety::Safe)
939939
.set_c_variadic(decl.c_variadic());
940940
let result = ty::Binder::bind_with_vars(
941941
self.tcx.mk_fn_sig(supplied_arguments, supplied_return, fn_sig_kind),
@@ -1098,7 +1098,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10981098

10991099
let fn_sig_kind = FnSigKind::default()
11001100
.set_abi(ExternAbi::RustCall)
1101-
.set_safe(true)
1101+
.set_safety(hir::Safety::Safe)
11021102
.set_c_variadic(decl.c_variadic());
11031103
let result = ty::Binder::dummy(self.tcx.mk_fn_sig(supplied_arguments, err_ty, fn_sig_kind));
11041104

compiler/rustc_middle/src/ty/context.rs

Lines changed: 24 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use rustc_span::def_id::{CRATE_DEF_ID, DefPathHash, StableCrateId};
4646
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym};
4747
use rustc_type_ir::TyKind::*;
4848
pub use rustc_type_ir::lift::Lift;
49-
use rustc_type_ir::{CollectAndApply, FnSigKind, WithCachedTypeInfo, elaborate, search_graph};
49+
use rustc_type_ir::{CollectAndApply, WithCachedTypeInfo, elaborate, search_graph};
5050
use tracing::{debug, instrument};
5151

5252
use crate::arena::Arena;
@@ -66,11 +66,11 @@ use crate::traits;
6666
use crate::traits::solve::{ExternalConstraints, ExternalConstraintsData, PredefinedOpaques};
6767
use crate::ty::predicate::ExistentialPredicateStableCmpExt as _;
6868
use crate::ty::{
69-
self, AdtDef, AdtDefData, AdtKind, Binder, Clause, Clauses, Const, GenericArg, GenericArgs,
70-
GenericArgsRef, GenericParamDefKind, List, ListWithCachedTypeInfo, ParamConst, Pattern,
71-
PatternKind, PolyExistentialPredicate, PolyFnSig, Predicate, PredicateKind, PredicatePolarity,
72-
Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyVid, ValTree, ValTreeKind,
73-
Visibility,
69+
self, AdtDef, AdtDefData, AdtKind, Binder, Clause, Clauses, Const, FnSigKind, GenericArg,
70+
GenericArgs, GenericArgsRef, GenericParamDefKind, List, ListWithCachedTypeInfo, ParamConst,
71+
Pattern, PatternKind, PolyExistentialPredicate, PolyFnSig, Predicate, PredicateKind,
72+
PredicatePolarity, Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyVid,
73+
ValTree, ValTreeKind, Visibility,
7474
};
7575

7676
impl<'tcx> rustc_type_ir::inherent::DefId<TyCtxt<'tcx>> for DefId {
@@ -83,50 +83,6 @@ impl<'tcx> rustc_type_ir::inherent::DefId<TyCtxt<'tcx>> for DefId {
8383
}
8484
}
8585

86-
impl<'tcx> rustc_type_ir::inherent::FSigKind<TyCtxt<'tcx>> for FnSigKind {
87-
fn fn_sig_kind(self) -> Self {
88-
self
89-
}
90-
91-
fn new(abi: ExternAbi, safety: hir::Safety, c_variadic: bool) -> Self {
92-
FnSigKind::default().set_abi(abi).set_safe(safety.is_safe()).set_c_variadic(c_variadic)
93-
}
94-
95-
fn abi(self) -> ExternAbi {
96-
self.abi()
97-
}
98-
99-
fn safety(self) -> hir::Safety {
100-
if self.is_safe() { hir::Safety::Safe } else { hir::Safety::Unsafe }
101-
}
102-
103-
fn c_variadic(self) -> bool {
104-
self.c_variadic()
105-
}
106-
}
107-
108-
impl<'tcx> rustc_type_ir::inherent::Abi<TyCtxt<'tcx>> for ExternAbi {
109-
fn abi(self) -> Self {
110-
self
111-
}
112-
113-
fn rust() -> Self {
114-
ExternAbi::Rust
115-
}
116-
117-
fn is_rust(self) -> bool {
118-
matches!(self, ExternAbi::Rust)
119-
}
120-
121-
fn pack_abi(self) -> u8 {
122-
self.as_packed()
123-
}
124-
125-
fn unpack_abi(abi_index: u8) -> Self {
126-
Self::from_packed(abi_index)
127-
}
128-
}
129-
13086
impl<'tcx> rustc_type_ir::inherent::Safety<TyCtxt<'tcx>> for hir::Safety {
13187
fn safe() -> Self {
13288
hir::Safety::Safe
@@ -1335,7 +1291,7 @@ impl<'tcx> TyCtxt<'tcx> {
13351291
let caller_features = &self.body_codegen_attrs(caller).target_features;
13361292
if self.is_target_feature_call_safe(&fun_features, &caller_features) {
13371293
return Some(fun_sig.map_bound(|sig| ty::FnSig {
1338-
fn_sig_kind: fun_sig.fn_sig_kind().set_safe(true),
1294+
fn_sig_kind: fun_sig.fn_sig_kind().set_safety(hir::Safety::Safe),
13391295
..sig
13401296
}));
13411297
}
@@ -2104,7 +2060,10 @@ impl<'tcx> TyCtxt<'tcx> {
21042060
assert!(sig.safety().is_safe());
21052061
Ty::new_fn_ptr(
21062062
self,
2107-
sig.map_bound(|sig| ty::FnSig { fn_sig_kind: sig.fn_sig_kind.set_safe(false), ..sig }),
2063+
sig.map_bound(|sig| ty::FnSig {
2064+
fn_sig_kind: sig.fn_sig_kind.set_safety(hir::Safety::Unsafe),
2065+
..sig
2066+
}),
21082067
)
21092068
}
21102069

@@ -2113,7 +2072,10 @@ impl<'tcx> TyCtxt<'tcx> {
21132072
/// unsafe.
21142073
pub fn safe_to_unsafe_sig(self, sig: PolyFnSig<'tcx>) -> PolyFnSig<'tcx> {
21152074
assert!(sig.safety().is_safe());
2116-
sig.map_bound(|sig| ty::FnSig { fn_sig_kind: sig.fn_sig_kind.set_safe(false), ..sig })
2075+
sig.map_bound(|sig| ty::FnSig {
2076+
fn_sig_kind: sig.fn_sig_kind.set_safety(hir::Safety::Unsafe),
2077+
..sig
2078+
})
21172079
}
21182080

21192081
/// Given the def_id of a Trait `trait_def_id` and the name of an associated item `assoc_name`
@@ -2158,7 +2120,7 @@ impl<'tcx> TyCtxt<'tcx> {
21582120
self.mk_fn_sig(
21592121
params,
21602122
s.output(),
2161-
s.fn_sig_kind.set_safe(safety.is_safe()).set_abi(ExternAbi::Rust),
2123+
s.fn_sig_kind.set_safety(safety).set_abi(ExternAbi::Rust),
21622124
)
21632125
})
21642126
}
@@ -2417,7 +2379,12 @@ impl<'tcx> TyCtxt<'tcx> {
24172379
// IntoIterator` instead of `I: Iterator`, and it doesn't have a slice
24182380
// variant, because of the need to combine `inputs` and `output`. This
24192381
// explains the lack of `_from_iter` suffix.
2420-
pub fn mk_fn_sig<I, T>(self, inputs: I, output: I::Item, fn_sig_kind: FnSigKind) -> T::Output
2382+
pub fn mk_fn_sig<I, T>(
2383+
self,
2384+
inputs: I,
2385+
output: I::Item,
2386+
fn_sig_kind: FnSigKind<'tcx>,
2387+
) -> T::Output
24212388
where
24222389
I: IntoIterator<Item = T>,
24232390
T: CollectAndApply<Ty<'tcx>, ty::FnSig<'tcx>>,
@@ -2439,7 +2406,7 @@ impl<'tcx> TyCtxt<'tcx> {
24392406
I: IntoIterator<Item = T>,
24402407
T: CollectAndApply<Ty<'tcx>, ty::FnSig<'tcx>>,
24412408
{
2442-
self.mk_fn_sig(inputs, output, FnSigKind::default().set_safe(safety.is_safe()))
2409+
self.mk_fn_sig(inputs, output, FnSigKind::default().set_safety(safety))
24432410
}
24442411

24452412
/// `mk_fn_sig`, but with a safe Rust ABI, and no C-variadic argument.
@@ -2448,7 +2415,7 @@ impl<'tcx> TyCtxt<'tcx> {
24482415
I: IntoIterator<Item = T>,
24492416
T: CollectAndApply<Ty<'tcx>, ty::FnSig<'tcx>>,
24502417
{
2451-
self.mk_fn_sig(inputs, output, FnSigKind::default().set_safe(true))
2418+
self.mk_fn_sig(inputs, output, FnSigKind::default().set_safety(hir::Safety::Safe))
24522419
}
24532420

24542421
pub fn mk_poly_existential_predicates_from_iter<I, T>(self, iter: I) -> T::Output

compiler/rustc_middle/src/ty/context/impl_interner.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22
33
use std::{debug_assert_matches, fmt};
44

5-
use rustc_abi::ExternAbi;
65
use rustc_errors::ErrorGuaranteed;
76
use rustc_hir as hir;
87
use rustc_hir::def::{CtorKind, CtorOf, DefKind};
98
use rustc_hir::def_id::{DefId, LocalDefId};
109
use rustc_hir::lang_items::LangItem;
1110
use rustc_span::{DUMMY_SP, Span, Symbol};
1211
use rustc_type_ir::lang_items::{SolverAdtLangItem, SolverLangItem, SolverTraitLangItem};
13-
use rustc_type_ir::{
14-
CollectAndApply, FnSigKind, Interner, TypeFoldable, Unnormalized, search_graph,
15-
};
12+
use rustc_type_ir::{CollectAndApply, Interner, TypeFoldable, Unnormalized, search_graph};
1613

1714
use crate::dep_graph::{DepKind, DepNodeIndex};
1815
use crate::infer::canonical::CanonicalVarKinds;
@@ -92,9 +89,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
9289
type AllocId = crate::mir::interpret::AllocId;
9390
type Pat = Pattern<'tcx>;
9491
type PatList = &'tcx List<Pattern<'tcx>>;
95-
type FSigKind = FnSigKind;
9692
type Safety = hir::Safety;
97-
type Abi = ExternAbi;
9893
type Const = ty::Const<'tcx>;
9994
type Consts = &'tcx List<Self::Const>;
10095

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
751751
if self.tcx().codegen_fn_attrs(def_id).safe_target_features {
752752
write!(self, "#[target_features] ")?;
753753
sig = sig.map_bound(|mut sig| {
754-
sig.fn_sig_kind = sig.fn_sig_kind.set_safe(true);
754+
sig.fn_sig_kind = sig.fn_sig_kind.set_safety(hir::Safety::Safe);
755755
sig
756756
});
757757
}

compiler/rustc_middle/src/ty/structural_impls.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ TrivialLiftImpls! {
198198
rustc_hir::Safety,
199199
rustc_middle::mir::ConstValue,
200200
rustc_type_ir::BoundConstness,
201-
rustc_type_ir::FnSigKind,
202201
rustc_type_ir::PredicatePolarity,
203202
// tidy-alphabetical-end
204203
}

compiler/rustc_middle/src/ty/sty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub type TypeAndMut<'tcx> = ir::TypeAndMut<TyCtxt<'tcx>>;
3737
pub type AliasTy<'tcx> = ir::AliasTy<TyCtxt<'tcx>>;
3838
pub type AliasTyKind<'tcx> = ir::AliasTyKind<TyCtxt<'tcx>>;
3939
pub type FnSig<'tcx> = ir::FnSig<TyCtxt<'tcx>>;
40-
pub type FnSigKind = ir::FnSigKind;
40+
pub type FnSigKind<'tcx> = ir::FnSigKind<TyCtxt<'tcx>>;
4141
pub type Binder<'tcx, T> = ir::Binder<TyCtxt<'tcx>, T>;
4242
pub type EarlyBinder<'tcx, T> = ir::EarlyBinder<TyCtxt<'tcx>, T>;
4343
pub type Unnormalized<'tcx, T> = ir::Unnormalized<TyCtxt<'tcx>, T>;

compiler/rustc_public/src/unstable/convert/internal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ impl RustcInternal for FnSig {
314314
) -> Self::T<'tcx> {
315315
let fn_sig_kind = rustc_ty::FnSigKind::default()
316316
.set_abi(self.abi.internal(tables, tcx))
317-
.set_safe(self.safety == Safety::Safe)
317+
.set_safety(self.safety.internal(tables, tcx))
318318
.set_c_variadic(self.c_variadic);
319319
tcx.lift(rustc_ty::FnSig {
320320
inputs_and_output: tcx.mk_type_list(&self.inputs_and_output.internal(tables, tcx)),

compiler/rustc_public/src/unstable/convert/stable/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ where
257257

258258
// This internal type isn't publicly exposed, because it is an implementation detail.
259259
// But it's a public field of FnSig (which has a public mirror type), so allow conversions.
260-
impl<'tcx> Stable<'tcx> for ty::FnSigKind {
260+
impl<'tcx> Stable<'tcx> for ty::FnSigKind<'tcx> {
261261
type T = (bool /*c_variadic*/, crate::mir::Safety, crate::ty::Abi);
262262
fn stable<'cx>(
263263
&self,

0 commit comments

Comments
 (0)