@@ -20,7 +20,6 @@ use syntax_pos::{Span, DUMMY_SP};
20
20
use codemap:: { respan, Spanned } ;
21
21
use abi:: Abi ;
22
22
use ext:: hygiene:: { Mark , SyntaxContext } ;
23
- use parse:: parser:: { RecoverQPath , PathStyle } ;
24
23
use print:: pprust;
25
24
use ptr:: P ;
26
25
use rustc_data_structures:: indexed_vec;
@@ -485,6 +484,30 @@ impl fmt::Debug for Pat {
485
484
}
486
485
487
486
impl Pat {
487
+ pub ( super ) fn to_ty ( & self ) -> Option < P < Ty > > {
488
+ let node = match & self . node {
489
+ PatKind :: Wild => TyKind :: Infer ,
490
+ PatKind :: Ident ( BindingMode :: ByValue ( Mutability :: Immutable ) , ident, None ) =>
491
+ TyKind :: Path ( None , Path :: from_ident ( ident. span , ident. node ) ) ,
492
+ PatKind :: Path ( qself, path) => TyKind :: Path ( qself. clone ( ) , path. clone ( ) ) ,
493
+ PatKind :: Mac ( mac) => TyKind :: Mac ( mac. clone ( ) ) ,
494
+ PatKind :: Ref ( pat, mutbl) =>
495
+ pat. to_ty ( ) . map ( |ty| TyKind :: Rptr ( None , MutTy { ty, mutbl : * mutbl } ) ) ?,
496
+ PatKind :: Slice ( pats, None , _) if pats. len ( ) == 1 =>
497
+ pats[ 0 ] . to_ty ( ) . map ( TyKind :: Slice ) ?,
498
+ PatKind :: Tuple ( pats, None ) => {
499
+ let mut tys = Vec :: new ( ) ;
500
+ for pat in pats {
501
+ tys. push ( pat. to_ty ( ) ?) ;
502
+ }
503
+ TyKind :: Tup ( tys)
504
+ }
505
+ _ => return None ,
506
+ } ;
507
+
508
+ Some ( P ( Ty { node, id : self . id , span : self . span } ) )
509
+ }
510
+
488
511
pub fn walk < F > ( & self , it : & mut F ) -> bool
489
512
where F : FnMut ( & Pat ) -> bool
490
513
{
@@ -520,38 +543,6 @@ impl Pat {
520
543
}
521
544
}
522
545
523
- impl RecoverQPath for Pat {
524
- fn to_ty ( & self ) -> Option < P < Ty > > {
525
- let node = match & self . node {
526
- PatKind :: Wild => TyKind :: Infer ,
527
- PatKind :: Ident ( BindingMode :: ByValue ( Mutability :: Immutable ) , ident, None ) =>
528
- TyKind :: Path ( None , Path :: from_ident ( ident. span , ident. node ) ) ,
529
- PatKind :: Path ( qself, path) => TyKind :: Path ( qself. clone ( ) , path. clone ( ) ) ,
530
- PatKind :: Mac ( mac) => TyKind :: Mac ( mac. clone ( ) ) ,
531
- PatKind :: Ref ( pat, mutbl) =>
532
- pat. to_ty ( ) . map ( |ty| TyKind :: Rptr ( None , MutTy { ty, mutbl : * mutbl } ) ) ?,
533
- PatKind :: Slice ( pats, None , _) if pats. len ( ) == 1 =>
534
- pats[ 0 ] . to_ty ( ) . map ( TyKind :: Slice ) ?,
535
- PatKind :: Tuple ( pats, None ) => {
536
- let mut tys = Vec :: new ( ) ;
537
- for pat in pats {
538
- tys. push ( pat. to_ty ( ) ?) ;
539
- }
540
- TyKind :: Tup ( tys)
541
- }
542
- _ => return None ,
543
- } ;
544
-
545
- Some ( P ( Ty { node, id : self . id , span : self . span } ) )
546
- }
547
- fn to_recovered ( & self , qself : Option < QSelf > , path : Path ) -> Self {
548
- Self { span : path. span , node : PatKind :: Path ( qself, path) , id : self . id }
549
- }
550
- fn to_string ( & self ) -> String {
551
- pprust:: pat_to_string ( self )
552
- }
553
- }
554
-
555
546
/// A single field in a struct pattern
556
547
///
557
548
/// Patterns like the fields of Foo `{ x, ref y, ref mut z }`
@@ -919,10 +910,8 @@ impl Expr {
919
910
_ => None ,
920
911
}
921
912
}
922
- }
923
913
924
- impl RecoverQPath for Expr {
925
- fn to_ty ( & self ) -> Option < P < Ty > > {
914
+ pub ( super ) fn to_ty ( & self ) -> Option < P < Ty > > {
926
915
let node = match & self . node {
927
916
ExprKind :: Path ( qself, path) => TyKind :: Path ( qself. clone ( ) , path. clone ( ) ) ,
928
917
ExprKind :: Mac ( mac) => TyKind :: Mac ( mac. clone ( ) ) ,
@@ -951,13 +940,6 @@ impl RecoverQPath for Expr {
951
940
952
941
Some ( P ( Ty { node, id : self . id , span : self . span } ) )
953
942
}
954
- fn to_recovered ( & self , qself : Option < QSelf > , path : Path ) -> Self {
955
- Self { span : path. span , node : ExprKind :: Path ( qself, path) ,
956
- id : self . id , attrs : self . attrs . clone ( ) }
957
- }
958
- fn to_string ( & self ) -> String {
959
- pprust:: expr_to_string ( self )
960
- }
961
943
}
962
944
963
945
impl fmt:: Debug for Expr {
@@ -1469,19 +1451,6 @@ pub struct Ty {
1469
1451
pub span : Span ,
1470
1452
}
1471
1453
1472
- impl RecoverQPath for Ty {
1473
- fn to_ty ( & self ) -> Option < P < Ty > > {
1474
- Some ( P ( self . clone ( ) ) )
1475
- }
1476
- fn to_recovered ( & self , qself : Option < QSelf > , path : Path ) -> Self {
1477
- Self { span : path. span , node : TyKind :: Path ( qself, path) , id : self . id }
1478
- }
1479
- fn to_string ( & self ) -> String {
1480
- pprust:: ty_to_string ( self )
1481
- }
1482
- const PATH_STYLE : PathStyle = PathStyle :: Type ;
1483
- }
1484
-
1485
1454
impl fmt:: Debug for Ty {
1486
1455
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1487
1456
write ! ( f, "type({})" , pprust:: ty_to_string( self ) )
0 commit comments