diff options
| author | lcnr <rust@lcnr.de> | 2024-11-22 12:17:50 +0100 |
|---|---|---|
| committer | lcnr <rust@lcnr.de> | 2024-11-23 13:51:57 +0100 |
| commit | f4b516b10c95c7b33d148d1c284d02a331acce2d (patch) | |
| tree | f6d9bbf956e5100219bb91de06bd90ed324a5d97 /compiler/rustc_pattern_analysis | |
| parent | 0f8405f702c2b6c2ddd34cf4b6c284e6f2575579 (diff) | |
| download | rust-f4b516b10c95c7b33d148d1c284d02a331acce2d.tar.gz rust-f4b516b10c95c7b33d148d1c284d02a331acce2d.zip | |
thir building: use typing_env directly
Diffstat (limited to 'compiler/rustc_pattern_analysis')
| -rw-r--r-- | compiler/rustc_pattern_analysis/src/rustc.rs | 38 |
1 files changed, 13 insertions, 25 deletions
diff --git a/compiler/rustc_pattern_analysis/src/rustc.rs b/compiler/rustc_pattern_analysis/src/rustc.rs index cc0763ac751..e6887d47396 100644 --- a/compiler/rustc_pattern_analysis/src/rustc.rs +++ b/compiler/rustc_pattern_analysis/src/rustc.rs @@ -9,7 +9,6 @@ use rustc_index::{Idx, IndexVec}; use rustc_middle::middle::stability::EvalResult; use rustc_middle::mir::{self, Const}; use rustc_middle::thir::{self, Pat, PatKind, PatRange, PatRangeBoundary}; -use rustc_middle::traits::Reveal; use rustc_middle::ty::layout::IntegerExt; use rustc_middle::ty::{ self, FieldDef, OpaqueTypeKey, ScalarInt, Ty, TyCtxt, TypeVisitableExt, VariantDef, @@ -86,7 +85,7 @@ pub struct RustcPatCtxt<'p, 'tcx: 'p> { /// not. E.g., `struct Foo { _private: ! }` cannot be seen to be empty /// outside its module and should not be matchable with an empty match statement. pub module: DefId, - pub param_env: ty::ParamEnv<'tcx>, + pub typing_env: ty::TypingEnv<'tcx>, /// To allocate the result of `self.ctor_sub_tys()` pub dropless_arena: &'p DroplessArena, /// Lint level at the match. @@ -109,17 +108,6 @@ impl<'p, 'tcx: 'p> fmt::Debug for RustcPatCtxt<'p, 'tcx> { } impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { - pub fn typing_mode(&self) -> ty::TypingMode<'tcx> { - debug_assert_eq!(self.param_env.reveal(), Reveal::UserFacing); - // FIXME(#132279): This is inside of a body. If we need to use the `param_env` - // and `typing_mode` we should reveal opaques defined by that body. - ty::TypingMode::non_body_analysis() - } - - pub fn typing_env(&self) -> ty::TypingEnv<'tcx> { - ty::TypingEnv { typing_mode: self.typing_mode(), param_env: self.param_env } - } - /// Type inference occasionally gives us opaque types in places where corresponding patterns /// have more specific types. To avoid inconsistencies as well as detect opaque uninhabited /// types, we use the corresponding concrete type if possible. @@ -151,7 +139,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { pub fn is_uninhabited(&self, ty: Ty<'tcx>) -> bool { !ty.inhabited_predicate(self.tcx).apply_revealing_opaque( self.tcx, - self.typing_env(), + self.typing_env, self.module, &|key| self.reveal_opaque_key(key), ) @@ -191,7 +179,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { variant.fields.iter().map(move |field| { let ty = field.ty(self.tcx, args); // `field.ty()` doesn't normalize after instantiating. - let ty = self.tcx.normalize_erasing_regions(self.typing_env(), ty); + let ty = self.tcx.normalize_erasing_regions(self.typing_env, ty); let ty = self.reveal_opaque_ty(ty); (field, ty) }) @@ -381,7 +369,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { let is_inhabited = v .inhabited_predicate(cx.tcx, *def) .instantiate(cx.tcx, args) - .apply_revealing_opaque(cx.tcx, cx.typing_env(), cx.module, &|key| { + .apply_revealing_opaque(cx.tcx, cx.typing_env, cx.module, &|key| { cx.reveal_opaque_key(key) }); // Variants that depend on a disabled unstable feature. @@ -442,7 +430,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { match bdy { PatRangeBoundary::NegInfinity => MaybeInfiniteInt::NegInfinity, PatRangeBoundary::Finite(value) => { - let bits = value.eval_bits(self.tcx, self.typing_env()); + let bits = value.eval_bits(self.tcx, self.typing_env); match *ty.kind() { ty::Int(ity) => { let size = Integer::from_int_ty(&self.tcx, ity).size().bits(); @@ -551,7 +539,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { PatKind::Constant { value } => { match ty.kind() { ty::Bool => { - ctor = match value.try_eval_bool(cx.tcx, cx.typing_env()) { + ctor = match value.try_eval_bool(cx.tcx, cx.typing_env) { Some(b) => Bool(b), None => Opaque(OpaqueId::new()), }; @@ -559,7 +547,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { arity = 0; } ty::Char | ty::Int(_) | ty::Uint(_) => { - ctor = match value.try_eval_bits(cx.tcx, cx.typing_env()) { + ctor = match value.try_eval_bits(cx.tcx, cx.typing_env) { Some(bits) => { let x = match *ty.kind() { ty::Int(ity) => { @@ -576,7 +564,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { arity = 0; } ty::Float(ty::FloatTy::F16) => { - ctor = match value.try_eval_bits(cx.tcx, cx.typing_env()) { + ctor = match value.try_eval_bits(cx.tcx, cx.typing_env) { Some(bits) => { use rustc_apfloat::Float; let value = rustc_apfloat::ieee::Half::from_bits(bits); @@ -588,7 +576,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { arity = 0; } ty::Float(ty::FloatTy::F32) => { - ctor = match value.try_eval_bits(cx.tcx, cx.typing_env()) { + ctor = match value.try_eval_bits(cx.tcx, cx.typing_env) { Some(bits) => { use rustc_apfloat::Float; let value = rustc_apfloat::ieee::Single::from_bits(bits); @@ -600,7 +588,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { arity = 0; } ty::Float(ty::FloatTy::F64) => { - ctor = match value.try_eval_bits(cx.tcx, cx.typing_env()) { + ctor = match value.try_eval_bits(cx.tcx, cx.typing_env) { Some(bits) => { use rustc_apfloat::Float; let value = rustc_apfloat::ieee::Double::from_bits(bits); @@ -612,7 +600,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { arity = 0; } ty::Float(ty::FloatTy::F128) => { - ctor = match value.try_eval_bits(cx.tcx, cx.typing_env()) { + ctor = match value.try_eval_bits(cx.tcx, cx.typing_env) { Some(bits) => { use rustc_apfloat::Float; let value = rustc_apfloat::ieee::Quad::from_bits(bits); @@ -661,8 +649,8 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { } ty::Float(fty) => { use rustc_apfloat::Float; - let lo = lo.as_finite().map(|c| c.eval_bits(cx.tcx, cx.typing_env())); - let hi = hi.as_finite().map(|c| c.eval_bits(cx.tcx, cx.typing_env())); + let lo = lo.as_finite().map(|c| c.eval_bits(cx.tcx, cx.typing_env)); + let hi = hi.as_finite().map(|c| c.eval_bits(cx.tcx, cx.typing_env)); match fty { ty::FloatTy::F16 => { use rustc_apfloat::ieee::Half; |
