Skip to content

Commit d3c489c

Browse files
committed
don't demote expressions just because const_eval fails
this might introduce subtle bugs to code generation
1 parent 9d7ed99 commit d3c489c

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

src/librustc_passes/consts.rs

-1
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,6 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
498498
Err(ConstEvalErr { kind: Math(ConstMathErr::Overflow(Op::Shl)), ..}) |
499499
Err(ConstEvalErr { kind: IndexOpFeatureGated, ..}) => {},
500500
Err(msg) => {
501-
self.qualif = self.qualif | ConstQualif::NOT_CONST;
502501
self.tcx.sess.add_lint(CONST_ERR, ex.id,
503502
msg.span,
504503
msg.description().into_owned())

src/test/compile-fail/const-err.rs

+5
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// these errors are not actually "const_err", they occur in trans/consts
12+
// and are unconditional warnings that can't be denied or allowed
13+
1114
#![feature(rustc_attrs)]
1215
#![allow(exceeding_bitshifts)]
16+
#![allow(const_err)]
1317

1418
fn black_box<T>(_: T) {
1519
unimplemented!()
@@ -21,6 +25,7 @@ fn main() {
2125
//~^ WARN attempted to negate with overflow
2226
let b = 200u8 + 200u8 + 200u8;
2327
//~^ WARN attempted to add with overflow
28+
//~| WARN attempted to add with overflow
2429
let c = 200u8 * 4;
2530
//~^ WARN attempted to multiply with overflow
2631
let d = 42u8 - (42u8 + 1);

src/test/compile-fail/const-err2.rs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2012 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+
#![feature(rustc_attrs)]
12+
#![allow(exceeding_bitshifts)]
13+
#![deny(const_err)]
14+
15+
fn black_box<T>(_: T) {
16+
unimplemented!()
17+
}
18+
19+
fn main() {
20+
let a = -std::i8::MIN;
21+
//~^ ERROR attempted to negate with overflow
22+
let b = 200u8 + 200u8 + 200u8;
23+
//~^ ERROR attempted to add with overflow
24+
//~| ERROR attempted to add with overflow
25+
let c = 200u8 * 4;
26+
//~^ ERROR attempted to multiply with overflow
27+
let d = 42u8 - (42u8 + 1);
28+
//~^ ERROR attempted to subtract with overflow
29+
let _e = [5u8][1];
30+
black_box(a);
31+
black_box(b);
32+
black_box(c);
33+
black_box(d);
34+
}

0 commit comments

Comments
 (0)