@@ -22,11 +22,11 @@ use super::glb::Glb;
2222use super :: lub:: Lub ;
2323use super :: type_relating:: TypeRelating ;
2424use super :: StructurallyRelateAliases ;
25- use crate :: infer:: { DefineOpaqueTypes , InferCtxt , TypeTrace } ;
25+ use crate :: infer:: { DefineOpaqueTypes , InferCtxt , InferOk , TypeTrace } ;
2626use crate :: traits:: { Obligation , PredicateObligations } ;
2727use rustc_middle:: bug;
28- use rustc_middle:: infer:: canonical:: OriginalQueryValues ;
2928use rustc_middle:: infer:: unify_key:: EffectVarValue ;
29+ use rustc_middle:: traits:: ObligationCause ;
3030use rustc_middle:: ty:: error:: { ExpectedFound , TypeError } ;
3131use rustc_middle:: ty:: relate:: { RelateResult , TypeRelation } ;
3232use rustc_middle:: ty:: { self , InferConst , Ty , TyCtxt , TypeVisitableExt , Upcast } ;
@@ -159,34 +159,12 @@ impl<'tcx> InferCtxt<'tcx> {
159159 let a = self . shallow_resolve_const ( a) ;
160160 let b = self . shallow_resolve_const ( b) ;
161161
162- // We should never have to relate the `ty` field on `Const` as it is checked elsewhere that consts have the
163- // correct type for the generic param they are an argument for. However there have been a number of cases
164- // historically where asserting that the types are equal has found bugs in the compiler so this is valuable
165- // to check even if it is a bit nasty impl wise :(
166- //
167- // This probe is probably not strictly necessary but it seems better to be safe and not accidentally find
168- // ourselves with a check to find bugs being required for code to compile because it made inference progress.
169- self . probe ( |_| {
170- if a. ty ( ) == b. ty ( ) {
171- return Ok ( ( ) ) ;
172- }
162+ // It is always an error if the types of two constants that are related are not equal.
163+ let InferOk { value : ( ) , obligations } = self
164+ . at ( & ObligationCause :: dummy_with_span ( relation. span ( ) ) , relation. param_env ( ) )
165+ . eq ( DefineOpaqueTypes :: No , a. ty ( ) , b. ty ( ) ) ?;
166+ relation. register_obligations ( obligations) ;
173167
174- // We don't have access to trait solving machinery in `rustc_infer` so the logic for determining if the
175- // two const param's types are able to be equal has to go through a canonical query with the actual logic
176- // in `rustc_trait_selection`.
177- let canonical = self . canonicalize_query (
178- relation. param_env ( ) . and ( ( a. ty ( ) , b. ty ( ) ) ) ,
179- & mut OriginalQueryValues :: default ( ) ,
180- ) ;
181- self . tcx . check_tys_might_be_eq ( canonical) . map_err ( |_| {
182- // The error will only be reported later. If we emit an ErrorGuaranteed
183- // here, then we will never get to the code that actually emits the error.
184- self . tcx . dcx ( ) . delayed_bug ( format ! (
185- "cannot relate consts of different types (a={a:?}, b={b:?})" ,
186- ) ) ;
187- TypeError :: Mismatch
188- } )
189- } ) ?;
190168 match ( a. kind ( ) , b. kind ( ) ) {
191169 (
192170 ty:: ConstKind :: Infer ( InferConst :: Var ( a_vid) ) ,
0 commit comments