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