-
-
Notifications
You must be signed in to change notification settings - Fork 15k
introduce UnevaluatedConstKind #157094
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
base: main
Are you sure you want to change the base?
introduce UnevaluatedConstKind #157094
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,9 +22,10 @@ pub use valtree::*; | |
|
|
||
| pub type ConstKind<'tcx> = ir::ConstKind<TyCtxt<'tcx>>; | ||
| pub type UnevaluatedConst<'tcx> = ir::UnevaluatedConst<TyCtxt<'tcx>>; | ||
| pub type UnevaluatedConstKind<'tcx> = ir::UnevaluatedConstKind<TyCtxt<'tcx>>; | ||
|
|
||
| #[cfg(target_pointer_width = "64")] | ||
| rustc_data_structures::static_assert_size!(ConstKind<'_>, 24); | ||
| rustc_data_structures::static_assert_size!(ConstKind<'_>, 32); | ||
|
|
||
| #[derive(Copy, Clone, PartialEq, Eq, Hash, StableHash)] | ||
| #[rustc_pass_by_value] | ||
|
|
@@ -107,7 +108,6 @@ impl<'tcx> Const<'tcx> { | |
|
|
||
| #[inline] | ||
| pub fn new_unevaluated(tcx: TyCtxt<'tcx>, uv: ty::UnevaluatedConst<'tcx>) -> Const<'tcx> { | ||
| tcx.debug_assert_args_compatible(uv.def, uv.args); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this assert has moved to the UnevaluatedConstKind constructor, which is what AliasTyKind does |
||
| Const::new(tcx, ty::ConstKind::Unevaluated(uv)) | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -219,6 +219,26 @@ impl<'tcx> Interner for TyCtxt<'tcx> { | |
| } | ||
| } | ||
|
|
||
| fn unevaluated_const_kind_from_def_id( | ||
| self, | ||
| def_id: Self::DefId, | ||
| ) -> ty::UnevaluatedConstKind<'tcx> { | ||
| match self.def_kind(def_id) { | ||
| DefKind::AssocConst { .. } => { | ||
| if let DefKind::Impl { of_trait: false } = self.def_kind(self.parent(def_id)) { | ||
| ty::UnevaluatedConstKind::Inherent { def_id } | ||
| } else { | ||
| ty::UnevaluatedConstKind::Projection { def_id } | ||
| } | ||
| } | ||
| DefKind::Const { .. } => ty::UnevaluatedConstKind::Free { def_id }, | ||
| DefKind::AnonConst | DefKind::InlineConst | DefKind::Ctor(_, CtorKind::Const) => { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am unsure about |
||
| ty::UnevaluatedConstKind::Anon { def_id } | ||
| } | ||
| kind => bug!("unexpected DefKind in UnevaluatedConst: {kind:?}"), | ||
| } | ||
| } | ||
|
|
||
| fn alias_term_kind_from_def_id(self, def_id: DefId) -> ty::AliasTermKind<'tcx> { | ||
| match self.def_kind(def_id) { | ||
| DefKind::AssocTy => { | ||
|
|
@@ -239,7 +259,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> { | |
| DefKind::TyAlias => ty::AliasTermKind::FreeTy { def_id }, | ||
| DefKind::Const { .. } => ty::AliasTermKind::FreeConst { def_id }, | ||
| DefKind::AnonConst | DefKind::Ctor(_, CtorKind::Const) => { | ||
| ty::AliasTermKind::UnevaluatedConst { def_id } | ||
| ty::AliasTermKind::AnonConst { def_id } | ||
| } | ||
| kind => bug!("unexpected DefKind in AliasTy: {kind:?}"), | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
N.B.