@@ -4,81 +4,87 @@ use rustc_ast::ast::*;
4
4
use rustc_ast:: ptr:: P ;
5
5
use rustc_hir as hir;
6
6
use rustc_hir:: def:: Res ;
7
+ use rustc_middle:: limits:: ensure_sufficient_stack;
7
8
use rustc_span:: { source_map:: Spanned , Span } ;
8
9
9
10
impl < ' a , ' hir > LoweringContext < ' a , ' hir > {
10
11
crate fn lower_pat ( & mut self , p : & Pat ) -> & ' hir hir:: Pat < ' hir > {
11
- let node = match p. kind {
12
- PatKind :: Wild => hir:: PatKind :: Wild ,
13
- PatKind :: Ident ( ref binding_mode, ident, ref sub) => {
14
- let lower_sub = |this : & mut Self | sub. as_ref ( ) . map ( |s| this. lower_pat ( & * s) ) ;
15
- let node = self . lower_pat_ident ( p, binding_mode, ident, lower_sub) ;
16
- node
17
- }
18
- PatKind :: Lit ( ref e) => hir:: PatKind :: Lit ( self . lower_expr ( e) ) ,
19
- PatKind :: TupleStruct ( ref path, ref pats) => {
20
- let qpath = self . lower_qpath (
21
- p. id ,
22
- & None ,
23
- path,
24
- ParamMode :: Optional ,
25
- ImplTraitContext :: disallowed ( ) ,
26
- ) ;
27
- let ( pats, ddpos) = self . lower_pat_tuple ( pats, "tuple struct" ) ;
28
- hir:: PatKind :: TupleStruct ( qpath, pats, ddpos)
29
- }
30
- PatKind :: Or ( ref pats) => {
31
- hir:: PatKind :: Or ( self . arena . alloc_from_iter ( pats. iter ( ) . map ( |x| self . lower_pat ( x) ) ) )
32
- }
33
- PatKind :: Path ( ref qself, ref path) => {
34
- let qpath = self . lower_qpath (
35
- p. id ,
36
- qself,
37
- path,
38
- ParamMode :: Optional ,
39
- ImplTraitContext :: disallowed ( ) ,
40
- ) ;
41
- hir:: PatKind :: Path ( qpath)
42
- }
43
- PatKind :: Struct ( ref path, ref fields, etc) => {
44
- let qpath = self . lower_qpath (
45
- p. id ,
46
- & None ,
47
- path,
48
- ParamMode :: Optional ,
49
- ImplTraitContext :: disallowed ( ) ,
50
- ) ;
12
+ ensure_sufficient_stack ( || {
13
+ let node = match p. kind {
14
+ PatKind :: Wild => hir:: PatKind :: Wild ,
15
+ PatKind :: Ident ( ref binding_mode, ident, ref sub) => {
16
+ let lower_sub = |this : & mut Self | sub. as_ref ( ) . map ( |s| this. lower_pat ( & * s) ) ;
17
+ let node = self . lower_pat_ident ( p, binding_mode, ident, lower_sub) ;
18
+ node
19
+ }
20
+ PatKind :: Lit ( ref e) => hir:: PatKind :: Lit ( self . lower_expr ( e) ) ,
21
+ PatKind :: TupleStruct ( ref path, ref pats) => {
22
+ let qpath = self . lower_qpath (
23
+ p. id ,
24
+ & None ,
25
+ path,
26
+ ParamMode :: Optional ,
27
+ ImplTraitContext :: disallowed ( ) ,
28
+ ) ;
29
+ let ( pats, ddpos) = self . lower_pat_tuple ( pats, "tuple struct" ) ;
30
+ hir:: PatKind :: TupleStruct ( qpath, pats, ddpos)
31
+ }
32
+ PatKind :: Or ( ref pats) => hir:: PatKind :: Or (
33
+ self . arena . alloc_from_iter ( pats. iter ( ) . map ( |x| self . lower_pat ( x) ) ) ,
34
+ ) ,
35
+ PatKind :: Path ( ref qself, ref path) => {
36
+ let qpath = self . lower_qpath (
37
+ p. id ,
38
+ qself,
39
+ path,
40
+ ParamMode :: Optional ,
41
+ ImplTraitContext :: disallowed ( ) ,
42
+ ) ;
43
+ hir:: PatKind :: Path ( qpath)
44
+ }
45
+ PatKind :: Struct ( ref path, ref fields, etc) => {
46
+ let qpath = self . lower_qpath (
47
+ p. id ,
48
+ & None ,
49
+ path,
50
+ ParamMode :: Optional ,
51
+ ImplTraitContext :: disallowed ( ) ,
52
+ ) ;
51
53
52
- let fs = self . arena . alloc_from_iter ( fields. iter ( ) . map ( |f| hir:: FieldPat {
53
- hir_id : self . next_id ( ) ,
54
- ident : f. ident ,
55
- pat : self . lower_pat ( & f. pat ) ,
56
- is_shorthand : f. is_shorthand ,
57
- span : f. span ,
58
- } ) ) ;
59
- hir:: PatKind :: Struct ( qpath, fs, etc)
60
- }
61
- PatKind :: Tuple ( ref pats) => {
62
- let ( pats, ddpos) = self . lower_pat_tuple ( pats, "tuple" ) ;
63
- hir:: PatKind :: Tuple ( pats, ddpos)
64
- }
65
- PatKind :: Box ( ref inner) => hir:: PatKind :: Box ( self . lower_pat ( inner) ) ,
66
- PatKind :: Ref ( ref inner, mutbl) => hir:: PatKind :: Ref ( self . lower_pat ( inner) , mutbl) ,
67
- PatKind :: Range ( ref e1, ref e2, Spanned { node : ref end, .. } ) => hir:: PatKind :: Range (
68
- e1. as_deref ( ) . map ( |e| self . lower_expr ( e) ) ,
69
- e2. as_deref ( ) . map ( |e| self . lower_expr ( e) ) ,
70
- self . lower_range_end ( end, e2. is_some ( ) ) ,
71
- ) ,
72
- PatKind :: Slice ( ref pats) => self . lower_pat_slice ( pats) ,
73
- PatKind :: Rest => {
74
- // If we reach here the `..` pattern is not semantically allowed.
75
- self . ban_illegal_rest_pat ( p. span )
76
- }
77
- PatKind :: Paren ( ref inner) => return self . lower_pat ( inner) ,
78
- PatKind :: MacCall ( _) => panic ! ( "Shouldn't exist here" ) ,
79
- } ;
54
+ let fs = self . arena . alloc_from_iter ( fields. iter ( ) . map ( |f| hir:: FieldPat {
55
+ hir_id : self . next_id ( ) ,
56
+ ident : f. ident ,
57
+ pat : self . lower_pat ( & f. pat ) ,
58
+ is_shorthand : f. is_shorthand ,
59
+ span : f. span ,
60
+ } ) ) ;
61
+ hir:: PatKind :: Struct ( qpath, fs, etc)
62
+ }
63
+ PatKind :: Tuple ( ref pats) => {
64
+ let ( pats, ddpos) = self . lower_pat_tuple ( pats, "tuple" ) ;
65
+ hir:: PatKind :: Tuple ( pats, ddpos)
66
+ }
67
+ PatKind :: Box ( ref inner) => hir:: PatKind :: Box ( self . lower_pat ( inner) ) ,
68
+ PatKind :: Ref ( ref inner, mutbl) => hir:: PatKind :: Ref ( self . lower_pat ( inner) , mutbl) ,
69
+ PatKind :: Range ( ref e1, ref e2, Spanned { node : ref end, .. } ) => {
70
+ hir:: PatKind :: Range (
71
+ e1. as_deref ( ) . map ( |e| self . lower_expr ( e) ) ,
72
+ e2. as_deref ( ) . map ( |e| self . lower_expr ( e) ) ,
73
+ self . lower_range_end ( end, e2. is_some ( ) ) ,
74
+ )
75
+ }
76
+ PatKind :: Slice ( ref pats) => self . lower_pat_slice ( pats) ,
77
+ PatKind :: Rest => {
78
+ // If we reach here the `..` pattern is not semantically allowed.
79
+ self . ban_illegal_rest_pat ( p. span )
80
+ }
81
+ // FIXME: consider not using recursion to lower this.
82
+ PatKind :: Paren ( ref inner) => return self . lower_pat ( inner) ,
83
+ PatKind :: MacCall ( _) => panic ! ( "{:?} shouldn't exist here" , p. span) ,
84
+ } ;
80
85
81
- self . pat_with_node_id_of ( p, node)
86
+ self . pat_with_node_id_of ( p, node)
87
+ } )
82
88
}
83
89
84
90
fn lower_pat_tuple (
0 commit comments