@@ -250,3 +250,145 @@ impl FlagComputation {
250250 }
251251 }
252252}
253+
254+ pub ( crate ) fn sty_in_local_arena ( st : & ty:: TypeVariants ) -> bool {
255+ match * st {
256+ ty:: TyBool |
257+ ty:: TyChar |
258+ ty:: TyInt ( _) |
259+ ty:: TyFloat ( _) |
260+ ty:: TyUint ( _) |
261+ ty:: TyNever |
262+ ty:: TyStr |
263+ ty:: TyForeign ( ..) |
264+ ty:: TyError |
265+ ty:: TyParam ( ..) => false ,
266+
267+ ty:: TyGenerator ( _, ref substs, ref interior) => {
268+ substs_in_local_arena ( & substs. substs ) ||
269+ ty_in_local_arena ( interior. witness )
270+ }
271+
272+ ty:: TyGeneratorWitness ( ref ts) => {
273+ tys_in_local_arena ( & ts. skip_binder ( ) [ ..] )
274+ }
275+
276+ ty:: TyClosure ( _, ref substs) => {
277+ substs_in_local_arena ( & substs. substs )
278+ }
279+
280+ ty:: TyInfer ( infer) => {
281+ match infer {
282+ ty:: FreshTy ( _) |
283+ ty:: FreshIntTy ( _) |
284+ ty:: FreshFloatTy ( _) |
285+ ty:: CanonicalTy ( _) => false ,
286+ ty:: TyVar ( _) |
287+ ty:: IntVar ( _) |
288+ ty:: FloatVar ( _) => true
289+ }
290+ }
291+
292+ ty:: TyAdt ( _, substs) => {
293+ substs_in_local_arena ( substs)
294+ }
295+
296+ ty:: TyProjection ( ref data) => {
297+ substs_in_local_arena ( data. substs )
298+ }
299+
300+ ty:: TyAnon ( _, substs) => {
301+ substs_in_local_arena ( substs)
302+ }
303+
304+ ty:: TyDynamic ( ref obj, r) => {
305+ for predicate in obj. skip_binder ( ) . iter ( ) {
306+ match * predicate {
307+ ty:: ExistentialPredicate :: Trait ( tr) => {
308+ if substs_in_local_arena ( tr. substs ) {
309+ return true ;
310+ }
311+ }
312+ ty:: ExistentialPredicate :: Projection ( p) => {
313+ if substs_in_local_arena ( p. substs ) || ty_in_local_arena ( p. ty ) {
314+ return true ;
315+ }
316+ }
317+ ty:: ExistentialPredicate :: AutoTrait ( _) => { }
318+ }
319+ }
320+ r. keep_in_local_tcx ( )
321+ }
322+
323+ ty:: TyArray ( tt, len) => {
324+ ty_in_local_arena ( tt) ||
325+ const_in_local_arena ( len)
326+ }
327+
328+ ty:: TySlice ( tt) => {
329+ ty_in_local_arena ( tt)
330+ }
331+
332+ ty:: TyRawPtr ( ref m) => {
333+ ty_in_local_arena ( m. ty )
334+ }
335+
336+ ty:: TyRef ( r, ref m) => {
337+ r. keep_in_local_tcx ( ) ||
338+ ty_in_local_arena ( m. ty )
339+ }
340+
341+ ty:: TyTuple ( ref ts) => {
342+ tys_in_local_arena ( & ts[ ..] )
343+ }
344+
345+ ty:: TyFnDef ( _, substs) => {
346+ substs_in_local_arena ( substs)
347+ }
348+
349+ ty:: TyFnPtr ( f) => {
350+ tys_in_local_arena ( f. skip_binder ( ) . inputs ( ) ) ||
351+ ty_in_local_arena ( f. skip_binder ( ) . output ( ) )
352+ }
353+ }
354+ }
355+
356+ #[ inline( always) ]
357+ fn ty_in_local_arena ( ty : Ty ) -> bool {
358+ ty. flags . intersects ( ty:: TypeFlags :: KEEP_IN_LOCAL_TCX )
359+ }
360+
361+ fn tys_in_local_arena ( tys : & [ Ty ] ) -> bool {
362+ for & ty in tys {
363+ if ty_in_local_arena ( ty) {
364+ return true ;
365+ }
366+ }
367+ false
368+ }
369+
370+ #[ inline( always) ]
371+ fn const_in_local_arena ( constant : & ty:: Const ) -> bool {
372+ if ty_in_local_arena ( constant. ty ) {
373+ return true ;
374+ }
375+ match constant. val {
376+ ConstVal :: Value ( _) => false ,
377+ ConstVal :: Unevaluated ( _, substs) => substs_in_local_arena ( substs) ,
378+ }
379+ }
380+
381+ fn substs_in_local_arena ( substs : & Substs ) -> bool {
382+ for ty in substs. types ( ) {
383+ if ty_in_local_arena ( ty) {
384+ return true ;
385+ }
386+ }
387+
388+ for r in substs. regions ( ) {
389+ if r. keep_in_local_tcx ( ) {
390+ return true ;
391+ }
392+ }
393+ false
394+ }
0 commit comments