@@ -70,25 +70,14 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
70
70
// into itself infinitely and any partial substitutions in the query
71
71
// response are probably not useful anyways, so just return an empty
72
72
// query response.
73
- Response {
74
- var_values : CanonicalVarValues {
75
- var_values : self . tcx ( ) . mk_substs_from_iter (
76
- self . var_values . var_values . iter ( ) . map ( |arg| -> ty:: GenericArg < ' tcx > {
77
- match arg. unpack ( ) {
78
- GenericArgKind :: Lifetime ( _) => self . next_region_infer ( ) . into ( ) ,
79
- GenericArgKind :: Type ( _) => self . next_ty_infer ( ) . into ( ) ,
80
- GenericArgKind :: Const ( ct) => {
81
- self . next_const_infer ( ct. ty ( ) ) . into ( )
82
- }
83
- }
84
- } ) ,
85
- ) ,
86
- } ,
87
- external_constraints : self
88
- . tcx ( )
89
- . mk_external_constraints ( ExternalConstraintsData :: default ( ) ) ,
90
- certainty,
91
- }
73
+ //
74
+ // This may prevent us from potentially useful inference, e.g.
75
+ // 2 candidates, one ambiguous and one overflow, which both
76
+ // have the same inference constraints.
77
+ //
78
+ // Changing this to retain some constraints in the future
79
+ // won't be a breaking change, so this is good enough for now.
80
+ return Ok ( self . make_ambiguous_response_no_constraints ( MaybeCause :: Overflow ) ) ;
92
81
}
93
82
} ;
94
83
@@ -101,6 +90,40 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
101
90
Ok ( canonical)
102
91
}
103
92
93
+ /// Constructs a totally unconstrained, ambiguous response to a goal.
94
+ ///
95
+ /// Take care when using this, since often it's useful to respond with
96
+ /// ambiguity but return constrained variables to guide inference.
97
+ pub ( in crate :: solve) fn make_ambiguous_response_no_constraints (
98
+ & self ,
99
+ maybe_cause : MaybeCause ,
100
+ ) -> CanonicalResponse < ' tcx > {
101
+ let unconstrained_response = Response {
102
+ var_values : CanonicalVarValues {
103
+ var_values : self . tcx ( ) . mk_substs_from_iter ( self . var_values . var_values . iter ( ) . map (
104
+ |arg| -> ty:: GenericArg < ' tcx > {
105
+ match arg. unpack ( ) {
106
+ GenericArgKind :: Lifetime ( _) => self . next_region_infer ( ) . into ( ) ,
107
+ GenericArgKind :: Type ( _) => self . next_ty_infer ( ) . into ( ) ,
108
+ GenericArgKind :: Const ( ct) => self . next_const_infer ( ct. ty ( ) ) . into ( ) ,
109
+ }
110
+ } ,
111
+ ) ) ,
112
+ } ,
113
+ external_constraints : self
114
+ . tcx ( )
115
+ . mk_external_constraints ( ExternalConstraintsData :: default ( ) ) ,
116
+ certainty : Certainty :: Maybe ( maybe_cause) ,
117
+ } ;
118
+
119
+ Canonicalizer :: canonicalize (
120
+ self . infcx ,
121
+ CanonicalizeMode :: Response { max_input_universe : self . max_input_universe } ,
122
+ & mut Default :: default ( ) ,
123
+ unconstrained_response,
124
+ )
125
+ }
126
+
104
127
#[ instrument( level = "debug" , skip( self ) , ret) ]
105
128
fn compute_external_query_constraints ( & self ) -> Result < ExternalConstraints < ' tcx > , NoSolution > {
106
129
// Cannot use `take_registered_region_obligations` as we may compute the response
0 commit comments