@@ -13,17 +13,11 @@ pub(super) fn inferred_outlives_of(
1313 item_def_id : LocalDefId ,
1414) -> & [ ( ty:: Clause < ' _ > , Span ) ] {
1515 match tcx. def_kind ( item_def_id) {
16- DefKind :: Struct | DefKind :: Enum | DefKind :: Union => {
17- let crate_map = tcx. inferred_outlives_crate ( ( ) ) ;
18- crate_map. predicates . get ( & item_def_id. to_def_id ( ) ) . copied ( ) . unwrap_or ( & [ ] )
19- }
20- DefKind :: TyAlias if tcx. type_alias_is_lazy ( item_def_id) => {
21- let crate_map = tcx. inferred_outlives_crate ( ( ) ) ;
22- crate_map. predicates . get ( & item_def_id. to_def_id ( ) ) . copied ( ) . unwrap_or ( & [ ] )
23- }
16+ DefKind :: Struct | DefKind :: Enum | DefKind :: Union | DefKind :: Const => { }
17+ DefKind :: TyAlias if tcx. type_alias_is_lazy ( item_def_id) => { }
2418 DefKind :: AnonConst if tcx. features ( ) . generic_const_exprs ( ) => {
2519 let id = tcx. local_def_id_to_hir_id ( item_def_id) ;
26- if tcx. hir_opt_const_param_default_param_def_id ( id) . is_some ( ) {
20+ return if tcx. hir_opt_const_param_default_param_def_id ( id) . is_some ( ) {
2721 // In `generics_of` we set the generics' parent to be our parent's parent which means that
2822 // we lose out on the predicates of our actual parent if we dont return those predicates here.
2923 // (See comment in `generics_of` for more information on why the parent shenanigans is necessary)
@@ -40,21 +34,23 @@ pub(super) fn inferred_outlives_of(
4034 tcx. inferred_outlives_of ( item_def_id)
4135 } else {
4236 & [ ]
43- }
37+ } ;
4438 }
45- _ => & [ ] ,
39+ _ => return & [ ] ,
40+ }
41+
42+ if tcx. generics_of ( item_def_id) . is_empty ( ) {
43+ // Fast path.
44+ return & [ ] ;
4645 }
46+
47+ let crate_map = tcx. inferred_outlives_crate ( ( ) ) ;
48+ crate_map. predicates . get ( & item_def_id. to_def_id ( ) ) . copied ( ) . unwrap_or ( & [ ] )
4749}
4850
51+ /// Compute a map from each applicable item in the local crate to its
52+ /// inferred / implied outlives-predicates.
4953pub ( super ) fn inferred_outlives_crate ( tcx : TyCtxt < ' _ > , ( ) : ( ) ) -> CratePredicatesMap < ' _ > {
50- // Compute a map from each ADT (struct/enum/union) and lazy type alias to
51- // the **explicit** outlives predicates (`T: 'a`, `'a: 'b`) that the user wrote.
52- // Typically there won't be many of these, except in older code where
53- // they were mandatory. Nonetheless, we have to ensure that every such
54- // predicate is satisfied, so they form a kind of base set of requirements
55- // for the type.
56-
57- // Compute the inferred predicates
5854 let global_inferred_outlives = implicit_infer:: infer_predicates ( tcx) ;
5955
6056 // Convert the inferred predicates into the "collected" form the
0 commit comments