@@ -17,15 +17,15 @@ use rustc::hir;
17
17
use rustc:: hir:: def_id:: { DefId , DefIndex } ;
18
18
use rustc:: hir:: intravisit:: { self , NestedVisitorMap , Visitor } ;
19
19
use rustc:: infer:: InferCtxt ;
20
+ use rustc:: ty:: adjustment:: { Adjust , Adjustment } ;
21
+ use rustc:: ty:: fold:: { BottomUpFolder , TypeFoldable , TypeFolder } ;
20
22
use rustc:: ty:: subst:: UnpackedKind ;
21
23
use rustc:: ty:: { self , Ty , TyCtxt } ;
22
- use rustc:: ty:: adjustment:: { Adjust , Adjustment } ;
23
- use rustc:: ty:: fold:: { TypeFoldable , TypeFolder , BottomUpFolder } ;
24
24
use rustc:: util:: nodemap:: DefIdSet ;
25
+ use rustc_data_structures:: sync:: Lrc ;
26
+ use std:: mem;
25
27
use syntax:: ast;
26
28
use syntax_pos:: Span ;
27
- use std:: mem;
28
- use rustc_data_structures:: sync:: Lrc ;
29
29
30
30
///////////////////////////////////////////////////////////////////////////
31
31
// Entry point
@@ -55,17 +55,15 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
55
55
) ;
56
56
debug ! (
57
57
"used_trait_imports({:?}) = {:?}" ,
58
- item_def_id,
59
- used_trait_imports
58
+ item_def_id, used_trait_imports
60
59
) ;
61
60
wbcx. tables . used_trait_imports = used_trait_imports;
62
61
63
62
wbcx. tables . tainted_by_errors = self . is_tainted_by_errors ( ) ;
64
63
65
64
debug ! (
66
65
"writeback: tables for {:?} are {:#?}" ,
67
- item_def_id,
68
- wbcx. tables
66
+ item_def_id, wbcx. tables
69
67
) ;
70
68
71
69
self . tcx . alloc_tables ( wbcx. tables )
@@ -118,8 +116,8 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
118
116
// operating on scalars, we clear the overload.
119
117
fn fix_scalar_builtin_expr ( & mut self , e : & hir:: Expr ) {
120
118
match e. node {
121
- hir:: ExprKind :: Unary ( hir:: UnNeg , ref inner) |
122
- hir:: ExprKind :: Unary ( hir:: UnNot , ref inner) => {
119
+ hir:: ExprKind :: Unary ( hir:: UnNeg , ref inner)
120
+ | hir:: ExprKind :: Unary ( hir:: UnNot , ref inner) => {
123
121
let inner_ty = self . fcx . node_ty ( inner. hir_id ) ;
124
122
let inner_ty = self . fcx . resolve_type_vars_if_possible ( & inner_ty) ;
125
123
@@ -178,8 +176,7 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
178
176
let index_ty = tables. expr_ty_adjusted ( & index) ;
179
177
let index_ty = self . fcx . resolve_type_vars_if_possible ( & index_ty) ;
180
178
181
- if base_ty. builtin_index ( ) . is_some ( )
182
- && index_ty == self . fcx . tcx . types . usize {
179
+ if base_ty. builtin_index ( ) . is_some ( ) && index_ty == self . fcx . tcx . types . usize {
183
180
// Remove the method call record
184
181
tables. type_dependent_defs_mut ( ) . remove ( e. hir_id ) ;
185
182
tables. node_substs_mut ( ) . remove ( e. hir_id ) ;
@@ -191,24 +188,26 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
191
188
// of size information - we need to get rid of it
192
189
// Since this is "after" the other adjustment to be
193
190
// discarded, we do an extra `pop()`
194
- Some ( Adjustment { kind : Adjust :: Unsize , .. } ) => {
191
+ Some ( Adjustment {
192
+ kind : Adjust :: Unsize ,
193
+ ..
194
+ } ) => {
195
195
// So the borrow discard actually happens here
196
196
a. pop ( ) ;
197
- } ,
197
+ }
198
198
_ => { }
199
199
}
200
200
} ) ;
201
201
}
202
- } ,
202
+ }
203
203
// Might encounter non-valid indexes at this point, so there
204
204
// has to be a fall-through
205
- _ => { } ,
205
+ _ => { }
206
206
}
207
207
}
208
208
}
209
209
}
210
210
211
-
212
211
///////////////////////////////////////////////////////////////////////////
213
212
// Impl of Visitor for Resolver
214
213
//
@@ -262,7 +261,9 @@ impl<'cx, 'gcx, 'tcx> Visitor<'gcx> for WritebackCx<'cx, 'gcx, 'tcx> {
262
261
if let Some ( & bm) = self . fcx . tables . borrow ( ) . pat_binding_modes ( ) . get ( p. hir_id ) {
263
262
self . tables . pat_binding_modes_mut ( ) . insert ( p. hir_id , bm) ;
264
263
} else {
265
- self . tcx ( ) . sess . delay_span_bug ( p. span , "missing binding mode" ) ;
264
+ self . tcx ( )
265
+ . sess
266
+ . delay_span_bug ( p. span , "missing binding mode" ) ;
266
267
}
267
268
}
268
269
hir:: PatKind :: Struct ( _, ref fields, _) => {
@@ -310,8 +311,7 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
310
311
} ;
311
312
debug ! (
312
313
"Upvar capture for {:?} resolved to {:?}" ,
313
- upvar_id,
314
- new_upvar_capture
314
+ upvar_id, new_upvar_capture
315
315
) ;
316
316
self . tables
317
317
. upvar_capture_map
@@ -425,8 +425,7 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
425
425
if subst == ty {
426
426
// found it in the substitution list, replace with the
427
427
// parameter from the existential type
428
- return self
429
- . tcx ( )
428
+ return self . tcx ( )
430
429
. global_tcx ( )
431
430
. mk_ty_param ( param. index , param. name ) ;
432
431
}
@@ -464,14 +463,16 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
464
463
name : p. name ,
465
464
} ;
466
465
trace ! ( "replace {:?} with {:?}" , region, reg) ;
467
- return self . tcx ( ) . global_tcx ( )
466
+ return self . tcx ( )
467
+ . global_tcx ( )
468
468
. mk_region ( ty:: ReEarlyBound ( reg) ) ;
469
469
}
470
470
}
471
471
}
472
472
trace ! ( "anon_defn: {:#?}" , anon_defn) ;
473
473
trace ! ( "generics: {:#?}" , generics) ;
474
- self . tcx ( ) . sess
474
+ self . tcx ( )
475
+ . sess
475
476
. struct_span_err (
476
477
span,
477
478
"non-defining existential type use in defining scope" ,
@@ -480,25 +481,35 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
480
481
span,
481
482
format ! (
482
483
"lifetime `{}` is part of concrete type but not used \
483
- in parameter list of existential type",
484
+ in parameter list of existential type",
484
485
region,
485
486
) ,
486
487
)
487
488
. emit ( ) ;
488
489
self . tcx ( ) . global_tcx ( ) . mk_region ( ty:: ReStatic )
489
490
}
490
491
}
491
- }
492
+ } ,
492
493
} )
493
494
} ;
494
495
495
- let old = self . tables . concrete_existential_types . insert ( def_id, definition_ty) ;
496
+ if let ty:: Anon ( defin_ty_def_id, _substs) = definition_ty. sty {
497
+ if def_id == defin_ty_def_id {
498
+ // Concrete type resolved to the existential type itself
499
+ // Force a cycle error
500
+ self . tcx ( ) . at ( span) . type_of ( defin_ty_def_id) ;
501
+ }
502
+ }
503
+
504
+ let old = self . tables
505
+ . concrete_existential_types
506
+ . insert ( def_id, definition_ty) ;
496
507
if let Some ( old) = old {
497
508
if old != definition_ty {
498
509
span_bug ! (
499
510
span,
500
511
"visit_anon_types tried to write \
501
- different types for the same existential type: {:?}, {:?}, {:?}",
512
+ different types for the same existential type: {:?}, {:?}, {:?}",
502
513
def_id,
503
514
definition_ty,
504
515
old,
@@ -510,7 +521,12 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
510
521
511
522
fn visit_field_id ( & mut self , node_id : ast:: NodeId ) {
512
523
let hir_id = self . tcx ( ) . hir . node_to_hir_id ( node_id) ;
513
- if let Some ( index) = self . fcx . tables . borrow_mut ( ) . field_indices_mut ( ) . remove ( hir_id) {
524
+ if let Some ( index) = self . fcx
525
+ . tables
526
+ . borrow_mut ( )
527
+ . field_indices_mut ( )
528
+ . remove ( hir_id)
529
+ {
514
530
self . tables . field_indices_mut ( ) . insert ( hir_id, index) ;
515
531
}
516
532
}
@@ -559,8 +575,7 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
559
575
let resolved_adjustment = self . resolve ( & adjustment, & span) ;
560
576
debug ! (
561
577
"Adjustments for node {:?}: {:?}" ,
562
- hir_id,
563
- resolved_adjustment
578
+ hir_id, resolved_adjustment
564
579
) ;
565
580
self . tables
566
581
. adjustments_mut ( )
@@ -584,8 +599,7 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
584
599
let resolved_adjustment = self . resolve ( & adjustment, & span) ;
585
600
debug ! (
586
601
"pat_adjustments for node {:?}: {:?}" ,
587
- hir_id,
588
- resolved_adjustment
602
+ hir_id, resolved_adjustment
589
603
) ;
590
604
self . tables
591
605
. pat_adjustments_mut ( )
@@ -701,7 +715,8 @@ impl<'cx, 'gcx, 'tcx> Resolver<'cx, 'gcx, 'tcx> {
701
715
fn report_error ( & self , t : Ty < ' tcx > ) {
702
716
if !self . tcx . sess . has_errors ( ) {
703
717
self . infcx
704
- . need_type_info_err ( Some ( self . body . id ( ) ) , self . span . to_span ( & self . tcx ) , t) . emit ( ) ;
718
+ . need_type_info_err ( Some ( self . body . id ( ) ) , self . span . to_span ( & self . tcx ) , t)
719
+ . emit ( ) ;
705
720
}
706
721
}
707
722
}
0 commit comments