Skip to content

Commit c6d25dc

Browse files
committed
Don't ICE on horrible transmutes in pattern constants
1 parent 1a2964a commit c6d25dc

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

src/librustc_mir/hair/pattern/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,9 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
364364
lo,
365365
hi,
366366
self.param_env.and(ty),
367-
).unwrap();
367+
);
368368
match (end, cmp) {
369-
(RangeEnd::Excluded, Ordering::Less) =>
369+
(RangeEnd::Excluded, Some(Ordering::Less)) =>
370370
PatternKind::Range { lo, hi, end },
371371
(RangeEnd::Excluded, _) => {
372372
span_err!(
@@ -377,7 +377,8 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
377377
);
378378
PatternKind::Wild
379379
},
380-
(RangeEnd::Included, Ordering::Greater) => {
380+
(RangeEnd::Included, None) |
381+
(RangeEnd::Included, Some(Ordering::Greater)) => {
381382
let mut err = struct_span_err!(
382383
self.tcx.sess,
383384
lo_expr.span,
@@ -398,7 +399,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
398399
err.emit();
399400
PatternKind::Wild
400401
},
401-
(RangeEnd::Included, _) => PatternKind::Range { lo, hi, end },
402+
(RangeEnd::Included, Some(_)) => PatternKind::Range { lo, hi, end },
402403
}
403404
}
404405
_ => PatternKind::Wild
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
match 40u64 {
13+
0...10 => {},
14+
10...BAR => {}, //~ ERROR lower range bound must be less than or equal to upper
15+
_ => {},
16+
}
17+
}
18+
19+
union Foo {
20+
f: Int,
21+
r: &'static u32,
22+
}
23+
24+
#[cfg(target_pointer_width="64")]
25+
type Int = u64;
26+
27+
#[cfg(target_pointer_width="32")]
28+
type Int = u32;
29+
30+
const BAR: Int = unsafe { Foo { r: &42 }.f };
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0030]: lower range bound must be less than or equal to upper
2+
--> $DIR/ref_to_int_match.rs:14:9
3+
|
4+
LL | 10...BAR => {}, //~ ERROR lower range bound must be less than or equal to upper
5+
| ^^ lower bound larger than upper bound
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0030`.

0 commit comments

Comments
 (0)