Skip to content

Commit 8a704f6

Browse files
committed
rustc: Remove the TyCtxt field from ParameterEnvironment.
1 parent 0053b44 commit 8a704f6

File tree

20 files changed

+82
-84
lines changed

20 files changed

+82
-84
lines changed

src/librustc/infer/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub struct InferCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
9292
// For region variables.
9393
region_vars: RegionVarBindings<'a, 'tcx>,
9494

95-
pub parameter_environment: ty::ParameterEnvironment<'a, 'tcx>,
95+
pub parameter_environment: ty::ParameterEnvironment<'gcx>,
9696

9797
// the set of predicates on which errors have been reported, to
9898
// avoid reporting the same error twice.
@@ -387,7 +387,7 @@ impl fmt::Display for FixupError {
387387
impl<'a, 'tcx> InferCtxt<'a, 'tcx, 'tcx> {
388388
pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>,
389389
tables: &'a RefCell<ty::Tables<'tcx>>,
390-
param_env: Option<ty::ParameterEnvironment<'a, 'tcx>>,
390+
param_env: Option<ty::ParameterEnvironment<'tcx>>,
391391
projection_mode: ProjectionMode)
392392
-> Self {
393393
InferCtxt {
@@ -1440,7 +1440,7 @@ pub fn drain_fulfillment_cx<T>(&self,
14401440
// cases.
14411441
!traits::type_known_to_meet_builtin_bound(self, ty, ty::BoundCopy, span)
14421442
} else {
1443-
ty.moves_by_default(&self.parameter_environment, span)
1443+
ty.moves_by_default(self.tcx, &self.parameter_environment, span)
14441444
}
14451445
}
14461446

@@ -1484,7 +1484,7 @@ pub fn drain_fulfillment_cx<T>(&self,
14841484
self.tables.borrow().upvar_capture_map.get(&upvar_id).cloned()
14851485
}
14861486

1487-
pub fn param_env<'b>(&'b self) -> &'b ty::ParameterEnvironment<'b,'tcx> {
1487+
pub fn param_env(&self) -> &ty::ParameterEnvironment<'tcx> {
14881488
&self.parameter_environment
14891489
}
14901490

src/librustc/traits/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub use self::ObligationCauseCode::*;
1818
use hir::def_id::DefId;
1919
use middle::free_region::FreeRegionMap;
2020
use ty::subst;
21-
use ty::{self, Ty, TypeFoldable};
21+
use ty::{self, Ty, TyCtxt, TypeFoldable};
2222
use infer::InferCtxt;
2323

2424
use std::rc::Rc;
@@ -378,9 +378,10 @@ pub fn type_known_to_meet_builtin_bound<'a,'tcx>(infcx: &InferCtxt<'a,'tcx, 'tcx
378378

379379
// FIXME: this is gonna need to be removed ...
380380
/// Normalizes the parameter environment, reporting errors if they occur.
381-
pub fn normalize_param_env_or_error<'a,'tcx>(unnormalized_env: ty::ParameterEnvironment<'a,'tcx>,
382-
cause: ObligationCause<'tcx>)
383-
-> ty::ParameterEnvironment<'a,'tcx>
381+
pub fn normalize_param_env_or_error<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
382+
unnormalized_env: ty::ParameterEnvironment<'tcx>,
383+
cause: ObligationCause<'tcx>)
384+
-> ty::ParameterEnvironment<'tcx>
384385
{
385386
// I'm not wild about reporting errors here; I'd prefer to
386387
// have the errors get reported at a defined place (e.g.,
@@ -397,7 +398,6 @@ pub fn normalize_param_env_or_error<'a,'tcx>(unnormalized_env: ty::ParameterEnvi
397398
// and errors will get reported then; so after typeck we
398399
// can be sure that no errors should occur.
399400

400-
let tcx = unnormalized_env.tcx;
401401
let span = cause.span;
402402
let body_id = cause.body_id;
403403

src/librustc/traits/select.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx, 'tcx> {
287287
self.infcx.tcx
288288
}
289289

290-
pub fn param_env(&self) -> &'cx ty::ParameterEnvironment<'cx, 'tcx> {
290+
pub fn param_env(&self) -> &'cx ty::ParameterEnvironment<'tcx> {
291291
self.infcx.param_env()
292292
}
293293

src/librustc/ty/layout.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ impl<'a, 'tcx> Layout {
790790
ty::TyRef(_, ty::TypeAndMut { ty: pointee, .. }) |
791791
ty::TyRawPtr(ty::TypeAndMut { ty: pointee, .. }) => {
792792
let non_zero = !ty.is_unsafe_ptr();
793-
if pointee.is_sized(&infcx.parameter_environment, DUMMY_SP) {
793+
if pointee.is_sized(tcx, &infcx.parameter_environment, DUMMY_SP) {
794794
Scalar { value: Pointer, non_zero: non_zero }
795795
} else {
796796
let unsized_part = tcx.struct_tail(pointee);
@@ -883,7 +883,7 @@ impl<'a, 'tcx> Layout {
883883
// the unsized field. Several other pieces of code assume that the unsized
884884
// field is definitely the last one.
885885
if def.dtor_kind().has_drop_flag() &&
886-
ty.is_sized(&infcx.parameter_environment, DUMMY_SP) {
886+
ty.is_sized(tcx, &infcx.parameter_environment, DUMMY_SP) {
887887
st.extend(dl, Some(Ok(&Scalar {
888888
value: Int(I8),
889889
non_zero: false

src/librustc/ty/mod.rs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,9 +1209,7 @@ impl<'tcx> TraitRef<'tcx> {
12091209
/// future I hope to refine the representation of types so as to make
12101210
/// more distinctions clearer.
12111211
#[derive(Clone)]
1212-
pub struct ParameterEnvironment<'a, 'tcx:'a> {
1213-
pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
1214-
1212+
pub struct ParameterEnvironment<'tcx> {
12151213
/// See `construct_free_substs` for details.
12161214
pub free_substs: Substs<'tcx>,
12171215

@@ -1243,13 +1241,12 @@ pub struct ParameterEnvironment<'a, 'tcx:'a> {
12431241
pub free_id_outlive: CodeExtent,
12441242
}
12451243

1246-
impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
1244+
impl<'a, 'tcx> ParameterEnvironment<'tcx> {
12471245
pub fn with_caller_bounds(&self,
12481246
caller_bounds: Vec<ty::Predicate<'tcx>>)
1249-
-> ParameterEnvironment<'a,'tcx>
1247+
-> ParameterEnvironment<'tcx>
12501248
{
12511249
ParameterEnvironment {
1252-
tcx: self.tcx,
12531250
free_substs: self.free_substs.clone(),
12541251
implicit_region_bound: self.implicit_region_bound,
12551252
caller_bounds: caller_bounds,
@@ -1260,7 +1257,8 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
12601257
}
12611258

12621259
/// Construct a parameter environment given an item, impl item, or trait item
1263-
pub fn for_item(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: NodeId) -> ParameterEnvironment<'a, 'tcx> {
1260+
pub fn for_item(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: NodeId)
1261+
-> ParameterEnvironment<'tcx> {
12641262
match tcx.map.find(id) {
12651263
Some(ast_map::NodeImplItem(ref impl_item)) => {
12661264
match impl_item.node {
@@ -2546,14 +2544,14 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
25462544
///
25472545
/// (Note that this implies that if `ty` has a destructor attached,
25482546
/// then `type_needs_drop` will definitely return `true` for `ty`.)
2549-
pub fn type_needs_drop_given_env<'b>(self,
2550-
ty: Ty<'tcx>,
2551-
param_env: &ty::ParameterEnvironment<'b,'tcx>) -> bool {
2547+
pub fn type_needs_drop_given_env(self,
2548+
ty: Ty<'tcx>,
2549+
param_env: &ty::ParameterEnvironment<'tcx>) -> bool {
25522550
// Issue #22536: We first query type_moves_by_default. It sees a
25532551
// normalized version of the type, and therefore will definitely
25542552
// know whether the type implements Copy (and thus needs no
25552553
// cleanup/drop/zeroing) ...
2556-
let implements_copy = !ty.moves_by_default(param_env, DUMMY_SP);
2554+
let implements_copy = !ty.moves_by_default(self, param_env, DUMMY_SP);
25572555

25582556
if implements_copy { return false; }
25592557

@@ -2803,13 +2801,12 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
28032801

28042802
/// Construct a parameter environment suitable for static contexts or other contexts where there
28052803
/// are no free type/lifetime parameters in scope.
2806-
pub fn empty_parameter_environment(self) -> ParameterEnvironment<'a,'tcx> {
2804+
pub fn empty_parameter_environment(self) -> ParameterEnvironment<'tcx> {
28072805

28082806
// for an empty parameter environment, there ARE no free
28092807
// regions, so it shouldn't matter what we use for the free id
28102808
let free_id_outlive = self.region_maps.node_extent(ast::DUMMY_NODE_ID);
2811-
ty::ParameterEnvironment { tcx: self,
2812-
free_substs: Substs::empty(),
2809+
ty::ParameterEnvironment { free_substs: Substs::empty(),
28132810
caller_bounds: Vec::new(),
28142811
implicit_region_bound: ty::ReEmpty,
28152812
selection_cache: traits::SelectionCache::new(),
@@ -2856,7 +2853,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
28562853
generics: &ty::Generics<'tcx>,
28572854
generic_predicates: &ty::GenericPredicates<'tcx>,
28582855
free_id_outlive: CodeExtent)
2859-
-> ParameterEnvironment<'a, 'tcx>
2856+
-> ParameterEnvironment<'tcx>
28602857
{
28612858
//
28622859
// Construct the free substs.
@@ -2886,7 +2883,6 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
28862883
//
28872884

28882885
let unnormalized_env = ty::ParameterEnvironment {
2889-
tcx: self,
28902886
free_substs: free_substs,
28912887
implicit_region_bound: ty::ReScope(free_id_outlive),
28922888
caller_bounds: predicates,
@@ -2896,7 +2892,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
28962892
};
28972893

28982894
let cause = traits::ObligationCause::misc(span, free_id_outlive.node_id(&self.region_maps));
2899-
traits::normalize_param_env_or_error(unnormalized_env, cause)
2895+
traits::normalize_param_env_or_error(self, unnormalized_env, cause)
29002896
}
29012897

29022898
pub fn is_method_call(self, expr_id: NodeId) -> bool {

src/librustc/ty/structural_impls.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,10 +758,9 @@ impl<'tcx> TypeFoldable<'tcx> for ty::ClosureUpvar<'tcx> {
758758
}
759759
}
760760

761-
impl<'a, 'tcx> TypeFoldable<'tcx> for ty::ParameterEnvironment<'a, 'tcx> where 'tcx: 'a {
761+
impl<'tcx> TypeFoldable<'tcx> for ty::ParameterEnvironment<'tcx> {
762762
fn super_fold_with<F:TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
763763
ty::ParameterEnvironment {
764-
tcx: self.tcx,
765764
free_substs: self.free_substs.fold_with(folder),
766765
implicit_region_bound: self.implicit_region_bound.fold_with(folder),
767766
caller_bounds: self.caller_bounds.fold_with(folder),

src/librustc/ty/util.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,10 @@ pub enum Representability {
129129
SelfRecursive,
130130
}
131131

132-
impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
133-
pub fn can_type_implement_copy(&self, self_type: Ty<'tcx>, span: Span)
134-
-> Result<(),CopyImplementationError> {
135-
let tcx = self.tcx;
136-
132+
impl<'tcx> ParameterEnvironment<'tcx> {
133+
pub fn can_type_implement_copy<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
134+
self_type: Ty<'tcx>, span: Span)
135+
-> Result<(),CopyImplementationError> {
137136
// FIXME: (@jroesch) float this code up
138137
let infcx = InferCtxt::new(tcx, &tcx.tables, Some(self.clone()),
139138
ProjectionMode::Topmost);
@@ -509,12 +508,10 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
509508
}
510509

511510
impl<'a, 'tcx> ty::TyS<'tcx> {
512-
fn impls_bound(&'tcx self, param_env: &ParameterEnvironment<'a, 'tcx>,
513-
bound: ty::BuiltinBound,
514-
span: Span)
515-
-> bool
511+
fn impls_bound(&'tcx self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
512+
param_env: &ParameterEnvironment<'tcx>,
513+
bound: ty::BuiltinBound, span: Span) -> bool
516514
{
517-
let tcx = param_env.tcx;
518515
let infcx = InferCtxt::new(tcx, &tcx.tables, Some(param_env.clone()),
519516
ProjectionMode::Topmost);
520517

@@ -528,7 +525,8 @@ impl<'a, 'tcx> ty::TyS<'tcx> {
528525
}
529526

530527
// FIXME (@jroesch): I made this public to use it, not sure if should be private
531-
pub fn moves_by_default(&'tcx self, param_env: &ParameterEnvironment<'a, 'tcx>,
528+
pub fn moves_by_default(&'tcx self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
529+
param_env: &ParameterEnvironment<'tcx>,
532530
span: Span) -> bool {
533531
if self.flags.get().intersects(TypeFlags::MOVENESS_CACHED) {
534532
return self.flags.get().intersects(TypeFlags::MOVES_BY_DEFAULT);
@@ -550,7 +548,7 @@ impl<'a, 'tcx> ty::TyS<'tcx> {
550548
TyArray(..) | TySlice(_) | TyTrait(..) | TyTuple(..) |
551549
TyClosure(..) | TyEnum(..) | TyStruct(..) |
552550
TyProjection(..) | TyParam(..) | TyInfer(..) | TyError => None
553-
}.unwrap_or_else(|| !self.impls_bound(param_env, ty::BoundCopy, span));
551+
}.unwrap_or_else(|| !self.impls_bound(tcx, param_env, ty::BoundCopy, span));
554552

555553
if !self.has_param_types() && !self.has_self_ty() {
556554
self.flags.set(self.flags.get() | if result {
@@ -564,17 +562,19 @@ impl<'a, 'tcx> ty::TyS<'tcx> {
564562
}
565563

566564
#[inline]
567-
pub fn is_sized(&'tcx self, param_env: &ParameterEnvironment<'a, 'tcx>,
565+
pub fn is_sized(&'tcx self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
566+
param_env: &ParameterEnvironment<'tcx>,
568567
span: Span) -> bool
569568
{
570569
if self.flags.get().intersects(TypeFlags::SIZEDNESS_CACHED) {
571570
return self.flags.get().intersects(TypeFlags::IS_SIZED);
572571
}
573572

574-
self.is_sized_uncached(param_env, span)
573+
self.is_sized_uncached(tcx, param_env, span)
575574
}
576575

577-
fn is_sized_uncached(&'tcx self, param_env: &ParameterEnvironment<'a, 'tcx>,
576+
fn is_sized_uncached(&'tcx self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
577+
param_env: &ParameterEnvironment<'tcx>,
578578
span: Span) -> bool {
579579
assert!(!self.needs_infer());
580580

@@ -588,7 +588,7 @@ impl<'a, 'tcx> ty::TyS<'tcx> {
588588

589589
TyEnum(..) | TyStruct(..) | TyProjection(..) | TyParam(..) |
590590
TyInfer(..) | TyError => None
591-
}.unwrap_or_else(|| self.impls_bound(param_env, ty::BoundSized, span));
591+
}.unwrap_or_else(|| self.impls_bound(tcx, param_env, ty::BoundSized, span));
592592

593593
if !self.has_param_types() && !self.has_self_ty() {
594594
self.flags.set(self.flags.get() | if result {

src/librustc/util/ppaux.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ impl<'tcx> fmt::Debug for ty::ClosureUpvar<'tcx> {
557557
}
558558
}
559559

560-
impl<'a, 'tcx> fmt::Debug for ty::ParameterEnvironment<'a, 'tcx> {
560+
impl<'tcx> fmt::Debug for ty::ParameterEnvironment<'tcx> {
561561
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
562562
write!(f, "ParameterEnvironment(\
563563
free_substs={:?}, \

src/librustc_borrowck/borrowck/check_loans.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ struct CheckLoanCtxt<'a, 'tcx: 'a> {
9292
dfcx_loans: &'a LoanDataFlow<'a, 'tcx>,
9393
move_data: &'a move_data::FlowedMoveData<'a, 'tcx>,
9494
all_loans: &'a [Loan<'tcx>],
95-
param_env: &'a ty::ParameterEnvironment<'a, 'tcx>,
95+
param_env: &'a ty::ParameterEnvironment<'tcx>,
9696
}
9797

9898
impl<'a, 'tcx> euv::Delegate<'tcx> for CheckLoanCtxt<'a, 'tcx> {

src/librustc_borrowck/borrowck/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -627,13 +627,13 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
627627
db.emit();
628628
}
629629

630-
pub fn report_use_of_moved_value<'b>(&self,
631-
use_span: Span,
632-
use_kind: MovedValueUseKind,
633-
lp: &LoanPath<'tcx>,
634-
the_move: &move_data::Move,
635-
moved_lp: &LoanPath<'tcx>,
636-
_param_env: &ty::ParameterEnvironment<'b,'tcx>) {
630+
pub fn report_use_of_moved_value(&self,
631+
use_span: Span,
632+
use_kind: MovedValueUseKind,
633+
lp: &LoanPath<'tcx>,
634+
the_move: &move_data::Move,
635+
moved_lp: &LoanPath<'tcx>,
636+
_param_env: &ty::ParameterEnvironment<'tcx>) {
637637
let (verb, verb_participle) = match use_kind {
638638
MovedInUse => ("use", "used"),
639639
MovedInCapture => ("capture", "captured"),

src/librustc_const_eval/check_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl<'a> FromIterator<Vec<&'a Pat>> for Matrix<'a> {
107107
//NOTE: appears to be the only place other then InferCtxt to contain a ParamEnv
108108
pub struct MatchCheckCtxt<'a, 'tcx: 'a> {
109109
pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
110-
pub param_env: ParameterEnvironment<'a, 'tcx>,
110+
pub param_env: ParameterEnvironment<'tcx>,
111111
}
112112

113113
#[derive(Clone, PartialEq)]

src/librustc_lint/builtin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,10 +497,10 @@ impl LateLintPass for MissingCopyImplementations {
497497
let parameter_environment = cx.tcx.empty_parameter_environment();
498498
// FIXME (@jroesch) should probably inver this so that the parameter env still impls this
499499
// method
500-
if !ty.moves_by_default(&parameter_environment, item.span) {
500+
if !ty.moves_by_default(cx.tcx, &parameter_environment, item.span) {
501501
return;
502502
}
503-
if parameter_environment.can_type_implement_copy(ty, item.span).is_ok() {
503+
if parameter_environment.can_type_implement_copy(cx.tcx, ty, item.span).is_ok() {
504504
cx.span_lint(MISSING_COPY_IMPLEMENTATIONS,
505505
item.span,
506506
"type could implement `Copy`; consider adding `impl \

0 commit comments

Comments
 (0)