Skip to content

Commit a9f9145

Browse files
committed
CTFE: exposing pointers and calling extern fn doesn't need an RFC, it is just impossible
1 parent ee285ea commit a9f9145

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

compiler/rustc_const_eval/src/const_eval/machine.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,10 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
269269
);
270270
throw_inval!(AlreadyReported(guar));
271271
} else {
272+
// `find_mir_or_eval_fn` checks that this is a const fn before even calling us,
273+
// so this should be unreachable.
272274
let path = ecx.tcx.def_path_str(def.did);
273-
Err(ConstEvalErrKind::NeedsRfc(format!("calling extern function `{}`", path))
274-
.into())
275+
bug!("trying to call extern function `{path}` at compile-time");
275276
}
276277
}
277278
_ => Ok(ecx.tcx.instance_mir(instance)),
@@ -469,7 +470,8 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
469470
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
470471
_ptr: Pointer<AllocId>,
471472
) -> InterpResult<'tcx> {
472-
Err(ConstEvalErrKind::NeedsRfc("exposing pointers".to_string()).into())
473+
// This is only reachable with -Zunleash-the-miri-inside-of-you.
474+
throw_unsup_format!("exposing pointers is not possible at compile-time")
473475
}
474476

475477
#[inline(always)]

compiler/rustc_const_eval/src/interpret/machine.rs

+1
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ pub macro compile_time_machine(<$mir: lifetime, $tcx: lifetime>) {
490490
) -> InterpResult<$tcx, Pointer<Option<AllocId>>> {
491491
// Allow these casts, but make the pointer not dereferenceable.
492492
// (I.e., they behave like transmutation.)
493+
// This is correct because no pointers can ever be exposed in compile-time evaluation.
493494
Ok(Pointer::from_addr(addr))
494495
}
495496

src/test/ui/consts/miri_unleashed/ptr_arith.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
static PTR_INT_CAST: () = {
99
let x = &0 as *const _ as usize;
1010
//~^ ERROR could not evaluate static initializer
11-
//~| "exposing pointers" needs an rfc before being allowed inside constants
11+
//~| exposing pointers
1212
let _v = x == x;
1313
};
1414

src/test/ui/consts/miri_unleashed/ptr_arith.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0080]: could not evaluate static initializer
22
--> $DIR/ptr_arith.rs:9:13
33
|
44
LL | let x = &0 as *const _ as usize;
5-
| ^^^^^^^^^^^^^^^^^^^^^^^ "exposing pointers" needs an rfc before being allowed inside constants
5+
| ^^^^^^^^^^^^^^^^^^^^^^^ exposing pointers is not possible at compile-time
66

77
error[E0080]: could not evaluate static initializer
88
--> $DIR/ptr_arith.rs:17:14

0 commit comments

Comments
 (0)