@@ -413,13 +413,36 @@ impl<'tcx> Body<'tcx> {
413413 }
414414
415415 pub fn typing_env ( & self , tcx : TyCtxt < ' tcx > ) -> TypingEnv < ' tcx > {
416- match self . phase {
417- // FIXME(#132279): we should reveal the opaques defined in the body during analysis.
418- MirPhase :: Built | MirPhase :: Analysis ( _) => TypingEnv :: new (
419- tcx. param_env ( self . source . def_id ( ) ) ,
420- ty:: TypingMode :: non_body_analysis ( ) ,
421- ) ,
422- MirPhase :: Runtime ( _) => TypingEnv :: post_analysis ( tcx, self . source . def_id ( ) ) ,
416+ if tcx. use_typing_mode_borrowck ( ) {
417+ match self . phase {
418+ MirPhase :: Built if let Some ( def_id) = self . source . def_id ( ) . as_local ( ) => {
419+ TypingEnv :: new (
420+ tcx. param_env ( self . source . def_id ( ) ) ,
421+ ty:: TypingMode :: borrowck ( tcx, def_id) ,
422+ )
423+ }
424+ MirPhase :: Analysis ( _) if let Some ( def_id) = self . source . def_id ( ) . as_local ( ) => {
425+ TypingEnv :: new (
426+ tcx. param_env ( self . source . def_id ( ) ) ,
427+ ty:: TypingMode :: post_borrowck_analysis ( tcx, def_id) ,
428+ )
429+ }
430+ MirPhase :: Built | MirPhase :: Analysis ( _) => {
431+ // This branch happens for drop glue and fn ptr shims.
432+ // FIXME: why do we do any of this analysis on drop glue etc?
433+ // This should ideally all be skipped.
434+ TypingEnv :: post_analysis ( tcx, self . source . def_id ( ) )
435+ }
436+ MirPhase :: Runtime ( _) => TypingEnv :: post_analysis ( tcx, self . source . def_id ( ) ) ,
437+ }
438+ } else {
439+ match self . phase {
440+ MirPhase :: Built | MirPhase :: Analysis ( _) => TypingEnv :: new (
441+ tcx. param_env ( self . source . def_id ( ) ) ,
442+ ty:: TypingMode :: non_body_analysis ( ) ,
443+ ) ,
444+ MirPhase :: Runtime ( _) => TypingEnv :: post_analysis ( tcx, self . source . def_id ( ) ) ,
445+ }
423446 }
424447 }
425448
0 commit comments