1
Fork 0

Stabilize const_fn_transmute

This commit is contained in:
Jacob Pratt 2021-06-03 02:11:14 -04:00
parent fd853c00e2
commit 36f02f3523
No known key found for this signature in database
GPG key ID: B80E19E4662B5AA4
12 changed files with 15 additions and 47 deletions

View file

@ -876,15 +876,6 @@ impl Visitor<'tcx> for Checker<'mir, 'tcx> {
let is_intrinsic = tcx.fn_sig(callee).abi() == RustIntrinsic;
// 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 is_intrinsic && tcx.item_name(callee) == sym::transmute {
self.check_op(ops::Transmute);
return;
}
if !tcx.is_const_fn_raw(callee) {
let mut permitted = false;

View file

@ -501,29 +501,6 @@ impl NonConstOp for ThreadLocalAccess {
}
}
#[derive(Debug)]
pub struct Transmute;
impl NonConstOp for Transmute {
fn status_in_item(&self, ccx: &ConstCx<'_, '_>) -> Status {
if ccx.const_kind() != hir::ConstContext::ConstFn {
Status::Allowed
} else {
Status::Unstable(sym::const_fn_transmute)
}
}
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
let mut err = feature_err(
&ccx.tcx.sess.parse_sess,
sym::const_fn_transmute,
span,
&format!("`transmute` is not allowed in {}s", ccx.const_kind()),
);
err.note("`transmute` is only allowed in constants and statics for now");
err
}
}
#[derive(Debug)]
pub struct UnionAccess;
impl NonConstOp for UnionAccess {