@@ -22,8 +22,8 @@ use rustc_type_ir::inherent::{
22
22
use rustc_type_ir:: lang_items:: TraitSolverLangItem ;
23
23
use rustc_type_ir:: solve:: SizedTraitKind ;
24
24
use rustc_type_ir:: {
25
- AliasTerm , AliasTermKind , AliasTy , EarlyBinder , FlagComputation , Flags , ImplPolarity , InferTy ,
26
- ProjectionPredicate , TraitPredicate , TraitRef , Upcast ,
25
+ AliasTerm , AliasTermKind , AliasTy , AliasTyKind , EarlyBinder , FlagComputation , Flags ,
26
+ ImplPolarity , InferTy , ProjectionPredicate , TraitPredicate , TraitRef , Upcast ,
27
27
} ;
28
28
use salsa:: plumbing:: AsId ;
29
29
use smallvec:: { SmallVec , smallvec} ;
@@ -626,12 +626,7 @@ impl<'db> inherent::AdtDef<DbInterner<'db>> for AdtDef {
626
626
fn struct_tail_ty (
627
627
self ,
628
628
interner : DbInterner < ' db > ,
629
- ) -> Option <
630
- rustc_type_ir:: EarlyBinder <
631
- DbInterner < ' db > ,
632
- <DbInterner < ' db > as rustc_type_ir:: Interner >:: Ty ,
633
- > ,
634
- > {
629
+ ) -> Option < EarlyBinder < DbInterner < ' db > , Ty < ' db > > > {
635
630
let db = interner. db ( ) ;
636
631
let hir_def:: AdtId :: StructId ( struct_id) = self . inner ( ) . id else {
637
632
return None ;
@@ -645,10 +640,7 @@ impl<'db> inherent::AdtDef<DbInterner<'db>> for AdtDef {
645
640
fn all_field_tys (
646
641
self ,
647
642
interner : DbInterner < ' db > ,
648
- ) -> rustc_type_ir:: EarlyBinder <
649
- DbInterner < ' db > ,
650
- impl IntoIterator < Item = <DbInterner < ' db > as rustc_type_ir:: Interner >:: Ty > ,
651
- > {
643
+ ) -> EarlyBinder < DbInterner < ' db > , impl IntoIterator < Item = Ty < ' db > > > {
652
644
let db = interner. db ( ) ;
653
645
// FIXME: this is disabled just to match the behavior with chalk right now
654
646
let field_tys = |id : VariantId | {
@@ -679,19 +671,14 @@ impl<'db> inherent::AdtDef<DbInterner<'db>> for AdtDef {
679
671
. collect ( ) ,
680
672
} ;
681
673
682
- rustc_type_ir :: EarlyBinder :: bind ( tys)
674
+ EarlyBinder :: bind ( tys)
683
675
}
684
676
685
677
fn sizedness_constraint (
686
678
self ,
687
679
interner : DbInterner < ' db > ,
688
680
sizedness : SizedTraitKind ,
689
- ) -> Option <
690
- rustc_type_ir:: EarlyBinder <
691
- DbInterner < ' db > ,
692
- <DbInterner < ' db > as rustc_type_ir:: Interner >:: Ty ,
693
- > ,
694
- > {
681
+ ) -> Option < EarlyBinder < DbInterner < ' db > , Ty < ' db > > > {
695
682
if self . is_struct ( ) {
696
683
let tail_ty = self . all_field_tys ( interner) . skip_binder ( ) . into_iter ( ) . last ( ) ?;
697
684
@@ -1024,8 +1011,8 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
1024
1011
false
1025
1012
}
1026
1013
1027
- fn expand_abstract_consts < T : rustc_type_ir:: TypeFoldable < Self > > ( self , t : T ) -> T {
1028
- t
1014
+ fn expand_abstract_consts < T : rustc_type_ir:: TypeFoldable < Self > > ( self , _ : T ) -> T {
1015
+ unreachable ! ( "only used by the old trait solver in rustc" ) ;
1029
1016
}
1030
1017
1031
1018
fn generics_of ( self , def_id : Self :: DefId ) -> Self :: GenericsOf {
@@ -1054,6 +1041,9 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
1054
1041
) ,
1055
1042
SolverDefId :: InternedOpaqueTyId ( _def_id) => {
1056
1043
// FIXME(next-solver): track variances
1044
+ //
1045
+ // We compute them based on the only `Ty` level info in rustc,
1046
+ // move `variances_of_opaque` into `rustc_next_trait_solver` for reuse.
1057
1047
VariancesOf :: new_from_iter (
1058
1048
self ,
1059
1049
( 0 ..self . generics_of ( def_id) . count ( ) ) . map ( |_| Variance :: Invariant ) ,
@@ -1063,7 +1053,7 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
1063
1053
}
1064
1054
}
1065
1055
1066
- fn type_of ( self , def_id : Self :: DefId ) -> rustc_type_ir :: EarlyBinder < Self , Self :: Ty > {
1056
+ fn type_of ( self , def_id : Self :: DefId ) -> EarlyBinder < Self , Self :: Ty > {
1067
1057
let def_id = match def_id {
1068
1058
SolverDefId :: TypeAliasId ( id) => {
1069
1059
use hir_def:: Lookup ;
@@ -1074,6 +1064,13 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
1074
1064
crate :: TyDefId :: TypeAliasId ( id)
1075
1065
}
1076
1066
SolverDefId :: AdtId ( id) => crate :: TyDefId :: AdtId ( id) ,
1067
+ // FIXME(next-solver): This uses the types of `query mir_borrowck` in rustc.
1068
+ //
1069
+ // We currently always use the type from HIR typeck which ignores regions. This
1070
+ // should be fine.
1071
+ SolverDefId :: InternedOpaqueTyId ( _) => {
1072
+ return self . type_of_opaque_hir_typeck ( def_id) ;
1073
+ }
1077
1074
_ => panic ! ( "Unexpected def_id `{def_id:?}` provided for `type_of`" ) ,
1078
1075
} ;
1079
1076
self . db ( ) . ty_ns ( def_id)
@@ -1087,9 +1084,12 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
1087
1084
AdtDef :: new ( def_id, self )
1088
1085
}
1089
1086
1090
- fn alias_ty_kind ( self , alias : rustc_type_ir:: AliasTy < Self > ) -> rustc_type_ir:: AliasTyKind {
1091
- // FIXME: not currently creating any others
1092
- rustc_type_ir:: AliasTyKind :: Projection
1087
+ fn alias_ty_kind ( self , alias : rustc_type_ir:: AliasTy < Self > ) -> AliasTyKind {
1088
+ match alias. def_id {
1089
+ SolverDefId :: InternedOpaqueTyId ( _) => AliasTyKind :: Opaque ,
1090
+ SolverDefId :: TypeAliasId ( _) => AliasTyKind :: Projection ,
1091
+ _ => unimplemented ! ( "Unexpected alias: {:?}" , alias. def_id) ,
1092
+ }
1093
1093
}
1094
1094
1095
1095
fn alias_term_kind (
@@ -1100,7 +1100,7 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
1100
1100
SolverDefId :: InternedOpaqueTyId ( _) => AliasTermKind :: OpaqueTy ,
1101
1101
SolverDefId :: TypeAliasId ( _) => AliasTermKind :: ProjectionTy ,
1102
1102
SolverDefId :: ConstId ( _) => AliasTermKind :: UnevaluatedConst ,
1103
- _ => unreachable ! ( "Unexpected alias: {:?}" , alias. def_id) ,
1103
+ _ => unimplemented ! ( "Unexpected alias: {:?}" , alias. def_id) ,
1104
1104
}
1105
1105
}
1106
1106
@@ -1194,8 +1194,7 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
1194
1194
fn fn_sig (
1195
1195
self ,
1196
1196
def_id : Self :: DefId ,
1197
- ) -> rustc_type_ir:: EarlyBinder < Self , rustc_type_ir:: Binder < Self , rustc_type_ir:: FnSig < Self > > >
1198
- {
1197
+ ) -> EarlyBinder < Self , rustc_type_ir:: Binder < Self , rustc_type_ir:: FnSig < Self > > > {
1199
1198
let id = match def_id {
1200
1199
SolverDefId :: FunctionId ( id) => CallableDefId :: FunctionId ( id) ,
1201
1200
SolverDefId :: Ctor ( ctor) => match ctor {
@@ -1248,7 +1247,7 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
1248
1247
fn item_bounds (
1249
1248
self ,
1250
1249
def_id : Self :: DefId ,
1251
- ) -> rustc_type_ir :: EarlyBinder < Self , impl IntoIterator < Item = Self :: Clause > > {
1250
+ ) -> EarlyBinder < Self , impl IntoIterator < Item = Self :: Clause > > {
1252
1251
explicit_item_bounds ( self , def_id) . map_bound ( |bounds| {
1253
1252
Clauses :: new_from_iter ( self , elaborate ( self , bounds) . collect :: < Vec < _ > > ( ) )
1254
1253
} )
@@ -1258,7 +1257,7 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
1258
1257
fn item_self_bounds (
1259
1258
self ,
1260
1259
def_id : Self :: DefId ,
1261
- ) -> rustc_type_ir :: EarlyBinder < Self , impl IntoIterator < Item = Self :: Clause > > {
1260
+ ) -> EarlyBinder < Self , impl IntoIterator < Item = Self :: Clause > > {
1262
1261
explicit_item_bounds ( self , def_id) . map_bound ( |bounds| {
1263
1262
Clauses :: new_from_iter (
1264
1263
self ,
@@ -1270,7 +1269,7 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
1270
1269
fn item_non_self_bounds (
1271
1270
self ,
1272
1271
def_id : Self :: DefId ,
1273
- ) -> rustc_type_ir :: EarlyBinder < Self , impl IntoIterator < Item = Self :: Clause > > {
1272
+ ) -> EarlyBinder < Self , impl IntoIterator < Item = Self :: Clause > > {
1274
1273
let all_bounds: FxHashSet < _ > = self . item_bounds ( def_id) . skip_binder ( ) . into_iter ( ) . collect ( ) ;
1275
1274
let own_bounds: FxHashSet < _ > =
1276
1275
self . item_self_bounds ( def_id) . skip_binder ( ) . into_iter ( ) . collect ( ) ;
@@ -1288,7 +1287,7 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
1288
1287
fn predicates_of (
1289
1288
self ,
1290
1289
def_id : Self :: DefId ,
1291
- ) -> rustc_type_ir :: EarlyBinder < Self , impl IntoIterator < Item = Self :: Clause > > {
1290
+ ) -> EarlyBinder < Self , impl IntoIterator < Item = Self :: Clause > > {
1292
1291
let predicates = self . db ( ) . generic_predicates_ns ( def_id. try_into ( ) . unwrap ( ) ) ;
1293
1292
let predicates: Vec < _ > = predicates. iter ( ) . cloned ( ) . collect ( ) ;
1294
1293
EarlyBinder :: bind ( predicates. into_iter ( ) )
@@ -1298,7 +1297,7 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
1298
1297
fn own_predicates_of (
1299
1298
self ,
1300
1299
def_id : Self :: DefId ,
1301
- ) -> rustc_type_ir :: EarlyBinder < Self , impl IntoIterator < Item = Self :: Clause > > {
1300
+ ) -> EarlyBinder < Self , impl IntoIterator < Item = Self :: Clause > > {
1302
1301
let predicates = self . db ( ) . generic_predicates_without_parent_ns ( def_id. try_into ( ) . unwrap ( ) ) ;
1303
1302
let predicates: Vec < _ > = predicates. iter ( ) . cloned ( ) . collect ( ) ;
1304
1303
EarlyBinder :: bind ( predicates. into_iter ( ) )
@@ -1308,38 +1307,36 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
1308
1307
fn explicit_super_predicates_of (
1309
1308
self ,
1310
1309
def_id : Self :: DefId ,
1311
- ) -> rustc_type_ir:: EarlyBinder < Self , impl IntoIterator < Item = ( Self :: Clause , Self :: Span ) > >
1312
- {
1310
+ ) -> EarlyBinder < Self , impl IntoIterator < Item = ( Self :: Clause , Self :: Span ) > > {
1313
1311
let predicates: Vec < ( Clause < ' db > , Span ) > = self
1314
1312
. db ( )
1315
1313
. generic_predicates_ns ( def_id. try_into ( ) . unwrap ( ) )
1316
1314
. iter ( )
1317
1315
. cloned ( )
1318
1316
. map ( |p| ( p, Span :: dummy ( ) ) )
1319
1317
. collect ( ) ;
1320
- rustc_type_ir :: EarlyBinder :: bind ( predicates)
1318
+ EarlyBinder :: bind ( predicates)
1321
1319
}
1322
1320
1323
1321
#[ tracing:: instrument( skip( self ) , ret) ]
1324
1322
fn explicit_implied_predicates_of (
1325
1323
self ,
1326
1324
def_id : Self :: DefId ,
1327
- ) -> rustc_type_ir:: EarlyBinder < Self , impl IntoIterator < Item = ( Self :: Clause , Self :: Span ) > >
1328
- {
1325
+ ) -> EarlyBinder < Self , impl IntoIterator < Item = ( Self :: Clause , Self :: Span ) > > {
1329
1326
let predicates: Vec < ( Clause < ' db > , Span ) > = self
1330
1327
. db ( )
1331
1328
. generic_predicates_ns ( def_id. try_into ( ) . unwrap ( ) )
1332
1329
. iter ( )
1333
1330
. cloned ( )
1334
1331
. map ( |p| ( p, Span :: dummy ( ) ) )
1335
1332
. collect ( ) ;
1336
- rustc_type_ir :: EarlyBinder :: bind ( predicates)
1333
+ EarlyBinder :: bind ( predicates)
1337
1334
}
1338
1335
1339
1336
fn impl_super_outlives (
1340
1337
self ,
1341
1338
impl_def_id : Self :: DefId ,
1342
- ) -> rustc_type_ir :: EarlyBinder < Self , impl IntoIterator < Item = Self :: Clause > > {
1339
+ ) -> EarlyBinder < Self , impl IntoIterator < Item = Self :: Clause > > {
1343
1340
let impl_id = match impl_def_id {
1344
1341
SolverDefId :: ImplId ( id) => id,
1345
1342
_ => unreachable ! ( ) ,
@@ -1362,11 +1359,11 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
1362
1359
fn const_conditions (
1363
1360
self ,
1364
1361
def_id : Self :: DefId ,
1365
- ) -> rustc_type_ir :: EarlyBinder <
1362
+ ) -> EarlyBinder <
1366
1363
Self ,
1367
1364
impl IntoIterator < Item = rustc_type_ir:: Binder < Self , rustc_type_ir:: TraitRef < Self > > > ,
1368
1365
> {
1369
- rustc_type_ir :: EarlyBinder :: bind ( [ unimplemented ! ( ) ] )
1366
+ EarlyBinder :: bind ( [ unimplemented ! ( ) ] )
1370
1367
}
1371
1368
1372
1369
fn has_target_features ( self , def_id : Self :: DefId ) -> bool {
@@ -1740,7 +1737,7 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
1740
1737
}
1741
1738
1742
1739
fn has_item_definition ( self , def_id : Self :: DefId ) -> bool {
1743
- // FIXME: should check if has value
1740
+ // FIXME(next-solver) : should check if the associated item has a value.
1744
1741
true
1745
1742
}
1746
1743
@@ -1753,7 +1750,7 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
1753
1750
fn impl_trait_ref (
1754
1751
self ,
1755
1752
impl_def_id : Self :: DefId ,
1756
- ) -> rustc_type_ir :: EarlyBinder < Self , rustc_type_ir:: TraitRef < Self > > {
1753
+ ) -> EarlyBinder < Self , rustc_type_ir:: TraitRef < Self > > {
1757
1754
let impl_id = match impl_def_id {
1758
1755
SolverDefId :: ImplId ( id) => id,
1759
1756
_ => panic ! ( "Unexpected SolverDefId in impl_trait_ref" ) ,
@@ -1815,7 +1812,8 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
1815
1812
}
1816
1813
1817
1814
fn trait_may_be_implemented_via_object ( self , trait_def_id : Self :: DefId ) -> bool {
1818
- // FIXME(next-solver)
1815
+ // FIXME(next-solver): should check the `TraitFlags` for
1816
+ // the `#[rustc_do_not_implement_via_object]` flag
1819
1817
true
1820
1818
}
1821
1819
@@ -1954,12 +1952,12 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
1954
1952
fn explicit_implied_const_bounds (
1955
1953
self ,
1956
1954
def_id : Self :: DefId ,
1957
- ) -> rustc_type_ir :: EarlyBinder <
1955
+ ) -> EarlyBinder <
1958
1956
Self ,
1959
1957
impl IntoIterator < Item = rustc_type_ir:: Binder < Self , rustc_type_ir:: TraitRef < Self > > > ,
1960
1958
> {
1961
1959
// FIXME(next-solver)
1962
- rustc_type_ir :: EarlyBinder :: bind ( [ ] )
1960
+ EarlyBinder :: bind ( [ ] )
1963
1961
}
1964
1962
1965
1963
fn fn_is_const ( self , def_id : Self :: DefId ) -> bool {
@@ -1982,21 +1980,31 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
1982
1980
None
1983
1981
}
1984
1982
1985
- fn type_of_opaque_hir_typeck (
1986
- self ,
1987
- def_id : Self :: LocalDefId ,
1988
- ) -> rustc_type_ir:: EarlyBinder < Self , Self :: Ty > {
1989
- // FIXME(next-solver)
1990
- unimplemented ! ( )
1983
+ fn type_of_opaque_hir_typeck ( self , def_id : Self :: LocalDefId ) -> EarlyBinder < Self , Self :: Ty > {
1984
+ match def_id {
1985
+ SolverDefId :: InternedOpaqueTyId ( opaque) => {
1986
+ let impl_trait_id = self . db ( ) . lookup_intern_impl_trait_id ( opaque) ;
1987
+ match impl_trait_id {
1988
+ crate :: ImplTraitId :: ReturnTypeImplTrait ( func, idx) => {
1989
+ let infer = self . db ( ) . infer ( func. into ( ) ) ;
1990
+ EarlyBinder :: bind ( infer. type_of_rpit [ idx] . to_nextsolver ( self ) )
1991
+ }
1992
+ crate :: ImplTraitId :: TypeAliasImplTrait ( ..)
1993
+ | crate :: ImplTraitId :: AsyncBlockTypeImplTrait ( _, _) => {
1994
+ // FIXME(next-solver)
1995
+ EarlyBinder :: bind ( Ty :: new_error ( self , ErrorGuaranteed ) )
1996
+ }
1997
+ }
1998
+ }
1999
+ _ => panic ! ( "Unexpected SolverDefId in type_of_opaque_hir_typeck" ) ,
2000
+ }
1991
2001
}
1992
2002
1993
2003
fn coroutine_hidden_types (
1994
2004
self ,
1995
2005
def_id : Self :: DefId ,
1996
- ) -> rustc_type_ir:: EarlyBinder <
1997
- Self ,
1998
- rustc_type_ir:: Binder < Self , rustc_type_ir:: CoroutineWitnessTypes < Self > > ,
1999
- > {
2006
+ ) -> EarlyBinder < Self , rustc_type_ir:: Binder < Self , rustc_type_ir:: CoroutineWitnessTypes < Self > > >
2007
+ {
2000
2008
// FIXME(next-solver)
2001
2009
unimplemented ! ( )
2002
2010
}
0 commit comments