@@ -286,41 +286,16 @@ impl ParenthesizedArgs {
286286
287287pub use crate :: node_id:: { NodeId , CRATE_NODE_ID , DUMMY_NODE_ID } ;
288288
289- /// A modifier on a bound, e.g., `?Trait` or `~const Trait`.
290- ///
291- /// Negative bounds should also be handled here.
289+ /// Modifiers on a trait bound like `~const`, `?` and `!`.
292290#[ derive( Copy , Clone , PartialEq , Eq , Encodable , Decodable , Debug ) ]
293- pub enum TraitBoundModifier {
294- /// No modifiers
295- None ,
296-
297- /// `!Trait`
298- Negative ,
299-
300- /// `?Trait`
301- Maybe ,
302-
303- /// `~const Trait`
304- MaybeConst ( Span ) ,
305-
306- /// `~const !Trait`
307- //
308- // This parses but will be rejected during AST validation.
309- MaybeConstNegative ,
310-
311- /// `~const ?Trait`
312- //
313- // This parses but will be rejected during AST validation.
314- MaybeConstMaybe ,
291+ pub struct TraitBoundModifiers {
292+ pub constness : BoundConstness ,
293+ pub polarity : BoundPolarity ,
315294}
316295
317- impl TraitBoundModifier {
318- pub fn to_constness ( self ) -> Const {
319- match self {
320- Self :: MaybeConst ( span) => Const :: Yes ( span) ,
321- _ => Const :: No ,
322- }
323- }
296+ impl TraitBoundModifiers {
297+ pub const NONE : Self =
298+ Self { constness : BoundConstness :: Never , polarity : BoundPolarity :: Positive } ;
324299}
325300
326301/// The AST represents all type param bounds as types.
@@ -329,7 +304,7 @@ impl TraitBoundModifier {
329304/// detects `Copy`, `Send` and `Sync`.
330305#[ derive( Clone , Encodable , Decodable , Debug ) ]
331306pub enum GenericBound {
332- Trait ( PolyTraitRef , TraitBoundModifier ) ,
307+ Trait ( PolyTraitRef , TraitBoundModifiers ) ,
333308 Outlives ( Lifetime ) ,
334309}
335310
@@ -1193,7 +1168,7 @@ impl Expr {
11931168 match & self . kind {
11941169 ExprKind :: Path ( None , path) => Some ( GenericBound :: Trait (
11951170 PolyTraitRef :: new ( ThinVec :: new ( ) , path. clone ( ) , self . span ) ,
1196- TraitBoundModifier :: None ,
1171+ TraitBoundModifiers :: NONE ,
11971172 ) ) ,
11981173 _ => None ,
11991174 }
@@ -2491,6 +2466,15 @@ pub enum Const {
24912466 No ,
24922467}
24932468
2469+ impl From < BoundConstness > for Const {
2470+ fn from ( constness : BoundConstness ) -> Self {
2471+ match constness {
2472+ BoundConstness :: Maybe ( span) => Self :: Yes ( span) ,
2473+ BoundConstness :: Never => Self :: No ,
2474+ }
2475+ }
2476+ }
2477+
24942478/// Item defaultness.
24952479/// For details see the [RFC #2532](https://github.com/rust-lang/rfcs/pull/2532).
24962480#[ derive( Copy , Clone , PartialEq , Encodable , Decodable , Debug , HashStable_Generic ) ]
@@ -2516,7 +2500,9 @@ impl fmt::Debug for ImplPolarity {
25162500 }
25172501}
25182502
2519- #[ derive( Copy , Clone , PartialEq , Encodable , Decodable , HashStable_Generic ) ]
2503+ /// The polarity of a trait bound.
2504+ #[ derive( Copy , Clone , PartialEq , Eq , Encodable , Decodable , Debug ) ]
2505+ #[ derive( HashStable_Generic ) ]
25202506pub enum BoundPolarity {
25212507 /// `Type: Trait`
25222508 Positive ,
@@ -2526,6 +2512,35 @@ pub enum BoundPolarity {
25262512 Maybe ( Span ) ,
25272513}
25282514
2515+ impl BoundPolarity {
2516+ pub fn as_str ( self ) -> & ' static str {
2517+ match self {
2518+ Self :: Positive => "" ,
2519+ Self :: Negative ( _) => "!" ,
2520+ Self :: Maybe ( _) => "?" ,
2521+ }
2522+ }
2523+ }
2524+
2525+ /// The constness of a trait bound.
2526+ #[ derive( Copy , Clone , PartialEq , Eq , Encodable , Decodable , Debug ) ]
2527+ #[ derive( HashStable_Generic ) ]
2528+ pub enum BoundConstness {
2529+ /// `Type: Trait`
2530+ Never ,
2531+ /// `Type: ~const Trait`
2532+ Maybe ( Span ) ,
2533+ }
2534+
2535+ impl BoundConstness {
2536+ pub fn as_str ( self ) -> & ' static str {
2537+ match self {
2538+ Self :: Never => "" ,
2539+ Self :: Maybe ( _) => "~const" ,
2540+ }
2541+ }
2542+ }
2543+
25292544#[ derive( Clone , Encodable , Decodable , Debug ) ]
25302545pub enum FnRetTy {
25312546 /// Returns type is not specified.
@@ -3255,7 +3270,7 @@ mod size_asserts {
32553270 static_assert_size ! ( ForeignItem , 96 ) ;
32563271 static_assert_size ! ( ForeignItemKind , 24 ) ;
32573272 static_assert_size ! ( GenericArg , 24 ) ;
3258- static_assert_size ! ( GenericBound , 64 ) ;
3273+ static_assert_size ! ( GenericBound , 72 ) ;
32593274 static_assert_size ! ( Generics , 40 ) ;
32603275 static_assert_size ! ( Impl , 136 ) ;
32613276 static_assert_size ! ( Item , 136 ) ;
0 commit comments