@@ -23,7 +23,7 @@ use util::ppaux::{Repr, UserString};
23
23
use std:: collections:: HashSet ;
24
24
use syntax:: ast;
25
25
use syntax:: ast_util:: local_def;
26
- use syntax:: codemap:: Span ;
26
+ use syntax:: codemap:: { DUMMY_SP , Span } ;
27
27
use syntax:: parse:: token:: { self , special_idents} ;
28
28
use syntax:: visit;
29
29
use syntax:: visit:: Visitor ;
@@ -162,15 +162,14 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
162
162
self . with_fcx ( item, |this, fcx| {
163
163
let variants = lookup_fields ( fcx) ;
164
164
let mut bounds_checker = BoundsChecker :: new ( fcx,
165
- item. span ,
166
165
item. id ,
167
166
Some ( & mut this. cache ) ) ;
168
167
debug ! ( "check_type_defn at bounds_checker.scope: {:?}" , bounds_checker. scope) ;
169
168
170
- for variant in & variants {
169
+ for variant in & variants {
171
170
for field in & variant. fields {
172
171
// Regions are checked below.
173
- bounds_checker. check_traits_in_ty ( field. ty ) ;
172
+ bounds_checker. check_traits_in_ty ( field. ty , field . span ) ;
174
173
}
175
174
176
175
// For DST, all intermediate types must be sized.
@@ -199,7 +198,6 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
199
198
{
200
199
self . with_fcx ( item, |this, fcx| {
201
200
let mut bounds_checker = BoundsChecker :: new ( fcx,
202
- item. span ,
203
201
item. id ,
204
202
Some ( & mut this. cache ) ) ;
205
203
debug ! ( "check_item_type at bounds_checker.scope: {:?}" , bounds_checker. scope) ;
@@ -209,7 +207,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
209
207
& fcx. inh . param_env . free_substs ,
210
208
& type_scheme. ty ) ;
211
209
212
- bounds_checker. check_traits_in_ty ( item_ty) ;
210
+ bounds_checker. check_traits_in_ty ( item_ty, item . span ) ;
213
211
} ) ;
214
212
}
215
213
@@ -218,7 +216,6 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
218
216
{
219
217
self . with_fcx ( item, |this, fcx| {
220
218
let mut bounds_checker = BoundsChecker :: new ( fcx,
221
- item. span ,
222
219
item. id ,
223
220
Some ( & mut this. cache ) ) ;
224
221
debug ! ( "check_impl at bounds_checker.scope: {:?}" , bounds_checker. scope) ;
@@ -231,7 +228,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
231
228
& fcx. inh . param_env . free_substs ,
232
229
& self_ty) ;
233
230
234
- bounds_checker. check_traits_in_ty ( self_ty) ;
231
+ bounds_checker. check_traits_in_ty ( self_ty, item . span ) ;
235
232
236
233
// Similarly, obtain an "inside" reference to the trait
237
234
// that the impl implements.
@@ -252,7 +249,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
252
249
// trait reference. Instead, this is done at the impl site.
253
250
// Arguably this is wrong and we should treat the trait-reference
254
251
// the same way as we treat the self-type.
255
- bounds_checker. check_trait_ref ( & trait_ref) ;
252
+ bounds_checker. check_trait_ref ( & trait_ref, item . span ) ;
256
253
257
254
let cause =
258
255
traits:: ObligationCause :: new (
@@ -483,11 +480,10 @@ pub struct BoundsChecker<'cx,'tcx:'cx> {
483
480
484
481
impl < ' cx , ' tcx > BoundsChecker < ' cx , ' tcx > {
485
482
pub fn new ( fcx : & ' cx FnCtxt < ' cx , ' tcx > ,
486
- span : Span ,
487
483
scope : ast:: NodeId ,
488
484
cache : Option < & ' cx mut HashSet < Ty < ' tcx > > > )
489
485
-> BoundsChecker < ' cx , ' tcx > {
490
- BoundsChecker { fcx : fcx, span : span , scope : scope,
486
+ BoundsChecker { fcx : fcx, span : DUMMY_SP , scope : scope,
491
487
cache : cache, binding_count : 0 }
492
488
}
493
489
@@ -500,30 +496,32 @@ impl<'cx,'tcx> BoundsChecker<'cx,'tcx> {
500
496
///
501
497
/// Note that it does not (currently, at least) check that `A : Copy` (that check is delegated
502
498
/// to the point where impl `A : Trait<B>` is implemented).
503
- pub fn check_trait_ref ( & mut self , trait_ref : & ty:: TraitRef < ' tcx > ) {
499
+ pub fn check_trait_ref ( & mut self , trait_ref : & ty:: TraitRef < ' tcx > , span : Span ) {
504
500
let trait_predicates = ty:: lookup_predicates ( self . fcx . tcx ( ) , trait_ref. def_id ) ;
505
501
506
- let bounds = self . fcx . instantiate_bounds ( self . span ,
502
+ let bounds = self . fcx . instantiate_bounds ( span,
507
503
trait_ref. substs ,
508
504
& trait_predicates) ;
509
505
510
506
self . fcx . add_obligations_for_parameters (
511
507
traits:: ObligationCause :: new (
512
- self . span ,
508
+ span,
513
509
self . fcx . body_id ,
514
510
traits:: ItemObligation ( trait_ref. def_id ) ) ,
515
511
& bounds) ;
516
512
517
513
for & ty in & trait_ref. substs . types {
518
- self . check_traits_in_ty ( ty) ;
514
+ self . check_traits_in_ty ( ty, span ) ;
519
515
}
520
516
}
521
517
522
- pub fn check_ty ( & mut self , ty : Ty < ' tcx > ) {
518
+ pub fn check_ty ( & mut self , ty : Ty < ' tcx > , span : Span ) {
519
+ self . span = span;
523
520
ty. fold_with ( self ) ;
524
521
}
525
522
526
- fn check_traits_in_ty ( & mut self , ty : Ty < ' tcx > ) {
523
+ fn check_traits_in_ty ( & mut self , ty : Ty < ' tcx > , span : Span ) {
524
+ self . span = span;
527
525
// When checking types outside of a type def'n, we ignore
528
526
// region obligations. See discussion below in fold_ty().
529
527
self . binding_count += 1 ;
0 commit comments