thir building: use typing_env directly
This commit is contained in:
parent
0f8405f702
commit
f4b516b10c
5 changed files with 32 additions and 67 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue