diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2020-07-11 08:53:06 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-11 08:53:06 -0700 |
| commit | 90f1d724c8d9b364b4b0c81817484afa04c73009 (patch) | |
| tree | faeaf565f2045577edb5641c3cd091f25109219f /src/librustc_mir | |
| parent | 346aec9b02f3c74f3fce97fd6bda24709d220e49 (diff) | |
| parent | dd872be5da0887d800ae9a001ec212c7161f661c (diff) | |
| download | rust-90f1d724c8d9b364b4b0c81817484afa04c73009.tar.gz rust-90f1d724c8d9b364b4b0c81817484afa04c73009.zip | |
Rollup merge of #72920 - oli-obk:const_transmute, r=RalfJung
Stabilize `transmute` in constants and statics but not const fn cc #53605 (leaving issue open so we can add `transmute` to `const fn` later) Previous attempt: #64011 r? @RalfJung cc @rust-lang/wg-const-eval
Diffstat (limited to 'src/librustc_mir')
| -rw-r--r-- | src/librustc_mir/transform/qualify_min_const_fn.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/librustc_mir/transform/qualify_min_const_fn.rs b/src/librustc_mir/transform/qualify_min_const_fn.rs index 7041e2db27e..52b1eba3b93 100644 --- a/src/librustc_mir/transform/qualify_min_const_fn.rs +++ b/src/librustc_mir/transform/qualify_min_const_fn.rs @@ -6,6 +6,7 @@ use rustc_middle::ty::subst::GenericArgKind; use rustc_middle::ty::{self, adjustment::PointerCast, Ty, TyCtxt}; use rustc_span::symbol::{sym, Symbol}; use rustc_span::Span; +use rustc_target::spec::abi::Abi::RustIntrinsic; use std::borrow::Cow; type McfResult = Result<(), (Span, Cow<'static, str>)>; @@ -418,6 +419,20 @@ fn check_terminator( )); } + // HACK: This is to "unstabilize" the `transmute` intrinsic + // within const fns. `transmute` is allowed in all other const contexts. + // This won't really scale to more intrinsics or functions. Let's allow const + // transmutes in const fn before we add more hacks to this. + if tcx.fn_sig(fn_def_id).abi() == RustIntrinsic + && tcx.item_name(fn_def_id) == sym::transmute + && !feature_allowed(tcx, def_id, sym::const_fn_transmute) + { + return Err(( + span, + "can only call `transmute` from const items, not `const fn`".into(), + )); + } + check_operand(tcx, func, span, fn_def_id, body)?; for arg in args { |
