@@ -340,13 +340,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
340
340
) ;
341
341
hir:: ItemKind :: Union ( ident, generics, vdata)
342
342
}
343
- ItemKind :: Impl ( box Impl {
344
- safety,
345
- polarity,
346
- defaultness,
347
- constness,
343
+ ItemKind :: Impl ( Impl {
348
344
generics : ast_generics,
349
- of_trait : trait_ref ,
345
+ of_trait,
350
346
self_ty : ty,
351
347
items : impl_items,
352
348
} ) => {
@@ -364,54 +360,30 @@ impl<'hir> LoweringContext<'_, 'hir> {
364
360
// lifetime to be added, but rather a reference to a
365
361
// parent lifetime.
366
362
let itctx = ImplTraitContext :: Universal ;
367
- let ( generics, ( trait_ref , lowered_ty) ) =
363
+ let ( generics, ( of_trait , lowered_ty) ) =
368
364
self . lower_generics ( ast_generics, id, itctx, |this| {
369
- let modifiers = TraitBoundModifiers {
370
- constness : BoundConstness :: Never ,
371
- asyncness : BoundAsyncness :: Normal ,
372
- // we don't use this in bound lowering
373
- polarity : BoundPolarity :: Positive ,
374
- } ;
375
-
376
- let trait_ref = trait_ref. as_ref ( ) . map ( |trait_ref| {
377
- this. lower_trait_ref (
378
- modifiers,
379
- trait_ref,
380
- ImplTraitContext :: Disallowed ( ImplTraitPosition :: Trait ) ,
381
- )
382
- } ) ;
365
+ let of_trait = of_trait
366
+ . as_deref ( )
367
+ . map ( |of_trait| this. lower_trait_impl_header ( of_trait) ) ;
383
368
384
369
let lowered_ty = this. lower_ty (
385
370
ty,
386
371
ImplTraitContext :: Disallowed ( ImplTraitPosition :: ImplSelf ) ,
387
372
) ;
388
373
389
- ( trait_ref , lowered_ty)
374
+ ( of_trait , lowered_ty)
390
375
} ) ;
391
376
392
377
let new_impl_items = self
393
378
. arena
394
379
. alloc_from_iter ( impl_items. iter ( ) . map ( |item| self . lower_impl_item_ref ( item) ) ) ;
395
380
396
- // `defaultness.has_value()` is never called for an `impl`, always `true` in order
397
- // to not cause an assertion failure inside the `lower_defaultness` function.
398
- let has_val = true ;
399
- let ( defaultness, defaultness_span) = self . lower_defaultness ( * defaultness, has_val) ;
400
- let polarity = match polarity {
401
- ImplPolarity :: Positive => ImplPolarity :: Positive ,
402
- ImplPolarity :: Negative ( s) => ImplPolarity :: Negative ( self . lower_span ( * s) ) ,
403
- } ;
404
- hir:: ItemKind :: Impl ( self . arena . alloc ( hir:: Impl {
405
- constness : self . lower_constness ( * constness) ,
406
- safety : self . lower_safety ( * safety, hir:: Safety :: Safe ) ,
407
- polarity,
408
- defaultness,
409
- defaultness_span,
381
+ hir:: ItemKind :: Impl ( hir:: Impl {
410
382
generics,
411
- of_trait : trait_ref ,
383
+ of_trait,
412
384
self_ty : lowered_ty,
413
385
items : new_impl_items,
414
- } ) )
386
+ } )
415
387
}
416
388
ItemKind :: Trait ( box Trait {
417
389
constness,
@@ -982,6 +954,44 @@ impl<'hir> LoweringContext<'_, 'hir> {
982
954
self . expr ( span, hir:: ExprKind :: Err ( guar) )
983
955
}
984
956
957
+ fn lower_trait_impl_header (
958
+ & mut self ,
959
+ trait_impl_header : & TraitImplHeader ,
960
+ ) -> & ' hir hir:: TraitImplHeader < ' hir > {
961
+ let TraitImplHeader { constness, safety, polarity, defaultness, ref trait_ref } =
962
+ * trait_impl_header;
963
+ let constness = self . lower_constness ( constness) ;
964
+ let safety = self . lower_safety ( safety, hir:: Safety :: Safe ) ;
965
+ let polarity = match polarity {
966
+ ImplPolarity :: Positive => ImplPolarity :: Positive ,
967
+ ImplPolarity :: Negative ( s) => ImplPolarity :: Negative ( self . lower_span ( s) ) ,
968
+ } ;
969
+ // `defaultness.has_value()` is never called for an `impl`, always `true` in order
970
+ // to not cause an assertion failure inside the `lower_defaultness` function.
971
+ let has_val = true ;
972
+ let ( defaultness, defaultness_span) = self . lower_defaultness ( defaultness, has_val) ;
973
+ let modifiers = TraitBoundModifiers {
974
+ constness : BoundConstness :: Never ,
975
+ asyncness : BoundAsyncness :: Normal ,
976
+ // we don't use this in bound lowering
977
+ polarity : BoundPolarity :: Positive ,
978
+ } ;
979
+ let trait_ref = self . lower_trait_ref (
980
+ modifiers,
981
+ trait_ref,
982
+ ImplTraitContext :: Disallowed ( ImplTraitPosition :: Trait ) ,
983
+ ) ;
984
+
985
+ self . arena . alloc ( hir:: TraitImplHeader {
986
+ constness,
987
+ safety,
988
+ polarity,
989
+ defaultness,
990
+ defaultness_span,
991
+ trait_ref,
992
+ } )
993
+ }
994
+
985
995
fn lower_impl_item (
986
996
& mut self ,
987
997
i : & AssocItem ,
0 commit comments