@@ -7,6 +7,7 @@ use crate::errors::UnableToConstructConstantValue;
7
7
use crate :: infer:: region_constraints:: { Constraint , RegionConstraintData } ;
8
8
use crate :: infer:: InferCtxt ;
9
9
use crate :: traits:: project:: ProjectAndUnifyResult ;
10
+ use rustc_infer:: traits:: util:: PredicateSet ;
10
11
use rustc_middle:: mir:: interpret:: ErrorHandled ;
11
12
use rustc_middle:: ty:: fold:: { TypeFolder , TypeSuperFoldable } ;
12
13
use rustc_middle:: ty:: visit:: TypeVisitableExt ;
@@ -344,13 +345,24 @@ impl<'tcx> AutoTraitFinder<'tcx> {
344
345
_ => panic ! ( "Unexpected error for '{:?}': {:?}" , ty, result) ,
345
346
} ;
346
347
347
- let normalized_preds = elaborate_predicates (
348
+ let elaborated_preds = elaborate_predicates (
348
349
tcx,
349
350
computed_preds. clone ( ) . chain ( user_computed_preds. iter ( ) . cloned ( ) ) ,
350
351
)
351
- . map ( |o| o. predicate ) ;
352
+ . map ( |obligation| obligation. predicate ) ;
353
+
354
+ // FIXME(generic_const_exprs):
355
+ // This deduplication is required only when generic_const_exprs is not active
356
+ // see #108397 for more information.
357
+ let mut seen_preds = PredicateSet :: new ( tcx) ;
358
+ let obctx = ObligationCtxt :: new ( infcx) ;
359
+ let deduped_preds = elaborated_preds
360
+ . into_iter ( )
361
+ . map ( |pred| obctx. normalize ( & dummy_cause, param_env, pred) )
362
+ . filter ( |normalized_pred| seen_preds. insert ( * normalized_pred) ) ;
363
+
352
364
new_env = ty:: ParamEnv :: new (
353
- tcx. mk_predicates_from_iter ( normalized_preds ) ,
365
+ tcx. mk_predicates_from_iter ( deduped_preds ) ,
354
366
param_env. reveal ( ) ,
355
367
param_env. constness ( ) ,
356
368
) ;
0 commit comments