1
Fork 0

Errors in promoteds may only cause lints not hard errors

This commit is contained in:
Oliver Scherer 2020-01-08 21:31:08 +01:00
parent 6e1bbff2c6
commit ecd5852194
19 changed files with 157 additions and 176 deletions

View file

@ -20,10 +20,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
// use `get_static` to get at their id. // use `get_static` to get at their id.
// FIXME(oli-obk): can we unify this somehow, maybe by making const eval of statics // FIXME(oli-obk): can we unify this somehow, maybe by making const eval of statics
// always produce `&STATIC`. This may also simplify how const eval works with statics. // always produce `&STATIC`. This may also simplify how const eval works with statics.
ty::ConstKind::Unevaluated(def_id, substs, promoted) ty::ConstKind::Unevaluated(def_id, substs, None) if self.cx.tcx().is_static(def_id) => {
if self.cx.tcx().is_static(def_id) =>
{
assert!(promoted.is_none());
assert!(substs.is_empty(), "we don't support generic statics yet"); assert!(substs.is_empty(), "we don't support generic statics yet");
let static_ = bx.get_static(def_id); let static_ = bx.get_static(def_id);
// we treat operands referring to statics as if they were `&STATIC` instead // we treat operands referring to statics as if they were `&STATIC` instead
@ -49,10 +46,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
.tcx() .tcx()
.const_eval_resolve(ty::ParamEnv::reveal_all(), def_id, substs, promoted, None) .const_eval_resolve(ty::ParamEnv::reveal_all(), def_id, substs, promoted, None)
.map_err(|err| { .map_err(|err| {
if promoted.is_none() {
self.cx self.cx
.tcx() .tcx()
.sess .sess
.span_err(constant.span, "erroneous constant encountered"); .span_err(constant.span, "erroneous constant encountered");
}
err err
}) })
} }

View file

@ -18,7 +18,7 @@ use rustc::ty::layout::{
HasDataLayout, HasTyCtxt, LayoutError, LayoutOf, Size, TargetDataLayout, TyLayout, HasDataLayout, HasTyCtxt, LayoutError, LayoutOf, Size, TargetDataLayout, TyLayout,
}; };
use rustc::ty::subst::{InternalSubsts, Subst}; use rustc::ty::subst::{InternalSubsts, Subst};
use rustc::ty::{self, Instance, ParamEnv, Ty, TyCtxt, TypeFoldable}; use rustc::ty::{self, ConstKind, Instance, ParamEnv, Ty, TyCtxt, TypeFoldable};
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_hir::def::DefKind; use rustc_hir::def::DefKind;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
@ -441,8 +441,15 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
Ok(op) => Some(op), Ok(op) => Some(op),
Err(error) => { Err(error) => {
let err = error_to_const_error(&self.ecx, error); let err = error_to_const_error(&self.ecx, error);
match self.lint_root(source_info) { if let Some(lint_root) = self.lint_root(source_info) {
Some(lint_root) if c.literal.needs_subst() => { let lint_only = match c.literal.val {
// Promoteds must lint and not error as the user didn't ask for them
ConstKind::Unevaluated(_, _, Some(_)) => true,
// Out of backwards compatibility we cannot report hard errors in unused
// generic functions using associated constants of the generic parameters.
_ => c.literal.needs_subst(),
};
if lint_only {
// Out of backwards compatibility we cannot report hard errors in unused // Out of backwards compatibility we cannot report hard errors in unused
// generic functions using associated constants of the generic parameters. // generic functions using associated constants of the generic parameters.
err.report_as_lint( err.report_as_lint(
@ -451,10 +458,11 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
lint_root, lint_root,
Some(c.span), Some(c.span),
); );
} } else {
_ => {
err.report_as_error(self.ecx.tcx, "erroneous constant used"); err.report_as_error(self.ecx.tcx, "erroneous constant used");
} }
} else {
err.report_as_error(self.ecx.tcx, "erroneous constant used");
} }
None None
} }

View file

@ -1,6 +1,6 @@
#![allow(const_err)] #![allow(const_err)]
// error-pattern: referenced constant has errors // error-pattern: attempt to divide by zero
fn main() { fn main() {
let x = &(1 / (1 - 1)); let x = &(1 / (1 - 1));

View file

@ -1,8 +1,10 @@
// build-fail // build-pass
#![warn(const_err)]
fn main() { fn main() {
&{[1, 2, 3][4]}; &{ [1, 2, 3][4] };
//~^ ERROR index out of bounds //~^ WARN index out of bounds
//~| ERROR reaching this expression at runtime will panic or abort //~| WARN reaching this expression at runtime will panic or abort
//~| ERROR erroneous constant used [E0080] //~| WARN erroneous constant used [const_err]
} }

View file

@ -1,25 +1,26 @@
error: index out of bounds: the len is 3 but the index is 4 warning: index out of bounds: the len is 3 but the index is 4
--> $DIR/array-literal-index-oob.rs:4:7 --> $DIR/array-literal-index-oob.rs:6:8
| |
LL | &{[1, 2, 3][4]}; LL | &{ [1, 2, 3][4] };
| ^^^^^^^^^^^^ | ^^^^^^^^^^^^
| |
= note: `#[deny(const_err)]` on by default note: lint level defined here
--> $DIR/array-literal-index-oob.rs:3:9
error: reaching this expression at runtime will panic or abort
--> $DIR/array-literal-index-oob.rs:4:7
| |
LL | &{[1, 2, 3][4]}; LL | #![warn(const_err)]
| --^^^^^^^^^^^^- | ^^^^^^^^^
warning: reaching this expression at runtime will panic or abort
--> $DIR/array-literal-index-oob.rs:6:8
|
LL | &{ [1, 2, 3][4] };
| ---^^^^^^^^^^^^--
| | | |
| indexing out of bounds: the len is 3 but the index is 4 | indexing out of bounds: the len is 3 but the index is 4
error[E0080]: erroneous constant used warning: erroneous constant used
--> $DIR/array-literal-index-oob.rs:4:5 --> $DIR/array-literal-index-oob.rs:6:5
| |
LL | &{[1, 2, 3][4]}; LL | &{ [1, 2, 3][4] };
| ^^^^^^^^^^^^^^^ referenced constant has errors | ^^^^^^^^^^^^^^^^^ referenced constant has errors
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0080`.

View file

@ -10,5 +10,5 @@ const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
fn main() { fn main() {
println!("{}", FOO); println!("{}", FOO);
//~^ ERROR //~^ ERROR
//~| ERROR erroneous constant used [E0080] //~| WARN erroneous constant used [const_err]
} }

View file

@ -18,12 +18,12 @@ error[E0080]: evaluation of constant expression failed
LL | println!("{}", FOO); LL | println!("{}", FOO);
| ^^^ referenced constant has errors | ^^^ referenced constant has errors
error[E0080]: erroneous constant used warning: erroneous constant used
--> $DIR/conditional_array_execution.rs:11:20 --> $DIR/conditional_array_execution.rs:11:20
| |
LL | println!("{}", FOO); LL | println!("{}", FOO);
| ^^^ referenced constant has errors | ^^^ referenced constant has errors
error: aborting due to 2 previous errors error: aborting due to previous error
For more information about this error, try `rustc --explain E0080`. For more information about this error, try `rustc --explain E0080`.

View file

@ -4,7 +4,9 @@
#![feature(const_fn)] #![feature(const_fn)]
#![allow(const_err)] #![allow(const_err)]
fn double(x: usize) -> usize { x * 2 } fn double(x: usize) -> usize {
x * 2
}
const X: fn(usize) -> usize = double; const X: fn(usize) -> usize = double;
const fn bar(x: fn(usize) -> usize, y: usize) -> usize { const fn bar(x: fn(usize) -> usize, y: usize) -> usize {
@ -17,8 +19,6 @@ const Z: usize = bar(double, 2); // FIXME: should fail to typeck someday
fn main() { fn main() {
assert_eq!(Y, 4); assert_eq!(Y, 4);
//~^ ERROR evaluation of constant expression failed //~^ ERROR evaluation of constant expression failed
//~| ERROR erroneous constant used [E0080]
assert_eq!(Z, 4); assert_eq!(Z, 4);
//~^ ERROR evaluation of constant expression failed //~^ ERROR evaluation of constant expression failed
//~| ERROR erroneous constant used [E0080]
} }

View file

@ -1,11 +1,11 @@
warning: skipping const checks warning: skipping const checks
--> $DIR/const_fn_ptr_fail2.rs:11:5 --> $DIR/const_fn_ptr_fail2.rs:13:5
| |
LL | x(y) LL | x(y)
| ^^^^ | ^^^^
error[E0080]: evaluation of constant expression failed error[E0080]: evaluation of constant expression failed
--> $DIR/const_fn_ptr_fail2.rs:18:5 --> $DIR/const_fn_ptr_fail2.rs:20:5
| |
LL | assert_eq!(Y, 4); LL | assert_eq!(Y, 4);
| ^^^^^^^^^^^-^^^^^ | ^^^^^^^^^^^-^^^^^
@ -14,16 +14,8 @@ LL | assert_eq!(Y, 4);
| |
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error[E0080]: erroneous constant used
--> $DIR/const_fn_ptr_fail2.rs:18:5
|
LL | assert_eq!(Y, 4);
| ^^^^^^^^^^^^^^^^^ referenced constant has errors
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error[E0080]: evaluation of constant expression failed error[E0080]: evaluation of constant expression failed
--> $DIR/const_fn_ptr_fail2.rs:21:5 --> $DIR/const_fn_ptr_fail2.rs:22:5
| |
LL | assert_eq!(Z, 4); LL | assert_eq!(Z, 4);
| ^^^^^^^^^^^-^^^^^ | ^^^^^^^^^^^-^^^^^
@ -32,14 +24,6 @@ LL | assert_eq!(Z, 4);
| |
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error[E0080]: erroneous constant used error: aborting due to 2 previous errors
--> $DIR/const_fn_ptr_fail2.rs:21:5
|
LL | assert_eq!(Z, 4);
| ^^^^^^^^^^^^^^^^^ referenced constant has errors
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0080`. For more information about this error, try `rustc --explain E0080`.

View file

@ -7,13 +7,13 @@ const fn foo(x: u32) -> u32 {
} }
fn main() { fn main() {
const X: u32 = 0-1; const X: u32 = 0 - 1;
//~^ WARN any use of this value will cause //~^ WARN any use of this value will cause
const Y: u32 = foo(0-1); const Y: u32 = foo(0 - 1);
//~^ WARN any use of this value will cause //~^ WARN any use of this value will cause
println!("{} {}", X, Y); println!("{} {}", X, Y);
//~^ ERROR evaluation of constant expression failed //~^ ERROR evaluation of constant expression failed
//~| ERROR evaluation of constant expression failed //~| ERROR evaluation of constant expression failed
//~| ERROR erroneous constant used [E0080] //~| WARN erroneous constant used [const_err]
//~| ERROR erroneous constant used [E0080] //~| WARN erroneous constant used [const_err]
} }

View file

@ -1,8 +1,8 @@
warning: any use of this value will cause an error warning: any use of this value will cause an error
--> $DIR/issue-43197.rs:10:20 --> $DIR/issue-43197.rs:10:20
| |
LL | const X: u32 = 0-1; LL | const X: u32 = 0 - 1;
| ---------------^^^- | ---------------^^^^^-
| | | |
| attempt to subtract with overflow | attempt to subtract with overflow
| |
@ -15,8 +15,8 @@ LL | #![warn(const_err)]
warning: any use of this value will cause an error warning: any use of this value will cause an error
--> $DIR/issue-43197.rs:12:24 --> $DIR/issue-43197.rs:12:24
| |
LL | const Y: u32 = foo(0-1); LL | const Y: u32 = foo(0 - 1);
| -------------------^^^-- | -------------------^^^^^--
| | | |
| attempt to subtract with overflow | attempt to subtract with overflow
@ -26,7 +26,7 @@ error[E0080]: evaluation of constant expression failed
LL | println!("{} {}", X, Y); LL | println!("{} {}", X, Y);
| ^ referenced constant has errors | ^ referenced constant has errors
error[E0080]: erroneous constant used warning: erroneous constant used
--> $DIR/issue-43197.rs:14:23 --> $DIR/issue-43197.rs:14:23
| |
LL | println!("{} {}", X, Y); LL | println!("{} {}", X, Y);
@ -38,12 +38,12 @@ error[E0080]: evaluation of constant expression failed
LL | println!("{} {}", X, Y); LL | println!("{} {}", X, Y);
| ^ referenced constant has errors | ^ referenced constant has errors
error[E0080]: erroneous constant used warning: erroneous constant used
--> $DIR/issue-43197.rs:14:26 --> $DIR/issue-43197.rs:14:26
| |
LL | println!("{} {}", X, Y); LL | println!("{} {}", X, Y);
| ^ referenced constant has errors | ^ referenced constant has errors
error: aborting due to 4 previous errors error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0080`. For more information about this error, try `rustc --explain E0080`.

View file

@ -25,6 +25,5 @@ impl Foo for u16 {
fn main() { fn main() {
println!("{}", <Bar<u16, u8> as Foo>::AMT); println!("{}", <Bar<u16, u8> as Foo>::AMT);
//~^ ERROR erroneous constant used [E0080] //~^ ERROR evaluation of constant expression failed [E0080]
//~| ERROR evaluation of constant expression failed [E0080]
} }

View file

@ -4,12 +4,6 @@ error[E0080]: evaluation of constant expression failed
LL | println!("{}", <Bar<u16, u8> as Foo>::AMT); LL | println!("{}", <Bar<u16, u8> as Foo>::AMT);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors | ^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
error[E0080]: erroneous constant used error: aborting due to previous error
--> $DIR/issue-44578.rs:27:20
|
LL | println!("{}", <Bar<u16, u8> as Foo>::AMT);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0080`. For more information about this error, try `rustc --explain E0080`.

View file

@ -1,22 +1,22 @@
// build-fail // build-pass
// compile-flags: -O // compile-flags: -O
#![deny(const_err)] #![warn(const_err)]
fn main() { fn main() {
println!("{}", 0u32 - 1); println!("{}", 0u32 - 1);
let _x = 0u32 - 1; let _x = 0u32 - 1;
//~^ ERROR const_err //~^ WARN const_err
println!("{}", 1/(1-1)); println!("{}", 1 / (1 - 1));
//~^ ERROR attempt to divide by zero [const_err] //~^ WARN attempt to divide by zero [const_err]
//~| ERROR const_err //~| WARN const_err
//~| ERROR erroneous constant used [E0080] //~| WARN erroneous constant used [const_err]
let _x = 1/(1-1); let _x = 1 / (1 - 1);
//~^ ERROR const_err //~^ WARN const_err
println!("{}", 1/(false as u32)); println!("{}", 1 / (false as u32));
//~^ ERROR attempt to divide by zero [const_err] //~^ WARN attempt to divide by zero [const_err]
//~| ERROR const_err //~| WARN const_err
//~| ERROR erroneous constant used [E0080] //~| WARN erroneous constant used [const_err]
let _x = 1/(false as u32); let _x = 1 / (false as u32);
//~^ ERROR const_err //~^ WARN const_err
} }

View file

@ -1,4 +1,4 @@
error: this expression will panic at runtime warning: this expression will panic at runtime
--> $DIR/promoted_errors.rs:8:14 --> $DIR/promoted_errors.rs:8:14
| |
LL | let _x = 0u32 - 1; LL | let _x = 0u32 - 1;
@ -7,57 +7,54 @@ LL | let _x = 0u32 - 1;
note: lint level defined here note: lint level defined here
--> $DIR/promoted_errors.rs:4:9 --> $DIR/promoted_errors.rs:4:9
| |
LL | #![deny(const_err)] LL | #![warn(const_err)]
| ^^^^^^^^^ | ^^^^^^^^^
error: attempt to divide by zero warning: attempt to divide by zero
--> $DIR/promoted_errors.rs:10:20 --> $DIR/promoted_errors.rs:10:20
| |
LL | println!("{}", 1/(1-1)); LL | println!("{}", 1 / (1 - 1));
| ^^^^^^^ | ^^^^^^^^^^^
error: reaching this expression at runtime will panic or abort warning: reaching this expression at runtime will panic or abort
--> $DIR/promoted_errors.rs:10:20 --> $DIR/promoted_errors.rs:10:20
| |
LL | println!("{}", 1/(1-1)); LL | println!("{}", 1 / (1 - 1));
| ^^^^^^^ dividing by zero | ^^^^^^^^^^^ dividing by zero
error[E0080]: erroneous constant used warning: erroneous constant used
--> $DIR/promoted_errors.rs:10:20 --> $DIR/promoted_errors.rs:10:20
| |
LL | println!("{}", 1/(1-1)); LL | println!("{}", 1 / (1 - 1));
| ^^^^^^^ referenced constant has errors | ^^^^^^^^^^^ referenced constant has errors
error: attempt to divide by zero warning: attempt to divide by zero
--> $DIR/promoted_errors.rs:14:14 --> $DIR/promoted_errors.rs:14:14
| |
LL | let _x = 1/(1-1); LL | let _x = 1 / (1 - 1);
| ^^^^^^^ | ^^^^^^^^^^^
error: attempt to divide by zero warning: attempt to divide by zero
--> $DIR/promoted_errors.rs:16:20 --> $DIR/promoted_errors.rs:16:20
| |
LL | println!("{}", 1/(false as u32)); LL | println!("{}", 1 / (false as u32));
| ^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^
error: reaching this expression at runtime will panic or abort warning: reaching this expression at runtime will panic or abort
--> $DIR/promoted_errors.rs:16:20 --> $DIR/promoted_errors.rs:16:20
| |
LL | println!("{}", 1/(false as u32)); LL | println!("{}", 1 / (false as u32));
| ^^^^^^^^^^^^^^^^ dividing by zero | ^^^^^^^^^^^^^^^^^^ dividing by zero
error[E0080]: erroneous constant used warning: erroneous constant used
--> $DIR/promoted_errors.rs:16:20 --> $DIR/promoted_errors.rs:16:20
| |
LL | println!("{}", 1/(false as u32)); LL | println!("{}", 1 / (false as u32));
| ^^^^^^^^^^^^^^^^ referenced constant has errors | ^^^^^^^^^^^^^^^^^^ referenced constant has errors
error: attempt to divide by zero warning: attempt to divide by zero
--> $DIR/promoted_errors.rs:20:14 --> $DIR/promoted_errors.rs:20:14
| |
LL | let _x = 1/(false as u32); LL | let _x = 1 / (false as u32);
| ^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^
error: aborting due to 9 previous errors
For more information about this error, try `rustc --explain E0080`.

View file

@ -1,23 +1,23 @@
// build-fail // build-pass
// compile-flags: -C overflow-checks=on -O // compile-flags: -C overflow-checks=on -O
#![deny(const_err)] #![warn(const_err)]
fn main() { fn main() {
println!("{}", 0u32 - 1); println!("{}", 0u32 - 1);
//~^ ERROR attempt to subtract with overflow //~^ WARN attempt to subtract with overflow
let _x = 0u32 - 1; let _x = 0u32 - 1;
//~^ ERROR attempt to subtract with overflow //~^ WARN attempt to subtract with overflow
println!("{}", 1/(1-1)); println!("{}", 1 / (1 - 1));
//~^ ERROR attempt to divide by zero [const_err] //~^ WARN attempt to divide by zero [const_err]
//~| ERROR const_err //~| WARN const_err
//~| ERROR erroneous constant used [E0080] //~| WARN erroneous constant used [const_err]
let _x = 1/(1-1); let _x = 1 / (1 - 1);
//~^ ERROR const_err //~^ WARN const_err
println!("{}", 1/(false as u32)); println!("{}", 1 / (false as u32));
//~^ ERROR attempt to divide by zero [const_err] //~^ WARN attempt to divide by zero [const_err]
//~| ERROR const_err //~| WARN const_err
//~| ERROR erroneous constant used [E0080] //~| WARN erroneous constant used [const_err]
let _x = 1/(false as u32); let _x = 1 / (false as u32);
//~^ ERROR const_err //~^ WARN const_err
} }

View file

@ -1,4 +1,4 @@
error: attempt to subtract with overflow warning: attempt to subtract with overflow
--> $DIR/promoted_errors2.rs:7:20 --> $DIR/promoted_errors2.rs:7:20
| |
LL | println!("{}", 0u32 - 1); LL | println!("{}", 0u32 - 1);
@ -7,63 +7,60 @@ LL | println!("{}", 0u32 - 1);
note: lint level defined here note: lint level defined here
--> $DIR/promoted_errors2.rs:4:9 --> $DIR/promoted_errors2.rs:4:9
| |
LL | #![deny(const_err)] LL | #![warn(const_err)]
| ^^^^^^^^^ | ^^^^^^^^^
error: attempt to subtract with overflow warning: attempt to subtract with overflow
--> $DIR/promoted_errors2.rs:9:14 --> $DIR/promoted_errors2.rs:9:14
| |
LL | let _x = 0u32 - 1; LL | let _x = 0u32 - 1;
| ^^^^^^^^ | ^^^^^^^^
error: attempt to divide by zero warning: attempt to divide by zero
--> $DIR/promoted_errors2.rs:11:20 --> $DIR/promoted_errors2.rs:11:20
| |
LL | println!("{}", 1/(1-1)); LL | println!("{}", 1 / (1 - 1));
| ^^^^^^^ | ^^^^^^^^^^^
error: reaching this expression at runtime will panic or abort warning: reaching this expression at runtime will panic or abort
--> $DIR/promoted_errors2.rs:11:20 --> $DIR/promoted_errors2.rs:11:20
| |
LL | println!("{}", 1/(1-1)); LL | println!("{}", 1 / (1 - 1));
| ^^^^^^^ dividing by zero | ^^^^^^^^^^^ dividing by zero
error[E0080]: erroneous constant used warning: erroneous constant used
--> $DIR/promoted_errors2.rs:11:20 --> $DIR/promoted_errors2.rs:11:20
| |
LL | println!("{}", 1/(1-1)); LL | println!("{}", 1 / (1 - 1));
| ^^^^^^^ referenced constant has errors | ^^^^^^^^^^^ referenced constant has errors
error: attempt to divide by zero warning: attempt to divide by zero
--> $DIR/promoted_errors2.rs:15:14 --> $DIR/promoted_errors2.rs:15:14
| |
LL | let _x = 1/(1-1); LL | let _x = 1 / (1 - 1);
| ^^^^^^^ | ^^^^^^^^^^^
error: attempt to divide by zero warning: attempt to divide by zero
--> $DIR/promoted_errors2.rs:17:20 --> $DIR/promoted_errors2.rs:17:20
| |
LL | println!("{}", 1/(false as u32)); LL | println!("{}", 1 / (false as u32));
| ^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^
error: reaching this expression at runtime will panic or abort warning: reaching this expression at runtime will panic or abort
--> $DIR/promoted_errors2.rs:17:20 --> $DIR/promoted_errors2.rs:17:20
| |
LL | println!("{}", 1/(false as u32)); LL | println!("{}", 1 / (false as u32));
| ^^^^^^^^^^^^^^^^ dividing by zero | ^^^^^^^^^^^^^^^^^^ dividing by zero
error[E0080]: erroneous constant used warning: erroneous constant used
--> $DIR/promoted_errors2.rs:17:20 --> $DIR/promoted_errors2.rs:17:20
| |
LL | println!("{}", 1/(false as u32)); LL | println!("{}", 1 / (false as u32));
| ^^^^^^^^^^^^^^^^ referenced constant has errors | ^^^^^^^^^^^^^^^^^^ referenced constant has errors
error: attempt to divide by zero warning: attempt to divide by zero
--> $DIR/promoted_errors2.rs:21:14 --> $DIR/promoted_errors2.rs:21:14
| |
LL | let _x = 1/(false as u32); LL | let _x = 1 / (false as u32);
| ^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^
error: aborting due to 10 previous errors
For more information about this error, try `rustc --explain E0080`.

View file

@ -13,5 +13,5 @@ const C: () = foo(); //~ WARN: skipping const checks
fn main() { fn main() {
println!("{:?}", C); println!("{:?}", C);
//~^ ERROR: evaluation of constant expression failed //~^ ERROR: evaluation of constant expression failed
//~| ERROR: erroneous constant used [E0080] //~| WARN: erroneous constant used [const_err]
} }

View file

@ -24,12 +24,12 @@ error[E0080]: evaluation of constant expression failed
LL | println!("{:?}", C); LL | println!("{:?}", C);
| ^ referenced constant has errors | ^ referenced constant has errors
error[E0080]: erroneous constant used warning: erroneous constant used
--> $DIR/non_const_fn.rs:14:22 --> $DIR/non_const_fn.rs:14:22
| |
LL | println!("{:?}", C); LL | println!("{:?}", C);
| ^ referenced constant has errors | ^ referenced constant has errors
error: aborting due to 2 previous errors error: aborting due to previous error
For more information about this error, try `rustc --explain E0080`. For more information about this error, try `rustc --explain E0080`.