@@ -215,6 +215,9 @@ pub struct TraitDef<'a> {
215
215
/// Is it an `unsafe` trait?
216
216
pub is_unsafe : bool ,
217
217
218
+ /// Is it a `const` impl?
219
+ pub is_const : bool ,
220
+
218
221
/// Can this trait be derived for unions?
219
222
pub supports_unions : bool ,
220
223
@@ -568,7 +571,7 @@ impl<'a> TraitDef<'a> {
568
571
} ) ;
569
572
570
573
let Generics { mut params, mut where_clause, .. } =
571
- self . generics . to_generics ( cx, self . span , type_ident, generics) ;
574
+ self . generics . to_generics ( cx, self . span , type_ident, generics, self . is_const ) ;
572
575
where_clause. span = generics. where_clause . span ;
573
576
let ctxt = self . span . ctxt ( ) ;
574
577
let span = generics. span . with_ctxt ( ctxt) ;
@@ -583,10 +586,24 @@ impl<'a> TraitDef<'a> {
583
586
// extra restrictions on the generics parameters to the
584
587
// type being derived upon
585
588
self . additional_bounds . iter ( ) . map ( |p| {
586
- cx. trait_bound ( p. to_path ( cx, self . span , type_ident, generics) )
589
+ cx. trait_bound (
590
+ p. to_path ( cx, self . span , type_ident, generics) ,
591
+ if self . is_const {
592
+ ast:: TraitBoundModifier :: MaybeConst
593
+ } else {
594
+ ast:: TraitBoundModifier :: None
595
+ } ,
596
+ )
587
597
} ) . chain (
588
598
// require the current trait
589
- iter:: once ( cx. trait_bound ( trait_path. clone ( ) ) )
599
+ iter:: once ( cx. trait_bound (
600
+ trait_path. clone ( ) ,
601
+ if self . is_const {
602
+ ast:: TraitBoundModifier :: MaybeConst
603
+ } else {
604
+ ast:: TraitBoundModifier :: None
605
+ }
606
+ ) )
590
607
) . chain (
591
608
// also add in any bounds from the declaration
592
609
param. bounds . iter ( ) . cloned ( )
@@ -663,11 +680,27 @@ impl<'a> TraitDef<'a> {
663
680
let mut bounds: Vec < _ > = self
664
681
. additional_bounds
665
682
. iter ( )
666
- . map ( |p| cx. trait_bound ( p. to_path ( cx, self . span , type_ident, generics) ) )
683
+ . map ( |p| {
684
+ cx. trait_bound (
685
+ p. to_path ( cx, self . span , type_ident, generics) ,
686
+ if self . is_const {
687
+ ast:: TraitBoundModifier :: MaybeConst
688
+ } else {
689
+ ast:: TraitBoundModifier :: None
690
+ } ,
691
+ )
692
+ } )
667
693
. collect ( ) ;
668
694
669
695
// require the current trait
670
- bounds. push ( cx. trait_bound ( trait_path. clone ( ) ) ) ;
696
+ bounds. push ( cx. trait_bound (
697
+ trait_path. clone ( ) ,
698
+ if self . is_const {
699
+ ast:: TraitBoundModifier :: MaybeConst
700
+ } else {
701
+ ast:: TraitBoundModifier :: None
702
+ } ,
703
+ ) ) ;
671
704
672
705
let predicate = ast:: WhereBoundPredicate {
673
706
span : self . span ,
@@ -723,6 +756,7 @@ impl<'a> TraitDef<'a> {
723
756
a. extend ( self . attributes . iter ( ) . cloned ( ) ) ;
724
757
725
758
let unsafety = if self . is_unsafe { ast:: Unsafe :: Yes ( self . span ) } else { ast:: Unsafe :: No } ;
759
+ let constness = if self . is_const { ast:: Const :: Yes ( self . span ) } else { ast:: Const :: No } ;
726
760
727
761
cx. item (
728
762
self . span ,
@@ -732,7 +766,7 @@ impl<'a> TraitDef<'a> {
732
766
unsafety,
733
767
polarity : ast:: ImplPolarity :: Positive ,
734
768
defaultness : ast:: Defaultness :: Final ,
735
- constness : ast :: Const :: No ,
769
+ constness,
736
770
generics : trait_generics,
737
771
of_trait : opt_trait_ref,
738
772
self_ty : self_type,
@@ -933,7 +967,8 @@ impl<'a> MethodDef<'a> {
933
967
) -> P < ast:: AssocItem > {
934
968
let span = trait_. span ;
935
969
// Create the generics that aren't for `Self`.
936
- let fn_generics = self . generics . to_generics ( cx, span, type_ident, generics) ;
970
+ let fn_generics =
971
+ self . generics . to_generics ( cx, span, type_ident, generics, trait_. is_const ) ;
937
972
938
973
let args = {
939
974
let self_args = explicit_self. map ( |explicit_self| {
0 commit comments