@@ -116,7 +116,7 @@ pub enum TypeRef {
116116 Reference ( Box < TypeRef > , Option < LifetimeRef > , Mutability ) ,
117117 // FIXME: for full const generics, the latter element (length) here is going to have to be an
118118 // expression that is further lowered later in hir_ty.
119- Array ( Box < TypeRef > , ConstScalarOrPath ) ,
119+ Array ( Box < TypeRef > , ConstRefOrPath ) ,
120120 Slice ( Box < TypeRef > ) ,
121121 /// A fn pointer. Last element of the vector is the return type.
122122 Fn ( Vec < ( Option < Name > , TypeRef ) > , bool /*varargs*/ , bool /*is_unsafe*/ ) ,
@@ -188,7 +188,7 @@ impl TypeRef {
188188 // `hir_def::body::lower` to lower this into an `Expr` and then evaluate it at the
189189 // `hir_ty` level, which would allow knowing the type of:
190190 // let v: [u8; 2 + 2] = [0u8; 4];
191- let len = ConstScalarOrPath :: from_expr_opt ( inner. expr ( ) ) ;
191+ let len = ConstRefOrPath :: from_expr_opt ( inner. expr ( ) ) ;
192192 TypeRef :: Array ( Box :: new ( TypeRef :: from_ast_opt ( ctx, inner. ty ( ) ) ) , len)
193193 }
194194 ast:: Type :: SliceType ( inner) => {
@@ -378,25 +378,25 @@ impl TypeBound {
378378}
379379
380380#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
381- pub enum ConstScalarOrPath {
382- Scalar ( ConstScalar ) ,
381+ pub enum ConstRefOrPath {
382+ Scalar ( ConstRef ) ,
383383 Path ( Name ) ,
384384}
385385
386- impl std:: fmt:: Display for ConstScalarOrPath {
386+ impl std:: fmt:: Display for ConstRefOrPath {
387387 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
388388 match self {
389- ConstScalarOrPath :: Scalar ( s) => s. fmt ( f) ,
390- ConstScalarOrPath :: Path ( n) => n. fmt ( f) ,
389+ ConstRefOrPath :: Scalar ( s) => s. fmt ( f) ,
390+ ConstRefOrPath :: Path ( n) => n. fmt ( f) ,
391391 }
392392 }
393393}
394394
395- impl ConstScalarOrPath {
395+ impl ConstRefOrPath {
396396 pub ( crate ) fn from_expr_opt ( expr : Option < ast:: Expr > ) -> Self {
397397 match expr {
398398 Some ( x) => Self :: from_expr ( x) ,
399- None => Self :: Scalar ( ConstScalar :: Unknown ) ,
399+ None => Self :: Scalar ( ConstRef :: Unknown ) ,
400400 }
401401 }
402402
@@ -407,16 +407,16 @@ impl ConstScalarOrPath {
407407 ast:: Expr :: PathExpr ( p) => {
408408 match p. path ( ) . and_then ( |x| x. segment ( ) ) . and_then ( |x| x. name_ref ( ) ) {
409409 Some ( x) => Self :: Path ( x. as_name ( ) ) ,
410- None => Self :: Scalar ( ConstScalar :: Unknown ) ,
410+ None => Self :: Scalar ( ConstRef :: Unknown ) ,
411411 }
412412 }
413413 ast:: Expr :: PrefixExpr ( prefix_expr) => match prefix_expr. op_kind ( ) {
414414 Some ( ast:: UnaryOp :: Neg ) => {
415415 let unsigned = Self :: from_expr_opt ( prefix_expr. expr ( ) ) ;
416416 // Add sign
417417 match unsigned {
418- Self :: Scalar ( ConstScalar :: UInt ( num) ) => {
419- Self :: Scalar ( ConstScalar :: Int ( -( num as i128 ) ) )
418+ Self :: Scalar ( ConstRef :: UInt ( num) ) => {
419+ Self :: Scalar ( ConstRef :: Int ( -( num as i128 ) ) )
420420 }
421421 other => other,
422422 }
@@ -425,22 +425,22 @@ impl ConstScalarOrPath {
425425 } ,
426426 ast:: Expr :: Literal ( literal) => Self :: Scalar ( match literal. kind ( ) {
427427 ast:: LiteralKind :: IntNumber ( num) => {
428- num. value ( ) . map ( ConstScalar :: UInt ) . unwrap_or ( ConstScalar :: Unknown )
428+ num. value ( ) . map ( ConstRef :: UInt ) . unwrap_or ( ConstRef :: Unknown )
429429 }
430430 ast:: LiteralKind :: Char ( c) => {
431- c. value ( ) . map ( ConstScalar :: Char ) . unwrap_or ( ConstScalar :: Unknown )
431+ c. value ( ) . map ( ConstRef :: Char ) . unwrap_or ( ConstRef :: Unknown )
432432 }
433- ast:: LiteralKind :: Bool ( f) => ConstScalar :: Bool ( f) ,
434- _ => ConstScalar :: Unknown ,
433+ ast:: LiteralKind :: Bool ( f) => ConstRef :: Bool ( f) ,
434+ _ => ConstRef :: Unknown ,
435435 } ) ,
436- _ => Self :: Scalar ( ConstScalar :: Unknown ) ,
436+ _ => Self :: Scalar ( ConstRef :: Unknown ) ,
437437 }
438438 }
439439}
440440
441441/// A concrete constant value
442- #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
443- pub enum ConstScalar {
442+ #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
443+ pub enum ConstRef {
444444 Int ( i128 ) ,
445445 UInt ( u128 ) ,
446446 Bool ( bool ) ,
@@ -454,18 +454,18 @@ pub enum ConstScalar {
454454 Unknown ,
455455}
456456
457- impl ConstScalar {
457+ impl ConstRef {
458458 pub fn builtin_type ( & self ) -> BuiltinType {
459459 match self {
460- ConstScalar :: UInt ( _) | ConstScalar :: Unknown => BuiltinType :: Uint ( BuiltinUint :: U128 ) ,
461- ConstScalar :: Int ( _) => BuiltinType :: Int ( BuiltinInt :: I128 ) ,
462- ConstScalar :: Char ( _) => BuiltinType :: Char ,
463- ConstScalar :: Bool ( _) => BuiltinType :: Bool ,
460+ ConstRef :: UInt ( _) | ConstRef :: Unknown => BuiltinType :: Uint ( BuiltinUint :: U128 ) ,
461+ ConstRef :: Int ( _) => BuiltinType :: Int ( BuiltinInt :: I128 ) ,
462+ ConstRef :: Char ( _) => BuiltinType :: Char ,
463+ ConstRef :: Bool ( _) => BuiltinType :: Bool ,
464464 }
465465 }
466466}
467467
468- impl From < Literal > for ConstScalar {
468+ impl From < Literal > for ConstRef {
469469 fn from ( literal : Literal ) -> Self {
470470 match literal {
471471 Literal :: Char ( c) => Self :: Char ( c) ,
@@ -477,14 +477,14 @@ impl From<Literal> for ConstScalar {
477477 }
478478}
479479
480- impl std:: fmt:: Display for ConstScalar {
480+ impl std:: fmt:: Display for ConstRef {
481481 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> Result < ( ) , std:: fmt:: Error > {
482482 match self {
483- ConstScalar :: Int ( num) => num. fmt ( f) ,
484- ConstScalar :: UInt ( num) => num. fmt ( f) ,
485- ConstScalar :: Bool ( flag) => flag. fmt ( f) ,
486- ConstScalar :: Char ( c) => write ! ( f, "'{c}'" ) ,
487- ConstScalar :: Unknown => f. write_char ( '_' ) ,
483+ ConstRef :: Int ( num) => num. fmt ( f) ,
484+ ConstRef :: UInt ( num) => num. fmt ( f) ,
485+ ConstRef :: Bool ( flag) => flag. fmt ( f) ,
486+ ConstRef :: Char ( c) => write ! ( f, "'{c}'" ) ,
487+ ConstRef :: Unknown => f. write_char ( '_' ) ,
488488 }
489489 }
490490}
0 commit comments