Skip to content

Commit 4ad50c5

Browse files
committed
Auto merge of rust-lang#140978 - davidtwco:deep-reject-in-match-norm-trait-ref, r=<try>
trait_sel: deep reject `match_normalize_trait_ref` Spotted during an in-person review of rust-lang#137944 at RustWeek: `match_normalize_trait_ref` could be using `DeepRejectCtxt` to exit early as an optimisation for prejection candidates, like is done in param candidates. r? `@lcnr` cc `@oli-obk`
2 parents 414482f + a5e1dba commit 4ad50c5

File tree

2 files changed

+9
-2
lines changed
  • compiler
    • rustc_middle/src/ty
    • rustc_trait_selection/src/traits/select

2 files changed

+9
-2
lines changed

compiler/rustc_middle/src/ty/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ pub use rustc_session::lint::RegisteredTools;
5252
use rustc_span::hygiene::MacroKind;
5353
use rustc_span::{DUMMY_SP, ExpnId, ExpnKind, Ident, Span, Symbol, kw, sym};
5454
pub use rustc_type_ir::data_structures::{DelayedMap, DelayedSet};
55+
pub use rustc_type_ir::fast_reject::DeepRejectCtxt;
5556
#[allow(
5657
hidden_glob_reexports,
5758
rustc::usage_of_type_ir_inherent,

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ use rustc_middle::ty::abstract_const::NotConstEvaluatable;
2727
use rustc_middle::ty::error::TypeErrorToStringExt;
2828
use rustc_middle::ty::print::{PrintTraitRefExt as _, with_no_trimmed_paths};
2929
use rustc_middle::ty::{
30-
self, GenericArgsRef, PolyProjectionPredicate, Ty, TyCtxt, TypeFoldable, TypeVisitableExt,
31-
TypingMode, Upcast, elaborate,
30+
self, DeepRejectCtxt, GenericArgsRef, PolyProjectionPredicate, Ty, TyCtxt, TypeFoldable,
31+
TypeVisitableExt, TypingMode, Upcast, elaborate,
3232
};
3333
use rustc_span::{Symbol, sym};
3434
use tracing::{debug, instrument, trace};
@@ -1669,6 +1669,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16691669
return Err(());
16701670
}
16711671

1672+
let drcx = DeepRejectCtxt::relate_rigid_rigid(self.infcx.tcx);
1673+
let obligation_args = obligation.predicate.skip_binder().trait_ref.args;
1674+
if !drcx.args_may_unify(obligation_args, trait_bound.skip_binder().args) {
1675+
return Err(());
1676+
}
1677+
16721678
let trait_bound = self.infcx.instantiate_binder_with_fresh_vars(
16731679
obligation.cause.span,
16741680
HigherRankedType,

0 commit comments

Comments
 (0)