@@ -20,7 +20,6 @@ use syntax_pos::{Span, DUMMY_SP};
2020use codemap:: { respan, Spanned } ;
2121use abi:: Abi ;
2222use ext:: hygiene:: { Mark , SyntaxContext } ;
23- use parse:: parser:: { RecoverQPath , PathStyle } ;
2423use print:: pprust;
2524use ptr:: P ;
2625use rustc_data_structures:: indexed_vec;
@@ -485,6 +484,30 @@ impl fmt::Debug for Pat {
485484}
486485
487486impl 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+
488511 pub fn walk < F > ( & self , it : & mut F ) -> bool
489512 where F : FnMut ( & Pat ) -> bool
490513 {
@@ -520,38 +543,6 @@ impl Pat {
520543 }
521544}
522545
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-
555546/// A single field in a struct pattern
556547///
557548/// Patterns like the fields of Foo `{ x, ref y, ref mut z }`
@@ -919,10 +910,8 @@ impl Expr {
919910 _ => None ,
920911 }
921912 }
922- }
923913
924- impl RecoverQPath for Expr {
925- fn to_ty ( & self ) -> Option < P < Ty > > {
914+ pub ( super ) fn to_ty ( & self ) -> Option < P < Ty > > {
926915 let node = match & self . node {
927916 ExprKind :: Path ( qself, path) => TyKind :: Path ( qself. clone ( ) , path. clone ( ) ) ,
928917 ExprKind :: Mac ( mac) => TyKind :: Mac ( mac. clone ( ) ) ,
@@ -951,13 +940,6 @@ impl RecoverQPath for Expr {
951940
952941 Some ( P ( Ty { node, id : self . id , span : self . span } ) )
953942 }
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- }
961943}
962944
963945impl fmt:: Debug for Expr {
@@ -1469,19 +1451,6 @@ pub struct Ty {
14691451 pub span : Span ,
14701452}
14711453
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-
14851454impl fmt:: Debug for Ty {
14861455 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
14871456 write ! ( f, "type({})" , pprust:: ty_to_string( self ) )
0 commit comments