66use rustc_infer:: infer:: TyCtxtInferExt ;
77use rustc_middle:: bug;
88use rustc_middle:: traits:: CodegenObligationError ;
9- use rustc_middle:: ty:: { self , PseudoCanonicalInput , TyCtxt , TypeVisitableExt , Upcast } ;
9+ use rustc_middle:: ty:: { self , PseudoCanonicalInput , TyCtxt , TypeVisitableExt } ;
1010use rustc_trait_selection:: error_reporting:: InferCtxtErrorExt ;
1111use rustc_trait_selection:: traits:: {
1212 ImplSource , Obligation , ObligationCause , ObligationCtxt , ScrubbedTraitError , SelectionContext ,
13- Unimplemented , sizedness_fast_path ,
13+ Unimplemented , extended_sizedness_fast_path ,
1414} ;
1515use tracing:: debug;
1616
@@ -34,15 +34,22 @@ pub(crate) fn codegen_select_candidate<'tcx>(
3434 let ( infcx, param_env) = tcx. infer_ctxt ( ) . ignoring_regions ( ) . build_with_typing_env ( typing_env) ;
3535 let mut selcx = SelectionContext :: new ( & infcx) ;
3636
37- if sizedness_fast_path ( tcx, trait_ref. upcast ( tcx) ) {
37+ let obligation_cause = ObligationCause :: dummy ( ) ;
38+ let obligation = Obligation :: new ( tcx, obligation_cause, param_env, trait_ref) ;
39+
40+ if extended_sizedness_fast_path ( & infcx, & obligation) {
3841 return Ok ( & * tcx. arena . alloc ( ImplSource :: Builtin (
3942 ty:: solve:: BuiltinImplSource :: Trivial ,
4043 Default :: default ( ) ,
4144 ) ) ) ;
4245 }
4346
44- let obligation_cause = ObligationCause :: dummy ( ) ;
45- let obligation = Obligation :: new ( tcx, obligation_cause, param_env, trait_ref) ;
47+ // Calling `sizedness_fast_path` upcasts to `PolyObligation`, rather than `TraitObligation`
48+ let obligation = if let Some ( clause) = obligation. predicate . as_trait_clause ( ) {
49+ obligation. with ( tcx, clause. skip_binder ( ) )
50+ } else {
51+ bug ! ( "trait ref upcast to non-trait clause" ) ;
52+ } ;
4653
4754 let selection = match selcx. select ( & obligation) {
4855 Ok ( Some ( selection) ) => selection,
0 commit comments