@@ -22,11 +22,11 @@ use super::glb::Glb;
22
22
use super :: lub:: Lub ;
23
23
use super :: type_relating:: TypeRelating ;
24
24
use super :: StructurallyRelateAliases ;
25
- use crate :: infer:: { DefineOpaqueTypes , InferCtxt , TypeTrace } ;
25
+ use crate :: infer:: { DefineOpaqueTypes , InferCtxt , InferOk , TypeTrace } ;
26
26
use crate :: traits:: { Obligation , PredicateObligations } ;
27
27
use rustc_middle:: bug;
28
- use rustc_middle:: infer:: canonical:: OriginalQueryValues ;
29
28
use rustc_middle:: infer:: unify_key:: EffectVarValue ;
29
+ use rustc_middle:: traits:: ObligationCause ;
30
30
use rustc_middle:: ty:: error:: { ExpectedFound , TypeError } ;
31
31
use rustc_middle:: ty:: relate:: { RelateResult , TypeRelation } ;
32
32
use rustc_middle:: ty:: { self , InferConst , Ty , TyCtxt , TypeVisitableExt , Upcast } ;
@@ -159,36 +159,11 @@ impl<'tcx> InferCtxt<'tcx> {
159
159
let a = self . shallow_resolve_const ( a) ;
160
160
let b = self . shallow_resolve_const ( b) ;
161
161
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 ;
172
- }
173
-
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) . unwrap_or_else ( |_| {
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
- // We treat these constants as if they were of the same type, so that any
188
- // such constants being used in impls make these impls match barring other mismatches.
189
- // This helps with diagnostics down the road.
190
- } ) ;
191
- } ) ;
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) ;
192
167
193
168
match ( a. kind ( ) , b. kind ( ) ) {
194
169
(
0 commit comments