Rollup merge of #64781 - Mark-Simulacrum:no-global-tcx, r=eddyb

Remove stray references to the old global tcx
This commit is contained in:
Mazdak Farrokhzad 2019-09-28 05:37:43 +02:00 committed by GitHub
commit 4db233e454
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
44 changed files with 97 additions and 209 deletions

View file

@ -590,7 +590,7 @@ impl DepGraph {
// mark it as green by recursively marking all of its // mark it as green by recursively marking all of its
// dependencies green. // dependencies green.
self.try_mark_previous_green( self.try_mark_previous_green(
tcx.global_tcx(), tcx,
data, data,
prev_index, prev_index,
&dep_node &dep_node

View file

@ -1462,7 +1462,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
// type-checking closure types are in local tables only. // type-checking closure types are in local tables only.
if !self.in_progress_tables.is_some() || !ty.has_closure_types() { if !self.in_progress_tables.is_some() || !ty.has_closure_types() {
if !(param_env, ty).has_local_value() { if !(param_env, ty).has_local_value() {
return ty.is_copy_modulo_regions(self.tcx.global_tcx(), param_env, span); return ty.is_copy_modulo_regions(self.tcx, param_env, span);
} }
} }

View file

@ -561,15 +561,13 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
def_id, instantiated_ty def_id, instantiated_ty
); );
let gcx = self.tcx.global_tcx();
// Use substs to build up a reverse map from regions to their // Use substs to build up a reverse map from regions to their
// identity mappings. This is necessary because of `impl // identity mappings. This is necessary because of `impl
// Trait` lifetimes are computed by replacing existing // Trait` lifetimes are computed by replacing existing
// lifetimes with 'static and remapping only those used in the // lifetimes with 'static and remapping only those used in the
// `impl Trait` return type, resulting in the parameters // `impl Trait` return type, resulting in the parameters
// shifting. // shifting.
let id_substs = InternalSubsts::identity_for_item(gcx, def_id); let id_substs = InternalSubsts::identity_for_item(self.tcx, def_id);
let map: FxHashMap<GenericArg<'tcx>, GenericArg<'tcx>> = opaque_defn let map: FxHashMap<GenericArg<'tcx>, GenericArg<'tcx>> = opaque_defn
.substs .substs
.iter() .iter()
@ -854,7 +852,7 @@ impl TypeFolder<'tcx> for ReverseMapper<'tcx> {
) )
.emit(); .emit();
self.tcx().global_tcx().mk_region(ty::ReStatic) self.tcx().mk_region(ty::ReStatic)
}, },
} }
} }

View file

@ -82,7 +82,7 @@ impl ExprVisitor<'tcx> {
// Special-case transmutting from `typeof(function)` and // Special-case transmutting from `typeof(function)` and
// `Option<typeof(function)>` to present a clearer error. // `Option<typeof(function)>` to present a clearer error.
let from = unpack_option_like(self.tcx.global_tcx(), from); let from = unpack_option_like(self.tcx, from);
if let (&ty::FnDef(..), SizeSkeleton::Known(size_to)) = (&from.kind, sk_to) { if let (&ty::FnDef(..), SizeSkeleton::Known(size_to)) = (&from.kind, sk_to) {
if size_to == Pointer.size(&self.tcx) { if size_to == Pointer.size(&self.tcx) {
struct_span_err!(self.tcx.sess, span, E0591, struct_span_err!(self.tcx.sess, span, E0591,

View file

@ -749,7 +749,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
.unwrap_or(ty::ClosureKind::LATTICE_BOTTOM), .unwrap_or(ty::ClosureKind::LATTICE_BOTTOM),
None => None =>
closure_substs.closure_kind(closure_def_id, self.tcx.global_tcx()), closure_substs.closure_kind(closure_def_id, self.tcx),
} }
} }
_ => span_bug!(span, "unexpected type for fn in mem_categorization: {:?}", ty), _ => span_bug!(span, "unexpected type for fn in mem_categorization: {:?}", ty),

View file

@ -1504,7 +1504,7 @@ impl<'tcx> TerminatorKind<'tcx> {
Goto { .. } => vec!["".into()], Goto { .. } => vec!["".into()],
SwitchInt { ref values, switch_ty, .. } => ty::tls::with(|tcx| { SwitchInt { ref values, switch_ty, .. } => ty::tls::with(|tcx| {
let param_env = ty::ParamEnv::empty(); let param_env = ty::ParamEnv::empty();
let switch_ty = tcx.lift_to_global(&switch_ty).unwrap(); let switch_ty = tcx.lift(&switch_ty).unwrap();
let size = tcx.layout_of(param_env.and(switch_ty)).unwrap().size; let size = tcx.layout_of(param_env.and(switch_ty)).unwrap().size;
values values
.iter() .iter()

View file

@ -108,7 +108,7 @@ impl TraitEngine<'tcx> for FulfillmentContext<'tcx> {
goal: obligation.goal.predicate, goal: obligation.goal.predicate,
}, &mut orig_values); }, &mut orig_values);
match infcx.tcx.global_tcx().evaluate_goal(canonical_goal) { match infcx.tcx.evaluate_goal(canonical_goal) {
Ok(response) => { Ok(response) => {
if response.is_proven() { if response.is_proven() {
making_progress = true; making_progress = true;

View file

@ -497,7 +497,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
4 4
}; };
let normalize = |candidate| self.tcx.global_tcx().infer_ctxt().enter(|ref infcx| { let normalize = |candidate| self.tcx.infer_ctxt().enter(|ref infcx| {
let normalized = infcx let normalized = infcx
.at(&ObligationCause::dummy(), ty::ParamEnv::empty()) .at(&ObligationCause::dummy(), ty::ParamEnv::empty())
.normalize(candidate) .normalize(candidate)
@ -783,8 +783,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
} }
ty::Predicate::ObjectSafe(trait_def_id) => { ty::Predicate::ObjectSafe(trait_def_id) => {
let violations = self.tcx.global_tcx() let violations = self.tcx.object_safety_violations(trait_def_id);
.object_safety_violations(trait_def_id);
if let Some(err) = self.tcx.report_object_safety_error( if let Some(err) = self.tcx.report_object_safety_error(
span, span,
trait_def_id, trait_def_id,
@ -920,7 +919,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
} }
TraitNotObjectSafe(did) => { TraitNotObjectSafe(did) => {
let violations = self.tcx.global_tcx().object_safety_violations(did); let violations = self.tcx.object_safety_violations(did);
if let Some(err) = self.tcx.report_object_safety_error(span, did, violations) { if let Some(err) = self.tcx.report_object_safety_error(span, did, violations) {
err err
} else { } else {

View file

@ -495,7 +495,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
} else { } else {
if !substs.has_local_value() { if !substs.has_local_value() {
let instance = ty::Instance::resolve( let instance = ty::Instance::resolve(
self.selcx.tcx().global_tcx(), self.selcx.tcx(),
obligation.param_env, obligation.param_env,
def_id, def_id,
substs, substs,

View file

@ -40,12 +40,11 @@ impl<'cx, 'tcx> At<'cx, 'tcx> {
}; };
} }
let gcx = tcx.global_tcx();
let mut orig_values = OriginalQueryValues::default(); let mut orig_values = OriginalQueryValues::default();
let c_ty = self.infcx.canonicalize_query(&self.param_env.and(ty), &mut orig_values); let c_ty = self.infcx.canonicalize_query(&self.param_env.and(ty), &mut orig_values);
let span = self.cause.span; let span = self.cause.span;
debug!("c_ty = {:?}", c_ty); debug!("c_ty = {:?}", c_ty);
if let Ok(result) = &gcx.dropck_outlives(c_ty) { if let Ok(result) = &tcx.dropck_outlives(c_ty) {
if result.is_proven() { if result.is_proven() {
if let Ok(InferOk { value, obligations }) = if let Ok(InferOk { value, obligations }) =
self.infcx.instantiate_query_response_and_region_obligations( self.infcx.instantiate_query_response_and_region_obligations(

View file

@ -50,7 +50,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
// Run canonical query. If overflow occurs, rerun from scratch but this time // Run canonical query. If overflow occurs, rerun from scratch but this time
// in standard trait query mode so that overflow is handled appropriately // in standard trait query mode so that overflow is handled appropriately
// within `SelectionContext`. // within `SelectionContext`.
self.tcx.global_tcx().evaluate_obligation(c_pred) self.tcx.evaluate_obligation(c_pred)
} }
// Helper function that canonicalizes and runs the query. If an // Helper function that canonicalizes and runs the query. If an

View file

@ -141,7 +141,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
// binder). It would be better to normalize in a // binder). It would be better to normalize in a
// binding-aware fashion. // binding-aware fashion.
let gcx = self.infcx.tcx.global_tcx(); let tcx = self.infcx.tcx;
let mut orig_values = OriginalQueryValues::default(); let mut orig_values = OriginalQueryValues::default();
// HACK(matthewjasper) `'static` is special-cased in selection, // HACK(matthewjasper) `'static` is special-cased in selection,
@ -150,7 +150,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
&self.param_env.and(*data), &mut orig_values); &self.param_env.and(*data), &mut orig_values);
debug!("QueryNormalizer: c_data = {:#?}", c_data); debug!("QueryNormalizer: c_data = {:#?}", c_data);
debug!("QueryNormalizer: orig_values = {:#?}", orig_values); debug!("QueryNormalizer: orig_values = {:#?}", orig_values);
match gcx.normalize_projection_ty(c_data) { match tcx.normalize_projection_ty(c_data) {
Ok(result) => { Ok(result) => {
// We don't expect ambiguity. // We don't expect ambiguity.
if result.is_ambiguous() { if result.is_ambiguous() {

View file

@ -97,7 +97,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
let mut orig_values = OriginalQueryValues::default(); let mut orig_values = OriginalQueryValues::default();
let key = self.canonicalize_query(&param_env.and(ty), &mut orig_values); let key = self.canonicalize_query(&param_env.and(ty), &mut orig_values);
let result = match self.tcx.global_tcx().implied_outlives_bounds(key) { let result = match self.tcx.implied_outlives_bounds(key) {
Ok(r) => r, Ok(r) => r,
Err(NoSolution) => { Err(NoSolution) => {
self.tcx.sess.delay_span_bug( self.tcx.sess.delay_span_bug(

View file

@ -1,4 +1,4 @@
use crate::infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse}; use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse};
use crate::traits::query::Fallible; use crate::traits::query::Fallible;
use crate::hir::def_id::DefId; use crate::hir::def_id::DefId;
use crate::ty::{ParamEnvAnd, Ty, TyCtxt}; use crate::ty::{ParamEnvAnd, Ty, TyCtxt};
@ -37,12 +37,6 @@ impl<'tcx> super::QueryTypeOp<'tcx> for AscribeUserType<'tcx> {
) -> Fallible<CanonicalizedQueryResponse<'tcx, ()>> { ) -> Fallible<CanonicalizedQueryResponse<'tcx, ()>> {
tcx.type_op_ascribe_user_type(canonicalized) tcx.type_op_ascribe_user_type(canonicalized)
} }
fn shrink_to_tcx_lifetime(
v: &'a CanonicalizedQueryResponse<'tcx, ()>,
) -> &'a Canonical<'tcx, QueryResponse<'tcx, ()>> {
v
}
} }
BraceStructTypeFoldableImpl! { BraceStructTypeFoldableImpl! {

View file

@ -1,4 +1,4 @@
use crate::infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse}; use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse};
use crate::traits::query::Fallible; use crate::traits::query::Fallible;
use crate::ty::{ParamEnvAnd, Ty, TyCtxt}; use crate::ty::{ParamEnvAnd, Ty, TyCtxt};
@ -34,12 +34,6 @@ impl<'tcx> super::QueryTypeOp<'tcx> for Eq<'tcx> {
) -> Fallible<CanonicalizedQueryResponse<'tcx, ()>> { ) -> Fallible<CanonicalizedQueryResponse<'tcx, ()>> {
tcx.type_op_eq(canonicalized) tcx.type_op_eq(canonicalized)
} }
fn shrink_to_tcx_lifetime(
v: &'a CanonicalizedQueryResponse<'tcx, ()>,
) -> &'a Canonical<'tcx, QueryResponse<'tcx, ()>> {
v
}
} }
BraceStructTypeFoldableImpl! { BraceStructTypeFoldableImpl! {

View file

@ -1,4 +1,4 @@
use crate::infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse}; use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse};
use crate::traits::query::outlives_bounds::OutlivesBound; use crate::traits::query::outlives_bounds::OutlivesBound;
use crate::traits::query::Fallible; use crate::traits::query::Fallible;
use crate::ty::{ParamEnvAnd, Ty, TyCtxt}; use crate::ty::{ParamEnvAnd, Ty, TyCtxt};
@ -38,12 +38,6 @@ impl<'tcx> super::QueryTypeOp<'tcx> for ImpliedOutlivesBounds<'tcx> {
tcx.implied_outlives_bounds(canonicalized) tcx.implied_outlives_bounds(canonicalized)
} }
fn shrink_to_tcx_lifetime(
v: &'a CanonicalizedQueryResponse<'tcx, Self::QueryResponse>,
) -> &'a Canonical<'tcx, QueryResponse<'tcx, Self::QueryResponse>> {
v
}
} }
BraceStructTypeFoldableImpl! { BraceStructTypeFoldableImpl! {

View file

@ -1,6 +1,6 @@
use crate::infer::canonical::{ use crate::infer::canonical::{
Canonical, Canonicalized, CanonicalizedQueryResponse, OriginalQueryValues, Canonicalized, CanonicalizedQueryResponse, OriginalQueryValues,
QueryRegionConstraints, QueryResponse, QueryRegionConstraints,
}; };
use crate::infer::{InferCtxt, InferOk}; use crate::infer::{InferCtxt, InferOk};
use std::fmt; use std::fmt;
@ -66,22 +66,6 @@ pub trait QueryTypeOp<'tcx>: fmt::Debug + Sized + TypeFoldable<'tcx> + 'tcx {
canonicalized: Canonicalized<'tcx, ParamEnvAnd<'tcx, Self>>, canonicalized: Canonicalized<'tcx, ParamEnvAnd<'tcx, Self>>,
) -> Fallible<CanonicalizedQueryResponse<'tcx, Self::QueryResponse>>; ) -> Fallible<CanonicalizedQueryResponse<'tcx, Self::QueryResponse>>;
/// Casts a lifted query result (which is in the gcx lifetime)
/// into the tcx lifetime. This is always just an identity cast,
/// but the generic code doesn't realize it -- put another way, in
/// the generic code, we have a `Lifted<'tcx, Self::QueryResponse>`
/// and we want to convert that to a `Self::QueryResponse`. This is
/// not a priori valid, so we can't do it -- but in practice, it
/// is always a no-op (e.g., the lifted form of a type,
/// `Ty<'tcx>`, is a subtype of `Ty<'tcx>`). So we have to push
/// the operation into the impls that know more specifically what
/// `QueryResponse` is. This operation would (maybe) be nicer with
/// something like HKTs or GATs, since then we could make
/// `QueryResponse` parametric and `'tcx` and `'tcx` etc.
fn shrink_to_tcx_lifetime(
lifted_query_result: &'a CanonicalizedQueryResponse<'tcx, Self::QueryResponse>,
) -> &'a Canonical<'tcx, QueryResponse<'tcx, Self::QueryResponse>>;
fn fully_perform_into( fn fully_perform_into(
query_key: ParamEnvAnd<'tcx, Self>, query_key: ParamEnvAnd<'tcx, Self>,
infcx: &InferCtxt<'_, 'tcx>, infcx: &InferCtxt<'_, 'tcx>,
@ -99,7 +83,6 @@ pub trait QueryTypeOp<'tcx>: fmt::Debug + Sized + TypeFoldable<'tcx> + 'tcx {
let canonical_self = let canonical_self =
infcx.canonicalize_hr_query_hack(&query_key, &mut canonical_var_values); infcx.canonicalize_hr_query_hack(&query_key, &mut canonical_var_values);
let canonical_result = Self::perform_query(infcx.tcx, canonical_self)?; let canonical_result = Self::perform_query(infcx.tcx, canonical_self)?;
let canonical_result = Self::shrink_to_tcx_lifetime(&canonical_result);
let param_env = query_key.param_env; let param_env = query_key.param_env;

View file

@ -1,4 +1,4 @@
use crate::infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse}; use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse};
use std::fmt; use std::fmt;
use crate::traits::query::Fallible; use crate::traits::query::Fallible;
use crate::ty::fold::TypeFoldable; use crate::ty::fold::TypeFoldable;
@ -38,12 +38,6 @@ where
) -> Fallible<CanonicalizedQueryResponse<'tcx, Self::QueryResponse>> { ) -> Fallible<CanonicalizedQueryResponse<'tcx, Self::QueryResponse>> {
T::type_op_method(tcx, canonicalized) T::type_op_method(tcx, canonicalized)
} }
fn shrink_to_tcx_lifetime(
v: &'a CanonicalizedQueryResponse<'tcx, T>,
) -> &'a Canonical<'tcx, QueryResponse<'tcx, T>> {
T::shrink_to_tcx_lifetime(v)
}
} }
pub trait Normalizable<'tcx>: fmt::Debug + TypeFoldable<'tcx> + Lift<'tcx> + Copy { pub trait Normalizable<'tcx>: fmt::Debug + TypeFoldable<'tcx> + Lift<'tcx> + Copy {
@ -51,12 +45,6 @@ pub trait Normalizable<'tcx>: fmt::Debug + TypeFoldable<'tcx> + Lift<'tcx> + Cop
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
canonicalized: Canonicalized<'tcx, ParamEnvAnd<'tcx, Normalize<Self>>>, canonicalized: Canonicalized<'tcx, ParamEnvAnd<'tcx, Normalize<Self>>>,
) -> Fallible<CanonicalizedQueryResponse<'tcx, Self>>; ) -> Fallible<CanonicalizedQueryResponse<'tcx, Self>>;
/// Converts from the `'tcx` (lifted) form of `Self` into the `tcx`
/// form of `Self`.
fn shrink_to_tcx_lifetime(
v: &'a CanonicalizedQueryResponse<'tcx, Self>,
) -> &'a Canonical<'tcx, QueryResponse<'tcx, Self>>;
} }
impl Normalizable<'tcx> for Ty<'tcx> { impl Normalizable<'tcx> for Ty<'tcx> {
@ -66,12 +54,6 @@ impl Normalizable<'tcx> for Ty<'tcx> {
) -> Fallible<CanonicalizedQueryResponse<'tcx, Self>> { ) -> Fallible<CanonicalizedQueryResponse<'tcx, Self>> {
tcx.type_op_normalize_ty(canonicalized) tcx.type_op_normalize_ty(canonicalized)
} }
fn shrink_to_tcx_lifetime(
v: &'a CanonicalizedQueryResponse<'tcx, Self>,
) -> &'a Canonical<'tcx, QueryResponse<'tcx, Self>> {
v
}
} }
impl Normalizable<'tcx> for ty::Predicate<'tcx> { impl Normalizable<'tcx> for ty::Predicate<'tcx> {
@ -81,12 +63,6 @@ impl Normalizable<'tcx> for ty::Predicate<'tcx> {
) -> Fallible<CanonicalizedQueryResponse<'tcx, Self>> { ) -> Fallible<CanonicalizedQueryResponse<'tcx, Self>> {
tcx.type_op_normalize_predicate(canonicalized) tcx.type_op_normalize_predicate(canonicalized)
} }
fn shrink_to_tcx_lifetime(
v: &'a CanonicalizedQueryResponse<'tcx, Self>,
) -> &'a Canonical<'tcx, QueryResponse<'tcx, Self>> {
v
}
} }
impl Normalizable<'tcx> for ty::PolyFnSig<'tcx> { impl Normalizable<'tcx> for ty::PolyFnSig<'tcx> {
@ -96,12 +72,6 @@ impl Normalizable<'tcx> for ty::PolyFnSig<'tcx> {
) -> Fallible<CanonicalizedQueryResponse<'tcx, Self>> { ) -> Fallible<CanonicalizedQueryResponse<'tcx, Self>> {
tcx.type_op_normalize_poly_fn_sig(canonicalized) tcx.type_op_normalize_poly_fn_sig(canonicalized)
} }
fn shrink_to_tcx_lifetime(
v: &'a CanonicalizedQueryResponse<'tcx, Self>,
) -> &'a Canonical<'tcx, QueryResponse<'tcx, Self>> {
v
}
} }
impl Normalizable<'tcx> for ty::FnSig<'tcx> { impl Normalizable<'tcx> for ty::FnSig<'tcx> {
@ -111,12 +81,6 @@ impl Normalizable<'tcx> for ty::FnSig<'tcx> {
) -> Fallible<CanonicalizedQueryResponse<'tcx, Self>> { ) -> Fallible<CanonicalizedQueryResponse<'tcx, Self>> {
tcx.type_op_normalize_fn_sig(canonicalized) tcx.type_op_normalize_fn_sig(canonicalized)
} }
fn shrink_to_tcx_lifetime(
v: &'a CanonicalizedQueryResponse<'tcx, Self>,
) -> &'a Canonical<'tcx, QueryResponse<'tcx, Self>> {
v
}
} }
BraceStructTypeFoldableImpl! { BraceStructTypeFoldableImpl! {

View file

@ -1,4 +1,4 @@
use crate::infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse}; use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse};
use crate::traits::query::dropck_outlives::trivial_dropck_outlives; use crate::traits::query::dropck_outlives::trivial_dropck_outlives;
use crate::traits::query::dropck_outlives::DropckOutlivesResult; use crate::traits::query::dropck_outlives::DropckOutlivesResult;
use crate::traits::query::Fallible; use crate::traits::query::Fallible;
@ -53,12 +53,6 @@ impl super::QueryTypeOp<'tcx> for DropckOutlives<'tcx> {
tcx.dropck_outlives(canonicalized) tcx.dropck_outlives(canonicalized)
} }
fn shrink_to_tcx_lifetime(
lifted_query_result: &'a CanonicalizedQueryResponse<'tcx, Self::QueryResponse>,
) -> &'a Canonical<'tcx, QueryResponse<'tcx, Self::QueryResponse>> {
lifted_query_result
}
} }
BraceStructTypeFoldableImpl! { BraceStructTypeFoldableImpl! {

View file

@ -1,4 +1,4 @@
use crate::infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse}; use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse};
use crate::traits::query::Fallible; use crate::traits::query::Fallible;
use crate::ty::{ParamEnvAnd, Predicate, TyCtxt}; use crate::ty::{ParamEnvAnd, Predicate, TyCtxt};
@ -43,12 +43,6 @@ impl<'tcx> super::QueryTypeOp<'tcx> for ProvePredicate<'tcx> {
) -> Fallible<CanonicalizedQueryResponse<'tcx, ()>> { ) -> Fallible<CanonicalizedQueryResponse<'tcx, ()>> {
tcx.type_op_prove_predicate(canonicalized) tcx.type_op_prove_predicate(canonicalized)
} }
fn shrink_to_tcx_lifetime(
v: &'a CanonicalizedQueryResponse<'tcx, ()>,
) -> &'a Canonical<'tcx, QueryResponse<'tcx, ()>> {
v
}
} }
BraceStructTypeFoldableImpl! { BraceStructTypeFoldableImpl! {

View file

@ -1,4 +1,4 @@
use crate::infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse}; use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse};
use crate::traits::query::Fallible; use crate::traits::query::Fallible;
use crate::ty::{ParamEnvAnd, Ty, TyCtxt}; use crate::ty::{ParamEnvAnd, Ty, TyCtxt};
@ -34,12 +34,6 @@ impl<'tcx> super::QueryTypeOp<'tcx> for Subtype<'tcx> {
) -> Fallible<CanonicalizedQueryResponse<'tcx, ()>> { ) -> Fallible<CanonicalizedQueryResponse<'tcx, ()>> {
tcx.type_op_subtype(canonicalized) tcx.type_op_subtype(canonicalized)
} }
fn shrink_to_tcx_lifetime(
v: &'a CanonicalizedQueryResponse<'tcx, ()>,
) -> &'a Canonical<'tcx, QueryResponse<'tcx, ()>> {
v
}
} }
BraceStructTypeFoldableImpl! { BraceStructTypeFoldableImpl! {

View file

@ -2491,7 +2491,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
if other.evaluation.must_apply_modulo_regions() { if other.evaluation.must_apply_modulo_regions() {
match victim.candidate { match victim.candidate {
ImplCandidate(victim_def) => { ImplCandidate(victim_def) => {
let tcx = self.tcx().global_tcx(); let tcx = self.tcx();
return tcx.specializes((other_def, victim_def)) return tcx.specializes((other_def, victim_def))
|| tcx.impls_are_allowed_to_overlap( || tcx.impls_are_allowed_to_overlap(
other_def, victim_def).is_some(); other_def, victim_def).is_some();

View file

@ -162,7 +162,6 @@ impl<'tcx> Children {
} }
}; };
let tcx = tcx.global_tcx();
let (le, ge) = traits::overlapping_impls( let (le, ge) = traits::overlapping_impls(
tcx, tcx,
possible_sibling, possible_sibling,

View file

@ -661,8 +661,7 @@ impl<'tcx> TyCtxt<'tcx> {
} }
} }
None => { None => {
self.global_tcx() self.impl_defaultness(node_item_def_id)
.impl_defaultness(node_item_def_id)
.is_default() .is_default()
} }
} }

View file

@ -1067,14 +1067,6 @@ pub struct GlobalCtxt<'tcx> {
} }
impl<'tcx> TyCtxt<'tcx> { impl<'tcx> TyCtxt<'tcx> {
/// Gets the global `TyCtxt`.
#[inline]
pub fn global_tcx(self) -> TyCtxt<'tcx> {
TyCtxt {
gcx: self.gcx,
}
}
#[inline(always)] #[inline(always)]
pub fn hir(self) -> &'tcx hir_map::Map<'tcx> { pub fn hir(self) -> &'tcx hir_map::Map<'tcx> {
&self.hir_map &self.hir_map
@ -1156,11 +1148,6 @@ impl<'tcx> TyCtxt<'tcx> {
value.lift_to_tcx(self) value.lift_to_tcx(self)
} }
/// Like lift, but only tries in the global tcx.
pub fn lift_to_global<T: ?Sized + Lift<'tcx>>(self, value: &T) -> Option<T::Lifted> {
value.lift_to_tcx(self.global_tcx())
}
/// Creates a type context and call the closure with a `TyCtxt` reference /// Creates a type context and call the closure with a `TyCtxt` reference
/// to the context. The closure enforces that the type context and any interned /// to the context. The closure enforces that the type context and any interned
/// value (types, substs, etc.) can only be used while `ty::tls` has a valid /// value (types, substs, etc.) can only be used while `ty::tls` has a valid
@ -1432,7 +1419,7 @@ impl<'tcx> TyCtxt<'tcx> {
-> Result<(), E::Error> -> Result<(), E::Error>
where E: ty::codec::TyEncoder where E: ty::codec::TyEncoder
{ {
self.queries.on_disk_cache.serialize(self.global_tcx(), encoder) self.queries.on_disk_cache.serialize(self, encoder)
} }
/// If `true`, we should use the MIR-based borrowck, but also /// If `true`, we should use the MIR-based borrowck, but also
@ -1600,7 +1587,7 @@ impl<'tcx> GlobalCtxt<'tcx> {
let tcx = TyCtxt { let tcx = TyCtxt {
gcx: self, gcx: self,
}; };
ty::tls::with_related_context(tcx.global_tcx(), |icx| { ty::tls::with_related_context(tcx, |icx| {
let new_icx = ty::tls::ImplicitCtxt { let new_icx = ty::tls::ImplicitCtxt {
tcx, tcx,
query: icx.query.clone(), query: icx.query.clone(),
@ -2425,7 +2412,7 @@ impl<'tcx> TyCtxt<'tcx> {
#[inline] #[inline]
pub fn mk_array(self, ty: Ty<'tcx>, n: u64) -> Ty<'tcx> { pub fn mk_array(self, ty: Ty<'tcx>, n: u64) -> Ty<'tcx> {
self.mk_ty(Array(ty, ty::Const::from_usize(self.global_tcx(), n))) self.mk_ty(Array(ty, ty::Const::from_usize(self, n)))
} }
#[inline] #[inline]
@ -2640,7 +2627,7 @@ impl<'tcx> TyCtxt<'tcx> {
if ts.len() == 0 { if ts.len() == 0 {
List::empty() List::empty()
} else { } else {
self.global_tcx()._intern_canonical_var_infos(ts) self._intern_canonical_var_infos(ts)
} }
} }

View file

@ -193,7 +193,7 @@ impl<'tcx> ty::TyS<'tcx> {
ty::Adt(def, _) => format!("{} `{}`", def.descr(), tcx.def_path_str(def.did)).into(), ty::Adt(def, _) => format!("{} `{}`", def.descr(), tcx.def_path_str(def.did)).into(),
ty::Foreign(def_id) => format!("extern type `{}`", tcx.def_path_str(def_id)).into(), ty::Foreign(def_id) => format!("extern type `{}`", tcx.def_path_str(def_id)).into(),
ty::Array(_, n) => { ty::Array(_, n) => {
let n = tcx.lift_to_global(&n).unwrap(); let n = tcx.lift(&n).unwrap();
match n.try_eval_usize(tcx, ty::ParamEnv::empty()) { match n.try_eval_usize(tcx, ty::ParamEnv::empty()) {
Some(n) => { Some(n) => {
format!("array of {} element{}", n, pluralise!(n)).into() format!("array of {} element{}", n, pluralise!(n)).into()

View file

@ -210,7 +210,7 @@ impl<'tcx> Instance<'tcx> {
} }
pub fn mono(tcx: TyCtxt<'tcx>, def_id: DefId) -> Instance<'tcx> { pub fn mono(tcx: TyCtxt<'tcx>, def_id: DefId) -> Instance<'tcx> {
Instance::new(def_id, tcx.global_tcx().empty_substs_for_def_id(def_id)) Instance::new(def_id, tcx.empty_substs_for_def_id(def_id))
} }
#[inline] #[inline]

View file

@ -1883,7 +1883,7 @@ impl<'tcx> HasDataLayout for TyCtxt<'tcx> {
impl<'tcx> HasTyCtxt<'tcx> for TyCtxt<'tcx> { impl<'tcx> HasTyCtxt<'tcx> for TyCtxt<'tcx> {
fn tcx(&self) -> TyCtxt<'tcx> { fn tcx(&self) -> TyCtxt<'tcx> {
self.global_tcx() *self
} }
} }
@ -2003,7 +2003,7 @@ impl TyCtxt<'tcx> {
pub fn layout_of(self, param_env_and_ty: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) pub fn layout_of(self, param_env_and_ty: ty::ParamEnvAnd<'tcx, Ty<'tcx>>)
-> Result<TyLayout<'tcx>, LayoutError<'tcx>> { -> Result<TyLayout<'tcx>, LayoutError<'tcx>> {
let cx = LayoutCx { let cx = LayoutCx {
tcx: self.global_tcx(), tcx: self,
param_env: param_env_and_ty.param_env param_env: param_env_and_ty.param_env
}; };
cx.layout_of(param_env_and_ty.value) cx.layout_of(param_env_and_ty.value)
@ -2017,7 +2017,7 @@ impl ty::query::TyCtxtAt<'tcx> {
pub fn layout_of(self, param_env_and_ty: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) pub fn layout_of(self, param_env_and_ty: ty::ParamEnvAnd<'tcx, Ty<'tcx>>)
-> Result<TyLayout<'tcx>, LayoutError<'tcx>> { -> Result<TyLayout<'tcx>, LayoutError<'tcx>> {
let cx = LayoutCx { let cx = LayoutCx {
tcx: self.global_tcx().at(self.span), tcx: self.at(self.span),
param_env: param_env_and_ty.param_env param_env: param_env_and_ty.param_env
}; };
cx.layout_of(param_env_and_ty.value) cx.layout_of(param_env_and_ty.value)

View file

@ -2378,7 +2378,7 @@ impl<'tcx> AdtDef {
pub fn eval_explicit_discr(&self, tcx: TyCtxt<'tcx>, expr_did: DefId) -> Option<Discr<'tcx>> { pub fn eval_explicit_discr(&self, tcx: TyCtxt<'tcx>, expr_did: DefId) -> Option<Discr<'tcx>> {
let param_env = tcx.param_env(expr_did); let param_env = tcx.param_env(expr_did);
let repr_type = self.repr.discr_type(); let repr_type = self.repr.discr_type();
let substs = InternalSubsts::identity_for_item(tcx.global_tcx(), expr_did); let substs = InternalSubsts::identity_for_item(tcx, expr_did);
let instance = ty::Instance::new(expr_did, substs); let instance = ty::Instance::new(expr_did, substs);
let cid = GlobalId { let cid = GlobalId {
instance, instance,
@ -2387,7 +2387,7 @@ impl<'tcx> AdtDef {
match tcx.const_eval(param_env.and(cid)) { match tcx.const_eval(param_env.and(cid)) {
Ok(val) => { Ok(val) => {
// FIXME: Find the right type and use it instead of `val.ty` here // FIXME: Find the right type and use it instead of `val.ty` here
if let Some(b) = val.try_eval_bits(tcx.global_tcx(), param_env, val.ty) { if let Some(b) = val.try_eval_bits(tcx, param_env, val.ty) {
trace!("discriminants: {} ({:?})", b, repr_type); trace!("discriminants: {} ({:?})", b, repr_type);
Some(Discr { Some(Discr {
val: b, val: b,
@ -2423,7 +2423,7 @@ impl<'tcx> AdtDef {
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
) -> impl Iterator<Item = (VariantIdx, Discr<'tcx>)> + Captures<'tcx> { ) -> impl Iterator<Item = (VariantIdx, Discr<'tcx>)> + Captures<'tcx> {
let repr_type = self.repr.discr_type(); let repr_type = self.repr.discr_type();
let initial = repr_type.initial_discriminant(tcx.global_tcx()); let initial = repr_type.initial_discriminant(tcx);
let mut prev_discr = None::<Discr<'tcx>>; let mut prev_discr = None::<Discr<'tcx>>;
self.variants.iter_enumerated().map(move |(i, v)| { self.variants.iter_enumerated().map(move |(i, v)| {
let mut discr = prev_discr.map_or(initial, |d| d.wrap_incr(tcx)); let mut discr = prev_discr.map_or(initial, |d| d.wrap_incr(tcx));
@ -2457,7 +2457,7 @@ impl<'tcx> AdtDef {
let (val, offset) = self.discriminant_def_for_variant(variant_index); let (val, offset) = self.discriminant_def_for_variant(variant_index);
let explicit_value = val let explicit_value = val
.and_then(|expr_did| self.eval_explicit_discr(tcx, expr_did)) .and_then(|expr_did| self.eval_explicit_discr(tcx, expr_did))
.unwrap_or_else(|| self.repr.discr_type().initial_discriminant(tcx.global_tcx())); .unwrap_or_else(|| self.repr.discr_type().initial_discriminant(tcx));
explicit_value.checked_add(tcx, offset as u128).0 explicit_value.checked_add(tcx, offset as u128).0
} }

View file

@ -917,7 +917,7 @@ pub trait PrettyPrinter<'tcx>:
let min = 1u128 << (bit_size - 1); let min = 1u128 << (bit_size - 1);
let max = min - 1; let max = min - 1;
let ty = self.tcx().lift_to_global(&ct.ty).unwrap(); let ty = self.tcx().lift(&ct.ty).unwrap();
let size = self.tcx().layout_of(ty::ParamEnv::empty().and(ty)) let size = self.tcx().layout_of(ty::ParamEnv::empty().and(ty))
.unwrap() .unwrap()
.size; .size;

View file

@ -265,7 +265,7 @@ impl<'tcx> TyCtxt<'tcx> {
tls::with_related_context(self, move |current_icx| { tls::with_related_context(self, move |current_icx| {
// Update the `ImplicitCtxt` to point to our new query job. // Update the `ImplicitCtxt` to point to our new query job.
let new_icx = tls::ImplicitCtxt { let new_icx = tls::ImplicitCtxt {
tcx: self.global_tcx(), tcx: self,
query: Some(job), query: Some(job),
diagnostics, diagnostics,
layout_depth: current_icx.layout_depth, layout_depth: current_icx.layout_depth,
@ -274,7 +274,7 @@ impl<'tcx> TyCtxt<'tcx> {
// Use the `ImplicitCtxt` while we execute the query. // Use the `ImplicitCtxt` while we execute the query.
tls::enter_context(&new_icx, |_| { tls::enter_context(&new_icx, |_| {
compute(self.global_tcx()) compute(self)
}) })
}) })
} }
@ -384,7 +384,7 @@ impl<'tcx> TyCtxt<'tcx> {
let ((result, dep_node_index), diagnostics) = with_diagnostics(|diagnostics| { let ((result, dep_node_index), diagnostics) = with_diagnostics(|diagnostics| {
self.start_query(job.job.clone(), diagnostics, |tcx| { self.start_query(job.job.clone(), diagnostics, |tcx| {
tcx.dep_graph.with_anon_task(Q::dep_kind(), || { tcx.dep_graph.with_anon_task(Q::dep_kind(), || {
Q::compute(tcx.global_tcx(), key) Q::compute(tcx, key)
}) })
}) })
}); });
@ -445,10 +445,10 @@ impl<'tcx> TyCtxt<'tcx> {
debug_assert!(self.dep_graph.is_green(dep_node)); debug_assert!(self.dep_graph.is_green(dep_node));
// First we try to load the result from the on-disk cache. // First we try to load the result from the on-disk cache.
let result = if Q::cache_on_disk(self.global_tcx(), key.clone(), None) && let result = if Q::cache_on_disk(self, key.clone(), None) &&
self.sess.opts.debugging_opts.incremental_queries { self.sess.opts.debugging_opts.incremental_queries {
self.sess.profiler(|p| p.incremental_load_result_start(Q::NAME)); self.sess.profiler(|p| p.incremental_load_result_start(Q::NAME));
let result = Q::try_load_from_disk(self.global_tcx(), prev_dep_node_index); let result = Q::try_load_from_disk(self, prev_dep_node_index);
self.sess.profiler(|p| p.incremental_load_result_end(Q::NAME)); self.sess.profiler(|p| p.incremental_load_result_end(Q::NAME));
// We always expect to find a cached result for things that // We always expect to find a cached result for things that
@ -643,7 +643,7 @@ impl<'tcx> TyCtxt<'tcx> {
macro_rules! handle_cycle_error { macro_rules! handle_cycle_error {
([][$tcx: expr, $error:expr]) => {{ ([][$tcx: expr, $error:expr]) => {{
$tcx.report_cycle($error).emit(); $tcx.report_cycle($error).emit();
Value::from_cycle_error($tcx.global_tcx()) Value::from_cycle_error($tcx)
}}; }};
([fatal_cycle$(, $modifiers:ident)*][$tcx:expr, $error:expr]) => {{ ([fatal_cycle$(, $modifiers:ident)*][$tcx:expr, $error:expr]) => {{
$tcx.report_cycle($error).emit(); $tcx.report_cycle($error).emit();
@ -652,7 +652,7 @@ macro_rules! handle_cycle_error {
}}; }};
([cycle_delay_bug$(, $modifiers:ident)*][$tcx:expr, $error:expr]) => {{ ([cycle_delay_bug$(, $modifiers:ident)*][$tcx:expr, $error:expr]) => {{
$tcx.report_cycle($error).delay_as_bug(); $tcx.report_cycle($error).delay_as_bug();
Value::from_cycle_error($tcx.global_tcx()) Value::from_cycle_error($tcx)
}}; }};
([$other:ident$(, $modifiers:ident)*][$($args:tt)*]) => { ([$other:ident$(, $modifiers:ident)*][$($args:tt)*]) => {
handle_cycle_error!([$($modifiers),*][$($args)*]) handle_cycle_error!([$($modifiers),*][$($args)*])
@ -999,7 +999,7 @@ macro_rules! define_queries_inner {
// would be missing appropriate entries in `providers`. // would be missing appropriate entries in `providers`.
.unwrap_or(&tcx.queries.fallback_extern_providers) .unwrap_or(&tcx.queries.fallback_extern_providers)
.$name; .$name;
provider(tcx.global_tcx(), key) provider(tcx, key)
}) })
} }

View file

@ -442,8 +442,8 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
.map(|c| c.is_green()) .map(|c| c.is_green())
.unwrap_or(false)); .unwrap_or(false));
let key = RecoverKey::recover(tcx.global_tcx(), self).unwrap(); let key = RecoverKey::recover(tcx, self).unwrap();
if queries::#name::cache_on_disk(tcx.global_tcx(), key, None) { if queries::#name::cache_on_disk(tcx, key, None) {
let _ = tcx.#name(key); let _ = tcx.#name(key);
} }
} }

View file

@ -621,7 +621,7 @@ impl<'cx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tcx
target: _, target: _,
unwind: _, unwind: _,
} => { } => {
let gcx = self.infcx.tcx.global_tcx(); let tcx = self.infcx.tcx;
// Compute the type with accurate region information. // Compute the type with accurate region information.
let drop_place_ty = drop_place.ty(self.body, self.infcx.tcx); let drop_place_ty = drop_place.ty(self.body, self.infcx.tcx);
@ -629,10 +629,10 @@ impl<'cx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tcx
// Erase the regions. // Erase the regions.
let drop_place_ty = self.infcx.tcx.erase_regions(&drop_place_ty).ty; let drop_place_ty = self.infcx.tcx.erase_regions(&drop_place_ty).ty;
// "Lift" into the gcx -- once regions are erased, this type should be in the // "Lift" into the tcx -- once regions are erased, this type should be in the
// global arenas; this "lift" operation basically just asserts that is true, but // global arenas; this "lift" operation basically just asserts that is true, but
// that is useful later. // that is useful later.
gcx.lift_to_global(&drop_place_ty).unwrap(); tcx.lift(&drop_place_ty).unwrap();
debug!("visit_terminator_drop \ debug!("visit_terminator_drop \
loc: {:?} term: {:?} drop_place: {:?} drop_place_ty: {:?} span: {:?}", loc: {:?} term: {:?} drop_place: {:?} drop_place_ty: {:?} span: {:?}",

View file

@ -1894,9 +1894,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
// Erase the regions from `ty` to get a global type. The // Erase the regions from `ty` to get a global type. The
// `Sized` bound in no way depends on precise regions, so this // `Sized` bound in no way depends on precise regions, so this
// shouldn't affect `is_sized`. // shouldn't affect `is_sized`.
let gcx = tcx.global_tcx();
let erased_ty = tcx.erase_regions(&ty); let erased_ty = tcx.erase_regions(&ty);
if !erased_ty.is_sized(gcx.at(span), self.param_env) { if !erased_ty.is_sized(tcx.at(span), self.param_env) {
// in current MIR construction, all non-control-flow rvalue // in current MIR construction, all non-control-flow rvalue
// expressions evaluate through `as_temp` or `into` a return // expressions evaluate through `as_temp` or `into` a return
// slot or local, so to find all unsized rvalues it is enough // slot or local, so to find all unsized rvalues it is enough

View file

@ -521,9 +521,8 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
defining_ty: DefiningTy<'tcx>, defining_ty: DefiningTy<'tcx>,
) -> UniversalRegionIndices<'tcx> { ) -> UniversalRegionIndices<'tcx> {
let tcx = self.infcx.tcx; let tcx = self.infcx.tcx;
let gcx = tcx.global_tcx();
let closure_base_def_id = tcx.closure_base_def_id(self.mir_def_id); let closure_base_def_id = tcx.closure_base_def_id(self.mir_def_id);
let identity_substs = InternalSubsts::identity_for_item(gcx, closure_base_def_id); let identity_substs = InternalSubsts::identity_for_item(tcx, closure_base_def_id);
let fr_substs = match defining_ty { let fr_substs = match defining_ty {
DefiningTy::Closure(_, ClosureSubsts { ref substs }) DefiningTy::Closure(_, ClosureSubsts { ref substs })
| DefiningTy::Generator(_, GeneratorSubsts { ref substs }, _) => { | DefiningTy::Generator(_, GeneratorSubsts { ref substs }, _) => {
@ -542,7 +541,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
DefiningTy::FnDef(_, substs) | DefiningTy::Const(_, substs) => substs, DefiningTy::FnDef(_, substs) | DefiningTy::Const(_, substs) => substs,
}; };
let global_mapping = iter::once((gcx.lifetimes.re_static, fr_static)); let global_mapping = iter::once((tcx.lifetimes.re_static, fr_static));
let subst_mapping = identity_substs let subst_mapping = identity_substs
.regions() .regions()
.zip(fr_substs.regions().map(|r| r.to_region_vid())); .zip(fr_substs.regions().map(|r| r.to_region_vid()));

View file

@ -148,9 +148,8 @@ pub(crate) fn on_all_drop_children_bits<'tcx, F>(
let ty = place.ty(body, tcx).ty; let ty = place.ty(body, tcx).ty;
debug!("on_all_drop_children_bits({:?}, {:?} : {:?})", path, place, ty); debug!("on_all_drop_children_bits({:?}, {:?} : {:?})", path, place, ty);
let gcx = tcx.global_tcx();
let erased_ty = tcx.erase_regions(&ty); let erased_ty = tcx.erase_regions(&ty);
if erased_ty.needs_drop(gcx, ctxt.param_env) { if erased_ty.needs_drop(tcx, ctxt.param_env) {
each_child(child); each_child(child);
} else { } else {
debug!("on_all_drop_children_bits - skipping") debug!("on_all_drop_children_bits - skipping")

View file

@ -543,9 +543,9 @@ fn make_mirror_unadjusted<'a, 'tcx>(
// Now comes the rote stuff: // Now comes the rote stuff:
hir::ExprKind::Repeat(ref v, ref count) => { hir::ExprKind::Repeat(ref v, ref count) => {
let def_id = cx.tcx.hir().local_def_id(count.hir_id); let def_id = cx.tcx.hir().local_def_id(count.hir_id);
let substs = InternalSubsts::identity_for_item(cx.tcx.global_tcx(), def_id); let substs = InternalSubsts::identity_for_item(cx.tcx, def_id);
let instance = ty::Instance::resolve( let instance = ty::Instance::resolve(
cx.tcx.global_tcx(), cx.tcx,
cx.param_env, cx.param_env,
def_id, def_id,
substs, substs,

View file

@ -83,7 +83,7 @@ impl<'a, 'tcx> Cx<'a, 'tcx> {
infcx, infcx,
root_lint_level: src_id, root_lint_level: src_id,
param_env: tcx.param_env(src_def_id), param_env: tcx.param_env(src_def_id),
identity_substs: InternalSubsts::identity_for_item(tcx.global_tcx(), src_def_id), identity_substs: InternalSubsts::identity_for_item(tcx, src_def_id),
region_scope_tree: tcx.region_scope_tree(src_def_id), region_scope_tree: tcx.region_scope_tree(src_def_id),
tables, tables,
constness, constness,
@ -154,12 +154,11 @@ impl<'a, 'tcx> Cx<'a, 'tcx> {
} }
pub fn pattern_from_hir(&mut self, p: &hir::Pat) -> Pat<'tcx> { pub fn pattern_from_hir(&mut self, p: &hir::Pat) -> Pat<'tcx> {
let tcx = self.tcx.global_tcx(); let p = match self.tcx.hir().get(p.hir_id) {
let p = match tcx.hir().get(p.hir_id) {
Node::Pat(p) | Node::Binding(p) => p, Node::Pat(p) | Node::Binding(p) => p,
node => bug!("pattern became {:?}", node) node => bug!("pattern became {:?}", node)
}; };
Pat::from_hir(tcx, self.param_env.and(self.identity_substs), self.tables(), p) Pat::from_hir(self.tcx, self.param_env.and(self.identity_substs), self.tables(), p)
} }
pub fn trait_method(&mut self, pub fn trait_method(&mut self,
@ -187,7 +186,7 @@ impl<'a, 'tcx> Cx<'a, 'tcx> {
} }
pub fn needs_drop(&mut self, ty: Ty<'tcx>) -> bool { pub fn needs_drop(&mut self, ty: Ty<'tcx>) -> bool {
ty.needs_drop(self.tcx.global_tcx(), self.param_env) ty.needs_drop(self.tcx, self.param_env)
} }
pub fn tcx(&self) -> TyCtxt<'tcx> { pub fn tcx(&self) -> TyCtxt<'tcx> {

View file

@ -79,7 +79,7 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> &'tcx
} }
ty::InstanceDef::ClosureOnceShim { call_once } => { ty::InstanceDef::ClosureOnceShim { call_once } => {
let fn_mut = tcx.lang_items().fn_mut_trait().unwrap(); let fn_mut = tcx.lang_items().fn_mut_trait().unwrap();
let call_mut = tcx.global_tcx() let call_mut = tcx
.associated_items(fn_mut) .associated_items(fn_mut)
.find(|it| it.kind == ty::AssocKind::Method) .find(|it| it.kind == ty::AssocKind::Method)
.unwrap().def_id; .unwrap().def_id;

View file

@ -474,7 +474,7 @@ impl context::UnificationOps<ChalkArenas<'tcx>, ChalkArenas<'tcx>>
&self, &self,
value: DelayedLiteral<ChalkArenas<'tcx>>, value: DelayedLiteral<ChalkArenas<'tcx>>,
) -> DelayedLiteral<ChalkArenas<'tcx>> { ) -> DelayedLiteral<ChalkArenas<'tcx>> {
match self.infcx.tcx.lift_to_global(&value) { match self.infcx.tcx.lift(&value) {
Some(literal) => literal, Some(literal) => literal,
None => bug!("cannot lift {:?}", value), None => bug!("cannot lift {:?}", value),
} }

View file

@ -1269,7 +1269,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// to avoid ICEs. // to avoid ICEs.
for item in &regular_traits { for item in &regular_traits {
let object_safety_violations = let object_safety_violations =
tcx.global_tcx().astconv_object_safety_violations(item.trait_ref().def_id()); tcx.astconv_object_safety_violations(item.trait_ref().def_id());
if !object_safety_violations.is_empty() { if !object_safety_violations.is_empty() {
tcx.report_object_safety_error( tcx.report_object_safety_error(
span, span,

View file

@ -932,9 +932,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Ok(self.to_const(count, tcx.type_of(count_def_id))) Ok(self.to_const(count, tcx.type_of(count_def_id)))
} else { } else {
let param_env = ty::ParamEnv::empty(); let param_env = ty::ParamEnv::empty();
let substs = InternalSubsts::identity_for_item(tcx.global_tcx(), count_def_id); let substs = InternalSubsts::identity_for_item(tcx, count_def_id);
let instance = ty::Instance::resolve( let instance = ty::Instance::resolve(
tcx.global_tcx(), tcx,
param_env, param_env,
count_def_id, count_def_id,
substs, substs,

View file

@ -48,7 +48,7 @@ impl<'tcx> CheckWfFcxBuilder<'tcx> {
// empty `param_env`. // empty `param_env`.
check_false_global_bounds(&fcx, span, id); check_false_global_bounds(&fcx, span, id);
} }
let wf_tys = f(&fcx, fcx.tcx.global_tcx()); let wf_tys = f(&fcx, fcx.tcx);
fcx.select_all_obligations_or_error(); fcx.select_all_obligations_or_error();
fcx.regionck_item(id, span, &wf_tys); fcx.regionck_item(id, span, &wf_tys);
}); });
@ -366,8 +366,8 @@ fn check_item_type(
) { ) {
debug!("check_item_type: {:?}", item_id); debug!("check_item_type: {:?}", item_id);
for_id(tcx, item_id, ty_span).with_fcx(|fcx, gcx| { for_id(tcx, item_id, ty_span).with_fcx(|fcx, tcx| {
let ty = gcx.type_of(gcx.hir().local_def_id(item_id)); let ty = tcx.type_of(tcx.hir().local_def_id(item_id));
let item_ty = fcx.normalize_associated_types_in(ty_span, &ty); let item_ty = fcx.normalize_associated_types_in(ty_span, &ty);
let mut forbid_unsized = true; let mut forbid_unsized = true;

View file

@ -322,29 +322,29 @@ fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: DefId) {
} }
} }
pub fn coerce_unsized_info<'tcx>(gcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUnsizedInfo { pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUnsizedInfo {
debug!("compute_coerce_unsized_info(impl_did={:?})", impl_did); debug!("compute_coerce_unsized_info(impl_did={:?})", impl_did);
let coerce_unsized_trait = gcx.lang_items().coerce_unsized_trait().unwrap(); let coerce_unsized_trait = tcx.lang_items().coerce_unsized_trait().unwrap();
let unsize_trait = gcx.lang_items().require(UnsizeTraitLangItem).unwrap_or_else(|err| { let unsize_trait = tcx.lang_items().require(UnsizeTraitLangItem).unwrap_or_else(|err| {
gcx.sess.fatal(&format!("`CoerceUnsized` implementation {}", err)); tcx.sess.fatal(&format!("`CoerceUnsized` implementation {}", err));
}); });
// this provider should only get invoked for local def-ids // this provider should only get invoked for local def-ids
let impl_hir_id = gcx.hir().as_local_hir_id(impl_did).unwrap_or_else(|| { let impl_hir_id = tcx.hir().as_local_hir_id(impl_did).unwrap_or_else(|| {
bug!("coerce_unsized_info: invoked for non-local def-id {:?}", impl_did) bug!("coerce_unsized_info: invoked for non-local def-id {:?}", impl_did)
}); });
let source = gcx.type_of(impl_did); let source = tcx.type_of(impl_did);
let trait_ref = gcx.impl_trait_ref(impl_did).unwrap(); let trait_ref = tcx.impl_trait_ref(impl_did).unwrap();
assert_eq!(trait_ref.def_id, coerce_unsized_trait); assert_eq!(trait_ref.def_id, coerce_unsized_trait);
let target = trait_ref.substs.type_at(1); let target = trait_ref.substs.type_at(1);
debug!("visit_implementation_of_coerce_unsized: {:?} -> {:?} (bound)", debug!("visit_implementation_of_coerce_unsized: {:?} -> {:?} (bound)",
source, source,
target); target);
let span = gcx.hir().span(impl_hir_id); let span = tcx.hir().span(impl_hir_id);
let param_env = gcx.param_env(impl_did); let param_env = tcx.param_env(impl_did);
assert!(!source.has_escaping_bound_vars()); assert!(!source.has_escaping_bound_vars());
let err_info = CoerceUnsizedInfo { custom_kind: None }; let err_info = CoerceUnsizedInfo { custom_kind: None };
@ -353,7 +353,7 @@ pub fn coerce_unsized_info<'tcx>(gcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn
source, source,
target); target);
gcx.infer_ctxt().enter(|infcx| { tcx.infer_ctxt().enter(|infcx| {
let cause = ObligationCause::misc(span, impl_hir_id); let cause = ObligationCause::misc(span, impl_hir_id);
let check_mutbl = |mt_a: ty::TypeAndMut<'tcx>, let check_mutbl = |mt_a: ty::TypeAndMut<'tcx>,
mt_b: ty::TypeAndMut<'tcx>, mt_b: ty::TypeAndMut<'tcx>,
@ -372,24 +372,24 @@ pub fn coerce_unsized_info<'tcx>(gcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn
infcx.sub_regions(infer::RelateObjectBound(span), r_b, r_a); infcx.sub_regions(infer::RelateObjectBound(span), r_b, r_a);
let mt_a = ty::TypeAndMut { ty: ty_a, mutbl: mutbl_a }; let mt_a = ty::TypeAndMut { ty: ty_a, mutbl: mutbl_a };
let mt_b = ty::TypeAndMut { ty: ty_b, mutbl: mutbl_b }; let mt_b = ty::TypeAndMut { ty: ty_b, mutbl: mutbl_b };
check_mutbl(mt_a, mt_b, &|ty| gcx.mk_imm_ref(r_b, ty)) check_mutbl(mt_a, mt_b, &|ty| tcx.mk_imm_ref(r_b, ty))
} }
(&ty::Ref(_, ty_a, mutbl_a), &ty::RawPtr(mt_b)) => { (&ty::Ref(_, ty_a, mutbl_a), &ty::RawPtr(mt_b)) => {
let mt_a = ty::TypeAndMut { ty: ty_a, mutbl: mutbl_a }; let mt_a = ty::TypeAndMut { ty: ty_a, mutbl: mutbl_a };
check_mutbl(mt_a, mt_b, &|ty| gcx.mk_imm_ptr(ty)) check_mutbl(mt_a, mt_b, &|ty| tcx.mk_imm_ptr(ty))
} }
(&ty::RawPtr(mt_a), &ty::RawPtr(mt_b)) => { (&ty::RawPtr(mt_a), &ty::RawPtr(mt_b)) => {
check_mutbl(mt_a, mt_b, &|ty| gcx.mk_imm_ptr(ty)) check_mutbl(mt_a, mt_b, &|ty| tcx.mk_imm_ptr(ty))
} }
(&ty::Adt(def_a, substs_a), &ty::Adt(def_b, substs_b)) if def_a.is_struct() && (&ty::Adt(def_a, substs_a), &ty::Adt(def_b, substs_b)) if def_a.is_struct() &&
def_b.is_struct() => { def_b.is_struct() => {
if def_a != def_b { if def_a != def_b {
let source_path = gcx.def_path_str(def_a.did); let source_path = tcx.def_path_str(def_a.did);
let target_path = gcx.def_path_str(def_b.did); let target_path = tcx.def_path_str(def_b.did);
span_err!(gcx.sess, span_err!(tcx.sess,
span, span,
E0377, E0377,
"the trait `CoerceUnsized` may only be implemented \ "the trait `CoerceUnsized` may only be implemented \
@ -443,9 +443,9 @@ pub fn coerce_unsized_info<'tcx>(gcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn
let diff_fields = fields.iter() let diff_fields = fields.iter()
.enumerate() .enumerate()
.filter_map(|(i, f)| { .filter_map(|(i, f)| {
let (a, b) = (f.ty(gcx, substs_a), f.ty(gcx, substs_b)); let (a, b) = (f.ty(tcx, substs_a), f.ty(tcx, substs_b));
if gcx.type_of(f.did).is_phantom_data() { if tcx.type_of(f.did).is_phantom_data() {
// Ignore PhantomData fields // Ignore PhantomData fields
return None; return None;
} }
@ -472,7 +472,7 @@ pub fn coerce_unsized_info<'tcx>(gcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn
.collect::<Vec<_>>(); .collect::<Vec<_>>();
if diff_fields.is_empty() { if diff_fields.is_empty() {
span_err!(gcx.sess, span_err!(tcx.sess,
span, span,
E0374, E0374,
"the trait `CoerceUnsized` may only be implemented \ "the trait `CoerceUnsized` may only be implemented \
@ -480,14 +480,14 @@ pub fn coerce_unsized_info<'tcx>(gcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn
being coerced, none found"); being coerced, none found");
return err_info; return err_info;
} else if diff_fields.len() > 1 { } else if diff_fields.len() > 1 {
let item = gcx.hir().expect_item(impl_hir_id); let item = tcx.hir().expect_item(impl_hir_id);
let span = if let ItemKind::Impl(.., Some(ref t), _, _) = item.kind { let span = if let ItemKind::Impl(.., Some(ref t), _, _) = item.kind {
t.path.span t.path.span
} else { } else {
gcx.hir().span(impl_hir_id) tcx.hir().span(impl_hir_id)
}; };
let mut err = struct_span_err!(gcx.sess, let mut err = struct_span_err!(tcx.sess,
span, span,
E0375, E0375,
"implementing the trait \ "implementing the trait \
@ -514,7 +514,7 @@ pub fn coerce_unsized_info<'tcx>(gcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn
} }
_ => { _ => {
span_err!(gcx.sess, span_err!(tcx.sess,
span, span,
E0376, E0376,
"the trait `CoerceUnsized` may only be implemented \ "the trait `CoerceUnsized` may only be implemented \
@ -527,7 +527,7 @@ pub fn coerce_unsized_info<'tcx>(gcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn
// Register an obligation for `A: Trait<B>`. // Register an obligation for `A: Trait<B>`.
let cause = traits::ObligationCause::misc(span, impl_hir_id); let cause = traits::ObligationCause::misc(span, impl_hir_id);
let predicate = gcx.predicate_for_trait_def(param_env, let predicate = tcx.predicate_for_trait_def(param_env,
cause, cause,
trait_def_id, trait_def_id,
0, 0,