diff options
| author | Oliver Schneider <git-spam-no-reply9815368754983@oli-obk.de> | 2016-03-16 10:54:00 +0100 |
|---|---|---|
| committer | Oliver Schneider <git-spam-no-reply9815368754983@oli-obk.de> | 2016-03-16 10:54:00 +0100 |
| commit | 7a2c50f9512ff5816aeb5e3341d0b3c217ba88f8 (patch) | |
| tree | 06342af4073b06c2c75b9403af04ee640fc51244 | |
| parent | 0986d645b9d3f01e102c84fb91abf42de00e7b28 (diff) | |
| download | rust-7a2c50f9512ff5816aeb5e3341d0b3c217ba88f8.tar.gz rust-7a2c50f9512ff5816aeb5e3341d0b3c217ba88f8.zip | |
don't assume the rhs of a bitshift is of any particular type
| -rw-r--r-- | src/librustc/middle/const_eval.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass/const-bitshift-rhs-inference.rs | 33 |
2 files changed, 34 insertions, 1 deletions
diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index 8a1a0080eb0..5d4226fe4ce 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -671,7 +671,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &TyCtxt<'tcx>, } hir::ExprBinary(op, ref a, ref b) => { let b_ty = match op.node { - hir::BiShl | hir::BiShr => ty_hint.checked_or(tcx.types.usize), + hir::BiShl | hir::BiShr => ty_hint.erase_hint(), _ => ty_hint }; // technically, if we don't have type hints, but integral eval diff --git a/src/test/run-pass/const-bitshift-rhs-inference.rs b/src/test/run-pass/const-bitshift-rhs-inference.rs new file mode 100644 index 00000000000..b377fd230b9 --- /dev/null +++ b/src/test/run-pass/const-bitshift-rhs-inference.rs @@ -0,0 +1,33 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +const RHS: u8 = 8; +const IRHS: i8 = 8; +const RHS16: u16 = 8; +const IRHS16: i16 = 8; +const RHS32: u32 = 8; +const IRHS32: i32 = 8; +const RHS64: u64 = 8; +const IRHS64: i64 = 8; +const RHSUS: usize = 8; +const IRHSIS: isize = 8; + +fn main() { + let _: [&'static str; 1 << RHS] = [""; 256]; + let _: [&'static str; 1 << IRHS] = [""; 256]; + let _: [&'static str; 1 << RHS16] = [""; 256]; + let _: [&'static str; 1 << IRHS16] = [""; 256]; + let _: [&'static str; 1 << RHS32] = [""; 256]; + let _: [&'static str; 1 << IRHS32] = [""; 256]; + let _: [&'static str; 1 << RHS64] = [""; 256]; + let _: [&'static str; 1 << IRHS64] = [""; 256]; + let _: [&'static str; 1 << RHSUS] = [""; 256]; + let _: [&'static str; 1 << IRHSIS] = [""; 256]; +} |
