@@ -29,7 +29,7 @@ pub enum InstanceDef<'tcx> {
2929 /// - `fn` items
3030 /// - closures
3131 /// - generators
32- Item ( DefId ) ,
32+ Item ( ty :: WithOptParam < DefId > ) ,
3333
3434 /// An intrinsic `fn` item (with `"rust-intrinsic"` or `"platform-intrinsic"` ABI).
3535 ///
@@ -160,8 +160,8 @@ impl<'tcx> Instance<'tcx> {
160160 self . substs . non_erasable_generics ( ) . next ( ) ?;
161161
162162 match self . def {
163- InstanceDef :: Item ( def_id ) => tcx
164- . upstream_monomorphizations_for ( def_id )
163+ InstanceDef :: Item ( def ) => tcx
164+ . upstream_monomorphizations_for ( def . did )
165165 . and_then ( |monos| monos. get ( & self . substs ) . cloned ( ) ) ,
166166 InstanceDef :: DropGlue ( _, Some ( _) ) => tcx. upstream_drop_glue_for ( self . substs ) ,
167167 _ => None ,
@@ -171,10 +171,10 @@ impl<'tcx> Instance<'tcx> {
171171
172172impl < ' tcx > InstanceDef < ' tcx > {
173173 #[ inline]
174- pub fn def_id ( & self ) -> DefId {
175- match * self {
176- InstanceDef :: Item ( def_id )
177- | InstanceDef :: VtableShim ( def_id)
174+ pub fn def_id ( self ) -> DefId {
175+ match self {
176+ InstanceDef :: Item ( def ) => def . did ,
177+ InstanceDef :: VtableShim ( def_id)
178178 | InstanceDef :: ReifyShim ( def_id)
179179 | InstanceDef :: FnPtrShim ( def_id, _)
180180 | InstanceDef :: Virtual ( def_id, _)
@@ -185,6 +185,21 @@ impl<'tcx> InstanceDef<'tcx> {
185185 }
186186 }
187187
188+ #[ inline]
189+ pub fn with_opt_param ( self ) -> ty:: WithOptParam < DefId > {
190+ match self {
191+ InstanceDef :: Item ( def) => def,
192+ InstanceDef :: VtableShim ( def_id)
193+ | InstanceDef :: ReifyShim ( def_id)
194+ | InstanceDef :: FnPtrShim ( def_id, _)
195+ | InstanceDef :: Virtual ( def_id, _)
196+ | InstanceDef :: Intrinsic ( def_id)
197+ | InstanceDef :: ClosureOnceShim { call_once : def_id }
198+ | InstanceDef :: DropGlue ( def_id, _)
199+ | InstanceDef :: CloneShim ( def_id, _) => ty:: WithOptParam :: dummy ( def_id) ,
200+ }
201+ }
202+
188203 #[ inline]
189204 pub fn attrs ( & self , tcx : TyCtxt < ' tcx > ) -> ty:: Attributes < ' tcx > {
190205 tcx. get_attrs ( self . def_id ( ) )
@@ -198,7 +213,7 @@ impl<'tcx> InstanceDef<'tcx> {
198213 pub fn requires_inline ( & self , tcx : TyCtxt < ' tcx > ) -> bool {
199214 use rustc_hir:: definitions:: DefPathData ;
200215 let def_id = match * self {
201- ty:: InstanceDef :: Item ( def_id ) => def_id ,
216+ ty:: InstanceDef :: Item ( def ) => def . did ,
202217 ty:: InstanceDef :: DropGlue ( _, Some ( _) ) => return false ,
203218 _ => return true ,
204219 } ;
@@ -244,8 +259,8 @@ impl<'tcx> InstanceDef<'tcx> {
244259
245260 pub fn requires_caller_location ( & self , tcx : TyCtxt < ' _ > ) -> bool {
246261 match * self {
247- InstanceDef :: Item ( def_id ) => {
248- tcx. codegen_fn_attrs ( def_id ) . flags . contains ( CodegenFnAttrFlags :: TRACK_CALLER )
262+ InstanceDef :: Item ( def ) => {
263+ tcx. codegen_fn_attrs ( def . did ) . flags . contains ( CodegenFnAttrFlags :: TRACK_CALLER )
249264 }
250265 _ => false ,
251266 }
@@ -283,7 +298,7 @@ impl<'tcx> Instance<'tcx> {
283298 def_id,
284299 substs
285300 ) ;
286- Instance { def : InstanceDef :: Item ( def_id) , substs }
301+ Instance { def : InstanceDef :: Item ( ty :: WithOptParam :: dummy ( def_id) ) , substs }
287302 }
288303
289304 pub fn mono ( tcx : TyCtxt < ' tcx > , def_id : DefId ) -> Instance < ' tcx > {
@@ -356,9 +371,9 @@ impl<'tcx> Instance<'tcx> {
356371 debug ! ( "resolve(def_id={:?}, substs={:?})" , def_id, substs) ;
357372 Instance :: resolve ( tcx, param_env, def_id, substs) . ok ( ) . flatten ( ) . map ( |mut resolved| {
358373 match resolved. def {
359- InstanceDef :: Item ( def_id ) if resolved. def . requires_caller_location ( tcx) => {
374+ InstanceDef :: Item ( def ) if resolved. def . requires_caller_location ( tcx) => {
360375 debug ! ( " => fn pointer created for function with #[track_caller]" ) ;
361- resolved. def = InstanceDef :: ReifyShim ( def_id ) ;
376+ resolved. def = InstanceDef :: ReifyShim ( def . did ) ;
362377 }
363378 InstanceDef :: Virtual ( def_id, _) => {
364379 debug ! ( " => fn pointer created for virtual call" ) ;
0 commit comments