Skip to content

Commit c502f84

Browse files
committed
Auto merge of #118735 - lcnr:predicate-split, r=<try>
perf: experiment with only non-functional changes from #118725 cc #118735 r? `@ghost`
2 parents 21982a4 + 1eab6aa commit c502f84

File tree

3 files changed

+50
-41
lines changed

3 files changed

+50
-41
lines changed

compiler/rustc_infer/src/traits/util.rs

+44-26
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,9 @@ impl<'tcx, O: Elaboratable<'tcx>> Elaborator<'tcx, O> {
261261
fn elaborate(&mut self, elaboratable: &O) {
262262
let tcx = self.visited.tcx;
263263

264-
// We only elaborate clauses.
265-
let Some(clause) = elaboratable.predicate().as_clause() else {
266-
return;
267-
};
268-
269-
let bound_clause = clause.kind();
270-
match bound_clause.skip_binder() {
271-
ty::ClauseKind::Trait(data) => {
264+
let bound_predicate = elaboratable.predicate().kind();
265+
match bound_predicate.skip_binder() {
266+
ty::PredicateKind::Clause(ty::ClauseKind::Trait(data)) => {
272267
// Negative trait bounds do not imply any supertrait bounds
273268
if data.polarity == ty::ImplPolarity::Negative {
274269
return;
@@ -285,16 +280,49 @@ impl<'tcx, O: Elaboratable<'tcx>> Elaborator<'tcx, O> {
285280
let obligations =
286281
predicates.predicates.iter().enumerate().map(|(index, &(clause, span))| {
287282
elaboratable.child_with_derived_cause(
288-
clause.subst_supertrait(tcx, &bound_clause.rebind(data.trait_ref)),
283+
clause.subst_supertrait(tcx, &bound_predicate.rebind(data.trait_ref)),
289284
span,
290-
bound_clause.rebind(data),
285+
bound_predicate.rebind(data),
291286
index,
292287
)
293288
});
294289
debug!(?data, ?obligations, "super_predicates");
295290
self.extend_deduped(obligations);
296291
}
297-
ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(ty_max, r_min)) => {
292+
ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(..)) => {
293+
// Currently, we do not elaborate WF predicates,
294+
// although we easily could.
295+
}
296+
ty::PredicateKind::ObjectSafe(..) => {
297+
// Currently, we do not elaborate object-safe
298+
// predicates.
299+
}
300+
ty::PredicateKind::Subtype(..) => {
301+
// Currently, we do not "elaborate" predicates like `X <: Y`,
302+
// though conceivably we might.
303+
}
304+
ty::PredicateKind::Coerce(..) => {
305+
// Currently, we do not "elaborate" predicates like `X -> Y`,
306+
// though conceivably we might.
307+
}
308+
ty::PredicateKind::Clause(ty::ClauseKind::Projection(..)) => {
309+
// Nothing to elaborate in a projection predicate.
310+
}
311+
ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(..)) => {
312+
// Currently, we do not elaborate const-evaluatable
313+
// predicates.
314+
}
315+
ty::PredicateKind::ConstEquate(..) => {
316+
// Currently, we do not elaborate const-equate
317+
// predicates.
318+
}
319+
ty::PredicateKind::Clause(ty::ClauseKind::RegionOutlives(..)) => {
320+
// Nothing to elaborate from `'a: 'b`.
321+
}
322+
ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(
323+
ty_max,
324+
r_min,
325+
))) => {
298326
// We know that `T: 'a` for some type `T`. We can
299327
// often elaborate this. For example, if we know that
300328
// `[U]: 'a`, that implies that `U: 'a`. Similarly, if
@@ -357,25 +385,15 @@ impl<'tcx, O: Elaboratable<'tcx>> Elaborator<'tcx, O> {
357385
}
358386
})
359387
.map(|clause| {
360-
elaboratable.child(bound_clause.rebind(clause).to_predicate(tcx))
388+
elaboratable.child(bound_predicate.rebind(clause).to_predicate(tcx))
361389
}),
362390
);
363391
}
364-
ty::ClauseKind::RegionOutlives(..) => {
365-
// Nothing to elaborate from `'a: 'b`.
366-
}
367-
ty::ClauseKind::WellFormed(..) => {
368-
// Currently, we do not elaborate WF predicates,
369-
// although we easily could.
370-
}
371-
ty::ClauseKind::Projection(..) => {
372-
// Nothing to elaborate in a projection predicate.
373-
}
374-
ty::ClauseKind::ConstEvaluatable(..) => {
375-
// Currently, we do not elaborate const-evaluatable
376-
// predicates.
392+
ty::PredicateKind::Ambiguous => {}
393+
ty::PredicateKind::NormalizesTo(..) | ty::PredicateKind::AliasRelate(..) => {
394+
// No
377395
}
378-
ty::ClauseKind::ConstArgHasType(..) => {
396+
ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(..)) => {
379397
// Nothing to elaborate
380398
}
381399
}

compiler/rustc_trait_selection/src/traits/fulfill.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,8 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
360360
ProcessResult::Changed(mk_pending(vec![obligation.with(infcx.tcx, pred)]))
361361
}
362362
ty::PredicateKind::Ambiguous => ProcessResult::Unchanged,
363-
ty::PredicateKind::NormalizesTo(..) => {
364-
bug!("NormalizesTo is only used by the new solver")
365-
}
366-
ty::PredicateKind::AliasRelate(..) => {
367-
bug!("AliasRelate is only used by the new solver")
363+
ty::PredicateKind::NormalizesTo(..) | ty::PredicateKind::AliasRelate(..) => {
364+
bug!("only used by the new solver")
368365
}
369366
},
370367
Some(pred) => match pred {
@@ -415,11 +412,8 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
415412
}
416413

417414
ty::PredicateKind::Ambiguous => ProcessResult::Unchanged,
418-
ty::PredicateKind::NormalizesTo(..) => {
419-
bug!("NormalizesTo is only used by the new solver")
420-
}
421-
ty::PredicateKind::AliasRelate(..) => {
422-
bug!("AliasRelate is only used by the new solver")
415+
ty::PredicateKind::NormalizesTo(..) | ty::PredicateKind::AliasRelate(..) => {
416+
bug!("only used by the new solver")
423417
}
424418

425419
// General case overflow check. Allow `process_trait_obligation`

compiler/rustc_trait_selection/src/traits/select/mod.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -990,11 +990,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
990990
}
991991
}
992992
}
993-
ty::PredicateKind::NormalizesTo(..) => {
994-
bug!("NormalizesTo is only used by the new solver")
995-
}
996-
ty::PredicateKind::AliasRelate(..) => {
997-
bug!("AliasRelate is only used by the new solver")
993+
ty::PredicateKind::NormalizesTo(..) | ty::PredicateKind::AliasRelate(..) => {
994+
bug!("only used by the new solver")
998995
}
999996
ty::PredicateKind::Ambiguous => Ok(EvaluatedToAmbig),
1000997
ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, ty)) => {

0 commit comments

Comments
 (0)