Skip to content

Commit 7a2c50f

Browse files
committed
don't assume the rhs of a bitshift is of any particular type
1 parent 0986d64 commit 7a2c50f

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/librustc/middle/const_eval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &TyCtxt<'tcx>,
671671
}
672672
hir::ExprBinary(op, ref a, ref b) => {
673673
let b_ty = match op.node {
674-
hir::BiShl | hir::BiShr => ty_hint.checked_or(tcx.types.usize),
674+
hir::BiShl | hir::BiShr => ty_hint.erase_hint(),
675675
_ => ty_hint
676676
};
677677
// technically, if we don't have type hints, but integral eval
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2016 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+
const RHS: u8 = 8;
12+
const IRHS: i8 = 8;
13+
const RHS16: u16 = 8;
14+
const IRHS16: i16 = 8;
15+
const RHS32: u32 = 8;
16+
const IRHS32: i32 = 8;
17+
const RHS64: u64 = 8;
18+
const IRHS64: i64 = 8;
19+
const RHSUS: usize = 8;
20+
const IRHSIS: isize = 8;
21+
22+
fn main() {
23+
let _: [&'static str; 1 << RHS] = [""; 256];
24+
let _: [&'static str; 1 << IRHS] = [""; 256];
25+
let _: [&'static str; 1 << RHS16] = [""; 256];
26+
let _: [&'static str; 1 << IRHS16] = [""; 256];
27+
let _: [&'static str; 1 << RHS32] = [""; 256];
28+
let _: [&'static str; 1 << IRHS32] = [""; 256];
29+
let _: [&'static str; 1 << RHS64] = [""; 256];
30+
let _: [&'static str; 1 << IRHS64] = [""; 256];
31+
let _: [&'static str; 1 << RHSUS] = [""; 256];
32+
let _: [&'static str; 1 << IRHSIS] = [""; 256];
33+
}

0 commit comments

Comments
 (0)