@@ -27,11 +27,17 @@ struct BoundModifiers {
2727}
2828
2929impl BoundModifiers {
30- fn trait_bound_modifier ( & self ) -> TraitBoundModifier {
31- match self . maybe {
32- Some ( _) => TraitBoundModifier :: Maybe ,
33- None => TraitBoundModifier :: None ,
34- }
30+ fn to_trait_bound_modifier ( & self ) -> Result < TraitBoundModifier , & ' static str > {
31+ let modifier = match ( self . maybe , self . maybe_const ) {
32+ ( None , None ) => TraitBoundModifier :: None ,
33+ ( Some ( _) , None ) => TraitBoundModifier :: Maybe ,
34+ ( None , Some ( _) ) => TraitBoundModifier :: MaybeConst ,
35+ ( Some ( _) , Some ( _) ) => {
36+ return Err ( "`?const` and `?` are mutually exclusive" ) ;
37+ }
38+ } ;
39+
40+ Ok ( modifier)
3541 }
3642}
3743
@@ -215,7 +221,7 @@ impl<'a> Parser<'a> {
215221 ) -> PResult < ' a , TyKind > {
216222 assert_ne ! ( self . token, token:: Question ) ;
217223
218- let poly_trait_ref = PolyTraitRef :: new ( generic_params, path, None , lo. to ( self . prev_span ) ) ;
224+ let poly_trait_ref = PolyTraitRef :: new ( generic_params, path, lo. to ( self . prev_span ) ) ;
219225 let mut bounds = vec ! [ GenericBound :: Trait ( poly_trait_ref, TraitBoundModifier :: None ) ] ;
220226 if parse_plus {
221227 self . eat_plus ( ) ; // `+`, or `+=` gets split and `+` is discarded
@@ -557,9 +563,18 @@ impl<'a> Parser<'a> {
557563 self . expect ( & token:: CloseDelim ( token:: Paren ) ) ?;
558564 }
559565
560- let constness = modifiers. maybe_const . map ( |_| ast:: Constness :: NotConst ) ;
561- let poly_trait = PolyTraitRef :: new ( lifetime_defs, path, constness, lo. to ( self . prev_span ) ) ;
562- Ok ( GenericBound :: Trait ( poly_trait, modifiers. trait_bound_modifier ( ) ) )
566+ let modifier = match modifiers. to_trait_bound_modifier ( ) {
567+ Ok ( m) => m,
568+ Err ( msg) => {
569+ self . struct_span_err ( lo. to ( self . prev_span ) , msg) . emit ( ) ;
570+
571+ // Continue compilation as if the user had written `?Trait`.
572+ TraitBoundModifier :: Maybe
573+ }
574+ } ;
575+
576+ let poly_trait = PolyTraitRef :: new ( lifetime_defs, path, lo. to ( self . prev_span ) ) ;
577+ Ok ( GenericBound :: Trait ( poly_trait, modifier) )
563578 }
564579
565580 /// Optionally parses `for<$generic_params>`.
0 commit comments