Skip to content

Commit b144fa6

Browse files
committed
Require either wrapping nullary intrinsincs in const blocks or explicitly deciding not to
1 parent 293a634 commit b144fa6

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

compiler/rustc_codegen_ssa/src/mir/intrinsic.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_abi::WrappingRange;
2-
use rustc_middle::bug;
32
use rustc_middle::mir::SourceInfo;
43
use rustc_middle::ty::{self, Ty, TyCtxt};
4+
use rustc_middle::{bug, span_bug};
55
use rustc_session::config::OptLevel;
66
use rustc_span::sym;
77

@@ -98,6 +98,27 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
9898
discr.to_atomic_ordering()
9999
};
100100

101+
if args.is_empty() {
102+
match name {
103+
sym::abort
104+
| sym::unreachable
105+
| sym::cold_path
106+
| sym::breakpoint
107+
| sym::assert_zero_valid
108+
| sym::assert_mem_uninitialized_valid
109+
| sym::assert_inhabited
110+
| sym::ub_checks
111+
| sym::contract_checks
112+
| sym::atomic_fence
113+
| sym::atomic_singlethreadfence
114+
| sym::caller_location => {}
115+
_ => {
116+
span_bug!(span, "nullary intrinsic {name} must either be in a const block or explicitly opted out because it is inherently a runtime intrinsic
117+
");
118+
}
119+
}
120+
}
121+
101122
let llval = match name {
102123
sym::abort => {
103124
bx.abort();

0 commit comments

Comments
 (0)