@@ -14,7 +14,6 @@ use rustc_middle::ty::{
1414} ;
1515use rustc_span:: sym;
1616use rustc_trait_selection:: error_reporting:: InferCtxtErrorExt as _;
17- use rustc_trait_selection:: solve:: InferCtxtSelectExt as _;
1817use rustc_trait_selection:: traits:: { self , ObligationCtxt } ;
1918use tracing:: debug;
2019use traits:: translate_args;
@@ -119,81 +118,23 @@ fn resolve_associated_item<'tcx>(
119118 let trait_ref = ty:: TraitRef :: from_assoc ( tcx, trait_id, rcvr_args) ;
120119
121120 let input = typing_env. as_query_input ( trait_ref) ;
122- let vtbl = if constness == Constness :: Const && tcx. next_trait_solver_globally ( ) {
123- let ( infcx, param_env) =
124- tcx. infer_ctxt ( ) . ignoring_regions ( ) . build_with_typing_env ( typing_env) ;
125-
126- let obligation_cause = ObligationCause :: dummy ( ) ;
127- let host_predicate =
128- ty:: HostEffectPredicate { trait_ref, constness : ty:: BoundConstness :: Const } ;
129- let obligation = Obligation :: new ( tcx, obligation_cause, param_env, host_predicate) ;
130-
131- let selection = match infcx. select_host_effect_predicate_in_new_trait_solver ( & obligation) {
132- Ok ( Some ( selection) ) => selection,
133- Ok ( None ) => return Ok ( None ) ,
134- Err ( SelectionError :: Unimplemented ) => return Ok ( None ) ,
135- Err ( e) => {
136- bug ! ( "Encountered error `{:?}` selecting `{:?}` during codegen" , e, host_predicate)
137- }
138- } ;
139-
140- debug ! ( ?selection) ;
141-
142- // Currently, we use a fulfillment context to completely resolve
143- // all nested obligations. This is because they can inform the
144- // inference of the impl's type parameters.
145- let ocx = ObligationCtxt :: new ( & infcx) ;
146- let impl_source = selection. map ( |obligation| {
147- ocx. register_obligation ( obligation) ;
148- } ) ;
121+ let candidate = if constness == Constness :: Const && tcx. next_trait_solver_globally ( ) {
122+ tcx. codegen_select_candidate_for_ctfe ( input)
123+ } else {
124+ tcx. codegen_select_candidate ( input)
125+ } ;
149126
150- // In principle, we only need to do this so long as `impl_source`
151- // contains unbound type parameters. It could be a slight
152- // optimization to stop iterating early.
153- let errors = ocx. evaluate_obligations_error_on_ambiguity ( ) ;
154- if !errors. is_empty ( ) {
155- // `rustc_monomorphize::collector` assumes there are no type errors.
156- // Cycle errors are the only post-monomorphization errors possible; emit them now so
157- // `rustc_ty_utils::resolve_associated_item` doesn't return `None` post-monomorphization.
158- for err in errors {
159- if let ScrubbedTraitError :: Cycle ( cycle) = err {
160- infcx. err_ctxt ( ) . report_overflow_obligation_cycle ( & cycle) ;
161- }
162- }
127+ let impl_src = match candidate {
128+ Ok ( impl_src) => impl_src,
129+ Err ( CodegenObligationError :: Ambiguity | CodegenObligationError :: Unimplemented ) => {
163130 return Ok ( None ) ;
164131 }
165-
166- let impl_source = infcx. resolve_vars_if_possible ( impl_source) ;
167- let impl_source = tcx. erase_and_anonymize_regions ( impl_source) ;
168- if impl_source. has_non_region_infer ( ) {
169- // Unused generic types or consts on an impl get replaced with inference vars,
170- // but never resolved, causing the return value of a query to contain inference
171- // vars. We do not have a concept for this and will in fact ICE in stable hashing
172- // of the return value. So bail out instead.
173- let guar = match impl_source {
174- ImplSource :: UserDefined ( impl_) => tcx. dcx ( ) . span_delayed_bug (
175- tcx. def_span ( impl_. impl_def_id ) ,
176- "this impl has unconstrained generic parameters" ,
177- ) ,
178- _ => unreachable ! ( ) ,
179- } ;
180- return Err ( guar) ;
181- }
182-
183- & * tcx. arena . alloc ( impl_source)
184- } else {
185- match tcx. codegen_select_candidate ( input) {
186- Ok ( vtbl) => vtbl,
187- Err ( CodegenObligationError :: Ambiguity | CodegenObligationError :: Unimplemented ) => {
188- return Ok ( None ) ;
189- }
190- Err ( CodegenObligationError :: UnconstrainedParam ( guar) ) => return Err ( guar) ,
191- }
132+ Err ( CodegenObligationError :: UnconstrainedParam ( guar) ) => return Err ( guar) ,
192133 } ;
193134
194135 // Now that we know which impl is being used, we can dispatch to
195136 // the actual function:
196- Ok ( match vtbl {
137+ Ok ( match impl_src {
197138 traits:: ImplSource :: UserDefined ( impl_data) => {
198139 debug ! (
199140 "resolving ImplSource::UserDefined: {:?}, {:?}, {:?}, {:?}" ,
0 commit comments