From 7fdf06cdde49c8cd87e34e85a95c1fe90ebdb0c3 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Sun, 26 Aug 2018 15:19:34 +0200 Subject: [PATCH 01/21] Report const eval error inside the query --- src/librustc/dep_graph/dep_node.rs | 1 + src/librustc/hir/def.rs | 3 + src/librustc/hir/map/mod.rs | 7 +- src/librustc/ich/impls_hir.rs | 1 + src/librustc/ich/impls_ty.rs | 12 +- src/librustc/mir/interpret/error.rs | 65 ++++--- src/librustc/mir/interpret/mod.rs | 2 +- src/librustc/traits/error_reporting.rs | 16 +- src/librustc/traits/fulfill.rs | 14 +- src/librustc/traits/mod.rs | 3 +- src/librustc/traits/structural_impls.rs | 4 +- src/librustc/ty/mod.rs | 12 +- src/librustc/ty/query/config.rs | 24 +++ src/librustc/ty/query/mod.rs | 12 ++ src/librustc/ty/query/plumbing.rs | 1 + src/librustc/ty/structural_impls.rs | 160 +----------------- src/librustc_codegen_llvm/mir/constant.rs | 19 +-- src/librustc_codegen_llvm/mir/operand.rs | 16 +- src/librustc_lint/builtin.rs | 24 +-- src/librustc_lint/lib.rs | 1 - src/librustc_mir/const_eval.rs | 144 +++++++++++----- src/librustc_mir/hair/cx/expr.rs | 7 +- src/librustc_mir/hair/pattern/mod.rs | 8 +- src/librustc_mir/interpret/eval_context.rs | 9 +- src/librustc_mir/interpret/memory.rs | 6 +- src/librustc_mir/lib.rs | 1 + src/librustc_mir/monomorphize/collector.rs | 41 +++-- src/librustc_mir/transform/const_prop.rs | 39 +++-- src/librustc_save_analysis/lib.rs | 1 + src/librustc_typeck/check/mod.rs | 7 - src/test/compile-fail/const-fn-error.rs | 4 +- src/test/compile-fail/issue-52443.rs | 2 +- src/test/ui/array_const_index-0.rs | 5 +- src/test/ui/array_const_index-0.stderr | 19 ++- src/test/ui/array_const_index-1.rs | 5 +- src/test/ui/array_const_index-1.stderr | 19 ++- src/test/ui/consts/const-array-oob.rs | 2 +- src/test/ui/consts/const-array-oob.stderr | 16 +- src/test/ui/consts/const-call.stderr | 8 +- src/test/ui/consts/const-err-early.rs | 13 +- src/test/ui/consts/const-err-early.stderr | 65 +++++-- src/test/ui/consts/const-err-multi.rs | 7 +- src/test/ui/consts/const-err-multi.stderr | 56 +++--- src/test/ui/consts/const-err.rs | 13 +- src/test/ui/consts/const-err.stderr | 33 ++-- src/test/ui/consts/const-err4.rs | 2 +- src/test/ui/consts/const-err4.stderr | 2 +- .../conditional_array_execution.nll.stderr | 29 ++++ .../const-eval/conditional_array_execution.rs | 3 +- .../conditional_array_execution.stderr | 15 +- .../const-eval/const-eval-overflow-2.stderr | 6 +- .../const-eval/const-eval-overflow-3.stderr | 16 +- .../const-eval/const-eval-overflow-4.rs | 3 +- .../const-eval/const-eval-overflow-4.stderr | 16 +- .../consts/const-eval/const-eval-overflow2.rs | 41 ++--- .../const-eval/const-eval-overflow2.stderr | 115 +++++++++---- .../const-eval/const-eval-overflow2b.rs | 41 ++--- .../const-eval/const-eval-overflow2b.stderr | 115 +++++++++---- .../const-eval/const-eval-overflow2c.rs | 41 ++--- .../const-eval/const-eval-overflow2c.stderr | 115 +++++++++---- .../const-pointer-values-in-various-types.rs | 44 ++--- src/test/ui/consts/const-eval/const_panic.rs | 15 +- .../ui/consts/const-eval/const_panic.stderr | 36 ++-- .../consts/const-eval/const_panic_libcore.rs | 6 +- .../const-eval/const_panic_libcore.stderr | 6 +- .../const-eval/const_panic_libcore_main.rs | 6 +- .../const_panic_libcore_main.stderr | 12 +- .../ui/consts/const-eval/const_raw_ptr_ops.rs | 8 +- .../const-eval/const_raw_ptr_ops.stderr | 16 +- .../ui/consts/const-eval/double_check2.stderr | 2 +- .../ui/consts/const-eval/infinite_loop.rs | 2 +- .../ui/consts/const-eval/infinite_loop.stderr | 23 +-- .../consts/const-eval/issue-43197.nll.stderr | 43 +++++ src/test/ui/consts/const-eval/issue-43197.rs | 10 +- .../ui/consts/const-eval/issue-43197.stderr | 36 +--- .../consts/const-eval/issue-44578.nll.stderr | 15 ++ src/test/ui/consts/const-eval/issue-44578.rs | 3 +- .../ui/consts/const-eval/issue-44578.stderr | 13 +- .../ui/consts/const-eval/issue-50814-2.rs | 5 +- .../ui/consts/const-eval/issue-50814-2.stderr | 19 ++- src/test/ui/consts/const-eval/issue-50814.rs | 5 +- .../ui/consts/const-eval/issue-50814.stderr | 19 ++- .../ui/consts/const-eval/issue-52443.stderr | 49 ++++++ .../consts/const-eval/match-test-ptr-null.rs | 3 +- .../const-eval/match-test-ptr-null.stderr | 16 +- .../const-eval/promoted_const_fn_fail.rs | 2 +- .../promoted_const_fn_fail_deny_const_err.rs | 36 ++++ ...omoted_const_fn_fail_deny_const_err.stderr | 19 +++ .../consts/const-eval/promoted_errors.stderr | 12 ++ .../ui/consts/const-eval/pub_const_err.rs | 2 +- .../ui/consts/const-eval/pub_const_err.stderr | 14 +- .../ui/consts/const-eval/pub_const_err_bin.rs | 2 +- .../const-eval/pub_const_err_bin.stderr | 14 +- .../consts/const-eval/shift_overflow.stderr | 2 +- src/test/ui/consts/const-eval/ub-enum.rs | 6 +- src/test/ui/consts/const-eval/ub-enum.stderr | 6 +- .../const-eval/union-const-eval-field.rs | 5 +- .../const-eval/union-const-eval-field.stderr | 32 +++- src/test/ui/consts/const-eval/union-ice.rs | 6 +- .../ui/consts/const-eval/union-ice.stderr | 12 +- .../ui/consts/const-eval/union-ub-fat-ptr.rs | 29 ++-- .../consts/const-eval/union-ub-fat-ptr.stderr | 38 ++--- src/test/ui/consts/const-eval/union-ub.rs | 2 +- src/test/ui/consts/const-eval/union-ub.stderr | 2 +- src/test/ui/consts/const-fn-error.stderr | 41 +++++ src/test/ui/consts/const-integer-bool-ops.rs | 10 ++ .../ui/consts/const-integer-bool-ops.stderr | 95 +++++++++-- .../const-len-underflow-separate-spans.rs | 4 +- .../const-len-underflow-separate-spans.stderr | 36 ++-- .../ui/consts/const-len-underflow-subspans.rs | 2 +- .../const-len-underflow-subspans.stderr | 16 +- src/test/ui/consts/const-size_of-cycle.stderr | 5 + src/test/ui/consts/const-slice-oob.rs | 4 +- src/test/ui/consts/const-slice-oob.stderr | 19 ++- src/test/ui/consts/const-tup-index-span.rs | 1 + .../ui/consts/const-tup-index-span.stderr | 11 +- src/test/ui/error-codes/E0080.rs | 3 - src/test/ui/error-codes/E0080.stderr | 28 +-- src/test/ui/error-codes/E0396-fixed.rs | 2 +- src/test/ui/error-codes/E0396-fixed.stderr | 2 +- src/test/ui/eval-enum.rs | 6 +- src/test/ui/eval-enum.stderr | 34 +--- .../infinite/infinite-recursion-const-fn.rs | 4 +- .../infinite-recursion-const-fn.stderr | 14 +- src/test/ui/issues/issue-39559-2.stderr | 14 +- src/test/ui/issues/issue-41394.rs | 1 + src/test/ui/issues/issue-41394.stderr | 11 +- src/test/ui/issues/issue-43105.rs | 3 +- src/test/ui/issues/issue-43105.stderr | 18 +- src/test/ui/issues/issue-44415.stderr | 5 + src/test/ui/issues/issue-50599.rs | 1 + src/test/ui/issues/issue-50599.stderr | 11 +- .../recursive-static-definition.stderr | 5 + .../ui/type/type-dependent-def-issue-49241.rs | 1 + .../type-dependent-def-issue-49241.stderr | 11 +- 135 files changed, 1470 insertions(+), 1088 deletions(-) create mode 100644 src/test/ui/consts/const-eval/conditional_array_execution.nll.stderr create mode 100644 src/test/ui/consts/const-eval/issue-43197.nll.stderr create mode 100644 src/test/ui/consts/const-eval/issue-44578.nll.stderr create mode 100644 src/test/ui/consts/const-eval/issue-52443.stderr create mode 100644 src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.rs create mode 100644 src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.stderr create mode 100644 src/test/ui/consts/const-fn-error.stderr diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs index 4d6d3bd56f2d8..61996b5a8a75c 100644 --- a/src/librustc/dep_graph/dep_node.rs +++ b/src/librustc/dep_graph/dep_node.rs @@ -530,6 +530,7 @@ define_dep_nodes!( <'tcx> [] UsedTraitImports(DefId), [] HasTypeckTables(DefId), [] ConstEval { param_env: ParamEnvAnd<'tcx, GlobalId<'tcx>> }, + [] ConstEvalRaw { param_env: ParamEnvAnd<'tcx, GlobalId<'tcx>> }, [] CheckMatch(DefId), [] SymbolName(DefId), [] InstanceSymbolName { instance: Instance<'tcx> }, diff --git a/src/librustc/hir/def.rs b/src/librustc/hir/def.rs index 5d9d4deb0abc9..72a45ebd8e4c0 100644 --- a/src/librustc/hir/def.rs +++ b/src/librustc/hir/def.rs @@ -74,6 +74,7 @@ pub enum Def { SelfCtor(DefId /* impl */), // DefId refers to the impl Method(DefId), AssociatedConst(DefId), + Closure(hir::BodyId), Local(ast::NodeId), Upvar(ast::NodeId, // node id of closed over local @@ -281,6 +282,7 @@ impl Def { id } + Def::Closure(_) | Def::Local(..) | Def::Upvar(..) | Def::Label(..) | @@ -319,6 +321,7 @@ impl Def { Def::Trait(..) => "trait", Def::ForeignTy(..) => "foreign type", Def::Method(..) => "method", + Def::Closure(_) => "closure", Def::Const(..) => "constant", Def::AssociatedConst(..) => "associated constant", Def::TyParam(..) => "type parameter", diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index f5f9bcd3b5ea5..d36268cfe3a4f 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -340,9 +340,14 @@ impl<'hir> Map<'hir> { let def_id = self.local_def_id(variant.node.data.id()); Some(Def::Variant(def_id)) } + Node::Expr(expr) => { + match expr.node { + ExprKind::Closure(_, _, body_id, _, _) => Some(Def::Closure(body_id)), + _ => None, + } + } Node::Field(_) | Node::AnonConst(_) | - Node::Expr(_) | Node::Stmt(_) | Node::Ty(_) | Node::TraitRef(_) | diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index a48bd4eeb09a3..4b64591029c3f 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -1044,6 +1044,7 @@ impl_stable_hash_for!(enum hir::def::Def { SelfCtor(impl_def_id), VariantCtor(def_id, ctor_kind), Method(def_id), + Closure(body_id), AssociatedConst(def_id), Local(def_id), Upvar(def_id, index, expr_id), diff --git a/src/librustc/ich/impls_ty.rs b/src/librustc/ich/impls_ty.rs index 642eb11006649..7e5d19850f48d 100644 --- a/src/librustc/ich/impls_ty.rs +++ b/src/librustc/ich/impls_ty.rs @@ -483,10 +483,9 @@ impl_stable_hash_for!(struct ty::Const<'tcx> { val }); -impl_stable_hash_for!(struct ::mir::interpret::ConstEvalErr<'tcx> { - span, - stacktrace, - error +impl_stable_hash_for!(enum mir::interpret::ErrorHandled { + Reported, + TooGeneric }); impl_stable_hash_for!(struct ::mir::interpret::FrameInfo { @@ -503,8 +502,6 @@ impl_stable_hash_for!(struct ty::GenericPredicates<'tcx> { predicates }); -impl_stable_hash_for!(struct ::mir::interpret::EvalError<'tcx> { kind }); - impl<'a, 'gcx, O: HashStable>> HashStable> for ::mir::interpret::EvalErrorKind<'gcx, O> { fn hash_stable(&self, @@ -543,7 +540,6 @@ for ::mir::interpret::EvalErrorKind<'gcx, O> { UnimplementedTraitSelection | TypeckError | TooGeneric | - CheckMatchError | DerefFunctionPointer | ExecuteMemory | OverflowNeg | @@ -551,6 +547,7 @@ for ::mir::interpret::EvalErrorKind<'gcx, O> { DivisionByZero | GeneratorResumedAfterReturn | GeneratorResumedAfterPanic | + ReferencedConstant | InfiniteLoop => {} ReadUndefBytes(offset) => offset.hash_stable(hcx, hasher), InvalidDiscriminant(val) => val.hash_stable(hcx, hasher), @@ -560,7 +557,6 @@ for ::mir::interpret::EvalErrorKind<'gcx, O> { line.hash_stable(hcx, hasher); col.hash_stable(hcx, hasher); }, - ReferencedConstant(ref err) => err.hash_stable(hcx, hasher), MachineError(ref err) => err.hash_stable(hcx, hasher), FunctionAbiMismatch(a, b) => { a.hash_stable(hcx, hasher); diff --git a/src/librustc/mir/interpret/error.rs b/src/librustc/mir/interpret/error.rs index fe466e247c917..f7f4c50b96d40 100644 --- a/src/librustc/mir/interpret/error.rs +++ b/src/librustc/mir/interpret/error.rs @@ -13,7 +13,6 @@ use std::{fmt, env}; use mir; use ty::{Ty, layout}; use ty::layout::{Size, Align}; -use rustc_data_structures::sync::Lrc; use rustc_target::spec::abi::Abi; use super::{ @@ -30,7 +29,26 @@ use syntax_pos::Span; use syntax::ast; use syntax::symbol::Symbol; -pub type ConstEvalResult<'tcx> = Result<&'tcx ty::Const<'tcx>, Lrc>>; +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum ErrorHandled { + /// Already reported a lint or an error for this evaluation + Reported, + /// Don't emit an error, the evaluation failed because the MIR was generic + /// and the substs didn't fully monomorphize it. + TooGeneric, +} + +impl ErrorHandled { + pub fn assert_reported(self) { + match self { + ErrorHandled::Reported => {}, + ErrorHandled::TooGeneric => bug!("MIR interpretation failed without reporting an error \ + even though it was fully monomorphized"), + } + } +} + +pub type ConstEvalResult<'tcx> = Result<&'tcx ty::Const<'tcx>, ErrorHandled>; #[derive(Clone, Debug, RustcEncodable, RustcDecodable)] pub struct ConstEvalErr<'tcx> { @@ -50,7 +68,7 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> { pub fn struct_error(&self, tcx: TyCtxtAt<'a, 'gcx, 'tcx>, message: &str) - -> Option> + -> Result, ErrorHandled> { self.struct_generic(tcx, message, None) } @@ -58,10 +76,14 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> { pub fn report_as_error(&self, tcx: TyCtxtAt<'a, 'gcx, 'tcx>, message: &str - ) { + ) -> ErrorHandled { let err = self.struct_error(tcx, message); - if let Some(mut err) = err { - err.emit(); + match err { + Ok(mut err) => { + err.emit(); + ErrorHandled::Reported + }, + Err(err) => err, } } @@ -69,14 +91,18 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> { tcx: TyCtxtAt<'a, 'gcx, 'tcx>, message: &str, lint_root: ast::NodeId, - ) { + ) -> ErrorHandled { let lint = self.struct_generic( tcx, message, Some(lint_root), ); - if let Some(mut lint) = lint { - lint.emit(); + match lint { + Ok(mut lint) => { + lint.emit(); + ErrorHandled::Reported + }, + Err(err) => err, } } @@ -85,15 +111,11 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> { tcx: TyCtxtAt<'a, 'gcx, 'tcx>, message: &str, lint_root: Option, - ) -> Option> { + ) -> Result, ErrorHandled> { match self.error.kind { - ::mir::interpret::EvalErrorKind::TypeckError | - ::mir::interpret::EvalErrorKind::TooGeneric | - ::mir::interpret::EvalErrorKind::CheckMatchError | - ::mir::interpret::EvalErrorKind::Layout(_) => return None, - ::mir::interpret::EvalErrorKind::ReferencedConstant(ref inner) => { - inner.struct_generic(tcx, "referenced constant has errors", lint_root)?.emit(); - }, + EvalErrorKind::TooGeneric => return Err(ErrorHandled::TooGeneric), + EvalErrorKind::TypeckError | + EvalErrorKind::Layout(_) => return Err(ErrorHandled::Reported), _ => {}, } trace!("reporting const eval failure at {:?}", self.span); @@ -117,7 +139,7 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> { for FrameInfo { span, location, .. } in &self.stacktrace { err.span_label(*span, format!("inside call to `{}`", location)); } - Some(err) + Ok(err) } } @@ -279,10 +301,9 @@ pub enum EvalErrorKind<'tcx, O> { TypeckError, /// Resolution can fail if we are in a too generic context TooGeneric, - CheckMatchError, /// Cannot compute this constant because it depends on another one /// which already produced an error - ReferencedConstant(Lrc>), + ReferencedConstant, GeneratorResumedAfterReturn, GeneratorResumedAfterPanic, InfiniteLoop, @@ -407,9 +428,7 @@ impl<'tcx, O> EvalErrorKind<'tcx, O> { "encountered constants with type errors, stopping evaluation", TooGeneric => "encountered overly generic constant", - CheckMatchError => - "match checking failed", - ReferencedConstant(_) => + ReferencedConstant => "referenced constant has errors", Overflow(mir::BinOp::Add) => "attempt to add with overflow", Overflow(mir::BinOp::Sub) => "attempt to subtract with overflow", diff --git a/src/librustc/mir/interpret/mod.rs b/src/librustc/mir/interpret/mod.rs index 4c2b2b2d41d1b..40a4b8b375a20 100644 --- a/src/librustc/mir/interpret/mod.rs +++ b/src/librustc/mir/interpret/mod.rs @@ -20,7 +20,7 @@ mod value; pub use self::error::{ EvalError, EvalResult, EvalErrorKind, AssertMessage, ConstEvalErr, struct_error, - FrameInfo, ConstEvalResult, + FrameInfo, ConstEvalResult, ErrorHandled, }; pub use self::value::{Scalar, ConstValue}; diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index dc0039926448c..a7513b325fe6d 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -880,18 +880,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { self.tcx.report_object_safety_error(span, did, violations) } - ConstEvalFailure(ref err) => { - match err.struct_error( - self.tcx.at(span), - "could not evaluate constant expression", - ) { - Some(err) => err, - None => { - self.tcx.sess.delay_span_bug(span, - &format!("constant in type had an ignored error: {:?}", err)); - return; - } - } + // already reported in the query + ConstEvalFailure => { + self.tcx.sess.delay_span_bug(span, "constant in type had an ignored error"); + return; } Overflow => { diff --git a/src/librustc/traits/fulfill.rs b/src/librustc/traits/fulfill.rs index e6bf02cd73e0d..320902263af61 100644 --- a/src/librustc/traits/fulfill.rs +++ b/src/librustc/traits/fulfill.rs @@ -16,8 +16,6 @@ use rustc_data_structures::obligation_forest::{Error, ForestObligation, Obligati use rustc_data_structures::obligation_forest::{ObligationProcessor, ProcessResult}; use std::marker::PhantomData; use hir::def_id::DefId; -use mir::interpret::ConstEvalErr; -use mir::interpret::EvalErrorKind; use super::CodeAmbiguity; use super::CodeProjectionError; @@ -491,17 +489,11 @@ impl<'a, 'b, 'gcx, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'gcx, match self.selcx.tcx().at(obligation.cause.span) .const_eval(param_env.and(cid)) { Ok(_) => ProcessResult::Changed(vec![]), - Err(err) => ProcessResult::Error( - CodeSelectionError(ConstEvalFailure(err))) + Err(_) => ProcessResult::Error( + CodeSelectionError(ConstEvalFailure)) } } else { - ProcessResult::Error( - CodeSelectionError(ConstEvalFailure(ConstEvalErr { - span: obligation.cause.span, - error: EvalErrorKind::TooGeneric.into(), - stacktrace: vec![], - }.into())) - ) + ProcessResult::Error(CodeSelectionError(ConstEvalFailure)) } }, None => { diff --git a/src/librustc/traits/mod.rs b/src/librustc/traits/mod.rs index 8bceebb23950c..c809c94f4449d 100644 --- a/src/librustc/traits/mod.rs +++ b/src/librustc/traits/mod.rs @@ -23,7 +23,6 @@ use hir::def_id::DefId; use infer::SuppressRegionErrors; use infer::outlives::env::OutlivesEnvironment; use middle::region; -use mir::interpret::ConstEvalErr; use ty::subst::Substs; use ty::{self, AdtKind, List, Ty, TyCtxt, GenericParamDefKind, ToPredicate}; use ty::error::{ExpectedFound, TypeError}; @@ -438,7 +437,7 @@ pub enum SelectionError<'tcx> { ty::PolyTraitRef<'tcx>, ty::error::TypeError<'tcx>), TraitNotObjectSafe(DefId), - ConstEvalFailure(Lrc>), + ConstEvalFailure, Overflow, } diff --git a/src/librustc/traits/structural_impls.rs b/src/librustc/traits/structural_impls.rs index c50c9703eb557..e7cb9ff06234f 100644 --- a/src/librustc/traits/structural_impls.rs +++ b/src/librustc/traits/structural_impls.rs @@ -172,9 +172,7 @@ impl<'a, 'tcx> Lift<'tcx> for traits::SelectionError<'a> { ) } super::TraitNotObjectSafe(def_id) => Some(super::TraitNotObjectSafe(def_id)), - super::ConstEvalFailure(ref err) => tcx.lift(&**err).map(|err| super::ConstEvalFailure( - err.into(), - )), + super::ConstEvalFailure(ref err) => Some(super::ConstEvalFailure), super::Overflow => Some(super::Overflow), } } diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 5a2f062f233cf..6a6d111fb3bff 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -27,7 +27,7 @@ use middle::lang_items::{FnTraitLangItem, FnMutTraitLangItem, FnOnceTraitLangIte use middle::privacy::AccessLevels; use middle::resolve_lifetime::ObjectLifetimeDefault; use mir::Mir; -use mir::interpret::GlobalId; +use mir::interpret::{GlobalId, ErrorHandled}; use mir::GeneratorLayout; use session::CrateDisambiguator; use traits::{self, Reveal}; @@ -2191,11 +2191,7 @@ impl<'a, 'gcx, 'tcx> AdtDef { None } } - Err(err) => { - err.report_as_error( - tcx.at(tcx.def_span(expr_did)), - "could not evaluate enum discriminant", - ); + Err(ErrorHandled::Reported) => { if !expr_did.is_local() { span_bug!(tcx.def_span(expr_did), "variant discriminant evaluation succeeded \ @@ -2203,6 +2199,10 @@ impl<'a, 'gcx, 'tcx> AdtDef { } None } + Err(ErrorHandled::TooGeneric) => span_bug!( + tcx.def_span(expr_did), + "enum discriminant depends on generic arguments", + ), } } diff --git a/src/librustc/ty/query/config.rs b/src/librustc/ty/query/config.rs index 0f6ff93c52336..bb33def51cc3b 100644 --- a/src/librustc/ty/query/config.rs +++ b/src/librustc/ty/query/config.rs @@ -296,6 +296,30 @@ impl<'tcx> QueryDescription<'tcx> for queries::reachable_set<'tcx> { } impl<'tcx> QueryDescription<'tcx> for queries::const_eval<'tcx> { + fn describe( + tcx: TyCtxt<'_, '_, '_>, + key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>, + ) -> Cow<'static, str> { + format!( + "const-evaluating + checking `{}`", + tcx.item_path_str(key.value.instance.def.def_id()), + ).into() + } + + #[inline] + fn cache_on_disk(_key: Self::Key) -> bool { + true + } + + #[inline] + fn try_load_from_disk<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>, + id: SerializedDepNodeIndex) + -> Option { + tcx.queries.on_disk_cache.try_load_query_result(tcx, id).map(Ok) + } +} + +impl<'tcx> QueryDescription<'tcx> for queries::const_eval_raw<'tcx> { fn describe(tcx: TyCtxt<'_, '_, '_>, key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>) -> Cow<'static, str> { diff --git a/src/librustc/ty/query/mod.rs b/src/librustc/ty/query/mod.rs index a59a15da08d99..ed7b2cffc46f6 100644 --- a/src/librustc/ty/query/mod.rs +++ b/src/librustc/ty/query/mod.rs @@ -301,6 +301,14 @@ define_queries! { <'tcx> }, Other { + /// Evaluate a constant without running sanity checks + /// + /// DO NOT USE THIS outside const eval. Const eval uses this to break query cycles during + /// validation. Please add a comment to every use site explaining why using `const_eval` + /// isn't sufficient + [] fn const_eval_raw: const_eval_raw_dep_node(ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>) + -> ConstEvalResult<'tcx>, + /// Results of evaluating const items or constants embedded in /// other items (such as enum variant explicit discriminants). [] fn const_eval: const_eval_dep_node(ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>) @@ -776,6 +784,10 @@ fn const_eval_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>) -> DepConstructor<'tcx> { DepConstructor::ConstEval { param_env } } +fn const_eval_raw_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>) + -> DepConstructor<'tcx> { + DepConstructor::ConstEvalRaw { param_env } +} fn mir_keys<'tcx>(_: CrateNum) -> DepConstructor<'tcx> { DepConstructor::MirKeys diff --git a/src/librustc/ty/query/plumbing.rs b/src/librustc/ty/query/plumbing.rs index 789658dcf72dc..8bbfd92d688ed 100644 --- a/src/librustc/ty/query/plumbing.rs +++ b/src/librustc/ty/query/plumbing.rs @@ -1063,6 +1063,7 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>, DepKind::NeedsDrop | DepKind::Layout | DepKind::ConstEval | + DepKind::ConstEvalRaw | DepKind::InstanceSymbolName | DepKind::MirShim | DepKind::BorrowCheckKrate | diff --git a/src/librustc/ty/structural_impls.rs b/src/librustc/ty/structural_impls.rs index 273799bd4bd34..a93dca4af426b 100644 --- a/src/librustc/ty/structural_impls.rs +++ b/src/librustc/ty/structural_impls.rs @@ -13,7 +13,7 @@ //! hand, though we've recently added some macros (e.g., //! `BraceStructLiftImpl!`) to help with the tedium. -use mir::interpret::{ConstValue, ConstEvalErr}; +use mir::interpret::ConstValue; use ty::{self, Lift, Ty, TyCtxt}; use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor}; use rustc_data_structures::indexed_vec::{IndexVec, Idx}; @@ -460,164 +460,6 @@ impl<'a, 'tcx> Lift<'tcx> for ty::error::TypeError<'a> { } } -impl<'a, 'tcx> Lift<'tcx> for ConstEvalErr<'a> { - type Lifted = ConstEvalErr<'tcx>; - fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option { - tcx.lift(&self.error).map(|error| { - ConstEvalErr { - span: self.span, - stacktrace: self.stacktrace.clone(), - error, - } - }) - } -} - -impl<'a, 'tcx> Lift<'tcx> for interpret::EvalError<'a> { - type Lifted = interpret::EvalError<'tcx>; - fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option { - Some(interpret::EvalError { - kind: tcx.lift(&self.kind)?, - }) - } -} - -impl<'a, 'tcx, O: Lift<'tcx>> Lift<'tcx> for interpret::EvalErrorKind<'a, O> { - type Lifted = interpret::EvalErrorKind<'tcx, >::Lifted>; - fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option { - use ::mir::interpret::EvalErrorKind::*; - Some(match *self { - MachineError(ref err) => MachineError(err.clone()), - FunctionAbiMismatch(a, b) => FunctionAbiMismatch(a, b), - FunctionArgMismatch(a, b) => FunctionArgMismatch( - tcx.lift(&a)?, - tcx.lift(&b)?, - ), - FunctionRetMismatch(a, b) => FunctionRetMismatch( - tcx.lift(&a)?, - tcx.lift(&b)?, - ), - FunctionArgCountMismatch => FunctionArgCountMismatch, - NoMirFor(ref s) => NoMirFor(s.clone()), - UnterminatedCString(ptr) => UnterminatedCString(ptr), - DanglingPointerDeref => DanglingPointerDeref, - DoubleFree => DoubleFree, - InvalidMemoryAccess => InvalidMemoryAccess, - InvalidFunctionPointer => InvalidFunctionPointer, - InvalidBool => InvalidBool, - InvalidDiscriminant(val) => InvalidDiscriminant(val), - PointerOutOfBounds { - ptr, - access, - allocation_size, - } => PointerOutOfBounds { ptr, access, allocation_size }, - InvalidNullPointerUsage => InvalidNullPointerUsage, - ReadPointerAsBytes => ReadPointerAsBytes, - ReadBytesAsPointer => ReadBytesAsPointer, - ReadForeignStatic => ReadForeignStatic, - InvalidPointerMath => InvalidPointerMath, - ReadUndefBytes(offset) => ReadUndefBytes(offset), - DeadLocal => DeadLocal, - InvalidBoolOp(bop) => InvalidBoolOp(bop), - Unimplemented(ref s) => Unimplemented(s.clone()), - DerefFunctionPointer => DerefFunctionPointer, - ExecuteMemory => ExecuteMemory, - BoundsCheck { ref len, ref index } => BoundsCheck { - len: tcx.lift(len)?, - index: tcx.lift(index)?, - }, - Intrinsic(ref s) => Intrinsic(s.clone()), - InvalidChar(c) => InvalidChar(c), - StackFrameLimitReached => StackFrameLimitReached, - OutOfTls => OutOfTls, - TlsOutOfBounds => TlsOutOfBounds, - AbiViolation(ref s) => AbiViolation(s.clone()), - AlignmentCheckFailed { - required, - has, - } => AlignmentCheckFailed { required, has }, - MemoryLockViolation { - ptr, - len, - frame, - access, - ref lock, - } => MemoryLockViolation { ptr, len, frame, access, lock: lock.clone() }, - MemoryAcquireConflict { - ptr, - len, - kind, - ref lock, - } => MemoryAcquireConflict { ptr, len, kind, lock: lock.clone() }, - InvalidMemoryLockRelease { - ptr, - len, - frame, - ref lock, - } => InvalidMemoryLockRelease { ptr, len, frame, lock: lock.clone() }, - DeallocatedLockedMemory { - ptr, - ref lock, - } => DeallocatedLockedMemory { ptr, lock: lock.clone() }, - ValidationFailure(ref s) => ValidationFailure(s.clone()), - CalledClosureAsFunction => CalledClosureAsFunction, - VtableForArgumentlessMethod => VtableForArgumentlessMethod, - ModifiedConstantMemory => ModifiedConstantMemory, - AssumptionNotHeld => AssumptionNotHeld, - InlineAsm => InlineAsm, - TypeNotPrimitive(ty) => TypeNotPrimitive(tcx.lift(&ty)?), - ReallocatedWrongMemoryKind(ref a, ref b) => { - ReallocatedWrongMemoryKind(a.clone(), b.clone()) - }, - DeallocatedWrongMemoryKind(ref a, ref b) => { - DeallocatedWrongMemoryKind(a.clone(), b.clone()) - }, - ReallocateNonBasePtr => ReallocateNonBasePtr, - DeallocateNonBasePtr => DeallocateNonBasePtr, - IncorrectAllocationInformation(a, b, c, d) => { - IncorrectAllocationInformation(a, b, c, d) - }, - Layout(lay) => Layout(tcx.lift(&lay)?), - HeapAllocZeroBytes => HeapAllocZeroBytes, - HeapAllocNonPowerOfTwoAlignment(n) => HeapAllocNonPowerOfTwoAlignment(n), - Unreachable => Unreachable, - Panic { ref msg, ref file, line, col } => Panic { - msg: msg.clone(), - file: file.clone(), - line, col, - }, - ReadFromReturnPointer => ReadFromReturnPointer, - PathNotFound(ref v) => PathNotFound(v.clone()), - UnimplementedTraitSelection => UnimplementedTraitSelection, - TypeckError => TypeckError, - TooGeneric => TooGeneric, - CheckMatchError => CheckMatchError, - ReferencedConstant(ref err) => ReferencedConstant(tcx.lift(&**err)?.into()), - OverflowNeg => OverflowNeg, - Overflow(op) => Overflow(op), - DivisionByZero => DivisionByZero, - RemainderByZero => RemainderByZero, - GeneratorResumedAfterReturn => GeneratorResumedAfterReturn, - GeneratorResumedAfterPanic => GeneratorResumedAfterPanic, - InfiniteLoop => InfiniteLoop, - }) - } -} - -impl<'a, 'tcx> Lift<'tcx> for ty::layout::LayoutError<'a> { - type Lifted = ty::layout::LayoutError<'tcx>; - fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option { - match *self { - ty::layout::LayoutError::Unknown(ref ty) => { - tcx.lift(ty).map(ty::layout::LayoutError::Unknown) - } - ty::layout::LayoutError::SizeOverflow(ref ty) => { - tcx.lift(ty).map(ty::layout::LayoutError::SizeOverflow) - } - } - } -} - impl<'a, 'tcx> Lift<'tcx> for ty::InstanceDef<'a> { type Lifted = ty::InstanceDef<'tcx>; fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option { diff --git a/src/librustc_codegen_llvm/mir/constant.rs b/src/librustc_codegen_llvm/mir/constant.rs index 9f0f744389089..1f66ee36170dc 100644 --- a/src/librustc_codegen_llvm/mir/constant.rs +++ b/src/librustc_codegen_llvm/mir/constant.rs @@ -9,12 +9,11 @@ // except according to those terms. use llvm; -use rustc::mir::interpret::{ConstEvalErr, read_target_uint}; +use rustc::mir::interpret::{ErrorHandled, read_target_uint}; use rustc_mir::const_eval::const_field; use rustc::hir::def_id::DefId; use rustc::mir; use rustc_data_structures::indexed_vec::Idx; -use rustc_data_structures::sync::Lrc; use rustc::mir::interpret::{GlobalId, Pointer, Scalar, Allocation, ConstValue, AllocType}; use rustc::ty::{self, Ty}; use rustc::ty::layout::{self, HasDataLayout, LayoutOf, Size}; @@ -124,7 +123,7 @@ pub fn const_alloc_to_llvm(cx: &CodegenCx<'ll, '_>, alloc: &Allocation) -> &'ll pub fn codegen_static_initializer( cx: &CodegenCx<'ll, 'tcx>, def_id: DefId, -) -> Result<(&'ll Value, &'tcx Allocation), Lrc>> { +) -> Result<(&'ll Value, &'tcx Allocation), ErrorHandled> { let instance = ty::Instance::mono(cx.tcx, def_id); let cid = GlobalId { instance, @@ -145,7 +144,7 @@ impl FunctionCx<'a, 'll, 'tcx> { &mut self, bx: &Builder<'a, 'll, 'tcx>, constant: &'tcx ty::Const<'tcx>, - ) -> Result<&'tcx ty::Const<'tcx>, Lrc>> { + ) -> Result<&'tcx ty::Const<'tcx>, ErrorHandled> { match constant.val { ConstValue::Unevaluated(def_id, ref substs) => { let tcx = bx.tcx(); @@ -165,7 +164,7 @@ impl FunctionCx<'a, 'll, 'tcx> { &mut self, bx: &Builder<'a, 'll, 'tcx>, constant: &mir::Constant<'tcx>, - ) -> Result<&'tcx ty::Const<'tcx>, Lrc>> { + ) -> Result<&'tcx ty::Const<'tcx>, ErrorHandled> { let c = self.monomorphize(&constant.literal); self.fully_evaluate(bx, c) } @@ -176,7 +175,7 @@ impl FunctionCx<'a, 'll, 'tcx> { bx: &Builder<'a, 'll, 'tcx>, span: Span, ty: Ty<'tcx>, - constant: Result<&'tcx ty::Const<'tcx>, Lrc>>, + constant: Result<&'tcx ty::Const<'tcx>, ErrorHandled>, ) -> (&'ll Value, Ty<'tcx>) { constant .and_then(|c| { @@ -185,7 +184,7 @@ impl FunctionCx<'a, 'll, 'tcx> { ty::Array(_, n) => n.unwrap_usize(bx.tcx()), ref other => bug!("invalid simd shuffle type: {}", other), }; - let values: Result, Lrc<_>> = (0..fields).map(|field| { + let values: Result, ErrorHandled> = (0..fields).map(|field| { let field = const_field( bx.tcx(), ty::ParamEnv::reveal_all(), @@ -211,9 +210,9 @@ impl FunctionCx<'a, 'll, 'tcx> { let llval = C_struct(bx.cx, &values?, false); Ok((llval, c.ty)) }) - .unwrap_or_else(|e| { - e.report_as_error( - bx.tcx().at(span), + .unwrap_or_else(|_| { + bx.tcx().sess.span_err( + span, "could not evaluate shuffle_indices at compile time", ); // We've errored, so we don't have to produce working code. diff --git a/src/librustc_codegen_llvm/mir/operand.rs b/src/librustc_codegen_llvm/mir/operand.rs index ab43531240f3f..25f03cbe97075 100644 --- a/src/librustc_codegen_llvm/mir/operand.rs +++ b/src/librustc_codegen_llvm/mir/operand.rs @@ -8,11 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use rustc::mir::interpret::{ConstValue, ConstEvalErr}; +use rustc::mir::interpret::{ConstValue, ErrorHandled}; use rustc::mir; use rustc::ty; use rustc::ty::layout::{self, Align, LayoutOf, TyLayout}; use rustc_data_structures::sync::Lrc; +use rustc_data_structures::indexed_vec::Idx; use base; use common::{CodegenCx, C_undef, C_usize}; @@ -79,7 +80,7 @@ impl OperandRef<'ll, 'tcx> { pub fn from_const(bx: &Builder<'a, 'll, 'tcx>, val: &'tcx ty::Const<'tcx>) - -> Result, Lrc>> { + -> Result, ErrorHandled> { let layout = bx.cx.layout_of(val.ty); if layout.is_zst() { @@ -424,10 +425,13 @@ impl FunctionCx<'a, 'll, 'tcx> { self.eval_mir_constant(bx, constant) .and_then(|c| OperandRef::from_const(bx, c)) .unwrap_or_else(|err| { - err.report_as_error( - bx.tcx().at(constant.span), - "could not evaluate constant operand", - ); + match err { + // errored or at least linted + ErrorHandled::Reported => {}, + ErrorHandled::TooGeneric => { + bug!("codgen encountered polymorphic constant") + }, + } // Allow RalfJ to sleep soundly knowing that even refactorings that remove // the above error (or silence it under some conditions) will not cause UB let fnname = bx.cx.get_intrinsic(&("llvm.trap")); diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index bc5f688729c36..597b6ae236676 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -1590,7 +1590,7 @@ fn validate_const<'a, 'tcx>( } } -fn check_const(cx: &LateContext, body_id: hir::BodyId, what: &str) { +fn check_const(cx: &LateContext, body_id: hir::BodyId) { let def_id = cx.tcx.hir.body_owner_def_id(body_id); let is_static = cx.tcx.is_static(def_id).is_some(); let param_env = if is_static { @@ -1603,27 +1603,15 @@ fn check_const(cx: &LateContext, body_id: hir::BodyId, what: &str) { instance: ty::Instance::mono(cx.tcx, def_id), promoted: None }; - match cx.tcx.const_eval(param_env.and(cid)) { - Ok(val) => validate_const(cx.tcx, val, param_env, cid, what), - Err(err) => { - // errors for statics are already reported directly in the query, avoid duplicates - if !is_static { - let span = cx.tcx.def_span(def_id); - err.report_as_lint( - cx.tcx.at(span), - &format!("this {} cannot be used", what), - cx.current_lint_root(), - ); - } - }, - } + // trigger the query once for all constants since that will already report the errors + let _ = cx.tcx.const_eval(param_env.and(cid)); } struct UnusedBrokenConstVisitor<'a, 'tcx: 'a>(&'a LateContext<'a, 'tcx>); impl<'a, 'tcx, 'v> hir::intravisit::Visitor<'v> for UnusedBrokenConstVisitor<'a, 'tcx> { fn visit_nested_body(&mut self, id: hir::BodyId) { - check_const(self.0, id, "array length"); + check_const(self.0, id); } fn nested_visit_map<'this>(&'this mut self) -> hir::intravisit::NestedVisitorMap<'this, 'v> { hir::intravisit::NestedVisitorMap::None @@ -1634,10 +1622,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedBrokenConst { fn check_item(&mut self, cx: &LateContext, it: &hir::Item) { match it.node { hir::ItemKind::Const(_, body_id) => { - check_const(cx, body_id, "constant"); + check_const(cx, body_id); }, hir::ItemKind::Static(_, _, body_id) => { - check_const(cx, body_id, "static"); + check_const(cx, body_id); }, hir::ItemKind::Ty(ref ty, _) => hir::intravisit::walk_ty( &mut UnusedBrokenConstVisitor(cx), diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index 5bf2b76e66849..211b8471115cc 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -152,7 +152,6 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) { UnreachablePub: UnreachablePub, UnnameableTestItems: UnnameableTestItems::new(), TypeAliasBounds: TypeAliasBounds, - UnusedBrokenConst: UnusedBrokenConst, TrivialConstraints: TrivialConstraints, TypeLimits: TypeLimits::new(), MissingDoc: MissingDoc::new(), diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index bc917140bbd67..6ad1536a63052 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -17,13 +17,16 @@ use std::hash::Hash; use std::collections::hash_map::Entry; use rustc::hir::{self, def_id::DefId}; -use rustc::mir::interpret::ConstEvalErr; +use rustc::hir::def::Def; +use rustc::mir::interpret::{ConstEvalErr, ErrorHandled}; use rustc::mir; use rustc::ty::{self, Ty, TyCtxt, Instance, query::TyCtxtAt}; use rustc::ty::layout::{self, Size, LayoutOf, TyLayout}; use rustc::ty::subst::Subst; +use rustc::util::nodemap::FxHashSet; use rustc_data_structures::indexed_vec::IndexVec; use rustc_data_structures::fx::FxHashMap; +use rustc::util::common::ErrorReported; use syntax::ast::Mutability; use syntax::source_map::{Span, DUMMY_SP}; @@ -509,13 +512,11 @@ pub fn const_field<'a, 'tcx>( // this is not called for statics. op_to_const(&ecx, field, true) })(); - result.map_err(|err| { - let (trace, span) = ecx.generate_stacktrace(None); - ConstEvalErr { - error: err, - stacktrace: trace, - span, - }.into() + result.map_err(|error| { + let stacktrace = ecx.generate_stacktrace(None); + let err = ::rustc::mir::interpret::ConstEvalErr { error, stacktrace, span: ecx.tcx.span }; + err.report_as_error(ecx.tcx, "could not access field of constant"); + ErrorHandled::Reported }) } @@ -531,25 +532,58 @@ pub fn const_variant_index<'a, 'tcx>( Ok(ecx.read_discriminant(op)?.1) } -pub fn const_to_allocation_provider<'a, 'tcx>( - _tcx: TyCtxt<'a, 'tcx, 'tcx>, - val: &'tcx ty::Const<'tcx>, -) -> &'tcx Allocation { - // FIXME: This really does not need to be a query. Instead, we should have a query for statics - // that returns an allocation directly (or an `AllocId`?), after doing a sanity check of the - // value and centralizing error reporting. - match val.val { - ConstValue::ByRef(_, alloc, offset) => { - assert_eq!(offset.bytes(), 0); - return alloc; - }, - _ => bug!("const_to_allocation called on non-static"), - } +fn validate_const<'a, 'tcx>( + tcx: ty::TyCtxt<'a, 'tcx, 'tcx>, + constant: &'tcx ty::Const<'tcx>, + key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>, +) -> ::rustc::mir::interpret::ConstEvalResult<'tcx> { + let cid = key.value; + let ecx = mk_eval_cx(tcx, cid.instance, key.param_env).unwrap(); + let val = (|| { + let op = ecx.const_to_op(constant)?; + let mut todo = vec![(op, Vec::new())]; + let mut seen = FxHashSet(); + seen.insert(op); + while let Some((op, mut path)) = todo.pop() { + ecx.validate_operand( + op, + &mut path, + &mut seen, + &mut todo, + )?; + } + Ok(constant) + })(); + + val.map_err(|error| { + let stacktrace = ecx.generate_stacktrace(None); + let err = ::rustc::mir::interpret::ConstEvalErr { error, stacktrace, span: ecx.tcx.span }; + match err.struct_error(ecx.tcx, "it is undefined behavior to use this value") { + Ok(mut diag) => { + diag.note("The rules on what exactly is undefined behavior aren't clear, \ + so this check might be overzealous. Please open an issue on the rust compiler \ + repository if you believe it should not be considered undefined behavior", + ); + diag.emit(); + ErrorHandled::Reported + } + Err(err) => err, + } + }) } pub fn const_eval_provider<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>, +) -> ::rustc::mir::interpret::ConstEvalResult<'tcx> { + tcx.const_eval_raw(key).and_then(|val| { + validate_const(tcx, val, key) + }) +} + +pub fn const_eval_raw_provider<'a, 'tcx>( + tcx: TyCtxt<'a, 'tcx, 'tcx>, + key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>, ) -> ::rustc::mir::interpret::ConstEvalResult<'tcx> { trace!("const eval: {:?}", key); let cid = key.value; @@ -557,15 +591,10 @@ pub fn const_eval_provider<'a, 'tcx>( if let Some(id) = tcx.hir.as_local_node_id(def_id) { let tables = tcx.typeck_tables_of(def_id); - let span = tcx.def_span(def_id); // Do match-check before building MIR - if tcx.check_match(def_id).is_err() { - return Err(ConstEvalErr { - error: EvalErrorKind::CheckMatchError.into(), - stacktrace: vec![], - span, - }.into()); + if let Err(ErrorReported) = tcx.check_match(def_id) { + return Err(ErrorHandled::Reported) } if let hir::BodyOwnerKind::Const = tcx.hir.body_owner_kind(id) { @@ -574,11 +603,7 @@ pub fn const_eval_provider<'a, 'tcx>( // Do not continue into miri if typeck errors occurred; it will fail horribly if tables.tainted_by_errors { - return Err(ConstEvalErr { - error: EvalErrorKind::CheckMatchError.into(), - stacktrace: vec![], - span, - }.into()); + return Err(ErrorHandled::Reported) } }; @@ -593,19 +618,50 @@ pub fn const_eval_provider<'a, 'tcx>( } } op_to_const(&ecx, op, normalize) - }).map_err(|err| { - let (trace, span) = ecx.generate_stacktrace(None); - let err = ConstEvalErr { - error: err, - stacktrace: trace, - span, - }; + }).map_err(|error| { + let stacktrace = ecx.generate_stacktrace(None); + let err = ConstEvalErr { error, stacktrace, span: ecx.tcx.span }; if tcx.is_static(def_id).is_some() { - err.report_as_error(ecx.tcx, "could not evaluate static initializer"); + let err = err.report_as_error(ecx.tcx, "could not evaluate static initializer"); if tcx.sess.err_count() == 0 { - span_bug!(span, "static eval failure didn't emit an error: {:#?}", err); + span_bug!(ecx.tcx.span, "static eval failure didn't emit an error: {:#?}", err); + } + err + } else if def_id.is_local() { + // constant defined in this crate, we can figure out a lint level! + match tcx.describe_def(def_id) { + Some(Def::Const(_)) | Some(Def::AssociatedConst(_)) => { + let node_id = tcx.hir.as_local_node_id(def_id).unwrap(); + err.report_as_lint( + tcx.at(tcx.def_span(def_id)), + "any use of this value will cause an error", + node_id, + ) + }, + _ => if let Some(p) = cid.promoted { + let span = tcx.optimized_mir(def_id).promoted[p].span; + if let EvalErrorKind::ReferencedConstant = err.error.kind { + err.report_as_error( + tcx.at(span), + "evaluation of constant expression failed", + ) + } else { + err.report_as_lint( + tcx.at(span), + "reaching this expression at runtime will panic or abort", + tcx.hir.as_local_node_id(def_id).unwrap(), + ) + } + } else { + err.report_as_error( + ecx.tcx, + "evaluation of constant value failed", + ) + }, } + } else { + // use of constant from other crate + err.report_as_error(ecx.tcx, "could not evaluate constant") } - err.into() }) } diff --git a/src/librustc_mir/hair/cx/expr.rs b/src/librustc_mir/hair/cx/expr.rs index 1df5f78975139..48fcdd42ff5e0 100644 --- a/src/librustc_mir/hair/cx/expr.rs +++ b/src/librustc_mir/hair/cx/expr.rs @@ -15,7 +15,7 @@ use hair::cx::block; use hair::cx::to_ref::ToRef; use hair::util::UserAnnotatedTyHelpers; use rustc::hir::def::{Def, CtorKind}; -use rustc::mir::interpret::GlobalId; +use rustc::mir::interpret::{GlobalId, ErrorHandled}; use rustc::ty::{self, AdtKind, Ty}; use rustc::ty::adjustment::{Adjustment, Adjust, AutoBorrow, AutoBorrowMutability}; use rustc::ty::cast::CastKind as TyCastKind; @@ -571,8 +571,9 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, let span = cx.tcx.def_span(def_id); let count = match cx.tcx.at(span).const_eval(cx.param_env.and(global_id)) { Ok(cv) => cv.unwrap_usize(cx.tcx), - Err(e) => { - e.report_as_error(cx.tcx.at(span), "could not evaluate array length"); + Err(ErrorHandled::Reported) => 0, + Err(ErrorHandled::TooGeneric) => { + cx.tcx.sess.span_err(span, "array lengths can't depend on generic parameters"); 0 }, }; diff --git a/src/librustc_mir/hair/pattern/mod.rs b/src/librustc_mir/hair/pattern/mod.rs index cb974366a3029..4649c28aff518 100644 --- a/src/librustc_mir/hair/pattern/mod.rs +++ b/src/librustc_mir/hair/pattern/mod.rs @@ -732,13 +732,13 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { Ok(value) => { return self.const_to_pat(instance, value, id, span) }, - Err(err) => { - err.report_as_error( - self.tcx.at(span), + Err(_) => { + self.tcx.sess.span_err( + span, "could not evaluate constant pattern", ); PatternKind::Wild - }, + } } }, None => { diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index 189388921650c..ce991c50330bb 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -611,8 +611,9 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc } else { self.param_env }; - self.tcx.const_eval(param_env.and(gid)) - .map_err(|err| EvalErrorKind::ReferencedConstant(err).into()) + self.tcx.const_eval(param_env.and(gid)).map_err(|_| { + EvalErrorKind::ReferencedConstant.into() + }) } pub fn dump_place(&self, place: Place) { @@ -679,7 +680,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc } } - pub fn generate_stacktrace(&self, explicit_span: Option) -> (Vec, Span) { + pub fn generate_stacktrace(&self, explicit_span: Option) -> Vec { let mut last_span = None; let mut frames = Vec::new(); // skip 1 because the last frame is just the environment of the constant @@ -716,7 +717,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc frames.push(FrameInfo { span, location, lint_root }); } trace!("generate stacktrace: {:#?}, {:?}", frames, explicit_span); - (frames, self.tcx.span) + frames } #[inline(always)] diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index 9adca6c429798..b46e914133aad 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -368,10 +368,12 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> { instance, promoted: None, }; - tcx.const_eval(ty::ParamEnv::reveal_all().and(gid)).map_err(|err| { + // use the raw query here to break validation cycles. Later uses of the static will call the + // full query anyway + tcx.const_eval_raw(ty::ParamEnv::reveal_all().and(gid)).map_err(|_| { // no need to report anything, the const_eval call takes care of that for statics assert!(tcx.is_static(def_id).is_some()); - EvalErrorKind::ReferencedConstant(err).into() + EvalErrorKind::ReferencedConstant.into() }).map(|const_val| { if let ConstValue::ByRef(_, allocation, _) = const_val.val { // We got tcx memory. Let the machine figure out whether and how to diff --git a/src/librustc_mir/lib.rs b/src/librustc_mir/lib.rs index 2f44dff2e22c3..d4495d3085d31 100644 --- a/src/librustc_mir/lib.rs +++ b/src/librustc_mir/lib.rs @@ -94,6 +94,7 @@ pub fn provide(providers: &mut Providers) { shim::provide(providers); transform::provide(providers); providers.const_eval = const_eval::const_eval_provider; + providers.const_eval_raw = const_eval::const_eval_raw_provider; providers.check_match = hair::pattern::check_match; } diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index 6b60b5340eee7..e8c482e836ff4 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -202,7 +202,7 @@ use rustc::session::config; use rustc::mir::{self, Location, Promoted}; use rustc::mir::visit::Visitor as MirVisitor; use rustc::mir::mono::MonoItem; -use rustc::mir::interpret::{Scalar, GlobalId, AllocType}; +use rustc::mir::interpret::{Scalar, GlobalId, AllocType, ErrorHandled}; use monomorphize::{self, Instance}; use rustc::util::nodemap::{FxHashSet, FxHashMap, DefIdMap}; @@ -988,6 +988,20 @@ impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> { hir::ItemKind::Const(..) => { // const items only generate mono items if they are // actually used somewhere. Just declaring them is insufficient. + + // but even just declaring them must collect the items they refer to + let def_id = self.tcx.hir.local_def_id(item.id); + + let instance = Instance::mono(self.tcx, def_id); + let cid = GlobalId { + instance, + promoted: None, + }; + let param_env = ty::ParamEnv::reveal_all(); + + if let Ok(val) = self.tcx.const_eval(param_env.and(cid)) { + collect_const(self.tcx, val, instance.substs, &mut self.output); + } } hir::ItemKind::Fn(..) => { let def_id = self.tcx.hir.local_def_id(item.id); @@ -1198,15 +1212,10 @@ fn collect_neighbours<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, }; match tcx.const_eval(param_env.and(cid)) { Ok(val) => collect_const(tcx, val, instance.substs, output), - Err(err) => { - use rustc::mir::interpret::EvalErrorKind; - if let EvalErrorKind::ReferencedConstant(_) = err.error.kind { - err.report_as_error( - tcx.at(mir.promoted[i].span), - "erroneous constant used", - ); - } - }, + Err(ErrorHandled::Reported) => {}, + Err(ErrorHandled::TooGeneric) => span_bug!( + mir.promoted[i].span, "collection encountered polymorphic constant", + ), } } } @@ -1247,14 +1256,10 @@ fn collect_const<'a, 'tcx>( }; match tcx.const_eval(param_env.and(cid)) { Ok(val) => val.val, - Err(err) => { - let span = tcx.def_span(def_id); - err.report_as_error( - tcx.at(span), - "constant evaluation error", - ); - return; - } + Err(ErrorHandled::Reported) => return, + Err(ErrorHandled::TooGeneric) => span_bug!( + tcx.def_span(def_id), "collection encountered polymorphic constant", + ), } }, _ => constant.val, diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 626baf207eebc..6da40aa4a116b 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -18,7 +18,7 @@ use rustc::mir::{NullOp, UnOp, StatementKind, Statement, BasicBlock, LocalKind}; use rustc::mir::{TerminatorKind, ClearCrossCrate, SourceInfo, BinOp, ProjectionElem}; use rustc::mir::visit::{Visitor, PlaceContext}; use rustc::mir::interpret::{ - ConstEvalErr, EvalErrorKind, Scalar, GlobalId, EvalResult + ConstEvalErr, EvalErrorKind, Scalar, GlobalId, EvalResult, }; use rustc::ty::{TyCtxt, self, Instance}; use interpret::{self, EvalContext, Value, OpTy, MemoryKind, ScalarMaybeUndef}; @@ -45,12 +45,17 @@ impl MirPass for ConstProp { return; } match tcx.describe_def(source.def_id) { - // skip statics/consts because they'll be evaluated by miri anyway - Some(Def::Const(..)) | - Some(Def::Static(..)) => return, - // we still run on associated constants, because they might not get evaluated - // within the current crate - _ => {}, + // Only run const prop on functions, methods, closures and associated constants + | Some(Def::Fn(_)) + | Some(Def::Method(_)) + | Some(Def::AssociatedConst(_)) + | Some(Def::Closure(_)) + => {} + // skip anon_const/statics/consts because they'll be evaluated by miri anyway + def => { + trace!("ConstProp skipped for {:?} ({:?})", source.def_id, def); + return + }, } trace!("ConstProp starting for {:?}", source.def_id); @@ -144,8 +149,8 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> { let r = match f(self) { Ok(val) => Some(val), Err(error) => { - let (stacktrace, span) = self.ecx.generate_stacktrace(None); - let diagnostic = ConstEvalErr { span, error, stacktrace }; + let stacktrace = self.ecx.generate_stacktrace(None); + let diagnostic = ConstEvalErr { span: source_info.span, error, stacktrace }; use rustc::mir::interpret::EvalErrorKind::*; match diagnostic.error.kind { // don't report these, they make no sense in a const prop context @@ -208,7 +213,7 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> { | ReadFromReturnPointer | GeneratorResumedAfterReturn | GeneratorResumedAfterPanic - | ReferencedConstant(_) + | ReferencedConstant | InfiniteLoop => { // FIXME: report UB here @@ -223,7 +228,6 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> { | UnimplementedTraitSelection | TypeckError | TooGeneric - | CheckMatchError // these are just noise => {}, @@ -264,16 +268,11 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> { Some((op, c.span)) }, Err(error) => { - let (stacktrace, span) = self.ecx.generate_stacktrace(None); - let err = ConstEvalErr { - span, - error, - stacktrace, + let stacktrace = self.ecx.generate_stacktrace(None); + let err = ::rustc::mir::interpret::ConstEvalErr { + error, stacktrace, span: source_info.span, }; - err.report_as_error( - self.tcx.at(source_info.span), - "could not evaluate constant", - ); + err.report_as_error(self.ecx.tcx, "erroneous constant used"); None }, } diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index 4b43a1a6270f8..cdd25b8aa7acc 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -827,6 +827,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { ref_id: id_from_def_id(def_id), }) } + HirDef::Closure(_) | HirDef::PrimTy(..) | HirDef::SelfTy(..) | HirDef::Label(..) | diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 1c562859bb48d..55cfac20e9410 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -4238,13 +4238,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { }; let count = tcx.const_eval(param_env.and(global_id)); - if let Err(ref err) = count { - err.report_as_error( - tcx.at(tcx.def_span(count_def_id)), - "could not evaluate repeat length", - ); - } - let uty = match expected { ExpectHasType(uty) => { match uty.sty { diff --git a/src/test/compile-fail/const-fn-error.rs b/src/test/compile-fail/const-fn-error.rs index 6eda41730b307..0eee0b4c7b89d 100644 --- a/src/test/compile-fail/const-fn-error.rs +++ b/src/test/compile-fail/const-fn-error.rs @@ -16,7 +16,7 @@ const fn f(x: usize) -> usize { let mut sum = 0; //~^ let bindings in constant functions are unstable //~| statements in constant functions are unstable - for i in 0..x { + for i in 0..x { //~ ERROR E0080 //~^ ERROR E0015 //~| ERROR E0019 sum += i; @@ -26,5 +26,5 @@ const fn f(x: usize) -> usize { #[allow(unused_variables)] fn main() { - let a : [i32; f(X)]; //~ ERROR E0080 + let a : [i32; f(X)]; } diff --git a/src/test/compile-fail/issue-52443.rs b/src/test/compile-fail/issue-52443.rs index 2ae94f6d6420a..1ed513033fd5d 100644 --- a/src/test/compile-fail/issue-52443.rs +++ b/src/test/compile-fail/issue-52443.rs @@ -14,5 +14,5 @@ fn main() { [(); {while true {break}; 0}]; //~ ERROR constant contains unimplemented expression type [(); { for _ in 0usize.. {}; 0}]; //~ ERROR calls in constants are limited to constant functions //~^ ERROR constant contains unimplemented expression type - //~| ERROR could not evaluate repeat length + //~| ERROR evaluation of constant value failed } diff --git a/src/test/ui/array_const_index-0.rs b/src/test/ui/array_const_index-0.rs index 91007fcd63a28..2403d50db3953 100644 --- a/src/test/ui/array_const_index-0.rs +++ b/src/test/ui/array_const_index-0.rs @@ -11,8 +11,9 @@ const A: &'static [i32] = &[]; const B: i32 = (&A)[1]; //~^ index out of bounds: the len is 0 but the index is 1 -//~| ERROR this constant cannot be used +//~| ERROR any use of this value will cause an error +//~| ERROR any use of this value will cause an error fn main() { - let _ = B; + let _ = B; //~ ERROR erroneous constant used } diff --git a/src/test/ui/array_const_index-0.stderr b/src/test/ui/array_const_index-0.stderr index b71d224f4f0eb..95ed88bde108c 100644 --- a/src/test/ui/array_const_index-0.stderr +++ b/src/test/ui/array_const_index-0.stderr @@ -1,4 +1,4 @@ -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/array_const_index-0.rs:12:1 | LL | const B: i32 = (&A)[1]; @@ -8,5 +8,20 @@ LL | const B: i32 = (&A)[1]; | = note: #[deny(const_err)] on by default -error: aborting due to previous error +error: any use of this value will cause an error + --> $DIR/array_const_index-0.rs:12:1 + | +LL | const B: i32 = (&A)[1]; + | ^^^^^^^^^^^^^^^-------^ + | | + | index out of bounds: the len is 0 but the index is 1 + +error[E0080]: erroneous constant used + --> $DIR/array_const_index-0.rs:18:13 + | +LL | let _ = B; //~ ERROR erroneous constant used + | ^ referenced constant has errors + +error: aborting due to 3 previous errors +For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/array_const_index-1.rs b/src/test/ui/array_const_index-1.rs index 66739d308a70f..0a49348761c08 100644 --- a/src/test/ui/array_const_index-1.rs +++ b/src/test/ui/array_const_index-1.rs @@ -11,8 +11,9 @@ const A: [i32; 0] = []; const B: i32 = A[1]; //~^ index out of bounds: the len is 0 but the index is 1 -//~| ERROR this constant cannot be used +//~| ERROR any use of this value will cause an error +//~| ERROR any use of this value will cause an error fn main() { - let _ = B; + let _ = B; //~ ERROR erroneous constant used } diff --git a/src/test/ui/array_const_index-1.stderr b/src/test/ui/array_const_index-1.stderr index 02f86a693af0c..5fcfc14e2c0d0 100644 --- a/src/test/ui/array_const_index-1.stderr +++ b/src/test/ui/array_const_index-1.stderr @@ -1,4 +1,4 @@ -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/array_const_index-1.rs:12:1 | LL | const B: i32 = A[1]; @@ -8,5 +8,20 @@ LL | const B: i32 = A[1]; | = note: #[deny(const_err)] on by default -error: aborting due to previous error +error: any use of this value will cause an error + --> $DIR/array_const_index-1.rs:12:1 + | +LL | const B: i32 = A[1]; + | ^^^^^^^^^^^^^^^----^ + | | + | index out of bounds: the len is 0 but the index is 1 + +error[E0080]: erroneous constant used + --> $DIR/array_const_index-1.rs:18:13 + | +LL | let _ = B; //~ ERROR erroneous constant used + | ^ referenced constant has errors + +error: aborting due to 3 previous errors +For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-array-oob.rs b/src/test/ui/consts/const-array-oob.rs index 22a3c5ceeb714..227364cffd115 100644 --- a/src/test/ui/consts/const-array-oob.rs +++ b/src/test/ui/consts/const-array-oob.rs @@ -16,7 +16,7 @@ const FOO: [usize; 3] = [1, 2, 3]; const BAR: usize = FOO[5]; // no error, because the error below occurs before regular const eval const BLUB: [u32; FOO[4]] = [5, 6]; -//~^ ERROR could not evaluate constant expression [E0080] +//~^ ERROR evaluation of constant value failed [E0080] //~| index out of bounds: the len is 3 but the index is 4 fn main() { diff --git a/src/test/ui/consts/const-array-oob.stderr b/src/test/ui/consts/const-array-oob.stderr index 19ec9a4aa1745..5986376938b90 100644 --- a/src/test/ui/consts/const-array-oob.stderr +++ b/src/test/ui/consts/const-array-oob.stderr @@ -1,19 +1,9 @@ -error: index out of bounds: the len is 3 but the index is 4 +error[E0080]: evaluation of constant value failed --> $DIR/const-array-oob.rs:18:19 | LL | const BLUB: [u32; FOO[4]] = [5, 6]; - | ^^^^^^ - | - = note: #[deny(const_err)] on by default - -error[E0080]: could not evaluate constant expression - --> $DIR/const-array-oob.rs:18:13 - | -LL | const BLUB: [u32; FOO[4]] = [5, 6]; - | ^^^^^^------^ - | | - | index out of bounds: the len is 3 but the index is 4 + | ^^^^^^ index out of bounds: the len is 3 but the index is 4 -error: aborting due to 2 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-call.stderr b/src/test/ui/consts/const-call.stderr index 81be93e916e8b..e0427d0d04c9a 100644 --- a/src/test/ui/consts/const-call.stderr +++ b/src/test/ui/consts/const-call.stderr @@ -4,6 +4,12 @@ error[E0015]: calls in constants are limited to constant functions, tuple struct LL | let _ = [0; f(2)]; | ^^^^ -error: aborting due to previous error +error[E0080]: evaluation of constant value failed + --> $DIR/const-call.rs:16:17 + | +LL | let _ = [0; f(2)]; + | ^^^^ calling non-const fn `f` + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0015`. diff --git a/src/test/ui/consts/const-err-early.rs b/src/test/ui/consts/const-err-early.rs index 39b1b342eac31..488e6f49e14bb 100644 --- a/src/test/ui/consts/const-err-early.rs +++ b/src/test/ui/consts/const-err-early.rs @@ -11,16 +11,17 @@ #![deny(const_err)] pub const A: i8 = -std::i8::MIN; //~ ERROR const_err +//~^ ERROR const_err pub const B: u8 = 200u8 + 200u8; //~ ERROR const_err pub const C: u8 = 200u8 * 4; //~ ERROR const_err pub const D: u8 = 42u8 - (42u8 + 1); //~ ERROR const_err pub const E: u8 = [5u8][1]; //~ ERROR const_err fn main() { - let _a = A; - let _b = B; - let _c = C; - let _d = D; - let _e = E; - let _e = [6u8][1]; + let _a = A; //~ ERROR erroneous constant used + let _b = B; //~ ERROR erroneous constant used + let _c = C; //~ ERROR erroneous constant used + let _d = D; //~ ERROR erroneous constant used + let _e = E; //~ ERROR erroneous constant used + let _e = [6u8][1]; //~ ERROR index out of bounds } diff --git a/src/test/ui/consts/const-err-early.stderr b/src/test/ui/consts/const-err-early.stderr index 36f3ac1a9bca2..21c7bf0a70a49 100644 --- a/src/test/ui/consts/const-err-early.stderr +++ b/src/test/ui/consts/const-err-early.stderr @@ -1,4 +1,4 @@ -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const-err-early.rs:13:1 | LL | pub const A: i8 = -std::i8::MIN; //~ ERROR const_err @@ -12,37 +12,82 @@ note: lint level defined here LL | #![deny(const_err)] | ^^^^^^^^^ -error: this constant cannot be used - --> $DIR/const-err-early.rs:14:1 +error: any use of this value will cause an error + --> $DIR/const-err-early.rs:15:1 | LL | pub const B: u8 = 200u8 + 200u8; //~ ERROR const_err | ^^^^^^^^^^^^^^^^^^-------------^ | | | attempt to add with overflow -error: this constant cannot be used - --> $DIR/const-err-early.rs:15:1 +error: any use of this value will cause an error + --> $DIR/const-err-early.rs:16:1 | LL | pub const C: u8 = 200u8 * 4; //~ ERROR const_err | ^^^^^^^^^^^^^^^^^^---------^ | | | attempt to multiply with overflow -error: this constant cannot be used - --> $DIR/const-err-early.rs:16:1 +error: any use of this value will cause an error + --> $DIR/const-err-early.rs:17:1 | LL | pub const D: u8 = 42u8 - (42u8 + 1); //~ ERROR const_err | ^^^^^^^^^^^^^^^^^^-----------------^ | | | attempt to subtract with overflow -error: this constant cannot be used - --> $DIR/const-err-early.rs:17:1 +error: any use of this value will cause an error + --> $DIR/const-err-early.rs:18:1 | LL | pub const E: u8 = [5u8][1]; //~ ERROR const_err | ^^^^^^^^^^^^^^^^^^--------^ | | | index out of bounds: the len is 1 but the index is 1 -error: aborting due to 5 previous errors +error: any use of this value will cause an error + --> $DIR/const-err-early.rs:13:1 + | +LL | pub const A: i8 = -std::i8::MIN; //~ ERROR const_err + | ^^^^^^^^^^^^^^^^^^-------------^ + | | + | attempt to negate with overflow + +error[E0080]: erroneous constant used + --> $DIR/const-err-early.rs:21:14 + | +LL | let _a = A; //~ ERROR erroneous constant used + | ^ referenced constant has errors + +error[E0080]: erroneous constant used + --> $DIR/const-err-early.rs:22:14 + | +LL | let _b = B; //~ ERROR erroneous constant used + | ^ referenced constant has errors + +error[E0080]: erroneous constant used + --> $DIR/const-err-early.rs:23:14 + | +LL | let _c = C; //~ ERROR erroneous constant used + | ^ referenced constant has errors + +error[E0080]: erroneous constant used + --> $DIR/const-err-early.rs:24:14 + | +LL | let _d = D; //~ ERROR erroneous constant used + | ^ referenced constant has errors + +error[E0080]: erroneous constant used + --> $DIR/const-err-early.rs:25:14 + | +LL | let _e = E; //~ ERROR erroneous constant used + | ^ referenced constant has errors + +error: index out of bounds: the len is 1 but the index is 1 + --> $DIR/const-err-early.rs:26:14 + | +LL | let _e = [6u8][1]; //~ ERROR index out of bounds + | ^^^^^^^^ + +error: aborting due to 12 previous errors +For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-err-multi.rs b/src/test/ui/consts/const-err-multi.rs index f2ee8a7078c7c..c3960b839925f 100644 --- a/src/test/ui/consts/const-err-multi.rs +++ b/src/test/ui/consts/const-err-multi.rs @@ -11,17 +11,16 @@ #![deny(const_err)] pub const A: i8 = -std::i8::MIN; -//~^ ERROR this constant cannot be used -pub const B: i8 = A; //~^ ERROR const_err //~| ERROR const_err +pub const B: i8 = A; +//~^ ERROR const_err pub const C: u8 = A as u8; //~^ ERROR const_err -//~| ERROR const_err pub const D: i8 = 50 - A; //~^ ERROR const_err -//~| ERROR const_err fn main() { let _ = (A, B, C, D); + //~^ ERROR erroneous constant used } diff --git a/src/test/ui/consts/const-err-multi.stderr b/src/test/ui/consts/const-err-multi.stderr index dd3eaa4c47b9d..0717302dbf9aa 100644 --- a/src/test/ui/consts/const-err-multi.stderr +++ b/src/test/ui/consts/const-err-multi.stderr @@ -1,4 +1,4 @@ -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const-err-multi.rs:13:1 | LL | pub const A: i8 = -std::i8::MIN; @@ -12,33 +12,15 @@ note: lint level defined here LL | #![deny(const_err)] | ^^^^^^^^^ -error: referenced constant has errors - --> $DIR/const-err-multi.rs:15:1 - | -LL | pub const A: i8 = -std::i8::MIN; - | ------------- attempt to negate with overflow -LL | //~^ ERROR this constant cannot be used -LL | pub const B: i8 = A; - | ^^^^^^^^^^^^^^^^^^^^ - -error: this constant cannot be used - --> $DIR/const-err-multi.rs:15:1 +error: any use of this value will cause an error + --> $DIR/const-err-multi.rs:16:1 | LL | pub const B: i8 = A; | ^^^^^^^^^^^^^^^^^^-^ | | | referenced constant has errors -error: referenced constant has errors - --> $DIR/const-err-multi.rs:18:1 - | -LL | pub const A: i8 = -std::i8::MIN; - | ------------- attempt to negate with overflow -... -LL | pub const C: u8 = A as u8; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const-err-multi.rs:18:1 | LL | pub const C: u8 = A as u8; @@ -46,22 +28,28 @@ LL | pub const C: u8 = A as u8; | | | referenced constant has errors -error: referenced constant has errors - --> $DIR/const-err-multi.rs:21:1 - | -LL | pub const A: i8 = -std::i8::MIN; - | ------------- attempt to negate with overflow -... -LL | pub const D: i8 = 50 - A; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: this constant cannot be used - --> $DIR/const-err-multi.rs:21:1 +error: any use of this value will cause an error + --> $DIR/const-err-multi.rs:20:1 | LL | pub const D: i8 = 50 - A; | ^^^^^^^^^^^^^^^^^^------^ | | | referenced constant has errors -error: aborting due to 7 previous errors +error: any use of this value will cause an error + --> $DIR/const-err-multi.rs:13:1 + | +LL | pub const A: i8 = -std::i8::MIN; + | ^^^^^^^^^^^^^^^^^^-------------^ + | | + | attempt to negate with overflow + +error[E0080]: erroneous constant used + --> $DIR/const-err-multi.rs:24:13 + | +LL | let _ = (A, B, C, D); + | ^^^^^^^^^^^^ referenced constant has errors + +error: aborting due to 6 previous errors +For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-err.rs b/src/test/ui/consts/const-err.rs index 8683f6a023192..7c59e8b953596 100644 --- a/src/test/ui/consts/const-err.rs +++ b/src/test/ui/consts/const-err.rs @@ -10,23 +10,18 @@ // compile-flags: -Zforce-overflow-checks=on -// these errors are not actually "const_err", they occur in codegen/consts -// and are unconditional warnings that can't be denied or allowed - #![allow(exceeding_bitshifts)] -#![allow(const_err)] +#![warn(const_err)] fn black_box(_: T) { unimplemented!() } -// Make sure that the two uses get two errors. const FOO: u8 = [5u8][1]; -//~^ ERROR constant evaluation error -//~| index out of bounds: the len is 1 but the index is 1 +//~^ WARN any use of this value will cause an error +//~| WARN any use of this value will cause an error fn main() { black_box((FOO, FOO)); - //~^ ERROR referenced constant has errors - //~| ERROR could not evaluate constant + //~^ ERROR erroneous constant used } diff --git a/src/test/ui/consts/const-err.stderr b/src/test/ui/consts/const-err.stderr index 1674f99b6823d..b46277f4b019f 100644 --- a/src/test/ui/consts/const-err.stderr +++ b/src/test/ui/consts/const-err.stderr @@ -1,26 +1,31 @@ -error[E0080]: referenced constant has errors - --> $DIR/const-err.rs:29:15 +warning: any use of this value will cause an error + --> $DIR/const-err.rs:20:1 | LL | const FOO: u8 = [5u8][1]; - | -------- index out of bounds: the len is 1 but the index is 1 -... -LL | black_box((FOO, FOO)); - | ^^^^^^^^^^ - -error[E0080]: could not evaluate constant - --> $DIR/const-err.rs:29:15 + | ^^^^^^^^^^^^^^^^--------^ + | | + | index out of bounds: the len is 1 but the index is 1 | -LL | black_box((FOO, FOO)); - | ^^^^^^^^^^ referenced constant has errors +note: lint level defined here + --> $DIR/const-err.rs:14:9 + | +LL | #![warn(const_err)] + | ^^^^^^^^^ -error[E0080]: constant evaluation error - --> $DIR/const-err.rs:24:1 +warning: any use of this value will cause an error + --> $DIR/const-err.rs:20:1 | LL | const FOO: u8 = [5u8][1]; | ^^^^^^^^^^^^^^^^--------^ | | | index out of bounds: the len is 1 but the index is 1 -error: aborting due to 3 previous errors +error[E0080]: erroneous constant used + --> $DIR/const-err.rs:25:15 + | +LL | black_box((FOO, FOO)); + | ^^^^^^^^^^ referenced constant has errors + +error: aborting due to previous error For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-err4.rs b/src/test/ui/consts/const-err4.rs index 10376d5780908..0bbc254453cff 100644 --- a/src/test/ui/consts/const-err4.rs +++ b/src/test/ui/consts/const-err4.rs @@ -16,7 +16,7 @@ union Foo { enum Bar { Boo = [unsafe { Foo { b: () }.a }; 4][3], - //~^ ERROR could not evaluate enum discriminant + //~^ ERROR evaluation of constant value failed } fn main() { diff --git a/src/test/ui/consts/const-err4.stderr b/src/test/ui/consts/const-err4.stderr index dc64737b22f5e..bb50f38062ee9 100644 --- a/src/test/ui/consts/const-err4.stderr +++ b/src/test/ui/consts/const-err4.stderr @@ -1,4 +1,4 @@ -error[E0080]: could not evaluate enum discriminant +error[E0080]: evaluation of constant value failed --> $DIR/const-err4.rs:18:11 | LL | Boo = [unsafe { Foo { b: () }.a }; 4][3], diff --git a/src/test/ui/consts/const-eval/conditional_array_execution.nll.stderr b/src/test/ui/consts/const-eval/conditional_array_execution.nll.stderr new file mode 100644 index 0000000000000..b6c35b8ebbd93 --- /dev/null +++ b/src/test/ui/consts/const-eval/conditional_array_execution.nll.stderr @@ -0,0 +1,29 @@ +warning: any use of this value will cause an error + --> $DIR/conditional_array_execution.rs:15:1 + | +LL | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize]; + | ^^^^^^^^^^^^^^^^^^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | attempt to subtract with overflow + | +note: lint level defined here + --> $DIR/conditional_array_execution.rs:11:9 + | +LL | #![warn(const_err)] + | ^^^^^^^^^ + +error[E0080]: evaluation of constant expression failed + --> $DIR/conditional_array_execution.rs:19:14 + | +LL | println!("{}", FOO); + | ^^^^ --- referenced constant has errors + +error[E0080]: evaluation of constant expression failed + --> $DIR/conditional_array_execution.rs:19:20 + | +LL | println!("{}", FOO); + | ^^^ referenced constant has errors + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-eval/conditional_array_execution.rs b/src/test/ui/consts/const-eval/conditional_array_execution.rs index 8142ed0155aae..4e245c6b9e8cf 100644 --- a/src/test/ui/consts/const-eval/conditional_array_execution.rs +++ b/src/test/ui/consts/const-eval/conditional_array_execution.rs @@ -13,10 +13,9 @@ const X: u32 = 5; const Y: u32 = 6; const FOO: u32 = [X - Y, Y - X][(X < Y) as usize]; -//~^ WARN this constant cannot be used +//~^ WARN any use of this value will cause an error fn main() { println!("{}", FOO); //~^ ERROR - //~| ERROR } diff --git a/src/test/ui/consts/const-eval/conditional_array_execution.stderr b/src/test/ui/consts/const-eval/conditional_array_execution.stderr index 29f5f8e2ade59..90131080ed16b 100644 --- a/src/test/ui/consts/const-eval/conditional_array_execution.stderr +++ b/src/test/ui/consts/const-eval/conditional_array_execution.stderr @@ -1,4 +1,4 @@ -warning: this constant cannot be used +warning: any use of this value will cause an error --> $DIR/conditional_array_execution.rs:15:1 | LL | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize]; @@ -12,21 +12,12 @@ note: lint level defined here LL | #![warn(const_err)] | ^^^^^^^^^ -error[E0080]: referenced constant has errors - --> $DIR/conditional_array_execution.rs:19:20 - | -LL | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize]; - | ----- attempt to subtract with overflow -... -LL | println!("{}", FOO); - | ^^^ - -error[E0080]: erroneous constant used +error[E0080]: evaluation of constant expression failed --> $DIR/conditional_array_execution.rs:19:20 | LL | println!("{}", FOO); | ^^^ 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`. diff --git a/src/test/ui/consts/const-eval/const-eval-overflow-2.stderr b/src/test/ui/consts/const-eval/const-eval-overflow-2.stderr index e99d409880e07..70c98977301a9 100644 --- a/src/test/ui/consts/const-eval/const-eval-overflow-2.stderr +++ b/src/test/ui/consts/const-eval/const-eval-overflow-2.stderr @@ -1,12 +1,8 @@ -error[E0080]: could not evaluate constant pattern +error: could not evaluate constant pattern --> $DIR/const-eval-overflow-2.rs:25:9 | -LL | const NEG_NEG_128: i8 = -NEG_128; - | -------- attempt to negate with overflow -... LL | NEG_NEG_128 => println!("A"), | ^^^^^^^^^^^ error: aborting due to previous error -For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-eval/const-eval-overflow-3.stderr b/src/test/ui/consts/const-eval/const-eval-overflow-3.stderr index f2b4e6b3b567b..bcef9eff2f899 100644 --- a/src/test/ui/consts/const-eval/const-eval-overflow-3.stderr +++ b/src/test/ui/consts/const-eval/const-eval-overflow-3.stderr @@ -1,19 +1,9 @@ -error: attempt to add with overflow +error[E0080]: evaluation of constant value failed --> $DIR/const-eval-overflow-3.rs:30:11 | LL | = [0; (i8::MAX + 1) as usize]; - | ^^^^^^^^^^^^^ - | - = note: #[deny(const_err)] on by default - -error[E0080]: could not evaluate repeat length - --> $DIR/const-eval-overflow-3.rs:30:11 - | -LL | = [0; (i8::MAX + 1) as usize]; - | -------------^^^^^^^^^ - | | - | attempt to add with overflow + | ^^^^^^^^^^^^^ attempt to add with overflow -error: aborting due to 2 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-eval/const-eval-overflow-4.rs b/src/test/ui/consts/const-eval/const-eval-overflow-4.rs index e9fc8ec0c374e..5d692d9d7fc9e 100644 --- a/src/test/ui/consts/const-eval/const-eval-overflow-4.rs +++ b/src/test/ui/consts/const-eval/const-eval-overflow-4.rs @@ -21,8 +21,7 @@ use std::{u8, u16, u32, u64, usize}; const A_I8_T : [u32; (i8::MAX as i8 + 1i8) as usize] - //~^ ERROR attempt to add with overflow - //~| ERROR could not evaluate constant expression + //~^ ERROR evaluation of constant value failed = [0; (i8::MAX as usize) + 1]; fn main() { diff --git a/src/test/ui/consts/const-eval/const-eval-overflow-4.stderr b/src/test/ui/consts/const-eval/const-eval-overflow-4.stderr index b12aa032b6070..fd186dc719cd5 100644 --- a/src/test/ui/consts/const-eval/const-eval-overflow-4.stderr +++ b/src/test/ui/consts/const-eval/const-eval-overflow-4.stderr @@ -1,19 +1,9 @@ -error: attempt to add with overflow +error[E0080]: evaluation of constant value failed --> $DIR/const-eval-overflow-4.rs:23:13 | LL | : [u32; (i8::MAX as i8 + 1i8) as usize] - | ^^^^^^^^^^^^^^^^^^^^^ - | - = note: #[deny(const_err)] on by default - -error[E0080]: could not evaluate constant expression - --> $DIR/const-eval-overflow-4.rs:23:7 - | -LL | : [u32; (i8::MAX as i8 + 1i8) as usize] - | ^^^^^^---------------------^^^^^^^^^^ - | | - | attempt to add with overflow + | ^^^^^^^^^^^^^^^^^^^^^ attempt to add with overflow -error: aborting due to 2 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-eval/const-eval-overflow2.rs b/src/test/ui/consts/const-eval/const-eval-overflow2.rs index 88fc518277535..ee29423a90cde 100644 --- a/src/test/ui/consts/const-eval/const-eval-overflow2.rs +++ b/src/test/ui/consts/const-eval/const-eval-overflow2.rs @@ -21,62 +21,55 @@ use std::fmt; use std::{i8, i16, i32, i64, isize}; use std::{u8, u16, u32, u64, usize}; -const VALS_I8: (i8,) = - //~^ ERROR this constant cannot be used +const VALS_I8: (i8,) = //~ ERROR any use of this value will cause an error + //~^ const_err ( i8::MIN - 1, ); -const VALS_I16: (i16,) = - //~^ ERROR this constant cannot be used +const VALS_I16: (i16,) = //~ ERROR any use of this value will cause an error ( i16::MIN - 1, ); -const VALS_I32: (i32,) = - //~^ ERROR this constant cannot be used +const VALS_I32: (i32,) = //~ ERROR any use of this value will cause an error ( i32::MIN - 1, ); -const VALS_I64: (i64,) = - //~^ ERROR this constant cannot be used +const VALS_I64: (i64,) = //~ ERROR any use of this value will cause an error ( i64::MIN - 1, ); -const VALS_U8: (u8,) = - //~^ ERROR this constant cannot be used +const VALS_U8: (u8,) = //~ ERROR any use of this value will cause an error ( u8::MIN - 1, ); -const VALS_U16: (u16,) = ( - //~^ ERROR this constant cannot be used +const VALS_U16: (u16,) = ( //~ ERROR any use of this value will cause an error u16::MIN - 1, ); -const VALS_U32: (u32,) = ( - //~^ ERROR this constant cannot be used +const VALS_U32: (u32,) = ( //~ ERROR any use of this value will cause an error u32::MIN - 1, ); -const VALS_U64: (u64,) = - //~^ ERROR this constant cannot be used +const VALS_U64: (u64,) = //~ ERROR any use of this value will cause an error ( u64::MIN - 1, ); fn main() { - foo(VALS_I8); - foo(VALS_I16); - foo(VALS_I32); - foo(VALS_I64); + foo(VALS_I8); //~ ERROR erroneous constant used + foo(VALS_I16); //~ ERROR erroneous constant used + foo(VALS_I32); //~ ERROR erroneous constant used + foo(VALS_I64); //~ ERROR erroneous constant used - foo(VALS_U8); - foo(VALS_U16); - foo(VALS_U32); - foo(VALS_U64); + foo(VALS_U8); //~ ERROR erroneous constant used + foo(VALS_U16); //~ ERROR erroneous constant used + foo(VALS_U32); //~ ERROR erroneous constant used + foo(VALS_U64); //~ ERROR erroneous constant used } fn foo(_: T) { diff --git a/src/test/ui/consts/const-eval/const-eval-overflow2.stderr b/src/test/ui/consts/const-eval/const-eval-overflow2.stderr index 5cf5ce367e253..f10a6eee6de9c 100644 --- a/src/test/ui/consts/const-eval/const-eval-overflow2.stderr +++ b/src/test/ui/consts/const-eval/const-eval-overflow2.stderr @@ -1,8 +1,8 @@ -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const-eval-overflow2.rs:24:1 | -LL | / const VALS_I8: (i8,) = -LL | | //~^ ERROR this constant cannot be used +LL | / const VALS_I8: (i8,) = //~ ERROR any use of this value will cause an error +LL | | //~^ const_err LL | | ( LL | | i8::MIN - 1, | | ----------- attempt to subtract with overflow @@ -15,80 +15,133 @@ note: lint level defined here LL | #![deny(const_err)] | ^^^^^^^^^ -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const-eval-overflow2.rs:30:1 | -LL | / const VALS_I16: (i16,) = -LL | | //~^ ERROR this constant cannot be used +LL | / const VALS_I16: (i16,) = //~ ERROR any use of this value will cause an error LL | | ( LL | | i16::MIN - 1, | | ------------ attempt to subtract with overflow LL | | ); | |_______^ -error: this constant cannot be used - --> $DIR/const-eval-overflow2.rs:36:1 +error: any use of this value will cause an error + --> $DIR/const-eval-overflow2.rs:35:1 | -LL | / const VALS_I32: (i32,) = -LL | | //~^ ERROR this constant cannot be used +LL | / const VALS_I32: (i32,) = //~ ERROR any use of this value will cause an error LL | | ( LL | | i32::MIN - 1, | | ------------ attempt to subtract with overflow LL | | ); | |_______^ -error: this constant cannot be used - --> $DIR/const-eval-overflow2.rs:42:1 +error: any use of this value will cause an error + --> $DIR/const-eval-overflow2.rs:40:1 | -LL | / const VALS_I64: (i64,) = -LL | | //~^ ERROR this constant cannot be used +LL | / const VALS_I64: (i64,) = //~ ERROR any use of this value will cause an error LL | | ( LL | | i64::MIN - 1, | | ------------ attempt to subtract with overflow LL | | ); | |_______^ -error: this constant cannot be used - --> $DIR/const-eval-overflow2.rs:48:1 +error: any use of this value will cause an error + --> $DIR/const-eval-overflow2.rs:45:1 | -LL | / const VALS_U8: (u8,) = -LL | | //~^ ERROR this constant cannot be used +LL | / const VALS_U8: (u8,) = //~ ERROR any use of this value will cause an error LL | | ( LL | | u8::MIN - 1, | | ----------- attempt to subtract with overflow LL | | ); | |_______^ -error: this constant cannot be used - --> $DIR/const-eval-overflow2.rs:54:1 +error: any use of this value will cause an error + --> $DIR/const-eval-overflow2.rs:50:1 | -LL | / const VALS_U16: (u16,) = ( -LL | | //~^ ERROR this constant cannot be used +LL | / const VALS_U16: (u16,) = ( //~ ERROR any use of this value will cause an error LL | | u16::MIN - 1, | | ------------ attempt to subtract with overflow LL | | ); | |_______^ -error: this constant cannot be used - --> $DIR/const-eval-overflow2.rs:59:1 +error: any use of this value will cause an error + --> $DIR/const-eval-overflow2.rs:54:1 | -LL | / const VALS_U32: (u32,) = ( -LL | | //~^ ERROR this constant cannot be used +LL | / const VALS_U32: (u32,) = ( //~ ERROR any use of this value will cause an error LL | | u32::MIN - 1, | | ------------ attempt to subtract with overflow LL | | ); | |_______^ -error: this constant cannot be used - --> $DIR/const-eval-overflow2.rs:64:1 +error: any use of this value will cause an error + --> $DIR/const-eval-overflow2.rs:58:1 | -LL | / const VALS_U64: (u64,) = -LL | | //~^ ERROR this constant cannot be used +LL | / const VALS_U64: (u64,) = //~ ERROR any use of this value will cause an error LL | | ( LL | | u64::MIN - 1, | | ------------ attempt to subtract with overflow LL | | ); | |_______^ -error: aborting due to 8 previous errors +error: any use of this value will cause an error + --> $DIR/const-eval-overflow2.rs:24:1 + | +LL | / const VALS_I8: (i8,) = //~ ERROR any use of this value will cause an error +LL | | //~^ const_err +LL | | ( +LL | | i8::MIN - 1, + | | ----------- attempt to subtract with overflow +LL | | ); + | |_______^ + +error[E0080]: erroneous constant used + --> $DIR/const-eval-overflow2.rs:64:5 + | +LL | foo(VALS_I8); //~ ERROR erroneous constant used + | ^^^^^^^^^^^^ referenced constant has errors + +error[E0080]: erroneous constant used + --> $DIR/const-eval-overflow2.rs:65:5 + | +LL | foo(VALS_I16); //~ ERROR erroneous constant used + | ^^^^^^^^^^^^^ referenced constant has errors + +error[E0080]: erroneous constant used + --> $DIR/const-eval-overflow2.rs:66:5 + | +LL | foo(VALS_I32); //~ ERROR erroneous constant used + | ^^^^^^^^^^^^^ referenced constant has errors + +error[E0080]: erroneous constant used + --> $DIR/const-eval-overflow2.rs:67:5 + | +LL | foo(VALS_I64); //~ ERROR erroneous constant used + | ^^^^^^^^^^^^^ referenced constant has errors + +error[E0080]: erroneous constant used + --> $DIR/const-eval-overflow2.rs:69:5 + | +LL | foo(VALS_U8); //~ ERROR erroneous constant used + | ^^^^^^^^^^^^ referenced constant has errors + +error[E0080]: erroneous constant used + --> $DIR/const-eval-overflow2.rs:70:5 + | +LL | foo(VALS_U16); //~ ERROR erroneous constant used + | ^^^^^^^^^^^^^ referenced constant has errors + +error[E0080]: erroneous constant used + --> $DIR/const-eval-overflow2.rs:71:5 + | +LL | foo(VALS_U32); //~ ERROR erroneous constant used + | ^^^^^^^^^^^^^ referenced constant has errors + +error[E0080]: erroneous constant used + --> $DIR/const-eval-overflow2.rs:72:5 + | +LL | foo(VALS_U64); //~ ERROR erroneous constant used + | ^^^^^^^^^^^^^ referenced constant has errors + +error: aborting due to 17 previous errors +For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-eval/const-eval-overflow2b.rs b/src/test/ui/consts/const-eval/const-eval-overflow2b.rs index 1878daea93198..55dc2a894054a 100644 --- a/src/test/ui/consts/const-eval/const-eval-overflow2b.rs +++ b/src/test/ui/consts/const-eval/const-eval-overflow2b.rs @@ -21,62 +21,55 @@ use std::fmt; use std::{i8, i16, i32, i64, isize}; use std::{u8, u16, u32, u64, usize}; -const VALS_I8: (i8,) = - //~^ ERROR this constant cannot be used +const VALS_I8: (i8,) = //~ ERROR any use of this value will cause an error + //~^ const_err ( i8::MAX + 1, ); -const VALS_I16: (i16,) = - //~^ ERROR this constant cannot be used +const VALS_I16: (i16,) = //~ ERROR any use of this value will cause an error ( i16::MAX + 1, ); -const VALS_I32: (i32,) = - //~^ ERROR this constant cannot be used +const VALS_I32: (i32,) = //~ ERROR any use of this value will cause an error ( i32::MAX + 1, ); -const VALS_I64: (i64,) = - //~^ ERROR this constant cannot be used +const VALS_I64: (i64,) = //~ ERROR any use of this value will cause an error ( i64::MAX + 1, ); -const VALS_U8: (u8,) = - //~^ ERROR this constant cannot be used +const VALS_U8: (u8,) = //~ ERROR any use of this value will cause an error ( u8::MAX + 1, ); -const VALS_U16: (u16,) = ( - //~^ ERROR this constant cannot be used +const VALS_U16: (u16,) = ( //~ ERROR any use of this value will cause an error u16::MAX + 1, ); -const VALS_U32: (u32,) = ( - //~^ ERROR this constant cannot be used +const VALS_U32: (u32,) = ( //~ ERROR any use of this value will cause an error u32::MAX + 1, ); -const VALS_U64: (u64,) = - //~^ ERROR this constant cannot be used +const VALS_U64: (u64,) = //~ ERROR any use of this value will cause an error ( u64::MAX + 1, ); fn main() { - foo(VALS_I8); - foo(VALS_I16); - foo(VALS_I32); - foo(VALS_I64); + foo(VALS_I8); //~ ERROR erroneous constant used + foo(VALS_I16); //~ ERROR erroneous constant used + foo(VALS_I32); //~ ERROR erroneous constant used + foo(VALS_I64); //~ ERROR erroneous constant used - foo(VALS_U8); - foo(VALS_U16); - foo(VALS_U32); - foo(VALS_U64); + foo(VALS_U8); //~ ERROR erroneous constant used + foo(VALS_U16); //~ ERROR erroneous constant used + foo(VALS_U32); //~ ERROR erroneous constant used + foo(VALS_U64); //~ ERROR erroneous constant used } fn foo(_: T) { diff --git a/src/test/ui/consts/const-eval/const-eval-overflow2b.stderr b/src/test/ui/consts/const-eval/const-eval-overflow2b.stderr index 458a9e11e7573..3b78fb51a623a 100644 --- a/src/test/ui/consts/const-eval/const-eval-overflow2b.stderr +++ b/src/test/ui/consts/const-eval/const-eval-overflow2b.stderr @@ -1,8 +1,8 @@ -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const-eval-overflow2b.rs:24:1 | -LL | / const VALS_I8: (i8,) = -LL | | //~^ ERROR this constant cannot be used +LL | / const VALS_I8: (i8,) = //~ ERROR any use of this value will cause an error +LL | | //~^ const_err LL | | ( LL | | i8::MAX + 1, | | ----------- attempt to add with overflow @@ -15,80 +15,133 @@ note: lint level defined here LL | #![deny(const_err)] | ^^^^^^^^^ -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const-eval-overflow2b.rs:30:1 | -LL | / const VALS_I16: (i16,) = -LL | | //~^ ERROR this constant cannot be used +LL | / const VALS_I16: (i16,) = //~ ERROR any use of this value will cause an error LL | | ( LL | | i16::MAX + 1, | | ------------ attempt to add with overflow LL | | ); | |_______^ -error: this constant cannot be used - --> $DIR/const-eval-overflow2b.rs:36:1 +error: any use of this value will cause an error + --> $DIR/const-eval-overflow2b.rs:35:1 | -LL | / const VALS_I32: (i32,) = -LL | | //~^ ERROR this constant cannot be used +LL | / const VALS_I32: (i32,) = //~ ERROR any use of this value will cause an error LL | | ( LL | | i32::MAX + 1, | | ------------ attempt to add with overflow LL | | ); | |_______^ -error: this constant cannot be used - --> $DIR/const-eval-overflow2b.rs:42:1 +error: any use of this value will cause an error + --> $DIR/const-eval-overflow2b.rs:40:1 | -LL | / const VALS_I64: (i64,) = -LL | | //~^ ERROR this constant cannot be used +LL | / const VALS_I64: (i64,) = //~ ERROR any use of this value will cause an error LL | | ( LL | | i64::MAX + 1, | | ------------ attempt to add with overflow LL | | ); | |_______^ -error: this constant cannot be used - --> $DIR/const-eval-overflow2b.rs:48:1 +error: any use of this value will cause an error + --> $DIR/const-eval-overflow2b.rs:45:1 | -LL | / const VALS_U8: (u8,) = -LL | | //~^ ERROR this constant cannot be used +LL | / const VALS_U8: (u8,) = //~ ERROR any use of this value will cause an error LL | | ( LL | | u8::MAX + 1, | | ----------- attempt to add with overflow LL | | ); | |_______^ -error: this constant cannot be used - --> $DIR/const-eval-overflow2b.rs:54:1 +error: any use of this value will cause an error + --> $DIR/const-eval-overflow2b.rs:50:1 | -LL | / const VALS_U16: (u16,) = ( -LL | | //~^ ERROR this constant cannot be used +LL | / const VALS_U16: (u16,) = ( //~ ERROR any use of this value will cause an error LL | | u16::MAX + 1, | | ------------ attempt to add with overflow LL | | ); | |_______^ -error: this constant cannot be used - --> $DIR/const-eval-overflow2b.rs:59:1 +error: any use of this value will cause an error + --> $DIR/const-eval-overflow2b.rs:54:1 | -LL | / const VALS_U32: (u32,) = ( -LL | | //~^ ERROR this constant cannot be used +LL | / const VALS_U32: (u32,) = ( //~ ERROR any use of this value will cause an error LL | | u32::MAX + 1, | | ------------ attempt to add with overflow LL | | ); | |_______^ -error: this constant cannot be used - --> $DIR/const-eval-overflow2b.rs:64:1 +error: any use of this value will cause an error + --> $DIR/const-eval-overflow2b.rs:58:1 | -LL | / const VALS_U64: (u64,) = -LL | | //~^ ERROR this constant cannot be used +LL | / const VALS_U64: (u64,) = //~ ERROR any use of this value will cause an error LL | | ( LL | | u64::MAX + 1, | | ------------ attempt to add with overflow LL | | ); | |_______^ -error: aborting due to 8 previous errors +error: any use of this value will cause an error + --> $DIR/const-eval-overflow2b.rs:24:1 + | +LL | / const VALS_I8: (i8,) = //~ ERROR any use of this value will cause an error +LL | | //~^ const_err +LL | | ( +LL | | i8::MAX + 1, + | | ----------- attempt to add with overflow +LL | | ); + | |_______^ + +error[E0080]: erroneous constant used + --> $DIR/const-eval-overflow2b.rs:64:5 + | +LL | foo(VALS_I8); //~ ERROR erroneous constant used + | ^^^^^^^^^^^^ referenced constant has errors + +error[E0080]: erroneous constant used + --> $DIR/const-eval-overflow2b.rs:65:5 + | +LL | foo(VALS_I16); //~ ERROR erroneous constant used + | ^^^^^^^^^^^^^ referenced constant has errors + +error[E0080]: erroneous constant used + --> $DIR/const-eval-overflow2b.rs:66:5 + | +LL | foo(VALS_I32); //~ ERROR erroneous constant used + | ^^^^^^^^^^^^^ referenced constant has errors + +error[E0080]: erroneous constant used + --> $DIR/const-eval-overflow2b.rs:67:5 + | +LL | foo(VALS_I64); //~ ERROR erroneous constant used + | ^^^^^^^^^^^^^ referenced constant has errors + +error[E0080]: erroneous constant used + --> $DIR/const-eval-overflow2b.rs:69:5 + | +LL | foo(VALS_U8); //~ ERROR erroneous constant used + | ^^^^^^^^^^^^ referenced constant has errors + +error[E0080]: erroneous constant used + --> $DIR/const-eval-overflow2b.rs:70:5 + | +LL | foo(VALS_U16); //~ ERROR erroneous constant used + | ^^^^^^^^^^^^^ referenced constant has errors + +error[E0080]: erroneous constant used + --> $DIR/const-eval-overflow2b.rs:71:5 + | +LL | foo(VALS_U32); //~ ERROR erroneous constant used + | ^^^^^^^^^^^^^ referenced constant has errors + +error[E0080]: erroneous constant used + --> $DIR/const-eval-overflow2b.rs:72:5 + | +LL | foo(VALS_U64); //~ ERROR erroneous constant used + | ^^^^^^^^^^^^^ referenced constant has errors + +error: aborting due to 17 previous errors +For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-eval/const-eval-overflow2c.rs b/src/test/ui/consts/const-eval/const-eval-overflow2c.rs index f3d28295bf81c..93ba11efc5998 100644 --- a/src/test/ui/consts/const-eval/const-eval-overflow2c.rs +++ b/src/test/ui/consts/const-eval/const-eval-overflow2c.rs @@ -21,62 +21,55 @@ use std::fmt; use std::{i8, i16, i32, i64, isize}; use std::{u8, u16, u32, u64, usize}; -const VALS_I8: (i8,) = - //~^ ERROR this constant cannot be used +const VALS_I8: (i8,) = //~ ERROR any use of this value will cause an error + //~^ const_err ( i8::MIN * 2, ); -const VALS_I16: (i16,) = - //~^ ERROR this constant cannot be used +const VALS_I16: (i16,) = //~ ERROR any use of this value will cause an error ( i16::MIN * 2, ); -const VALS_I32: (i32,) = - //~^ ERROR this constant cannot be used +const VALS_I32: (i32,) = //~ ERROR any use of this value will cause an error ( i32::MIN * 2, ); -const VALS_I64: (i64,) = - //~^ ERROR this constant cannot be used +const VALS_I64: (i64,) = //~ ERROR any use of this value will cause an error ( i64::MIN * 2, ); -const VALS_U8: (u8,) = - //~^ ERROR this constant cannot be used +const VALS_U8: (u8,) = //~ ERROR any use of this value will cause an error ( u8::MAX * 2, ); -const VALS_U16: (u16,) = ( - //~^ ERROR this constant cannot be used +const VALS_U16: (u16,) = ( //~ ERROR any use of this value will cause an error u16::MAX * 2, ); -const VALS_U32: (u32,) = ( - //~^ ERROR this constant cannot be used +const VALS_U32: (u32,) = ( //~ ERROR any use of this value will cause an error u32::MAX * 2, ); -const VALS_U64: (u64,) = - //~^ ERROR this constant cannot be used +const VALS_U64: (u64,) = //~ ERROR any use of this value will cause an error ( u64::MAX * 2, ); fn main() { - foo(VALS_I8); - foo(VALS_I16); - foo(VALS_I32); - foo(VALS_I64); + foo(VALS_I8); //~ ERROR erroneous constant used + foo(VALS_I16); //~ ERROR erroneous constant used + foo(VALS_I32); //~ ERROR erroneous constant used + foo(VALS_I64); //~ ERROR erroneous constant used - foo(VALS_U8); - foo(VALS_U16); - foo(VALS_U32); - foo(VALS_U64); + foo(VALS_U8); //~ ERROR erroneous constant used + foo(VALS_U16); //~ ERROR erroneous constant used + foo(VALS_U32); //~ ERROR erroneous constant used + foo(VALS_U64); //~ ERROR erroneous constant used } fn foo(_: T) { diff --git a/src/test/ui/consts/const-eval/const-eval-overflow2c.stderr b/src/test/ui/consts/const-eval/const-eval-overflow2c.stderr index 866860281cf66..abaae4bd54227 100644 --- a/src/test/ui/consts/const-eval/const-eval-overflow2c.stderr +++ b/src/test/ui/consts/const-eval/const-eval-overflow2c.stderr @@ -1,8 +1,8 @@ -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const-eval-overflow2c.rs:24:1 | -LL | / const VALS_I8: (i8,) = -LL | | //~^ ERROR this constant cannot be used +LL | / const VALS_I8: (i8,) = //~ ERROR any use of this value will cause an error +LL | | //~^ const_err LL | | ( LL | | i8::MIN * 2, | | ----------- attempt to multiply with overflow @@ -15,80 +15,133 @@ note: lint level defined here LL | #![deny(const_err)] | ^^^^^^^^^ -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const-eval-overflow2c.rs:30:1 | -LL | / const VALS_I16: (i16,) = -LL | | //~^ ERROR this constant cannot be used +LL | / const VALS_I16: (i16,) = //~ ERROR any use of this value will cause an error LL | | ( LL | | i16::MIN * 2, | | ------------ attempt to multiply with overflow LL | | ); | |_______^ -error: this constant cannot be used - --> $DIR/const-eval-overflow2c.rs:36:1 +error: any use of this value will cause an error + --> $DIR/const-eval-overflow2c.rs:35:1 | -LL | / const VALS_I32: (i32,) = -LL | | //~^ ERROR this constant cannot be used +LL | / const VALS_I32: (i32,) = //~ ERROR any use of this value will cause an error LL | | ( LL | | i32::MIN * 2, | | ------------ attempt to multiply with overflow LL | | ); | |_______^ -error: this constant cannot be used - --> $DIR/const-eval-overflow2c.rs:42:1 +error: any use of this value will cause an error + --> $DIR/const-eval-overflow2c.rs:40:1 | -LL | / const VALS_I64: (i64,) = -LL | | //~^ ERROR this constant cannot be used +LL | / const VALS_I64: (i64,) = //~ ERROR any use of this value will cause an error LL | | ( LL | | i64::MIN * 2, | | ------------ attempt to multiply with overflow LL | | ); | |_______^ -error: this constant cannot be used - --> $DIR/const-eval-overflow2c.rs:48:1 +error: any use of this value will cause an error + --> $DIR/const-eval-overflow2c.rs:45:1 | -LL | / const VALS_U8: (u8,) = -LL | | //~^ ERROR this constant cannot be used +LL | / const VALS_U8: (u8,) = //~ ERROR any use of this value will cause an error LL | | ( LL | | u8::MAX * 2, | | ----------- attempt to multiply with overflow LL | | ); | |_______^ -error: this constant cannot be used - --> $DIR/const-eval-overflow2c.rs:54:1 +error: any use of this value will cause an error + --> $DIR/const-eval-overflow2c.rs:50:1 | -LL | / const VALS_U16: (u16,) = ( -LL | | //~^ ERROR this constant cannot be used +LL | / const VALS_U16: (u16,) = ( //~ ERROR any use of this value will cause an error LL | | u16::MAX * 2, | | ------------ attempt to multiply with overflow LL | | ); | |_______^ -error: this constant cannot be used - --> $DIR/const-eval-overflow2c.rs:59:1 +error: any use of this value will cause an error + --> $DIR/const-eval-overflow2c.rs:54:1 | -LL | / const VALS_U32: (u32,) = ( -LL | | //~^ ERROR this constant cannot be used +LL | / const VALS_U32: (u32,) = ( //~ ERROR any use of this value will cause an error LL | | u32::MAX * 2, | | ------------ attempt to multiply with overflow LL | | ); | |_______^ -error: this constant cannot be used - --> $DIR/const-eval-overflow2c.rs:64:1 +error: any use of this value will cause an error + --> $DIR/const-eval-overflow2c.rs:58:1 | -LL | / const VALS_U64: (u64,) = -LL | | //~^ ERROR this constant cannot be used +LL | / const VALS_U64: (u64,) = //~ ERROR any use of this value will cause an error LL | | ( LL | | u64::MAX * 2, | | ------------ attempt to multiply with overflow LL | | ); | |_______^ -error: aborting due to 8 previous errors +error: any use of this value will cause an error + --> $DIR/const-eval-overflow2c.rs:24:1 + | +LL | / const VALS_I8: (i8,) = //~ ERROR any use of this value will cause an error +LL | | //~^ const_err +LL | | ( +LL | | i8::MIN * 2, + | | ----------- attempt to multiply with overflow +LL | | ); + | |_______^ + +error[E0080]: erroneous constant used + --> $DIR/const-eval-overflow2c.rs:64:5 + | +LL | foo(VALS_I8); //~ ERROR erroneous constant used + | ^^^^^^^^^^^^ referenced constant has errors + +error[E0080]: erroneous constant used + --> $DIR/const-eval-overflow2c.rs:65:5 + | +LL | foo(VALS_I16); //~ ERROR erroneous constant used + | ^^^^^^^^^^^^^ referenced constant has errors + +error[E0080]: erroneous constant used + --> $DIR/const-eval-overflow2c.rs:66:5 + | +LL | foo(VALS_I32); //~ ERROR erroneous constant used + | ^^^^^^^^^^^^^ referenced constant has errors + +error[E0080]: erroneous constant used + --> $DIR/const-eval-overflow2c.rs:67:5 + | +LL | foo(VALS_I64); //~ ERROR erroneous constant used + | ^^^^^^^^^^^^^ referenced constant has errors + +error[E0080]: erroneous constant used + --> $DIR/const-eval-overflow2c.rs:69:5 + | +LL | foo(VALS_U8); //~ ERROR erroneous constant used + | ^^^^^^^^^^^^ referenced constant has errors + +error[E0080]: erroneous constant used + --> $DIR/const-eval-overflow2c.rs:70:5 + | +LL | foo(VALS_U16); //~ ERROR erroneous constant used + | ^^^^^^^^^^^^^ referenced constant has errors + +error[E0080]: erroneous constant used + --> $DIR/const-eval-overflow2c.rs:71:5 + | +LL | foo(VALS_U32); //~ ERROR erroneous constant used + | ^^^^^^^^^^^^^ referenced constant has errors + +error[E0080]: erroneous constant used + --> $DIR/const-eval-overflow2c.rs:72:5 + | +LL | foo(VALS_U64); //~ ERROR erroneous constant used + | ^^^^^^^^^^^^^ referenced constant has errors + +error: aborting due to 17 previous errors +For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-eval/const-pointer-values-in-various-types.rs b/src/test/ui/consts/const-eval/const-pointer-values-in-various-types.rs index dc84e2a88d64a..05d79a7d63393 100644 --- a/src/test/ui/consts/const-eval/const-pointer-values-in-various-types.rs +++ b/src/test/ui/consts/const-eval/const-pointer-values-in-various-types.rs @@ -25,86 +25,86 @@ fn main() { //~^ ERROR this constant likely exhibits undefined behavior const I32_REF_U8_UNION: u8 = unsafe { Nonsense { int_32_ref: &3 }.uint_8 }; - //~^ ERROR this constant cannot be used + //~^ ERROR any use of this value will cause an error const I32_REF_U16_UNION: u16 = unsafe { Nonsense { int_32_ref: &3 }.uint_16 }; - //~^ ERROR this constant cannot be used + //~^ ERROR any use of this value will cause an error const I32_REF_U32_UNION: u32 = unsafe { Nonsense { int_32_ref: &3 }.uint_32 }; - //~^ ERROR this constant cannot be used + //~^ ERROR any use of this value will cause an error const I32_REF_U64_UNION: u64 = unsafe { Nonsense { int_32_ref: &3 }.uint_64 }; //~^ ERROR this constant likely exhibits undefined behavior const I32_REF_U128_UNION: u128 = unsafe { Nonsense { int_32_ref: &3 }.uint_128 }; - //~^ ERROR this constant cannot be used + //~^ ERROR any use of this value will cause an error const I32_REF_I8_UNION: i8 = unsafe { Nonsense { int_32_ref: &3 }.int_8 }; - //~^ ERROR this constant cannot be used + //~^ ERROR any use of this value will cause an error const I32_REF_I16_UNION: i16 = unsafe { Nonsense { int_32_ref: &3 }.int_16 }; - //~^ ERROR this constant cannot be used + //~^ ERROR any use of this value will cause an error const I32_REF_I32_UNION: i32 = unsafe { Nonsense { int_32_ref: &3 }.int_32 }; - //~^ ERROR this constant cannot be used + //~^ ERROR any use of this value will cause an error const I32_REF_I64_UNION: i64 = unsafe { Nonsense { int_32_ref: &3 }.int_64 }; //~^ ERROR this constant likely exhibits undefined behavior const I32_REF_I128_UNION: i128 = unsafe { Nonsense { int_32_ref: &3 }.int_128 }; - //~^ ERROR this constant cannot be used + //~^ ERROR any use of this value will cause an error const I32_REF_F32_UNION: f32 = unsafe { Nonsense { int_32_ref: &3 }.float_32 }; - //~^ ERROR this constant cannot be used + //~^ ERROR any use of this value will cause an error const I32_REF_F64_UNION: f64 = unsafe { Nonsense { int_32_ref: &3 }.float_64 }; //~^ ERROR this constant likely exhibits undefined behavior const I32_REF_BOOL_UNION: bool = unsafe { Nonsense { int_32_ref: &3 }.truthy_falsey }; - //~^ ERROR this constant cannot be used + //~^ ERROR any use of this value will cause an error const I32_REF_CHAR_UNION: char = unsafe { Nonsense { int_32_ref: &3 }.character }; - //~^ ERROR this constant cannot be used + //~^ ERROR any use of this value will cause an error const STR_U8_UNION: u8 = unsafe { Nonsense { stringy: "3" }.uint_8 }; - //~^ ERROR this constant cannot be used + //~^ ERROR any use of this value will cause an error const STR_U16_UNION: u16 = unsafe { Nonsense { stringy: "3" }.uint_16 }; - //~^ ERROR this constant cannot be used + //~^ ERROR any use of this value will cause an error const STR_U32_UNION: u32 = unsafe { Nonsense { stringy: "3" }.uint_32 }; - //~^ ERROR this constant cannot be used + //~^ ERROR any use of this value will cause an error const STR_U64_UNION: u64 = unsafe { Nonsense { stringy: "3" }.uint_64 }; //~^ ERROR this constant likely exhibits undefined behavior const STR_U128_UNION: u128 = unsafe { Nonsense { stringy: "3" }.uint_128 }; - //~^ ERROR this constant cannot be used + //~^ ERROR any use of this value will cause an error const STR_I8_UNION: i8 = unsafe { Nonsense { stringy: "3" }.int_8 }; - //~^ ERROR this constant cannot be used + //~^ ERROR any use of this value will cause an error const STR_I16_UNION: i16 = unsafe { Nonsense { stringy: "3" }.int_16 }; - //~^ ERROR this constant cannot be used + //~^ ERROR any use of this value will cause an error const STR_I32_UNION: i32 = unsafe { Nonsense { stringy: "3" }.int_32 }; - //~^ ERROR this constant cannot be used + //~^ ERROR any use of this value will cause an error const STR_I64_UNION: i64 = unsafe { Nonsense { stringy: "3" }.int_64 }; //~^ ERROR this constant likely exhibits undefined behavior const STR_I128_UNION: i128 = unsafe { Nonsense { stringy: "3" }.int_128 }; - //~^ ERROR this constant cannot be used + //~^ ERROR any use of this value will cause an error const STR_F32_UNION: f32 = unsafe { Nonsense { stringy: "3" }.float_32 }; - //~^ ERROR this constant cannot be used + //~^ ERROR any use of this value will cause an error const STR_F64_UNION: f64 = unsafe { Nonsense { stringy: "3" }.float_64 }; //~^ ERROR this constant likely exhibits undefined behavior const STR_BOOL_UNION: bool = unsafe { Nonsense { stringy: "3" }.truthy_falsey }; - //~^ ERROR this constant cannot be used + //~^ ERROR any use of this value will cause an error const STR_CHAR_UNION: char = unsafe { Nonsense { stringy: "3" }.character }; - //~^ ERROR this constant cannot be used + //~^ ERROR any use of this value will cause an error } diff --git a/src/test/ui/consts/const-eval/const_panic.rs b/src/test/ui/consts/const-eval/const_panic.rs index f2170f509eb30..9af631afed4ff 100644 --- a/src/test/ui/consts/const-eval/const_panic.rs +++ b/src/test/ui/consts/const-eval/const_panic.rs @@ -9,14 +9,13 @@ // except according to those terms. #![feature(const_panic)] +#![crate_type = "lib"] -fn main() {} +pub const Z: () = panic!("cheese"); +//~^ ERROR any use of this value will cause an error -const Z: () = panic!("cheese"); -//~^ ERROR this constant cannot be used +pub const Y: () = unreachable!(); +//~^ ERROR any use of this value will cause an error -const Y: () = unreachable!(); -//~^ ERROR this constant cannot be used - -const X: () = unimplemented!(); -//~^ ERROR this constant cannot be used +pub const X: () = unimplemented!(); +//~^ ERROR any use of this value will cause an error diff --git a/src/test/ui/consts/const-eval/const_panic.stderr b/src/test/ui/consts/const-eval/const_panic.stderr index c11146f4882c2..fcdbcbf5bfa69 100644 --- a/src/test/ui/consts/const-eval/const_panic.stderr +++ b/src/test/ui/consts/const-eval/const_panic.stderr @@ -1,31 +1,31 @@ -error: this constant cannot be used - --> $DIR/const_panic.rs:15:1 +error: any use of this value will cause an error + --> $DIR/const_panic.rs:14:1 | -LL | const Z: () = panic!("cheese"); - | ^^^^^^^^^^^^^^----------------^ - | | - | the evaluated program panicked at 'cheese', $DIR/const_panic.rs:15:15 +LL | pub const Z: () = panic!("cheese"); + | ^^^^^^^^^^^^^^^^^^----------------^ + | | + | the evaluated program panicked at 'cheese', $DIR/const_panic.rs:14:19 | = note: #[deny(const_err)] on by default = 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: this constant cannot be used - --> $DIR/const_panic.rs:18:1 +error: any use of this value will cause an error + --> $DIR/const_panic.rs:17:1 | -LL | const Y: () = unreachable!(); - | ^^^^^^^^^^^^^^--------------^ - | | - | the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic.rs:18:15 +LL | pub const Y: () = unreachable!(); + | ^^^^^^^^^^^^^^^^^^--------------^ + | | + | the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic.rs:17:19 | = 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: this constant cannot be used - --> $DIR/const_panic.rs:21:1 +error: any use of this value will cause an error + --> $DIR/const_panic.rs:20:1 | -LL | const X: () = unimplemented!(); - | ^^^^^^^^^^^^^^----------------^ - | | - | the evaluated program panicked at 'not yet implemented', $DIR/const_panic.rs:21:15 +LL | pub const X: () = unimplemented!(); + | ^^^^^^^^^^^^^^^^^^----------------^ + | | + | the evaluated program panicked at 'not yet implemented', $DIR/const_panic.rs:20:19 | = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) diff --git a/src/test/ui/consts/const-eval/const_panic_libcore.rs b/src/test/ui/consts/const-eval/const_panic_libcore.rs index 59aeca18129a8..11da8742b10f6 100644 --- a/src/test/ui/consts/const-eval/const_panic_libcore.rs +++ b/src/test/ui/consts/const-eval/const_panic_libcore.rs @@ -13,10 +13,10 @@ #![feature(const_panic)] const Z: () = panic!("cheese"); -//~^ ERROR this constant cannot be used +//~^ ERROR any use of this value will cause an error const Y: () = unreachable!(); -//~^ ERROR this constant cannot be used +//~^ ERROR any use of this value will cause an error const X: () = unimplemented!(); -//~^ ERROR this constant cannot be used +//~^ ERROR any use of this value will cause an error diff --git a/src/test/ui/consts/const-eval/const_panic_libcore.stderr b/src/test/ui/consts/const-eval/const_panic_libcore.stderr index 45f2ee7744e82..a8f04b96a8b1f 100644 --- a/src/test/ui/consts/const-eval/const_panic_libcore.stderr +++ b/src/test/ui/consts/const-eval/const_panic_libcore.stderr @@ -1,4 +1,4 @@ -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const_panic_libcore.rs:15:1 | LL | const Z: () = panic!("cheese"); @@ -9,7 +9,7 @@ LL | const Z: () = panic!("cheese"); = note: #[deny(const_err)] on by default = 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: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const_panic_libcore.rs:18:1 | LL | const Y: () = unreachable!(); @@ -19,7 +19,7 @@ LL | const Y: () = unreachable!(); | = 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: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const_panic_libcore.rs:21:1 | LL | const X: () = unimplemented!(); diff --git a/src/test/ui/consts/const-eval/const_panic_libcore_main.rs b/src/test/ui/consts/const-eval/const_panic_libcore_main.rs index 0364123994dff..03365ae46abaf 100644 --- a/src/test/ui/consts/const-eval/const_panic_libcore_main.rs +++ b/src/test/ui/consts/const-eval/const_panic_libcore_main.rs @@ -17,13 +17,13 @@ use core::panic::PanicInfo; const Z: () = panic!("cheese"); -//~^ ERROR this constant cannot be used +//~^ ERROR any use of this value will cause an error const Y: () = unreachable!(); -//~^ ERROR this constant cannot be used +//~^ ERROR any use of this value will cause an error const X: () = unimplemented!(); -//~^ ERROR this constant cannot be used +//~^ ERROR any use of this value will cause an error #[lang = "eh_personality"] fn eh() {} diff --git a/src/test/ui/consts/const-eval/const_panic_libcore_main.stderr b/src/test/ui/consts/const-eval/const_panic_libcore_main.stderr index 44b30c08cdea2..9a7c510029cbc 100644 --- a/src/test/ui/consts/const-eval/const_panic_libcore_main.stderr +++ b/src/test/ui/consts/const-eval/const_panic_libcore_main.stderr @@ -1,5 +1,5 @@ -error: this constant cannot be used - --> $DIR/const_panic_libcore_main.rs:19:1 +error: any use of this value will cause an error + --> $DIR/const_panic_libcore_main.rs:20:1 | LL | const Z: () = panic!("cheese"); | ^^^^^^^^^^^^^^----------------^ @@ -9,8 +9,8 @@ LL | const Z: () = panic!("cheese"); = note: #[deny(const_err)] on by default = 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: this constant cannot be used - --> $DIR/const_panic_libcore_main.rs:22:1 +error: any use of this value will cause an error + --> $DIR/const_panic_libcore_main.rs:23:1 | LL | const Y: () = unreachable!(); | ^^^^^^^^^^^^^^--------------^ @@ -19,8 +19,8 @@ LL | const Y: () = unreachable!(); | = 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: this constant cannot be used - --> $DIR/const_panic_libcore_main.rs:25:1 +error: any use of this value will cause an error + --> $DIR/const_panic_libcore_main.rs:26:1 | LL | const X: () = unimplemented!(); | ^^^^^^^^^^^^^^----------------^ diff --git a/src/test/ui/consts/const-eval/const_raw_ptr_ops.rs b/src/test/ui/consts/const-eval/const_raw_ptr_ops.rs index 2aff6a7c55c20..3cd2c04c9f1f4 100644 --- a/src/test/ui/consts/const-eval/const_raw_ptr_ops.rs +++ b/src/test/ui/consts/const-eval/const_raw_ptr_ops.rs @@ -13,15 +13,15 @@ fn main() {} // unconst and bad, will thus error in miri -const X: bool = &1 as *const i32 == &2 as *const i32; //~ ERROR cannot be used +const X: bool = &1 as *const i32 == &2 as *const i32; //~ ERROR any use of this value will cause // unconst and fine const X2: bool = 42 as *const i32 == 43 as *const i32; // unconst and fine const Y: usize = 42usize as *const i32 as usize + 1; // unconst and bad, will thus error in miri -const Y2: usize = &1 as *const i32 as usize + 1; //~ ERROR cannot be used +const Y2: usize = &1 as *const i32 as usize + 1; //~ ERROR any use of this value will cause // unconst and fine const Z: i32 = unsafe { *(&1 as *const i32) }; // unconst and bad, will thus error in miri -const Z2: i32 = unsafe { *(42 as *const i32) }; //~ ERROR cannot be used -const Z3: i32 = unsafe { *(44 as *const i32) }; //~ ERROR cannot be used +const Z2: i32 = unsafe { *(42 as *const i32) }; //~ ERROR any use of this value will cause +const Z3: i32 = unsafe { *(44 as *const i32) }; //~ ERROR any use of this value will cause diff --git a/src/test/ui/consts/const-eval/const_raw_ptr_ops.stderr b/src/test/ui/consts/const-eval/const_raw_ptr_ops.stderr index df1e6f8e4c4f0..72bbdeb0183d6 100644 --- a/src/test/ui/consts/const-eval/const_raw_ptr_ops.stderr +++ b/src/test/ui/consts/const-eval/const_raw_ptr_ops.stderr @@ -1,33 +1,33 @@ -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const_raw_ptr_ops.rs:16:1 | -LL | const X: bool = &1 as *const i32 == &2 as *const i32; //~ ERROR cannot be used +LL | const X: bool = &1 as *const i32 == &2 as *const i32; //~ ERROR any use of this value will cause | ^^^^^^^^^^^^^^^^------------------------------------^ | | | "pointer arithmetic or comparison" needs an rfc before being allowed inside constants | = note: #[deny(const_err)] on by default -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const_raw_ptr_ops.rs:22:1 | -LL | const Y2: usize = &1 as *const i32 as usize + 1; //~ ERROR cannot be used +LL | const Y2: usize = &1 as *const i32 as usize + 1; //~ ERROR any use of this value will cause | ^^^^^^^^^^^^^^^^^^-----------------------------^ | | | "pointer arithmetic or comparison" needs an rfc before being allowed inside constants -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const_raw_ptr_ops.rs:26:1 | -LL | const Z2: i32 = unsafe { *(42 as *const i32) }; //~ ERROR cannot be used +LL | const Z2: i32 = unsafe { *(42 as *const i32) }; //~ ERROR any use of this value will cause | ^^^^^^^^^^^^^^^^^^^^^^^^^-------------------^^^ | | | a memory access tried to interpret some bytes as a pointer -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const_raw_ptr_ops.rs:27:1 | -LL | const Z3: i32 = unsafe { *(44 as *const i32) }; //~ ERROR cannot be used +LL | const Z3: i32 = unsafe { *(44 as *const i32) }; //~ ERROR any use of this value will cause | ^^^^^^^^^^^^^^^^^^^^^^^^^-------------------^^^ | | | a memory access tried to interpret some bytes as a pointer diff --git a/src/test/ui/consts/const-eval/double_check2.stderr b/src/test/ui/consts/const-eval/double_check2.stderr index 21025877340ea..9dd7570232d37 100644 --- a/src/test/ui/consts/const-eval/double_check2.stderr +++ b/src/test/ui/consts/const-eval/double_check2.stderr @@ -1,4 +1,4 @@ -error[E0080]: this static likely exhibits undefined behavior +error[E0080]: it is undefined behavior to use this value --> $DIR/double_check2.rs:25:1 | LL | / static FOO: (&Foo, &Bar) = unsafe {( //~ undefined behavior diff --git a/src/test/ui/consts/const-eval/infinite_loop.rs b/src/test/ui/consts/const-eval/infinite_loop.rs index a1f8ab7f87882..d23b6250b4df2 100644 --- a/src/test/ui/consts/const-eval/infinite_loop.rs +++ b/src/test/ui/consts/const-eval/infinite_loop.rs @@ -15,10 +15,10 @@ fn main() { // The value of `n` will loop indefinitely (4 - 2 - 1 - 4). let _ = [(); { //~^ WARNING Constant evaluating a complex constant, this might take some time - //~| ERROR could not evaluate repeat length let mut n = 113383; // #20 in https://oeis.org/A006884 while n != 0 { //~ ERROR constant contains unimplemented expression type n = if n % 2 == 0 { n/2 } else { 3*n + 1 }; + //~^ ERROR evaluation of constant value failed } n }]; diff --git a/src/test/ui/consts/const-eval/infinite_loop.stderr b/src/test/ui/consts/const-eval/infinite_loop.stderr index f69aae2920360..2ff80e5efb57d 100644 --- a/src/test/ui/consts/const-eval/infinite_loop.stderr +++ b/src/test/ui/consts/const-eval/infinite_loop.stderr @@ -1,8 +1,9 @@ error[E0019]: constant contains unimplemented expression type - --> $DIR/infinite_loop.rs:20:9 + --> $DIR/infinite_loop.rs:19:9 | LL | / while n != 0 { //~ ERROR constant contains unimplemented expression type LL | | n = if n % 2 == 0 { n/2 } else { 3*n + 1 }; +LL | | //~^ ERROR evaluation of constant value failed LL | | } | |_________^ @@ -12,28 +13,18 @@ warning: Constant evaluating a complex constant, this might take some time LL | let _ = [(); { | __________________^ LL | | //~^ WARNING Constant evaluating a complex constant, this might take some time -LL | | //~| ERROR could not evaluate repeat length LL | | let mut n = 113383; // #20 in https://oeis.org/A006884 +LL | | while n != 0 { //~ ERROR constant contains unimplemented expression type ... | LL | | n LL | | }]; | |_____^ -error[E0080]: could not evaluate repeat length - --> $DIR/infinite_loop.rs:16:18 +error[E0080]: evaluation of constant value failed + --> $DIR/infinite_loop.rs:20:20 | -LL | let _ = [(); { - | __________________^ -LL | | //~^ WARNING Constant evaluating a complex constant, this might take some time -LL | | //~| ERROR could not evaluate repeat length -LL | | let mut n = 113383; // #20 in https://oeis.org/A006884 -LL | | while n != 0 { //~ ERROR constant contains unimplemented expression type -LL | | n = if n % 2 == 0 { n/2 } else { 3*n + 1 }; - | | ---------- duplicate interpreter state observed here, const evaluation will never terminate -LL | | } -LL | | n -LL | | }]; - | |_____^ +LL | n = if n % 2 == 0 { n/2 } else { 3*n + 1 }; + | ^^^^^^^^^^ duplicate interpreter state observed here, const evaluation will never terminate error: aborting due to 2 previous errors diff --git a/src/test/ui/consts/const-eval/issue-43197.nll.stderr b/src/test/ui/consts/const-eval/issue-43197.nll.stderr new file mode 100644 index 0000000000000..86a86922d3b79 --- /dev/null +++ b/src/test/ui/consts/const-eval/issue-43197.nll.stderr @@ -0,0 +1,43 @@ +warning: any use of this value will cause an error + --> $DIR/issue-43197.rs:20:5 + | +LL | const X: u32 = 0-1; + | ^^^^^^^^^^^^^^^---^ + | | + | attempt to subtract with overflow + | +note: lint level defined here + --> $DIR/issue-43197.rs:11:9 + | +LL | #![warn(const_err)] + | ^^^^^^^^^ + +warning: any use of this value will cause an error + --> $DIR/issue-43197.rs:22:5 + | +LL | const Y: u32 = foo(0-1); + | ^^^^^^^^^^^^^^^^^^^---^^ + | | + | attempt to subtract with overflow + +error[E0080]: evaluation of constant expression failed + --> $DIR/issue-43197.rs:24:14 + | +LL | println!("{} {}", X, Y); + | ^^^^^^^ - referenced constant has errors + +error[E0080]: evaluation of constant expression failed + --> $DIR/issue-43197.rs:24:26 + | +LL | println!("{} {}", X, Y); + | ^ referenced constant has errors + +error[E0080]: evaluation of constant expression failed + --> $DIR/issue-43197.rs:24:23 + | +LL | println!("{} {}", X, Y); + | ^ referenced constant has errors + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-eval/issue-43197.rs b/src/test/ui/consts/const-eval/issue-43197.rs index 6e60fd834d4c3..125b5e4d208cc 100644 --- a/src/test/ui/consts/const-eval/issue-43197.rs +++ b/src/test/ui/consts/const-eval/issue-43197.rs @@ -16,12 +16,10 @@ const fn foo(x: u32) -> u32 { fn main() { const X: u32 = 0-1; - //~^ WARN this constant cannot be used + //~^ WARN any use of this value will cause const Y: u32 = foo(0-1); - //~^ WARN this constant cannot be used + //~^ WARN any use of this value will cause println!("{} {}", X, Y); - //~^ ERROR erroneous constant used - //~| ERROR erroneous constant used - //~| ERROR E0080 - //~| ERROR E0080 + //~^ ERROR evaluation of constant expression failed + //~| ERROR evaluation of constant expression failed } diff --git a/src/test/ui/consts/const-eval/issue-43197.stderr b/src/test/ui/consts/const-eval/issue-43197.stderr index 6229790f8adc2..95d435818303b 100644 --- a/src/test/ui/consts/const-eval/issue-43197.stderr +++ b/src/test/ui/consts/const-eval/issue-43197.stderr @@ -1,5 +1,5 @@ -warning: this constant cannot be used - --> $DIR/issue-43197.rs:18:5 +warning: any use of this value will cause an error + --> $DIR/issue-43197.rs:20:5 | LL | const X: u32 = 0-1; | ^^^^^^^^^^^^^^^---^ @@ -12,44 +12,26 @@ note: lint level defined here LL | #![warn(const_err)] | ^^^^^^^^^ -warning: this constant cannot be used - --> $DIR/issue-43197.rs:20:5 +warning: any use of this value will cause an error + --> $DIR/issue-43197.rs:22:5 | LL | const Y: u32 = foo(0-1); | ^^^^^^^^^^^^^^^^^^^---^^ | | | attempt to subtract with overflow -error[E0080]: referenced constant has errors - --> $DIR/issue-43197.rs:22:26 - | -LL | const Y: u32 = foo(0-1); - | --- attempt to subtract with overflow -LL | //~^ WARN this constant cannot be used -LL | println!("{} {}", X, Y); - | ^ - -error[E0080]: erroneous constant used - --> $DIR/issue-43197.rs:22:26 +error[E0080]: evaluation of constant expression failed + --> $DIR/issue-43197.rs:24:26 | LL | println!("{} {}", X, Y); | ^ referenced constant has errors -error[E0080]: referenced constant has errors - --> $DIR/issue-43197.rs:22:23 - | -LL | const X: u32 = 0-1; - | --- attempt to subtract with overflow -... -LL | println!("{} {}", X, Y); - | ^ - -error[E0080]: erroneous constant used - --> $DIR/issue-43197.rs:22:23 +error[E0080]: evaluation of constant expression failed + --> $DIR/issue-43197.rs:24:23 | LL | println!("{} {}", X, Y); | ^ 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`. diff --git a/src/test/ui/consts/const-eval/issue-44578.nll.stderr b/src/test/ui/consts/const-eval/issue-44578.nll.stderr new file mode 100644 index 0000000000000..71e06e36361e8 --- /dev/null +++ b/src/test/ui/consts/const-eval/issue-44578.nll.stderr @@ -0,0 +1,15 @@ +error[E0080]: evaluation of constant expression failed + --> $DIR/issue-44578.rs:35:14 + | +LL | println!("{}", as Foo>::AMT); + | ^^^^ -------------------------- referenced constant has errors + +error[E0080]: evaluation of constant expression failed + --> $DIR/issue-44578.rs:35:20 + | +LL | println!("{}", as Foo>::AMT); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-eval/issue-44578.rs b/src/test/ui/consts/const-eval/issue-44578.rs index 59ac4ab311c6c..9bd84b91d7f02 100644 --- a/src/test/ui/consts/const-eval/issue-44578.rs +++ b/src/test/ui/consts/const-eval/issue-44578.rs @@ -33,6 +33,5 @@ impl Foo for u16 { fn main() { println!("{}", as Foo>::AMT); - //~^ ERROR erroneous constant used - //~| ERROR E0080 + //~^ ERROR E0080 } diff --git a/src/test/ui/consts/const-eval/issue-44578.stderr b/src/test/ui/consts/const-eval/issue-44578.stderr index 06174f37dcad1..570a8960164c0 100644 --- a/src/test/ui/consts/const-eval/issue-44578.stderr +++ b/src/test/ui/consts/const-eval/issue-44578.stderr @@ -1,18 +1,9 @@ -error[E0080]: referenced constant has errors - --> $DIR/issue-44578.rs:35:20 - | -LL | const AMT: usize = [A::AMT][(A::AMT > B::AMT) as usize]; - | ------------------------------------ index out of bounds: the len is 1 but the index is 1 -... -LL | println!("{}", as Foo>::AMT); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error[E0080]: erroneous constant used +error[E0080]: evaluation of constant expression failed --> $DIR/issue-44578.rs:35:20 | LL | println!("{}", as Foo>::AMT); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ 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`. diff --git a/src/test/ui/consts/const-eval/issue-50814-2.rs b/src/test/ui/consts/const-eval/issue-50814-2.rs index af627ee5fbe70..9a59ffd65ac21 100644 --- a/src/test/ui/consts/const-eval/issue-50814-2.rs +++ b/src/test/ui/consts/const-eval/issue-50814-2.rs @@ -19,12 +19,11 @@ trait Foo { struct A(T); impl Foo for A { - const BAR: usize = [5, 6, 7][T::BOO]; + const BAR: usize = [5, 6, 7][T::BOO]; //~ ERROR any use of this value will cause an error } fn foo() -> &'static usize { - & as Foo>::BAR //~ ERROR erroneous constant used -//~| ERROR E0080 + & as Foo>::BAR //~ ERROR E0080 } impl C for () { diff --git a/src/test/ui/consts/const-eval/issue-50814-2.stderr b/src/test/ui/consts/const-eval/issue-50814-2.stderr index 1e37e9498120f..b36b3cf526c68 100644 --- a/src/test/ui/consts/const-eval/issue-50814-2.stderr +++ b/src/test/ui/consts/const-eval/issue-50814-2.stderr @@ -1,16 +1,17 @@ -error[E0080]: referenced constant has errors - --> $DIR/issue-50814-2.rs:26:5 +error: any use of this value will cause an error + --> $DIR/issue-50814-2.rs:22:5 + | +LL | const BAR: usize = [5, 6, 7][T::BOO]; //~ ERROR any use of this value will cause an error + | ^^^^^^^^^^^^^^^^^^^-----------------^ + | | + | index out of bounds: the len is 3 but the index is 42 | -LL | const BAR: usize = [5, 6, 7][T::BOO]; - | ----------------- index out of bounds: the len is 3 but the index is 42 -... -LL | & as Foo>::BAR //~ ERROR erroneous constant used - | ^^^^^^^^^^^^^^^^^^^^^^ + = note: #[deny(const_err)] on by default -error[E0080]: erroneous constant used +error[E0080]: evaluation of constant expression failed --> $DIR/issue-50814-2.rs:26:5 | -LL | & as Foo>::BAR //~ ERROR erroneous constant used +LL | & as Foo>::BAR //~ ERROR E0080 | ^--------------------- | | | referenced constant has errors diff --git a/src/test/ui/consts/const-eval/issue-50814.rs b/src/test/ui/consts/const-eval/issue-50814.rs index 8f2752453b52e..3c7f182644942 100644 --- a/src/test/ui/consts/const-eval/issue-50814.rs +++ b/src/test/ui/consts/const-eval/issue-50814.rs @@ -20,12 +20,11 @@ impl Unsigned for U8 { struct Sum(A,B); impl Unsigned for Sum { - const MAX: u8 = A::MAX + B::MAX; + const MAX: u8 = A::MAX + B::MAX; //~ ERROR any use of this value will cause an error } fn foo(_: T) -> &'static u8 { - &Sum::::MAX //~ ERROR erroneous constant used -//~| ERROR E0080 + &Sum::::MAX //~ ERROR E0080 } fn main() { diff --git a/src/test/ui/consts/const-eval/issue-50814.stderr b/src/test/ui/consts/const-eval/issue-50814.stderr index 16160207c573b..ebd0e34ab7e5f 100644 --- a/src/test/ui/consts/const-eval/issue-50814.stderr +++ b/src/test/ui/consts/const-eval/issue-50814.stderr @@ -1,16 +1,17 @@ -error[E0080]: referenced constant has errors - --> $DIR/issue-50814.rs:27:5 +error: any use of this value will cause an error + --> $DIR/issue-50814.rs:23:5 + | +LL | const MAX: u8 = A::MAX + B::MAX; //~ ERROR any use of this value will cause an error + | ^^^^^^^^^^^^^^^^---------------^ + | | + | attempt to add with overflow | -LL | const MAX: u8 = A::MAX + B::MAX; - | --------------- attempt to add with overflow -... -LL | &Sum::::MAX //~ ERROR erroneous constant used - | ^^^^^^^^^^^^^^^^^^ + = note: #[deny(const_err)] on by default -error[E0080]: erroneous constant used +error[E0080]: evaluation of constant expression failed --> $DIR/issue-50814.rs:27:5 | -LL | &Sum::::MAX //~ ERROR erroneous constant used +LL | &Sum::::MAX //~ ERROR E0080 | ^----------------- | | | referenced constant has errors diff --git a/src/test/ui/consts/const-eval/issue-52443.stderr b/src/test/ui/consts/const-eval/issue-52443.stderr new file mode 100644 index 0000000000000..807a70dd2014f --- /dev/null +++ b/src/test/ui/consts/const-eval/issue-52443.stderr @@ -0,0 +1,49 @@ +error[E0308]: mismatched types + --> $DIR/issue-52443.rs:12:10 + | +LL | [(); & { loop { continue } } ]; //~ ERROR mismatched types + | ^^^^^^^^^^^^^^^^^^^^^^^ + | | + | expected usize, found reference + | help: consider removing the borrow: `{ loop { continue } }` + | + = note: expected type `usize` + found type `&_` + +error[E0308]: mismatched types + --> $DIR/issue-52443.rs:13:17 + | +LL | [(); loop { break }]; //~ ERROR mismatched types + | ^^^^^ expected (), found usize + | + = note: expected type `()` + found type `usize` + +error[E0019]: constant contains unimplemented expression type + --> $DIR/issue-52443.rs:14:11 + | +LL | [(); {while true {break}; 0}]; //~ ERROR constant contains unimplemented expression type + | ^^^^^^^^^^^^^^^^^^ + +error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants + --> $DIR/issue-52443.rs:15:21 + | +LL | [(); { for _ in 0usize.. {}; 0}]; //~ ERROR calls in constants are limited to constant functions + | ^^^^^^^^ + +error[E0019]: constant contains unimplemented expression type + --> $DIR/issue-52443.rs:15:21 + | +LL | [(); { for _ in 0usize.. {}; 0}]; //~ ERROR calls in constants are limited to constant functions + | ^^^^^^^^ + +error[E0080]: evaluation of constant value failed + --> $DIR/issue-52443.rs:15:21 + | +LL | [(); { for _ in 0usize.. {}; 0}]; //~ ERROR calls in constants are limited to constant functions + | ^^^^^^^^ calling non-const fn `>::into_iter` + +error: aborting due to 6 previous errors + +Some errors occurred: E0015, E0019, E0080, E0308. +For more information about an error, try `rustc --explain E0015`. diff --git a/src/test/ui/consts/const-eval/match-test-ptr-null.rs b/src/test/ui/consts/const-eval/match-test-ptr-null.rs index 81fcd23fb786d..1a3164b0b03f6 100644 --- a/src/test/ui/consts/const-eval/match-test-ptr-null.rs +++ b/src/test/ui/consts/const-eval/match-test-ptr-null.rs @@ -12,10 +12,11 @@ fn main() { // Make sure match uses the usual pointer comparison code path -- i.e., it should complain // that pointer comparison is disallowed, not that parts of a pointer are accessed as raw // bytes. - let _: [u8; 0] = [4; { //~ ERROR could not evaluate repeat length + let _: [u8; 0] = [4; { match &1 as *const i32 as usize { //~ ERROR casting pointers to integers in constants 0 => 42, //~ ERROR constant contains unimplemented expression type //~^ NOTE "pointer arithmetic or comparison" needs an rfc before being allowed + //~| ERROR evaluation of constant value failed n => n, } }]; diff --git a/src/test/ui/consts/const-eval/match-test-ptr-null.stderr b/src/test/ui/consts/const-eval/match-test-ptr-null.stderr index 26577948faefa..86812b6c493a1 100644 --- a/src/test/ui/consts/const-eval/match-test-ptr-null.stderr +++ b/src/test/ui/consts/const-eval/match-test-ptr-null.stderr @@ -12,19 +12,11 @@ error[E0019]: constant contains unimplemented expression type LL | 0 => 42, //~ ERROR constant contains unimplemented expression type | ^ -error[E0080]: could not evaluate repeat length - --> $DIR/match-test-ptr-null.rs:15:26 +error[E0080]: evaluation of constant value failed + --> $DIR/match-test-ptr-null.rs:17:13 | -LL | let _: [u8; 0] = [4; { //~ ERROR could not evaluate repeat length - | __________________________^ -LL | | match &1 as *const i32 as usize { //~ ERROR casting pointers to integers in constants -LL | | 0 => 42, //~ ERROR constant contains unimplemented expression type - | | - "pointer arithmetic or comparison" needs an rfc before being allowed inside constants -LL | | //~^ NOTE "pointer arithmetic or comparison" needs an rfc before being allowed -LL | | n => n, -LL | | } -LL | | }]; - | |_____^ +LL | 0 => 42, //~ ERROR constant contains unimplemented expression type + | ^ "pointer arithmetic or comparison" needs an rfc before being allowed inside constants error: aborting due to 3 previous errors diff --git a/src/test/ui/consts/const-eval/promoted_const_fn_fail.rs b/src/test/ui/consts/const-eval/promoted_const_fn_fail.rs index 9b03ddd189168..aa6cd888018f4 100644 --- a/src/test/ui/consts/const-eval/promoted_const_fn_fail.rs +++ b/src/test/ui/consts/const-eval/promoted_const_fn_fail.rs @@ -10,7 +10,7 @@ #![feature(const_fn, const_fn_union)] -#![deny(const_err)] +#![allow(const_err)] union Bar { a: &'static u8, diff --git a/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.rs b/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.rs new file mode 100644 index 0000000000000..9f19e68f2a82f --- /dev/null +++ b/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.rs @@ -0,0 +1,36 @@ +// Copyright 2018 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(const_fn, const_fn_union)] + +#![deny(const_err)] + +union Bar { + a: &'static u8, + b: usize, +} + +const fn bar() -> u8 { + unsafe { + // this will error as long as this test + // is run on a system whose pointers need more + // than 8 bits + Bar { a: &42 }.b as u8 + } +} + +fn main() { + // FIXME(oli-obk): this should panic at runtime + // this will actually compile, but then + // abort at runtime (not panic, hard abort). + let x: &'static u8 = &(bar() + 1); + let y = *x; + unreachable!(); +} diff --git a/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.stderr b/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.stderr new file mode 100644 index 0000000000000..3eeacbf842a4c --- /dev/null +++ b/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.stderr @@ -0,0 +1,19 @@ +error: reaching this expression at runtime will panic or abort + --> $DIR/promoted_const_fn_fail_deny_const_err.rs:33:26 + | +LL | Bar { a: &42 }.b as u8 + | ---------------------- a raw memory access tried to access part of a pointer value as raw bytes +... +LL | let x: &'static u8 = &(bar() + 1); + | ^^-----^^^^^ + | | + | inside call to `bar` + | +note: lint level defined here + --> $DIR/promoted_const_fn_fail_deny_const_err.rs:13:9 + | +LL | #![deny(const_err)] + | ^^^^^^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/consts/const-eval/promoted_errors.stderr b/src/test/ui/consts/const-eval/promoted_errors.stderr index 85b5696be947c..26499fcb9b555 100644 --- a/src/test/ui/consts/const-eval/promoted_errors.stderr +++ b/src/test/ui/consts/const-eval/promoted_errors.stderr @@ -46,3 +46,15 @@ warning: this expression will panic at runtime LL | let _x = 1/(false as u32); | ^^^^^^^^^^^^^^^^ attempt to divide by zero +warning: reaching this expression at runtime will panic or abort + --> $DIR/promoted_errors.rs:24:20 + | +LL | println!("{}", 1/(false as u32)); + | ^^^^^^^^^^^^^^^^ attempt to divide by zero + +warning: reaching this expression at runtime will panic or abort + --> $DIR/promoted_errors.rs:19:20 + | +LL | println!("{}", 1/(1-1)); + | ^^^^^^^ attempt to divide by zero + diff --git a/src/test/ui/consts/const-eval/pub_const_err.rs b/src/test/ui/consts/const-eval/pub_const_err.rs index b7cfa949bac95..48c172b5e3164 100644 --- a/src/test/ui/consts/const-eval/pub_const_err.rs +++ b/src/test/ui/consts/const-eval/pub_const_err.rs @@ -14,7 +14,7 @@ #![crate_type = "lib"] pub const Z: u32 = 0 - 1; -//~^ WARN this constant cannot be used +//~^ WARN any use of this value will cause an error pub type Foo = [i32; 0 - 1]; //~^ WARN attempt to subtract with overflow diff --git a/src/test/ui/consts/const-eval/pub_const_err.stderr b/src/test/ui/consts/const-eval/pub_const_err.stderr index fa3a79a5f1790..2194180c2efdf 100644 --- a/src/test/ui/consts/const-eval/pub_const_err.stderr +++ b/src/test/ui/consts/const-eval/pub_const_err.stderr @@ -1,4 +1,4 @@ -warning: this constant cannot be used +warning: any use of this value will cause an error --> $DIR/pub_const_err.rs:16:1 | LL | pub const Z: u32 = 0 - 1; @@ -12,15 +12,3 @@ note: lint level defined here LL | #![warn(const_err)] | ^^^^^^^^^ -warning: attempt to subtract with overflow - --> $DIR/pub_const_err.rs:19:22 - | -LL | pub type Foo = [i32; 0 - 1]; - | ^^^^^ - -warning: this array length cannot be used - --> $DIR/pub_const_err.rs:19:22 - | -LL | pub type Foo = [i32; 0 - 1]; - | ^^^^^ attempt to subtract with overflow - diff --git a/src/test/ui/consts/const-eval/pub_const_err_bin.rs b/src/test/ui/consts/const-eval/pub_const_err_bin.rs index bafa5b2f4da12..849d40cf107b7 100644 --- a/src/test/ui/consts/const-eval/pub_const_err_bin.rs +++ b/src/test/ui/consts/const-eval/pub_const_err_bin.rs @@ -12,7 +12,7 @@ #![warn(const_err)] pub const Z: u32 = 0 - 1; -//~^ WARN this constant cannot be used +//~^ WARN any use of this value will cause an error pub type Foo = [i32; 0 - 1]; //~^ WARN attempt to subtract with overflow diff --git a/src/test/ui/consts/const-eval/pub_const_err_bin.stderr b/src/test/ui/consts/const-eval/pub_const_err_bin.stderr index 73229c60d14db..60834e006503c 100644 --- a/src/test/ui/consts/const-eval/pub_const_err_bin.stderr +++ b/src/test/ui/consts/const-eval/pub_const_err_bin.stderr @@ -1,4 +1,4 @@ -warning: this constant cannot be used +warning: any use of this value will cause an error --> $DIR/pub_const_err_bin.rs:14:1 | LL | pub const Z: u32 = 0 - 1; @@ -12,15 +12,3 @@ note: lint level defined here LL | #![warn(const_err)] | ^^^^^^^^^ -warning: attempt to subtract with overflow - --> $DIR/pub_const_err_bin.rs:17:22 - | -LL | pub type Foo = [i32; 0 - 1]; - | ^^^^^ - -warning: this array length cannot be used - --> $DIR/pub_const_err_bin.rs:17:22 - | -LL | pub type Foo = [i32; 0 - 1]; - | ^^^^^ attempt to subtract with overflow - diff --git a/src/test/ui/consts/const-eval/shift_overflow.stderr b/src/test/ui/consts/const-eval/shift_overflow.stderr index 00a748249ea0a..f1d30394d380e 100644 --- a/src/test/ui/consts/const-eval/shift_overflow.stderr +++ b/src/test/ui/consts/const-eval/shift_overflow.stderr @@ -1,4 +1,4 @@ -error[E0080]: could not evaluate enum discriminant +error[E0080]: evaluation of constant value failed --> $DIR/shift_overflow.rs:13:9 | LL | X = 1 << ((u32::max_value() as u64) + 1), //~ ERROR E0080 diff --git a/src/test/ui/consts/const-eval/ub-enum.rs b/src/test/ui/consts/const-eval/ub-enum.rs index bcb71af54afdb..2f7a5dda9ffcb 100644 --- a/src/test/ui/consts/const-eval/ub-enum.rs +++ b/src/test/ui/consts/const-eval/ub-enum.rs @@ -20,7 +20,7 @@ union TransmuteEnum { // A pointer is guaranteed non-null const BAD_ENUM: Enum = unsafe { TransmuteEnum { a: &1 }.b }; -//~^ ERROR this constant likely exhibits undefined behavior +//~^ ERROR is undefined behavior // Invalid enum discriminant #[repr(usize)] @@ -33,7 +33,7 @@ union TransmuteEnum2 { b: Enum2, } const BAD_ENUM2 : Enum2 = unsafe { TransmuteEnum2 { a: 0 }.b }; -//~^ ERROR this constant likely exhibits undefined behavior +//~^ ERROR is undefined behavior // Invalid enum field content (mostly to test printing of apths for enum tuple // variants and tuples). @@ -43,7 +43,7 @@ union TransmuteChar { } // Need to create something which does not clash with enum layout optimizations. const BAD_ENUM_CHAR : Option<(char, char)> = Some(('x', unsafe { TransmuteChar { a: !0 }.b })); -//~^ ERROR this constant likely exhibits undefined behavior +//~^ ERROR is undefined behavior fn main() { } diff --git a/src/test/ui/consts/const-eval/ub-enum.stderr b/src/test/ui/consts/const-eval/ub-enum.stderr index 243343c94b065..4cbaa2f3a906f 100644 --- a/src/test/ui/consts/const-eval/ub-enum.stderr +++ b/src/test/ui/consts/const-eval/ub-enum.stderr @@ -1,4 +1,4 @@ -error[E0080]: this constant likely exhibits undefined behavior +error[E0080]: it is undefined behavior to use this value --> $DIR/ub-enum.rs:22:1 | LL | const BAD_ENUM: Enum = unsafe { TransmuteEnum { a: &1 }.b }; @@ -6,7 +6,7 @@ LL | const BAD_ENUM: Enum = unsafe { TransmuteEnum { a: &1 }.b }; | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior -error[E0080]: this constant likely exhibits undefined behavior +error[E0080]: it is undefined behavior to use this value --> $DIR/ub-enum.rs:35:1 | LL | const BAD_ENUM2 : Enum2 = unsafe { TransmuteEnum2 { a: 0 }.b }; @@ -14,7 +14,7 @@ LL | const BAD_ENUM2 : Enum2 = unsafe { TransmuteEnum2 { a: 0 }.b }; | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior -error[E0080]: this constant likely exhibits undefined behavior +error[E0080]: it is undefined behavior to use this value --> $DIR/ub-enum.rs:45:1 | LL | const BAD_ENUM_CHAR : Option<(char, char)> = Some(('x', unsafe { TransmuteChar { a: !0 }.b })); diff --git a/src/test/ui/consts/const-eval/union-const-eval-field.rs b/src/test/ui/consts/const-eval/union-const-eval-field.rs index 5723f4a4159aa..40d1f97a80757 100644 --- a/src/test/ui/consts/const-eval/union-const-eval-field.rs +++ b/src/test/ui/consts/const-eval/union-const-eval-field.rs @@ -34,12 +34,15 @@ const fn read_field2() -> Field2 { } const fn read_field3() -> Field3 { - const FIELD3: Field3 = unsafe { UNION.field3 }; //~ ERROR cannot be used + const FIELD3: Field3 = unsafe { UNION.field3 }; //~ ERROR any use of this value + //~^ ERROR any use of this value FIELD3 + //~^ erroneous constant used } fn main() { assert_eq!(read_field1(), FLOAT1_AS_I32); assert_eq!(read_field2(), 1.0); assert_eq!(read_field3(), unsafe { UNION.field3 }); + //~^ ERROR evaluation of constant expression failed } diff --git a/src/test/ui/consts/const-eval/union-const-eval-field.stderr b/src/test/ui/consts/const-eval/union-const-eval-field.stderr index 811450c8cba47..39320791a3fd0 100644 --- a/src/test/ui/consts/const-eval/union-const-eval-field.stderr +++ b/src/test/ui/consts/const-eval/union-const-eval-field.stderr @@ -1,10 +1,36 @@ -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/union-const-eval-field.rs:37:5 | -LL | const FIELD3: Field3 = unsafe { UNION.field3 }; //~ ERROR cannot be used +LL | const FIELD3: Field3 = unsafe { UNION.field3 }; //~ ERROR any use of this value | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempted to read undefined bytes | = note: #[deny(const_err)] on by default -error: aborting due to previous error +error: any use of this value will cause an error + --> $DIR/union-const-eval-field.rs:37:5 + | +LL | const FIELD3: Field3 = unsafe { UNION.field3 }; //~ ERROR any use of this value + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempted to read undefined bytes + +error[E0080]: erroneous constant used + --> $DIR/union-const-eval-field.rs:39:5 + | +LL | FIELD3 + | ^^^^^^ referenced constant has errors + +error[E0080]: evaluation of constant expression failed + --> $DIR/union-const-eval-field.rs:46:5 + | +LL | FIELD3 + | ------ referenced constant has errors +... +LL | assert_eq!(read_field3(), unsafe { UNION.field3 }); + | ^^^^^^^^^^^-------------^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | inside call to `read_field3` + | + = 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`. diff --git a/src/test/ui/consts/const-eval/union-ice.rs b/src/test/ui/consts/const-eval/union-ice.rs index 5d50004e5549d..5a8ea711d86be 100644 --- a/src/test/ui/consts/const-eval/union-ice.rs +++ b/src/test/ui/consts/const-eval/union-ice.rs @@ -20,9 +20,9 @@ union DummyUnion { const UNION: DummyUnion = DummyUnion { field1: 1065353216 }; -const FIELD3: Field3 = unsafe { UNION.field3 }; //~ ERROR this constant cannot be used +const FIELD3: Field3 = unsafe { UNION.field3 }; //~ ERROR will cause an error -const FIELD_PATH: Struct = Struct { //~ ERROR this constant likely exhibits undefined behavior +const FIELD_PATH: Struct = Struct { //~ ERROR any use of this value will cause an error a: 42, b: unsafe { UNION.field3 }, }; @@ -32,7 +32,7 @@ struct Struct { b: Field3, } -const FIELD_PATH2: Struct2 = Struct2 { //~ ERROR this constant likely exhibits undefined behavior +const FIELD_PATH2: Struct2 = Struct2 { //~ ERROR it is undefined behavior to use this value b: [ 21, unsafe { UNION.field3 }, diff --git a/src/test/ui/consts/const-eval/union-ice.stderr b/src/test/ui/consts/const-eval/union-ice.stderr index 4484dd6a14740..7f5cb731c8eee 100644 --- a/src/test/ui/consts/const-eval/union-ice.stderr +++ b/src/test/ui/consts/const-eval/union-ice.stderr @@ -1,15 +1,15 @@ -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/union-ice.rs:23:1 | -LL | const FIELD3: Field3 = unsafe { UNION.field3 }; //~ ERROR this constant cannot be used +LL | const FIELD3: Field3 = unsafe { UNION.field3 }; //~ ERROR will cause an error | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempted to read undefined bytes | = note: #[deny(const_err)] on by default -error[E0080]: this constant likely exhibits undefined behavior +error: any use of this value will cause an error --> $DIR/union-ice.rs:25:1 | -LL | / const FIELD_PATH: Struct = Struct { //~ ERROR this constant likely exhibits undefined behavior +LL | / const FIELD_PATH: Struct = Struct { //~ ERROR any use of this value will cause an error LL | | a: 42, LL | | b: unsafe { UNION.field3 }, LL | | }; @@ -17,10 +17,10 @@ LL | | }; | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior -error[E0080]: this constant likely exhibits undefined behavior +error[E0080]: it is undefined behavior to use this value --> $DIR/union-ice.rs:35:1 | -LL | / const FIELD_PATH2: Struct2 = Struct2 { //~ ERROR this constant likely exhibits undefined behavior +LL | / const FIELD_PATH2: Struct2 = Struct2 { //~ ERROR it is undefined behavior to use this value LL | | b: [ LL | | 21, LL | | unsafe { UNION.field3 }, diff --git a/src/test/ui/consts/const-eval/union-ub-fat-ptr.rs b/src/test/ui/consts/const-eval/union-ub-fat-ptr.rs index 0c42d28eb00f4..479cee92b94b3 100644 --- a/src/test/ui/consts/const-eval/union-ub-fat-ptr.rs +++ b/src/test/ui/consts/const-eval/union-ub-fat-ptr.rs @@ -85,55 +85,56 @@ type MySliceBool = MySlice<[bool]>; const A: &str = unsafe { SliceTransmute { repr: SliceRepr { ptr: &42, len: 1 } }.str}; // bad str const B: &str = unsafe { SliceTransmute { repr: SliceRepr { ptr: &42, len: 999 } }.str}; -//~^ ERROR this constant likely exhibits undefined behavior +//~^ ERROR it is undefined behavior to use this value // bad str const C: &str = unsafe { SliceTransmute { bad: BadSliceRepr { ptr: &42, len: &3 } }.str}; -//~^ ERROR this constant likely exhibits undefined behavior +//~^ ERROR it is undefined behavior to use this value // bad str in user-defined unsized type const C2: &MyStr = unsafe { SliceTransmute { bad: BadSliceRepr { ptr: &42, len: &3 } }.my_str}; -//~^ ERROR this constant likely exhibits undefined behavior +//~^ ERROR it is undefined behavior to use this value // OK const A2: &[u8] = unsafe { SliceTransmute { repr: SliceRepr { ptr: &42, len: 1 } }.slice}; // bad slice const B2: &[u8] = unsafe { SliceTransmute { repr: SliceRepr { ptr: &42, len: 999 } }.slice}; -//~^ ERROR this constant likely exhibits undefined behavior +//~^ ERROR it is undefined behavior to use this value // bad slice const C3: &[u8] = unsafe { SliceTransmute { bad: BadSliceRepr { ptr: &42, len: &3 } }.slice}; -//~^ ERROR this constant likely exhibits undefined behavior +//~^ ERROR it is undefined behavior to use this value // bad trait object const D: &Trait = unsafe { DynTransmute { repr: DynRepr { ptr: &92, vtable: &3 } }.rust}; -//~^ ERROR this constant likely exhibits undefined behavior +//~^ ERROR it is undefined behavior to use this value // bad trait object const E: &Trait = unsafe { DynTransmute { repr2: DynRepr2 { ptr: &92, vtable: &3 } }.rust}; -//~^ ERROR this constant likely exhibits undefined behavior +//~^ ERROR it is undefined behavior to use this value // bad trait object const F: &Trait = unsafe { DynTransmute { bad: BadDynRepr { ptr: &92, vtable: 3 } }.rust}; -//~^ ERROR this constant likely exhibits undefined behavior +//~^ ERROR it is undefined behavior to use this value // bad data *inside* the trait object const G: &Trait = &unsafe { BoolTransmute { val: 3 }.bl }; -//~^ ERROR this constant likely exhibits undefined behavior +//~^ ERROR it is undefined behavior to use this value + // bad data *inside* the slice const H: &[bool] = &[unsafe { BoolTransmute { val: 3 }.bl }]; -//~^ ERROR this constant likely exhibits undefined behavior +//~^ ERROR it is undefined behavior to use this value // good MySliceBool const I1: &MySliceBool = &MySlice(true, [false]); // bad: sized field is not okay const I2: &MySliceBool = &MySlice(unsafe { BoolTransmute { val: 3 }.bl }, [false]); -//~^ ERROR this constant likely exhibits undefined behavior +//~^ ERROR it is undefined behavior to use this value // bad: unsized part is not okay const I3: &MySliceBool = &MySlice(true, [unsafe { BoolTransmute { val: 3 }.bl }]); -//~^ ERROR this constant likely exhibits undefined behavior +//~^ ERROR it is undefined behavior to use this value // invalid UTF-8 const J1: &str = unsafe { SliceTransmute { slice: &[0xFF] }.str }; -//~^ ERROR this constant likely exhibits undefined behavior +//~^ ERROR it is undefined behavior to use this value // invalid UTF-8 in user-defined str-like const J2: &MyStr = unsafe { SliceTransmute { slice: &[0xFF] }.my_str }; -//~^ ERROR this constant likely exhibits undefined behavior +//~^ ERROR it is undefined behavior to use this value fn main() { } diff --git a/src/test/ui/consts/const-eval/union-ub-fat-ptr.stderr b/src/test/ui/consts/const-eval/union-ub-fat-ptr.stderr index c4632ffe30974..b61ea9ca6f95b 100644 --- a/src/test/ui/consts/const-eval/union-ub-fat-ptr.stderr +++ b/src/test/ui/consts/const-eval/union-ub-fat-ptr.stderr @@ -1,4 +1,4 @@ -error[E0080]: this constant likely exhibits undefined behavior +error[E0080]: it is undefined behavior to use this value --> $DIR/union-ub-fat-ptr.rs:87:1 | LL | const B: &str = unsafe { SliceTransmute { repr: SliceRepr { ptr: &42, len: 999 } }.str}; @@ -6,7 +6,7 @@ LL | const B: &str = unsafe { SliceTransmute { repr: SliceRepr { ptr: &42, len: | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior -error[E0080]: this constant likely exhibits undefined behavior +error[E0080]: it is undefined behavior to use this value --> $DIR/union-ub-fat-ptr.rs:90:1 | LL | const C: &str = unsafe { SliceTransmute { bad: BadSliceRepr { ptr: &42, len: &3 } }.str}; @@ -14,7 +14,7 @@ LL | const C: &str = unsafe { SliceTransmute { bad: BadSliceRepr { ptr: &42, len | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior -error[E0080]: this constant likely exhibits undefined behavior +error[E0080]: it is undefined behavior to use this value --> $DIR/union-ub-fat-ptr.rs:93:1 | LL | const C2: &MyStr = unsafe { SliceTransmute { bad: BadSliceRepr { ptr: &42, len: &3 } }.my_str}; @@ -22,7 +22,7 @@ LL | const C2: &MyStr = unsafe { SliceTransmute { bad: BadSliceRepr { ptr: &42, | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior -error[E0080]: this constant likely exhibits undefined behavior +error[E0080]: it is undefined behavior to use this value --> $DIR/union-ub-fat-ptr.rs:99:1 | LL | const B2: &[u8] = unsafe { SliceTransmute { repr: SliceRepr { ptr: &42, len: 999 } }.slice}; @@ -30,7 +30,7 @@ LL | const B2: &[u8] = unsafe { SliceTransmute { repr: SliceRepr { ptr: &42, len | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior -error[E0080]: this constant likely exhibits undefined behavior +error[E0080]: it is undefined behavior to use this value --> $DIR/union-ub-fat-ptr.rs:102:1 | LL | const C3: &[u8] = unsafe { SliceTransmute { bad: BadSliceRepr { ptr: &42, len: &3 } }.slice}; @@ -38,7 +38,7 @@ LL | const C3: &[u8] = unsafe { SliceTransmute { bad: BadSliceRepr { ptr: &42, l | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior -error[E0080]: this constant likely exhibits undefined behavior +error[E0080]: it is undefined behavior to use this value --> $DIR/union-ub-fat-ptr.rs:106:1 | LL | const D: &Trait = unsafe { DynTransmute { repr: DynRepr { ptr: &92, vtable: &3 } }.rust}; @@ -46,7 +46,7 @@ LL | const D: &Trait = unsafe { DynTransmute { repr: DynRepr { ptr: &92, vtable: | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior -error[E0080]: this constant likely exhibits undefined behavior +error[E0080]: it is undefined behavior to use this value --> $DIR/union-ub-fat-ptr.rs:109:1 | LL | const E: &Trait = unsafe { DynTransmute { repr2: DynRepr2 { ptr: &92, vtable: &3 } }.rust}; @@ -54,7 +54,7 @@ LL | const E: &Trait = unsafe { DynTransmute { repr2: DynRepr2 { ptr: &92, vtabl | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior -error[E0080]: this constant likely exhibits undefined behavior +error[E0080]: it is undefined behavior to use this value --> $DIR/union-ub-fat-ptr.rs:112:1 | LL | const F: &Trait = unsafe { DynTransmute { bad: BadDynRepr { ptr: &92, vtable: 3 } }.rust}; @@ -62,7 +62,7 @@ LL | const F: &Trait = unsafe { DynTransmute { bad: BadDynRepr { ptr: &92, vtabl | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior -error[E0080]: this constant likely exhibits undefined behavior +error[E0080]: it is undefined behavior to use this value --> $DIR/union-ub-fat-ptr.rs:116:1 | LL | const G: &Trait = &unsafe { BoolTransmute { val: 3 }.bl }; @@ -70,40 +70,40 @@ LL | const G: &Trait = &unsafe { BoolTransmute { val: 3 }.bl }; | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior -error[E0080]: this constant likely exhibits undefined behavior - --> $DIR/union-ub-fat-ptr.rs:119:1 +error[E0080]: it is undefined behavior to use this value + --> $DIR/union-ub-fat-ptr.rs:120:1 | LL | const H: &[bool] = &[unsafe { BoolTransmute { val: 3 }.bl }]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 3 at .[0], but expected something in the range 0..=1 | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior -error[E0080]: this constant likely exhibits undefined behavior - --> $DIR/union-ub-fat-ptr.rs:125:1 +error[E0080]: it is undefined behavior to use this value + --> $DIR/union-ub-fat-ptr.rs:126:1 | LL | const I2: &MySliceBool = &MySlice(unsafe { BoolTransmute { val: 3 }.bl }, [false]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 3 at ..0, but expected something in the range 0..=1 | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior -error[E0080]: this constant likely exhibits undefined behavior - --> $DIR/union-ub-fat-ptr.rs:128:1 +error[E0080]: it is undefined behavior to use this value + --> $DIR/union-ub-fat-ptr.rs:129:1 | LL | const I3: &MySliceBool = &MySlice(true, [unsafe { BoolTransmute { val: 3 }.bl }]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 3 at ..1[0], but expected something in the range 0..=1 | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior -error[E0080]: this constant likely exhibits undefined behavior - --> $DIR/union-ub-fat-ptr.rs:132:1 +error[E0080]: it is undefined behavior to use this value + --> $DIR/union-ub-fat-ptr.rs:133:1 | LL | const J1: &str = unsafe { SliceTransmute { slice: &[0xFF] }.str }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered uninitialized or non-UTF-8 data in str at . | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior -error[E0080]: this constant likely exhibits undefined behavior - --> $DIR/union-ub-fat-ptr.rs:135:1 +error[E0080]: it is undefined behavior to use this value + --> $DIR/union-ub-fat-ptr.rs:136:1 | LL | const J2: &MyStr = unsafe { SliceTransmute { slice: &[0xFF] }.my_str }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered uninitialized or non-UTF-8 data in str at ..0 diff --git a/src/test/ui/consts/const-eval/union-ub.rs b/src/test/ui/consts/const-eval/union-ub.rs index 86b3bdaa6b79e..008f1f2364866 100644 --- a/src/test/ui/consts/const-eval/union-ub.rs +++ b/src/test/ui/consts/const-eval/union-ub.rs @@ -34,7 +34,7 @@ union Bar { // the value is not valid for bools const BAD_BOOL: bool = unsafe { DummyUnion { u8: 42 }.bool}; -//~^ ERROR this constant likely exhibits undefined behavior +//~^ ERROR it is undefined behavior to use this value // The value is not valid for any union variant, but that's fine // unions are just a convenient way to transmute bits around diff --git a/src/test/ui/consts/const-eval/union-ub.stderr b/src/test/ui/consts/const-eval/union-ub.stderr index 2a04dae337b27..bb916ddbbcfd7 100644 --- a/src/test/ui/consts/const-eval/union-ub.stderr +++ b/src/test/ui/consts/const-eval/union-ub.stderr @@ -1,4 +1,4 @@ -error[E0080]: this constant likely exhibits undefined behavior +error[E0080]: it is undefined behavior to use this value --> $DIR/union-ub.rs:36:1 | LL | const BAD_BOOL: bool = unsafe { DummyUnion { u8: 42 }.bool}; diff --git a/src/test/ui/consts/const-fn-error.stderr b/src/test/ui/consts/const-fn-error.stderr new file mode 100644 index 0000000000000..a7b757f2d0000 --- /dev/null +++ b/src/test/ui/consts/const-fn-error.stderr @@ -0,0 +1,41 @@ +error[E0658]: let bindings in constant functions are unstable (see issue #48821) + --> $DIR/const-fn-error.rs:16:19 + | +LL | let mut sum = 0; + | ^ + | + = help: add #![feature(const_let)] to the crate attributes to enable + +error[E0658]: statements in constant functions are unstable (see issue #48821) + --> $DIR/const-fn-error.rs:16:19 + | +LL | let mut sum = 0; + | ^ + | + = help: add #![feature(const_let)] to the crate attributes to enable + +error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants + --> $DIR/const-fn-error.rs:19:14 + | +LL | for i in 0..x { //~ ERROR E0080 + | ^^^^ + +error[E0019]: constant function contains unimplemented expression type + --> $DIR/const-fn-error.rs:19:14 + | +LL | for i in 0..x { //~ ERROR E0080 + | ^^^^ + +error[E0080]: evaluation of constant value failed + --> $DIR/const-fn-error.rs:19:14 + | +LL | for i in 0..x { //~ ERROR E0080 + | ^^^^ calling non-const fn `>::into_iter` +... +LL | let a : [i32; f(X)]; + | ---- inside call to `f` + +error: aborting due to 5 previous errors + +Some errors occurred: E0015, E0019, E0080, E0658. +For more information about an error, try `rustc --explain E0015`. diff --git a/src/test/ui/consts/const-integer-bool-ops.rs b/src/test/ui/consts/const-integer-bool-ops.rs index 29bc665a22e7b..5f0829eb35874 100644 --- a/src/test/ui/consts/const-integer-bool-ops.rs +++ b/src/test/ui/consts/const-integer-bool-ops.rs @@ -16,6 +16,7 @@ const X: usize = 42 && 39; //~| ERROR mismatched types //~| expected usize, found bool const ARR: [i32; X] = [99; 34]; +//~^ ERROR evaluation of constant value failed const X1: usize = 42 || 39; //~^ ERROR mismatched types @@ -25,6 +26,7 @@ const X1: usize = 42 || 39; //~| ERROR mismatched types //~| expected usize, found bool const ARR1: [i32; X1] = [99; 47]; +//~^ ERROR evaluation of constant value failed const X2: usize = -42 || -39; //~^ ERROR mismatched types @@ -34,6 +36,7 @@ const X2: usize = -42 || -39; //~| ERROR mismatched types //~| expected usize, found bool const ARR2: [i32; X2] = [99; 18446744073709551607]; +//~^ ERROR evaluation of constant value failed const X3: usize = -42 && -39; //~^ ERROR mismatched types @@ -43,36 +46,43 @@ const X3: usize = -42 && -39; //~| ERROR mismatched types //~| expected usize, found bool const ARR3: [i32; X3] = [99; 6]; +//~^ ERROR evaluation of constant value failed const Y: usize = 42.0 == 42.0; //~^ ERROR mismatched types //~| expected usize, found bool const ARRR: [i32; Y] = [99; 1]; +//~^ ERROR evaluation of constant value failed const Y1: usize = 42.0 >= 42.0; //~^ ERROR mismatched types //~| expected usize, found bool const ARRR1: [i32; Y1] = [99; 1]; +//~^ ERROR evaluation of constant value failed const Y2: usize = 42.0 <= 42.0; //~^ ERROR mismatched types //~| expected usize, found bool const ARRR2: [i32; Y2] = [99; 1]; +//~^ ERROR evaluation of constant value failed const Y3: usize = 42.0 > 42.0; //~^ ERROR mismatched types //~| expected usize, found bool const ARRR3: [i32; Y3] = [99; 0]; +//~^ ERROR evaluation of constant value failed const Y4: usize = 42.0 < 42.0; //~^ ERROR mismatched types //~| expected usize, found bool const ARRR4: [i32; Y4] = [99; 0]; +//~^ ERROR evaluation of constant value failed const Y5: usize = 42.0 != 42.0; //~^ ERROR mismatched types //~| expected usize, found bool const ARRR5: [i32; Y5] = [99; 0]; +//~^ ERROR evaluation of constant value failed fn main() { let _ = ARR; diff --git a/src/test/ui/consts/const-integer-bool-ops.stderr b/src/test/ui/consts/const-integer-bool-ops.stderr index 8075a3f0863b6..1bcb3ea719d1a 100644 --- a/src/test/ui/consts/const-integer-bool-ops.stderr +++ b/src/test/ui/consts/const-integer-bool-ops.stderr @@ -22,8 +22,14 @@ error[E0308]: mismatched types LL | const X: usize = 42 && 39; | ^^^^^^^^ expected usize, found bool +error[E0080]: evaluation of constant value failed + --> $DIR/const-integer-bool-ops.rs:18:18 + | +LL | const ARR: [i32; X] = [99; 34]; + | ^ referenced constant has errors + error[E0308]: mismatched types - --> $DIR/const-integer-bool-ops.rs:20:19 + --> $DIR/const-integer-bool-ops.rs:21:19 | LL | const X1: usize = 42 || 39; | ^^ expected bool, found integral variable @@ -32,7 +38,7 @@ LL | const X1: usize = 42 || 39; found type `{integer}` error[E0308]: mismatched types - --> $DIR/const-integer-bool-ops.rs:20:25 + --> $DIR/const-integer-bool-ops.rs:21:25 | LL | const X1: usize = 42 || 39; | ^^ expected bool, found integral variable @@ -41,13 +47,19 @@ LL | const X1: usize = 42 || 39; found type `{integer}` error[E0308]: mismatched types - --> $DIR/const-integer-bool-ops.rs:20:19 + --> $DIR/const-integer-bool-ops.rs:21:19 | LL | const X1: usize = 42 || 39; | ^^^^^^^^ expected usize, found bool +error[E0080]: evaluation of constant value failed + --> $DIR/const-integer-bool-ops.rs:28:19 + | +LL | const ARR1: [i32; X1] = [99; 47]; + | ^^ referenced constant has errors + error[E0308]: mismatched types - --> $DIR/const-integer-bool-ops.rs:29:19 + --> $DIR/const-integer-bool-ops.rs:31:19 | LL | const X2: usize = -42 || -39; | ^^^ expected bool, found integral variable @@ -56,7 +68,7 @@ LL | const X2: usize = -42 || -39; found type `{integer}` error[E0308]: mismatched types - --> $DIR/const-integer-bool-ops.rs:29:26 + --> $DIR/const-integer-bool-ops.rs:31:26 | LL | const X2: usize = -42 || -39; | ^^^ expected bool, found integral variable @@ -65,14 +77,20 @@ LL | const X2: usize = -42 || -39; found type `{integer}` error[E0308]: mismatched types - --> $DIR/const-integer-bool-ops.rs:29:19 + --> $DIR/const-integer-bool-ops.rs:31:19 | LL | const X2: usize = -42 || -39; | ^^^^^^^^^^ expected usize, found bool -error[E0308]: mismatched types +error[E0080]: evaluation of constant value failed --> $DIR/const-integer-bool-ops.rs:38:19 | +LL | const ARR2: [i32; X2] = [99; 18446744073709551607]; + | ^^ referenced constant has errors + +error[E0308]: mismatched types + --> $DIR/const-integer-bool-ops.rs:41:19 + | LL | const X3: usize = -42 && -39; | ^^^ expected bool, found integral variable | @@ -80,7 +98,7 @@ LL | const X3: usize = -42 && -39; found type `{integer}` error[E0308]: mismatched types - --> $DIR/const-integer-bool-ops.rs:38:26 + --> $DIR/const-integer-bool-ops.rs:41:26 | LL | const X3: usize = -42 && -39; | ^^^ expected bool, found integral variable @@ -89,47 +107,90 @@ LL | const X3: usize = -42 && -39; found type `{integer}` error[E0308]: mismatched types - --> $DIR/const-integer-bool-ops.rs:38:19 + --> $DIR/const-integer-bool-ops.rs:41:19 | LL | const X3: usize = -42 && -39; | ^^^^^^^^^^ expected usize, found bool +error[E0080]: evaluation of constant value failed + --> $DIR/const-integer-bool-ops.rs:48:19 + | +LL | const ARR3: [i32; X3] = [99; 6]; + | ^^ referenced constant has errors + error[E0308]: mismatched types - --> $DIR/const-integer-bool-ops.rs:47:18 + --> $DIR/const-integer-bool-ops.rs:51:18 | LL | const Y: usize = 42.0 == 42.0; | ^^^^^^^^^^^^ expected usize, found bool +error[E0080]: evaluation of constant value failed + --> $DIR/const-integer-bool-ops.rs:54:19 + | +LL | const ARRR: [i32; Y] = [99; 1]; + | ^ referenced constant has errors + error[E0308]: mismatched types - --> $DIR/const-integer-bool-ops.rs:52:19 + --> $DIR/const-integer-bool-ops.rs:57:19 | LL | const Y1: usize = 42.0 >= 42.0; | ^^^^^^^^^^^^ expected usize, found bool +error[E0080]: evaluation of constant value failed + --> $DIR/const-integer-bool-ops.rs:60:20 + | +LL | const ARRR1: [i32; Y1] = [99; 1]; + | ^^ referenced constant has errors + error[E0308]: mismatched types - --> $DIR/const-integer-bool-ops.rs:57:19 + --> $DIR/const-integer-bool-ops.rs:63:19 | LL | const Y2: usize = 42.0 <= 42.0; | ^^^^^^^^^^^^ expected usize, found bool +error[E0080]: evaluation of constant value failed + --> $DIR/const-integer-bool-ops.rs:66:20 + | +LL | const ARRR2: [i32; Y2] = [99; 1]; + | ^^ referenced constant has errors + error[E0308]: mismatched types - --> $DIR/const-integer-bool-ops.rs:62:19 + --> $DIR/const-integer-bool-ops.rs:69:19 | LL | const Y3: usize = 42.0 > 42.0; | ^^^^^^^^^^^ expected usize, found bool +error[E0080]: evaluation of constant value failed + --> $DIR/const-integer-bool-ops.rs:72:20 + | +LL | const ARRR3: [i32; Y3] = [99; 0]; + | ^^ referenced constant has errors + error[E0308]: mismatched types - --> $DIR/const-integer-bool-ops.rs:67:19 + --> $DIR/const-integer-bool-ops.rs:75:19 | LL | const Y4: usize = 42.0 < 42.0; | ^^^^^^^^^^^ expected usize, found bool +error[E0080]: evaluation of constant value failed + --> $DIR/const-integer-bool-ops.rs:78:20 + | +LL | const ARRR4: [i32; Y4] = [99; 0]; + | ^^ referenced constant has errors + error[E0308]: mismatched types - --> $DIR/const-integer-bool-ops.rs:72:19 + --> $DIR/const-integer-bool-ops.rs:81:19 | LL | const Y5: usize = 42.0 != 42.0; | ^^^^^^^^^^^^ expected usize, found bool -error: aborting due to 18 previous errors +error[E0080]: evaluation of constant value failed + --> $DIR/const-integer-bool-ops.rs:84:20 + | +LL | const ARRR5: [i32; Y5] = [99; 0]; + | ^^ referenced constant has errors + +error: aborting due to 28 previous errors -For more information about this error, try `rustc --explain E0308`. +Some errors occurred: E0080, E0308. +For more information about an error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-len-underflow-separate-spans.rs b/src/test/ui/consts/const-len-underflow-separate-spans.rs index 8db1411005e57..68452082ef333 100644 --- a/src/test/ui/consts/const-len-underflow-separate-spans.rs +++ b/src/test/ui/consts/const-len-underflow-separate-spans.rs @@ -15,11 +15,9 @@ const ONE: usize = 1; const TWO: usize = 2; const LEN: usize = ONE - TWO; +//~^ ERROR any use of this value will cause an error fn main() { let a: [i8; LEN] = unimplemented!(); //~^ ERROR E0080 -//~| ERROR E0080 -//~| ERROR E0080 -//~| ERROR E0080 } diff --git a/src/test/ui/consts/const-len-underflow-separate-spans.stderr b/src/test/ui/consts/const-len-underflow-separate-spans.stderr index cf97a0dc55578..da39fa2e6f22c 100644 --- a/src/test/ui/consts/const-len-underflow-separate-spans.stderr +++ b/src/test/ui/consts/const-len-underflow-separate-spans.stderr @@ -1,35 +1,19 @@ -error[E0080]: referenced constant has errors - --> $DIR/const-len-underflow-separate-spans.rs:20:17 +error: any use of this value will cause an error + --> $DIR/const-len-underflow-separate-spans.rs:17:1 | LL | const LEN: usize = ONE - TWO; - | --------- attempt to subtract with overflow -... -LL | let a: [i8; LEN] = unimplemented!(); - | ^^^ - -error[E0080]: could not evaluate constant - --> $DIR/const-len-underflow-separate-spans.rs:20:17 + | ^^^^^^^^^^^^^^^^^^^---------^ + | | + | attempt to subtract with overflow | -LL | let a: [i8; LEN] = unimplemented!(); - | ^^^ referenced constant has errors + = note: #[deny(const_err)] on by default -error[E0080]: referenced constant has errors - --> $DIR/const-len-underflow-separate-spans.rs:20:12 +error[E0080]: evaluation of constant value failed + --> $DIR/const-len-underflow-separate-spans.rs:21:17 | -LL | const LEN: usize = ONE - TWO; - | --------- attempt to subtract with overflow -... LL | let a: [i8; LEN] = unimplemented!(); - | ^^^^^^^^^ - -error[E0080]: could not evaluate constant expression - --> $DIR/const-len-underflow-separate-spans.rs:20:12 - | -LL | let a: [i8; LEN] = unimplemented!(); - | ^^^^^---^ - | | - | 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`. diff --git a/src/test/ui/consts/const-len-underflow-subspans.rs b/src/test/ui/consts/const-len-underflow-subspans.rs index 054c272a3d321..10180f3648998 100644 --- a/src/test/ui/consts/const-len-underflow-subspans.rs +++ b/src/test/ui/consts/const-len-underflow-subspans.rs @@ -16,6 +16,6 @@ const TWO: usize = 2; fn main() { let a: [i8; ONE - TWO] = unimplemented!(); - //~^ ERROR could not evaluate constant expression + //~^ ERROR evaluation of constant value failed //~| attempt to subtract with overflow } diff --git a/src/test/ui/consts/const-len-underflow-subspans.stderr b/src/test/ui/consts/const-len-underflow-subspans.stderr index 860716c1f3855..3fca7ecb19a52 100644 --- a/src/test/ui/consts/const-len-underflow-subspans.stderr +++ b/src/test/ui/consts/const-len-underflow-subspans.stderr @@ -1,19 +1,9 @@ -error: attempt to subtract with overflow +error[E0080]: evaluation of constant value failed --> $DIR/const-len-underflow-subspans.rs:18:17 | LL | let a: [i8; ONE - TWO] = unimplemented!(); - | ^^^^^^^^^ - | - = note: #[deny(const_err)] on by default - -error[E0080]: could not evaluate constant expression - --> $DIR/const-len-underflow-subspans.rs:18:12 - | -LL | let a: [i8; ONE - TWO] = unimplemented!(); - | ^^^^^---------^ - | | - | attempt to subtract with overflow + | ^^^^^^^^^ attempt to subtract with overflow -error: aborting due to 2 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-size_of-cycle.stderr b/src/test/ui/consts/const-size_of-cycle.stderr index ab8b5792e681d..ea5d7c176ffb9 100644 --- a/src/test/ui/consts/const-size_of-cycle.stderr +++ b/src/test/ui/consts/const-size_of-cycle.stderr @@ -1,6 +1,11 @@ error[E0391]: cycle detected when computing layout of `Foo` | note: ...which requires normalizing `ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: All }, value: [u8; _] }`... +note: ...which requires const-evaluating + checking `Foo::bytes::{{constant}}`... + --> $DIR/const-size_of-cycle.rs:16:17 + | +LL | bytes: [u8; std::mem::size_of::()] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...which requires const-evaluating `Foo::bytes::{{constant}}`... --> $SRC_DIR/libcore/mem.rs:LL:COL | diff --git a/src/test/ui/consts/const-slice-oob.rs b/src/test/ui/consts/const-slice-oob.rs index 6d51ff3099809..b71556735d9f6 100644 --- a/src/test/ui/consts/const-slice-oob.rs +++ b/src/test/ui/consts/const-slice-oob.rs @@ -13,8 +13,10 @@ const FOO: &'static[u32] = &[1, 2, 3]; const BAR: u32 = FOO[5]; //~^ index out of bounds: the len is 3 but the index is 5 -//~| ERROR this constant cannot be used +//~| ERROR any use of this value will cause an error +//~| ERROR any use of this value will cause an error fn main() { let _ = BAR; + //~^ ERROR erroneous constant used } diff --git a/src/test/ui/consts/const-slice-oob.stderr b/src/test/ui/consts/const-slice-oob.stderr index 30260c36ffd35..8fd298a18d22c 100644 --- a/src/test/ui/consts/const-slice-oob.stderr +++ b/src/test/ui/consts/const-slice-oob.stderr @@ -1,4 +1,4 @@ -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const-slice-oob.rs:14:1 | LL | const BAR: u32 = FOO[5]; @@ -8,5 +8,20 @@ LL | const BAR: u32 = FOO[5]; | = note: #[deny(const_err)] on by default -error: aborting due to previous error +error: any use of this value will cause an error + --> $DIR/const-slice-oob.rs:14:1 + | +LL | const BAR: u32 = FOO[5]; + | ^^^^^^^^^^^^^^^^^------^ + | | + | index out of bounds: the len is 3 but the index is 5 + +error[E0080]: erroneous constant used + --> $DIR/const-slice-oob.rs:20:13 + | +LL | let _ = BAR; + | ^^^ referenced constant has errors + +error: aborting due to 3 previous errors +For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-tup-index-span.rs b/src/test/ui/consts/const-tup-index-span.rs index b42c440f87d74..e1d5811648185 100644 --- a/src/test/ui/consts/const-tup-index-span.rs +++ b/src/test/ui/consts/const-tup-index-span.rs @@ -14,6 +14,7 @@ const TUP: (usize,) = 5usize << 64; //~^ ERROR mismatched types //~| expected tuple, found usize const ARR: [i32; TUP.0] = []; +//~^ ERROR evaluation of constant value failed fn main() { } diff --git a/src/test/ui/consts/const-tup-index-span.stderr b/src/test/ui/consts/const-tup-index-span.stderr index e924862965611..3018baac5a586 100644 --- a/src/test/ui/consts/const-tup-index-span.stderr +++ b/src/test/ui/consts/const-tup-index-span.stderr @@ -7,6 +7,13 @@ LL | const TUP: (usize,) = 5usize << 64; = note: expected type `(usize,)` found type `usize` -error: aborting due to previous error +error[E0080]: evaluation of constant value failed + --> $DIR/const-tup-index-span.rs:16:18 + | +LL | const ARR: [i32; TUP.0] = []; + | ^^^ referenced constant has errors + +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0308`. +Some errors occurred: E0080, E0308. +For more information about an error, try `rustc --explain E0080`. diff --git a/src/test/ui/error-codes/E0080.rs b/src/test/ui/error-codes/E0080.rs index 7f3e6eaad9b17..2ab15dfedcaaa 100644 --- a/src/test/ui/error-codes/E0080.rs +++ b/src/test/ui/error-codes/E0080.rs @@ -12,9 +12,6 @@ enum Enum { X = (1 << 500), //~ ERROR E0080 //~| shift left with overflow Y = (1 / 0) //~ ERROR E0080 - //~| const_err - //~| const_err - //~| const_err } fn main() { diff --git a/src/test/ui/error-codes/E0080.stderr b/src/test/ui/error-codes/E0080.stderr index a213c2b1b208e..e60c905587de8 100644 --- a/src/test/ui/error-codes/E0080.stderr +++ b/src/test/ui/error-codes/E0080.stderr @@ -1,37 +1,15 @@ -error: attempt to shift left with overflow - --> $DIR/E0080.rs:12:9 - | -LL | X = (1 << 500), //~ ERROR E0080 - | ^^^^^^^^^^ - | - = note: #[deny(exceeding_bitshifts)] on by default - -error[E0080]: could not evaluate enum discriminant +error[E0080]: evaluation of constant value failed --> $DIR/E0080.rs:12:9 | LL | X = (1 << 500), //~ ERROR E0080 | ^^^^^^^^^^ attempt to shift left with overflow -error: attempt to divide by zero - --> $DIR/E0080.rs:14:9 - | -LL | Y = (1 / 0) //~ ERROR E0080 - | ^^^^^^^ - | - = note: #[deny(const_err)] on by default - -error: this expression will panic at runtime - --> $DIR/E0080.rs:14:9 - | -LL | Y = (1 / 0) //~ ERROR E0080 - | ^^^^^^^ attempt to divide by zero - -error[E0080]: could not evaluate enum discriminant +error[E0080]: evaluation of constant value failed --> $DIR/E0080.rs:14:9 | LL | Y = (1 / 0) //~ ERROR E0080 | ^^^^^^^ attempt to divide by zero -error: aborting due to 5 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/error-codes/E0396-fixed.rs b/src/test/ui/error-codes/E0396-fixed.rs index 08d20e7850d94..005f2c3668892 100644 --- a/src/test/ui/error-codes/E0396-fixed.rs +++ b/src/test/ui/error-codes/E0396-fixed.rs @@ -13,7 +13,7 @@ const REG_ADDR: *const u8 = 0x5f3759df as *const u8; const VALUE: u8 = unsafe { *REG_ADDR }; -//~^ ERROR this constant cannot be used +//~^ ERROR any use of this value will cause an error fn main() { } diff --git a/src/test/ui/error-codes/E0396-fixed.stderr b/src/test/ui/error-codes/E0396-fixed.stderr index 7d3c98c8ea808..e868d5a33fa45 100644 --- a/src/test/ui/error-codes/E0396-fixed.stderr +++ b/src/test/ui/error-codes/E0396-fixed.stderr @@ -1,4 +1,4 @@ -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/E0396-fixed.rs:15:1 | LL | const VALUE: u8 = unsafe { *REG_ADDR }; diff --git a/src/test/ui/eval-enum.rs b/src/test/ui/eval-enum.rs index ada038114d8d0..f8a87db88b13c 100644 --- a/src/test/ui/eval-enum.rs +++ b/src/test/ui/eval-enum.rs @@ -11,12 +11,10 @@ enum Test { DivZero = 1/0, //~^ attempt to divide by zero - //~| ERROR could not evaluate enum discriminant - //~| ERROR this expression will panic at runtime + //~| ERROR evaluation of constant value failed RemZero = 1%0, //~^ attempt to calculate the remainder with a divisor of zero - //~| ERROR could not evaluate enum discriminant - //~| ERROR this expression will panic at runtime + //~| ERROR evaluation of constant value failed } fn main() {} diff --git a/src/test/ui/eval-enum.stderr b/src/test/ui/eval-enum.stderr index f26c48f1a72ae..59c5ec10f6a86 100644 --- a/src/test/ui/eval-enum.stderr +++ b/src/test/ui/eval-enum.stderr @@ -1,41 +1,15 @@ -error: attempt to divide by zero - --> $DIR/eval-enum.rs:12:15 - | -LL | DivZero = 1/0, - | ^^^ - | - = note: #[deny(const_err)] on by default - -error: this expression will panic at runtime +error[E0080]: evaluation of constant value failed --> $DIR/eval-enum.rs:12:15 | LL | DivZero = 1/0, | ^^^ attempt to divide by zero -error[E0080]: could not evaluate enum discriminant - --> $DIR/eval-enum.rs:12:15 - | -LL | DivZero = 1/0, - | ^^^ attempt to divide by zero - -error: attempt to calculate the remainder with a divisor of zero - --> $DIR/eval-enum.rs:16:15 - | -LL | RemZero = 1%0, - | ^^^ - -error: this expression will panic at runtime - --> $DIR/eval-enum.rs:16:15 - | -LL | RemZero = 1%0, - | ^^^ attempt to calculate the remainder with a divisor of zero - -error[E0080]: could not evaluate enum discriminant - --> $DIR/eval-enum.rs:16:15 +error[E0080]: evaluation of constant value failed + --> $DIR/eval-enum.rs:15:15 | LL | RemZero = 1%0, | ^^^ attempt to calculate the remainder with a divisor of zero -error: aborting due to 6 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/infinite/infinite-recursion-const-fn.rs b/src/test/ui/infinite/infinite-recursion-const-fn.rs index f99a080a9f07d..ccf67ca3138ff 100644 --- a/src/test/ui/infinite/infinite-recursion-const-fn.rs +++ b/src/test/ui/infinite/infinite-recursion-const-fn.rs @@ -10,8 +10,8 @@ //https://github.com/rust-lang/rust/issues/31364 -const fn a() -> usize { b() } +const fn a() -> usize { b() } //~ ERROR evaluation of constant value failed const fn b() -> usize { a() } -const ARR: [i32; a()] = [5; 6]; //~ ERROR could not evaluate constant expression +const ARR: [i32; a()] = [5; 6]; fn main(){} diff --git a/src/test/ui/infinite/infinite-recursion-const-fn.stderr b/src/test/ui/infinite/infinite-recursion-const-fn.stderr index c77452d9abe20..82da89f1aa702 100644 --- a/src/test/ui/infinite/infinite-recursion-const-fn.stderr +++ b/src/test/ui/infinite/infinite-recursion-const-fn.stderr @@ -1,8 +1,8 @@ -error[E0080]: could not evaluate constant expression - --> $DIR/infinite-recursion-const-fn.rs:15:12 +error[E0080]: evaluation of constant value failed + --> $DIR/infinite-recursion-const-fn.rs:14:25 | -LL | const fn a() -> usize { b() } - | --- +LL | const fn a() -> usize { b() } //~ ERROR evaluation of constant value failed + | ^^^ | | | reached the configured maximum number of stack frames | inside call to `b` @@ -58,10 +58,8 @@ LL | const fn b() -> usize { a() } | inside call to `a` | inside call to `a` | inside call to `a` -LL | const ARR: [i32; a()] = [5; 6]; //~ ERROR could not evaluate constant expression - | ^^^^^^---^ - | | - | inside call to `a` +LL | const ARR: [i32; a()] = [5; 6]; + | --- inside call to `a` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-39559-2.stderr b/src/test/ui/issues/issue-39559-2.stderr index ca9da096b6c16..d7efcc5249486 100644 --- a/src/test/ui/issues/issue-39559-2.stderr +++ b/src/test/ui/issues/issue-39559-2.stderr @@ -4,12 +4,24 @@ error[E0015]: calls in constants are limited to constant functions, tuple struct LL | let array: [usize; Dim3::dim()] | ^^^^^^^^^^^ +error[E0080]: evaluation of constant value failed + --> $DIR/issue-39559-2.rs:24:24 + | +LL | let array: [usize; Dim3::dim()] + | ^^^^^^^^^^^ calling non-const fn `::dim` + error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants --> $DIR/issue-39559-2.rs:26:15 | LL | = [0; Dim3::dim()]; | ^^^^^^^^^^^ -error: aborting due to 2 previous errors +error[E0080]: evaluation of constant value failed + --> $DIR/issue-39559-2.rs:27:15 + | +LL | = [0; Dim3::dim()]; + | ^^^^^^^^^^^ calling non-const fn `::dim` + +error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0015`. diff --git a/src/test/ui/issues/issue-41394.rs b/src/test/ui/issues/issue-41394.rs index 89f11edaec862..539b8d2aab3da 100644 --- a/src/test/ui/issues/issue-41394.rs +++ b/src/test/ui/issues/issue-41394.rs @@ -15,6 +15,7 @@ enum Foo { enum Bar { A = Foo::A as isize + //~^ ERROR evaluation of constant value failed } fn main() {} diff --git a/src/test/ui/issues/issue-41394.stderr b/src/test/ui/issues/issue-41394.stderr index 9e4afb3b28ac1..4f170f0ce3d45 100644 --- a/src/test/ui/issues/issue-41394.stderr +++ b/src/test/ui/issues/issue-41394.stderr @@ -6,6 +6,13 @@ LL | A = "" + 1 | = note: an implementation of `std::ops::Add` might be missing for `&str` -error: aborting due to previous error +error[E0080]: evaluation of constant value failed + --> $DIR/issue-41394.rs:17:9 + | +LL | A = Foo::A as isize + | ^^^^^^^^^^^^^^^ referenced constant has errors + +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0369`. +Some errors occurred: E0080, E0369. +For more information about an error, try `rustc --explain E0080`. diff --git a/src/test/ui/issues/issue-43105.rs b/src/test/ui/issues/issue-43105.rs index 2bddc443d5baf..2b0eb68549795 100644 --- a/src/test/ui/issues/issue-43105.rs +++ b/src/test/ui/issues/issue-43105.rs @@ -12,10 +12,11 @@ fn xyz() -> u8 { 42 } const NUM: u8 = xyz(); //~^ ERROR calls in constants are limited to constant functions, tuple structs and tuple variants +//~| ERROR any use of this value will cause an error fn main() { match 1 { - NUM => unimplemented!(), + NUM => unimplemented!(), //~ ERROR could not evaluate constant pattern _ => unimplemented!(), } } diff --git a/src/test/ui/issues/issue-43105.stderr b/src/test/ui/issues/issue-43105.stderr index 67a6008cd8ebc..aba8351186bd9 100644 --- a/src/test/ui/issues/issue-43105.stderr +++ b/src/test/ui/issues/issue-43105.stderr @@ -4,6 +4,22 @@ error[E0015]: calls in constants are limited to constant functions, tuple struct LL | const NUM: u8 = xyz(); | ^^^^^ -error: aborting due to previous error +error: any use of this value will cause an error + --> $DIR/issue-43105.rs:13:1 + | +LL | const NUM: u8 = xyz(); + | ^^^^^^^^^^^^^^^^-----^ + | | + | calling non-const fn `xyz` + | + = note: #[deny(const_err)] on by default + +error: could not evaluate constant pattern + --> $DIR/issue-43105.rs:19:9 + | +LL | NUM => unimplemented!(), //~ ERROR could not evaluate constant pattern + | ^^^ + +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0015`. diff --git a/src/test/ui/issues/issue-44415.stderr b/src/test/ui/issues/issue-44415.stderr index ac2072c513ea0..f20c2c733591b 100644 --- a/src/test/ui/issues/issue-44415.stderr +++ b/src/test/ui/issues/issue-44415.stderr @@ -1,6 +1,11 @@ error[E0391]: cycle detected when computing layout of `Foo` | note: ...which requires normalizing `ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: All }, value: [u8; _] }`... +note: ...which requires const-evaluating + checking `Foo::bytes::{{constant}}`... + --> $DIR/issue-44415.rs:19:17 + | +LL | bytes: [u8; unsafe { intrinsics::size_of::() }], + | ^^^^^^ note: ...which requires const-evaluating `Foo::bytes::{{constant}}`... --> $DIR/issue-44415.rs:19:26 | diff --git a/src/test/ui/issues/issue-50599.rs b/src/test/ui/issues/issue-50599.rs index f46a562ce7a18..417f8c8848ea3 100644 --- a/src/test/ui/issues/issue-50599.rs +++ b/src/test/ui/issues/issue-50599.rs @@ -12,4 +12,5 @@ fn main() { const N: u32 = 1_000; const M: usize = (f64::from(N) * std::f64::LOG10_2) as usize; //~ ERROR cannot find value let mut digits = [0u32; M]; + //~^ ERROR evaluation of constant value failed } diff --git a/src/test/ui/issues/issue-50599.stderr b/src/test/ui/issues/issue-50599.stderr index 8337a31ec140b..5338f333d21fa 100644 --- a/src/test/ui/issues/issue-50599.stderr +++ b/src/test/ui/issues/issue-50599.stderr @@ -10,6 +10,13 @@ LL | use std::f32::consts::LOG10_2; LL | use std::f64::consts::LOG10_2; | -error: aborting due to previous error +error[E0080]: evaluation of constant value failed + --> $DIR/issue-50599.rs:14:29 + | +LL | let mut digits = [0u32; M]; + | ^ referenced constant has errors + +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0425`. +Some errors occurred: E0080, E0425. +For more information about an error, try `rustc --explain E0080`. diff --git a/src/test/ui/recursion/recursive-static-definition.stderr b/src/test/ui/recursion/recursive-static-definition.stderr index 2ab93bfd685c8..5bd0f90afbcae 100644 --- a/src/test/ui/recursion/recursive-static-definition.stderr +++ b/src/test/ui/recursion/recursive-static-definition.stderr @@ -5,6 +5,11 @@ LL | pub static FOO: u32 = FOO; | ^^^ | = note: ...which again requires const-evaluating `FOO`, completing the cycle +note: cycle used when const-evaluating + checking `FOO` + --> $DIR/recursive-static-definition.rs:11:1 + | +LL | pub static FOO: u32 = FOO; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/type/type-dependent-def-issue-49241.rs b/src/test/ui/type/type-dependent-def-issue-49241.rs index db27ae89e69fd..e479701492657 100644 --- a/src/test/ui/type/type-dependent-def-issue-49241.rs +++ b/src/test/ui/type/type-dependent-def-issue-49241.rs @@ -12,4 +12,5 @@ fn main() { let v = vec![0]; const l: usize = v.count(); //~ ERROR can't capture dynamic environment in a fn item let s: [u32; l] = v.into_iter().collect(); + //~^ ERROR evaluation of constant value failed } diff --git a/src/test/ui/type/type-dependent-def-issue-49241.stderr b/src/test/ui/type/type-dependent-def-issue-49241.stderr index 361d28f274fa3..361c3c0c3d5d9 100644 --- a/src/test/ui/type/type-dependent-def-issue-49241.stderr +++ b/src/test/ui/type/type-dependent-def-issue-49241.stderr @@ -6,6 +6,13 @@ LL | const l: usize = v.count(); //~ ERROR can't capture dynamic environment | = help: use the `|| { ... }` closure form instead -error: aborting due to previous error +error[E0080]: evaluation of constant value failed + --> $DIR/type-dependent-def-issue-49241.rs:14:18 + | +LL | let s: [u32; l] = v.into_iter().collect(); + | ^ referenced constant has errors + +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0434`. +Some errors occurred: E0080, E0434. +For more information about an error, try `rustc --explain E0080`. From cce53b3631ba67495e5f1db6cc2fcbe93faac0fb Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Thu, 30 Aug 2018 15:29:29 +0200 Subject: [PATCH 02/21] Forward `TooGeneric` errors --- src/librustc_mir/interpret/eval_context.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index ce991c50330bb..78e8ca0253396 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -24,6 +24,7 @@ use rustc::ty::{self, Ty, TyCtxt, TypeFoldable}; use rustc::ty::query::TyCtxtAt; use rustc_data_structures::indexed_vec::IndexVec; use rustc::mir::interpret::{ + ErrorHandled, GlobalId, Scalar, FrameInfo, AllocId, EvalResult, EvalErrorKind, truncate, sign_extend, @@ -611,8 +612,11 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc } else { self.param_env }; - self.tcx.const_eval(param_env.and(gid)).map_err(|_| { - EvalErrorKind::ReferencedConstant.into() + self.tcx.const_eval(param_env.and(gid)).map_err(|err| { + match err { + ErrorHandled::Reported => EvalErrorKind::ReferencedConstant.into(), + ErrorHandled::TooGeneric => EvalErrorKind::TooGeneric.into(), + } }) } From 6f84d6edf1da310d1022777dadf59b87b78bd8fb Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Thu, 30 Aug 2018 16:30:20 +0200 Subject: [PATCH 03/21] Layout errors can happen because something was too generic --- src/librustc/mir/interpret/error.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/librustc/mir/interpret/error.rs b/src/librustc/mir/interpret/error.rs index f7f4c50b96d40..75ce9b55c5037 100644 --- a/src/librustc/mir/interpret/error.rs +++ b/src/librustc/mir/interpret/error.rs @@ -12,7 +12,7 @@ use std::{fmt, env}; use mir; use ty::{Ty, layout}; -use ty::layout::{Size, Align}; +use ty::layout::{Size, Align, LayoutError}; use rustc_target::spec::abi::Abi; use super::{ @@ -113,9 +113,10 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> { lint_root: Option, ) -> Result, ErrorHandled> { match self.error.kind { + EvalErrorKind::Layout(LayoutError::Unknown(_)) | EvalErrorKind::TooGeneric => return Err(ErrorHandled::TooGeneric), - EvalErrorKind::TypeckError | - EvalErrorKind::Layout(_) => return Err(ErrorHandled::Reported), + EvalErrorKind::Layout(LayoutError::SizeOverflow(_)) | + EvalErrorKind::TypeckError => return Err(ErrorHandled::Reported), _ => {}, } trace!("reporting const eval failure at {:?}", self.span); From d34232bcaf6f2bdb3ac17d6025c4c68f9798be0b Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Fri, 31 Aug 2018 10:39:47 +0200 Subject: [PATCH 04/21] Fix rebase fallout --- src/librustc_mir/interpret/memory.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index b46e914133aad..0156872a4da8f 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -30,7 +30,7 @@ use syntax::ast::Mutability; use super::{ Pointer, AllocId, Allocation, ConstValue, GlobalId, EvalResult, Scalar, EvalErrorKind, AllocType, PointerArithmetic, - Machine, MemoryAccess, AllocMap, MayLeak, ScalarMaybeUndef, + Machine, MemoryAccess, AllocMap, MayLeak, ScalarMaybeUndef, ErrorHandled, }; #[derive(Debug, PartialEq, Eq, Copy, Clone, Hash)] @@ -370,10 +370,13 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> { }; // use the raw query here to break validation cycles. Later uses of the static will call the // full query anyway - tcx.const_eval_raw(ty::ParamEnv::reveal_all().and(gid)).map_err(|_| { + tcx.const_eval_raw(ty::ParamEnv::reveal_all().and(gid)).map_err(|err| { // no need to report anything, the const_eval call takes care of that for statics assert!(tcx.is_static(def_id).is_some()); - EvalErrorKind::ReferencedConstant.into() + match err { + ErrorHandled::Reported => EvalErrorKind::ReferencedConstant.into(), + ErrorHandled::TooGeneric => EvalErrorKind::TooGeneric.into(), + } }).map(|const_val| { if let ConstValue::ByRef(_, allocation, _) = const_val.val { // We got tcx memory. Let the machine figure out whether and how to From 0f970486183084634b08f516531c55d2286a38af Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Fri, 31 Aug 2018 10:40:14 +0200 Subject: [PATCH 05/21] Deduplicate all the ~~things~~ errors --- src/librustc_mir/const_eval.rs | 21 +++++++++ src/test/ui/array_const_index-0.rs | 1 - src/test/ui/array_const_index-0.stderr | 12 +---- src/test/ui/array_const_index-1.rs | 1 - src/test/ui/array_const_index-1.stderr | 12 +---- src/test/ui/consts/const-err-early.rs | 1 - src/test/ui/consts/const-err-early.stderr | 30 +++++-------- src/test/ui/consts/const-err-multi.rs | 1 - src/test/ui/consts/const-err-multi.stderr | 18 +++----- src/test/ui/consts/const-err.rs | 1 - src/test/ui/consts/const-err.stderr | 10 +---- .../consts/const-eval/const-eval-overflow2.rs | 1 - .../const-eval/const-eval-overflow2.stderr | 44 +++++++------------ .../const-eval/const-eval-overflow2b.rs | 1 - .../const-eval/const-eval-overflow2b.stderr | 44 +++++++------------ .../const-eval/const-eval-overflow2c.rs | 1 - .../const-eval/const-eval-overflow2c.stderr | 44 +++++++------------ .../consts/const-eval/transmute-const.stderr | 2 +- .../const-eval/union-const-eval-field.rs | 1 - .../const-eval/union-const-eval-field.stderr | 12 ++--- src/test/ui/consts/const-size_of-cycle.stderr | 27 +++++++----- src/test/ui/consts/const-slice-oob.rs | 1 - src/test/ui/consts/const-slice-oob.stderr | 12 +---- src/test/ui/issues/issue-44415.rs | 4 +- src/test/ui/issues/issue-44415.stderr | 25 ++++++----- .../recursive-static-definition.stderr | 5 +++ 26 files changed, 133 insertions(+), 199 deletions(-) diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index 6ad1536a63052..861d0b2f7e1ae 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -23,6 +23,7 @@ use rustc::mir; use rustc::ty::{self, Ty, TyCtxt, Instance, query::TyCtxtAt}; use rustc::ty::layout::{self, Size, LayoutOf, TyLayout}; use rustc::ty::subst::Subst; +use rustc::traits::Reveal; use rustc::util::nodemap::FxHashSet; use rustc_data_structures::indexed_vec::IndexVec; use rustc_data_structures::fx::FxHashMap; @@ -576,6 +577,16 @@ pub fn const_eval_provider<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>, ) -> ::rustc::mir::interpret::ConstEvalResult<'tcx> { + if key.param_env.reveal == Reveal::All { + let mut key = key.clone(); + key.param_env.reveal = Reveal::UserFacing; + match tcx.const_eval(key) { + // try again with reveal all as requested + Err(ErrorHandled::TooGeneric) => {}, + // dedupliate calls + other => return other, + } + } tcx.const_eval_raw(key).and_then(|val| { validate_const(tcx, val, key) }) @@ -585,6 +596,16 @@ pub fn const_eval_raw_provider<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>, ) -> ::rustc::mir::interpret::ConstEvalResult<'tcx> { + if key.param_env.reveal == Reveal::All { + let mut key = key.clone(); + key.param_env.reveal = Reveal::UserFacing; + match tcx.const_eval_raw(key) { + // try again with reveal all as requested + Err(ErrorHandled::TooGeneric) => {}, + // dedupliate calls + other => return other, + } + } trace!("const eval: {:?}", key); let cid = key.value; let def_id = cid.instance.def.def_id(); diff --git a/src/test/ui/array_const_index-0.rs b/src/test/ui/array_const_index-0.rs index 2403d50db3953..0ad297eeb5cdb 100644 --- a/src/test/ui/array_const_index-0.rs +++ b/src/test/ui/array_const_index-0.rs @@ -12,7 +12,6 @@ const A: &'static [i32] = &[]; const B: i32 = (&A)[1]; //~^ index out of bounds: the len is 0 but the index is 1 //~| ERROR any use of this value will cause an error -//~| ERROR any use of this value will cause an error fn main() { let _ = B; //~ ERROR erroneous constant used diff --git a/src/test/ui/array_const_index-0.stderr b/src/test/ui/array_const_index-0.stderr index 95ed88bde108c..38163b1f4b199 100644 --- a/src/test/ui/array_const_index-0.stderr +++ b/src/test/ui/array_const_index-0.stderr @@ -8,20 +8,12 @@ LL | const B: i32 = (&A)[1]; | = note: #[deny(const_err)] on by default -error: any use of this value will cause an error - --> $DIR/array_const_index-0.rs:12:1 - | -LL | const B: i32 = (&A)[1]; - | ^^^^^^^^^^^^^^^-------^ - | | - | index out of bounds: the len is 0 but the index is 1 - error[E0080]: erroneous constant used - --> $DIR/array_const_index-0.rs:18:13 + --> $DIR/array_const_index-0.rs:17:13 | LL | let _ = B; //~ ERROR erroneous constant used | ^ referenced constant has errors -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/array_const_index-1.rs b/src/test/ui/array_const_index-1.rs index 0a49348761c08..4c7dcfbb347d8 100644 --- a/src/test/ui/array_const_index-1.rs +++ b/src/test/ui/array_const_index-1.rs @@ -12,7 +12,6 @@ const A: [i32; 0] = []; const B: i32 = A[1]; //~^ index out of bounds: the len is 0 but the index is 1 //~| ERROR any use of this value will cause an error -//~| ERROR any use of this value will cause an error fn main() { let _ = B; //~ ERROR erroneous constant used diff --git a/src/test/ui/array_const_index-1.stderr b/src/test/ui/array_const_index-1.stderr index 5fcfc14e2c0d0..b122e590c8854 100644 --- a/src/test/ui/array_const_index-1.stderr +++ b/src/test/ui/array_const_index-1.stderr @@ -8,20 +8,12 @@ LL | const B: i32 = A[1]; | = note: #[deny(const_err)] on by default -error: any use of this value will cause an error - --> $DIR/array_const_index-1.rs:12:1 - | -LL | const B: i32 = A[1]; - | ^^^^^^^^^^^^^^^----^ - | | - | index out of bounds: the len is 0 but the index is 1 - error[E0080]: erroneous constant used - --> $DIR/array_const_index-1.rs:18:13 + --> $DIR/array_const_index-1.rs:17:13 | LL | let _ = B; //~ ERROR erroneous constant used | ^ referenced constant has errors -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-err-early.rs b/src/test/ui/consts/const-err-early.rs index 488e6f49e14bb..1cbfb91842775 100644 --- a/src/test/ui/consts/const-err-early.rs +++ b/src/test/ui/consts/const-err-early.rs @@ -11,7 +11,6 @@ #![deny(const_err)] pub const A: i8 = -std::i8::MIN; //~ ERROR const_err -//~^ ERROR const_err pub const B: u8 = 200u8 + 200u8; //~ ERROR const_err pub const C: u8 = 200u8 * 4; //~ ERROR const_err pub const D: u8 = 42u8 - (42u8 + 1); //~ ERROR const_err diff --git a/src/test/ui/consts/const-err-early.stderr b/src/test/ui/consts/const-err-early.stderr index 21c7bf0a70a49..8cc112191b512 100644 --- a/src/test/ui/consts/const-err-early.stderr +++ b/src/test/ui/consts/const-err-early.stderr @@ -13,7 +13,7 @@ LL | #![deny(const_err)] | ^^^^^^^^^ error: any use of this value will cause an error - --> $DIR/const-err-early.rs:15:1 + --> $DIR/const-err-early.rs:14:1 | LL | pub const B: u8 = 200u8 + 200u8; //~ ERROR const_err | ^^^^^^^^^^^^^^^^^^-------------^ @@ -21,7 +21,7 @@ LL | pub const B: u8 = 200u8 + 200u8; //~ ERROR const_err | attempt to add with overflow error: any use of this value will cause an error - --> $DIR/const-err-early.rs:16:1 + --> $DIR/const-err-early.rs:15:1 | LL | pub const C: u8 = 200u8 * 4; //~ ERROR const_err | ^^^^^^^^^^^^^^^^^^---------^ @@ -29,7 +29,7 @@ LL | pub const C: u8 = 200u8 * 4; //~ ERROR const_err | attempt to multiply with overflow error: any use of this value will cause an error - --> $DIR/const-err-early.rs:17:1 + --> $DIR/const-err-early.rs:16:1 | LL | pub const D: u8 = 42u8 - (42u8 + 1); //~ ERROR const_err | ^^^^^^^^^^^^^^^^^^-----------------^ @@ -37,57 +37,49 @@ LL | pub const D: u8 = 42u8 - (42u8 + 1); //~ ERROR const_err | attempt to subtract with overflow error: any use of this value will cause an error - --> $DIR/const-err-early.rs:18:1 + --> $DIR/const-err-early.rs:17:1 | LL | pub const E: u8 = [5u8][1]; //~ ERROR const_err | ^^^^^^^^^^^^^^^^^^--------^ | | | index out of bounds: the len is 1 but the index is 1 -error: any use of this value will cause an error - --> $DIR/const-err-early.rs:13:1 - | -LL | pub const A: i8 = -std::i8::MIN; //~ ERROR const_err - | ^^^^^^^^^^^^^^^^^^-------------^ - | | - | attempt to negate with overflow - error[E0080]: erroneous constant used - --> $DIR/const-err-early.rs:21:14 + --> $DIR/const-err-early.rs:20:14 | LL | let _a = A; //~ ERROR erroneous constant used | ^ referenced constant has errors error[E0080]: erroneous constant used - --> $DIR/const-err-early.rs:22:14 + --> $DIR/const-err-early.rs:21:14 | LL | let _b = B; //~ ERROR erroneous constant used | ^ referenced constant has errors error[E0080]: erroneous constant used - --> $DIR/const-err-early.rs:23:14 + --> $DIR/const-err-early.rs:22:14 | LL | let _c = C; //~ ERROR erroneous constant used | ^ referenced constant has errors error[E0080]: erroneous constant used - --> $DIR/const-err-early.rs:24:14 + --> $DIR/const-err-early.rs:23:14 | LL | let _d = D; //~ ERROR erroneous constant used | ^ referenced constant has errors error[E0080]: erroneous constant used - --> $DIR/const-err-early.rs:25:14 + --> $DIR/const-err-early.rs:24:14 | LL | let _e = E; //~ ERROR erroneous constant used | ^ referenced constant has errors error: index out of bounds: the len is 1 but the index is 1 - --> $DIR/const-err-early.rs:26:14 + --> $DIR/const-err-early.rs:25:14 | LL | let _e = [6u8][1]; //~ ERROR index out of bounds | ^^^^^^^^ -error: aborting due to 12 previous errors +error: aborting due to 11 previous errors For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-err-multi.rs b/src/test/ui/consts/const-err-multi.rs index c3960b839925f..20eaebfbe5656 100644 --- a/src/test/ui/consts/const-err-multi.rs +++ b/src/test/ui/consts/const-err-multi.rs @@ -12,7 +12,6 @@ pub const A: i8 = -std::i8::MIN; //~^ ERROR const_err -//~| ERROR const_err pub const B: i8 = A; //~^ ERROR const_err pub const C: u8 = A as u8; diff --git a/src/test/ui/consts/const-err-multi.stderr b/src/test/ui/consts/const-err-multi.stderr index 0717302dbf9aa..da6f31a38868c 100644 --- a/src/test/ui/consts/const-err-multi.stderr +++ b/src/test/ui/consts/const-err-multi.stderr @@ -13,7 +13,7 @@ LL | #![deny(const_err)] | ^^^^^^^^^ error: any use of this value will cause an error - --> $DIR/const-err-multi.rs:16:1 + --> $DIR/const-err-multi.rs:15:1 | LL | pub const B: i8 = A; | ^^^^^^^^^^^^^^^^^^-^ @@ -21,7 +21,7 @@ LL | pub const B: i8 = A; | referenced constant has errors error: any use of this value will cause an error - --> $DIR/const-err-multi.rs:18:1 + --> $DIR/const-err-multi.rs:17:1 | LL | pub const C: u8 = A as u8; | ^^^^^^^^^^^^^^^^^^-------^ @@ -29,27 +29,19 @@ LL | pub const C: u8 = A as u8; | referenced constant has errors error: any use of this value will cause an error - --> $DIR/const-err-multi.rs:20:1 + --> $DIR/const-err-multi.rs:19:1 | LL | pub const D: i8 = 50 - A; | ^^^^^^^^^^^^^^^^^^------^ | | | referenced constant has errors -error: any use of this value will cause an error - --> $DIR/const-err-multi.rs:13:1 - | -LL | pub const A: i8 = -std::i8::MIN; - | ^^^^^^^^^^^^^^^^^^-------------^ - | | - | attempt to negate with overflow - error[E0080]: erroneous constant used - --> $DIR/const-err-multi.rs:24:13 + --> $DIR/const-err-multi.rs:23:13 | LL | let _ = (A, B, C, D); | ^^^^^^^^^^^^ referenced constant has errors -error: aborting due to 6 previous errors +error: aborting due to 5 previous errors For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-err.rs b/src/test/ui/consts/const-err.rs index 7c59e8b953596..fff50c86646f3 100644 --- a/src/test/ui/consts/const-err.rs +++ b/src/test/ui/consts/const-err.rs @@ -19,7 +19,6 @@ fn black_box(_: T) { const FOO: u8 = [5u8][1]; //~^ WARN any use of this value will cause an error -//~| WARN any use of this value will cause an error fn main() { black_box((FOO, FOO)); diff --git a/src/test/ui/consts/const-err.stderr b/src/test/ui/consts/const-err.stderr index b46277f4b019f..e2ef7c3d0d463 100644 --- a/src/test/ui/consts/const-err.stderr +++ b/src/test/ui/consts/const-err.stderr @@ -12,16 +12,8 @@ note: lint level defined here LL | #![warn(const_err)] | ^^^^^^^^^ -warning: any use of this value will cause an error - --> $DIR/const-err.rs:20:1 - | -LL | const FOO: u8 = [5u8][1]; - | ^^^^^^^^^^^^^^^^--------^ - | | - | index out of bounds: the len is 1 but the index is 1 - error[E0080]: erroneous constant used - --> $DIR/const-err.rs:25:15 + --> $DIR/const-err.rs:24:15 | LL | black_box((FOO, FOO)); | ^^^^^^^^^^ referenced constant has errors diff --git a/src/test/ui/consts/const-eval/const-eval-overflow2.rs b/src/test/ui/consts/const-eval/const-eval-overflow2.rs index ee29423a90cde..c61a1b3edb726 100644 --- a/src/test/ui/consts/const-eval/const-eval-overflow2.rs +++ b/src/test/ui/consts/const-eval/const-eval-overflow2.rs @@ -22,7 +22,6 @@ use std::{i8, i16, i32, i64, isize}; use std::{u8, u16, u32, u64, usize}; const VALS_I8: (i8,) = //~ ERROR any use of this value will cause an error - //~^ const_err ( i8::MIN - 1, ); diff --git a/src/test/ui/consts/const-eval/const-eval-overflow2.stderr b/src/test/ui/consts/const-eval/const-eval-overflow2.stderr index f10a6eee6de9c..0484335fd0c23 100644 --- a/src/test/ui/consts/const-eval/const-eval-overflow2.stderr +++ b/src/test/ui/consts/const-eval/const-eval-overflow2.stderr @@ -2,7 +2,6 @@ error: any use of this value will cause an error --> $DIR/const-eval-overflow2.rs:24:1 | LL | / const VALS_I8: (i8,) = //~ ERROR any use of this value will cause an error -LL | | //~^ const_err LL | | ( LL | | i8::MIN - 1, | | ----------- attempt to subtract with overflow @@ -16,7 +15,7 @@ LL | #![deny(const_err)] | ^^^^^^^^^ error: any use of this value will cause an error - --> $DIR/const-eval-overflow2.rs:30:1 + --> $DIR/const-eval-overflow2.rs:29:1 | LL | / const VALS_I16: (i16,) = //~ ERROR any use of this value will cause an error LL | | ( @@ -26,7 +25,7 @@ LL | | ); | |_______^ error: any use of this value will cause an error - --> $DIR/const-eval-overflow2.rs:35:1 + --> $DIR/const-eval-overflow2.rs:34:1 | LL | / const VALS_I32: (i32,) = //~ ERROR any use of this value will cause an error LL | | ( @@ -36,7 +35,7 @@ LL | | ); | |_______^ error: any use of this value will cause an error - --> $DIR/const-eval-overflow2.rs:40:1 + --> $DIR/const-eval-overflow2.rs:39:1 | LL | / const VALS_I64: (i64,) = //~ ERROR any use of this value will cause an error LL | | ( @@ -46,7 +45,7 @@ LL | | ); | |_______^ error: any use of this value will cause an error - --> $DIR/const-eval-overflow2.rs:45:1 + --> $DIR/const-eval-overflow2.rs:44:1 | LL | / const VALS_U8: (u8,) = //~ ERROR any use of this value will cause an error LL | | ( @@ -56,7 +55,7 @@ LL | | ); | |_______^ error: any use of this value will cause an error - --> $DIR/const-eval-overflow2.rs:50:1 + --> $DIR/const-eval-overflow2.rs:49:1 | LL | / const VALS_U16: (u16,) = ( //~ ERROR any use of this value will cause an error LL | | u16::MIN - 1, @@ -65,7 +64,7 @@ LL | | ); | |_______^ error: any use of this value will cause an error - --> $DIR/const-eval-overflow2.rs:54:1 + --> $DIR/const-eval-overflow2.rs:53:1 | LL | / const VALS_U32: (u32,) = ( //~ ERROR any use of this value will cause an error LL | | u32::MIN - 1, @@ -74,7 +73,7 @@ LL | | ); | |_______^ error: any use of this value will cause an error - --> $DIR/const-eval-overflow2.rs:58:1 + --> $DIR/const-eval-overflow2.rs:57:1 | LL | / const VALS_U64: (u64,) = //~ ERROR any use of this value will cause an error LL | | ( @@ -83,65 +82,54 @@ LL | | u64::MIN - 1, LL | | ); | |_______^ -error: any use of this value will cause an error - --> $DIR/const-eval-overflow2.rs:24:1 - | -LL | / const VALS_I8: (i8,) = //~ ERROR any use of this value will cause an error -LL | | //~^ const_err -LL | | ( -LL | | i8::MIN - 1, - | | ----------- attempt to subtract with overflow -LL | | ); - | |_______^ - error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2.rs:64:5 + --> $DIR/const-eval-overflow2.rs:63:5 | LL | foo(VALS_I8); //~ ERROR erroneous constant used | ^^^^^^^^^^^^ referenced constant has errors error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2.rs:65:5 + --> $DIR/const-eval-overflow2.rs:64:5 | LL | foo(VALS_I16); //~ ERROR erroneous constant used | ^^^^^^^^^^^^^ referenced constant has errors error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2.rs:66:5 + --> $DIR/const-eval-overflow2.rs:65:5 | LL | foo(VALS_I32); //~ ERROR erroneous constant used | ^^^^^^^^^^^^^ referenced constant has errors error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2.rs:67:5 + --> $DIR/const-eval-overflow2.rs:66:5 | LL | foo(VALS_I64); //~ ERROR erroneous constant used | ^^^^^^^^^^^^^ referenced constant has errors error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2.rs:69:5 + --> $DIR/const-eval-overflow2.rs:68:5 | LL | foo(VALS_U8); //~ ERROR erroneous constant used | ^^^^^^^^^^^^ referenced constant has errors error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2.rs:70:5 + --> $DIR/const-eval-overflow2.rs:69:5 | LL | foo(VALS_U16); //~ ERROR erroneous constant used | ^^^^^^^^^^^^^ referenced constant has errors error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2.rs:71:5 + --> $DIR/const-eval-overflow2.rs:70:5 | LL | foo(VALS_U32); //~ ERROR erroneous constant used | ^^^^^^^^^^^^^ referenced constant has errors error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2.rs:72:5 + --> $DIR/const-eval-overflow2.rs:71:5 | LL | foo(VALS_U64); //~ ERROR erroneous constant used | ^^^^^^^^^^^^^ referenced constant has errors -error: aborting due to 17 previous errors +error: aborting due to 16 previous errors For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-eval/const-eval-overflow2b.rs b/src/test/ui/consts/const-eval/const-eval-overflow2b.rs index 55dc2a894054a..47b0977ec1d55 100644 --- a/src/test/ui/consts/const-eval/const-eval-overflow2b.rs +++ b/src/test/ui/consts/const-eval/const-eval-overflow2b.rs @@ -22,7 +22,6 @@ use std::{i8, i16, i32, i64, isize}; use std::{u8, u16, u32, u64, usize}; const VALS_I8: (i8,) = //~ ERROR any use of this value will cause an error - //~^ const_err ( i8::MAX + 1, ); diff --git a/src/test/ui/consts/const-eval/const-eval-overflow2b.stderr b/src/test/ui/consts/const-eval/const-eval-overflow2b.stderr index 3b78fb51a623a..8922b35a0b22f 100644 --- a/src/test/ui/consts/const-eval/const-eval-overflow2b.stderr +++ b/src/test/ui/consts/const-eval/const-eval-overflow2b.stderr @@ -2,7 +2,6 @@ error: any use of this value will cause an error --> $DIR/const-eval-overflow2b.rs:24:1 | LL | / const VALS_I8: (i8,) = //~ ERROR any use of this value will cause an error -LL | | //~^ const_err LL | | ( LL | | i8::MAX + 1, | | ----------- attempt to add with overflow @@ -16,7 +15,7 @@ LL | #![deny(const_err)] | ^^^^^^^^^ error: any use of this value will cause an error - --> $DIR/const-eval-overflow2b.rs:30:1 + --> $DIR/const-eval-overflow2b.rs:29:1 | LL | / const VALS_I16: (i16,) = //~ ERROR any use of this value will cause an error LL | | ( @@ -26,7 +25,7 @@ LL | | ); | |_______^ error: any use of this value will cause an error - --> $DIR/const-eval-overflow2b.rs:35:1 + --> $DIR/const-eval-overflow2b.rs:34:1 | LL | / const VALS_I32: (i32,) = //~ ERROR any use of this value will cause an error LL | | ( @@ -36,7 +35,7 @@ LL | | ); | |_______^ error: any use of this value will cause an error - --> $DIR/const-eval-overflow2b.rs:40:1 + --> $DIR/const-eval-overflow2b.rs:39:1 | LL | / const VALS_I64: (i64,) = //~ ERROR any use of this value will cause an error LL | | ( @@ -46,7 +45,7 @@ LL | | ); | |_______^ error: any use of this value will cause an error - --> $DIR/const-eval-overflow2b.rs:45:1 + --> $DIR/const-eval-overflow2b.rs:44:1 | LL | / const VALS_U8: (u8,) = //~ ERROR any use of this value will cause an error LL | | ( @@ -56,7 +55,7 @@ LL | | ); | |_______^ error: any use of this value will cause an error - --> $DIR/const-eval-overflow2b.rs:50:1 + --> $DIR/const-eval-overflow2b.rs:49:1 | LL | / const VALS_U16: (u16,) = ( //~ ERROR any use of this value will cause an error LL | | u16::MAX + 1, @@ -65,7 +64,7 @@ LL | | ); | |_______^ error: any use of this value will cause an error - --> $DIR/const-eval-overflow2b.rs:54:1 + --> $DIR/const-eval-overflow2b.rs:53:1 | LL | / const VALS_U32: (u32,) = ( //~ ERROR any use of this value will cause an error LL | | u32::MAX + 1, @@ -74,7 +73,7 @@ LL | | ); | |_______^ error: any use of this value will cause an error - --> $DIR/const-eval-overflow2b.rs:58:1 + --> $DIR/const-eval-overflow2b.rs:57:1 | LL | / const VALS_U64: (u64,) = //~ ERROR any use of this value will cause an error LL | | ( @@ -83,65 +82,54 @@ LL | | u64::MAX + 1, LL | | ); | |_______^ -error: any use of this value will cause an error - --> $DIR/const-eval-overflow2b.rs:24:1 - | -LL | / const VALS_I8: (i8,) = //~ ERROR any use of this value will cause an error -LL | | //~^ const_err -LL | | ( -LL | | i8::MAX + 1, - | | ----------- attempt to add with overflow -LL | | ); - | |_______^ - error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2b.rs:64:5 + --> $DIR/const-eval-overflow2b.rs:63:5 | LL | foo(VALS_I8); //~ ERROR erroneous constant used | ^^^^^^^^^^^^ referenced constant has errors error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2b.rs:65:5 + --> $DIR/const-eval-overflow2b.rs:64:5 | LL | foo(VALS_I16); //~ ERROR erroneous constant used | ^^^^^^^^^^^^^ referenced constant has errors error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2b.rs:66:5 + --> $DIR/const-eval-overflow2b.rs:65:5 | LL | foo(VALS_I32); //~ ERROR erroneous constant used | ^^^^^^^^^^^^^ referenced constant has errors error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2b.rs:67:5 + --> $DIR/const-eval-overflow2b.rs:66:5 | LL | foo(VALS_I64); //~ ERROR erroneous constant used | ^^^^^^^^^^^^^ referenced constant has errors error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2b.rs:69:5 + --> $DIR/const-eval-overflow2b.rs:68:5 | LL | foo(VALS_U8); //~ ERROR erroneous constant used | ^^^^^^^^^^^^ referenced constant has errors error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2b.rs:70:5 + --> $DIR/const-eval-overflow2b.rs:69:5 | LL | foo(VALS_U16); //~ ERROR erroneous constant used | ^^^^^^^^^^^^^ referenced constant has errors error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2b.rs:71:5 + --> $DIR/const-eval-overflow2b.rs:70:5 | LL | foo(VALS_U32); //~ ERROR erroneous constant used | ^^^^^^^^^^^^^ referenced constant has errors error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2b.rs:72:5 + --> $DIR/const-eval-overflow2b.rs:71:5 | LL | foo(VALS_U64); //~ ERROR erroneous constant used | ^^^^^^^^^^^^^ referenced constant has errors -error: aborting due to 17 previous errors +error: aborting due to 16 previous errors For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-eval/const-eval-overflow2c.rs b/src/test/ui/consts/const-eval/const-eval-overflow2c.rs index 93ba11efc5998..b4e1a0bc099af 100644 --- a/src/test/ui/consts/const-eval/const-eval-overflow2c.rs +++ b/src/test/ui/consts/const-eval/const-eval-overflow2c.rs @@ -22,7 +22,6 @@ use std::{i8, i16, i32, i64, isize}; use std::{u8, u16, u32, u64, usize}; const VALS_I8: (i8,) = //~ ERROR any use of this value will cause an error - //~^ const_err ( i8::MIN * 2, ); diff --git a/src/test/ui/consts/const-eval/const-eval-overflow2c.stderr b/src/test/ui/consts/const-eval/const-eval-overflow2c.stderr index abaae4bd54227..023156a40dd6d 100644 --- a/src/test/ui/consts/const-eval/const-eval-overflow2c.stderr +++ b/src/test/ui/consts/const-eval/const-eval-overflow2c.stderr @@ -2,7 +2,6 @@ error: any use of this value will cause an error --> $DIR/const-eval-overflow2c.rs:24:1 | LL | / const VALS_I8: (i8,) = //~ ERROR any use of this value will cause an error -LL | | //~^ const_err LL | | ( LL | | i8::MIN * 2, | | ----------- attempt to multiply with overflow @@ -16,7 +15,7 @@ LL | #![deny(const_err)] | ^^^^^^^^^ error: any use of this value will cause an error - --> $DIR/const-eval-overflow2c.rs:30:1 + --> $DIR/const-eval-overflow2c.rs:29:1 | LL | / const VALS_I16: (i16,) = //~ ERROR any use of this value will cause an error LL | | ( @@ -26,7 +25,7 @@ LL | | ); | |_______^ error: any use of this value will cause an error - --> $DIR/const-eval-overflow2c.rs:35:1 + --> $DIR/const-eval-overflow2c.rs:34:1 | LL | / const VALS_I32: (i32,) = //~ ERROR any use of this value will cause an error LL | | ( @@ -36,7 +35,7 @@ LL | | ); | |_______^ error: any use of this value will cause an error - --> $DIR/const-eval-overflow2c.rs:40:1 + --> $DIR/const-eval-overflow2c.rs:39:1 | LL | / const VALS_I64: (i64,) = //~ ERROR any use of this value will cause an error LL | | ( @@ -46,7 +45,7 @@ LL | | ); | |_______^ error: any use of this value will cause an error - --> $DIR/const-eval-overflow2c.rs:45:1 + --> $DIR/const-eval-overflow2c.rs:44:1 | LL | / const VALS_U8: (u8,) = //~ ERROR any use of this value will cause an error LL | | ( @@ -56,7 +55,7 @@ LL | | ); | |_______^ error: any use of this value will cause an error - --> $DIR/const-eval-overflow2c.rs:50:1 + --> $DIR/const-eval-overflow2c.rs:49:1 | LL | / const VALS_U16: (u16,) = ( //~ ERROR any use of this value will cause an error LL | | u16::MAX * 2, @@ -65,7 +64,7 @@ LL | | ); | |_______^ error: any use of this value will cause an error - --> $DIR/const-eval-overflow2c.rs:54:1 + --> $DIR/const-eval-overflow2c.rs:53:1 | LL | / const VALS_U32: (u32,) = ( //~ ERROR any use of this value will cause an error LL | | u32::MAX * 2, @@ -74,7 +73,7 @@ LL | | ); | |_______^ error: any use of this value will cause an error - --> $DIR/const-eval-overflow2c.rs:58:1 + --> $DIR/const-eval-overflow2c.rs:57:1 | LL | / const VALS_U64: (u64,) = //~ ERROR any use of this value will cause an error LL | | ( @@ -83,65 +82,54 @@ LL | | u64::MAX * 2, LL | | ); | |_______^ -error: any use of this value will cause an error - --> $DIR/const-eval-overflow2c.rs:24:1 - | -LL | / const VALS_I8: (i8,) = //~ ERROR any use of this value will cause an error -LL | | //~^ const_err -LL | | ( -LL | | i8::MIN * 2, - | | ----------- attempt to multiply with overflow -LL | | ); - | |_______^ - error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2c.rs:64:5 + --> $DIR/const-eval-overflow2c.rs:63:5 | LL | foo(VALS_I8); //~ ERROR erroneous constant used | ^^^^^^^^^^^^ referenced constant has errors error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2c.rs:65:5 + --> $DIR/const-eval-overflow2c.rs:64:5 | LL | foo(VALS_I16); //~ ERROR erroneous constant used | ^^^^^^^^^^^^^ referenced constant has errors error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2c.rs:66:5 + --> $DIR/const-eval-overflow2c.rs:65:5 | LL | foo(VALS_I32); //~ ERROR erroneous constant used | ^^^^^^^^^^^^^ referenced constant has errors error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2c.rs:67:5 + --> $DIR/const-eval-overflow2c.rs:66:5 | LL | foo(VALS_I64); //~ ERROR erroneous constant used | ^^^^^^^^^^^^^ referenced constant has errors error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2c.rs:69:5 + --> $DIR/const-eval-overflow2c.rs:68:5 | LL | foo(VALS_U8); //~ ERROR erroneous constant used | ^^^^^^^^^^^^ referenced constant has errors error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2c.rs:70:5 + --> $DIR/const-eval-overflow2c.rs:69:5 | LL | foo(VALS_U16); //~ ERROR erroneous constant used | ^^^^^^^^^^^^^ referenced constant has errors error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2c.rs:71:5 + --> $DIR/const-eval-overflow2c.rs:70:5 | LL | foo(VALS_U32); //~ ERROR erroneous constant used | ^^^^^^^^^^^^^ referenced constant has errors error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2c.rs:72:5 + --> $DIR/const-eval-overflow2c.rs:71:5 | LL | foo(VALS_U64); //~ ERROR erroneous constant used | ^^^^^^^^^^^^^ referenced constant has errors -error: aborting due to 17 previous errors +error: aborting due to 16 previous errors For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-eval/transmute-const.stderr b/src/test/ui/consts/const-eval/transmute-const.stderr index c9beca7aa30ac..91faa4684c392 100644 --- a/src/test/ui/consts/const-eval/transmute-const.stderr +++ b/src/test/ui/consts/const-eval/transmute-const.stderr @@ -1,4 +1,4 @@ -error[E0080]: this static likely exhibits undefined behavior +error[E0080]: it is undefined behavior to use this value --> $DIR/transmute-const.rs:15:1 | LL | static FOO: bool = unsafe { mem::transmute(3u8) }; diff --git a/src/test/ui/consts/const-eval/union-const-eval-field.rs b/src/test/ui/consts/const-eval/union-const-eval-field.rs index 40d1f97a80757..759dab6c25661 100644 --- a/src/test/ui/consts/const-eval/union-const-eval-field.rs +++ b/src/test/ui/consts/const-eval/union-const-eval-field.rs @@ -35,7 +35,6 @@ const fn read_field2() -> Field2 { const fn read_field3() -> Field3 { const FIELD3: Field3 = unsafe { UNION.field3 }; //~ ERROR any use of this value - //~^ ERROR any use of this value FIELD3 //~^ erroneous constant used } diff --git a/src/test/ui/consts/const-eval/union-const-eval-field.stderr b/src/test/ui/consts/const-eval/union-const-eval-field.stderr index 39320791a3fd0..6a64f0c36716f 100644 --- a/src/test/ui/consts/const-eval/union-const-eval-field.stderr +++ b/src/test/ui/consts/const-eval/union-const-eval-field.stderr @@ -6,20 +6,14 @@ LL | const FIELD3: Field3 = unsafe { UNION.field3 }; //~ ERROR any use of th | = note: #[deny(const_err)] on by default -error: any use of this value will cause an error - --> $DIR/union-const-eval-field.rs:37:5 - | -LL | const FIELD3: Field3 = unsafe { UNION.field3 }; //~ ERROR any use of this value - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempted to read undefined bytes - error[E0080]: erroneous constant used - --> $DIR/union-const-eval-field.rs:39:5 + --> $DIR/union-const-eval-field.rs:38:5 | LL | FIELD3 | ^^^^^^ referenced constant has errors error[E0080]: evaluation of constant expression failed - --> $DIR/union-const-eval-field.rs:46:5 + --> $DIR/union-const-eval-field.rs:45:5 | LL | FIELD3 | ------ referenced constant has errors @@ -31,6 +25,6 @@ LL | assert_eq!(read_field3(), unsafe { UNION.field3 }); | = 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 +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-size_of-cycle.stderr b/src/test/ui/consts/const-size_of-cycle.stderr index ea5d7c176ffb9..0c8fdfb6da293 100644 --- a/src/test/ui/consts/const-size_of-cycle.stderr +++ b/src/test/ui/consts/const-size_of-cycle.stderr @@ -1,22 +1,27 @@ -error[E0391]: cycle detected when computing layout of `Foo` - | -note: ...which requires normalizing `ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: All }, value: [u8; _] }`... -note: ...which requires const-evaluating + checking `Foo::bytes::{{constant}}`... +error[E0391]: cycle detected when const-evaluating + checking `Foo::bytes::{{constant}}` --> $DIR/const-size_of-cycle.rs:16:17 | LL | bytes: [u8; std::mem::size_of::()] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | note: ...which requires const-evaluating `Foo::bytes::{{constant}}`... --> $SRC_DIR/libcore/mem.rs:LL:COL | -LL | intrinsics::size_of::() - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: ...which again requires computing layout of `Foo`, completing the cycle -note: cycle used when const-evaluating `Foo::bytes::{{constant}}` - --> $SRC_DIR/libcore/mem.rs:LL:COL +LL | unsafe { intrinsics::size_of::() } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ +note: ...which requires computing layout of `Foo`... +note: ...which requires normalizing `ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: All }, value: [u8; _] }`... +note: ...which requires const-evaluating + checking `Foo::bytes::{{constant}}`... + --> $DIR/const-size_of-cycle.rs:16:17 + | +LL | bytes: [u8; std::mem::size_of::()] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: ...which again requires const-evaluating + checking `Foo::bytes::{{constant}}`, completing the cycle +note: cycle used when processing `Foo` + --> $DIR/const-size_of-cycle.rs:15:1 | -LL | intrinsics::size_of::() - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | struct Foo { + | ^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/consts/const-slice-oob.rs b/src/test/ui/consts/const-slice-oob.rs index b71556735d9f6..cc7f86f97a1fd 100644 --- a/src/test/ui/consts/const-slice-oob.rs +++ b/src/test/ui/consts/const-slice-oob.rs @@ -14,7 +14,6 @@ const FOO: &'static[u32] = &[1, 2, 3]; const BAR: u32 = FOO[5]; //~^ index out of bounds: the len is 3 but the index is 5 //~| ERROR any use of this value will cause an error -//~| ERROR any use of this value will cause an error fn main() { let _ = BAR; diff --git a/src/test/ui/consts/const-slice-oob.stderr b/src/test/ui/consts/const-slice-oob.stderr index 8fd298a18d22c..763afae62eaac 100644 --- a/src/test/ui/consts/const-slice-oob.stderr +++ b/src/test/ui/consts/const-slice-oob.stderr @@ -8,20 +8,12 @@ LL | const BAR: u32 = FOO[5]; | = note: #[deny(const_err)] on by default -error: any use of this value will cause an error - --> $DIR/const-slice-oob.rs:14:1 - | -LL | const BAR: u32 = FOO[5]; - | ^^^^^^^^^^^^^^^^^------^ - | | - | index out of bounds: the len is 3 but the index is 5 - error[E0080]: erroneous constant used - --> $DIR/const-slice-oob.rs:20:13 + --> $DIR/const-slice-oob.rs:19:13 | LL | let _ = BAR; | ^^^ referenced constant has errors -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/issues/issue-44415.rs b/src/test/ui/issues/issue-44415.rs index bd50f93945c51..6d55422dea079 100644 --- a/src/test/ui/issues/issue-44415.rs +++ b/src/test/ui/issues/issue-44415.rs @@ -8,15 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//~^^^^^^^^^^ ERROR cycle detected when computing layout of - - #![feature(core_intrinsics)] use std::intrinsics; struct Foo { bytes: [u8; unsafe { intrinsics::size_of::() }], + //~^ ERROR cycle detected when const-evaluating + checking x: usize, } diff --git a/src/test/ui/issues/issue-44415.stderr b/src/test/ui/issues/issue-44415.stderr index f20c2c733591b..4345a5dbf43f0 100644 --- a/src/test/ui/issues/issue-44415.stderr +++ b/src/test/ui/issues/issue-44415.stderr @@ -1,22 +1,27 @@ -error[E0391]: cycle detected when computing layout of `Foo` - | -note: ...which requires normalizing `ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: All }, value: [u8; _] }`... -note: ...which requires const-evaluating + checking `Foo::bytes::{{constant}}`... - --> $DIR/issue-44415.rs:19:17 +error[E0391]: cycle detected when const-evaluating + checking `Foo::bytes::{{constant}}` + --> $DIR/issue-44415.rs:17:17 | LL | bytes: [u8; unsafe { intrinsics::size_of::() }], | ^^^^^^ + | note: ...which requires const-evaluating `Foo::bytes::{{constant}}`... - --> $DIR/issue-44415.rs:19:26 + --> $DIR/issue-44415.rs:17:26 | LL | bytes: [u8; unsafe { intrinsics::size_of::() }], | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: ...which again requires computing layout of `Foo`, completing the cycle -note: cycle used when const-evaluating `Foo::bytes::{{constant}}` - --> $DIR/issue-44415.rs:19:26 +note: ...which requires computing layout of `Foo`... +note: ...which requires normalizing `ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: All }, value: [u8; _] }`... +note: ...which requires const-evaluating + checking `Foo::bytes::{{constant}}`... + --> $DIR/issue-44415.rs:17:17 | LL | bytes: [u8; unsafe { intrinsics::size_of::() }], - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^ + = note: ...which again requires const-evaluating + checking `Foo::bytes::{{constant}}`, completing the cycle +note: cycle used when processing `Foo` + --> $DIR/issue-44415.rs:16:1 + | +LL | struct Foo { + | ^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/recursion/recursive-static-definition.stderr b/src/test/ui/recursion/recursive-static-definition.stderr index 5bd0f90afbcae..c9a5e5eb44762 100644 --- a/src/test/ui/recursion/recursive-static-definition.stderr +++ b/src/test/ui/recursion/recursive-static-definition.stderr @@ -4,6 +4,11 @@ error[E0391]: cycle detected when const-evaluating `FOO` LL | pub static FOO: u32 = FOO; | ^^^ | +note: ...which requires const-evaluating `FOO`... + --> $DIR/recursive-static-definition.rs:11:1 + | +LL | pub static FOO: u32 = FOO; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: ...which again requires const-evaluating `FOO`, completing the cycle note: cycle used when const-evaluating + checking `FOO` --> $DIR/recursive-static-definition.rs:11:1 From 73e2b4662d32f517f8cb874e45f48c2a05a81456 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Fri, 31 Aug 2018 13:46:51 +0200 Subject: [PATCH 06/21] Prepare miri for unsized locals --- src/librustc_mir/interpret/place.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs index a4bb15662d8b2..b7bc4867307fb 100644 --- a/src/librustc_mir/interpret/place.rs +++ b/src/librustc_mir/interpret/place.rs @@ -880,9 +880,16 @@ where layout: TyLayout<'tcx>, kind: MemoryKind, ) -> EvalResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> { - assert!(!layout.is_unsized(), "cannot alloc memory for unsized type"); - let ptr = self.memory.allocate(layout.size, layout.align, kind)?; - Ok(MPlaceTy::from_aligned_ptr(ptr, layout)) + if layout.is_unsized() { + assert!(self.tcx.features().unsized_locals, "cannot alloc memory for unsized type"); + // allocate a fat pointer slot instead + let fat = self.tcx.mk_mut_ptr(layout.ty); + let fat = self.layout_of(fat)?; + self.allocate(fat, kind) + } else { + let ptr = self.memory.allocate(layout.size, layout.align, kind)?; + Ok(MPlaceTy::from_aligned_ptr(ptr, layout)) + } } pub fn write_discriminant_index( From b4ee38ede3d6a3418103336cecdb8bd08db8e5ab Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Fri, 31 Aug 2018 14:30:59 +0200 Subject: [PATCH 07/21] Don't extend `hir::Def` when there's already a dedicated "function-like" detector --- src/librustc/hir/def.rs | 3 --- src/librustc/hir/map/blocks.rs | 2 +- src/librustc/hir/map/mod.rs | 7 +----- src/librustc/ich/impls_hir.rs | 1 - src/librustc_mir/transform/const_prop.rs | 27 ++++++++++++++---------- src/librustc_save_analysis/lib.rs | 1 - 6 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/librustc/hir/def.rs b/src/librustc/hir/def.rs index 72a45ebd8e4c0..5d9d4deb0abc9 100644 --- a/src/librustc/hir/def.rs +++ b/src/librustc/hir/def.rs @@ -74,7 +74,6 @@ pub enum Def { SelfCtor(DefId /* impl */), // DefId refers to the impl Method(DefId), AssociatedConst(DefId), - Closure(hir::BodyId), Local(ast::NodeId), Upvar(ast::NodeId, // node id of closed over local @@ -282,7 +281,6 @@ impl Def { id } - Def::Closure(_) | Def::Local(..) | Def::Upvar(..) | Def::Label(..) | @@ -321,7 +319,6 @@ impl Def { Def::Trait(..) => "trait", Def::ForeignTy(..) => "foreign type", Def::Method(..) => "method", - Def::Closure(_) => "closure", Def::Const(..) => "constant", Def::AssociatedConst(..) => "associated constant", Def::TyParam(..) => "type parameter", diff --git a/src/librustc/hir/map/blocks.rs b/src/librustc/hir/map/blocks.rs index 69706aabcb050..1ab1c7d3fc5c4 100644 --- a/src/librustc/hir/map/blocks.rs +++ b/src/librustc/hir/map/blocks.rs @@ -43,7 +43,7 @@ pub struct FnLikeNode<'a> { node: Node<'a> } /// MaybeFnLike wraps a method that indicates if an object /// corresponds to some FnLikeNode. -pub trait MaybeFnLike { fn is_fn_like(&self) -> bool; } +trait MaybeFnLike { fn is_fn_like(&self) -> bool; } impl MaybeFnLike for ast::Item { fn is_fn_like(&self) -> bool { diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index d36268cfe3a4f..f5f9bcd3b5ea5 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -340,14 +340,9 @@ impl<'hir> Map<'hir> { let def_id = self.local_def_id(variant.node.data.id()); Some(Def::Variant(def_id)) } - Node::Expr(expr) => { - match expr.node { - ExprKind::Closure(_, _, body_id, _, _) => Some(Def::Closure(body_id)), - _ => None, - } - } Node::Field(_) | Node::AnonConst(_) | + Node::Expr(_) | Node::Stmt(_) | Node::Ty(_) | Node::TraitRef(_) | diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index 4b64591029c3f..a48bd4eeb09a3 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -1044,7 +1044,6 @@ impl_stable_hash_for!(enum hir::def::Def { SelfCtor(impl_def_id), VariantCtor(def_id, ctor_kind), Method(def_id), - Closure(body_id), AssociatedConst(def_id), Local(def_id), Upvar(def_id, index, expr_id), diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 6da40aa4a116b..6291d8cc80cb3 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -44,19 +44,24 @@ impl MirPass for ConstProp { if source.promoted.is_some() { return; } - match tcx.describe_def(source.def_id) { - // Only run const prop on functions, methods, closures and associated constants - | Some(Def::Fn(_)) - | Some(Def::Method(_)) - | Some(Def::AssociatedConst(_)) - | Some(Def::Closure(_)) - => {} + + use rustc::hir::map::blocks::FnLikeNode; + let node_id = tcx.hir.as_local_node_id(source.def_id) + .expect("Non-local call to local provider is_const_fn"); + + let is_fn_like = FnLikeNode::from_node(tcx.hir.get(node_id)).is_some(); + let is_assoc_const = match tcx.describe_def(source.def_id) { + Some(Def::AssociatedConst(_)) => true, + _ => false, + }; + + // Only run const prop on functions, methods, closures and associated constants + if !is_fn_like && !is_assoc_const { // skip anon_const/statics/consts because they'll be evaluated by miri anyway - def => { - trace!("ConstProp skipped for {:?} ({:?})", source.def_id, def); - return - }, + trace!("ConstProp skipped for {:?}", source.def_id); + return } + trace!("ConstProp starting for {:?}", source.def_id); // FIXME(oli-obk, eddyb) Optimize locals (or even local paths) to hold diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index cdd25b8aa7acc..4b43a1a6270f8 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -827,7 +827,6 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { ref_id: id_from_def_id(def_id), }) } - HirDef::Closure(_) | HirDef::PrimTy(..) | HirDef::SelfTy(..) | HirDef::Label(..) | From d736197bc2040d1b76e91567ae09f1eb35f3a28c Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 3 Sep 2018 17:09:24 +0200 Subject: [PATCH 08/21] Explain the `Reveal::UserFacing` deduplication trick --- src/librustc_mir/const_eval.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index 861d0b2f7e1ae..f105df304f459 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -577,6 +577,7 @@ pub fn const_eval_provider<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>, ) -> ::rustc::mir::interpret::ConstEvalResult<'tcx> { + // see comment in const_eval_provider for what we're doing here if key.param_env.reveal == Reveal::All { let mut key = key.clone(); key.param_env.reveal = Reveal::UserFacing; @@ -596,6 +597,12 @@ pub fn const_eval_raw_provider<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>, ) -> ::rustc::mir::interpret::ConstEvalResult<'tcx> { + // so we do a small trick here. We check whether we can evaluate the constant in the more + // restrictive `Reveal::UserFacing`, which most likely already was computed. In a large + // percentage of constants that will already have succeeded. Only associated constants of + // generic functions will fail due to not enough monomorphization information being available + + // in case we fail in the `UserFacing` variant, we just do the real computation. if key.param_env.reveal == Reveal::All { let mut key = key.clone(); key.param_env.reveal = Reveal::UserFacing; From e6f7f4af501f401be7b303b56416a2737498717b Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Tue, 4 Sep 2018 11:05:56 +0200 Subject: [PATCH 09/21] Document error/lint cases in const eval --- src/librustc_mir/const_eval.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index f105df304f459..5cda7154774cd 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -649,8 +649,10 @@ pub fn const_eval_raw_provider<'a, 'tcx>( }).map_err(|error| { let stacktrace = ecx.generate_stacktrace(None); let err = ConstEvalErr { error, stacktrace, span: ecx.tcx.span }; + // errors in statics are always emitted as fatal errors if tcx.is_static(def_id).is_some() { let err = err.report_as_error(ecx.tcx, "could not evaluate static initializer"); + // check that a static never produces `TooGeneric` if tcx.sess.err_count() == 0 { span_bug!(ecx.tcx.span, "static eval failure didn't emit an error: {:#?}", err); } @@ -658,6 +660,8 @@ pub fn const_eval_raw_provider<'a, 'tcx>( } else if def_id.is_local() { // constant defined in this crate, we can figure out a lint level! match tcx.describe_def(def_id) { + // constants never produce a hard error at the definition site. Anything else is + // a backwards compatibility hazard (and will break old versions of winapi for sure) Some(Def::Const(_)) | Some(Def::AssociatedConst(_)) => { let node_id = tcx.hir.as_local_node_id(def_id).unwrap(); err.report_as_lint( @@ -666,6 +670,8 @@ pub fn const_eval_raw_provider<'a, 'tcx>( node_id, ) }, + // promoting runtime code is only allowed to error if it references broken constants + // any other kind of error will be reported to the user as a deny-by-default lint _ => if let Some(p) = cid.promoted { let span = tcx.optimized_mir(def_id).promoted[p].span; if let EvalErrorKind::ReferencedConstant = err.error.kind { @@ -680,6 +686,8 @@ pub fn const_eval_raw_provider<'a, 'tcx>( tcx.hir.as_local_node_id(def_id).unwrap(), ) } + // anything else (array lengths, enum initializers, constant patterns) are reported + // as hard errors } else { err.report_as_error( ecx.tcx, @@ -688,7 +696,7 @@ pub fn const_eval_raw_provider<'a, 'tcx>( }, } } else { - // use of constant from other crate + // use of broken constant from other crate err.report_as_error(ecx.tcx, "could not evaluate constant") } }) From 6a6b3309e63854cbd0f0e2a0b9bd305f6b96cf81 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Tue, 4 Sep 2018 12:26:21 +0200 Subject: [PATCH 10/21] update tests to changes on rustc master --- .../const-pointer-values-in-various-types.rs | 14 ++--- ...nst-pointer-values-in-various-types.stderr | 58 +++++++++---------- src/test/ui/consts/const-eval/issue-52442.rs | 1 + .../ui/consts/const-eval/issue-52442.stderr | 13 ++++- .../ui/consts/const-eval/ref_to_int_match.rs | 4 +- .../consts/const-eval/ref_to_int_match.stderr | 20 +++++-- src/test/ui/consts/const-size_of-cycle.stderr | 10 ++-- src/test/ui/issues/issue-44415.stderr | 8 +-- .../issue-52023-array-size-pointer-cast.rs | 1 + ...issue-52023-array-size-pointer-cast.stderr | 13 ++++- 10 files changed, 85 insertions(+), 57 deletions(-) diff --git a/src/test/ui/consts/const-eval/const-pointer-values-in-various-types.rs b/src/test/ui/consts/const-eval/const-pointer-values-in-various-types.rs index 05d79a7d63393..23e1ab013ef3e 100644 --- a/src/test/ui/consts/const-eval/const-pointer-values-in-various-types.rs +++ b/src/test/ui/consts/const-eval/const-pointer-values-in-various-types.rs @@ -22,7 +22,7 @@ union Nonsense { fn main() { const I32_REF_USIZE_UNION: usize = unsafe { Nonsense { int_32_ref: &3 }.u }; - //~^ ERROR this constant likely exhibits undefined behavior + //~^ ERROR it is undefined behavior to use this value const I32_REF_U8_UNION: u8 = unsafe { Nonsense { int_32_ref: &3 }.uint_8 }; //~^ ERROR any use of this value will cause an error @@ -34,7 +34,7 @@ fn main() { //~^ ERROR any use of this value will cause an error const I32_REF_U64_UNION: u64 = unsafe { Nonsense { int_32_ref: &3 }.uint_64 }; - //~^ ERROR this constant likely exhibits undefined behavior + //~^ ERROR it is undefined behavior to use this value const I32_REF_U128_UNION: u128 = unsafe { Nonsense { int_32_ref: &3 }.uint_128 }; //~^ ERROR any use of this value will cause an error @@ -49,7 +49,7 @@ fn main() { //~^ ERROR any use of this value will cause an error const I32_REF_I64_UNION: i64 = unsafe { Nonsense { int_32_ref: &3 }.int_64 }; - //~^ ERROR this constant likely exhibits undefined behavior + //~^ ERROR it is undefined behavior to use this value const I32_REF_I128_UNION: i128 = unsafe { Nonsense { int_32_ref: &3 }.int_128 }; //~^ ERROR any use of this value will cause an error @@ -58,7 +58,7 @@ fn main() { //~^ ERROR any use of this value will cause an error const I32_REF_F64_UNION: f64 = unsafe { Nonsense { int_32_ref: &3 }.float_64 }; - //~^ ERROR this constant likely exhibits undefined behavior + //~^ ERROR it is undefined behavior to use this value const I32_REF_BOOL_UNION: bool = unsafe { Nonsense { int_32_ref: &3 }.truthy_falsey }; //~^ ERROR any use of this value will cause an error @@ -76,7 +76,7 @@ fn main() { //~^ ERROR any use of this value will cause an error const STR_U64_UNION: u64 = unsafe { Nonsense { stringy: "3" }.uint_64 }; - //~^ ERROR this constant likely exhibits undefined behavior + //~^ ERROR it is undefined behavior to use this value const STR_U128_UNION: u128 = unsafe { Nonsense { stringy: "3" }.uint_128 }; //~^ ERROR any use of this value will cause an error @@ -91,7 +91,7 @@ fn main() { //~^ ERROR any use of this value will cause an error const STR_I64_UNION: i64 = unsafe { Nonsense { stringy: "3" }.int_64 }; - //~^ ERROR this constant likely exhibits undefined behavior + //~^ ERROR it is undefined behavior to use this value const STR_I128_UNION: i128 = unsafe { Nonsense { stringy: "3" }.int_128 }; //~^ ERROR any use of this value will cause an error @@ -100,7 +100,7 @@ fn main() { //~^ ERROR any use of this value will cause an error const STR_F64_UNION: f64 = unsafe { Nonsense { stringy: "3" }.float_64 }; - //~^ ERROR this constant likely exhibits undefined behavior + //~^ ERROR it is undefined behavior to use this value const STR_BOOL_UNION: bool = unsafe { Nonsense { stringy: "3" }.truthy_falsey }; //~^ ERROR any use of this value will cause an error diff --git a/src/test/ui/consts/const-eval/const-pointer-values-in-various-types.stderr b/src/test/ui/consts/const-eval/const-pointer-values-in-various-types.stderr index 7be9345b6b423..cc1db5db6915c 100644 --- a/src/test/ui/consts/const-eval/const-pointer-values-in-various-types.stderr +++ b/src/test/ui/consts/const-eval/const-pointer-values-in-various-types.stderr @@ -1,4 +1,4 @@ -error[E0080]: this constant likely exhibits undefined behavior +error[E0080]: it is undefined behavior to use this value --> $DIR/const-pointer-values-in-various-types.rs:24:5 | LL | const I32_REF_USIZE_UNION: usize = unsafe { Nonsense { int_32_ref: &3 }.u }; @@ -6,7 +6,7 @@ LL | const I32_REF_USIZE_UNION: usize = unsafe { Nonsense { int_32_ref: &3 } | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const-pointer-values-in-various-types.rs:27:5 | LL | const I32_REF_U8_UNION: u8 = unsafe { Nonsense { int_32_ref: &3 }.uint_8 }; @@ -16,7 +16,7 @@ LL | const I32_REF_U8_UNION: u8 = unsafe { Nonsense { int_32_ref: &3 }.uint_ | = note: #[deny(const_err)] on by default -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const-pointer-values-in-various-types.rs:30:5 | LL | const I32_REF_U16_UNION: u16 = unsafe { Nonsense { int_32_ref: &3 }.uint_16 }; @@ -24,7 +24,7 @@ LL | const I32_REF_U16_UNION: u16 = unsafe { Nonsense { int_32_ref: &3 }.uin | | | a raw memory access tried to access part of a pointer value as raw bytes -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const-pointer-values-in-various-types.rs:33:5 | LL | const I32_REF_U32_UNION: u32 = unsafe { Nonsense { int_32_ref: &3 }.uint_32 }; @@ -32,7 +32,7 @@ LL | const I32_REF_U32_UNION: u32 = unsafe { Nonsense { int_32_ref: &3 }.uin | | | a raw memory access tried to access part of a pointer value as raw bytes -error[E0080]: this constant likely exhibits undefined behavior +error[E0080]: it is undefined behavior to use this value --> $DIR/const-pointer-values-in-various-types.rs:36:5 | LL | const I32_REF_U64_UNION: u64 = unsafe { Nonsense { int_32_ref: &3 }.uint_64 }; @@ -40,13 +40,13 @@ LL | const I32_REF_U64_UNION: u64 = unsafe { Nonsense { int_32_ref: &3 }.uin | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const-pointer-values-in-various-types.rs:39:5 | LL | const I32_REF_U128_UNION: u128 = unsafe { Nonsense { int_32_ref: &3 }.uint_128 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempted to read undefined bytes -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const-pointer-values-in-various-types.rs:42:5 | LL | const I32_REF_I8_UNION: i8 = unsafe { Nonsense { int_32_ref: &3 }.int_8 }; @@ -54,7 +54,7 @@ LL | const I32_REF_I8_UNION: i8 = unsafe { Nonsense { int_32_ref: &3 }.int_8 | | | a raw memory access tried to access part of a pointer value as raw bytes -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const-pointer-values-in-various-types.rs:45:5 | LL | const I32_REF_I16_UNION: i16 = unsafe { Nonsense { int_32_ref: &3 }.int_16 }; @@ -62,7 +62,7 @@ LL | const I32_REF_I16_UNION: i16 = unsafe { Nonsense { int_32_ref: &3 }.int | | | a raw memory access tried to access part of a pointer value as raw bytes -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const-pointer-values-in-various-types.rs:48:5 | LL | const I32_REF_I32_UNION: i32 = unsafe { Nonsense { int_32_ref: &3 }.int_32 }; @@ -70,7 +70,7 @@ LL | const I32_REF_I32_UNION: i32 = unsafe { Nonsense { int_32_ref: &3 }.int | | | a raw memory access tried to access part of a pointer value as raw bytes -error[E0080]: this constant likely exhibits undefined behavior +error[E0080]: it is undefined behavior to use this value --> $DIR/const-pointer-values-in-various-types.rs:51:5 | LL | const I32_REF_I64_UNION: i64 = unsafe { Nonsense { int_32_ref: &3 }.int_64 }; @@ -78,13 +78,13 @@ LL | const I32_REF_I64_UNION: i64 = unsafe { Nonsense { int_32_ref: &3 }.int | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const-pointer-values-in-various-types.rs:54:5 | LL | const I32_REF_I128_UNION: i128 = unsafe { Nonsense { int_32_ref: &3 }.int_128 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempted to read undefined bytes -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const-pointer-values-in-various-types.rs:57:5 | LL | const I32_REF_F32_UNION: f32 = unsafe { Nonsense { int_32_ref: &3 }.float_32 }; @@ -92,7 +92,7 @@ LL | const I32_REF_F32_UNION: f32 = unsafe { Nonsense { int_32_ref: &3 }.flo | | | a raw memory access tried to access part of a pointer value as raw bytes -error[E0080]: this constant likely exhibits undefined behavior +error[E0080]: it is undefined behavior to use this value --> $DIR/const-pointer-values-in-various-types.rs:60:5 | LL | const I32_REF_F64_UNION: f64 = unsafe { Nonsense { int_32_ref: &3 }.float_64 }; @@ -100,7 +100,7 @@ LL | const I32_REF_F64_UNION: f64 = unsafe { Nonsense { int_32_ref: &3 }.flo | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const-pointer-values-in-various-types.rs:63:5 | LL | const I32_REF_BOOL_UNION: bool = unsafe { Nonsense { int_32_ref: &3 }.truthy_falsey }; @@ -108,7 +108,7 @@ LL | const I32_REF_BOOL_UNION: bool = unsafe { Nonsense { int_32_ref: &3 }.t | | | a raw memory access tried to access part of a pointer value as raw bytes -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const-pointer-values-in-various-types.rs:66:5 | LL | const I32_REF_CHAR_UNION: char = unsafe { Nonsense { int_32_ref: &3 }.character }; @@ -116,7 +116,7 @@ LL | const I32_REF_CHAR_UNION: char = unsafe { Nonsense { int_32_ref: &3 }.c | | | a raw memory access tried to access part of a pointer value as raw bytes -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const-pointer-values-in-various-types.rs:69:5 | LL | const STR_U8_UNION: u8 = unsafe { Nonsense { stringy: "3" }.uint_8 }; @@ -124,7 +124,7 @@ LL | const STR_U8_UNION: u8 = unsafe { Nonsense { stringy: "3" }.uint_8 }; | | | a raw memory access tried to access part of a pointer value as raw bytes -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const-pointer-values-in-various-types.rs:72:5 | LL | const STR_U16_UNION: u16 = unsafe { Nonsense { stringy: "3" }.uint_16 }; @@ -132,7 +132,7 @@ LL | const STR_U16_UNION: u16 = unsafe { Nonsense { stringy: "3" }.uint_16 } | | | a raw memory access tried to access part of a pointer value as raw bytes -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const-pointer-values-in-various-types.rs:75:5 | LL | const STR_U32_UNION: u32 = unsafe { Nonsense { stringy: "3" }.uint_32 }; @@ -140,7 +140,7 @@ LL | const STR_U32_UNION: u32 = unsafe { Nonsense { stringy: "3" }.uint_32 } | | | a raw memory access tried to access part of a pointer value as raw bytes -error[E0080]: this constant likely exhibits undefined behavior +error[E0080]: it is undefined behavior to use this value --> $DIR/const-pointer-values-in-various-types.rs:78:5 | LL | const STR_U64_UNION: u64 = unsafe { Nonsense { stringy: "3" }.uint_64 }; @@ -148,7 +148,7 @@ LL | const STR_U64_UNION: u64 = unsafe { Nonsense { stringy: "3" }.uint_64 } | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const-pointer-values-in-various-types.rs:81:5 | LL | const STR_U128_UNION: u128 = unsafe { Nonsense { stringy: "3" }.uint_128 }; @@ -156,7 +156,7 @@ LL | const STR_U128_UNION: u128 = unsafe { Nonsense { stringy: "3" }.uint_12 | | | a raw memory access tried to access part of a pointer value as raw bytes -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const-pointer-values-in-various-types.rs:84:5 | LL | const STR_I8_UNION: i8 = unsafe { Nonsense { stringy: "3" }.int_8 }; @@ -164,7 +164,7 @@ LL | const STR_I8_UNION: i8 = unsafe { Nonsense { stringy: "3" }.int_8 }; | | | a raw memory access tried to access part of a pointer value as raw bytes -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const-pointer-values-in-various-types.rs:87:5 | LL | const STR_I16_UNION: i16 = unsafe { Nonsense { stringy: "3" }.int_16 }; @@ -172,7 +172,7 @@ LL | const STR_I16_UNION: i16 = unsafe { Nonsense { stringy: "3" }.int_16 }; | | | a raw memory access tried to access part of a pointer value as raw bytes -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const-pointer-values-in-various-types.rs:90:5 | LL | const STR_I32_UNION: i32 = unsafe { Nonsense { stringy: "3" }.int_32 }; @@ -180,7 +180,7 @@ LL | const STR_I32_UNION: i32 = unsafe { Nonsense { stringy: "3" }.int_32 }; | | | a raw memory access tried to access part of a pointer value as raw bytes -error[E0080]: this constant likely exhibits undefined behavior +error[E0080]: it is undefined behavior to use this value --> $DIR/const-pointer-values-in-various-types.rs:93:5 | LL | const STR_I64_UNION: i64 = unsafe { Nonsense { stringy: "3" }.int_64 }; @@ -188,7 +188,7 @@ LL | const STR_I64_UNION: i64 = unsafe { Nonsense { stringy: "3" }.int_64 }; | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const-pointer-values-in-various-types.rs:96:5 | LL | const STR_I128_UNION: i128 = unsafe { Nonsense { stringy: "3" }.int_128 }; @@ -196,7 +196,7 @@ LL | const STR_I128_UNION: i128 = unsafe { Nonsense { stringy: "3" }.int_128 | | | a raw memory access tried to access part of a pointer value as raw bytes -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const-pointer-values-in-various-types.rs:99:5 | LL | const STR_F32_UNION: f32 = unsafe { Nonsense { stringy: "3" }.float_32 }; @@ -204,7 +204,7 @@ LL | const STR_F32_UNION: f32 = unsafe { Nonsense { stringy: "3" }.float_32 | | | a raw memory access tried to access part of a pointer value as raw bytes -error[E0080]: this constant likely exhibits undefined behavior +error[E0080]: it is undefined behavior to use this value --> $DIR/const-pointer-values-in-various-types.rs:102:5 | LL | const STR_F64_UNION: f64 = unsafe { Nonsense { stringy: "3" }.float_64 }; @@ -212,7 +212,7 @@ LL | const STR_F64_UNION: f64 = unsafe { Nonsense { stringy: "3" }.float_64 | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const-pointer-values-in-various-types.rs:105:5 | LL | const STR_BOOL_UNION: bool = unsafe { Nonsense { stringy: "3" }.truthy_falsey }; @@ -220,7 +220,7 @@ LL | const STR_BOOL_UNION: bool = unsafe { Nonsense { stringy: "3" }.truthy_ | | | a raw memory access tried to access part of a pointer value as raw bytes -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const-pointer-values-in-various-types.rs:108:5 | LL | const STR_CHAR_UNION: char = unsafe { Nonsense { stringy: "3" }.character }; diff --git a/src/test/ui/consts/const-eval/issue-52442.rs b/src/test/ui/consts/const-eval/issue-52442.rs index 755dc153d4052..8e207b712c35d 100644 --- a/src/test/ui/consts/const-eval/issue-52442.rs +++ b/src/test/ui/consts/const-eval/issue-52442.rs @@ -10,4 +10,5 @@ fn main() { [(); { &loop { break } as *const _ as usize } ]; //~ ERROR unimplemented expression type + //~^ ERROR it is undefined behavior to use this value } diff --git a/src/test/ui/consts/const-eval/issue-52442.stderr b/src/test/ui/consts/const-eval/issue-52442.stderr index 586c9fa22cecd..93fc4bea5caa9 100644 --- a/src/test/ui/consts/const-eval/issue-52442.stderr +++ b/src/test/ui/consts/const-eval/issue-52442.stderr @@ -4,6 +4,15 @@ error[E0019]: constant contains unimplemented expression type LL | [(); { &loop { break } as *const _ as usize } ]; //~ ERROR unimplemented expression type | ^^^^^^^^^^^^^^ -error: aborting due to previous error +error[E0080]: it is undefined behavior to use this value + --> $DIR/issue-52442.rs:12:11 + | +LL | [(); { &loop { break } as *const _ as usize } ]; //~ ERROR unimplemented expression type + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer, but expected the type usize + | + = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior + +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0019`. +Some errors occurred: E0019, E0080. +For more information about an error, try `rustc --explain E0019`. diff --git a/src/test/ui/consts/const-eval/ref_to_int_match.rs b/src/test/ui/consts/const-eval/ref_to_int_match.rs index cb942f465e40f..2254ed5d9e350 100644 --- a/src/test/ui/consts/const-eval/ref_to_int_match.rs +++ b/src/test/ui/consts/const-eval/ref_to_int_match.rs @@ -14,7 +14,7 @@ fn main() { let n: Int = 40; match n { 0..=10 => {}, - 10..=BAR => {}, //~ ERROR lower range bound must be less than or equal to upper + 10..=BAR => {}, //~ ERROR could not evaluate constant pattern _ => {}, } } @@ -30,4 +30,4 @@ type Int = u64; #[cfg(target_pointer_width="32")] type Int = u32; -const BAR: Int = unsafe { Foo { r: &42 }.f }; +const BAR: Int = unsafe { Foo { r: &42 }.f }; //~ ERROR it is undefined behavior to use this value diff --git a/src/test/ui/consts/const-eval/ref_to_int_match.stderr b/src/test/ui/consts/const-eval/ref_to_int_match.stderr index e82a16c066fdb..1e65a871de41f 100644 --- a/src/test/ui/consts/const-eval/ref_to_int_match.stderr +++ b/src/test/ui/consts/const-eval/ref_to_int_match.stderr @@ -1,9 +1,17 @@ -error[E0030]: lower range bound must be less than or equal to upper - --> $DIR/ref_to_int_match.rs:17:9 +error[E0080]: it is undefined behavior to use this value + --> $DIR/ref_to_int_match.rs:33:1 | -LL | 10..=BAR => {}, //~ ERROR lower range bound must be less than or equal to upper - | ^^ lower bound larger than upper bound +LL | const BAR: Int = unsafe { Foo { r: &42 }.f }; //~ ERROR it is undefined behavior to use this value + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer, but expected the type u64 + | + = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior + +error: could not evaluate constant pattern + --> $DIR/ref_to_int_match.rs:17:14 + | +LL | 10..=BAR => {}, //~ ERROR could not evaluate constant pattern + | ^^^ -error: aborting due to previous error +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0030`. +For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-size_of-cycle.stderr b/src/test/ui/consts/const-size_of-cycle.stderr index 0c8fdfb6da293..8e1e81f7735dc 100644 --- a/src/test/ui/consts/const-size_of-cycle.stderr +++ b/src/test/ui/consts/const-size_of-cycle.stderr @@ -1,5 +1,5 @@ error[E0391]: cycle detected when const-evaluating + checking `Foo::bytes::{{constant}}` - --> $DIR/const-size_of-cycle.rs:16:17 + --> $DIR/const-size_of-cycle.rs:14:17 | LL | bytes: [u8; std::mem::size_of::()] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -7,18 +7,18 @@ LL | bytes: [u8; std::mem::size_of::()] note: ...which requires const-evaluating `Foo::bytes::{{constant}}`... --> $SRC_DIR/libcore/mem.rs:LL:COL | -LL | unsafe { intrinsics::size_of::() } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | intrinsics::size_of::() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...which requires computing layout of `Foo`... note: ...which requires normalizing `ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: All }, value: [u8; _] }`... note: ...which requires const-evaluating + checking `Foo::bytes::{{constant}}`... - --> $DIR/const-size_of-cycle.rs:16:17 + --> $DIR/const-size_of-cycle.rs:14:17 | LL | bytes: [u8; std::mem::size_of::()] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: ...which again requires const-evaluating + checking `Foo::bytes::{{constant}}`, completing the cycle note: cycle used when processing `Foo` - --> $DIR/const-size_of-cycle.rs:15:1 + --> $DIR/const-size_of-cycle.rs:13:1 | LL | struct Foo { | ^^^^^^^^^^ diff --git a/src/test/ui/issues/issue-44415.stderr b/src/test/ui/issues/issue-44415.stderr index 4345a5dbf43f0..e70dfe7ad4e0a 100644 --- a/src/test/ui/issues/issue-44415.stderr +++ b/src/test/ui/issues/issue-44415.stderr @@ -1,24 +1,24 @@ error[E0391]: cycle detected when const-evaluating + checking `Foo::bytes::{{constant}}` - --> $DIR/issue-44415.rs:17:17 + --> $DIR/issue-44415.rs:16:17 | LL | bytes: [u8; unsafe { intrinsics::size_of::() }], | ^^^^^^ | note: ...which requires const-evaluating `Foo::bytes::{{constant}}`... - --> $DIR/issue-44415.rs:17:26 + --> $DIR/issue-44415.rs:16:26 | LL | bytes: [u8; unsafe { intrinsics::size_of::() }], | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...which requires computing layout of `Foo`... note: ...which requires normalizing `ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: All }, value: [u8; _] }`... note: ...which requires const-evaluating + checking `Foo::bytes::{{constant}}`... - --> $DIR/issue-44415.rs:17:17 + --> $DIR/issue-44415.rs:16:17 | LL | bytes: [u8; unsafe { intrinsics::size_of::() }], | ^^^^^^ = note: ...which again requires const-evaluating + checking `Foo::bytes::{{constant}}`, completing the cycle note: cycle used when processing `Foo` - --> $DIR/issue-44415.rs:16:1 + --> $DIR/issue-44415.rs:15:1 | LL | struct Foo { | ^^^^^^^^^^ diff --git a/src/test/ui/issues/issue-52023-array-size-pointer-cast.rs b/src/test/ui/issues/issue-52023-array-size-pointer-cast.rs index 02bed69f0d40e..46cbdb6ac22df 100644 --- a/src/test/ui/issues/issue-52023-array-size-pointer-cast.rs +++ b/src/test/ui/issues/issue-52023-array-size-pointer-cast.rs @@ -10,4 +10,5 @@ fn main() { let _ = [0; (&0 as *const i32) as usize]; //~ ERROR casting pointers to integers in constants + //~^ ERROR it is undefined behavior to use this value } diff --git a/src/test/ui/issues/issue-52023-array-size-pointer-cast.stderr b/src/test/ui/issues/issue-52023-array-size-pointer-cast.stderr index 74270c2bef798..ba415d43a751a 100644 --- a/src/test/ui/issues/issue-52023-array-size-pointer-cast.stderr +++ b/src/test/ui/issues/issue-52023-array-size-pointer-cast.stderr @@ -6,6 +6,15 @@ LL | let _ = [0; (&0 as *const i32) as usize]; //~ ERROR casting pointers to | = help: add #![feature(const_raw_ptr_to_usize_cast)] to the crate attributes to enable -error: aborting due to previous error +error[E0080]: it is undefined behavior to use this value + --> $DIR/issue-52023-array-size-pointer-cast.rs:12:17 + | +LL | let _ = [0; (&0 as *const i32) as usize]; //~ ERROR casting pointers to integers in constants + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer, but expected the type usize + | + = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior + +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0658`. +Some errors occurred: E0080, E0658. +For more information about an error, try `rustc --explain E0080`. From 528c72371c99f1da4a13fb15321ed7b9c1b34c1e Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Tue, 4 Sep 2018 14:04:55 +0200 Subject: [PATCH 11/21] More mono items are generated now --- src/test/codegen-units/partitioning/vtable-through-const.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/test/codegen-units/partitioning/vtable-through-const.rs b/src/test/codegen-units/partitioning/vtable-through-const.rs index 74533c1015b60..ebda08a29f66d 100644 --- a/src/test/codegen-units/partitioning/vtable-through-const.rs +++ b/src/test/codegen-units/partitioning/vtable-through-const.rs @@ -38,6 +38,7 @@ mod mod1 { fn do_something_else(&self, x: T) -> T { x } } + //~ MONO_ITEM fn vtable_through_const::mod1[0]::id[0] @@ vtable_through_const-mod1.volatile[Internal] fn id(x: T) -> T { x } // These are referenced, so they produce mono-items (see start()) @@ -52,6 +53,8 @@ mod mod1 { fn do_something_else(&self) {} } + //~ MONO_ITEM fn vtable_through_const::mod1[0]::Trait2[0]::do_something[0] @@ vtable_through_const-mod1.volatile[Internal] + //~ MONO_ITEM fn vtable_through_const::mod1[0]::Trait2[0]::do_something_else[0] @@ vtable_through_const-mod1.volatile[Internal] impl Trait2 for u32 {} pub trait Trait2Gen { @@ -89,6 +92,8 @@ fn start(_: isize, _: *const *const u8) -> isize { // Same as above //~ MONO_ITEM fn vtable_through_const::mod1[0]::{{impl}}[1]::do_something[0] @@ vtable_through_const-mod1.volatile[External] //~ MONO_ITEM fn vtable_through_const::mod1[0]::{{impl}}[1]::do_something_else[0] @@ vtable_through_const-mod1.volatile[External] + //~ MONO_ITEM fn vtable_through_const::mod1[0]::{{impl}}[3]::do_something[0] @@ vtable_through_const-mod1.volatile[Internal] + //~ MONO_ITEM fn vtable_through_const::mod1[0]::{{impl}}[3]::do_something_else[0] @@ vtable_through_const-mod1.volatile[Internal] mod1::TRAIT1_GEN_REF.do_something(0u8); //~ MONO_ITEM fn vtable_through_const::mod1[0]::id[0] @@ vtable_through_const-mod1.volatile[External] From f4a3e50d782c609f0868d06fc2b03fbea6774a2f Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Tue, 4 Sep 2018 16:09:30 +0200 Subject: [PATCH 12/21] Update rustdoc test --- src/test/rustdoc/const-evalutation-ice.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/rustdoc/const-evalutation-ice.rs b/src/test/rustdoc/const-evalutation-ice.rs index 000ed709a8aae..5675f61bd4b0d 100644 --- a/src/test/rustdoc/const-evalutation-ice.rs +++ b/src/test/rustdoc/const-evalutation-ice.rs @@ -17,4 +17,4 @@ pub struct S { s: Cell } -pub type _S = [usize; 0 - (mem::size_of::() != 4) as usize]; +pub const N: usize = 0 - (mem::size_of::() != 4) as usize; From bf8471aeda0a00c37a4798942ef9d5ae551eef20 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Fri, 7 Sep 2018 10:53:31 +0200 Subject: [PATCH 13/21] Rebase fallout in ui output --- src/librustc_codegen_llvm/mir/operand.rs | 2 -- .../const_panic_libcore_main.stderr | 6 ++--- src/test/ui/consts/const-eval/issue-52475.rs | 3 +-- .../ui/consts/const-eval/issue-52475.stderr | 24 ++++++------------- src/test/ui/consts/const-int-unchecked.stderr | 4 ++-- 5 files changed, 13 insertions(+), 26 deletions(-) diff --git a/src/librustc_codegen_llvm/mir/operand.rs b/src/librustc_codegen_llvm/mir/operand.rs index 25f03cbe97075..d1b6aa7fc4280 100644 --- a/src/librustc_codegen_llvm/mir/operand.rs +++ b/src/librustc_codegen_llvm/mir/operand.rs @@ -12,8 +12,6 @@ use rustc::mir::interpret::{ConstValue, ErrorHandled}; use rustc::mir; use rustc::ty; use rustc::ty::layout::{self, Align, LayoutOf, TyLayout}; -use rustc_data_structures::sync::Lrc; -use rustc_data_structures::indexed_vec::Idx; use base; use common::{CodegenCx, C_undef, C_usize}; diff --git a/src/test/ui/consts/const-eval/const_panic_libcore_main.stderr b/src/test/ui/consts/const-eval/const_panic_libcore_main.stderr index 9a7c510029cbc..50794c8f0651c 100644 --- a/src/test/ui/consts/const-eval/const_panic_libcore_main.stderr +++ b/src/test/ui/consts/const-eval/const_panic_libcore_main.stderr @@ -1,5 +1,5 @@ error: any use of this value will cause an error - --> $DIR/const_panic_libcore_main.rs:20:1 + --> $DIR/const_panic_libcore_main.rs:19:1 | LL | const Z: () = panic!("cheese"); | ^^^^^^^^^^^^^^----------------^ @@ -10,7 +10,7 @@ LL | const Z: () = panic!("cheese"); = 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: any use of this value will cause an error - --> $DIR/const_panic_libcore_main.rs:23:1 + --> $DIR/const_panic_libcore_main.rs:22:1 | LL | const Y: () = unreachable!(); | ^^^^^^^^^^^^^^--------------^ @@ -20,7 +20,7 @@ LL | const Y: () = unreachable!(); = 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: any use of this value will cause an error - --> $DIR/const_panic_libcore_main.rs:26:1 + --> $DIR/const_panic_libcore_main.rs:25:1 | LL | const X: () = unimplemented!(); | ^^^^^^^^^^^^^^----------------^ diff --git a/src/test/ui/consts/const-eval/issue-52475.rs b/src/test/ui/consts/const-eval/issue-52475.rs index 1c1e6535e69dc..b21c1827e2ba2 100644 --- a/src/test/ui/consts/const-eval/issue-52475.rs +++ b/src/test/ui/consts/const-eval/issue-52475.rs @@ -13,11 +13,10 @@ fn main() { let _ = [(); { //~^ WARNING Constant evaluating a complex constant, this might take some time - //~| ERROR could not evaluate repeat length let mut x = &0; let mut n = 0; while n < 5 { //~ ERROR constant contains unimplemented expression type - n = (n + 1) % 5; + n = (n + 1) % 5; //~ ERROR evaluation of constant value failed x = &0; // Materialize a new AllocId } 0 diff --git a/src/test/ui/consts/const-eval/issue-52475.stderr b/src/test/ui/consts/const-eval/issue-52475.stderr index f45587f3f7580..c0cd98b2fca1e 100644 --- a/src/test/ui/consts/const-eval/issue-52475.stderr +++ b/src/test/ui/consts/const-eval/issue-52475.stderr @@ -1,8 +1,8 @@ error[E0019]: constant contains unimplemented expression type - --> $DIR/issue-52475.rs:19:9 + --> $DIR/issue-52475.rs:18:9 | LL | / while n < 5 { //~ ERROR constant contains unimplemented expression type -LL | | n = (n + 1) % 5; +LL | | n = (n + 1) % 5; //~ ERROR evaluation of constant value failed LL | | x = &0; // Materialize a new AllocId LL | | } | |_________^ @@ -13,28 +13,18 @@ warning: Constant evaluating a complex constant, this might take some time LL | let _ = [(); { | __________________^ LL | | //~^ WARNING Constant evaluating a complex constant, this might take some time -LL | | //~| ERROR could not evaluate repeat length LL | | let mut x = &0; +LL | | let mut n = 0; ... | LL | | 0 LL | | }]; | |_____^ -error[E0080]: could not evaluate repeat length - --> $DIR/issue-52475.rs:14:18 +error[E0080]: evaluation of constant value failed + --> $DIR/issue-52475.rs:19:17 | -LL | let _ = [(); { - | __________________^ -LL | | //~^ WARNING Constant evaluating a complex constant, this might take some time -LL | | //~| ERROR could not evaluate repeat length -LL | | let mut x = &0; -... | -LL | | n = (n + 1) % 5; - | | ----------- duplicate interpreter state observed here, const evaluation will never terminate -... | -LL | | 0 -LL | | }]; - | |_____^ +LL | n = (n + 1) % 5; //~ ERROR evaluation of constant value failed + | ^^^^^^^^^^^ duplicate interpreter state observed here, const evaluation will never terminate error: aborting due to 2 previous errors diff --git a/src/test/ui/consts/const-int-unchecked.stderr b/src/test/ui/consts/const-int-unchecked.stderr index b8fd0facbc1ae..314a3e488a12b 100644 --- a/src/test/ui/consts/const-int-unchecked.stderr +++ b/src/test/ui/consts/const-int-unchecked.stderr @@ -1,4 +1,4 @@ -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const-int-unchecked.rs:15:1 | LL | const SHR: u8 = unsafe { intrinsics::unchecked_shr(5_u8, 8) }; @@ -8,7 +8,7 @@ LL | const SHR: u8 = unsafe { intrinsics::unchecked_shr(5_u8, 8) }; | = note: #[deny(const_err)] on by default -error: this constant cannot be used +error: any use of this value will cause an error --> $DIR/const-int-unchecked.rs:17:1 | LL | const SHL: u8 = unsafe { intrinsics::unchecked_shl(5_u8, 8) }; From 7c34f2da577a0b3b8effdbcc0705499bc2a6861f Mon Sep 17 00:00:00 2001 From: Alexander Regueiro Date: Tue, 18 Sep 2018 04:26:39 +0100 Subject: [PATCH 14/21] Addressed minor issues brought up in review. --- src/librustc_mir/const_eval.rs | 15 +++++++++------ src/test/rustdoc/const-evalutation-ice.rs | 2 +- .../promoted_const_fn_fail_deny_const_err.rs | 10 ++++------ .../promoted_const_fn_fail_deny_const_err.stderr | 3 +-- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index 5cda7154774cd..c501ef8ecebad 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -597,12 +597,14 @@ pub fn const_eval_raw_provider<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>, ) -> ::rustc::mir::interpret::ConstEvalResult<'tcx> { - // so we do a small trick here. We check whether we can evaluate the constant in the more - // restrictive `Reveal::UserFacing`, which most likely already was computed. In a large - // percentage of constants that will already have succeeded. Only associated constants of - // generic functions will fail due to not enough monomorphization information being available - - // in case we fail in the `UserFacing` variant, we just do the real computation. + // Because the constant is computed twice (once per value of `Reveal`), we are at risk of + // reporting the same error twice here. To resolve this, we check whether we can evaluate the + // constant in the more restrictive `Reveal::UserFacing`, which most likely already was + // computed. For a large percentage of constants that will already have succeeded. Only + // associated constants of generic functions will fail due to not enough monomorphization + // information being available. + + // In case we fail in the `UserFacing` variant, we just do the real computation. if key.param_env.reveal == Reveal::All { let mut key = key.clone(); key.param_env.reveal = Reveal::UserFacing; @@ -614,6 +616,7 @@ pub fn const_eval_raw_provider<'a, 'tcx>( } } trace!("const eval: {:?}", key); + let cid = key.value; let def_id = cid.instance.def.def_id(); diff --git a/src/test/rustdoc/const-evalutation-ice.rs b/src/test/rustdoc/const-evalutation-ice.rs index 5675f61bd4b0d..64a20d498768e 100644 --- a/src/test/rustdoc/const-evalutation-ice.rs +++ b/src/test/rustdoc/const-evalutation-ice.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// Just check if we don't get an ICE for the _S type. +// Just check we don't get an ICE for the S type. use std::cell::Cell; use std::mem; diff --git a/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.rs b/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.rs index 9f19e68f2a82f..dca8f3c474583 100644 --- a/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.rs +++ b/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.rs @@ -19,17 +19,15 @@ union Bar { const fn bar() -> u8 { unsafe { - // this will error as long as this test - // is run on a system whose pointers need more - // than 8 bits + // This will error as long as this test is run on a system whose + // pointers need more than 8 bits. Bar { a: &42 }.b as u8 } } fn main() { - // FIXME(oli-obk): this should panic at runtime - // this will actually compile, but then - // abort at runtime (not panic, hard abort). + // This will compile, but then hard-abort at runtime. + // FIXME(oli-obk): this should instead panic (not hard-abort) at runtime. let x: &'static u8 = &(bar() + 1); let y = *x; unreachable!(); diff --git a/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.stderr b/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.stderr index 3eeacbf842a4c..8e21f90995476 100644 --- a/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.stderr +++ b/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.stderr @@ -1,5 +1,5 @@ error: reaching this expression at runtime will panic or abort - --> $DIR/promoted_const_fn_fail_deny_const_err.rs:33:26 + --> $DIR/promoted_const_fn_fail_deny_const_err.rs:31:26 | LL | Bar { a: &42 }.b as u8 | ---------------------- a raw memory access tried to access part of a pointer value as raw bytes @@ -16,4 +16,3 @@ LL | #![deny(const_err)] | ^^^^^^^^^ error: aborting due to previous error - From 7717a63182722b33d9c5c298157d54eaaf23dab2 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 19 Sep 2018 09:30:25 +0200 Subject: [PATCH 15/21] fix a test comment --- src/test/rustdoc/const-evalutation-ice.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/rustdoc/const-evalutation-ice.rs b/src/test/rustdoc/const-evalutation-ice.rs index 64a20d498768e..1c04c34ea6858 100644 --- a/src/test/rustdoc/const-evalutation-ice.rs +++ b/src/test/rustdoc/const-evalutation-ice.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// Just check we don't get an ICE for the S type. +// Just check we don't get an ICE for `N`. use std::cell::Cell; use std::mem; From b81302f42d2dfb3b36c91d9b0c5ab2c465214ead Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 19 Sep 2018 09:40:30 +0200 Subject: [PATCH 16/21] for now, just use NULL ptr for unsized locals --- src/librustc/mir/interpret/mod.rs | 10 +++++----- src/librustc_mir/interpret/place.rs | 20 ++++++++++++-------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/librustc/mir/interpret/mod.rs b/src/librustc/mir/interpret/mod.rs index 40a4b8b375a20..9ef123d2daf50 100644 --- a/src/librustc/mir/interpret/mod.rs +++ b/src/librustc/mir/interpret/mod.rs @@ -176,7 +176,7 @@ impl<'tcx, Tag> Pointer { Pointer { alloc_id, offset, tag } } - pub fn wrapping_signed_offset(self, i: i64, cx: C) -> Self { + pub fn wrapping_signed_offset(self, i: i64, cx: impl HasDataLayout) -> Self { Pointer::new_with_tag( self.alloc_id, Size::from_bytes(cx.data_layout().wrapping_signed_offset(self.offset.bytes(), i)), @@ -184,12 +184,12 @@ impl<'tcx, Tag> Pointer { ) } - pub fn overflowing_signed_offset(self, i: i128, cx: C) -> (Self, bool) { + pub fn overflowing_signed_offset(self, i: i128, cx: impl HasDataLayout) -> (Self, bool) { let (res, over) = cx.data_layout().overflowing_signed_offset(self.offset.bytes(), i); (Pointer::new_with_tag(self.alloc_id, Size::from_bytes(res), self.tag), over) } - pub fn signed_offset(self, i: i64, cx: C) -> EvalResult<'tcx, Self> { + pub fn signed_offset(self, i: i64, cx: impl HasDataLayout) -> EvalResult<'tcx, Self> { Ok(Pointer::new_with_tag( self.alloc_id, Size::from_bytes(cx.data_layout().signed_offset(self.offset.bytes(), i)?), @@ -197,12 +197,12 @@ impl<'tcx, Tag> Pointer { )) } - pub fn overflowing_offset(self, i: Size, cx: C) -> (Self, bool) { + pub fn overflowing_offset(self, i: Size, cx: impl HasDataLayout) -> (Self, bool) { let (res, over) = cx.data_layout().overflowing_offset(self.offset.bytes(), i.bytes()); (Pointer::new_with_tag(self.alloc_id, Size::from_bytes(res), self.tag), over) } - pub fn offset(self, i: Size, cx: C) -> EvalResult<'tcx, Self> { + pub fn offset(self, i: Size, cx: impl HasDataLayout) -> EvalResult<'tcx, Self> { Ok(Pointer::new_with_tag( self.alloc_id, Size::from_bytes(cx.data_layout().offset(self.offset.bytes(), i.bytes())?), diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs index b7bc4867307fb..4fa08e8c3111b 100644 --- a/src/librustc_mir/interpret/place.rs +++ b/src/librustc_mir/interpret/place.rs @@ -125,6 +125,12 @@ impl MemPlace { } } + /// Produces a Place that will error if attempted to be read from or written to + #[inline(always)] + pub fn null(cx: impl HasDataLayout) -> Self { + Self::from_scalar_ptr(Scalar::ptr_null(cx), Align::from_bytes(1, 1).unwrap()) + } + #[inline(always)] pub fn from_ptr(ptr: Pointer, align: Align) -> Self { Self::from_scalar_ptr(ptr.into(), align) @@ -209,17 +215,17 @@ impl<'tcx, Tag: ::std::fmt::Debug> OpTy<'tcx, Tag> { impl<'tcx, Tag: ::std::fmt::Debug> Place { /// Produces a Place that will error if attempted to be read from or written to - #[inline] + #[inline(always)] pub fn null(cx: impl HasDataLayout) -> Self { - Self::from_scalar_ptr(Scalar::ptr_null(cx), Align::from_bytes(1, 1).unwrap()) + Place::Ptr(MemPlace::null(cx)) } - #[inline] + #[inline(always)] pub fn from_scalar_ptr(ptr: Scalar, align: Align) -> Self { Place::Ptr(MemPlace::from_scalar_ptr(ptr, align)) } - #[inline] + #[inline(always)] pub fn from_ptr(ptr: Pointer, align: Align) -> Self { Place::Ptr(MemPlace::from_ptr(ptr, align)) } @@ -882,10 +888,8 @@ where ) -> EvalResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> { if layout.is_unsized() { assert!(self.tcx.features().unsized_locals, "cannot alloc memory for unsized type"); - // allocate a fat pointer slot instead - let fat = self.tcx.mk_mut_ptr(layout.ty); - let fat = self.layout_of(fat)?; - self.allocate(fat, kind) + // FIXME: What should we do here? + Ok(MPlaceTy::dangling(layout, &self)) } else { let ptr = self.memory.allocate(layout.size, layout.align, kind)?; Ok(MPlaceTy::from_aligned_ptr(ptr, layout)) From 94586bc13326237c5aac566b1972dcd9b1b14000 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 19 Sep 2018 10:59:01 +0200 Subject: [PATCH 17/21] fix ui tests (rebase fallout) --- .../const-eval/promoted_const_fn_fail_deny_const_err.stderr | 1 + src/test/ui/consts/const-size_of-cycle.stderr | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.stderr b/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.stderr index 8e21f90995476..c44acf9f1f828 100644 --- a/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.stderr +++ b/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.stderr @@ -16,3 +16,4 @@ LL | #![deny(const_err)] | ^^^^^^^^^ error: aborting due to previous error + diff --git a/src/test/ui/consts/const-size_of-cycle.stderr b/src/test/ui/consts/const-size_of-cycle.stderr index 8e1e81f7735dc..e824657f8afda 100644 --- a/src/test/ui/consts/const-size_of-cycle.stderr +++ b/src/test/ui/consts/const-size_of-cycle.stderr @@ -1,5 +1,5 @@ error[E0391]: cycle detected when const-evaluating + checking `Foo::bytes::{{constant}}` - --> $DIR/const-size_of-cycle.rs:14:17 + --> $DIR/const-size_of-cycle.rs:16:17 | LL | bytes: [u8; std::mem::size_of::()] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -12,13 +12,13 @@ LL | intrinsics::size_of::() note: ...which requires computing layout of `Foo`... note: ...which requires normalizing `ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: All }, value: [u8; _] }`... note: ...which requires const-evaluating + checking `Foo::bytes::{{constant}}`... - --> $DIR/const-size_of-cycle.rs:14:17 + --> $DIR/const-size_of-cycle.rs:16:17 | LL | bytes: [u8; std::mem::size_of::()] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: ...which again requires const-evaluating + checking `Foo::bytes::{{constant}}`, completing the cycle note: cycle used when processing `Foo` - --> $DIR/const-size_of-cycle.rs:13:1 + --> $DIR/const-size_of-cycle.rs:15:1 | LL | struct Foo { | ^^^^^^^^^^ From 7ed7fc881e7f4dabcdc45646257ddb979822d7f4 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 19 Sep 2018 17:22:03 +0200 Subject: [PATCH 18/21] add the lint back to the list, and fix tests --- src/librustc_lint/builtin.rs | 15 ------ src/librustc_lint/lib.rs | 1 + src/test/ui/array_const_index-0.rs | 2 +- src/test/ui/array_const_index-0.stderr | 9 +--- src/test/ui/array_const_index-1.rs | 2 +- src/test/ui/array_const_index-1.stderr | 9 +--- src/test/ui/consts/const-err-early.rs | 12 ++--- src/test/ui/consts/const-err-early.stderr | 39 +------------- src/test/ui/consts/const-err-multi.rs | 1 - src/test/ui/consts/const-err-multi.stderr | 9 +--- .../consts/const-eval/const-eval-overflow2.rs | 16 +++--- .../const-eval/const-eval-overflow2.stderr | 51 +------------------ .../const-eval/const-eval-overflow2b.rs | 16 +++--- .../const-eval/const-eval-overflow2b.stderr | 51 +------------------ .../const-eval/const-eval-overflow2c.rs | 16 +++--- .../const-eval/const-eval-overflow2c.stderr | 51 +------------------ .../ui/consts/const-eval/pub_const_err.rs | 2 - .../ui/consts/const-eval/pub_const_err_bin.rs | 2 - .../const-eval/union-const-eval-field.rs | 2 - .../const-eval/union-const-eval-field.stderr | 22 +------- .../consts/const-eval/unused-broken-const.rs | 18 +++++++ .../const-eval/unused-broken-const.stderr | 14 +++++ src/test/ui/consts/const-slice-oob.rs | 1 - src/test/ui/consts/const-slice-oob.stderr | 9 +--- 24 files changed, 74 insertions(+), 296 deletions(-) create mode 100644 src/test/ui/consts/const-eval/unused-broken-const.rs create mode 100644 src/test/ui/consts/const-eval/unused-broken-const.stderr diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 597b6ae236676..c50f57e6c903d 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -1607,17 +1607,6 @@ fn check_const(cx: &LateContext, body_id: hir::BodyId) { let _ = cx.tcx.const_eval(param_env.and(cid)); } -struct UnusedBrokenConstVisitor<'a, 'tcx: 'a>(&'a LateContext<'a, 'tcx>); - -impl<'a, 'tcx, 'v> hir::intravisit::Visitor<'v> for UnusedBrokenConstVisitor<'a, 'tcx> { - fn visit_nested_body(&mut self, id: hir::BodyId) { - check_const(self.0, id); - } - fn nested_visit_map<'this>(&'this mut self) -> hir::intravisit::NestedVisitorMap<'this, 'v> { - hir::intravisit::NestedVisitorMap::None - } -} - impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedBrokenConst { fn check_item(&mut self, cx: &LateContext, it: &hir::Item) { match it.node { @@ -1627,10 +1616,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedBrokenConst { hir::ItemKind::Static(_, _, body_id) => { check_const(cx, body_id); }, - hir::ItemKind::Ty(ref ty, _) => hir::intravisit::walk_ty( - &mut UnusedBrokenConstVisitor(cx), - ty - ), _ => {}, } } diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index 211b8471115cc..5bf2b76e66849 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -152,6 +152,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) { UnreachablePub: UnreachablePub, UnnameableTestItems: UnnameableTestItems::new(), TypeAliasBounds: TypeAliasBounds, + UnusedBrokenConst: UnusedBrokenConst, TrivialConstraints: TrivialConstraints, TypeLimits: TypeLimits::new(), MissingDoc: MissingDoc::new(), diff --git a/src/test/ui/array_const_index-0.rs b/src/test/ui/array_const_index-0.rs index 0ad297eeb5cdb..e82458b10d97e 100644 --- a/src/test/ui/array_const_index-0.rs +++ b/src/test/ui/array_const_index-0.rs @@ -14,5 +14,5 @@ const B: i32 = (&A)[1]; //~| ERROR any use of this value will cause an error fn main() { - let _ = B; //~ ERROR erroneous constant used + let _ = B; } diff --git a/src/test/ui/array_const_index-0.stderr b/src/test/ui/array_const_index-0.stderr index 38163b1f4b199..49c316eee12b2 100644 --- a/src/test/ui/array_const_index-0.stderr +++ b/src/test/ui/array_const_index-0.stderr @@ -8,12 +8,5 @@ LL | const B: i32 = (&A)[1]; | = note: #[deny(const_err)] on by default -error[E0080]: erroneous constant used - --> $DIR/array_const_index-0.rs:17:13 - | -LL | let _ = B; //~ ERROR erroneous constant used - | ^ 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`. diff --git a/src/test/ui/array_const_index-1.rs b/src/test/ui/array_const_index-1.rs index 4c7dcfbb347d8..21028a447f4e0 100644 --- a/src/test/ui/array_const_index-1.rs +++ b/src/test/ui/array_const_index-1.rs @@ -14,5 +14,5 @@ const B: i32 = A[1]; //~| ERROR any use of this value will cause an error fn main() { - let _ = B; //~ ERROR erroneous constant used + let _ = B; } diff --git a/src/test/ui/array_const_index-1.stderr b/src/test/ui/array_const_index-1.stderr index b122e590c8854..fa0e6e6afc6b0 100644 --- a/src/test/ui/array_const_index-1.stderr +++ b/src/test/ui/array_const_index-1.stderr @@ -8,12 +8,5 @@ LL | const B: i32 = A[1]; | = note: #[deny(const_err)] on by default -error[E0080]: erroneous constant used - --> $DIR/array_const_index-1.rs:17:13 - | -LL | let _ = B; //~ ERROR erroneous constant used - | ^ 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`. diff --git a/src/test/ui/consts/const-err-early.rs b/src/test/ui/consts/const-err-early.rs index 1cbfb91842775..39b1b342eac31 100644 --- a/src/test/ui/consts/const-err-early.rs +++ b/src/test/ui/consts/const-err-early.rs @@ -17,10 +17,10 @@ pub const D: u8 = 42u8 - (42u8 + 1); //~ ERROR const_err pub const E: u8 = [5u8][1]; //~ ERROR const_err fn main() { - let _a = A; //~ ERROR erroneous constant used - let _b = B; //~ ERROR erroneous constant used - let _c = C; //~ ERROR erroneous constant used - let _d = D; //~ ERROR erroneous constant used - let _e = E; //~ ERROR erroneous constant used - let _e = [6u8][1]; //~ ERROR index out of bounds + let _a = A; + let _b = B; + let _c = C; + let _d = D; + let _e = E; + let _e = [6u8][1]; } diff --git a/src/test/ui/consts/const-err-early.stderr b/src/test/ui/consts/const-err-early.stderr index 8cc112191b512..1dd6c096e3739 100644 --- a/src/test/ui/consts/const-err-early.stderr +++ b/src/test/ui/consts/const-err-early.stderr @@ -44,42 +44,5 @@ LL | pub const E: u8 = [5u8][1]; //~ ERROR const_err | | | index out of bounds: the len is 1 but the index is 1 -error[E0080]: erroneous constant used - --> $DIR/const-err-early.rs:20:14 - | -LL | let _a = A; //~ ERROR erroneous constant used - | ^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-err-early.rs:21:14 - | -LL | let _b = B; //~ ERROR erroneous constant used - | ^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-err-early.rs:22:14 - | -LL | let _c = C; //~ ERROR erroneous constant used - | ^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-err-early.rs:23:14 - | -LL | let _d = D; //~ ERROR erroneous constant used - | ^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-err-early.rs:24:14 - | -LL | let _e = E; //~ ERROR erroneous constant used - | ^ referenced constant has errors - -error: index out of bounds: the len is 1 but the index is 1 - --> $DIR/const-err-early.rs:25:14 - | -LL | let _e = [6u8][1]; //~ ERROR index out of bounds - | ^^^^^^^^ - -error: aborting due to 11 previous errors +error: aborting due to 5 previous errors -For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-err-multi.rs b/src/test/ui/consts/const-err-multi.rs index 20eaebfbe5656..5cf3114c64a6b 100644 --- a/src/test/ui/consts/const-err-multi.rs +++ b/src/test/ui/consts/const-err-multi.rs @@ -21,5 +21,4 @@ pub const D: i8 = 50 - A; fn main() { let _ = (A, B, C, D); - //~^ ERROR erroneous constant used } diff --git a/src/test/ui/consts/const-err-multi.stderr b/src/test/ui/consts/const-err-multi.stderr index da6f31a38868c..e77a31a9f5fa0 100644 --- a/src/test/ui/consts/const-err-multi.stderr +++ b/src/test/ui/consts/const-err-multi.stderr @@ -36,12 +36,5 @@ LL | pub const D: i8 = 50 - A; | | | referenced constant has errors -error[E0080]: erroneous constant used - --> $DIR/const-err-multi.rs:23:13 - | -LL | let _ = (A, B, C, D); - | ^^^^^^^^^^^^ referenced constant has errors - -error: aborting due to 5 previous errors +error: aborting due to 4 previous errors -For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-eval/const-eval-overflow2.rs b/src/test/ui/consts/const-eval/const-eval-overflow2.rs index c61a1b3edb726..8e094a7f7dcc7 100644 --- a/src/test/ui/consts/const-eval/const-eval-overflow2.rs +++ b/src/test/ui/consts/const-eval/const-eval-overflow2.rs @@ -60,15 +60,15 @@ const VALS_U64: (u64,) = //~ ERROR any use of this value will cause an error ); fn main() { - foo(VALS_I8); //~ ERROR erroneous constant used - foo(VALS_I16); //~ ERROR erroneous constant used - foo(VALS_I32); //~ ERROR erroneous constant used - foo(VALS_I64); //~ ERROR erroneous constant used + foo(VALS_I8); + foo(VALS_I16); + foo(VALS_I32); + foo(VALS_I64); - foo(VALS_U8); //~ ERROR erroneous constant used - foo(VALS_U16); //~ ERROR erroneous constant used - foo(VALS_U32); //~ ERROR erroneous constant used - foo(VALS_U64); //~ ERROR erroneous constant used + foo(VALS_U8); + foo(VALS_U16); + foo(VALS_U32); + foo(VALS_U64); } fn foo(_: T) { diff --git a/src/test/ui/consts/const-eval/const-eval-overflow2.stderr b/src/test/ui/consts/const-eval/const-eval-overflow2.stderr index 0484335fd0c23..596ba6bb223f0 100644 --- a/src/test/ui/consts/const-eval/const-eval-overflow2.stderr +++ b/src/test/ui/consts/const-eval/const-eval-overflow2.stderr @@ -82,54 +82,5 @@ LL | | u64::MIN - 1, LL | | ); | |_______^ -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2.rs:63:5 - | -LL | foo(VALS_I8); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2.rs:64:5 - | -LL | foo(VALS_I16); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2.rs:65:5 - | -LL | foo(VALS_I32); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2.rs:66:5 - | -LL | foo(VALS_I64); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2.rs:68:5 - | -LL | foo(VALS_U8); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2.rs:69:5 - | -LL | foo(VALS_U16); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2.rs:70:5 - | -LL | foo(VALS_U32); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2.rs:71:5 - | -LL | foo(VALS_U64); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^^ referenced constant has errors - -error: aborting due to 16 previous errors +error: aborting due to 8 previous errors -For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-eval/const-eval-overflow2b.rs b/src/test/ui/consts/const-eval/const-eval-overflow2b.rs index 47b0977ec1d55..c69d03071e756 100644 --- a/src/test/ui/consts/const-eval/const-eval-overflow2b.rs +++ b/src/test/ui/consts/const-eval/const-eval-overflow2b.rs @@ -60,15 +60,15 @@ const VALS_U64: (u64,) = //~ ERROR any use of this value will cause an error ); fn main() { - foo(VALS_I8); //~ ERROR erroneous constant used - foo(VALS_I16); //~ ERROR erroneous constant used - foo(VALS_I32); //~ ERROR erroneous constant used - foo(VALS_I64); //~ ERROR erroneous constant used + foo(VALS_I8); + foo(VALS_I16); + foo(VALS_I32); + foo(VALS_I64); - foo(VALS_U8); //~ ERROR erroneous constant used - foo(VALS_U16); //~ ERROR erroneous constant used - foo(VALS_U32); //~ ERROR erroneous constant used - foo(VALS_U64); //~ ERROR erroneous constant used + foo(VALS_U8); + foo(VALS_U16); + foo(VALS_U32); + foo(VALS_U64); } fn foo(_: T) { diff --git a/src/test/ui/consts/const-eval/const-eval-overflow2b.stderr b/src/test/ui/consts/const-eval/const-eval-overflow2b.stderr index 8922b35a0b22f..82f245eaee866 100644 --- a/src/test/ui/consts/const-eval/const-eval-overflow2b.stderr +++ b/src/test/ui/consts/const-eval/const-eval-overflow2b.stderr @@ -82,54 +82,5 @@ LL | | u64::MAX + 1, LL | | ); | |_______^ -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2b.rs:63:5 - | -LL | foo(VALS_I8); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2b.rs:64:5 - | -LL | foo(VALS_I16); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2b.rs:65:5 - | -LL | foo(VALS_I32); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2b.rs:66:5 - | -LL | foo(VALS_I64); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2b.rs:68:5 - | -LL | foo(VALS_U8); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2b.rs:69:5 - | -LL | foo(VALS_U16); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2b.rs:70:5 - | -LL | foo(VALS_U32); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2b.rs:71:5 - | -LL | foo(VALS_U64); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^^ referenced constant has errors - -error: aborting due to 16 previous errors +error: aborting due to 8 previous errors -For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-eval/const-eval-overflow2c.rs b/src/test/ui/consts/const-eval/const-eval-overflow2c.rs index b4e1a0bc099af..f442661ec630b 100644 --- a/src/test/ui/consts/const-eval/const-eval-overflow2c.rs +++ b/src/test/ui/consts/const-eval/const-eval-overflow2c.rs @@ -60,15 +60,15 @@ const VALS_U64: (u64,) = //~ ERROR any use of this value will cause an error ); fn main() { - foo(VALS_I8); //~ ERROR erroneous constant used - foo(VALS_I16); //~ ERROR erroneous constant used - foo(VALS_I32); //~ ERROR erroneous constant used - foo(VALS_I64); //~ ERROR erroneous constant used + foo(VALS_I8); + foo(VALS_I16); + foo(VALS_I32); + foo(VALS_I64); - foo(VALS_U8); //~ ERROR erroneous constant used - foo(VALS_U16); //~ ERROR erroneous constant used - foo(VALS_U32); //~ ERROR erroneous constant used - foo(VALS_U64); //~ ERROR erroneous constant used + foo(VALS_U8); + foo(VALS_U16); + foo(VALS_U32); + foo(VALS_U64); } fn foo(_: T) { diff --git a/src/test/ui/consts/const-eval/const-eval-overflow2c.stderr b/src/test/ui/consts/const-eval/const-eval-overflow2c.stderr index 023156a40dd6d..91064eb867d86 100644 --- a/src/test/ui/consts/const-eval/const-eval-overflow2c.stderr +++ b/src/test/ui/consts/const-eval/const-eval-overflow2c.stderr @@ -82,54 +82,5 @@ LL | | u64::MAX * 2, LL | | ); | |_______^ -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2c.rs:63:5 - | -LL | foo(VALS_I8); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2c.rs:64:5 - | -LL | foo(VALS_I16); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2c.rs:65:5 - | -LL | foo(VALS_I32); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2c.rs:66:5 - | -LL | foo(VALS_I64); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2c.rs:68:5 - | -LL | foo(VALS_U8); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2c.rs:69:5 - | -LL | foo(VALS_U16); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2c.rs:70:5 - | -LL | foo(VALS_U32); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2c.rs:71:5 - | -LL | foo(VALS_U64); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^^ referenced constant has errors - -error: aborting due to 16 previous errors +error: aborting due to 8 previous errors -For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-eval/pub_const_err.rs b/src/test/ui/consts/const-eval/pub_const_err.rs index 48c172b5e3164..41cf844a8e299 100644 --- a/src/test/ui/consts/const-eval/pub_const_err.rs +++ b/src/test/ui/consts/const-eval/pub_const_err.rs @@ -17,5 +17,3 @@ pub const Z: u32 = 0 - 1; //~^ WARN any use of this value will cause an error pub type Foo = [i32; 0 - 1]; -//~^ WARN attempt to subtract with overflow -//~| WARN this array length cannot be used diff --git a/src/test/ui/consts/const-eval/pub_const_err_bin.rs b/src/test/ui/consts/const-eval/pub_const_err_bin.rs index 849d40cf107b7..0ee7d603e31ad 100644 --- a/src/test/ui/consts/const-eval/pub_const_err_bin.rs +++ b/src/test/ui/consts/const-eval/pub_const_err_bin.rs @@ -15,7 +15,5 @@ pub const Z: u32 = 0 - 1; //~^ WARN any use of this value will cause an error pub type Foo = [i32; 0 - 1]; -//~^ WARN attempt to subtract with overflow -//~| WARN this array length cannot be used fn main() {} diff --git a/src/test/ui/consts/const-eval/union-const-eval-field.rs b/src/test/ui/consts/const-eval/union-const-eval-field.rs index 759dab6c25661..c0bfbc17629fc 100644 --- a/src/test/ui/consts/const-eval/union-const-eval-field.rs +++ b/src/test/ui/consts/const-eval/union-const-eval-field.rs @@ -36,12 +36,10 @@ const fn read_field2() -> Field2 { const fn read_field3() -> Field3 { const FIELD3: Field3 = unsafe { UNION.field3 }; //~ ERROR any use of this value FIELD3 - //~^ erroneous constant used } fn main() { assert_eq!(read_field1(), FLOAT1_AS_I32); assert_eq!(read_field2(), 1.0); assert_eq!(read_field3(), unsafe { UNION.field3 }); - //~^ ERROR evaluation of constant expression failed } diff --git a/src/test/ui/consts/const-eval/union-const-eval-field.stderr b/src/test/ui/consts/const-eval/union-const-eval-field.stderr index 6a64f0c36716f..565cd916ffcb1 100644 --- a/src/test/ui/consts/const-eval/union-const-eval-field.stderr +++ b/src/test/ui/consts/const-eval/union-const-eval-field.stderr @@ -6,25 +6,5 @@ LL | const FIELD3: Field3 = unsafe { UNION.field3 }; //~ ERROR any use of th | = note: #[deny(const_err)] on by default -error[E0080]: erroneous constant used - --> $DIR/union-const-eval-field.rs:38:5 - | -LL | FIELD3 - | ^^^^^^ referenced constant has errors - -error[E0080]: evaluation of constant expression failed - --> $DIR/union-const-eval-field.rs:45:5 - | -LL | FIELD3 - | ------ referenced constant has errors -... -LL | assert_eq!(read_field3(), unsafe { UNION.field3 }); - | ^^^^^^^^^^^-------------^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | inside call to `read_field3` - | - = 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 3 previous errors +error: aborting due to previous error -For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-eval/unused-broken-const.rs b/src/test/ui/consts/const-eval/unused-broken-const.rs new file mode 100644 index 0000000000000..53ce82f8e87b6 --- /dev/null +++ b/src/test/ui/consts/const-eval/unused-broken-const.rs @@ -0,0 +1,18 @@ +// Copyright 2018 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// make sure that an *unused* broken const triggers an error even in a check build + +// compile-flags: --emit=dep-info,metadata + +const FOO: i32 = [][0]; +//~^ ERROR any use of this value will cause an error + +fn main() {} diff --git a/src/test/ui/consts/const-eval/unused-broken-const.stderr b/src/test/ui/consts/const-eval/unused-broken-const.stderr new file mode 100644 index 0000000000000..5fb2a3722e20f --- /dev/null +++ b/src/test/ui/consts/const-eval/unused-broken-const.stderr @@ -0,0 +1,14 @@ +warning: due to multiple output types requested, the explicitly specified output file name will be adapted for each output type + +error: any use of this value will cause an error + --> $DIR/unused-broken-const.rs:15:1 + | +LL | const FOO: i32 = [][0]; + | ^^^^^^^^^^^^^^^^^-----^ + | | + | index out of bounds: the len is 0 but the index is 0 + | + = note: #[deny(const_err)] on by default + +error: aborting due to previous error + diff --git a/src/test/ui/consts/const-slice-oob.rs b/src/test/ui/consts/const-slice-oob.rs index cc7f86f97a1fd..04d9b01633b15 100644 --- a/src/test/ui/consts/const-slice-oob.rs +++ b/src/test/ui/consts/const-slice-oob.rs @@ -17,5 +17,4 @@ const BAR: u32 = FOO[5]; fn main() { let _ = BAR; - //~^ ERROR erroneous constant used } diff --git a/src/test/ui/consts/const-slice-oob.stderr b/src/test/ui/consts/const-slice-oob.stderr index 763afae62eaac..4a8ad5ed6ca77 100644 --- a/src/test/ui/consts/const-slice-oob.stderr +++ b/src/test/ui/consts/const-slice-oob.stderr @@ -8,12 +8,5 @@ LL | const BAR: u32 = FOO[5]; | = note: #[deny(const_err)] on by default -error[E0080]: erroneous constant used - --> $DIR/const-slice-oob.rs:19:13 - | -LL | let _ = BAR; - | ^^^ 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`. From d2e682afed62b3ba7b6cea55b6f8fcea296861a7 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 20 Sep 2018 08:06:57 +0200 Subject: [PATCH 19/21] preserve const eval error information through trait error system --- src/librustc/mir/interpret/error.rs | 2 +- src/librustc/traits/error_reporting.rs | 2 +- src/librustc/traits/fulfill.rs | 10 ++++++---- src/librustc/traits/mod.rs | 3 ++- src/librustc/traits/structural_impls.rs | 2 +- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/librustc/mir/interpret/error.rs b/src/librustc/mir/interpret/error.rs index 75ce9b55c5037..2445ce334c0e7 100644 --- a/src/librustc/mir/interpret/error.rs +++ b/src/librustc/mir/interpret/error.rs @@ -29,7 +29,7 @@ use syntax_pos::Span; use syntax::ast; use syntax::symbol::Symbol; -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum ErrorHandled { /// Already reported a lint or an error for this evaluation Reported, diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index a7513b325fe6d..7d52e9438f869 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -881,7 +881,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { } // already reported in the query - ConstEvalFailure => { + ConstEvalFailure(_) => { self.tcx.sess.delay_span_bug(span, "constant in type had an ignored error"); return; } diff --git a/src/librustc/traits/fulfill.rs b/src/librustc/traits/fulfill.rs index 320902263af61..cfa77b210e857 100644 --- a/src/librustc/traits/fulfill.rs +++ b/src/librustc/traits/fulfill.rs @@ -9,7 +9,7 @@ // except according to those terms. use infer::InferCtxt; -use mir::interpret::GlobalId; +use mir::interpret::{GlobalId, ErrorHandled}; use ty::{self, Ty, TypeFoldable, ToPolyTraitRef, ToPredicate}; use ty::error::ExpectedFound; use rustc_data_structures::obligation_forest::{Error, ForestObligation, ObligationForest}; @@ -489,11 +489,13 @@ impl<'a, 'b, 'gcx, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'gcx, match self.selcx.tcx().at(obligation.cause.span) .const_eval(param_env.and(cid)) { Ok(_) => ProcessResult::Changed(vec![]), - Err(_) => ProcessResult::Error( - CodeSelectionError(ConstEvalFailure)) + Err(err) => ProcessResult::Error( + CodeSelectionError(ConstEvalFailure(err))) } } else { - ProcessResult::Error(CodeSelectionError(ConstEvalFailure)) + ProcessResult::Error(CodeSelectionError( + ConstEvalFailure(ErrorHandled::TooGeneric) + )) } }, None => { diff --git a/src/librustc/traits/mod.rs b/src/librustc/traits/mod.rs index c809c94f4449d..6b2ec64668e9b 100644 --- a/src/librustc/traits/mod.rs +++ b/src/librustc/traits/mod.rs @@ -23,6 +23,7 @@ use hir::def_id::DefId; use infer::SuppressRegionErrors; use infer::outlives::env::OutlivesEnvironment; use middle::region; +use mir::interpret::ErrorHandled; use ty::subst::Substs; use ty::{self, AdtKind, List, Ty, TyCtxt, GenericParamDefKind, ToPredicate}; use ty::error::{ExpectedFound, TypeError}; @@ -437,7 +438,7 @@ pub enum SelectionError<'tcx> { ty::PolyTraitRef<'tcx>, ty::error::TypeError<'tcx>), TraitNotObjectSafe(DefId), - ConstEvalFailure, + ConstEvalFailure(ErrorHandled), Overflow, } diff --git a/src/librustc/traits/structural_impls.rs b/src/librustc/traits/structural_impls.rs index e7cb9ff06234f..24779a350d74b 100644 --- a/src/librustc/traits/structural_impls.rs +++ b/src/librustc/traits/structural_impls.rs @@ -172,7 +172,7 @@ impl<'a, 'tcx> Lift<'tcx> for traits::SelectionError<'a> { ) } super::TraitNotObjectSafe(def_id) => Some(super::TraitNotObjectSafe(def_id)), - super::ConstEvalFailure(ref err) => Some(super::ConstEvalFailure), + super::ConstEvalFailure(err) => Some(super::ConstEvalFailure(err)), super::Overflow => Some(super::Overflow), } } From 1c5ff292fcaac24ae2bab9d24fc70e34b112cbbe Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 1 Oct 2018 12:52:47 +0200 Subject: [PATCH 20/21] Rebase fallout --- src/librustc_lint/builtin.rs | 43 ---------------- src/librustc_mir/const_eval.rs | 13 ++--- src/test/compile-fail/const-fn-error.rs | 2 +- src/test/compile-fail/issue-52443.rs | 1 - src/test/ui/consts/const-call.stderr | 8 +-- .../conditional_array_execution.nll.stderr | 29 ----------- .../consts/const-eval/issue-43197.nll.stderr | 43 ---------------- .../ui/consts/const-eval/issue-43197.stderr | 8 +-- .../consts/const-eval/issue-44578.nll.stderr | 15 ------ .../ui/consts/const-eval/issue-52442.stderr | 2 +- .../ui/consts/const-eval/issue-52443.stderr | 49 ------------------- ...ed_const_fn_fail_deny_const_err.nll.stderr | 14 ++++++ ...omoted_const_fn_fail_deny_const_err.stderr | 21 +++----- .../consts/const-eval/ref_to_int_match.stderr | 2 +- .../ui/consts/const-eval/transmute-const.rs | 2 +- src/test/ui/consts/const-eval/ub-nonnull.rs | 6 +-- .../ui/consts/const-eval/ub-nonnull.stderr | 6 +-- src/test/ui/consts/const-eval/ub-ref.rs | 10 ++-- src/test/ui/consts/const-eval/ub-ref.stderr | 10 ++-- src/test/ui/consts/const-eval/ub-uninhabit.rs | 6 +-- .../ui/consts/const-eval/ub-uninhabit.stderr | 6 +-- src/test/ui/consts/const-eval/ub-upvars.rs | 2 +- .../ui/consts/const-eval/ub-upvars.stderr | 4 +- src/test/ui/consts/const-eval/union-ice.rs | 2 +- .../ui/consts/const-eval/union-ice.stderr | 4 +- src/test/ui/consts/const-fn-error.stderr | 41 ---------------- .../infinite-recursion-const-fn.stderr | 2 +- src/test/ui/issues/issue-39559-2.stderr | 14 +----- src/test/ui/issues/issue-43105.rs | 3 +- src/test/ui/issues/issue-43105.stderr | 18 +------ ...issue-52023-array-size-pointer-cast.stderr | 2 +- 31 files changed, 69 insertions(+), 319 deletions(-) delete mode 100644 src/test/ui/consts/const-eval/conditional_array_execution.nll.stderr delete mode 100644 src/test/ui/consts/const-eval/issue-43197.nll.stderr delete mode 100644 src/test/ui/consts/const-eval/issue-44578.nll.stderr delete mode 100644 src/test/ui/consts/const-eval/issue-52443.stderr create mode 100644 src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.nll.stderr delete mode 100644 src/test/ui/consts/const-fn-error.stderr diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index c50f57e6c903d..1632af6d3dd15 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -1547,49 +1547,6 @@ impl LintPass for UnusedBrokenConst { lint_array!() } } - -fn validate_const<'a, 'tcx>( - tcx: ty::TyCtxt<'a, 'tcx, 'tcx>, - constant: &ty::Const<'tcx>, - param_env: ty::ParamEnv<'tcx>, - gid: ::rustc::mir::interpret::GlobalId<'tcx>, - what: &str, -) { - let ecx = ::rustc_mir::const_eval::mk_eval_cx(tcx, gid.instance, param_env).unwrap(); - let result = (|| { - let op = ecx.const_to_op(constant)?; - let mut ref_tracking = ::rustc_mir::interpret::RefTracking::new(op); - while let Some((op, mut path)) = ref_tracking.todo.pop() { - ecx.validate_operand( - op, - &mut path, - Some(&mut ref_tracking), - /* const_mode */ true, - )?; - } - Ok(()) - })(); - if let Err(err) = result { - let (trace, span) = ecx.generate_stacktrace(None); - let err = ::rustc::mir::interpret::ConstEvalErr { - error: err, - stacktrace: trace, - span, - }; - let err = err.struct_error( - tcx.at(span), - &format!("this {} likely exhibits undefined behavior", what), - ); - if let Some(mut err) = err { - err.note("The rules on what exactly is undefined behavior aren't clear, \ - so this check might be overzealous. Please open an issue on the rust compiler \ - repository if you believe it should not be considered undefined behavior", - ); - err.emit(); - } - } -} - fn check_const(cx: &LateContext, body_id: hir::BodyId) { let def_id = cx.tcx.hir.body_owner_def_id(body_id); let is_static = cx.tcx.is_static(def_id).is_some(); diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index c501ef8ecebad..830f2fb089a5e 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -24,7 +24,6 @@ use rustc::ty::{self, Ty, TyCtxt, Instance, query::TyCtxtAt}; use rustc::ty::layout::{self, Size, LayoutOf, TyLayout}; use rustc::ty::subst::Subst; use rustc::traits::Reveal; -use rustc::util::nodemap::FxHashSet; use rustc_data_structures::indexed_vec::IndexVec; use rustc_data_structures::fx::FxHashMap; use rustc::util::common::ErrorReported; @@ -36,7 +35,7 @@ use interpret::{self, PlaceTy, MemPlace, OpTy, Operand, Value, Pointer, Scalar, ConstValue, EvalResult, EvalError, EvalErrorKind, GlobalId, EvalContext, StackPopCleanup, Allocation, AllocId, MemoryKind, - snapshot, + snapshot, RefTracking, }; /// Number of steps until the detector even starts doing anything. @@ -542,15 +541,13 @@ fn validate_const<'a, 'tcx>( let ecx = mk_eval_cx(tcx, cid.instance, key.param_env).unwrap(); let val = (|| { let op = ecx.const_to_op(constant)?; - let mut todo = vec![(op, Vec::new())]; - let mut seen = FxHashSet(); - seen.insert(op); - while let Some((op, mut path)) = todo.pop() { + let mut ref_tracking = RefTracking::new(op); + while let Some((op, mut path)) = ref_tracking.todo.pop() { ecx.validate_operand( op, &mut path, - &mut seen, - &mut todo, + Some(&mut ref_tracking), + /* const_mode */ true, )?; } Ok(constant) diff --git a/src/test/compile-fail/const-fn-error.rs b/src/test/compile-fail/const-fn-error.rs index 0eee0b4c7b89d..83f2735aa9d8e 100644 --- a/src/test/compile-fail/const-fn-error.rs +++ b/src/test/compile-fail/const-fn-error.rs @@ -16,7 +16,7 @@ const fn f(x: usize) -> usize { let mut sum = 0; //~^ let bindings in constant functions are unstable //~| statements in constant functions are unstable - for i in 0..x { //~ ERROR E0080 + for i in 0..x { //~^ ERROR E0015 //~| ERROR E0019 sum += i; diff --git a/src/test/compile-fail/issue-52443.rs b/src/test/compile-fail/issue-52443.rs index 1ed513033fd5d..fc42f87ccbfda 100644 --- a/src/test/compile-fail/issue-52443.rs +++ b/src/test/compile-fail/issue-52443.rs @@ -14,5 +14,4 @@ fn main() { [(); {while true {break}; 0}]; //~ ERROR constant contains unimplemented expression type [(); { for _ in 0usize.. {}; 0}]; //~ ERROR calls in constants are limited to constant functions //~^ ERROR constant contains unimplemented expression type - //~| ERROR evaluation of constant value failed } diff --git a/src/test/ui/consts/const-call.stderr b/src/test/ui/consts/const-call.stderr index e0427d0d04c9a..81be93e916e8b 100644 --- a/src/test/ui/consts/const-call.stderr +++ b/src/test/ui/consts/const-call.stderr @@ -4,12 +4,6 @@ error[E0015]: calls in constants are limited to constant functions, tuple struct LL | let _ = [0; f(2)]; | ^^^^ -error[E0080]: evaluation of constant value failed - --> $DIR/const-call.rs:16:17 - | -LL | let _ = [0; f(2)]; - | ^^^^ calling non-const fn `f` - -error: aborting due to 2 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0015`. diff --git a/src/test/ui/consts/const-eval/conditional_array_execution.nll.stderr b/src/test/ui/consts/const-eval/conditional_array_execution.nll.stderr deleted file mode 100644 index b6c35b8ebbd93..0000000000000 --- a/src/test/ui/consts/const-eval/conditional_array_execution.nll.stderr +++ /dev/null @@ -1,29 +0,0 @@ -warning: any use of this value will cause an error - --> $DIR/conditional_array_execution.rs:15:1 - | -LL | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize]; - | ^^^^^^^^^^^^^^^^^^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | attempt to subtract with overflow - | -note: lint level defined here - --> $DIR/conditional_array_execution.rs:11:9 - | -LL | #![warn(const_err)] - | ^^^^^^^^^ - -error[E0080]: evaluation of constant expression failed - --> $DIR/conditional_array_execution.rs:19:14 - | -LL | println!("{}", FOO); - | ^^^^ --- referenced constant has errors - -error[E0080]: evaluation of constant expression failed - --> $DIR/conditional_array_execution.rs:19:20 - | -LL | println!("{}", FOO); - | ^^^ referenced constant has errors - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-eval/issue-43197.nll.stderr b/src/test/ui/consts/const-eval/issue-43197.nll.stderr deleted file mode 100644 index 86a86922d3b79..0000000000000 --- a/src/test/ui/consts/const-eval/issue-43197.nll.stderr +++ /dev/null @@ -1,43 +0,0 @@ -warning: any use of this value will cause an error - --> $DIR/issue-43197.rs:20:5 - | -LL | const X: u32 = 0-1; - | ^^^^^^^^^^^^^^^---^ - | | - | attempt to subtract with overflow - | -note: lint level defined here - --> $DIR/issue-43197.rs:11:9 - | -LL | #![warn(const_err)] - | ^^^^^^^^^ - -warning: any use of this value will cause an error - --> $DIR/issue-43197.rs:22:5 - | -LL | const Y: u32 = foo(0-1); - | ^^^^^^^^^^^^^^^^^^^---^^ - | | - | attempt to subtract with overflow - -error[E0080]: evaluation of constant expression failed - --> $DIR/issue-43197.rs:24:14 - | -LL | println!("{} {}", X, Y); - | ^^^^^^^ - referenced constant has errors - -error[E0080]: evaluation of constant expression failed - --> $DIR/issue-43197.rs:24:26 - | -LL | println!("{} {}", X, Y); - | ^ referenced constant has errors - -error[E0080]: evaluation of constant expression failed - --> $DIR/issue-43197.rs:24:23 - | -LL | println!("{} {}", X, Y); - | ^ referenced constant has errors - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-eval/issue-43197.stderr b/src/test/ui/consts/const-eval/issue-43197.stderr index 95d435818303b..eaaebc5d75ae3 100644 --- a/src/test/ui/consts/const-eval/issue-43197.stderr +++ b/src/test/ui/consts/const-eval/issue-43197.stderr @@ -1,5 +1,5 @@ warning: any use of this value will cause an error - --> $DIR/issue-43197.rs:20:5 + --> $DIR/issue-43197.rs:18:5 | LL | const X: u32 = 0-1; | ^^^^^^^^^^^^^^^---^ @@ -13,7 +13,7 @@ LL | #![warn(const_err)] | ^^^^^^^^^ warning: any use of this value will cause an error - --> $DIR/issue-43197.rs:22:5 + --> $DIR/issue-43197.rs:20:5 | LL | const Y: u32 = foo(0-1); | ^^^^^^^^^^^^^^^^^^^---^^ @@ -21,13 +21,13 @@ LL | const Y: u32 = foo(0-1); | attempt to subtract with overflow error[E0080]: evaluation of constant expression failed - --> $DIR/issue-43197.rs:24:26 + --> $DIR/issue-43197.rs:22:26 | LL | println!("{} {}", X, Y); | ^ referenced constant has errors error[E0080]: evaluation of constant expression failed - --> $DIR/issue-43197.rs:24:23 + --> $DIR/issue-43197.rs:22:23 | LL | println!("{} {}", X, Y); | ^ referenced constant has errors diff --git a/src/test/ui/consts/const-eval/issue-44578.nll.stderr b/src/test/ui/consts/const-eval/issue-44578.nll.stderr deleted file mode 100644 index 71e06e36361e8..0000000000000 --- a/src/test/ui/consts/const-eval/issue-44578.nll.stderr +++ /dev/null @@ -1,15 +0,0 @@ -error[E0080]: evaluation of constant expression failed - --> $DIR/issue-44578.rs:35:14 - | -LL | println!("{}", as Foo>::AMT); - | ^^^^ -------------------------- referenced constant has errors - -error[E0080]: evaluation of constant expression failed - --> $DIR/issue-44578.rs:35:20 - | -LL | println!("{}", as Foo>::AMT); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-eval/issue-52442.stderr b/src/test/ui/consts/const-eval/issue-52442.stderr index 93fc4bea5caa9..3075be9e28b35 100644 --- a/src/test/ui/consts/const-eval/issue-52442.stderr +++ b/src/test/ui/consts/const-eval/issue-52442.stderr @@ -8,7 +8,7 @@ error[E0080]: it is undefined behavior to use this value --> $DIR/issue-52442.rs:12:11 | LL | [(); { &loop { break } as *const _ as usize } ]; //~ ERROR unimplemented expression type - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer, but expected the type usize + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer, but expected initialized plain bits | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior diff --git a/src/test/ui/consts/const-eval/issue-52443.stderr b/src/test/ui/consts/const-eval/issue-52443.stderr deleted file mode 100644 index 807a70dd2014f..0000000000000 --- a/src/test/ui/consts/const-eval/issue-52443.stderr +++ /dev/null @@ -1,49 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/issue-52443.rs:12:10 - | -LL | [(); & { loop { continue } } ]; //~ ERROR mismatched types - | ^^^^^^^^^^^^^^^^^^^^^^^ - | | - | expected usize, found reference - | help: consider removing the borrow: `{ loop { continue } }` - | - = note: expected type `usize` - found type `&_` - -error[E0308]: mismatched types - --> $DIR/issue-52443.rs:13:17 - | -LL | [(); loop { break }]; //~ ERROR mismatched types - | ^^^^^ expected (), found usize - | - = note: expected type `()` - found type `usize` - -error[E0019]: constant contains unimplemented expression type - --> $DIR/issue-52443.rs:14:11 - | -LL | [(); {while true {break}; 0}]; //~ ERROR constant contains unimplemented expression type - | ^^^^^^^^^^^^^^^^^^ - -error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants - --> $DIR/issue-52443.rs:15:21 - | -LL | [(); { for _ in 0usize.. {}; 0}]; //~ ERROR calls in constants are limited to constant functions - | ^^^^^^^^ - -error[E0019]: constant contains unimplemented expression type - --> $DIR/issue-52443.rs:15:21 - | -LL | [(); { for _ in 0usize.. {}; 0}]; //~ ERROR calls in constants are limited to constant functions - | ^^^^^^^^ - -error[E0080]: evaluation of constant value failed - --> $DIR/issue-52443.rs:15:21 - | -LL | [(); { for _ in 0usize.. {}; 0}]; //~ ERROR calls in constants are limited to constant functions - | ^^^^^^^^ calling non-const fn `>::into_iter` - -error: aborting due to 6 previous errors - -Some errors occurred: E0015, E0019, E0080, E0308. -For more information about an error, try `rustc --explain E0015`. diff --git a/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.nll.stderr b/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.nll.stderr new file mode 100644 index 0000000000000..c6b3dd242e9c1 --- /dev/null +++ b/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.nll.stderr @@ -0,0 +1,14 @@ +error[E0716]: temporary value dropped while borrowed + --> $DIR/promoted_const_fn_fail_deny_const_err.rs:31:27 + | +LL | let x: &'static u8 = &(bar() + 1); + | ----------- ^^^^^^^^^^^ creates a temporary which is freed while still in use + | | + | type annotation requires that borrow lasts for `'static` +... +LL | } + | - temporary value is freed at the end of this statement + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0716`. diff --git a/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.stderr b/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.stderr index c44acf9f1f828..728ff39f5790c 100644 --- a/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.stderr +++ b/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.stderr @@ -1,19 +1,14 @@ -error: reaching this expression at runtime will panic or abort - --> $DIR/promoted_const_fn_fail_deny_const_err.rs:31:26 +error[E0597]: borrowed value does not live long enough + --> $DIR/promoted_const_fn_fail_deny_const_err.rs:31:27 | -LL | Bar { a: &42 }.b as u8 - | ---------------------- a raw memory access tried to access part of a pointer value as raw bytes -... LL | let x: &'static u8 = &(bar() + 1); - | ^^-----^^^^^ - | | - | inside call to `bar` - | -note: lint level defined here - --> $DIR/promoted_const_fn_fail_deny_const_err.rs:13:9 + | ^^^^^^^^^^^ temporary value does not live long enough +... +LL | } + | - temporary value only lives until here | -LL | #![deny(const_err)] - | ^^^^^^^^^ + = note: borrowed value must be valid for the static lifetime... error: aborting due to previous error +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/consts/const-eval/ref_to_int_match.stderr b/src/test/ui/consts/const-eval/ref_to_int_match.stderr index 1e65a871de41f..d55c1c2c70ba1 100644 --- a/src/test/ui/consts/const-eval/ref_to_int_match.stderr +++ b/src/test/ui/consts/const-eval/ref_to_int_match.stderr @@ -2,7 +2,7 @@ error[E0080]: it is undefined behavior to use this value --> $DIR/ref_to_int_match.rs:33:1 | LL | const BAR: Int = unsafe { Foo { r: &42 }.f }; //~ ERROR it is undefined behavior to use this value - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer, but expected the type u64 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer, but expected initialized plain bits | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior diff --git a/src/test/ui/consts/const-eval/transmute-const.rs b/src/test/ui/consts/const-eval/transmute-const.rs index 477e7119ba937..1d0ac4c98f5ce 100644 --- a/src/test/ui/consts/const-eval/transmute-const.rs +++ b/src/test/ui/consts/const-eval/transmute-const.rs @@ -13,6 +13,6 @@ use std::mem; static FOO: bool = unsafe { mem::transmute(3u8) }; -//~^ ERROR this static likely exhibits undefined behavior +//~^ ERROR it is undefined behavior to use this value fn main() {} diff --git a/src/test/ui/consts/const-eval/ub-nonnull.rs b/src/test/ui/consts/const-eval/ub-nonnull.rs index 2b07eee3ccb46..6d6ad38afdb96 100644 --- a/src/test/ui/consts/const-eval/ub-nonnull.rs +++ b/src/test/ui/consts/const-eval/ub-nonnull.rs @@ -15,11 +15,11 @@ use std::ptr::NonNull; use std::num::{NonZeroU8, NonZeroUsize}; const NULL_PTR: NonNull = unsafe { mem::transmute(0usize) }; -//~^ ERROR this constant likely exhibits undefined behavior +//~^ ERROR it is undefined behavior to use this value const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) }; -//~^ ERROR this constant likely exhibits undefined behavior +//~^ ERROR it is undefined behavior to use this value const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) }; -//~^ ERROR this constant likely exhibits undefined behavior +//~^ ERROR it is undefined behavior to use this value fn main() {} diff --git a/src/test/ui/consts/const-eval/ub-nonnull.stderr b/src/test/ui/consts/const-eval/ub-nonnull.stderr index 8d1ca885b5aba..1fdea3f38d38d 100644 --- a/src/test/ui/consts/const-eval/ub-nonnull.stderr +++ b/src/test/ui/consts/const-eval/ub-nonnull.stderr @@ -1,4 +1,4 @@ -error[E0080]: this constant likely exhibits undefined behavior +error[E0080]: it is undefined behavior to use this value --> $DIR/ub-nonnull.rs:17:1 | LL | const NULL_PTR: NonNull = unsafe { mem::transmute(0usize) }; @@ -6,7 +6,7 @@ LL | const NULL_PTR: NonNull = unsafe { mem::transmute(0usize) }; | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior -error[E0080]: this constant likely exhibits undefined behavior +error[E0080]: it is undefined behavior to use this value --> $DIR/ub-nonnull.rs:20:1 | LL | const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) }; @@ -14,7 +14,7 @@ LL | const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) }; | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior -error[E0080]: this constant likely exhibits undefined behavior +error[E0080]: it is undefined behavior to use this value --> $DIR/ub-nonnull.rs:22:1 | LL | const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) }; diff --git a/src/test/ui/consts/const-eval/ub-ref.rs b/src/test/ui/consts/const-eval/ub-ref.rs index 584dc0691698a..2c2abd9127582 100644 --- a/src/test/ui/consts/const-eval/ub-ref.rs +++ b/src/test/ui/consts/const-eval/ub-ref.rs @@ -13,18 +13,18 @@ use std::mem; const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) }; -//~^ ERROR this constant likely exhibits undefined behavior +//~^ ERROR it is undefined behavior to use this value const NULL: &u16 = unsafe { mem::transmute(0usize) }; -//~^ ERROR this constant likely exhibits undefined behavior +//~^ ERROR it is undefined behavior to use this value const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) }; -//~^ ERROR this constant likely exhibits undefined behavior +//~^ ERROR it is undefined behavior to use this value const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }]; -//~^ ERROR this constant likely exhibits undefined behavior +//~^ ERROR it is undefined behavior to use this value const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) }; -//~^ ERROR this constant likely exhibits undefined behavior +//~^ ERROR it is undefined behavior to use this value fn main() {} diff --git a/src/test/ui/consts/const-eval/ub-ref.stderr b/src/test/ui/consts/const-eval/ub-ref.stderr index 8bcb6d190b89a..4ae4640d074e3 100644 --- a/src/test/ui/consts/const-eval/ub-ref.stderr +++ b/src/test/ui/consts/const-eval/ub-ref.stderr @@ -1,4 +1,4 @@ -error[E0080]: this constant likely exhibits undefined behavior +error[E0080]: it is undefined behavior to use this value --> $DIR/ub-ref.rs:15:1 | LL | const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) }; @@ -6,7 +6,7 @@ LL | const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) }; | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior -error[E0080]: this constant likely exhibits undefined behavior +error[E0080]: it is undefined behavior to use this value --> $DIR/ub-ref.rs:18:1 | LL | const NULL: &u16 = unsafe { mem::transmute(0usize) }; @@ -14,7 +14,7 @@ LL | const NULL: &u16 = unsafe { mem::transmute(0usize) }; | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior -error[E0080]: this constant likely exhibits undefined behavior +error[E0080]: it is undefined behavior to use this value --> $DIR/ub-ref.rs:21:1 | LL | const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) }; @@ -22,7 +22,7 @@ LL | const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) }; | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior -error[E0080]: this constant likely exhibits undefined behavior +error[E0080]: it is undefined behavior to use this value --> $DIR/ub-ref.rs:24:1 | LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }]; @@ -30,7 +30,7 @@ LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }]; | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior -error[E0080]: this constant likely exhibits undefined behavior +error[E0080]: it is undefined behavior to use this value --> $DIR/ub-ref.rs:27:1 | LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) }; diff --git a/src/test/ui/consts/const-eval/ub-uninhabit.rs b/src/test/ui/consts/const-eval/ub-uninhabit.rs index 99305beee5281..22262fd0b9774 100644 --- a/src/test/ui/consts/const-eval/ub-uninhabit.rs +++ b/src/test/ui/consts/const-eval/ub-uninhabit.rs @@ -16,13 +16,13 @@ use std::mem; enum Bar {} const BAD_BAD_BAD: Bar = unsafe { mem::transmute(()) }; -//~^ ERROR this constant likely exhibits undefined behavior +//~^ ERROR it is undefined behavior to use this value const BAD_BAD_REF: &Bar = unsafe { mem::transmute(1usize) }; -//~^ ERROR this constant likely exhibits undefined behavior +//~^ ERROR it is undefined behavior to use this value const BAD_BAD_ARRAY: [Bar; 1] = unsafe { mem::transmute(()) }; -//~^ ERROR this constant likely exhibits undefined behavior +//~^ ERROR it is undefined behavior to use this value fn main() { } diff --git a/src/test/ui/consts/const-eval/ub-uninhabit.stderr b/src/test/ui/consts/const-eval/ub-uninhabit.stderr index 136d5f2919946..2ac0a6e4e8673 100644 --- a/src/test/ui/consts/const-eval/ub-uninhabit.stderr +++ b/src/test/ui/consts/const-eval/ub-uninhabit.stderr @@ -1,4 +1,4 @@ -error[E0080]: this constant likely exhibits undefined behavior +error[E0080]: it is undefined behavior to use this value --> $DIR/ub-uninhabit.rs:18:1 | LL | const BAD_BAD_BAD: Bar = unsafe { mem::transmute(()) }; @@ -6,7 +6,7 @@ LL | const BAD_BAD_BAD: Bar = unsafe { mem::transmute(()) }; | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior -error[E0080]: this constant likely exhibits undefined behavior +error[E0080]: it is undefined behavior to use this value --> $DIR/ub-uninhabit.rs:21:1 | LL | const BAD_BAD_REF: &Bar = unsafe { mem::transmute(1usize) }; @@ -14,7 +14,7 @@ LL | const BAD_BAD_REF: &Bar = unsafe { mem::transmute(1usize) }; | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior -error[E0080]: this constant likely exhibits undefined behavior +error[E0080]: it is undefined behavior to use this value --> $DIR/ub-uninhabit.rs:24:1 | LL | const BAD_BAD_ARRAY: [Bar; 1] = unsafe { mem::transmute(()) }; diff --git a/src/test/ui/consts/const-eval/ub-upvars.rs b/src/test/ui/consts/const-eval/ub-upvars.rs index 309211d19d461..f591a5affe5da 100644 --- a/src/test/ui/consts/const-eval/ub-upvars.rs +++ b/src/test/ui/consts/const-eval/ub-upvars.rs @@ -12,7 +12,7 @@ use std::mem; -const BAD_UPVAR: &FnOnce() = &{ //~ ERROR this constant likely exhibits undefined behavior +const BAD_UPVAR: &FnOnce() = &{ //~ ERROR it is undefined behavior to use this value let bad_ref: &'static u16 = unsafe { mem::transmute(0usize) }; let another_var = 13; move || { let _ = bad_ref; let _ = another_var; } diff --git a/src/test/ui/consts/const-eval/ub-upvars.stderr b/src/test/ui/consts/const-eval/ub-upvars.stderr index 3ae140d6e1c20..178f80f88e8d6 100644 --- a/src/test/ui/consts/const-eval/ub-upvars.stderr +++ b/src/test/ui/consts/const-eval/ub-upvars.stderr @@ -1,7 +1,7 @@ -error[E0080]: this constant likely exhibits undefined behavior +error[E0080]: it is undefined behavior to use this value --> $DIR/ub-upvars.rs:15:1 | -LL | / const BAD_UPVAR: &FnOnce() = &{ //~ ERROR this constant likely exhibits undefined behavior +LL | / const BAD_UPVAR: &FnOnce() = &{ //~ ERROR it is undefined behavior to use this value LL | | let bad_ref: &'static u16 = unsafe { mem::transmute(0usize) }; LL | | let another_var = 13; LL | | move || { let _ = bad_ref; let _ = another_var; } diff --git a/src/test/ui/consts/const-eval/union-ice.rs b/src/test/ui/consts/const-eval/union-ice.rs index 5a8ea711d86be..0e4f1e09171de 100644 --- a/src/test/ui/consts/const-eval/union-ice.rs +++ b/src/test/ui/consts/const-eval/union-ice.rs @@ -22,7 +22,7 @@ const UNION: DummyUnion = DummyUnion { field1: 1065353216 }; const FIELD3: Field3 = unsafe { UNION.field3 }; //~ ERROR will cause an error -const FIELD_PATH: Struct = Struct { //~ ERROR any use of this value will cause an error +const FIELD_PATH: Struct = Struct { //~ ERROR it is undefined behavior to use this value a: 42, b: unsafe { UNION.field3 }, }; diff --git a/src/test/ui/consts/const-eval/union-ice.stderr b/src/test/ui/consts/const-eval/union-ice.stderr index 7f5cb731c8eee..d5a20640771df 100644 --- a/src/test/ui/consts/const-eval/union-ice.stderr +++ b/src/test/ui/consts/const-eval/union-ice.stderr @@ -6,10 +6,10 @@ LL | const FIELD3: Field3 = unsafe { UNION.field3 }; //~ ERROR will cause an err | = note: #[deny(const_err)] on by default -error: any use of this value will cause an error +error[E0080]: it is undefined behavior to use this value --> $DIR/union-ice.rs:25:1 | -LL | / const FIELD_PATH: Struct = Struct { //~ ERROR any use of this value will cause an error +LL | / const FIELD_PATH: Struct = Struct { //~ ERROR it is undefined behavior to use this value LL | | a: 42, LL | | b: unsafe { UNION.field3 }, LL | | }; diff --git a/src/test/ui/consts/const-fn-error.stderr b/src/test/ui/consts/const-fn-error.stderr deleted file mode 100644 index a7b757f2d0000..0000000000000 --- a/src/test/ui/consts/const-fn-error.stderr +++ /dev/null @@ -1,41 +0,0 @@ -error[E0658]: let bindings in constant functions are unstable (see issue #48821) - --> $DIR/const-fn-error.rs:16:19 - | -LL | let mut sum = 0; - | ^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error[E0658]: statements in constant functions are unstable (see issue #48821) - --> $DIR/const-fn-error.rs:16:19 - | -LL | let mut sum = 0; - | ^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants - --> $DIR/const-fn-error.rs:19:14 - | -LL | for i in 0..x { //~ ERROR E0080 - | ^^^^ - -error[E0019]: constant function contains unimplemented expression type - --> $DIR/const-fn-error.rs:19:14 - | -LL | for i in 0..x { //~ ERROR E0080 - | ^^^^ - -error[E0080]: evaluation of constant value failed - --> $DIR/const-fn-error.rs:19:14 - | -LL | for i in 0..x { //~ ERROR E0080 - | ^^^^ calling non-const fn `>::into_iter` -... -LL | let a : [i32; f(X)]; - | ---- inside call to `f` - -error: aborting due to 5 previous errors - -Some errors occurred: E0015, E0019, E0080, E0658. -For more information about an error, try `rustc --explain E0015`. diff --git a/src/test/ui/infinite/infinite-recursion-const-fn.stderr b/src/test/ui/infinite/infinite-recursion-const-fn.stderr index 82da89f1aa702..ef35bb6d98dae 100644 --- a/src/test/ui/infinite/infinite-recursion-const-fn.stderr +++ b/src/test/ui/infinite/infinite-recursion-const-fn.stderr @@ -1,5 +1,5 @@ error[E0080]: evaluation of constant value failed - --> $DIR/infinite-recursion-const-fn.rs:14:25 + --> $DIR/infinite-recursion-const-fn.rs:13:25 | LL | const fn a() -> usize { b() } //~ ERROR evaluation of constant value failed | ^^^ diff --git a/src/test/ui/issues/issue-39559-2.stderr b/src/test/ui/issues/issue-39559-2.stderr index d7efcc5249486..ca9da096b6c16 100644 --- a/src/test/ui/issues/issue-39559-2.stderr +++ b/src/test/ui/issues/issue-39559-2.stderr @@ -4,24 +4,12 @@ error[E0015]: calls in constants are limited to constant functions, tuple struct LL | let array: [usize; Dim3::dim()] | ^^^^^^^^^^^ -error[E0080]: evaluation of constant value failed - --> $DIR/issue-39559-2.rs:24:24 - | -LL | let array: [usize; Dim3::dim()] - | ^^^^^^^^^^^ calling non-const fn `::dim` - error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants --> $DIR/issue-39559-2.rs:26:15 | LL | = [0; Dim3::dim()]; | ^^^^^^^^^^^ -error[E0080]: evaluation of constant value failed - --> $DIR/issue-39559-2.rs:27:15 - | -LL | = [0; Dim3::dim()]; - | ^^^^^^^^^^^ calling non-const fn `::dim` - -error: aborting due to 4 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0015`. diff --git a/src/test/ui/issues/issue-43105.rs b/src/test/ui/issues/issue-43105.rs index 2b0eb68549795..2bddc443d5baf 100644 --- a/src/test/ui/issues/issue-43105.rs +++ b/src/test/ui/issues/issue-43105.rs @@ -12,11 +12,10 @@ fn xyz() -> u8 { 42 } const NUM: u8 = xyz(); //~^ ERROR calls in constants are limited to constant functions, tuple structs and tuple variants -//~| ERROR any use of this value will cause an error fn main() { match 1 { - NUM => unimplemented!(), //~ ERROR could not evaluate constant pattern + NUM => unimplemented!(), _ => unimplemented!(), } } diff --git a/src/test/ui/issues/issue-43105.stderr b/src/test/ui/issues/issue-43105.stderr index aba8351186bd9..67a6008cd8ebc 100644 --- a/src/test/ui/issues/issue-43105.stderr +++ b/src/test/ui/issues/issue-43105.stderr @@ -4,22 +4,6 @@ error[E0015]: calls in constants are limited to constant functions, tuple struct LL | const NUM: u8 = xyz(); | ^^^^^ -error: any use of this value will cause an error - --> $DIR/issue-43105.rs:13:1 - | -LL | const NUM: u8 = xyz(); - | ^^^^^^^^^^^^^^^^-----^ - | | - | calling non-const fn `xyz` - | - = note: #[deny(const_err)] on by default - -error: could not evaluate constant pattern - --> $DIR/issue-43105.rs:19:9 - | -LL | NUM => unimplemented!(), //~ ERROR could not evaluate constant pattern - | ^^^ - -error: aborting due to 3 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0015`. diff --git a/src/test/ui/issues/issue-52023-array-size-pointer-cast.stderr b/src/test/ui/issues/issue-52023-array-size-pointer-cast.stderr index ba415d43a751a..03de0efd07362 100644 --- a/src/test/ui/issues/issue-52023-array-size-pointer-cast.stderr +++ b/src/test/ui/issues/issue-52023-array-size-pointer-cast.stderr @@ -10,7 +10,7 @@ error[E0080]: it is undefined behavior to use this value --> $DIR/issue-52023-array-size-pointer-cast.rs:12:17 | LL | let _ = [0; (&0 as *const i32) as usize]; //~ ERROR casting pointers to integers in constants - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer, but expected the type usize + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer, but expected initialized plain bits | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior From 13d94ee1154770caa8e027394fa2221db2dfe5c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20S=CC=B6c=CC=B6h=CC=B6n=CC=B6e=CC=B6i=CC=B6d=CC=B6?= =?UTF-8?q?e=CC=B6r=20Scherer?= Date: Wed, 17 Oct 2018 10:06:03 +0200 Subject: [PATCH 21/21] Explain how unused constants may still cause a hard error --- src/librustc_mir/const_eval.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index 830f2fb089a5e..731feae623122 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -662,6 +662,10 @@ pub fn const_eval_raw_provider<'a, 'tcx>( match tcx.describe_def(def_id) { // constants never produce a hard error at the definition site. Anything else is // a backwards compatibility hazard (and will break old versions of winapi for sure) + // + // note that validation may still cause a hard error on this very same constant, + // because any code that existed before validation could not have failed validation + // thus preventing such a hard error from being a backwards compatibility hazard Some(Def::Const(_)) | Some(Def::AssociatedConst(_)) => { let node_id = tcx.hir.as_local_node_id(def_id).unwrap(); err.report_as_lint(