@@ -13,7 +13,8 @@ use self::Usefulness::*;
13
13
use self :: WitnessPreference :: * ;
14
14
15
15
use middle:: const_eval:: { compare_const_vals, const_bool, const_float, const_val} ;
16
- use middle:: const_eval:: { const_expr_to_pat, eval_const_expr, lookup_const_by_id} ;
16
+ use middle:: const_eval:: { eval_const_expr, eval_const_expr_partial} ;
17
+ use middle:: const_eval:: { const_expr_to_pat, lookup_const_by_id} ;
17
18
use middle:: def:: * ;
18
19
use middle:: expr_use_visitor:: { ConsumeMode , Delegate , ExprUseVisitor , Init } ;
19
20
use middle:: expr_use_visitor:: { JustWrite , LoanCause , MutateMode } ;
@@ -229,13 +230,6 @@ fn check_expr(cx: &mut MatchCheckCtxt, ex: &ast::Expr) {
229
230
}
230
231
}
231
232
232
- fn is_expr_const_nan ( tcx : & ty:: ctxt , expr : & ast:: Expr ) -> bool {
233
- match eval_const_expr ( tcx, expr) {
234
- const_float( f) => f. is_nan ( ) ,
235
- _ => false
236
- }
237
- }
238
-
239
233
fn check_for_bindings_named_the_same_as_variants ( cx : & MatchCheckCtxt , pat : & Pat ) {
240
234
ast_util:: walk_pat ( pat, |p| {
241
235
match p. node {
@@ -269,13 +263,26 @@ fn check_for_bindings_named_the_same_as_variants(cx: &MatchCheckCtxt, pat: &Pat)
269
263
// Check that we do not match against a static NaN (#6804)
270
264
fn check_for_static_nan ( cx : & MatchCheckCtxt , pat : & Pat ) {
271
265
ast_util:: walk_pat ( pat, |p| {
272
- match p. node {
273
- ast:: PatLit ( ref expr) if is_expr_const_nan ( cx. tcx , & * * expr) => {
274
- span_warn ! ( cx. tcx. sess, p. span, E0003 ,
275
- "unmatchable NaN in pattern, \
276
- use the is_nan method in a guard instead") ;
266
+ if let ast:: PatLit ( ref expr) = p. node {
267
+ match eval_const_expr_partial ( cx. tcx , & * * expr, None ) {
268
+ Ok ( const_float( f) ) if f. is_nan ( ) => {
269
+ span_warn ! ( cx. tcx. sess, p. span, E0003 ,
270
+ "unmatchable NaN in pattern, \
271
+ use the is_nan method in a guard instead") ;
272
+ }
273
+ Ok ( _) => { }
274
+
275
+ Err ( err) => {
276
+ let subspan = p. span . lo <= err. span . lo && err. span . hi <= p. span . hi ;
277
+ cx. tcx . sess . span_err ( err. span ,
278
+ & format ! ( "constant evaluation error: {}" ,
279
+ err. description( ) . as_slice( ) ) ) ;
280
+ if !subspan {
281
+ cx. tcx . sess . span_note ( p. span ,
282
+ "in pattern here" )
283
+ }
284
+ }
277
285
}
278
- _ => ( )
279
286
}
280
287
true
281
288
} ) ;
0 commit comments