Rollup merge of #34497 - oli-obk:double_negation, r=eddyb
Revert "skip double negation in const eval"
This reverts commit 735c018974
.
fixes #34395
The original commit was based on a mis-understanding of the overflowing literal lint.
This needs to be ported to beta.
r? @eddyb
This commit is contained in:
commit
2e893ea6de
2 changed files with 42 additions and 48 deletions
|
@ -543,8 +543,7 @@ pub fn eval_const_expr_partial<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
let result = match e.node {
|
||||
hir::ExprUnary(hir::UnNeg, ref inner) => {
|
||||
// unary neg literals already got their sign during creation
|
||||
match inner.node {
|
||||
hir::ExprLit(ref lit) => {
|
||||
if let hir::ExprLit(ref lit) = inner.node {
|
||||
use syntax::ast::*;
|
||||
use syntax::ast::LitIntType::*;
|
||||
const I8_OVERFLOW: u64 = ::std::i8::MAX as u64 + 1;
|
||||
|
@ -585,12 +584,6 @@ pub fn eval_const_expr_partial<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
},
|
||||
_ => {},
|
||||
}
|
||||
},
|
||||
hir::ExprUnary(hir::UnNeg, ref inner) => {
|
||||
// skip `--$expr`
|
||||
return eval_const_expr_partial(tcx, inner, ty_hint, fn_args);
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
match eval_const_expr_partial(tcx, &inner, ty_hint, fn_args)? {
|
||||
Float(f) => Float(-f),
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#[allow(unused_variables)]
|
||||
fn main() {
|
||||
let x2: i8 = --128; //~ error: literal out of range for i8
|
||||
//~^ error: attempted to negate with overflow
|
||||
|
||||
let x = -3.40282348e+38_f32; //~ error: literal out of range for f32
|
||||
let x = 3.40282348e+38_f32; //~ error: literal out of range for f32
|
||||
|
|
Loading…
Add table
Reference in a new issue