Skip to content

Commit 77d2f1c

Browse files
committed
---
yaml --- r: 64703 b: refs/heads/snap-stage3 c: fdd71be h: refs/heads/master i: 64701: 7b0a0c4 64699: 9b6e63b 64695: 0961075 64687: 5b186cc 64671: a59e9c7 64639: f6daf75 v: v3
1 parent e402d0a commit 77d2f1c

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 5c729c0dca65a014b6dec10cfd5259c6d0687d72
4+
refs/heads/snap-stage3: fdd71bece23b3d6776ca86336749e50560617a56
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/librustc/middle/check_match.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,23 @@ pub fn check_arms(cx: &MatchCheckCtxt, arms: &[arm]) {
104104
for arm.pats.iter().advance |pat| {
105105

106106
// Check that we do not match against a static NaN (#6804)
107-
match cx.tcx.def_map.find(&pat.id) {
108-
Some(&def_static(did, false)) => {
109-
let const_expr = lookup_const_by_id(cx.tcx, did).get();
110-
match eval_const_expr(cx.tcx, const_expr) {
111-
const_float(f) if f.is_NaN() => {
112-
let msg = "unmatchable NaN in pattern, use is_NaN() in a guard instead";
113-
cx.tcx.sess.span_warn(pat.span, msg);
107+
let pat_matches_nan: &fn(@pat) -> bool = |p| {
108+
match cx.tcx.def_map.find(&p.id) {
109+
Some(&def_static(did, false)) => {
110+
let const_expr = lookup_const_by_id(cx.tcx, did).get();
111+
match eval_const_expr(cx.tcx, const_expr) {
112+
const_float(f) if f.is_NaN() => true,
113+
_ => false
114114
}
115-
_ => {}
116115
}
116+
_ => false
117+
}
118+
};
119+
for walk_pat(*pat) |p| {
120+
if pat_matches_nan(p) {
121+
cx.tcx.sess.span_warn(p.span, "unmatchable NaN in pattern, \
122+
use is_NaN() in a guard instead");
117123
}
118-
_ => {}
119124
}
120125

121126
let v = ~[*pat];

branches/snap-stage3/src/test/compile-fail/issue-6804.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ fn main() {
99
_ => {},
1010
};
1111
//~^^^ WARNING unmatchable NaN in pattern, use is_NaN() in a guard instead
12+
match [x, 1.0] {
13+
[NaN, _] => {},
14+
_ => {},
15+
};
16+
//~^^^ WARNING unmatchable NaN in pattern, use is_NaN() in a guard instead
1217
}
1318

1419
// At least one error is needed so that compilation fails

0 commit comments

Comments
 (0)