diff options
| author | Yuki Okushi <huyuumi.dev@gmail.com> | 2019-12-11 04:32:57 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-12-11 04:32:57 +0900 |
| commit | a7f930748cefc33808686b7f748a503a445579f1 (patch) | |
| tree | 2fec156a29995f117e1b33468f2e93de9f09c6c7 /src/librustc_codegen_ssa | |
| parent | 9b1b12b94ac115cefd39fe9e4a6c24edfcecd4f1 (diff) | |
| parent | c1434716c1dc67f8c96b488121a9b91163516aa3 (diff) | |
| download | rust-a7f930748cefc33808686b7f748a503a445579f1.tar.gz rust-a7f930748cefc33808686b7f748a503a445579f1.zip | |
Rollup merge of #67134 - oli-obk:const_prop_zst, r=wesleywiser
Ensure that we get a hard error on generic ZST constants if their bod… …y causes an error during evaluation cc #67083 (does not fix because we still need the beta backport) r? @wesleywiser cc @RalfJung
Diffstat (limited to 'src/librustc_codegen_ssa')
| -rw-r--r-- | src/librustc_codegen_ssa/mir/constant.rs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/librustc_codegen_ssa/mir/constant.rs b/src/librustc_codegen_ssa/mir/constant.rs index 27891be6b82..fb8f504d04b 100644 --- a/src/librustc_codegen_ssa/mir/constant.rs +++ b/src/librustc_codegen_ssa/mir/constant.rs @@ -16,6 +16,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { constant: &mir::Constant<'tcx>, ) -> Result<OperandRef<'tcx, Bx::Value>, ErrorHandled> { match constant.literal.val { + // Special case unevaluated statics, because statics have an identity and thus should + // use `get_static` to get at their id. + // FIXME(oli-obk): can we unify this somehow, maybe by making const eval of statics + // always produce `&STATIC`. This may also simplify how const eval works with statics. ty::ConstKind::Unevaluated(def_id, substs) if self.cx.tcx().is_static(def_id) => { assert!(substs.is_empty(), "we don't support generic statics yet"); @@ -46,7 +50,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { instance, promoted: None, }; - self.cx.tcx().const_eval(ty::ParamEnv::reveal_all().and(cid)) + self.cx.tcx().const_eval(ty::ParamEnv::reveal_all().and(cid)).map_err(|err| { + self.cx.tcx().sess.span_err(constant.span, "erroneous constant encountered"); + err + }) }, _ => Ok(self.monomorphize(&constant.literal)), } |
