mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
ConstCx
stop using ParamEnv::reveal
This commit is contained in:
parent
84295b917d
commit
aab149b58c
@ -16,7 +16,7 @@ use rustc_middle::mir::visit::Visitor;
|
|||||||
use rustc_middle::mir::*;
|
use rustc_middle::mir::*;
|
||||||
use rustc_middle::span_bug;
|
use rustc_middle::span_bug;
|
||||||
use rustc_middle::ty::adjustment::PointerCoercion;
|
use rustc_middle::ty::adjustment::PointerCoercion;
|
||||||
use rustc_middle::ty::{self, Instance, InstanceKind, Ty, TypeVisitableExt, TypingMode};
|
use rustc_middle::ty::{self, Instance, InstanceKind, Ty, TypeVisitableExt};
|
||||||
use rustc_mir_dataflow::Analysis;
|
use rustc_mir_dataflow::Analysis;
|
||||||
use rustc_mir_dataflow::impls::MaybeStorageLive;
|
use rustc_mir_dataflow::impls::MaybeStorageLive;
|
||||||
use rustc_mir_dataflow::storage::always_storage_live_locals;
|
use rustc_mir_dataflow::storage::always_storage_live_locals;
|
||||||
@ -589,7 +589,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
|
|||||||
// Typeck only does a "non-const" check since it operates on HIR and cannot distinguish
|
// Typeck only does a "non-const" check since it operates on HIR and cannot distinguish
|
||||||
// which path expressions are getting called on and which path expressions are only used
|
// which path expressions are getting called on and which path expressions are only used
|
||||||
// as function pointers. This is required for correctness.
|
// as function pointers. This is required for correctness.
|
||||||
let infcx = tcx.infer_ctxt().build(TypingMode::from_param_env(param_env));
|
let infcx = tcx.infer_ctxt().build(body.phase.typing_mode());
|
||||||
let ocx = ObligationCtxt::new_with_diagnostics(&infcx);
|
let ocx = ObligationCtxt::new_with_diagnostics(&infcx);
|
||||||
|
|
||||||
let predicates = tcx.predicates_of(callee).instantiate(tcx, fn_args);
|
let predicates = tcx.predicates_of(callee).instantiate(tcx, fn_args);
|
||||||
|
@ -32,14 +32,7 @@ impl<'mir, 'tcx> ConstCx<'mir, 'tcx> {
|
|||||||
pub fn new(tcx: TyCtxt<'tcx>, body: &'mir mir::Body<'tcx>) -> Self {
|
pub fn new(tcx: TyCtxt<'tcx>, body: &'mir mir::Body<'tcx>) -> Self {
|
||||||
let def_id = body.source.def_id().expect_local();
|
let def_id = body.source.def_id().expect_local();
|
||||||
let param_env = tcx.param_env(def_id);
|
let param_env = tcx.param_env(def_id);
|
||||||
Self::new_with_param_env(tcx, body, param_env)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_with_param_env(
|
|
||||||
tcx: TyCtxt<'tcx>,
|
|
||||||
body: &'mir mir::Body<'tcx>,
|
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
|
||||||
) -> Self {
|
|
||||||
let const_kind = tcx.hir().body_const_context(body.source.def_id().expect_local());
|
let const_kind = tcx.hir().body_const_context(body.source.def_id().expect_local());
|
||||||
ConstCx { body, tcx, param_env, const_kind }
|
ConstCx { body, tcx, param_env, const_kind }
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ use rustc_middle::mir::CallSource;
|
|||||||
use rustc_middle::span_bug;
|
use rustc_middle::span_bug;
|
||||||
use rustc_middle::ty::print::{PrintTraitRefExt as _, with_no_trimmed_paths};
|
use rustc_middle::ty::print::{PrintTraitRefExt as _, with_no_trimmed_paths};
|
||||||
use rustc_middle::ty::{
|
use rustc_middle::ty::{
|
||||||
self, Closure, FnDef, FnPtr, GenericArgKind, GenericArgsRef, Param, TraitRef, Ty, TypingMode,
|
self, Closure, FnDef, FnPtr, GenericArgKind, GenericArgsRef, Param, TraitRef, Ty,
|
||||||
suggest_constraining_type_param,
|
suggest_constraining_type_param,
|
||||||
};
|
};
|
||||||
use rustc_middle::util::{CallDesugaringKind, CallKind, call_kind};
|
use rustc_middle::util::{CallDesugaringKind, CallKind, call_kind};
|
||||||
@ -116,7 +116,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
|
|||||||
let obligation =
|
let obligation =
|
||||||
Obligation::new(tcx, ObligationCause::dummy(), param_env, trait_ref);
|
Obligation::new(tcx, ObligationCause::dummy(), param_env, trait_ref);
|
||||||
|
|
||||||
let infcx = tcx.infer_ctxt().build(TypingMode::from_param_env(param_env));
|
let infcx = tcx.infer_ctxt().build(body.phase.typing_mode());
|
||||||
let mut selcx = SelectionContext::new(&infcx);
|
let mut selcx = SelectionContext::new(&infcx);
|
||||||
let implsrc = selcx.select(&obligation);
|
let implsrc = selcx.select(&obligation);
|
||||||
|
|
||||||
|
@ -19,9 +19,10 @@ use smallvec::SmallVec;
|
|||||||
|
|
||||||
use super::{BasicBlock, Const, Local, UserTypeProjection};
|
use super::{BasicBlock, Const, Local, UserTypeProjection};
|
||||||
use crate::mir::coverage::CoverageKind;
|
use crate::mir::coverage::CoverageKind;
|
||||||
use crate::traits::Reveal;
|
|
||||||
use crate::ty::adjustment::PointerCoercion;
|
use crate::ty::adjustment::PointerCoercion;
|
||||||
use crate::ty::{self, GenericArgsRef, List, Region, Ty, UserTypeAnnotationIndex};
|
use crate::ty::{
|
||||||
|
self, GenericArgsRef, List, Region, Ty, TyCtxt, TypingMode, UserTypeAnnotationIndex,
|
||||||
|
};
|
||||||
|
|
||||||
/// Represents the "flavors" of MIR.
|
/// Represents the "flavors" of MIR.
|
||||||
///
|
///
|
||||||
@ -102,10 +103,20 @@ impl MirPhase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reveal(&self) -> Reveal {
|
pub fn typing_mode<'tcx>(&self) -> TypingMode<'tcx> {
|
||||||
match *self {
|
match self {
|
||||||
MirPhase::Built | MirPhase::Analysis(_) => Reveal::UserFacing,
|
// FIXME(#132279): the MIR is quite clearly inside of a body, so we
|
||||||
MirPhase::Runtime(_) => Reveal::All,
|
// should instead reveal opaques defined by that body here.
|
||||||
|
MirPhase::Built | MirPhase::Analysis(_) => TypingMode::non_body_analysis(),
|
||||||
|
MirPhase::Runtime(_) => TypingMode::PostAnalysis,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn param_env<'tcx>(&self, tcx: TyCtxt<'tcx>, body_def_id: DefId) -> ty::ParamEnv<'tcx> {
|
||||||
|
match self.typing_mode() {
|
||||||
|
TypingMode::Coherence => unreachable!(),
|
||||||
|
TypingMode::Analysis { defining_opaque_types: _ } => tcx.param_env(body_def_id),
|
||||||
|
TypingMode::PostAnalysis => tcx.param_env_reveal_all_normalized(body_def_id),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,14 +5,14 @@ use rustc_hir::LangItem;
|
|||||||
use rustc_index::IndexVec;
|
use rustc_index::IndexVec;
|
||||||
use rustc_index::bit_set::BitSet;
|
use rustc_index::bit_set::BitSet;
|
||||||
use rustc_infer::infer::TyCtxtInferExt;
|
use rustc_infer::infer::TyCtxtInferExt;
|
||||||
use rustc_infer::traits::{Obligation, ObligationCause, Reveal};
|
use rustc_infer::traits::{Obligation, ObligationCause};
|
||||||
use rustc_middle::mir::coverage::CoverageKind;
|
use rustc_middle::mir::coverage::CoverageKind;
|
||||||
use rustc_middle::mir::visit::{NonUseContext, PlaceContext, Visitor};
|
use rustc_middle::mir::visit::{NonUseContext, PlaceContext, Visitor};
|
||||||
use rustc_middle::mir::*;
|
use rustc_middle::mir::*;
|
||||||
use rustc_middle::ty::adjustment::PointerCoercion;
|
use rustc_middle::ty::adjustment::PointerCoercion;
|
||||||
use rustc_middle::ty::{
|
use rustc_middle::ty::{
|
||||||
self, CoroutineArgsExt, InstanceKind, ParamEnv, ScalarInt, Ty, TyCtxt, TypeVisitableExt,
|
self, CoroutineArgsExt, InstanceKind, ParamEnv, ScalarInt, Ty, TyCtxt, TypeVisitableExt,
|
||||||
TypingMode, Variance,
|
Variance,
|
||||||
};
|
};
|
||||||
use rustc_middle::{bug, span_bug};
|
use rustc_middle::{bug, span_bug};
|
||||||
use rustc_target::abi::{FIRST_VARIANT, Size};
|
use rustc_target::abi::{FIRST_VARIANT, Size};
|
||||||
@ -50,11 +50,7 @@ impl<'tcx> crate::MirPass<'tcx> for Validator {
|
|||||||
}
|
}
|
||||||
let def_id = body.source.def_id();
|
let def_id = body.source.def_id();
|
||||||
let mir_phase = self.mir_phase;
|
let mir_phase = self.mir_phase;
|
||||||
let param_env = match mir_phase.reveal() {
|
let param_env = mir_phase.param_env(tcx, def_id);
|
||||||
Reveal::UserFacing => tcx.param_env(def_id),
|
|
||||||
Reveal::All => tcx.param_env_reveal_all_normalized(def_id),
|
|
||||||
};
|
|
||||||
|
|
||||||
let can_unwind = if mir_phase <= MirPhase::Runtime(RuntimePhase::Initial) {
|
let can_unwind = if mir_phase <= MirPhase::Runtime(RuntimePhase::Initial) {
|
||||||
// In this case `AbortUnwindingCalls` haven't yet been executed.
|
// In this case `AbortUnwindingCalls` haven't yet been executed.
|
||||||
true
|
true
|
||||||
@ -606,7 +602,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
let infcx = self.tcx.infer_ctxt().build(TypingMode::from_param_env(self.param_env));
|
let infcx = self.tcx.infer_ctxt().build(self.body.phase.typing_mode());
|
||||||
let ocx = ObligationCtxt::new(&infcx);
|
let ocx = ObligationCtxt::new(&infcx);
|
||||||
ocx.register_obligation(Obligation::new(
|
ocx.register_obligation(Obligation::new(
|
||||||
self.tcx,
|
self.tcx,
|
||||||
|
@ -17,7 +17,7 @@ use rustc_middle::mir::{
|
|||||||
};
|
};
|
||||||
use rustc_middle::traits::{BuiltinImplSource, ImplSource, ObligationCause};
|
use rustc_middle::traits::{BuiltinImplSource, ImplSource, ObligationCause};
|
||||||
use rustc_middle::ty::adjustment::PointerCoercion;
|
use rustc_middle::ty::adjustment::PointerCoercion;
|
||||||
use rustc_middle::ty::{self, GenericArgKind, TraitRef, Ty, TyCtxt, TypingMode};
|
use rustc_middle::ty::{self, GenericArgKind, TraitRef, Ty, TyCtxt};
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
use rustc_span::symbol::sym;
|
use rustc_span::symbol::sym;
|
||||||
use rustc_trait_selection::traits::{ObligationCtxt, SelectionContext};
|
use rustc_trait_selection::traits::{ObligationCtxt, SelectionContext};
|
||||||
@ -420,7 +420,7 @@ fn is_ty_const_destruct<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, body: &Body<'tcx>
|
|||||||
TraitRef::new(tcx, tcx.require_lang_item(LangItem::Destruct, Some(body.span)), [ty]),
|
TraitRef::new(tcx, tcx.require_lang_item(LangItem::Destruct, Some(body.span)), [ty]),
|
||||||
);
|
);
|
||||||
|
|
||||||
let infcx = tcx.infer_ctxt().build(TypingMode::from_param_env(obligation.param_env));
|
let infcx = tcx.infer_ctxt().build(body.phase.typing_mode());
|
||||||
let mut selcx = SelectionContext::new(&infcx);
|
let mut selcx = SelectionContext::new(&infcx);
|
||||||
let Some(impl_src) = selcx.select(&obligation).ok().flatten() else {
|
let Some(impl_src) = selcx.select(&obligation).ok().flatten() else {
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user