Skip to content

Commit 28ce588

Browse files
Uplift binder
1 parent e8fbd99 commit 28ce588

File tree

23 files changed

+703
-667
lines changed

23 files changed

+703
-667
lines changed

compiler/rustc_errors/src/diagnostic_impls.rs

+9
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ impl<I: rustc_type_ir::Interner> IntoDiagArg for rustc_type_ir::FnSig<I> {
118118
}
119119
}
120120

121+
impl<I: rustc_type_ir::Interner, T> IntoDiagArg for rustc_type_ir::Binder<I, T>
122+
where
123+
T: IntoDiagArg,
124+
{
125+
fn into_diag_arg(self) -> DiagArgValue {
126+
self.skip_binder().into_diag_arg()
127+
}
128+
}
129+
121130
into_diag_arg_for_number!(i8, u8, i16, u16, i32, u32, i64, u64, i128, u128, isize, usize);
122131

123132
impl IntoDiagArg for bool {

compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_hir::def_id::{DefId, LocalDefId};
1818
use rustc_infer::traits::FulfillmentError;
1919
use rustc_middle::bug;
2020
use rustc_middle::query::Key;
21-
use rustc_middle::ty::print::PrintTraitRefExt as _;
21+
use rustc_middle::ty::print::{PrintPolyTraitRefExt as _, PrintTraitRefExt as _};
2222
use rustc_middle::ty::GenericParamDefKind;
2323
use rustc_middle::ty::{self, suggest_constraining_type_param};
2424
use rustc_middle::ty::{AdtDef, Ty, TyCtxt, TypeVisitableExt};

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
4040
use rustc_infer::traits::ObligationCause;
4141
use rustc_middle::middle::stability::AllowUnstable;
4242
use rustc_middle::mir::interpret::{LitToConstError, LitToConstInput};
43+
use rustc_middle::ty::print::PrintPolyTraitRefExt as _;
4344
use rustc_middle::ty::{
4445
self, Const, GenericArgKind, GenericArgsRef, GenericParamDefKind, ParamEnv, Ty, TyCtxt,
4546
TypeVisitableExt,

compiler/rustc_middle/src/ty/codec.rs

+7-51
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,11 @@ impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> Encodable<E> for Ty<'tcx> {
115115
}
116116
}
117117

118-
impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> Encodable<E>
119-
for ty::Binder<'tcx, ty::PredicateKind<'tcx>>
120-
{
121-
fn encode(&self, e: &mut E) {
122-
self.bound_vars().encode(e);
123-
encode_with_shorthand(e, &self.skip_binder(), TyEncoder::predicate_shorthands);
124-
}
125-
}
126-
127118
impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> Encodable<E> for ty::Predicate<'tcx> {
128119
fn encode(&self, e: &mut E) {
129-
self.kind().encode(e);
120+
let kind = self.kind();
121+
kind.bound_vars().encode(e);
122+
encode_with_shorthand(e, &kind.skip_binder(), TyEncoder::predicate_shorthands);
130123
}
131124
}
132125

@@ -233,13 +226,11 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for Ty<'tcx> {
233226
}
234227
}
235228

236-
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D>
237-
for ty::Binder<'tcx, ty::PredicateKind<'tcx>>
238-
{
239-
fn decode(decoder: &mut D) -> ty::Binder<'tcx, ty::PredicateKind<'tcx>> {
229+
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for ty::Predicate<'tcx> {
230+
fn decode(decoder: &mut D) -> ty::Predicate<'tcx> {
240231
let bound_vars = Decodable::decode(decoder);
241232
// Handle shorthands first, if we have a usize > 0x80.
242-
ty::Binder::bind_with_vars(
233+
let predicate_kind = ty::Binder::bind_with_vars(
243234
if decoder.positioned_at_shorthand() {
244235
let pos = decoder.read_usize();
245236
assert!(pos >= SHORTHAND_OFFSET);
@@ -250,13 +241,7 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D>
250241
<ty::PredicateKind<'tcx> as Decodable<D>>::decode(decoder)
251242
},
252243
bound_vars,
253-
)
254-
}
255-
}
256-
257-
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for ty::Predicate<'tcx> {
258-
fn decode(decoder: &mut D) -> ty::Predicate<'tcx> {
259-
let predicate_kind = Decodable::decode(decoder);
244+
);
260245
decoder.interner().mk_predicate(predicate_kind)
261246
}
262247
}
@@ -599,32 +584,3 @@ macro_rules! implement_ty_decoder {
599584
}
600585
}
601586
}
602-
603-
macro_rules! impl_binder_encode_decode {
604-
($($t:ty),+ $(,)?) => {
605-
$(
606-
impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> Encodable<E> for ty::Binder<'tcx, $t> {
607-
fn encode(&self, e: &mut E) {
608-
self.bound_vars().encode(e);
609-
self.as_ref().skip_binder().encode(e);
610-
}
611-
}
612-
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for ty::Binder<'tcx, $t> {
613-
fn decode(decoder: &mut D) -> Self {
614-
let bound_vars = Decodable::decode(decoder);
615-
ty::Binder::bind_with_vars(Decodable::decode(decoder), bound_vars)
616-
}
617-
}
618-
)*
619-
}
620-
}
621-
622-
impl_binder_encode_decode! {
623-
&'tcx ty::List<Ty<'tcx>>,
624-
ty::FnSig<'tcx>,
625-
ty::Predicate<'tcx>,
626-
ty::TraitPredicate<'tcx>,
627-
ty::ExistentialPredicate<'tcx>,
628-
ty::TraitRef<'tcx>,
629-
ty::ExistentialTraitRef<'tcx>,
630-
}

compiler/rustc_middle/src/ty/context.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ use crate::ty::{
3131
self, AdtDef, AdtDefData, AdtKind, Binder, Clause, Clauses, Const, ConstData,
3232
GenericParamDefKind, ImplPolarity, List, ListWithCachedTypeInfo, ParamConst, ParamTy, Pattern,
3333
PatternKind, PolyExistentialPredicate, PolyFnSig, Predicate, PredicateKind, PredicatePolarity,
34-
Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyVid, TypeVisitable,
35-
Visibility,
34+
Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyVid, Visibility,
3635
};
3736
use crate::ty::{GenericArg, GenericArgs, GenericArgsRef};
3837
use rustc_ast::{self as ast, attr};
@@ -96,9 +95,8 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
9695
type GenericArg = ty::GenericArg<'tcx>;
9796
type Term = ty::Term<'tcx>;
9897

99-
type Binder<T: TypeVisitable<TyCtxt<'tcx>>> = Binder<'tcx, T>;
100-
type BoundVars = &'tcx List<ty::BoundVariableKind>;
101-
type BoundVar = ty::BoundVariableKind;
98+
type BoundVarKinds = &'tcx List<ty::BoundVariableKind>;
99+
type BoundVarKind = ty::BoundVariableKind;
102100

103101
type CanonicalVars = CanonicalVarInfos<'tcx>;
104102
type PredefinedOpaques = solve::PredefinedOpaques<'tcx>;
@@ -138,6 +136,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
138136

139137
type ParamEnv = ty::ParamEnv<'tcx>;
140138
type Predicate = Predicate<'tcx>;
139+
type Clause = Clause<'tcx>;
141140
type TraitPredicate = ty::TraitPredicate<'tcx>;
142141
type RegionOutlivesPredicate = ty::RegionOutlivesPredicate<'tcx>;
143142
type TypeOutlivesPredicate = ty::TypeOutlivesPredicate<'tcx>;
@@ -245,6 +244,10 @@ impl<'tcx> rustc_type_ir::inherent::Abi<TyCtxt<'tcx>> for abi::Abi {
245244
}
246245

247246
impl<'tcx> rustc_type_ir::inherent::Safety<TyCtxt<'tcx>> for hir::Safety {
247+
fn is_safe(self) -> bool {
248+
matches!(self, hir::Safety::Safe)
249+
}
250+
248251
fn prefix_str(self) -> &'static str {
249252
self.prefix_str()
250253
}

compiler/rustc_middle/src/ty/generic_args.rs

+8
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ impl<'tcx> rustc_type_ir::inherent::GenericArgs<TyCtxt<'tcx>> for ty::GenericArg
5151
fn identity_for_item(tcx: TyCtxt<'tcx>, def_id: DefId) -> ty::GenericArgsRef<'tcx> {
5252
GenericArgs::identity_for_item(tcx, def_id)
5353
}
54+
55+
fn extend_with_error(
56+
tcx: TyCtxt<'tcx>,
57+
def_id: DefId,
58+
original_args: &[ty::GenericArg<'tcx>],
59+
) -> ty::GenericArgsRef<'tcx> {
60+
ty::GenericArgs::extend_with_error(tcx, def_id, original_args)
61+
}
5462
}
5563

5664
impl<'tcx> rustc_type_ir::inherent::IntoKind for GenericArg<'tcx> {

0 commit comments

Comments
 (0)