@@ -417,26 +417,7 @@ impl ExprCollector<'_> {
417417 }
418418 }
419419
420- ast:: Expr :: Literal ( e) => {
421- let lit = match e. kind ( ) {
422- LiteralKind :: IntNumber { suffix } => {
423- let known_name = suffix. and_then ( |it| BuiltinInt :: from_suffix ( & it) ) ;
424-
425- Literal :: Int ( Default :: default ( ) , known_name)
426- }
427- LiteralKind :: FloatNumber { suffix } => {
428- let known_name = suffix. and_then ( |it| BuiltinFloat :: from_suffix ( & it) ) ;
429-
430- Literal :: Float ( Default :: default ( ) , known_name)
431- }
432- LiteralKind :: ByteString => Literal :: ByteString ( Default :: default ( ) ) ,
433- LiteralKind :: String => Literal :: String ( Default :: default ( ) ) ,
434- LiteralKind :: Byte => Literal :: Int ( Default :: default ( ) , Some ( BuiltinInt :: U8 ) ) ,
435- LiteralKind :: Bool => Literal :: Bool ( Default :: default ( ) ) ,
436- LiteralKind :: Char => Literal :: Char ( Default :: default ( ) ) ,
437- } ;
438- self . alloc_expr ( Expr :: Literal ( lit) , syntax_ptr)
439- }
420+ ast:: Expr :: Literal ( e) => self . alloc_expr ( Expr :: Literal ( e. kind ( ) . into ( ) ) , syntax_ptr) ,
440421 ast:: Expr :: IndexExpr ( e) => {
441422 let base = self . collect_expr_opt ( e. base ( ) ) ;
442423 let index = self . collect_expr_opt ( e. index ( ) ) ;
@@ -679,10 +660,19 @@ impl ExprCollector<'_> {
679660 suffix : suffix. into_iter ( ) . map ( |p| self . collect_pat ( p) ) . collect ( ) ,
680661 }
681662 }
663+ ast:: Pat :: LiteralPat ( lit) => {
664+ if let Some ( ast_lit) = lit. literal ( ) {
665+ let expr = Expr :: Literal ( ast_lit. kind ( ) . into ( ) ) ;
666+ let expr_ptr = AstPtr :: new ( & ast:: Expr :: Literal ( ast_lit) ) ;
667+ let expr_id = self . alloc_expr ( expr, expr_ptr) ;
668+ Pat :: Lit ( expr_id)
669+ } else {
670+ Pat :: Missing
671+ }
672+ }
682673
683674 // FIXME: implement
684675 ast:: Pat :: BoxPat ( _) => Pat :: Missing ,
685- ast:: Pat :: LiteralPat ( _) => Pat :: Missing ,
686676 ast:: Pat :: RangePat ( _) => Pat :: Missing ,
687677 } ;
688678 let ptr = AstPtr :: new ( & pat) ;
@@ -741,3 +731,25 @@ impl From<ast::BinOp> for BinaryOp {
741731 }
742732 }
743733}
734+
735+ impl From < ast:: LiteralKind > for Literal {
736+ fn from ( ast_lit_kind : ast:: LiteralKind ) -> Self {
737+ match ast_lit_kind {
738+ LiteralKind :: IntNumber { suffix } => {
739+ let known_name = suffix. and_then ( |it| BuiltinInt :: from_suffix ( & it) ) ;
740+
741+ Literal :: Int ( Default :: default ( ) , known_name)
742+ }
743+ LiteralKind :: FloatNumber { suffix } => {
744+ let known_name = suffix. and_then ( |it| BuiltinFloat :: from_suffix ( & it) ) ;
745+
746+ Literal :: Float ( Default :: default ( ) , known_name)
747+ }
748+ LiteralKind :: ByteString => Literal :: ByteString ( Default :: default ( ) ) ,
749+ LiteralKind :: String => Literal :: String ( Default :: default ( ) ) ,
750+ LiteralKind :: Byte => Literal :: Int ( Default :: default ( ) , Some ( BuiltinInt :: U8 ) ) ,
751+ LiteralKind :: Bool => Literal :: Bool ( Default :: default ( ) ) ,
752+ LiteralKind :: Char => Literal :: Char ( Default :: default ( ) ) ,
753+ }
754+ }
755+ }
0 commit comments