@@ -1134,43 +1134,20 @@ fn report_assoc_ty_on_inherent_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, span:
1134
1134
}
1135
1135
1136
1136
fn type_of < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , def_id : DefId ) -> Ty < ' tcx > {
1137
- checked_type_of ( tcx, def_id, true ) . unwrap ( )
1138
- }
1139
-
1140
- /// Same as [`type_of`] but returns [`Option`] instead of failing.
1141
- ///
1142
- /// If you want to fail anyway, you can set the `fail` parameter to true, but in this case,
1143
- /// you'd better just call [`type_of`] directly.
1144
- pub fn checked_type_of < ' a , ' tcx > (
1145
- tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
1146
- def_id : DefId ,
1147
- fail : bool ,
1148
- ) -> Option < Ty < ' tcx > > {
1149
1137
use rustc:: hir:: * ;
1150
1138
1151
- let hir_id = match tcx. hir ( ) . as_local_hir_id ( def_id) {
1152
- Some ( hir_id) => hir_id,
1153
- None => {
1154
- if !fail {
1155
- return None ;
1156
- }
1157
- bug ! ( "invalid node" ) ;
1158
- }
1159
- } ;
1139
+ let hir_id = tcx. hir ( ) . as_local_hir_id ( def_id) . unwrap ( ) ;
1160
1140
1161
1141
let icx = ItemCtxt :: new ( tcx, def_id) ;
1162
1142
1163
- Some ( match tcx. hir ( ) . get_by_hir_id ( hir_id) {
1143
+ match tcx. hir ( ) . get_by_hir_id ( hir_id) {
1164
1144
Node :: TraitItem ( item) => match item. node {
1165
1145
TraitItemKind :: Method ( ..) => {
1166
1146
let substs = InternalSubsts :: identity_for_item ( tcx, def_id) ;
1167
1147
tcx. mk_fn_def ( def_id, substs)
1168
1148
}
1169
1149
TraitItemKind :: Const ( ref ty, _) | TraitItemKind :: Type ( _, Some ( ref ty) ) => icx. to_ty ( ty) ,
1170
1150
TraitItemKind :: Type ( _, None ) => {
1171
- if !fail {
1172
- return None ;
1173
- }
1174
1151
span_bug ! ( item. span, "associated type missing default" ) ;
1175
1152
}
1176
1153
} ,
@@ -1252,9 +1229,6 @@ pub fn checked_type_of<'a, 'tcx>(
1252
1229
| ItemKind :: GlobalAsm ( ..)
1253
1230
| ItemKind :: ExternCrate ( ..)
1254
1231
| ItemKind :: Use ( ..) => {
1255
- if !fail {
1256
- return None ;
1257
- }
1258
1232
span_bug ! (
1259
1233
item. span,
1260
1234
"compute_type_of_item: unexpected item type: {:?}" ,
@@ -1293,7 +1267,7 @@ pub fn checked_type_of<'a, 'tcx>(
1293
1267
..
1294
1268
} ) => {
1295
1269
if gen. is_some ( ) {
1296
- return Some ( tcx. typeck_tables_of ( def_id) . node_type ( hir_id) ) ;
1270
+ return tcx. typeck_tables_of ( def_id) . node_type ( hir_id) ;
1297
1271
}
1298
1272
1299
1273
let substs = ty:: ClosureSubsts {
@@ -1371,9 +1345,6 @@ pub fn checked_type_of<'a, 'tcx>(
1371
1345
}
1372
1346
// Sanity check to make sure everything is as expected.
1373
1347
if !found_const {
1374
- if !fail {
1375
- return None ;
1376
- }
1377
1348
bug ! ( "no arg matching AnonConst in path" )
1378
1349
}
1379
1350
match path. def {
@@ -1389,37 +1360,24 @@ pub fn checked_type_of<'a, 'tcx>(
1389
1360
for param in & generics. params {
1390
1361
if let ty:: GenericParamDefKind :: Const = param. kind {
1391
1362
if param_index == arg_index {
1392
- return Some ( tcx. type_of ( param. def_id ) ) ;
1363
+ return tcx. type_of ( param. def_id ) ;
1393
1364
}
1394
1365
param_index += 1 ;
1395
1366
}
1396
1367
}
1397
1368
// This is no generic parameter associated with the arg. This is
1398
1369
// probably from an extra arg where one is not needed.
1399
- return Some ( tcx. types . err ) ;
1370
+ return tcx. types . err ;
1400
1371
}
1401
1372
Def :: Err => tcx. types . err ,
1402
- x => {
1403
- if !fail {
1404
- return None ;
1405
- }
1406
- bug ! ( "unexpected const parent path def {:?}" , x) ;
1407
- }
1408
- }
1409
- }
1410
- x => {
1411
- if !fail {
1412
- return None ;
1373
+ x => bug ! ( "unexpected const parent path def {:?}" , x) ,
1413
1374
}
1414
- bug ! ( "unexpected const parent path {:?}" , x) ;
1415
1375
}
1376
+ x => bug ! ( "unexpected const parent path {:?}" , x) ,
1416
1377
}
1417
1378
}
1418
1379
1419
1380
x => {
1420
- if !fail {
1421
- return None ;
1422
- }
1423
1381
bug ! ( "unexpected const parent in type_of_def_id(): {:?}" , x) ;
1424
1382
}
1425
1383
}
@@ -1430,21 +1388,13 @@ pub fn checked_type_of<'a, 'tcx>(
1430
1388
hir:: GenericParamKind :: Const { ref ty, .. } => {
1431
1389
icx. to_ty ( ty)
1432
1390
}
1433
- x => {
1434
- if !fail {
1435
- return None ;
1436
- }
1437
- bug ! ( "unexpected non-type Node::GenericParam: {:?}" , x)
1438
- } ,
1391
+ x => bug ! ( "unexpected non-type Node::GenericParam: {:?}" , x) ,
1439
1392
} ,
1440
1393
1441
1394
x => {
1442
- if !fail {
1443
- return None ;
1444
- }
1445
1395
bug ! ( "unexpected sort of node in type_of_def_id(): {:?}" , x) ;
1446
1396
}
1447
- } )
1397
+ }
1448
1398
}
1449
1399
1450
1400
fn find_existential_constraints < ' a , ' tcx > (
0 commit comments