@@ -13,7 +13,7 @@ use rustc_span::sym;
1313use rustc_trait_selection:: traits;
1414use rustc_type_ir:: ClosureKind ;
1515use tracing:: debug;
16- use traits:: { Reveal , translate_args} ;
16+ use traits:: translate_args;
1717
1818use crate :: errors:: UnexpectedFnPtrAssociatedItem ;
1919
@@ -133,18 +133,6 @@ fn resolve_associated_item<'tcx>(
133133 bug ! ( "{:?} not found in {:?}" , trait_item_id, impl_data. impl_def_id) ;
134134 } ) ;
135135
136- let typing_env = typing_env. with_reveal_all_normalized ( tcx) ;
137- let ( infcx, param_env) = tcx. infer_ctxt ( ) . build_with_typing_env ( typing_env) ;
138- let args = rcvr_args. rebase_onto ( tcx, trait_def_id, impl_data. args ) ;
139- let args = translate_args (
140- & infcx,
141- param_env,
142- impl_data. impl_def_id ,
143- args,
144- leaf_def. defining_node ,
145- ) ;
146- let args = infcx. tcx . erase_regions ( args) ;
147-
148136 // Since this is a trait item, we need to see if the item is either a trait default item
149137 // or a specialization because we can't resolve those unless we can `Reveal::All`.
150138 // NOTE: This should be kept in sync with the similar code in
@@ -157,16 +145,28 @@ fn resolve_associated_item<'tcx>(
157145 // and the obligation is monomorphic, otherwise passes such as
158146 // transmute checking and polymorphic MIR optimizations could
159147 // get a result which isn't correct for all monomorphizations.
160- if param_env . reveal ( ) == Reveal :: All {
161- !trait_ref . still_further_specializable ( )
162- } else {
163- false
148+ match typing_env . typing_mode {
149+ ty :: TypingMode :: Coherence
150+ | ty :: TypingMode :: Analysis { defining_opaque_types : _ } => false ,
151+ ty :: TypingMode :: PostAnalysis => !trait_ref . still_further_specializable ( ) ,
164152 }
165153 } ;
166154 if !eligible {
167155 return Ok ( None ) ;
168156 }
169157
158+ let typing_env = typing_env. with_reveal_all_normalized ( tcx) ;
159+ let ( infcx, param_env) = tcx. infer_ctxt ( ) . build_with_typing_env ( typing_env) ;
160+ let args = rcvr_args. rebase_onto ( tcx, trait_def_id, impl_data. args ) ;
161+ let args = translate_args (
162+ & infcx,
163+ param_env,
164+ impl_data. impl_def_id ,
165+ args,
166+ leaf_def. defining_node ,
167+ ) ;
168+ let args = infcx. tcx . erase_regions ( args) ;
169+
170170 // HACK: We may have overlapping `dyn Trait` built-in impls and
171171 // user-provided blanket impls. Detect that case here, and return
172172 // ambiguity.
0 commit comments