@@ -23,15 +23,13 @@ use rustc_span::{sym, Span, Symbol};
23
23
enum NonConstExpr {
24
24
Loop ( hir:: LoopSource ) ,
25
25
Match ( hir:: MatchSource ) ,
26
- OrPattern ,
27
26
}
28
27
29
28
impl NonConstExpr {
30
29
fn name ( self ) -> String {
31
30
match self {
32
31
Self :: Loop ( src) => format ! ( "`{}`" , src. name( ) ) ,
33
32
Self :: Match ( src) => format ! ( "`{}`" , src. name( ) ) ,
34
- Self :: OrPattern => "or-pattern" . to_string ( ) ,
35
33
}
36
34
}
37
35
@@ -40,22 +38,19 @@ impl NonConstExpr {
40
38
use hir:: MatchSource :: * ;
41
39
42
40
let gates: & [ _ ] = match self {
43
- Self :: Match ( Normal )
44
- | Self :: Match ( IfDesugar { .. } )
45
- | Self :: Match ( IfLetDesugar { .. } )
46
- | Self :: OrPattern => & [ sym :: const_if_match ] ,
47
-
48
- Self :: Loop ( Loop ) => & [ sym :: const_loop ] ,
41
+ // A `for` loop's desugaring contains a call to `IntoIterator::into_iter`,
42
+ // so they are not yet allowed with `#![feature(const_loop)]`.
43
+ // Likewise, `?` desugars to a call to `Try::into_result`.
44
+ Self :: Loop ( ForLoop ) | Self :: Match ( ForLoopDesugar | TryDesugar | AwaitDesugar ) => {
45
+ return None ;
46
+ }
49
47
50
- Self :: Loop ( While )
51
- | Self :: Loop ( WhileLet )
52
- | Self :: Match ( WhileDesugar | WhileLetDesugar ) => {
53
- & [ sym:: const_loop, sym:: const_if_match]
48
+ Self :: Loop ( Loop | While | WhileLet ) | Self :: Match ( WhileDesugar | WhileLetDesugar ) => {
49
+ & [ sym:: const_loop]
54
50
}
55
51
56
- // A `for` loop's desugaring contains a call to `IntoIterator::into_iter`,
57
- // so they are not yet allowed with `#![feature(const_loop)]`.
58
- _ => return None ,
52
+ // All other matches are allowed.
53
+ Self :: Match ( Normal | IfDesugar { .. } | IfLetDesugar { .. } ) => & [ ] ,
59
54
} ;
60
55
61
56
Some ( gates)
@@ -114,17 +109,6 @@ impl<'tcx> CheckConstVisitor<'tcx> {
114
109
match missing_gates. as_slice ( ) {
115
110
& [ ] => struct_span_err ! ( self . tcx. sess, span, E0744 , "{}" , msg) . emit ( ) ,
116
111
117
- // If the user enabled `#![feature(const_loop)]` but not `#![feature(const_if_match)]`,
118
- // explain why their `while` loop is being rejected.
119
- & [ gate @ sym:: const_if_match] if required_gates. contains ( & sym:: const_loop) => {
120
- feature_err ( & self . tcx . sess . parse_sess , gate, span, & msg)
121
- . note (
122
- "`#![feature(const_loop)]` alone is not sufficient, \
123
- since this loop expression contains an implicit conditional",
124
- )
125
- . emit ( ) ;
126
- }
127
-
128
112
& [ missing_primary, ref missing_secondary @ ..] => {
129
113
let mut err = feature_err ( & self . tcx . sess . parse_sess , missing_primary, span, & msg) ;
130
114
@@ -175,15 +159,6 @@ impl<'tcx> Visitor<'tcx> for CheckConstVisitor<'tcx> {
175
159
self . recurse_into ( kind, |this| intravisit:: walk_body ( this, body) ) ;
176
160
}
177
161
178
- fn visit_pat ( & mut self , p : & ' tcx hir:: Pat < ' tcx > ) {
179
- if self . const_kind . is_some ( ) {
180
- if let hir:: PatKind :: Or { .. } = p. kind {
181
- self . const_check_violated ( NonConstExpr :: OrPattern , p. span ) ;
182
- }
183
- }
184
- intravisit:: walk_pat ( self , p)
185
- }
186
-
187
162
fn visit_expr ( & mut self , e : & ' tcx hir:: Expr < ' tcx > ) {
188
163
match & e. kind {
189
164
// Skip the following checks if we are not currently in a const context.
0 commit comments