Add a comparison between match *self and intrinsics::unreachable()

This commit is contained in:
David Tolnay 2023-07-16 15:33:29 -07:00
parent f441adc89a
commit 56633b3f51
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -1149,8 +1149,9 @@ impl<'a> MethodDef<'a> {
let unify_fieldless_variants =
self.fieldless_variants_strategy == FieldlessVariantsStrategy::Unify;
// For zero-variant enum, this function body is unreachable.
// Generate `match *self {}`.
// For zero-variant enum, this function body is unreachable. Generate
// `match *self {}`. This produces machine code identical to `unsafe {
// core::intrinsics::unreachable() }` while being safe and stable.
if variants.is_empty() {
selflike_args.truncate(1);
let match_arg = cx.expr_deref(span, selflike_args.pop().unwrap());