@@ -13,7 +13,7 @@ use constrained_type_params::{identify_constrained_type_params, Parameter};
13
13
14
14
use hir:: def_id:: DefId ;
15
15
use rustc:: traits:: { self , ObligationCauseCode } ;
16
- use rustc:: ty:: { self , Lift , Ty , TyCtxt , GenericParamDefKind , TypeFoldable } ;
16
+ use rustc:: ty:: { self , Lift , Ty , TyCtxt , TyKind , GenericParamDefKind , TypeFoldable } ;
17
17
use rustc:: ty:: subst:: { Subst , Substs } ;
18
18
use rustc:: ty:: util:: ExplicitSelf ;
19
19
use rustc:: util:: nodemap:: { FxHashSet , FxHashMap } ;
@@ -119,14 +119,14 @@ pub fn check_item_well_formed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: Def
119
119
check_item_fn ( tcx, item) ;
120
120
}
121
121
hir:: ItemKind :: Static ( ref ty, ..) => {
122
- check_item_type ( tcx, item. id , ty. span ) ;
122
+ check_item_type ( tcx, item. id , ty. span , false ) ;
123
123
}
124
124
hir:: ItemKind :: Const ( ref ty, ..) => {
125
- check_item_type ( tcx, item. id , ty. span ) ;
125
+ check_item_type ( tcx, item. id , ty. span , false ) ;
126
126
}
127
127
hir:: ItemKind :: ForeignMod ( ref module) => for it in module. items . iter ( ) {
128
128
if let hir:: ForeignItemKind :: Static ( ref ty, ..) = it. node {
129
- check_item_type ( tcx, it. id , ty. span ) ;
129
+ check_item_type ( tcx, it. id , ty. span , true ) ;
130
130
}
131
131
} ,
132
132
hir:: ItemKind :: Struct ( ref struct_def, ref ast_generics) => {
@@ -340,23 +340,33 @@ fn check_item_fn<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item: &hir::Item) {
340
340
} )
341
341
}
342
342
343
- fn check_item_type < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , item_id : ast:: NodeId , ty_span : Span ) {
343
+ fn check_item_type < ' a , ' tcx > (
344
+ tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
345
+ item_id : ast:: NodeId ,
346
+ ty_span : Span ,
347
+ allow_foreign_ty : bool ,
348
+ ) {
344
349
debug ! ( "check_item_type: {:?}" , item_id) ;
345
350
346
351
for_id ( tcx, item_id, ty_span) . with_fcx ( |fcx, _this| {
347
352
let ty = fcx. tcx . type_of ( fcx. tcx . hir . local_def_id ( item_id) ) ;
348
353
let item_ty = fcx. normalize_associated_types_in ( ty_span, & ty) ;
349
354
355
+ let mut forbid_unsized = true ;
356
+ if allow_foreign_ty {
357
+ if let TyKind :: Foreign ( _) = tcx. struct_tail ( item_ty) . sty {
358
+ forbid_unsized = false ;
359
+ }
360
+ }
361
+
350
362
fcx. register_wf_obligation ( item_ty, ty_span, ObligationCauseCode :: MiscObligation ) ;
351
- fcx. register_bound (
352
- item_ty,
353
- fcx. tcx . require_lang_item ( lang_items:: SizedTraitLangItem ) ,
354
- traits:: ObligationCause :: new (
355
- ty_span,
356
- fcx. body_id ,
357
- traits:: MiscObligation ,
358
- ) ,
359
- ) ;
363
+ if forbid_unsized {
364
+ fcx. register_bound (
365
+ item_ty,
366
+ fcx. tcx . require_lang_item ( lang_items:: SizedTraitLangItem ) ,
367
+ traits:: ObligationCause :: new ( ty_span, fcx. body_id , traits:: MiscObligation ) ,
368
+ ) ;
369
+ }
360
370
361
371
vec ! [ ] // no implied bounds in a const etc
362
372
} ) ;
0 commit comments