Add impl_tag!
macro to implement Tag
for tagged pointer easily
This commit is contained in:
parent
13fc33e3f2
commit
77c83c0965
4 changed files with 244 additions and 29 deletions
|
@ -1626,29 +1626,12 @@ struct ParamTag {
|
|||
constness: hir::Constness,
|
||||
}
|
||||
|
||||
unsafe impl rustc_data_structures::tagged_ptr::Tag for ParamTag {
|
||||
const BITS: u32 = 2;
|
||||
|
||||
#[inline]
|
||||
fn into_usize(self) -> usize {
|
||||
match self {
|
||||
Self { reveal: traits::Reveal::UserFacing, constness: hir::Constness::NotConst } => 0,
|
||||
Self { reveal: traits::Reveal::All, constness: hir::Constness::NotConst } => 1,
|
||||
Self { reveal: traits::Reveal::UserFacing, constness: hir::Constness::Const } => 2,
|
||||
Self { reveal: traits::Reveal::All, constness: hir::Constness::Const } => 3,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn from_usize(ptr: usize) -> Self {
|
||||
match ptr {
|
||||
0 => Self { reveal: traits::Reveal::UserFacing, constness: hir::Constness::NotConst },
|
||||
1 => Self { reveal: traits::Reveal::All, constness: hir::Constness::NotConst },
|
||||
2 => Self { reveal: traits::Reveal::UserFacing, constness: hir::Constness::Const },
|
||||
3 => Self { reveal: traits::Reveal::All, constness: hir::Constness::Const },
|
||||
_ => std::hint::unreachable_unchecked(),
|
||||
}
|
||||
}
|
||||
impl_tag! {
|
||||
for ParamTag;
|
||||
ParamTag { reveal: traits::Reveal::UserFacing, constness: hir::Constness::NotConst } <=> 0,
|
||||
ParamTag { reveal: traits::Reveal::All, constness: hir::Constness::NotConst } <=> 1,
|
||||
ParamTag { reveal: traits::Reveal::UserFacing, constness: hir::Constness::Const } <=> 2,
|
||||
ParamTag { reveal: traits::Reveal::All, constness: hir::Constness::Const } <=> 3,
|
||||
}
|
||||
|
||||
impl<'tcx> fmt::Debug for ParamEnv<'tcx> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue