@@ -1142,10 +1142,6 @@ fn report_assoc_ty_on_inherent_impl(tcx: TyCtxt<'_>, span: Span) {
11421142 ) ;
11431143}
11441144
1145- fn type_of ( tcx : TyCtxt < ' _ > , def_id : DefId ) -> Ty < ' _ > {
1146- checked_type_of ( tcx, def_id, true ) . unwrap ( )
1147- }
1148-
11491145fn infer_placeholder_type (
11501146 tcx : TyCtxt < ' _ > ,
11511147 def_id : DefId ,
@@ -1189,26 +1185,14 @@ fn infer_placeholder_type(
11891185 ty
11901186}
11911187
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 < ' _ > {
11971189 use rustc:: hir:: * ;
11981190
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 ( ) ;
12081192
12091193 let icx = ItemCtxt :: new ( tcx, def_id) ;
12101194
1211- Some ( match tcx. hir ( ) . get ( hir_id) {
1195+ match tcx. hir ( ) . get ( hir_id) {
12121196 Node :: TraitItem ( item) => match item. kind {
12131197 TraitItemKind :: Method ( ..) => {
12141198 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<
12251209 } ,
12261210 TraitItemKind :: Type ( _, Some ( ref ty) ) => icx. to_ty ( ty) ,
12271211 TraitItemKind :: Type ( _, None ) => {
1228- if !fail {
1229- return None ;
1230- }
12311212 span_bug ! ( item. span, "associated type missing default" ) ;
12321213 }
12331214 } ,
@@ -1321,9 +1302,6 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
13211302 | ItemKind :: GlobalAsm ( ..)
13221303 | ItemKind :: ExternCrate ( ..)
13231304 | ItemKind :: Use ( ..) => {
1324- if !fail {
1325- return None ;
1326- }
13271305 span_bug ! (
13281306 item. span,
13291307 "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<
13611339 ..
13621340 } ) => {
13631341 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) ;
13651343 }
13661344
13671345 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<
14361414 . map ( |( index, _) | index)
14371415 . next ( )
14381416 } )
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+ } ) ;
14461420
14471421 // We've encountered an `AnonConst` in some path, so we need to
14481422 // 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<
14521426 tcx. generics_of ( tcx. parent ( def_id) . unwrap ( ) )
14531427 }
14541428 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 ,
14571430 res => {
14581431 tcx. sess . delay_span_bug (
14591432 DUMMY_SP ,
@@ -1462,7 +1435,7 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
14621435 res,
14631436 ) ,
14641437 ) ;
1465- return Some ( tcx. types . err ) ;
1438+ return tcx. types . err ;
14661439 }
14671440 } ;
14681441
@@ -1480,24 +1453,18 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
14801453 // probably from an extra arg where one is not needed.
14811454 . unwrap_or ( tcx. types . err )
14821455 } else {
1483- if !fail {
1484- return None ;
1485- }
14861456 tcx. sess . delay_span_bug (
14871457 DUMMY_SP ,
14881458 & format ! (
14891459 "unexpected const parent path {:?}" ,
14901460 parent_node,
14911461 ) ,
14921462 ) ;
1493- return Some ( tcx. types . err ) ;
1463+ return tcx. types . err ;
14941464 }
14951465 }
14961466
14971467 x => {
1498- if !fail {
1499- return None ;
1500- }
15011468 tcx. sess . delay_span_bug (
15021469 DUMMY_SP ,
15031470 & format ! (
@@ -1547,21 +1514,13 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
15471514 }
15481515 ty
15491516 }
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) ,
15561518 } ,
15571519
15581520 x => {
1559- if !fail {
1560- return None ;
1561- }
15621521 bug ! ( "unexpected sort of node in type_of_def_id(): {:?}" , x) ;
15631522 }
1564- } )
1523+ }
15651524}
15661525
15671526fn find_opaque_ty_constraints ( tcx : TyCtxt < ' _ > , def_id : DefId ) -> Ty < ' _ > {
0 commit comments