@@ -17,15 +17,15 @@ use rustc::hir;
1717use rustc:: hir:: def_id:: { DefId , DefIndex } ;
1818use rustc:: hir:: intravisit:: { self , NestedVisitorMap , Visitor } ;
1919use rustc:: infer:: InferCtxt ;
20+ use rustc:: ty:: adjustment:: { Adjust , Adjustment } ;
21+ use rustc:: ty:: fold:: { BottomUpFolder , TypeFoldable , TypeFolder } ;
2022use rustc:: ty:: subst:: UnpackedKind ;
2123use rustc:: ty:: { self , Ty , TyCtxt } ;
22- use rustc:: ty:: adjustment:: { Adjust , Adjustment } ;
23- use rustc:: ty:: fold:: { TypeFoldable , TypeFolder , BottomUpFolder } ;
2424use rustc:: util:: nodemap:: DefIdSet ;
25+ use rustc_data_structures:: sync:: Lrc ;
26+ use std:: mem;
2527use syntax:: ast;
2628use syntax_pos:: Span ;
27- use std:: mem;
28- use rustc_data_structures:: sync:: Lrc ;
2929
3030///////////////////////////////////////////////////////////////////////////
3131// Entry point
@@ -55,17 +55,15 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
5555 ) ;
5656 debug ! (
5757 "used_trait_imports({:?}) = {:?}" ,
58- item_def_id,
59- used_trait_imports
58+ item_def_id, used_trait_imports
6059 ) ;
6160 wbcx. tables . used_trait_imports = used_trait_imports;
6261
6362 wbcx. tables . tainted_by_errors = self . is_tainted_by_errors ( ) ;
6463
6564 debug ! (
6665 "writeback: tables for {:?} are {:#?}" ,
67- item_def_id,
68- wbcx. tables
66+ item_def_id, wbcx. tables
6967 ) ;
7068
7169 self . tcx . alloc_tables ( wbcx. tables )
@@ -118,8 +116,8 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
118116 // operating on scalars, we clear the overload.
119117 fn fix_scalar_builtin_expr ( & mut self , e : & hir:: Expr ) {
120118 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) => {
123121 let inner_ty = self . fcx . node_ty ( inner. hir_id ) ;
124122 let inner_ty = self . fcx . resolve_type_vars_if_possible ( & inner_ty) ;
125123
@@ -178,8 +176,7 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
178176 let index_ty = tables. expr_ty_adjusted ( & index) ;
179177 let index_ty = self . fcx . resolve_type_vars_if_possible ( & index_ty) ;
180178
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 {
183180 // Remove the method call record
184181 tables. type_dependent_defs_mut ( ) . remove ( e. hir_id ) ;
185182 tables. node_substs_mut ( ) . remove ( e. hir_id ) ;
@@ -191,24 +188,26 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
191188 // of size information - we need to get rid of it
192189 // Since this is "after" the other adjustment to be
193190 // discarded, we do an extra `pop()`
194- Some ( Adjustment { kind : Adjust :: Unsize , .. } ) => {
191+ Some ( Adjustment {
192+ kind : Adjust :: Unsize ,
193+ ..
194+ } ) => {
195195 // So the borrow discard actually happens here
196196 a. pop ( ) ;
197- } ,
197+ }
198198 _ => { }
199199 }
200200 } ) ;
201201 }
202- } ,
202+ }
203203 // Might encounter non-valid indexes at this point, so there
204204 // has to be a fall-through
205- _ => { } ,
205+ _ => { }
206206 }
207207 }
208208 }
209209}
210210
211-
212211///////////////////////////////////////////////////////////////////////////
213212// Impl of Visitor for Resolver
214213//
@@ -262,7 +261,9 @@ impl<'cx, 'gcx, 'tcx> Visitor<'gcx> for WritebackCx<'cx, 'gcx, 'tcx> {
262261 if let Some ( & bm) = self . fcx . tables . borrow ( ) . pat_binding_modes ( ) . get ( p. hir_id ) {
263262 self . tables . pat_binding_modes_mut ( ) . insert ( p. hir_id , bm) ;
264263 } 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" ) ;
266267 }
267268 }
268269 hir:: PatKind :: Struct ( _, ref fields, _) => {
@@ -310,8 +311,7 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
310311 } ;
311312 debug ! (
312313 "Upvar capture for {:?} resolved to {:?}" ,
313- upvar_id,
314- new_upvar_capture
314+ upvar_id, new_upvar_capture
315315 ) ;
316316 self . tables
317317 . upvar_capture_map
@@ -425,8 +425,7 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
425425 if subst == ty {
426426 // found it in the substitution list, replace with the
427427 // parameter from the existential type
428- return self
429- . tcx ( )
428+ return self . tcx ( )
430429 . global_tcx ( )
431430 . mk_ty_param ( param. index , param. name ) ;
432431 }
@@ -464,14 +463,16 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
464463 name : p. name ,
465464 } ;
466465 trace ! ( "replace {:?} with {:?}" , region, reg) ;
467- return self . tcx ( ) . global_tcx ( )
466+ return self . tcx ( )
467+ . global_tcx ( )
468468 . mk_region ( ty:: ReEarlyBound ( reg) ) ;
469469 }
470470 }
471471 }
472472 trace ! ( "anon_defn: {:#?}" , anon_defn) ;
473473 trace ! ( "generics: {:#?}" , generics) ;
474- self . tcx ( ) . sess
474+ self . tcx ( )
475+ . sess
475476 . struct_span_err (
476477 span,
477478 "non-defining existential type use in defining scope" ,
@@ -480,25 +481,35 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
480481 span,
481482 format ! (
482483 "lifetime `{}` is part of concrete type but not used \
483- in parameter list of existential type",
484+ in parameter list of existential type",
484485 region,
485486 ) ,
486487 )
487488 . emit ( ) ;
488489 self . tcx ( ) . global_tcx ( ) . mk_region ( ty:: ReStatic )
489490 }
490491 }
491- }
492+ } ,
492493 } )
493494 } ;
494495
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) ;
496507 if let Some ( old) = old {
497508 if old != definition_ty {
498509 span_bug ! (
499510 span,
500511 "visit_anon_types tried to write \
501- different types for the same existential type: {:?}, {:?}, {:?}",
512+ different types for the same existential type: {:?}, {:?}, {:?}",
502513 def_id,
503514 definition_ty,
504515 old,
@@ -510,7 +521,12 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
510521
511522 fn visit_field_id ( & mut self , node_id : ast:: NodeId ) {
512523 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+ {
514530 self . tables . field_indices_mut ( ) . insert ( hir_id, index) ;
515531 }
516532 }
@@ -559,8 +575,7 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
559575 let resolved_adjustment = self . resolve ( & adjustment, & span) ;
560576 debug ! (
561577 "Adjustments for node {:?}: {:?}" ,
562- hir_id,
563- resolved_adjustment
578+ hir_id, resolved_adjustment
564579 ) ;
565580 self . tables
566581 . adjustments_mut ( )
@@ -584,8 +599,7 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
584599 let resolved_adjustment = self . resolve ( & adjustment, & span) ;
585600 debug ! (
586601 "pat_adjustments for node {:?}: {:?}" ,
587- hir_id,
588- resolved_adjustment
602+ hir_id, resolved_adjustment
589603 ) ;
590604 self . tables
591605 . pat_adjustments_mut ( )
@@ -701,7 +715,8 @@ impl<'cx, 'gcx, 'tcx> Resolver<'cx, 'gcx, 'tcx> {
701715 fn report_error ( & self , t : Ty < ' tcx > ) {
702716 if !self . tcx . sess . has_errors ( ) {
703717 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 ( ) ;
705720 }
706721 }
707722}
0 commit comments