@@ -158,7 +158,7 @@ pub trait TypeInformationCtxt<'tcx> {
158
158
159
159
fn resolve_vars_if_possible < T : TypeFoldable < TyCtxt < ' tcx > > > ( & self , t : T ) -> T ;
160
160
161
- fn try_structurally_resolve_type ( & self , span : Span , ty : Ty < ' tcx > ) -> Ty < ' tcx > ;
161
+ fn structurally_resolve_type ( & self , span : Span , ty : Ty < ' tcx > ) -> Ty < ' tcx > ;
162
162
163
163
fn report_bug ( & self , span : Span , msg : impl ToString ) -> Self :: Error ;
164
164
@@ -191,8 +191,8 @@ impl<'tcx> TypeInformationCtxt<'tcx> for &FnCtxt<'_, 'tcx> {
191
191
self . infcx . resolve_vars_if_possible ( t)
192
192
}
193
193
194
- fn try_structurally_resolve_type ( & self , sp : Span , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
195
- ( * * self ) . try_structurally_resolve_type ( sp, ty)
194
+ fn structurally_resolve_type ( & self , sp : Span , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
195
+ ( * * self ) . structurally_resolve_type ( sp, ty)
196
196
}
197
197
198
198
fn report_bug ( & self , span : Span , msg : impl ToString ) -> Self :: Error {
@@ -236,7 +236,7 @@ impl<'tcx> TypeInformationCtxt<'tcx> for (&LateContext<'tcx>, LocalDefId) {
236
236
self . 0 . maybe_typeck_results ( ) . expect ( "expected typeck results" )
237
237
}
238
238
239
- fn try_structurally_resolve_type ( & self , _span : Span , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
239
+ fn structurally_resolve_type ( & self , _span : Span , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
240
240
// FIXME: Maybe need to normalize here.
241
241
ty
242
242
}
@@ -776,7 +776,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
776
776
777
777
// Select just those fields of the `with`
778
778
// expression that will actually be used
779
- match self . cx . try_structurally_resolve_type ( with_expr. span , with_place. place . ty ( ) ) . kind ( ) {
779
+ match self . cx . structurally_resolve_type ( with_expr. span , with_place. place . ty ( ) ) . kind ( ) {
780
780
ty:: Adt ( adt, args) if adt. is_struct ( ) => {
781
781
// Consume those fields of the with expression that are needed.
782
782
for ( f_index, with_field) in adt. non_enum_variant ( ) . fields . iter_enumerated ( ) {
@@ -1176,7 +1176,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
1176
1176
/// two operations: a dereference to reach the array data and then an index to
1177
1177
/// jump forward to the relevant item.
1178
1178
impl < ' tcx , Cx : TypeInformationCtxt < ' tcx > , D : Delegate < ' tcx > > ExprUseVisitor < ' tcx , Cx , D > {
1179
- fn resolve_type_vars_or_bug (
1179
+ fn expect_and_resolve_type (
1180
1180
& self ,
1181
1181
id : HirId ,
1182
1182
ty : Option < Ty < ' tcx > > ,
@@ -1185,12 +1185,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
1185
1185
Some ( ty) => {
1186
1186
let ty = self . cx . resolve_vars_if_possible ( ty) ;
1187
1187
self . cx . error_reported_in_ty ( ty) ?;
1188
- if ty. is_ty_var ( ) {
1189
- debug ! ( "resolve_type_vars_or_bug: infer var from {:?}" , ty) ;
1190
- Err ( self . cx . report_bug ( self . cx . tcx ( ) . hir_span ( id) , "encountered type variable" ) )
1191
- } else {
1192
- Ok ( ty)
1193
- }
1188
+ Ok ( ty)
1194
1189
}
1195
1190
None => {
1196
1191
// FIXME: We shouldn't be relying on the infcx being tainted.
@@ -1201,15 +1196,15 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
1201
1196
}
1202
1197
1203
1198
fn node_ty ( & self , hir_id : HirId ) -> Result < Ty < ' tcx > , Cx :: Error > {
1204
- self . resolve_type_vars_or_bug ( hir_id, self . cx . typeck_results ( ) . node_type_opt ( hir_id) )
1199
+ self . expect_and_resolve_type ( hir_id, self . cx . typeck_results ( ) . node_type_opt ( hir_id) )
1205
1200
}
1206
1201
1207
1202
fn expr_ty ( & self , expr : & hir:: Expr < ' _ > ) -> Result < Ty < ' tcx > , Cx :: Error > {
1208
- self . resolve_type_vars_or_bug ( expr. hir_id , self . cx . typeck_results ( ) . expr_ty_opt ( expr) )
1203
+ self . expect_and_resolve_type ( expr. hir_id , self . cx . typeck_results ( ) . expr_ty_opt ( expr) )
1209
1204
}
1210
1205
1211
1206
fn expr_ty_adjusted ( & self , expr : & hir:: Expr < ' _ > ) -> Result < Ty < ' tcx > , Cx :: Error > {
1212
- self . resolve_type_vars_or_bug (
1207
+ self . expect_and_resolve_type (
1213
1208
expr. hir_id ,
1214
1209
self . cx . typeck_results ( ) . expr_ty_adjusted_opt ( expr) ,
1215
1210
)
@@ -1264,10 +1259,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
1264
1259
// a bind-by-ref means that the base_ty will be the type of the ident itself,
1265
1260
// but what we want here is the type of the underlying value being borrowed.
1266
1261
// So peel off one-level, turning the &T into T.
1267
- match self
1268
- . cx
1269
- . try_structurally_resolve_type ( pat. span , base_ty)
1270
- . builtin_deref ( false )
1262
+ match self . cx . structurally_resolve_type ( pat. span , base_ty) . builtin_deref ( false )
1271
1263
{
1272
1264
Some ( ty) => Ok ( ty) ,
1273
1265
None => {
@@ -1513,10 +1505,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
1513
1505
if node_ty != place_ty
1514
1506
&& self
1515
1507
. cx
1516
- . try_structurally_resolve_type (
1517
- self . cx . tcx ( ) . hir_span ( base_place. hir_id ) ,
1518
- place_ty,
1519
- )
1508
+ . structurally_resolve_type ( self . cx . tcx ( ) . hir_span ( base_place. hir_id ) , place_ty)
1520
1509
. is_impl_trait ( )
1521
1510
{
1522
1511
projections. push ( Projection { kind : ProjectionKind :: OpaqueCast , ty : node_ty } ) ;
@@ -1538,7 +1527,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
1538
1527
let base_ty = self . expr_ty_adjusted ( base) ?;
1539
1528
1540
1529
let ty:: Ref ( region, _, mutbl) =
1541
- * self . cx . try_structurally_resolve_type ( base. span , base_ty) . kind ( )
1530
+ * self . cx . structurally_resolve_type ( base. span , base_ty) . kind ( )
1542
1531
else {
1543
1532
span_bug ! ( expr. span, "cat_overloaded_place: base is not a reference" ) ;
1544
1533
} ;
@@ -1556,7 +1545,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
1556
1545
let base_curr_ty = base_place. place . ty ( ) ;
1557
1546
let deref_ty = match self
1558
1547
. cx
1559
- . try_structurally_resolve_type ( self . cx . tcx ( ) . hir_span ( base_place. hir_id ) , base_curr_ty)
1548
+ . structurally_resolve_type ( self . cx . tcx ( ) . hir_span ( base_place. hir_id ) , base_curr_ty)
1560
1549
. builtin_deref ( true )
1561
1550
{
1562
1551
Some ( ty) => ty,
@@ -1584,7 +1573,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
1584
1573
) -> Result < VariantIdx , Cx :: Error > {
1585
1574
let res = self . cx . typeck_results ( ) . qpath_res ( qpath, pat_hir_id) ;
1586
1575
let ty = self . cx . typeck_results ( ) . node_type ( pat_hir_id) ;
1587
- let ty:: Adt ( adt_def, _) = self . cx . try_structurally_resolve_type ( span, ty) . kind ( ) else {
1576
+ let ty:: Adt ( adt_def, _) = self . cx . structurally_resolve_type ( span, ty) . kind ( ) else {
1588
1577
return Err ( self
1589
1578
. cx
1590
1579
. report_bug ( span, "struct or tuple struct pattern not applied to an ADT" ) ) ;
@@ -1616,7 +1605,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
1616
1605
span : Span ,
1617
1606
) -> Result < usize , Cx :: Error > {
1618
1607
let ty = self . cx . typeck_results ( ) . node_type ( pat_hir_id) ;
1619
- match self . cx . try_structurally_resolve_type ( span, ty) . kind ( ) {
1608
+ match self . cx . structurally_resolve_type ( span, ty) . kind ( ) {
1620
1609
ty:: Adt ( adt_def, _) => Ok ( adt_def. variant ( variant_index) . fields . len ( ) ) ,
1621
1610
_ => {
1622
1611
self . cx
@@ -1631,7 +1620,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
1631
1620
/// Here `pat_hir_id` is the HirId of the pattern itself.
1632
1621
fn total_fields_in_tuple ( & self , pat_hir_id : HirId , span : Span ) -> Result < usize , Cx :: Error > {
1633
1622
let ty = self . cx . typeck_results ( ) . node_type ( pat_hir_id) ;
1634
- match self . cx . try_structurally_resolve_type ( span, ty) . kind ( ) {
1623
+ match self . cx . structurally_resolve_type ( span, ty) . kind ( ) {
1635
1624
ty:: Tuple ( args) => Ok ( args. len ( ) ) ,
1636
1625
_ => Err ( self . cx . report_bug ( span, "tuple pattern not applied to a tuple" ) ) ,
1637
1626
}
@@ -1820,7 +1809,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
1820
1809
PatKind :: Slice ( before, ref slice, after) => {
1821
1810
let Some ( element_ty) = self
1822
1811
. cx
1823
- . try_structurally_resolve_type ( pat. span , place_with_id. place . ty ( ) )
1812
+ . structurally_resolve_type ( pat. span , place_with_id. place . ty ( ) )
1824
1813
. builtin_index ( )
1825
1814
else {
1826
1815
debug ! ( "explicit index of non-indexable type {:?}" , place_with_id) ;
@@ -1890,7 +1879,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
1890
1879
}
1891
1880
1892
1881
fn is_multivariant_adt ( & self , ty : Ty < ' tcx > , span : Span ) -> bool {
1893
- if let ty:: Adt ( def, _) = self . cx . try_structurally_resolve_type ( span, ty) . kind ( ) {
1882
+ if let ty:: Adt ( def, _) = self . cx . structurally_resolve_type ( span, ty) . kind ( ) {
1894
1883
// Note that if a non-exhaustive SingleVariant is defined in another crate, we need
1895
1884
// to assume that more cases will be added to the variant in the future. This mean
1896
1885
// that we should handle non-exhaustive SingleVariant the same way we would handle
0 commit comments