@@ -13,7 +13,7 @@ use rustc_span::sym;
13
13
use rustc_trait_selection:: traits;
14
14
use rustc_type_ir:: ClosureKind ;
15
15
use tracing:: debug;
16
- use traits:: { Reveal , translate_args} ;
16
+ use traits:: translate_args;
17
17
18
18
use crate :: errors:: UnexpectedFnPtrAssociatedItem ;
19
19
@@ -133,18 +133,6 @@ fn resolve_associated_item<'tcx>(
133
133
bug ! ( "{:?} not found in {:?}" , trait_item_id, impl_data. impl_def_id) ;
134
134
} ) ;
135
135
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
-
148
136
// Since this is a trait item, we need to see if the item is either a trait default item
149
137
// or a specialization because we can't resolve those unless we can `Reveal::All`.
150
138
// NOTE: This should be kept in sync with the similar code in
@@ -157,16 +145,28 @@ fn resolve_associated_item<'tcx>(
157
145
// and the obligation is monomorphic, otherwise passes such as
158
146
// transmute checking and polymorphic MIR optimizations could
159
147
// 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 ( ) ,
164
152
}
165
153
} ;
166
154
if !eligible {
167
155
return Ok ( None ) ;
168
156
}
169
157
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
+
170
170
// HACK: We may have overlapping `dyn Trait` built-in impls and
171
171
// user-provided blanket impls. Detect that case here, and return
172
172
// ambiguity.
0 commit comments