6
6
use rustc_infer:: infer:: TyCtxtInferExt ;
7
7
use rustc_middle:: bug;
8
8
use rustc_middle:: traits:: CodegenObligationError ;
9
- use rustc_middle:: ty:: { self , PseudoCanonicalInput , TyCtxt , TypeVisitableExt , Upcast } ;
9
+ use rustc_middle:: ty:: { self , PseudoCanonicalInput , TyCtxt , TypeVisitableExt } ;
10
10
use rustc_trait_selection:: error_reporting:: InferCtxtErrorExt ;
11
11
use rustc_trait_selection:: traits:: {
12
12
ImplSource , Obligation , ObligationCause , ObligationCtxt , ScrubbedTraitError , SelectionContext ,
13
- Unimplemented , sizedness_fast_path ,
13
+ Unimplemented , extended_sizedness_fast_path ,
14
14
} ;
15
15
use tracing:: debug;
16
16
@@ -34,15 +34,22 @@ pub(crate) fn codegen_select_candidate<'tcx>(
34
34
let ( infcx, param_env) = tcx. infer_ctxt ( ) . ignoring_regions ( ) . build_with_typing_env ( typing_env) ;
35
35
let mut selcx = SelectionContext :: new ( & infcx) ;
36
36
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) {
38
41
return Ok ( & * tcx. arena . alloc ( ImplSource :: Builtin (
39
42
ty:: solve:: BuiltinImplSource :: Trivial ,
40
43
Default :: default ( ) ,
41
44
) ) ) ;
42
45
}
43
46
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
+ } ;
46
53
47
54
let selection = match selcx. select ( & obligation) {
48
55
Ok ( Some ( selection) ) => selection,
0 commit comments