Skip to content

Commit bec1029

Browse files
committed
Auto merge of rust-lang#125335 - compiler-errors:binder, r=lcnr
Uplift `Binder`, `OutlivesPredicate` into `rustc_type_ir` Almost done with all the types 🙏 r? lcnr
2 parents b54dd08 + 1c8230e commit bec1029

File tree

32 files changed

+774
-734
lines changed

32 files changed

+774
-734
lines changed

compiler/rustc_borrowck/src/type_check/constraint_conversion.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
136136

137137
fn convert(
138138
&mut self,
139-
predicate: ty::OutlivesPredicate<ty::GenericArg<'tcx>, ty::Region<'tcx>>,
139+
predicate: ty::OutlivesPredicate<'tcx, ty::GenericArg<'tcx>>,
140140
constraint_category: ConstraintCategory<'tcx>,
141141
) {
142142
debug!("generate: constraints at: {:#?}", self.locations);
@@ -276,7 +276,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
276276
&self,
277277
ty: Ty<'tcx>,
278278
next_outlives_predicates: &mut Vec<(
279-
ty::OutlivesPredicate<ty::GenericArg<'tcx>, ty::Region<'tcx>>,
279+
ty::OutlivesPredicate<'tcx, ty::GenericArg<'tcx>>,
280280
ConstraintCategory<'tcx>,
281281
)>,
282282
) -> Ty<'tcx> {

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_hir_analysis/src/outlives/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use smallvec::smallvec;
99
/// Tracks the `T: 'a` or `'a: 'a` predicates that we have inferred
1010
/// must be added to the struct header.
1111
pub(crate) type RequiredPredicates<'tcx> =
12-
FxIndexMap<ty::OutlivesPredicate<GenericArg<'tcx>, ty::Region<'tcx>>, Span>;
12+
FxIndexMap<ty::OutlivesPredicate<'tcx, ty::GenericArg<'tcx>>, Span>;
1313

1414
/// Given a requirement `T: 'a` or `'b: 'a`, deduce the
1515
/// outlives_component and add it to `required_predicates`

compiler/rustc_infer/src/infer/outlives/env.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ struct OutlivesEnvironmentBuilder<'tcx> {
6464
/// "Region-bound pairs" tracks outlives relations that are known to
6565
/// be true, either because of explicit where-clauses like `T: 'a` or
6666
/// because of implied bounds.
67-
pub type RegionBoundPairs<'tcx> =
68-
FxIndexSet<ty::OutlivesPredicate<GenericKind<'tcx>, Region<'tcx>>>;
67+
pub type RegionBoundPairs<'tcx> = FxIndexSet<ty::OutlivesPredicate<'tcx, GenericKind<'tcx>>>;
6968

7069
impl<'tcx> OutlivesEnvironment<'tcx> {
7170
/// Create a builder using `ParamEnv` and add explicit outlives bounds into it.

compiler/rustc_infer/src/infer/outlives/verify.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
9494
pub fn approx_declared_bounds_from_env(
9595
&self,
9696
alias_ty: ty::AliasTy<'tcx>,
97-
) -> Vec<ty::Binder<'tcx, ty::OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>>>> {
97+
) -> Vec<ty::PolyTypeOutlivesPredicate<'tcx>> {
9898
let erased_alias_ty = self.tcx.erase_regions(alias_ty.to_ty(self.tcx));
9999
self.declared_generic_bounds_from_env_for_erased_ty(erased_alias_ty)
100100
}
@@ -193,7 +193,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
193193
fn declared_generic_bounds_from_env(
194194
&self,
195195
generic_ty: Ty<'tcx>,
196-
) -> Vec<ty::Binder<'tcx, ty::OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>>>> {
196+
) -> Vec<ty::PolyTypeOutlivesPredicate<'tcx>> {
197197
assert!(matches!(generic_ty.kind(), ty::Param(_) | ty::Placeholder(_)));
198198
self.declared_generic_bounds_from_env_for_erased_ty(generic_ty)
199199
}
@@ -213,7 +213,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
213213
fn declared_generic_bounds_from_env_for_erased_ty(
214214
&self,
215215
erased_ty: Ty<'tcx>,
216-
) -> Vec<ty::Binder<'tcx, ty::OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>>>> {
216+
) -> Vec<ty::PolyTypeOutlivesPredicate<'tcx>> {
217217
let tcx = self.tcx;
218218

219219
// To start, collect bounds from user environment. Note that

compiler/rustc_middle/src/infer/canonical.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use std::collections::hash_map::Entry;
3232
use crate::infer::MemberConstraint;
3333
use crate::mir::ConstraintCategory;
3434
use crate::ty::GenericArg;
35-
use crate::ty::{self, List, Region, Ty, TyCtxt, TypeFlags, TypeVisitableExt};
35+
use crate::ty::{self, List, Ty, TyCtxt, TypeFlags, TypeVisitableExt};
3636

3737
pub type Canonical<'tcx, V> = ir::Canonical<TyCtxt<'tcx>, V>;
3838
pub type CanonicalVarInfo<'tcx> = ir::CanonicalVarInfo<TyCtxt<'tcx>>;
@@ -141,7 +141,7 @@ impl<'tcx, R> QueryResponse<'tcx, R> {
141141
}
142142

143143
pub type QueryOutlivesConstraint<'tcx> =
144-
(ty::OutlivesPredicate<GenericArg<'tcx>, Region<'tcx>>, ConstraintCategory<'tcx>);
144+
(ty::OutlivesPredicate<'tcx, GenericArg<'tcx>>, ConstraintCategory<'tcx>);
145145

146146
TrivialTypeTraversalImpls! {
147147
crate::infer::canonical::Certainty,

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-15
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>;
@@ -123,7 +121,6 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
123121
type Abi = abi::Abi;
124122

125123
type Const = ty::Const<'tcx>;
126-
type AliasConst = ty::UnevaluatedConst<'tcx>;
127124
type PlaceholderConst = ty::PlaceholderConst;
128125
type ParamConst = ty::ParamConst;
129126
type BoundConst = ty::BoundVar;
@@ -138,15 +135,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
138135

139136
type ParamEnv = ty::ParamEnv<'tcx>;
140137
type Predicate = Predicate<'tcx>;
141-
type TraitPredicate = ty::TraitPredicate<'tcx>;
142-
type RegionOutlivesPredicate = ty::RegionOutlivesPredicate<'tcx>;
143-
type TypeOutlivesPredicate = ty::TypeOutlivesPredicate<'tcx>;
144-
type ProjectionPredicate = ty::ProjectionPredicate<'tcx>;
145-
type NormalizesTo = ty::NormalizesTo<'tcx>;
146-
type SubtypePredicate = ty::SubtypePredicate<'tcx>;
147-
148-
type CoercePredicate = ty::CoercePredicate<'tcx>;
149-
type ClosureKind = ty::ClosureKind;
138+
type Clause = Clause<'tcx>;
150139

151140
type Clauses = ty::Clauses<'tcx>;
152141

@@ -245,6 +234,10 @@ impl<'tcx> rustc_type_ir::inherent::Abi<TyCtxt<'tcx>> for abi::Abi {
245234
}
246235

247236
impl<'tcx> rustc_type_ir::inherent::Safety<TyCtxt<'tcx>> for hir::Safety {
237+
fn is_safe(self) -> bool {
238+
matches!(self, hir::Safety::Safe)
239+
}
240+
248241
fn prefix_str(self) -> &'static str {
249242
self.prefix_str()
250243
}

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)