@@ -19,11 +19,8 @@ pub use self::freshen::TypeFreshener;
19
19
pub use self :: region_inference:: { GenericKind , VerifyBound } ;
20
20
21
21
use hir:: def_id:: DefId ;
22
- use hir;
23
22
use middle:: free_region:: { FreeRegionMap , RegionRelations } ;
24
23
use middle:: region:: RegionMaps ;
25
- use middle:: mem_categorization as mc;
26
- use middle:: mem_categorization:: McResult ;
27
24
use middle:: lang_items;
28
25
use mir:: tcx:: LvalueTy ;
29
26
use ty:: subst:: { Kind , Subst , Substs } ;
@@ -36,7 +33,6 @@ use traits::{self, ObligationCause, PredicateObligations, Reveal};
36
33
use rustc_data_structures:: unify:: { self , UnificationTable } ;
37
34
use std:: cell:: { Cell , RefCell , Ref , RefMut } ;
38
35
use std:: fmt;
39
- use std:: ops:: Deref ;
40
36
use syntax:: ast;
41
37
use errors:: DiagnosticBuilder ;
42
38
use syntax_pos:: { self , Span , DUMMY_SP } ;
@@ -80,55 +76,23 @@ pub type FixupResult<T> = Result<T, FixupError>; // "fixup result"
80
76
/// `InProgress` (during typeck) or `Interned` (result of typeck).
81
77
/// Only the `InProgress` version supports `borrow_mut`.
82
78
#[ derive( Copy , Clone ) ]
83
- pub enum InferTables < ' a , ' gcx : ' a +' tcx , ' tcx : ' a > {
84
- Interned ( & ' a ty:: TypeckTables < ' gcx > ) ,
79
+ pub enum InferTables < ' a , ' tcx : ' a > {
85
80
InProgress ( & ' a RefCell < ty:: TypeckTables < ' tcx > > ) ,
86
81
Missing
87
82
}
88
83
89
- pub enum InferTablesRef < ' a , ' gcx : ' a +' tcx , ' tcx : ' a > {
90
- Interned ( & ' a ty:: TypeckTables < ' gcx > ) ,
91
- InProgress ( Ref < ' a , ty:: TypeckTables < ' tcx > > )
92
- }
93
-
94
- impl < ' a , ' gcx , ' tcx > Deref for InferTablesRef < ' a , ' gcx , ' tcx > {
95
- type Target = ty:: TypeckTables < ' tcx > ;
96
- fn deref ( & self ) -> & Self :: Target {
97
- match * self {
98
- InferTablesRef :: Interned ( tables) => tables,
99
- InferTablesRef :: InProgress ( ref tables) => tables
100
- }
101
- }
102
- }
103
-
104
- impl < ' a , ' gcx , ' tcx > InferTables < ' a , ' gcx , ' tcx > {
105
- pub fn borrow ( self ) -> InferTablesRef < ' a , ' gcx , ' tcx > {
84
+ impl < ' a , ' tcx > InferTables < ' a , ' tcx > {
85
+ pub fn borrow ( self ) -> Ref < ' a , ty:: TypeckTables < ' tcx > > {
106
86
match self {
107
- InferTables :: Interned ( tables) => InferTablesRef :: Interned ( tables) ,
108
- InferTables :: InProgress ( tables) => InferTablesRef :: InProgress ( tables. borrow ( ) ) ,
87
+ InferTables :: InProgress ( tables) => tables. borrow ( ) ,
109
88
InferTables :: Missing => {
110
89
bug ! ( "InferTables: infcx.tables.borrow() with no tables" )
111
90
}
112
91
}
113
92
}
114
93
115
- pub fn expect_interned ( self ) -> & ' a ty:: TypeckTables < ' gcx > {
116
- match self {
117
- InferTables :: Interned ( tables) => tables,
118
- InferTables :: InProgress ( _) => {
119
- bug ! ( "InferTables: infcx.tables.expect_interned() during type-checking" ) ;
120
- }
121
- InferTables :: Missing => {
122
- bug ! ( "InferTables: infcx.tables.expect_interned() with no tables" )
123
- }
124
- }
125
- }
126
-
127
94
pub fn borrow_mut ( self ) -> RefMut < ' a , ty:: TypeckTables < ' tcx > > {
128
95
match self {
129
- InferTables :: Interned ( _) => {
130
- bug ! ( "InferTables: infcx.tables.borrow_mut() outside of type-checking" ) ;
131
- }
132
96
InferTables :: InProgress ( tables) => tables. borrow_mut ( ) ,
133
97
InferTables :: Missing => {
134
98
bug ! ( "InferTables: infcx.tables.borrow_mut() with no tables" )
@@ -140,7 +104,7 @@ impl<'a, 'gcx, 'tcx> InferTables<'a, 'gcx, 'tcx> {
140
104
pub struct InferCtxt < ' a , ' gcx : ' a +' tcx , ' tcx : ' a > {
141
105
pub tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
142
106
143
- pub tables : InferTables < ' a , ' gcx , ' tcx > ,
107
+ pub tables : InferTables < ' a , ' tcx > ,
144
108
145
109
// Cache for projections. This cache is snapshotted along with the
146
110
// infcx.
@@ -397,41 +361,18 @@ impl fmt::Display for FixupError {
397
361
}
398
362
399
363
pub trait InferEnv < ' a , ' tcx > {
400
- fn to_parts ( self , tcx : TyCtxt < ' a , ' tcx , ' tcx > )
401
- -> ( Option < & ' a ty:: TypeckTables < ' tcx > > ,
402
- Option < ty:: TypeckTables < ' tcx > > ) ;
364
+ fn fresh_tables ( self ) -> Option < ty:: TypeckTables < ' tcx > > ;
403
365
}
404
366
405
367
impl < ' a , ' tcx > InferEnv < ' a , ' tcx > for ( ) {
406
- fn to_parts ( self , _: TyCtxt < ' a , ' tcx , ' tcx > )
407
- -> ( Option < & ' a ty:: TypeckTables < ' tcx > > ,
408
- Option < ty:: TypeckTables < ' tcx > > ) {
409
- ( None , None )
410
- }
411
- }
412
-
413
- impl < ' a , ' tcx > InferEnv < ' a , ' tcx > for & ' a ty:: TypeckTables < ' tcx > {
414
- fn to_parts ( self , _: TyCtxt < ' a , ' tcx , ' tcx > )
415
- -> ( Option < & ' a ty:: TypeckTables < ' tcx > > ,
416
- Option < ty:: TypeckTables < ' tcx > > ) {
417
- ( Some ( self ) , None )
368
+ fn fresh_tables ( self ) -> Option < ty:: TypeckTables < ' tcx > > {
369
+ None
418
370
}
419
371
}
420
372
421
373
impl < ' a , ' tcx > InferEnv < ' a , ' tcx > for ty:: TypeckTables < ' tcx > {
422
- fn to_parts ( self , _: TyCtxt < ' a , ' tcx , ' tcx > )
423
- -> ( Option < & ' a ty:: TypeckTables < ' tcx > > ,
424
- Option < ty:: TypeckTables < ' tcx > > ) {
425
- ( None , Some ( self ) )
426
- }
427
- }
428
-
429
- impl < ' a , ' tcx > InferEnv < ' a , ' tcx > for hir:: BodyId {
430
- fn to_parts ( self , tcx : TyCtxt < ' a , ' tcx , ' tcx > )
431
- -> ( Option < & ' a ty:: TypeckTables < ' tcx > > ,
432
- Option < ty:: TypeckTables < ' tcx > > ) {
433
- let def_id = tcx. hir . body_owner_def_id ( self ) ;
434
- ( Some ( tcx. typeck_tables_of ( def_id) ) , None )
374
+ fn fresh_tables ( self ) -> Option < ty:: TypeckTables < ' tcx > > {
375
+ Some ( self )
435
376
}
436
377
}
437
378
@@ -442,29 +383,24 @@ pub struct InferCtxtBuilder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
442
383
global_tcx : TyCtxt < ' a , ' gcx , ' gcx > ,
443
384
arena : DroplessArena ,
444
385
fresh_tables : Option < RefCell < ty:: TypeckTables < ' tcx > > > ,
445
- tables : Option < & ' a ty:: TypeckTables < ' gcx > > ,
446
386
}
447
387
448
388
impl < ' a , ' gcx , ' tcx > TyCtxt < ' a , ' gcx , ' gcx > {
449
389
pub fn infer_ctxt < E : InferEnv < ' a , ' gcx > > ( self , env : E ) -> InferCtxtBuilder < ' a , ' gcx , ' tcx > {
450
- let ( tables, fresh_tables) = env. to_parts ( self ) ;
451
390
InferCtxtBuilder {
452
391
global_tcx : self ,
453
392
arena : DroplessArena :: new ( ) ,
454
- fresh_tables : fresh_tables. map ( RefCell :: new) ,
455
- tables : tables,
393
+ fresh_tables : env. fresh_tables ( ) . map ( RefCell :: new) ,
456
394
}
457
395
}
458
396
459
397
/// Fake InferCtxt with the global tcx. Used by pre-MIR borrowck
460
398
/// for MemCategorizationContext/ExprUseVisitor.
461
399
/// If any inference functionality is used, ICEs will occur.
462
- pub fn borrowck_fake_infer_ctxt ( self , body : hir:: BodyId )
463
- -> InferCtxt < ' a , ' gcx , ' gcx > {
464
- let ( tables, _) = body. to_parts ( self ) ;
400
+ pub fn borrowck_fake_infer_ctxt ( self ) -> InferCtxt < ' a , ' gcx , ' gcx > {
465
401
InferCtxt {
466
402
tcx : self ,
467
- tables : InferTables :: Interned ( tables . unwrap ( ) ) ,
403
+ tables : InferTables :: Missing ,
468
404
type_variables : RefCell :: new ( type_variable:: TypeVariableTable :: new ( ) ) ,
469
405
int_unification_table : RefCell :: new ( UnificationTable :: new ( ) ) ,
470
406
float_unification_table : RefCell :: new ( UnificationTable :: new ( ) ) ,
@@ -488,11 +424,9 @@ impl<'a, 'gcx, 'tcx> InferCtxtBuilder<'a, 'gcx, 'tcx> {
488
424
global_tcx,
489
425
ref arena,
490
426
ref fresh_tables,
491
- tables,
492
427
} = * self ;
493
- let tables = tables. map ( InferTables :: Interned ) . unwrap_or_else ( || {
494
- fresh_tables. as_ref ( ) . map_or ( InferTables :: Missing , InferTables :: InProgress )
495
- } ) ;
428
+ let tables = fresh_tables. as_ref ( )
429
+ . map_or ( InferTables :: Missing , InferTables :: InProgress ) ;
496
430
global_tcx. enter_local ( arena, |tcx| f ( InferCtxt {
497
431
tcx : tcx,
498
432
tables : tables,
@@ -1190,28 +1124,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
1190
1124
self . tainted_by_errors_flag . set ( true )
1191
1125
}
1192
1126
1193
- pub fn node_type ( & self , id : ast:: NodeId ) -> Ty < ' tcx > {
1194
- match self . tables . borrow ( ) . node_types . get ( & id) {
1195
- Some ( & t) => t,
1196
- // FIXME
1197
- None if self . is_tainted_by_errors ( ) =>
1198
- self . tcx . types . err ,
1199
- None => {
1200
- bug ! ( "no type for node {}: {} in fcx" ,
1201
- id, self . tcx. hir. node_to_string( id) ) ;
1202
- }
1203
- }
1204
- }
1205
-
1206
- pub fn expr_ty ( & self , ex : & hir:: Expr ) -> Ty < ' tcx > {
1207
- match self . tables . borrow ( ) . node_types . get ( & ex. id ) {
1208
- Some ( & t) => t,
1209
- None => {
1210
- bug ! ( "no type for expr in fcx" ) ;
1211
- }
1212
- }
1213
- }
1214
-
1215
1127
pub fn resolve_regions_and_report_errors ( & self ,
1216
1128
region_context : DefId ,
1217
1129
region_map : & RegionMaps ,
@@ -1310,21 +1222,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
1310
1222
value. fold_with ( & mut r)
1311
1223
}
1312
1224
1313
- /// Resolves all type variables in `t` and then, if any were left
1314
- /// unresolved, substitutes an error type. This is used after the
1315
- /// main checking when doing a second pass before writeback. The
1316
- /// justification is that writeback will produce an error for
1317
- /// these unconstrained type variables.
1318
- fn resolve_type_vars_or_error ( & self , t : & Ty < ' tcx > ) -> mc:: McResult < Ty < ' tcx > > {
1319
- let ty = self . resolve_type_vars_if_possible ( t) ;
1320
- if ty. references_error ( ) || ty. is_ty_var ( ) {
1321
- debug ! ( "resolve_type_vars_or_error: error from {:?}" , ty) ;
1322
- Err ( ( ) )
1323
- } else {
1324
- Ok ( ty)
1325
- }
1326
- }
1327
-
1328
1225
pub fn fully_resolve < T : TypeFoldable < ' tcx > > ( & self , value : & T ) -> FixupResult < T > {
1329
1226
/*!
1330
1227
* Attempts to resolve all type/region variables in
@@ -1484,16 +1381,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
1484
1381
self . region_vars . verify_generic_bound ( origin, kind, a, bound) ;
1485
1382
}
1486
1383
1487
- pub fn node_ty ( & self , id : ast:: NodeId ) -> McResult < Ty < ' tcx > > {
1488
- let ty = self . node_type ( id) ;
1489
- self . resolve_type_vars_or_error ( & ty)
1490
- }
1491
-
1492
- pub fn expr_ty_adjusted ( & self , expr : & hir:: Expr ) -> McResult < Ty < ' tcx > > {
1493
- let ty = self . tables . borrow ( ) . expr_ty_adjusted ( expr) ;
1494
- self . resolve_type_vars_or_error ( & ty)
1495
- }
1496
-
1497
1384
pub fn type_moves_by_default ( & self ,
1498
1385
param_env : ty:: ParamEnv < ' tcx > ,
1499
1386
ty : Ty < ' tcx > ,
0 commit comments