@@ -1142,10 +1142,6 @@ fn report_assoc_ty_on_inherent_impl(tcx: TyCtxt<'_>, span: Span) {
1142
1142
) ;
1143
1143
}
1144
1144
1145
- fn type_of ( tcx : TyCtxt < ' _ > , def_id : DefId ) -> Ty < ' _ > {
1146
- checked_type_of ( tcx, def_id, true ) . unwrap ( )
1147
- }
1148
-
1149
1145
fn infer_placeholder_type (
1150
1146
tcx : TyCtxt < ' _ > ,
1151
1147
def_id : DefId ,
@@ -1189,26 +1185,14 @@ fn infer_placeholder_type(
1189
1185
ty
1190
1186
}
1191
1187
1192
- /// Same as [`type_of`] but returns [`Option`] instead of failing.
1193
- ///
1194
- /// If you want to fail anyway, you can set the `fail` parameter to true, but in this case,
1195
- /// you'd better just call [`type_of`] directly.
1196
- pub fn checked_type_of ( tcx : TyCtxt < ' _ > , def_id : DefId , fail : bool ) -> Option < Ty < ' _ > > {
1188
+ fn type_of ( tcx : TyCtxt < ' _ > , def_id : DefId ) -> Ty < ' _ > {
1197
1189
use rustc:: hir:: * ;
1198
1190
1199
- let hir_id = match tcx. hir ( ) . as_local_hir_id ( def_id) {
1200
- Some ( hir_id) => hir_id,
1201
- None => {
1202
- if !fail {
1203
- return None ;
1204
- }
1205
- bug ! ( "invalid node" ) ;
1206
- }
1207
- } ;
1191
+ let hir_id = tcx. hir ( ) . as_local_hir_id ( def_id) . unwrap ( ) ;
1208
1192
1209
1193
let icx = ItemCtxt :: new ( tcx, def_id) ;
1210
1194
1211
- Some ( match tcx. hir ( ) . get ( hir_id) {
1195
+ match tcx. hir ( ) . get ( hir_id) {
1212
1196
Node :: TraitItem ( item) => match item. kind {
1213
1197
TraitItemKind :: Method ( ..) => {
1214
1198
let substs = InternalSubsts :: identity_for_item ( tcx, def_id) ;
@@ -1225,9 +1209,6 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
1225
1209
} ,
1226
1210
TraitItemKind :: Type ( _, Some ( ref ty) ) => icx. to_ty ( ty) ,
1227
1211
TraitItemKind :: Type ( _, None ) => {
1228
- if !fail {
1229
- return None ;
1230
- }
1231
1212
span_bug ! ( item. span, "associated type missing default" ) ;
1232
1213
}
1233
1214
} ,
@@ -1321,9 +1302,6 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
1321
1302
| ItemKind :: GlobalAsm ( ..)
1322
1303
| ItemKind :: ExternCrate ( ..)
1323
1304
| ItemKind :: Use ( ..) => {
1324
- if !fail {
1325
- return None ;
1326
- }
1327
1305
span_bug ! (
1328
1306
item. span,
1329
1307
"compute_type_of_item: unexpected item type: {:?}" ,
@@ -1361,7 +1339,7 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
1361
1339
..
1362
1340
} ) => {
1363
1341
if gen. is_some ( ) {
1364
- return Some ( tcx. typeck_tables_of ( def_id) . node_type ( hir_id) ) ;
1342
+ return tcx. typeck_tables_of ( def_id) . node_type ( hir_id) ;
1365
1343
}
1366
1344
1367
1345
let substs = InternalSubsts :: identity_for_item ( tcx, def_id) ;
@@ -1436,13 +1414,9 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
1436
1414
. map ( |( index, _) | index)
1437
1415
. next ( )
1438
1416
} )
1439
- . or_else ( || {
1440
- if !fail {
1441
- None
1442
- } else {
1443
- bug ! ( "no arg matching AnonConst in path" )
1444
- }
1445
- } ) ?;
1417
+ . unwrap_or_else ( || {
1418
+ bug ! ( "no arg matching AnonConst in path" ) ;
1419
+ } ) ;
1446
1420
1447
1421
// We've encountered an `AnonConst` in some path, so we need to
1448
1422
// figure out which generic parameter it corresponds to and return
@@ -1452,8 +1426,7 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
1452
1426
tcx. generics_of ( tcx. parent ( def_id) . unwrap ( ) )
1453
1427
}
1454
1428
Res :: Def ( _, def_id) => tcx. generics_of ( def_id) ,
1455
- Res :: Err => return Some ( tcx. types . err ) ,
1456
- _ if !fail => return None ,
1429
+ Res :: Err => return tcx. types . err ,
1457
1430
res => {
1458
1431
tcx. sess . delay_span_bug (
1459
1432
DUMMY_SP ,
@@ -1462,7 +1435,7 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
1462
1435
res,
1463
1436
) ,
1464
1437
) ;
1465
- return Some ( tcx. types . err ) ;
1438
+ return tcx. types . err ;
1466
1439
}
1467
1440
} ;
1468
1441
@@ -1480,24 +1453,18 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
1480
1453
// probably from an extra arg where one is not needed.
1481
1454
. unwrap_or ( tcx. types . err )
1482
1455
} else {
1483
- if !fail {
1484
- return None ;
1485
- }
1486
1456
tcx. sess . delay_span_bug (
1487
1457
DUMMY_SP ,
1488
1458
& format ! (
1489
1459
"unexpected const parent path {:?}" ,
1490
1460
parent_node,
1491
1461
) ,
1492
1462
) ;
1493
- return Some ( tcx. types . err ) ;
1463
+ return tcx. types . err ;
1494
1464
}
1495
1465
}
1496
1466
1497
1467
x => {
1498
- if !fail {
1499
- return None ;
1500
- }
1501
1468
tcx. sess . delay_span_bug (
1502
1469
DUMMY_SP ,
1503
1470
& format ! (
@@ -1547,21 +1514,13 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
1547
1514
}
1548
1515
ty
1549
1516
}
1550
- x => {
1551
- if !fail {
1552
- return None ;
1553
- }
1554
- bug ! ( "unexpected non-type Node::GenericParam: {:?}" , x)
1555
- } ,
1517
+ x => bug ! ( "unexpected non-type Node::GenericParam: {:?}" , x) ,
1556
1518
} ,
1557
1519
1558
1520
x => {
1559
- if !fail {
1560
- return None ;
1561
- }
1562
1521
bug ! ( "unexpected sort of node in type_of_def_id(): {:?}" , x) ;
1563
1522
}
1564
- } )
1523
+ }
1565
1524
}
1566
1525
1567
1526
fn find_opaque_ty_constraints ( tcx : TyCtxt < ' _ > , def_id : DefId ) -> Ty < ' _ > {
0 commit comments