1- use hir:: Node ;
2- use rustc_hir as hir;
1+ use rustc_hir:: def:: DefKind ;
32use rustc_hir:: def_id:: LocalDefId ;
43use rustc_middle:: query:: Providers ;
54use rustc_middle:: ty:: GenericArgKind ;
@@ -17,45 +16,32 @@ pub fn provide(providers: &mut Providers) {
1716}
1817
1918fn inferred_outlives_of ( tcx : TyCtxt < ' _ > , item_def_id : LocalDefId ) -> & [ ( ty:: Clause < ' _ > , Span ) ] {
20- let id = tcx. local_def_id_to_hir_id ( item_def_id) ;
21-
22- if matches ! ( tcx. def_kind( item_def_id) , hir:: def:: DefKind :: AnonConst )
23- && tcx. features ( ) . generic_const_exprs
24- {
25- if tcx. hir ( ) . opt_const_param_default_param_def_id ( id) . is_some ( ) {
26- // In `generics_of` we set the generics' parent to be our parent's parent which means that
27- // we lose out on the predicates of our actual parent if we dont return those predicates here.
28- // (See comment in `generics_of` for more information on why the parent shenanigans is necessary)
29- //
30- // struct Foo<'a, 'b, const N: usize = { ... }>(&'a &'b ());
31- // ^^^ ^^^^^^^ the def id we are calling
32- // ^^^ inferred_outlives_of on
33- // parent item we dont have set as the
34- // parent of generics returned by `generics_of`
35- //
36- // In the above code we want the anon const to have predicates in its param env for `'b: 'a`
37- let item_def_id = tcx. hir ( ) . get_parent_item ( id) ;
38- // In the above code example we would be calling `inferred_outlives_of(Foo)` here
39- return tcx. inferred_outlives_of ( item_def_id) ;
19+ match tcx. def_kind ( item_def_id) {
20+ DefKind :: Struct | DefKind :: Enum | DefKind :: Union => {
21+ let crate_map = tcx. inferred_outlives_crate ( ( ) ) ;
22+ crate_map. predicates . get ( & item_def_id. to_def_id ( ) ) . copied ( ) . unwrap_or ( & [ ] )
4023 }
41- }
42-
43- match tcx. hir_node ( id) {
44- Node :: Item ( item) => match item. kind {
45- hir:: ItemKind :: Struct ( ..) | hir:: ItemKind :: Enum ( ..) | hir:: ItemKind :: Union ( ..) => {
46- let crate_map = tcx. inferred_outlives_crate ( ( ) ) ;
47-
48- let predicates =
49- crate_map. predicates . get ( & item_def_id. to_def_id ( ) ) . copied ( ) . unwrap_or ( & [ ] ) ;
50-
51- debug ! ( "inferred_outlives_of({:?}) = {:?}" , item_def_id, predicates) ;
52-
53- predicates
24+ DefKind :: AnonConst if tcx. features ( ) . generic_const_exprs => {
25+ 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 ( ) {
27+ // In `generics_of` we set the generics' parent to be our parent's parent which means that
28+ // we lose out on the predicates of our actual parent if we dont return those predicates here.
29+ // (See comment in `generics_of` for more information on why the parent shenanigans is necessary)
30+ //
31+ // struct Foo<'a, 'b, const N: usize = { ... }>(&'a &'b ());
32+ // ^^^ ^^^^^^^ the def id we are calling
33+ // ^^^ inferred_outlives_of on
34+ // parent item we dont have set as the
35+ // parent of generics returned by `generics_of`
36+ //
37+ // In the above code we want the anon const to have predicates in its param env for `'b: 'a`
38+ let item_def_id = tcx. hir ( ) . get_parent_item ( id) ;
39+ // In the above code example we would be calling `inferred_outlives_of(Foo)` here
40+ tcx. inferred_outlives_of ( item_def_id)
41+ } else {
42+ & [ ]
5443 }
55-
56- _ => & [ ] ,
57- } ,
58-
44+ }
5945 _ => & [ ] ,
6046 }
6147}
0 commit comments