@@ -269,26 +269,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
269
269
self . lower_use_tree ( use_tree, & prefix, id, vis, ident, attrs)
270
270
}
271
271
ItemKind :: Static ( ref t, m, ref e) => {
272
- let ty = self . lower_ty (
273
- t,
274
- if self . sess . features_untracked ( ) . impl_trait_in_bindings {
275
- ImplTraitContext :: OpaqueTy ( None , hir:: OpaqueTyOrigin :: Misc )
276
- } else {
277
- ImplTraitContext :: Disallowed ( ImplTraitPosition :: Binding )
278
- } ,
279
- ) ;
280
- hir:: ItemKind :: Static ( ty, m, self . lower_const_body ( span, Some ( e) ) )
272
+ let ( ty, body_id) = self . lower_const_item ( t, span, e. as_deref ( ) ) ;
273
+ hir:: ItemKind :: Static ( ty, m, body_id)
281
274
}
282
275
ItemKind :: Const ( ref t, ref e) => {
283
- let ty = self . lower_ty (
284
- t,
285
- if self . sess . features_untracked ( ) . impl_trait_in_bindings {
286
- ImplTraitContext :: OpaqueTy ( None , hir:: OpaqueTyOrigin :: Misc )
287
- } else {
288
- ImplTraitContext :: Disallowed ( ImplTraitPosition :: Binding )
289
- } ,
290
- ) ;
291
- hir:: ItemKind :: Const ( ty, self . lower_const_body ( span, Some ( e) ) )
276
+ let ( ty, body_id) = self . lower_const_item ( t, span, e. as_deref ( ) ) ;
277
+ hir:: ItemKind :: Const ( ty, body_id)
292
278
}
293
279
ItemKind :: Fn ( FnSig { ref decl, header } , ref generics, ref body) => {
294
280
let fn_def_id = self . resolver . definitions ( ) . local_def_id ( id) ;
@@ -457,6 +443,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
457
443
// not cause an assertion failure inside the `lower_defaultness` function.
458
444
}
459
445
446
+ fn lower_const_item (
447
+ & mut self ,
448
+ ty : & Ty ,
449
+ span : Span ,
450
+ body : Option < & Expr > ,
451
+ ) -> ( & ' hir hir:: Ty < ' hir > , hir:: BodyId ) {
452
+ let itctx = if self . sess . features_untracked ( ) . impl_trait_in_bindings {
453
+ ImplTraitContext :: OpaqueTy ( None , hir:: OpaqueTyOrigin :: Misc )
454
+ } else {
455
+ ImplTraitContext :: Disallowed ( ImplTraitPosition :: Binding )
456
+ } ;
457
+ let ty = self . lower_ty ( ty, itctx) ;
458
+ ( ty, self . lower_const_body ( span, body) )
459
+ }
460
+
460
461
fn lower_use_tree (
461
462
& mut self ,
462
463
tree : & UseTree ,
@@ -678,11 +679,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
678
679
679
680
hir:: ForeignItemKind :: Fn ( fn_dec, fn_args, generics)
680
681
}
681
- ForeignItemKind :: Static ( ref t, m) => {
682
+ ForeignItemKind :: Static ( ref t, m, _ ) => {
682
683
let ty = self . lower_ty ( t, ImplTraitContext :: disallowed ( ) ) ;
683
684
hir:: ForeignItemKind :: Static ( ty, m)
684
685
}
685
- ForeignItemKind :: Ty => hir:: ForeignItemKind :: Type ,
686
+ ForeignItemKind :: Const ( ref t, _) => {
687
+ // For recovery purposes.
688
+ let ty = self . lower_ty ( t, ImplTraitContext :: disallowed ( ) ) ;
689
+ hir:: ForeignItemKind :: Static ( ty, Mutability :: Not )
690
+ }
691
+ ForeignItemKind :: TyAlias ( ..) => hir:: ForeignItemKind :: Type ,
686
692
ForeignItemKind :: Macro ( _) => panic ! ( "macro shouldn't exist here" ) ,
687
693
} ,
688
694
vis : self . lower_visibility ( & i. vis , None ) ,
@@ -759,32 +765,27 @@ impl<'hir> LoweringContext<'_, 'hir> {
759
765
let trait_item_def_id = self . resolver . definitions ( ) . local_def_id ( i. id ) ;
760
766
761
767
let ( generics, kind) = match i. kind {
762
- AssocItemKind :: Const ( ref ty, ref default) => {
763
- let generics = self . lower_generics ( & i . generics , ImplTraitContext :: disallowed ( ) ) ;
768
+ AssocItemKind :: Static ( ref ty, _ , ref default) // Let's pretend this is a `const`.
769
+ | AssocItemKind :: Const ( ref ty , ref default ) => {
764
770
let ty = self . lower_ty ( ty, ImplTraitContext :: disallowed ( ) ) ;
765
- (
766
- generics,
767
- hir:: TraitItemKind :: Const (
768
- ty,
769
- default. as_ref ( ) . map ( |x| self . lower_const_body ( i. span , Some ( x) ) ) ,
770
- ) ,
771
- )
771
+ let body = default. as_ref ( ) . map ( |x| self . lower_const_body ( i. span , Some ( x) ) ) ;
772
+ ( hir:: Generics :: empty ( ) , hir:: TraitItemKind :: Const ( ty, body) )
772
773
}
773
- AssocItemKind :: Fn ( ref sig, None ) => {
774
+ AssocItemKind :: Fn ( ref sig, ref generics , None ) => {
774
775
let names = self . lower_fn_params_to_names ( & sig. decl ) ;
775
776
let ( generics, sig) =
776
- self . lower_method_sig ( & i . generics , sig, trait_item_def_id, false , None ) ;
777
+ self . lower_method_sig ( generics, sig, trait_item_def_id, false , None ) ;
777
778
( generics, hir:: TraitItemKind :: Method ( sig, hir:: TraitMethod :: Required ( names) ) )
778
779
}
779
- AssocItemKind :: Fn ( ref sig, Some ( ref body) ) => {
780
+ AssocItemKind :: Fn ( ref sig, ref generics , Some ( ref body) ) => {
780
781
let body_id = self . lower_fn_body_block ( i. span , & sig. decl , Some ( body) ) ;
781
782
let ( generics, sig) =
782
- self . lower_method_sig ( & i . generics , sig, trait_item_def_id, false , None ) ;
783
+ self . lower_method_sig ( generics, sig, trait_item_def_id, false , None ) ;
783
784
( generics, hir:: TraitItemKind :: Method ( sig, hir:: TraitMethod :: Provided ( body_id) ) )
784
785
}
785
- AssocItemKind :: TyAlias ( ref bounds, ref default) => {
786
+ AssocItemKind :: TyAlias ( ref generics , ref bounds, ref default) => {
786
787
let ty = default. as_ref ( ) . map ( |x| self . lower_ty ( x, ImplTraitContext :: disallowed ( ) ) ) ;
787
- let generics = self . lower_generics ( & i . generics , ImplTraitContext :: disallowed ( ) ) ;
788
+ let generics = self . lower_generics ( generics, ImplTraitContext :: disallowed ( ) ) ;
788
789
let kind = hir:: TraitItemKind :: Type (
789
790
self . lower_param_bounds ( bounds, ImplTraitContext :: disallowed ( ) ) ,
790
791
ty,
@@ -806,10 +807,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
806
807
}
807
808
808
809
fn lower_trait_item_ref ( & mut self , i : & AssocItem ) -> hir:: TraitItemRef {
809
- let ( kind, has_default) = match i. kind {
810
- AssocItemKind :: Const ( _, ref default) => ( hir:: AssocItemKind :: Const , default. is_some ( ) ) ,
811
- AssocItemKind :: TyAlias ( _, ref default) => ( hir:: AssocItemKind :: Type , default. is_some ( ) ) ,
812
- AssocItemKind :: Fn ( ref sig, ref default) => {
810
+ let ( kind, has_default) = match & i. kind {
811
+ AssocItemKind :: Static ( _, _, default) // Let's pretend this is a `const` for recovery.
812
+ | AssocItemKind :: Const ( _, default) => {
813
+ ( hir:: AssocItemKind :: Const , default. is_some ( ) )
814
+ }
815
+ AssocItemKind :: TyAlias ( _, _, default) => ( hir:: AssocItemKind :: Type , default. is_some ( ) ) ,
816
+ AssocItemKind :: Fn ( sig, _, default) => {
813
817
( hir:: AssocItemKind :: Method { has_self : sig. decl . has_self ( ) } , default. is_some ( ) )
814
818
}
815
819
AssocItemKind :: Macro ( ..) => unimplemented ! ( ) ,
@@ -832,22 +836,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
832
836
let impl_item_def_id = self . resolver . definitions ( ) . local_def_id ( i. id ) ;
833
837
834
838
let ( generics, kind) = match i. kind {
835
- AssocItemKind :: Const ( ref ty, ref expr) => {
836
- let generics = self . lower_generics ( & i. generics , ImplTraitContext :: disallowed ( ) ) ;
839
+ AssocItemKind :: Static ( ref ty, _, ref expr) | AssocItemKind :: Const ( ref ty, ref expr) => {
837
840
let ty = self . lower_ty ( ty, ImplTraitContext :: disallowed ( ) ) ;
838
841
(
839
- generics ,
842
+ hir :: Generics :: empty ( ) ,
840
843
hir:: ImplItemKind :: Const ( ty, self . lower_const_body ( i. span , expr. as_deref ( ) ) ) ,
841
844
)
842
845
}
843
- AssocItemKind :: Fn ( ref sig, ref body) => {
846
+ AssocItemKind :: Fn ( ref sig, ref generics , ref body) => {
844
847
self . current_item = Some ( i. span ) ;
845
848
let asyncness = sig. header . asyncness ;
846
849
let body_id =
847
850
self . lower_maybe_async_body ( i. span , & sig. decl , asyncness, body. as_deref ( ) ) ;
848
851
let impl_trait_return_allow = !self . is_in_trait_impl ;
849
852
let ( generics, sig) = self . lower_method_sig (
850
- & i . generics ,
853
+ generics,
851
854
sig,
852
855
impl_item_def_id,
853
856
impl_trait_return_allow,
@@ -856,8 +859,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
856
859
857
860
( generics, hir:: ImplItemKind :: Method ( sig, body_id) )
858
861
}
859
- AssocItemKind :: TyAlias ( _, ref ty) => {
860
- let generics = self . lower_generics ( & i . generics , ImplTraitContext :: disallowed ( ) ) ;
862
+ AssocItemKind :: TyAlias ( ref generics , _, ref ty) => {
863
+ let generics = self . lower_generics ( generics, ImplTraitContext :: disallowed ( ) ) ;
861
864
let kind = match ty {
862
865
None => {
863
866
let ty = self . arena . alloc ( self . ty ( i. span , hir:: TyKind :: Err ) ) ;
@@ -901,14 +904,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
901
904
vis : self . lower_visibility ( & i. vis , Some ( i. id ) ) ,
902
905
defaultness : self . lower_defaultness ( i. defaultness , true /* [1] */ ) ,
903
906
kind : match & i. kind {
904
- AssocItemKind :: Const ( ..) => hir:: AssocItemKind :: Const ,
905
- AssocItemKind :: TyAlias ( _, ty) => {
907
+ AssocItemKind :: Static ( ..) // Let's pretend this is a `const` for recovery.
908
+ | AssocItemKind :: Const ( ..) => hir:: AssocItemKind :: Const ,
909
+ AssocItemKind :: TyAlias ( _, _, ty) => {
906
910
match ty. as_deref ( ) . and_then ( |ty| ty. kind . opaque_top_hack ( ) ) {
907
911
None => hir:: AssocItemKind :: Type ,
908
912
Some ( _) => hir:: AssocItemKind :: OpaqueTy ,
909
913
}
910
914
}
911
- AssocItemKind :: Fn ( sig, _) => {
915
+ AssocItemKind :: Fn ( sig, _, _ ) => {
912
916
hir:: AssocItemKind :: Method { has_self : sig. decl . has_self ( ) }
913
917
}
914
918
AssocItemKind :: Macro ( ..) => unimplemented ! ( ) ,
0 commit comments