Conversation
This adds an `UnpackedKind` type as a typesafe counterpart to `Kind`. This should make future changes to kinds (such as const generics!) more resilient, as the type-checker should catch more potential issues.
src/librustc/ty/subst.rs
Outdated
| TYPE_TAG => unsafe { | ||
| UnpackedKind::Type(&*((ptr & !TAG_MASK) as *const _)) | ||
| }, | ||
| _ => bug!("packed kind has invalid tag") |
There was a problem hiding this comment.
cc @nikomatsakis Should this be bug!? That seems expensive. intrinsics::unreachable() should be fine since Kind can't be safely created with a different tag, and would avoid unnecessary cases in matches.
There was a problem hiding this comment.
I agree that unreachable! in this case seems ok, since we're meddling in unsafe code, and this is inside the abstraction barrier. Plus this is "inner loop" code.
|
r=me when the fallback case in |
| Ok(Kind::from(relation.relate_with_variance(variance, &a_r, &b_r)?)) | ||
| } else { | ||
| bug!() | ||
| match (a.unpack(), b.unpack()) { |
There was a problem hiding this comment.
nice, I've been wanting this to be done forever =)
src/librustc/ty/subst.rs
Outdated
| TYPE_TAG => unsafe { | ||
| UnpackedKind::Type(&*((ptr & !TAG_MASK) as *const _)) | ||
| }, | ||
| _ => bug!("packed kind has invalid tag") |
There was a problem hiding this comment.
I agree that unreachable! in this case seems ok, since we're meddling in unsafe code, and this is inside the abstraction barrier. Plus this is "inner loop" code.
|
@bors r+ |
|
📌 Commit f2b9686 has been approved by |
|
🌲 The tree is currently closed for pull requests below priority 99, this pull request will be tested once the tree is reopened |
Introduce UnpackedKind This adds an `UnpackedKind` type as a typesafe counterpart to `Kind`. This should make future changes to kinds (such as const generics!) more resilient, as the type-checker will be able to catch more potential issues. r? @eddyb cc @yodaldevoid
This adds an
UnpackedKindtype as a typesafe counterpart toKind. This should make future changes to kinds (such as const generics!) more resilient, as the type-checker will be able to catch more potential issues.r? @eddyb
cc @yodaldevoid