@@ -19,6 +19,7 @@ use rustc::util::nodemap::{FxHashSet, FxHashMap};
19
19
use rustc:: middle:: lang_items;
20
20
21
21
use syntax:: ast;
22
+ use syntax:: ast:: NodeId ;
22
23
use syntax:: feature_gate:: { self , GateIssue } ;
23
24
use syntax_pos:: Span ;
24
25
use errors:: { DiagnosticBuilder , DiagnosticId } ;
@@ -111,10 +112,10 @@ pub fn check_item_well_formed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: Def
111
112
check_item_fn ( tcx, item) ;
112
113
}
113
114
hir:: ItemStatic ( ..) => {
114
- check_item_type ( tcx, item) ;
115
+ check_item_type ( tcx, item. id ) ;
115
116
}
116
117
hir:: ItemConst ( ..) => {
117
- check_item_type ( tcx, item) ;
118
+ check_item_type ( tcx, item. id ) ;
118
119
}
119
120
hir:: ItemStruct ( ref struct_def, ref ast_generics) => {
120
121
check_type_defn ( tcx, item, false , |fcx| {
@@ -140,6 +141,17 @@ pub fn check_item_well_formed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: Def
140
141
hir:: ItemTrait ( ..) => {
141
142
check_trait ( tcx, item) ;
142
143
}
144
+ hir:: ItemForeignMod ( ref foreign_mod) => {
145
+ for foreign_item in foreign_mod. items . iter ( ) {
146
+ match foreign_item. node {
147
+ hir:: ForeignItemStatic ( ..) => {
148
+ check_item_type ( tcx, foreign_item. id ) ;
149
+ check_item_sized ( tcx, foreign_item. id ) ;
150
+ } ,
151
+ _ => { }
152
+ }
153
+ }
154
+ }
143
155
_ => { }
144
156
}
145
157
}
@@ -208,9 +220,9 @@ fn check_associated_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
208
220
} )
209
221
}
210
222
211
- fn for_item < ' a , ' gcx , ' tcx > ( tcx : TyCtxt < ' a , ' gcx , ' gcx > , item : & hir :: Item )
223
+ fn for_item < ' a , ' gcx , ' tcx > ( tcx : TyCtxt < ' a , ' gcx , ' gcx > , id : NodeId )
212
224
-> CheckWfFcxBuilder < ' a , ' gcx , ' tcx > {
213
- for_id ( tcx, item . id , item . span )
225
+ for_id ( tcx, id, tcx . hir . span ( id ) )
214
226
}
215
227
216
228
fn for_id < ' a , ' gcx , ' tcx > ( tcx : TyCtxt < ' a , ' gcx , ' gcx > , id : ast:: NodeId , span : Span )
@@ -229,7 +241,7 @@ fn check_type_defn<'a, 'tcx, F>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
229
241
item : & hir:: Item , all_sized : bool , mut lookup_fields : F )
230
242
where F : for <' fcx , ' gcx , ' tcx2 > FnMut ( & FnCtxt < ' fcx , ' gcx , ' tcx2 > ) -> Vec < AdtVariant < ' tcx2 > >
231
243
{
232
- for_item ( tcx, item) . with_fcx ( |fcx, fcx_tcx| {
244
+ for_item ( tcx, item. id ) . with_fcx ( |fcx, fcx_tcx| {
233
245
let variants = lookup_fields ( fcx) ;
234
246
let def_id = fcx. tcx . hir . local_def_id ( item. id ) ;
235
247
let packed = fcx. tcx . adt_def ( def_id) . repr . packed ( ) ;
@@ -283,14 +295,14 @@ fn check_type_defn<'a, 'tcx, F>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
283
295
284
296
fn check_trait < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , item : & hir:: Item ) {
285
297
let trait_def_id = tcx. hir . local_def_id ( item. id ) ;
286
- for_item ( tcx, item) . with_fcx ( |fcx, _| {
298
+ for_item ( tcx, item. id ) . with_fcx ( |fcx, _| {
287
299
check_where_clauses ( tcx, fcx, item. span , trait_def_id) ;
288
300
vec ! [ ]
289
301
} ) ;
290
302
}
291
303
292
304
fn check_item_fn < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , item : & hir:: Item ) {
293
- for_item ( tcx, item) . with_fcx ( |fcx, tcx| {
305
+ for_item ( tcx, item. id ) . with_fcx ( |fcx, tcx| {
294
306
let def_id = fcx. tcx . hir . local_def_id ( item. id ) ;
295
307
let sig = fcx. tcx . fn_sig ( def_id) ;
296
308
let sig = fcx. normalize_associated_types_in ( item. span , & sig) ;
@@ -301,16 +313,34 @@ fn check_item_fn<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item: &hir::Item) {
301
313
} )
302
314
}
303
315
316
+ pub fn check_item_sized < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , id : NodeId ) {
317
+ for_item ( tcx, id) . with_fcx ( |fcx, _this| {
318
+ let span = tcx. hir . span ( id) ;
319
+ let ty = fcx. tcx . type_of ( fcx. tcx . hir . local_def_id ( id) ) ;
320
+ let item_ty = fcx. normalize_associated_types_in ( span, & ty) ;
321
+
322
+ fcx. register_bound (
323
+ item_ty,
324
+ fcx. tcx . require_lang_item ( lang_items:: SizedTraitLangItem ) ,
325
+ traits:: ObligationCause :: new ( span,
326
+ fcx. body_id ,
327
+ traits:: SizedReturnType
328
+ )
329
+ ) ;
330
+
331
+ vec ! [ ] // no implied bounds in a const etc
332
+ } ) ;
333
+ }
334
+
304
335
fn check_item_type < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
305
- item : & hir :: Item )
336
+ id : NodeId )
306
337
{
307
- debug ! ( "check_item_type: {:?}" , item) ;
338
+ for_item ( tcx, id) . with_fcx ( |fcx, _this| {
339
+ let span = tcx. hir . span ( id) ;
340
+ let ty = fcx. tcx . type_of ( fcx. tcx . hir . local_def_id ( id) ) ;
341
+ let item_ty = fcx. normalize_associated_types_in ( span, & ty) ;
308
342
309
- for_item ( tcx, item) . with_fcx ( |fcx, _this| {
310
- let ty = fcx. tcx . type_of ( fcx. tcx . hir . local_def_id ( item. id ) ) ;
311
- let item_ty = fcx. normalize_associated_types_in ( item. span , & ty) ;
312
-
313
- fcx. register_wf_obligation ( item_ty, item. span , ObligationCauseCode :: MiscObligation ) ;
343
+ fcx. register_wf_obligation ( item_ty, span, ObligationCauseCode :: MiscObligation ) ;
314
344
315
345
vec ! [ ] // no implied bounds in a const etc
316
346
} ) ;
@@ -321,9 +351,7 @@ fn check_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
321
351
ast_self_ty : & hir:: Ty ,
322
352
ast_trait_ref : & Option < hir:: TraitRef > )
323
353
{
324
- debug ! ( "check_impl: {:?}" , item) ;
325
-
326
- for_item ( tcx, item) . with_fcx ( |fcx, tcx| {
354
+ for_item ( tcx, item. id ) . with_fcx ( |fcx, tcx| {
327
355
let item_def_id = fcx. tcx . hir . local_def_id ( item. id ) ;
328
356
329
357
match * ast_trait_ref {
0 commit comments