1
1
use rustc_ast:: ptr:: P ;
2
2
use rustc_ast:: * ;
3
- use rustc_data_structures:: stack:: ensure_sufficient_stack;
4
3
use rustc_hir as hir;
5
4
use rustc_hir:: def:: Res ;
6
5
use rustc_span:: Span ;
@@ -19,117 +18,115 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19
18
}
20
19
21
20
fn lower_pat_mut ( & mut self , mut pattern : & Pat ) -> hir:: Pat < ' hir > {
22
- ensure_sufficient_stack ( || {
23
- // loop here to avoid recursion
24
- let pat_hir_id = self . lower_node_id ( pattern. id ) ;
25
- let node = loop {
26
- match & pattern. kind {
27
- PatKind :: Wild => break hir:: PatKind :: Wild ,
28
- PatKind :: Never => break hir:: PatKind :: Never ,
29
- PatKind :: Ident ( binding_mode, ident, sub) => {
30
- let lower_sub = |this : & mut Self | sub. as_ref ( ) . map ( |s| this. lower_pat ( s) ) ;
31
- break self . lower_pat_ident (
32
- pattern,
33
- * binding_mode,
34
- * ident,
35
- pat_hir_id,
36
- lower_sub,
37
- ) ;
38
- }
39
- PatKind :: Lit ( e) => {
40
- break hir:: PatKind :: Lit ( self . lower_expr_within_pat ( e, false ) ) ;
41
- }
42
- PatKind :: TupleStruct ( qself, path, pats) => {
43
- let qpath = self . lower_qpath (
44
- pattern. id ,
45
- qself,
46
- path,
47
- ParamMode :: Optional ,
48
- AllowReturnTypeNotation :: No ,
49
- ImplTraitContext :: Disallowed ( ImplTraitPosition :: Path ) ,
50
- None ,
51
- ) ;
52
- let ( pats, ddpos) = self . lower_pat_tuple ( pats, "tuple struct" ) ;
53
- break hir:: PatKind :: TupleStruct ( qpath, pats, ddpos) ;
54
- }
55
- PatKind :: Or ( pats) => {
56
- break hir:: PatKind :: Or (
57
- self . arena . alloc_from_iter ( pats. iter ( ) . map ( |x| self . lower_pat_mut ( x) ) ) ,
58
- ) ;
59
- }
60
- PatKind :: Path ( qself, path) => {
61
- let qpath = self . lower_qpath (
62
- pattern. id ,
63
- qself,
64
- path,
65
- ParamMode :: Optional ,
66
- AllowReturnTypeNotation :: No ,
67
- ImplTraitContext :: Disallowed ( ImplTraitPosition :: Path ) ,
68
- None ,
69
- ) ;
70
- break hir:: PatKind :: Path ( qpath) ;
71
- }
72
- PatKind :: Struct ( qself, path, fields, etc) => {
73
- let qpath = self . lower_qpath (
74
- pattern. id ,
75
- qself,
76
- path,
77
- ParamMode :: Optional ,
78
- AllowReturnTypeNotation :: No ,
79
- ImplTraitContext :: Disallowed ( ImplTraitPosition :: Path ) ,
80
- None ,
81
- ) ;
21
+ // loop here to avoid recursion
22
+ let pat_hir_id = self . lower_node_id ( pattern. id ) ;
23
+ let node = loop {
24
+ match & pattern. kind {
25
+ PatKind :: Wild => break hir:: PatKind :: Wild ,
26
+ PatKind :: Never => break hir:: PatKind :: Never ,
27
+ PatKind :: Ident ( binding_mode, ident, sub) => {
28
+ let lower_sub = |this : & mut Self | sub. as_ref ( ) . map ( |s| this. lower_pat ( s) ) ;
29
+ break self . lower_pat_ident (
30
+ pattern,
31
+ * binding_mode,
32
+ * ident,
33
+ pat_hir_id,
34
+ lower_sub,
35
+ ) ;
36
+ }
37
+ PatKind :: Lit ( e) => {
38
+ break hir:: PatKind :: Lit ( self . lower_expr_within_pat ( e, false ) ) ;
39
+ }
40
+ PatKind :: TupleStruct ( qself, path, pats) => {
41
+ let qpath = self . lower_qpath (
42
+ pattern. id ,
43
+ qself,
44
+ path,
45
+ ParamMode :: Optional ,
46
+ AllowReturnTypeNotation :: No ,
47
+ ImplTraitContext :: Disallowed ( ImplTraitPosition :: Path ) ,
48
+ None ,
49
+ ) ;
50
+ let ( pats, ddpos) = self . lower_pat_tuple ( pats, "tuple struct" ) ;
51
+ break hir:: PatKind :: TupleStruct ( qpath, pats, ddpos) ;
52
+ }
53
+ PatKind :: Or ( pats) => {
54
+ break hir:: PatKind :: Or (
55
+ self . arena . alloc_from_iter ( pats. iter ( ) . map ( |x| self . lower_pat_mut ( x) ) ) ,
56
+ ) ;
57
+ }
58
+ PatKind :: Path ( qself, path) => {
59
+ let qpath = self . lower_qpath (
60
+ pattern. id ,
61
+ qself,
62
+ path,
63
+ ParamMode :: Optional ,
64
+ AllowReturnTypeNotation :: No ,
65
+ ImplTraitContext :: Disallowed ( ImplTraitPosition :: Path ) ,
66
+ None ,
67
+ ) ;
68
+ break hir:: PatKind :: Path ( qpath) ;
69
+ }
70
+ PatKind :: Struct ( qself, path, fields, etc) => {
71
+ let qpath = self . lower_qpath (
72
+ pattern. id ,
73
+ qself,
74
+ path,
75
+ ParamMode :: Optional ,
76
+ AllowReturnTypeNotation :: No ,
77
+ ImplTraitContext :: Disallowed ( ImplTraitPosition :: Path ) ,
78
+ None ,
79
+ ) ;
82
80
83
- let fs = self . arena . alloc_from_iter ( fields. iter ( ) . map ( |f| {
84
- let hir_id = self . lower_node_id ( f. id ) ;
85
- self . lower_attrs ( hir_id, & f. attrs ) ;
81
+ let fs = self . arena . alloc_from_iter ( fields. iter ( ) . map ( |f| {
82
+ let hir_id = self . lower_node_id ( f. id ) ;
83
+ self . lower_attrs ( hir_id, & f. attrs ) ;
86
84
87
- hir:: PatField {
88
- hir_id,
89
- ident : self . lower_ident ( f. ident ) ,
90
- pat : self . lower_pat ( & f. pat ) ,
91
- is_shorthand : f. is_shorthand ,
92
- span : self . lower_span ( f. span ) ,
93
- }
94
- } ) ) ;
95
- break hir:: PatKind :: Struct ( qpath, fs, * etc == ast:: PatFieldsRest :: Rest ) ;
96
- }
97
- PatKind :: Tuple ( pats) => {
98
- let ( pats, ddpos) = self . lower_pat_tuple ( pats, "tuple" ) ;
99
- break hir:: PatKind :: Tuple ( pats, ddpos) ;
100
- }
101
- PatKind :: Box ( inner) => {
102
- break hir:: PatKind :: Box ( self . lower_pat ( inner) ) ;
103
- }
104
- PatKind :: Deref ( inner) => {
105
- break hir:: PatKind :: Deref ( self . lower_pat ( inner) ) ;
106
- }
107
- PatKind :: Ref ( inner, mutbl) => {
108
- break hir:: PatKind :: Ref ( self . lower_pat ( inner) , * mutbl) ;
109
- }
110
- PatKind :: Range ( e1, e2, Spanned { node : end, .. } ) => {
111
- break hir:: PatKind :: Range (
112
- e1. as_deref ( ) . map ( |e| self . lower_expr_within_pat ( e, true ) ) ,
113
- e2. as_deref ( ) . map ( |e| self . lower_expr_within_pat ( e, true ) ) ,
114
- self . lower_range_end ( end, e2. is_some ( ) ) ,
115
- ) ;
116
- }
117
- // FIXME(guard_patterns): lower pattern guards to HIR
118
- PatKind :: Guard ( inner, _) => pattern = inner,
119
- PatKind :: Slice ( pats) => break self . lower_pat_slice ( pats) ,
120
- PatKind :: Rest => {
121
- // If we reach here the `..` pattern is not semantically allowed.
122
- break self . ban_illegal_rest_pat ( pattern. span ) ;
123
- }
124
- // return inner to be processed in next loop
125
- PatKind :: Paren ( inner) => pattern = inner,
126
- PatKind :: MacCall ( _) => panic ! ( "{:?} shouldn't exist here" , pattern. span) ,
127
- PatKind :: Err ( guar) => break hir:: PatKind :: Err ( * guar) ,
85
+ hir:: PatField {
86
+ hir_id,
87
+ ident : self . lower_ident ( f. ident ) ,
88
+ pat : self . lower_pat ( & f. pat ) ,
89
+ is_shorthand : f. is_shorthand ,
90
+ span : self . lower_span ( f. span ) ,
91
+ }
92
+ } ) ) ;
93
+ break hir:: PatKind :: Struct ( qpath, fs, * etc == ast:: PatFieldsRest :: Rest ) ;
128
94
}
129
- } ;
95
+ PatKind :: Tuple ( pats) => {
96
+ let ( pats, ddpos) = self . lower_pat_tuple ( pats, "tuple" ) ;
97
+ break hir:: PatKind :: Tuple ( pats, ddpos) ;
98
+ }
99
+ PatKind :: Box ( inner) => {
100
+ break hir:: PatKind :: Box ( self . lower_pat ( inner) ) ;
101
+ }
102
+ PatKind :: Deref ( inner) => {
103
+ break hir:: PatKind :: Deref ( self . lower_pat ( inner) ) ;
104
+ }
105
+ PatKind :: Ref ( inner, mutbl) => {
106
+ break hir:: PatKind :: Ref ( self . lower_pat ( inner) , * mutbl) ;
107
+ }
108
+ PatKind :: Range ( e1, e2, Spanned { node : end, .. } ) => {
109
+ break hir:: PatKind :: Range (
110
+ e1. as_deref ( ) . map ( |e| self . lower_expr_within_pat ( e, true ) ) ,
111
+ e2. as_deref ( ) . map ( |e| self . lower_expr_within_pat ( e, true ) ) ,
112
+ self . lower_range_end ( end, e2. is_some ( ) ) ,
113
+ ) ;
114
+ }
115
+ // FIXME(guard_patterns): lower pattern guards to HIR
116
+ PatKind :: Guard ( inner, _) => pattern = inner,
117
+ PatKind :: Slice ( pats) => break self . lower_pat_slice ( pats) ,
118
+ PatKind :: Rest => {
119
+ // If we reach here the `..` pattern is not semantically allowed.
120
+ break self . ban_illegal_rest_pat ( pattern. span ) ;
121
+ }
122
+ // return inner to be processed in next loop
123
+ PatKind :: Paren ( inner) => pattern = inner,
124
+ PatKind :: MacCall ( _) => panic ! ( "{:?} shouldn't exist here" , pattern. span) ,
125
+ PatKind :: Err ( guar) => break hir:: PatKind :: Err ( * guar) ,
126
+ }
127
+ } ;
130
128
131
- self . pat_with_node_id_of ( pattern, node, pat_hir_id)
132
- } )
129
+ self . pat_with_node_id_of ( pattern, node, pat_hir_id)
133
130
}
134
131
135
132
fn lower_pat_tuple (
0 commit comments