Skip to content

Commit 56633b3

Browse files
committed
Add a comparison between match *self and intrinsics::unreachable()
1 parent f441adc commit 56633b3

File tree

1 file changed

+3
-2
lines changed
  • compiler/rustc_builtin_macros/src/deriving/generic

1 file changed

+3
-2
lines changed

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1149,8 +1149,9 @@ impl<'a> MethodDef<'a> {
11491149
let unify_fieldless_variants =
11501150
self.fieldless_variants_strategy == FieldlessVariantsStrategy::Unify;
11511151

1152-
// For zero-variant enum, this function body is unreachable.
1153-
// Generate `match *self {}`.
1152+
// For zero-variant enum, this function body is unreachable. Generate
1153+
// `match *self {}`. This produces machine code identical to `unsafe {
1154+
// core::intrinsics::unreachable() }` while being safe and stable.
11541155
if variants.is_empty() {
11551156
selflike_args.truncate(1);
11561157
let match_arg = cx.expr_deref(span, selflike_args.pop().unwrap());

0 commit comments

Comments
 (0)