@@ -15,7 +15,7 @@ use rustc_middle::ty::{
15
15
self , AdtKind , GenericParamDefKind , ToPredicate , Ty , TyCtxt , TypeFoldable , WithConstness ,
16
16
} ;
17
17
use rustc_session:: parse:: feature_err;
18
- use rustc_span:: symbol:: { sym, Symbol } ;
18
+ use rustc_span:: symbol:: { sym, Ident , Symbol } ;
19
19
use rustc_span:: Span ;
20
20
use rustc_trait_selection:: opaque_types:: may_define_opaque_type;
21
21
use rustc_trait_selection:: traits:: query:: evaluate_obligation:: InferCtxtExt ;
@@ -142,8 +142,8 @@ pub fn check_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) {
142
142
_ => unreachable ! ( ) ,
143
143
}
144
144
}
145
- hir:: ItemKind :: Fn ( ..) => {
146
- check_item_fn ( tcx, item) ;
145
+ hir:: ItemKind :: Fn ( ref sig , ..) => {
146
+ check_item_fn ( tcx, item. hir_id , item . ident , item . span , sig . decl ) ;
147
147
}
148
148
hir:: ItemKind :: Static ( ref ty, ..) => {
149
149
check_item_type ( tcx, item. hir_id , ty. span , false ) ;
@@ -153,8 +153,14 @@ pub fn check_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) {
153
153
}
154
154
hir:: ItemKind :: ForeignMod ( ref module) => {
155
155
for it in module. items . iter ( ) {
156
- if let hir:: ForeignItemKind :: Static ( ref ty, ..) = it. kind {
157
- check_item_type ( tcx, it. hir_id , ty. span , true ) ;
156
+ match it. kind {
157
+ hir:: ForeignItemKind :: Fn ( ref decl, ..) => {
158
+ check_item_fn ( tcx, it. hir_id , it. ident , it. span , decl)
159
+ }
160
+ hir:: ForeignItemKind :: Static ( ref ty, ..) => {
161
+ check_item_type ( tcx, it. hir_id , ty. span , true )
162
+ }
163
+ hir:: ForeignItemKind :: Type => ( ) ,
158
164
}
159
165
}
160
166
}
@@ -303,7 +309,7 @@ fn check_associated_item(
303
309
fcx,
304
310
item. ident . span ,
305
311
sig,
306
- hir_sig,
312
+ hir_sig. decl ,
307
313
item. def_id ,
308
314
& mut implied_bounds,
309
315
) ;
@@ -564,22 +570,24 @@ fn check_associated_type_defaults(fcx: &FnCtxt<'_, '_>, trait_def_id: DefId) {
564
570
}
565
571
}
566
572
567
- fn check_item_fn ( tcx : TyCtxt < ' _ > , item : & hir:: Item < ' _ > ) {
568
- for_item ( tcx, item) . with_fcx ( |fcx, tcx| {
569
- let def_id = fcx. tcx . hir ( ) . local_def_id ( item. hir_id ) ;
573
+ fn check_item_fn (
574
+ tcx : TyCtxt < ' _ > ,
575
+ item_id : hir:: HirId ,
576
+ ident : Ident ,
577
+ span : Span ,
578
+ decl : & hir:: FnDecl < ' _ > ,
579
+ ) {
580
+ for_id ( tcx, item_id, span) . with_fcx ( |fcx, tcx| {
581
+ let def_id = fcx. tcx . hir ( ) . local_def_id ( item_id) ;
570
582
let sig = fcx. tcx . fn_sig ( def_id) ;
571
- let sig = fcx. normalize_associated_types_in ( item . span , & sig) ;
583
+ let sig = fcx. normalize_associated_types_in ( span, & sig) ;
572
584
let mut implied_bounds = vec ! [ ] ;
573
- let hir_sig = match & item. kind {
574
- ItemKind :: Fn ( sig, ..) => sig,
575
- _ => bug ! ( "expected `ItemKind::Fn`, found `{:?}`" , item. kind) ,
576
- } ;
577
585
check_fn_or_method (
578
586
tcx,
579
587
fcx,
580
- item . ident . span ,
588
+ ident. span ,
581
589
sig,
582
- hir_sig ,
590
+ decl ,
583
591
def_id. to_def_id ( ) ,
584
592
& mut implied_bounds,
585
593
) ;
@@ -835,28 +843,28 @@ fn check_fn_or_method<'fcx, 'tcx>(
835
843
fcx : & FnCtxt < ' fcx , ' tcx > ,
836
844
span : Span ,
837
845
sig : ty:: PolyFnSig < ' tcx > ,
838
- hir_sig : & hir:: FnSig < ' _ > ,
846
+ hir_decl : & hir:: FnDecl < ' _ > ,
839
847
def_id : DefId ,
840
848
implied_bounds : & mut Vec < Ty < ' tcx > > ,
841
849
) {
842
850
let sig = fcx. normalize_associated_types_in ( span, & sig) ;
843
851
let sig = fcx. tcx . liberate_late_bound_regions ( def_id, & sig) ;
844
852
845
- for ( & input_ty, span) in sig. inputs ( ) . iter ( ) . zip ( hir_sig . decl . inputs . iter ( ) . map ( |t| t. span ) ) {
853
+ for ( & input_ty, span) in sig. inputs ( ) . iter ( ) . zip ( hir_decl . inputs . iter ( ) . map ( |t| t. span ) ) {
846
854
fcx. register_wf_obligation ( input_ty. into ( ) , span, ObligationCauseCode :: MiscObligation ) ;
847
855
}
848
856
implied_bounds. extend ( sig. inputs ( ) ) ;
849
857
850
858
fcx. register_wf_obligation (
851
859
sig. output ( ) . into ( ) ,
852
- hir_sig . decl . output . span ( ) ,
860
+ hir_decl . output . span ( ) ,
853
861
ObligationCauseCode :: ReturnType ,
854
862
) ;
855
863
856
864
// FIXME(#25759) return types should not be implied bounds
857
865
implied_bounds. push ( sig. output ( ) ) ;
858
866
859
- check_where_clauses ( tcx, fcx, span, def_id, Some ( ( sig. output ( ) , hir_sig . decl . output . span ( ) ) ) ) ;
867
+ check_where_clauses ( tcx, fcx, span, def_id, Some ( ( sig. output ( ) , hir_decl . output . span ( ) ) ) ) ;
860
868
}
861
869
862
870
/// Checks "defining uses" of opaque `impl Trait` types to ensure that they meet the restrictions
0 commit comments