From 22eeff700e4d2b4c4160c63d8d3e14931268b5f8 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 21 Oct 2021 13:23:00 +0000 Subject: [PATCH] Prepare for more ParamEnv flags --- compiler/rustc_middle/src/ty/mod.rs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 2d692670372..4720c895a1e 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -1221,23 +1221,28 @@ pub struct ParamEnv<'tcx> { /// want `Reveal::All`. /// /// Note: This is packed, use the reveal() method to access it. - packed: CopyTaggedPtr<&'tcx List>, traits::Reveal, true>, + packed: CopyTaggedPtr<&'tcx List>, ParamTag, true>, } -unsafe impl rustc_data_structures::tagged_ptr::Tag for traits::Reveal { +#[derive(Copy, Clone)] +struct ParamTag { + reveal: traits::Reveal, +} + +unsafe impl rustc_data_structures::tagged_ptr::Tag for ParamTag { const BITS: usize = 1; #[inline] fn into_usize(self) -> usize { match self { - traits::Reveal::UserFacing => 0, - traits::Reveal::All => 1, + Self { reveal: traits::Reveal::UserFacing } => 0, + Self { reveal: traits::Reveal::All } => 1, } } #[inline] unsafe fn from_usize(ptr: usize) -> Self { match ptr { - 0 => traits::Reveal::UserFacing, - 1 => traits::Reveal::All, + 0 => Self { reveal: traits::Reveal::UserFacing }, + 1 => Self { reveal: traits::Reveal::All }, _ => std::hint::unreachable_unchecked(), } } @@ -1290,7 +1295,7 @@ impl<'tcx> ParamEnv<'tcx> { #[inline] pub fn reveal(self) -> traits::Reveal { - self.packed.tag() + self.packed.tag().reveal } /// Construct a trait environment with no where-clauses in scope @@ -1308,11 +1313,11 @@ impl<'tcx> ParamEnv<'tcx> { /// Construct a trait environment with the given set of predicates. #[inline] pub fn new(caller_bounds: &'tcx List>, reveal: Reveal) -> Self { - ty::ParamEnv { packed: CopyTaggedPtr::new(caller_bounds, reveal) } + ty::ParamEnv { packed: CopyTaggedPtr::new(caller_bounds, ParamTag { reveal }) } } pub fn with_user_facing(mut self) -> Self { - self.packed.set_tag(Reveal::UserFacing); + self.packed.set_tag(ParamTag { reveal: Reveal::UserFacing, ..self.packed.tag() }); self } @@ -1326,7 +1331,7 @@ impl<'tcx> ParamEnv<'tcx> { /// will be normalized to their underlying types. /// See PR #65989 and issue #65918 for more details pub fn with_reveal_all_normalized(self, tcx: TyCtxt<'tcx>) -> Self { - if self.packed.tag() == traits::Reveal::All { + if self.packed.tag().reveal == traits::Reveal::All { return self; }