@@ -1134,43 +1134,20 @@ fn report_assoc_ty_on_inherent_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, span:
11341134}
11351135
11361136fn 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 > > {
11491137 use rustc:: hir:: * ;
11501138
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 ( ) ;
11601140
11611141 let icx = ItemCtxt :: new ( tcx, def_id) ;
11621142
1163- Some ( match tcx. hir ( ) . get_by_hir_id ( hir_id) {
1143+ match tcx. hir ( ) . get_by_hir_id ( hir_id) {
11641144 Node :: TraitItem ( item) => match item. node {
11651145 TraitItemKind :: Method ( ..) => {
11661146 let substs = InternalSubsts :: identity_for_item ( tcx, def_id) ;
11671147 tcx. mk_fn_def ( def_id, substs)
11681148 }
11691149 TraitItemKind :: Const ( ref ty, _) | TraitItemKind :: Type ( _, Some ( ref ty) ) => icx. to_ty ( ty) ,
11701150 TraitItemKind :: Type ( _, None ) => {
1171- if !fail {
1172- return None ;
1173- }
11741151 span_bug ! ( item. span, "associated type missing default" ) ;
11751152 }
11761153 } ,
@@ -1252,9 +1229,6 @@ pub fn checked_type_of<'a, 'tcx>(
12521229 | ItemKind :: GlobalAsm ( ..)
12531230 | ItemKind :: ExternCrate ( ..)
12541231 | ItemKind :: Use ( ..) => {
1255- if !fail {
1256- return None ;
1257- }
12581232 span_bug ! (
12591233 item. span,
12601234 "compute_type_of_item: unexpected item type: {:?}" ,
@@ -1293,7 +1267,7 @@ pub fn checked_type_of<'a, 'tcx>(
12931267 ..
12941268 } ) => {
12951269 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) ;
12971271 }
12981272
12991273 let substs = ty:: ClosureSubsts {
@@ -1371,9 +1345,6 @@ pub fn checked_type_of<'a, 'tcx>(
13711345 }
13721346 // Sanity check to make sure everything is as expected.
13731347 if !found_const {
1374- if !fail {
1375- return None ;
1376- }
13771348 bug ! ( "no arg matching AnonConst in path" )
13781349 }
13791350 match path. def {
@@ -1389,37 +1360,24 @@ pub fn checked_type_of<'a, 'tcx>(
13891360 for param in & generics. params {
13901361 if let ty:: GenericParamDefKind :: Const = param. kind {
13911362 if param_index == arg_index {
1392- return Some ( tcx. type_of ( param. def_id ) ) ;
1363+ return tcx. type_of ( param. def_id ) ;
13931364 }
13941365 param_index += 1 ;
13951366 }
13961367 }
13971368 // This is no generic parameter associated with the arg. This is
13981369 // probably from an extra arg where one is not needed.
1399- return Some ( tcx. types . err ) ;
1370+ return tcx. types . err ;
14001371 }
14011372 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) ,
14131374 }
1414- bug ! ( "unexpected const parent path {:?}" , x) ;
14151375 }
1376+ x => bug ! ( "unexpected const parent path {:?}" , x) ,
14161377 }
14171378 }
14181379
14191380 x => {
1420- if !fail {
1421- return None ;
1422- }
14231381 bug ! ( "unexpected const parent in type_of_def_id(): {:?}" , x) ;
14241382 }
14251383 }
@@ -1430,21 +1388,13 @@ pub fn checked_type_of<'a, 'tcx>(
14301388 hir:: GenericParamKind :: Const { ref ty, .. } => {
14311389 icx. to_ty ( ty)
14321390 }
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) ,
14391392 } ,
14401393
14411394 x => {
1442- if !fail {
1443- return None ;
1444- }
14451395 bug ! ( "unexpected sort of node in type_of_def_id(): {:?}" , x) ;
14461396 }
1447- } )
1397+ }
14481398}
14491399
14501400fn find_existential_constraints < ' a , ' tcx > (
0 commit comments