@@ -116,7 +116,7 @@ pub enum TypeRef {
116
116
Reference ( Box < TypeRef > , Option < LifetimeRef > , Mutability ) ,
117
117
// FIXME: for full const generics, the latter element (length) here is going to have to be an
118
118
// expression that is further lowered later in hir_ty.
119
- Array ( Box < TypeRef > , ConstScalarOrPath ) ,
119
+ Array ( Box < TypeRef > , ConstRefOrPath ) ,
120
120
Slice ( Box < TypeRef > ) ,
121
121
/// A fn pointer. Last element of the vector is the return type.
122
122
Fn ( Vec < ( Option < Name > , TypeRef ) > , bool /*varargs*/ , bool /*is_unsafe*/ ) ,
@@ -188,7 +188,7 @@ impl TypeRef {
188
188
// `hir_def::body::lower` to lower this into an `Expr` and then evaluate it at the
189
189
// `hir_ty` level, which would allow knowing the type of:
190
190
// 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 ( ) ) ;
192
192
TypeRef :: Array ( Box :: new ( TypeRef :: from_ast_opt ( ctx, inner. ty ( ) ) ) , len)
193
193
}
194
194
ast:: Type :: SliceType ( inner) => {
@@ -378,25 +378,25 @@ impl TypeBound {
378
378
}
379
379
380
380
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
381
- pub enum ConstScalarOrPath {
382
- Scalar ( ConstScalar ) ,
381
+ pub enum ConstRefOrPath {
382
+ Scalar ( ConstRef ) ,
383
383
Path ( Name ) ,
384
384
}
385
385
386
- impl std:: fmt:: Display for ConstScalarOrPath {
386
+ impl std:: fmt:: Display for ConstRefOrPath {
387
387
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
388
388
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) ,
391
391
}
392
392
}
393
393
}
394
394
395
- impl ConstScalarOrPath {
395
+ impl ConstRefOrPath {
396
396
pub ( crate ) fn from_expr_opt ( expr : Option < ast:: Expr > ) -> Self {
397
397
match expr {
398
398
Some ( x) => Self :: from_expr ( x) ,
399
- None => Self :: Scalar ( ConstScalar :: Unknown ) ,
399
+ None => Self :: Scalar ( ConstRef :: Unknown ) ,
400
400
}
401
401
}
402
402
@@ -407,16 +407,16 @@ impl ConstScalarOrPath {
407
407
ast:: Expr :: PathExpr ( p) => {
408
408
match p. path ( ) . and_then ( |x| x. segment ( ) ) . and_then ( |x| x. name_ref ( ) ) {
409
409
Some ( x) => Self :: Path ( x. as_name ( ) ) ,
410
- None => Self :: Scalar ( ConstScalar :: Unknown ) ,
410
+ None => Self :: Scalar ( ConstRef :: Unknown ) ,
411
411
}
412
412
}
413
413
ast:: Expr :: PrefixExpr ( prefix_expr) => match prefix_expr. op_kind ( ) {
414
414
Some ( ast:: UnaryOp :: Neg ) => {
415
415
let unsigned = Self :: from_expr_opt ( prefix_expr. expr ( ) ) ;
416
416
// Add sign
417
417
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 ) ) )
420
420
}
421
421
other => other,
422
422
}
@@ -425,22 +425,22 @@ impl ConstScalarOrPath {
425
425
} ,
426
426
ast:: Expr :: Literal ( literal) => Self :: Scalar ( match literal. kind ( ) {
427
427
ast:: LiteralKind :: IntNumber ( num) => {
428
- num. value ( ) . map ( ConstScalar :: UInt ) . unwrap_or ( ConstScalar :: Unknown )
428
+ num. value ( ) . map ( ConstRef :: UInt ) . unwrap_or ( ConstRef :: Unknown )
429
429
}
430
430
ast:: LiteralKind :: Char ( c) => {
431
- c. value ( ) . map ( ConstScalar :: Char ) . unwrap_or ( ConstScalar :: Unknown )
431
+ c. value ( ) . map ( ConstRef :: Char ) . unwrap_or ( ConstRef :: Unknown )
432
432
}
433
- ast:: LiteralKind :: Bool ( f) => ConstScalar :: Bool ( f) ,
434
- _ => ConstScalar :: Unknown ,
433
+ ast:: LiteralKind :: Bool ( f) => ConstRef :: Bool ( f) ,
434
+ _ => ConstRef :: Unknown ,
435
435
} ) ,
436
- _ => Self :: Scalar ( ConstScalar :: Unknown ) ,
436
+ _ => Self :: Scalar ( ConstRef :: Unknown ) ,
437
437
}
438
438
}
439
439
}
440
440
441
441
/// 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 {
444
444
Int ( i128 ) ,
445
445
UInt ( u128 ) ,
446
446
Bool ( bool ) ,
@@ -454,18 +454,18 @@ pub enum ConstScalar {
454
454
Unknown ,
455
455
}
456
456
457
- impl ConstScalar {
457
+ impl ConstRef {
458
458
pub fn builtin_type ( & self ) -> BuiltinType {
459
459
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 ,
464
464
}
465
465
}
466
466
}
467
467
468
- impl From < Literal > for ConstScalar {
468
+ impl From < Literal > for ConstRef {
469
469
fn from ( literal : Literal ) -> Self {
470
470
match literal {
471
471
Literal :: Char ( c) => Self :: Char ( c) ,
@@ -477,14 +477,14 @@ impl From<Literal> for ConstScalar {
477
477
}
478
478
}
479
479
480
- impl std:: fmt:: Display for ConstScalar {
480
+ impl std:: fmt:: Display for ConstRef {
481
481
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> Result < ( ) , std:: fmt:: Error > {
482
482
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 ( '_' ) ,
488
488
}
489
489
}
490
490
}
0 commit comments