@@ -167,9 +167,9 @@ impl<'tcx> InferCtxt<'tcx> {
167
167
//
168
168
// This probe is probably not strictly necessary but it seems better to be safe and not accidentally find
169
169
// ourselves with a check to find bugs being required for code to compile because it made inference progress.
170
- let compatible_types = self . probe ( |_| {
170
+ self . probe ( |_| {
171
171
if a. ty ( ) == b. ty ( ) {
172
- return Ok ( ( ) ) ;
172
+ return ;
173
173
}
174
174
175
175
// We don't have access to trait solving machinery in `rustc_infer` so the logic for determining if the
@@ -179,32 +179,18 @@ impl<'tcx> InferCtxt<'tcx> {
179
179
relation. param_env ( ) . and ( ( a. ty ( ) , b. ty ( ) ) ) ,
180
180
& mut OriginalQueryValues :: default ( ) ,
181
181
) ;
182
- self . tcx . check_tys_might_be_eq ( canonical) . map_err ( |_| {
182
+ self . tcx . check_tys_might_be_eq ( canonical) . unwrap_or_else ( |_| {
183
+ // The error will only be reported later. If we emit an ErrorGuaranteed
184
+ // here, then we will never get to the code that actually emits the error.
183
185
self . tcx . dcx ( ) . delayed_bug ( format ! (
184
186
"cannot relate consts of different types (a={a:?}, b={b:?})" ,
185
- ) )
186
- } )
187
+ ) ) ;
188
+ // We treat these constants as if they were of the same type, so that any
189
+ // such constants being used in impls make these impls match barring other mismatches.
190
+ // This helps with diagnostics down the road.
191
+ } ) ;
187
192
} ) ;
188
193
189
- // If the consts have differing types, just bail with a const error with
190
- // the expected const's type. Specifically, we don't want const infer vars
191
- // to do any type shapeshifting before and after resolution.
192
- if let Err ( guar) = compatible_types {
193
- // HACK: equating both sides with `[const error]` eagerly prevents us
194
- // from leaving unconstrained inference vars during things like impl
195
- // matching in the solver.
196
- let a_error = ty:: Const :: new_error ( self . tcx , guar, a. ty ( ) ) ;
197
- if let ty:: ConstKind :: Infer ( InferConst :: Var ( vid) ) = a. kind ( ) {
198
- return self . unify_const_variable ( vid, a_error, relation. param_env ( ) ) ;
199
- }
200
- let b_error = ty:: Const :: new_error ( self . tcx , guar, b. ty ( ) ) ;
201
- if let ty:: ConstKind :: Infer ( InferConst :: Var ( vid) ) = b. kind ( ) {
202
- return self . unify_const_variable ( vid, b_error, relation. param_env ( ) ) ;
203
- }
204
-
205
- return Ok ( if relation. a_is_expected ( ) { a_error } else { b_error } ) ;
206
- }
207
-
208
194
match ( a. kind ( ) , b. kind ( ) ) {
209
195
(
210
196
ty:: ConstKind :: Infer ( InferConst :: Var ( a_vid) ) ,
0 commit comments