@@ -19,7 +19,8 @@ use middle::def;
1919use middle:: dependency_format;
2020use middle:: freevars:: CaptureModeMap ;
2121use middle:: freevars;
22- use middle:: lang_items:: { FnMutTraitLangItem , OpaqueStructLangItem } ;
22+ use middle:: lang_items:: { FnTraitLangItem , FnMutTraitLangItem } ;
23+ use middle:: lang_items:: { FnOnceTraitLangItem , OpaqueStructLangItem } ;
2324use middle:: lang_items:: { TyDescStructLangItem , TyVisitorTraitLangItem } ;
2425use middle:: mem_categorization as mc;
2526use middle:: resolve;
@@ -1205,6 +1206,24 @@ pub enum UnboxedClosureKind {
12051206 FnOnceUnboxedClosureKind ,
12061207}
12071208
1209+ impl UnboxedClosureKind {
1210+ pub fn trait_did ( & self , cx : & ctxt ) -> ast:: DefId {
1211+ let result = match * self {
1212+ FnUnboxedClosureKind => cx. lang_items . require ( FnTraitLangItem ) ,
1213+ FnMutUnboxedClosureKind => {
1214+ cx. lang_items . require ( FnMutTraitLangItem )
1215+ }
1216+ FnOnceUnboxedClosureKind => {
1217+ cx. lang_items . require ( FnOnceTraitLangItem )
1218+ }
1219+ } ;
1220+ match result {
1221+ Ok ( trait_did) => trait_did,
1222+ Err ( err) => cx. sess . fatal ( err. as_slice ( ) ) ,
1223+ }
1224+ }
1225+ }
1226+
12081227pub fn mk_ctxt ( s : Session ,
12091228 dm : resolve:: DefMap ,
12101229 named_region_map : resolve_lifetime:: NamedRegionMap ,
@@ -3195,19 +3214,23 @@ impl AutoRef {
31953214 }
31963215}
31973216
3198- pub fn method_call_type_param_defs ( tcx : & ctxt , origin : typeck:: MethodOrigin )
3199- -> VecPerParamSpace < TypeParameterDef > {
3217+ pub fn method_call_type_param_defs < T > ( typer : & T ,
3218+ origin : typeck:: MethodOrigin )
3219+ -> VecPerParamSpace < TypeParameterDef >
3220+ where T : mc:: Typer {
32003221 match origin {
32013222 typeck:: MethodStatic ( did) => {
3202- ty:: lookup_item_type ( tcx, did) . generics . types . clone ( )
3203- }
3204- typeck:: MethodStaticUnboxedClosure ( _) => {
3205- match tcx. lang_items . require ( FnMutTraitLangItem ) {
3206- Ok ( def_id) => {
3207- lookup_trait_def ( tcx, def_id) . generics . types . clone ( )
3208- }
3209- Err ( s) => tcx. sess . fatal ( s. as_slice ( ) ) ,
3210- }
3223+ ty:: lookup_item_type ( typer. tcx ( ) , did) . generics . types . clone ( )
3224+ }
3225+ typeck:: MethodStaticUnboxedClosure ( did) => {
3226+ let def_id = typer. unboxed_closures ( )
3227+ . borrow ( )
3228+ . find ( & did)
3229+ . expect ( "method_call_type_param_defs: didn't \
3230+ find unboxed closure")
3231+ . kind
3232+ . trait_did ( typer. tcx ( ) ) ;
3233+ lookup_trait_def ( typer. tcx ( ) , def_id) . generics . types . clone ( )
32113234 }
32123235 typeck:: MethodParam ( typeck:: MethodParam {
32133236 trait_id : trt_id,
@@ -3219,7 +3242,7 @@ pub fn method_call_type_param_defs(tcx: &ctxt, origin: typeck::MethodOrigin)
32193242 method_num : n_mth,
32203243 ..
32213244 } ) => {
3222- match ty:: trait_item ( tcx, trt_id, n_mth) {
3245+ match ty:: trait_item ( typer . tcx ( ) , trt_id, n_mth) {
32233246 ty:: MethodTraitItem ( method) => method. generics . types . clone ( ) ,
32243247 }
32253248 }
0 commit comments