@@ -118,10 +118,10 @@ pub fn check_item_well_formed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: Def
118
118
check_item_fn ( tcx, item) ;
119
119
}
120
120
hir:: ItemStatic ( ..) => {
121
- check_item_type ( tcx, item) ;
121
+ check_item_type ( tcx, item. id , None ) ;
122
122
}
123
123
hir:: ItemConst ( ..) => {
124
- check_item_type ( tcx, item) ;
124
+ check_item_type ( tcx, item. id , None ) ;
125
125
}
126
126
hir:: ItemStruct ( ref struct_def, ref ast_generics) => {
127
127
check_type_defn ( tcx, item, false , |fcx| {
@@ -147,6 +147,17 @@ pub fn check_item_well_formed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: Def
147
147
hir:: ItemTrait ( ..) => {
148
148
check_trait ( tcx, item) ;
149
149
}
150
+ hir:: ItemForeignMod ( ref foreign_mod) => {
151
+ for foreign_item in foreign_mod. items . iter ( ) {
152
+ match foreign_item. node {
153
+ hir:: ForeignItemStatic ( ..) => {
154
+ check_item_type ( tcx, foreign_item. id ,
155
+ Some ( ObligationCauseCode :: SizedReturnType ) ) ;
156
+ } ,
157
+ _ => { }
158
+ }
159
+ }
160
+ }
150
161
_ => { }
151
162
}
152
163
}
@@ -215,9 +226,9 @@ fn check_associated_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
215
226
} )
216
227
}
217
228
218
- fn for_item < ' a , ' gcx , ' tcx > ( tcx : TyCtxt < ' a , ' gcx , ' gcx > , item : & hir :: Item )
229
+ fn for_item < ' a , ' gcx , ' tcx > ( tcx : TyCtxt < ' a , ' gcx , ' gcx > , id : ast :: NodeId )
219
230
-> CheckWfFcxBuilder < ' a , ' gcx , ' tcx > {
220
- for_id ( tcx, item . id , item . span )
231
+ for_id ( tcx, id, tcx . hir . span ( id ) )
221
232
}
222
233
223
234
fn for_id < ' a , ' gcx , ' tcx > ( tcx : TyCtxt < ' a , ' gcx , ' gcx > , id : ast:: NodeId , span : Span )
@@ -236,7 +247,7 @@ fn check_type_defn<'a, 'tcx, F>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
236
247
item : & hir:: Item , all_sized : bool , mut lookup_fields : F )
237
248
where F : for <' fcx , ' gcx , ' tcx2 > FnMut ( & FnCtxt < ' fcx , ' gcx , ' tcx2 > ) -> Vec < AdtVariant < ' tcx2 > >
238
249
{
239
- for_item ( tcx, item) . with_fcx ( |fcx, fcx_tcx| {
250
+ for_item ( tcx, item. id ) . with_fcx ( |fcx, fcx_tcx| {
240
251
let variants = lookup_fields ( fcx) ;
241
252
let def_id = fcx. tcx . hir . local_def_id ( item. id ) ;
242
253
let packed = fcx. tcx . adt_def ( def_id) . repr . packed ( ) ;
@@ -290,14 +301,14 @@ fn check_type_defn<'a, 'tcx, F>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
290
301
291
302
fn check_trait < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , item : & hir:: Item ) {
292
303
let trait_def_id = tcx. hir . local_def_id ( item. id ) ;
293
- for_item ( tcx, item) . with_fcx ( |fcx, _| {
304
+ for_item ( tcx, item. id ) . with_fcx ( |fcx, _| {
294
305
check_where_clauses ( tcx, fcx, item. span , trait_def_id) ;
295
306
vec ! [ ]
296
307
} ) ;
297
308
}
298
309
299
310
fn check_item_fn < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , item : & hir:: Item ) {
300
- for_item ( tcx, item) . with_fcx ( |fcx, tcx| {
311
+ for_item ( tcx, item. id ) . with_fcx ( |fcx, tcx| {
301
312
let def_id = fcx. tcx . hir . local_def_id ( item. id ) ;
302
313
let sig = fcx. tcx . fn_sig ( def_id) ;
303
314
let sig = fcx. normalize_associated_types_in ( item. span , & sig) ;
@@ -309,15 +320,24 @@ fn check_item_fn<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item: &hir::Item) {
309
320
}
310
321
311
322
fn check_item_type < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
312
- item : & hir:: Item )
323
+ id : ast:: NodeId ,
324
+ size_check : Option < ObligationCauseCode < ' tcx > > )
313
325
{
314
- debug ! ( "check_item_type: {:?}" , item ) ;
326
+ debug ! ( "check_item_type: {:?}" , tcx . hir . get ( id ) ) ;
315
327
316
- for_item ( tcx, item) . with_fcx ( |fcx, _this| {
317
- let ty = fcx. tcx . type_of ( fcx. tcx . hir . local_def_id ( item. id ) ) ;
318
- let item_ty = fcx. normalize_associated_types_in ( item. span , & ty) ;
328
+ for_item ( tcx, id) . with_fcx ( |fcx, _this| {
329
+ let span = tcx. hir . span ( id) ;
330
+ let ty = fcx. tcx . type_of ( fcx. tcx . hir . local_def_id ( id) ) ;
331
+ let item_ty = fcx. normalize_associated_types_in ( span, & ty) ;
319
332
320
- fcx. register_wf_obligation ( item_ty, item. span , ObligationCauseCode :: MiscObligation ) ;
333
+ fcx. register_wf_obligation ( item_ty, span, ObligationCauseCode :: MiscObligation ) ;
334
+
335
+ match size_check {
336
+ None => { }
337
+ Some ( code) => {
338
+ fcx. require_type_is_sized ( item_ty, span, code) ;
339
+ }
340
+ }
321
341
322
342
vec ! [ ] // no implied bounds in a const etc
323
343
} ) ;
@@ -330,7 +350,7 @@ fn check_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
330
350
{
331
351
debug ! ( "check_impl: {:?}" , item) ;
332
352
333
- for_item ( tcx, item) . with_fcx ( |fcx, tcx| {
353
+ for_item ( tcx, item. id ) . with_fcx ( |fcx, tcx| {
334
354
let item_def_id = fcx. tcx . hir . local_def_id ( item. id ) ;
335
355
336
356
match * ast_trait_ref {
0 commit comments