-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cast and Coercion enums duplicate a lot of structure #59588
Labels
A-coercions
Area: implicit and explicit `expr as Type` coercions
C-cleanup
Category: PRs that clean code up or issues documenting cleanup.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Comments
oli-obk
added
the
C-cleanup
Category: PRs that clean code up or issues documenting cleanup.
label
Mar 31, 2019
jonas-schievink
added
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
A-coercions
Area: implicit and explicit `expr as Type` coercions
labels
Mar 31, 2019
@oli-obk Can i pick this up? |
It's all yours! |
pub enum Adjust<'tcx> {
/// Go from ! to any type.
NeverToAny,
/// Go from a fn-item type to a fn-pointer type.
ReifyFnPointer,
/// Go from a safe fn pointer to an unsafe fn pointer.
UnsafeFnPointer,
/// Go from a non-capturing closure to an fn pointer or an unsafe fn pointer.
/// It cannot convert a closure that requires unsafe.
ClosureFnPointer(hir::Unsafety),
/// Go from a mut raw pointer to a const raw pointer.
MutToConstPointer,
/// Dereference once, producing a place.
Deref(Option<OverloadedDeref<'tcx>>),
/// Take the address and produce either a `&` or `*` pointer.
Borrow(AutoBorrow<'tcx>),
/// Unsize a pointer/reference value, e.g., `&[T; n]` to
/// `&[T]`. Note that the source could be a thin or fat pointer.
/// This will do things like convert thin pointers to fat
/// pointers, or convert structs containing thin pointers to
/// structs containing fat pointers, or convert between fat
/// pointers. We don't store the details of how the transform is
/// done (in fact, we don't know that, because it might depend on
/// the precise type parameters). We just store the target
/// type. Codegen backends and miri figure out what has to be done
/// based on the precise source/target type at hand.
Unsize,
} pub enum CastKind {
Misc,
/// Converts unique, zero-sized type for a fn to fn()
ReifyFnPointer,
/// Converts non capturing closure to fn() or unsafe fn().
/// It cannot convert a closure that requires unsafe.
ClosureFnPointer(hir::Unsafety),
/// Converts safe fn() to unsafe fn()
UnsafeFnPointer,
/// Coerces *mut T to *const T, preserving T.
MutToConstPointer,
/// "Unsize" -- convert a thin-or-fat pointer to a fat pointer.
/// codegen must figure out the details once full monomorphization
/// is known. For example, this could be used to cast from a
/// `&[i32;N]` to a `&[i32]`, or a `Box<T>` to a `Box<dyn Trait>`
/// (presuming `T: Trait`).
Unsize,
}
|
Yes, that's expected. The shared variants can be moved to a new enum so e.g. enum CastKind {
Misc,
Pointer(PointerCast),
} |
bors
added a commit
that referenced
this issue
Apr 20, 2019
Refactor Adjust and CastKind fixes #59588
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-coercions
Area: implicit and explicit `expr as Type` coercions
C-cleanup
Category: PRs that clean code up or issues documenting cleanup.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
The
Adjust
enum in src/librustc/ty/adjustment.rs and theCastKind
enum in src/librustc/mir/mod.rs have all fields but one of theCastKind
enum in common. We should pull them out into a single enum that both use. Additionally this will allow merging some variants of ExprKind in src/librustc_mir/hair/mod.rs by having a singleCoerce
variant that has a field of the newly created enum.The text was updated successfully, but these errors were encountered: