@@ -30,6 +30,7 @@ use rustc_span::edit_distance::{
3030use rustc_span:: { DUMMY_SP , Ident , Span , Symbol , sym} ;
3131use rustc_trait_selection:: error_reporting:: infer:: need_type_info:: TypeAnnotationNeeded ;
3232use rustc_trait_selection:: infer:: InferCtxtExt as _;
33+ use rustc_trait_selection:: solve:: Goal ;
3334use rustc_trait_selection:: traits:: query:: CanonicalMethodAutoderefStepsGoal ;
3435use rustc_trait_selection:: traits:: query:: evaluate_obligation:: InferCtxtExt ;
3536use rustc_trait_selection:: traits:: query:: method_autoderef:: {
@@ -1872,7 +1873,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
18721873 }
18731874 }
18741875
1875- #[ instrument( level = "trace " , skip( self , possibly_unsatisfied_predicates) , ret) ]
1876+ #[ instrument( level = "debug " , skip( self , possibly_unsatisfied_predicates) , ret) ]
18761877 fn consider_probe (
18771878 & self ,
18781879 self_ty : Ty < ' tcx > ,
@@ -1884,15 +1885,17 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
18841885 Option < ObligationCause < ' tcx > > ,
18851886 ) > ,
18861887 ) -> ProbeResult {
1887- debug ! ( "consider_probe: self_ty={:?} probe={:?}" , self_ty, probe) ;
1888-
18891888 self . probe ( |snapshot| {
18901889 let outer_universe = self . universe ( ) ;
18911890
18921891 let mut result = ProbeResult :: Match ;
18931892 let cause = & self . misc ( self . span ) ;
18941893 let ocx = ObligationCtxt :: new_with_diagnostics ( self ) ;
18951894 ocx. register_obligations ( instantiate_self_ty_obligations. iter ( ) . cloned ( ) ) ;
1895+ let errors = ocx. select_where_possible ( ) ;
1896+ if !errors. is_empty ( ) {
1897+ unreachable ! ( "unexpected autoderef error {errors:?}" ) ;
1898+ }
18961899
18971900 let mut trait_predicate = None ;
18981901 let ( mut xform_self_ty, mut xform_ret_ty) ;
@@ -2104,6 +2107,16 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
21042107 }
21052108 }
21062109
2110+ if let Some ( predicate) = trait_predicate
2111+ && self . infcx . next_trait_solver ( )
2112+ {
2113+ let goal = Goal { param_env : self . param_env , predicate } ;
2114+
2115+ if !self . infcx . goal_may_hold_opaque_types_jank ( goal) {
2116+ result = ProbeResult :: NoMatch ;
2117+ }
2118+ }
2119+
21072120 if let ProbeResult :: Match = result
21082121 && let Some ( return_ty) = self . return_type
21092122 && let Some ( mut xform_ret_ty) = xform_ret_ty
@@ -2150,13 +2163,15 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
21502163 } ;
21512164 let ocx = ObligationCtxt :: new ( self ) ;
21522165 let self_ty = ocx. register_infer_ok_obligations ( ok) ;
2153- if !ocx. select_all_or_error ( ) . is_empty ( ) {
2154- return false ;
2166+ if ocx. select_all_or_error ( ) . is_empty ( ) {
2167+ !self . resolve_vars_if_possible ( self_ty) . is_ty_var ( )
2168+ } else {
2169+ true
21552170 }
2156-
2157- !self . resolve_vars_if_possible ( self_ty) . is_ty_var ( )
21582171 } ) {
2172+ debug ! ( "candidate constrains opaque --> reject" ) ;
21592173 result = ProbeResult :: NoMatch ;
2174+ break ;
21602175 }
21612176 }
21622177 }
0 commit comments