Skip to content

Commit 8d490e3

Browse files
committed
Auto merge of #123471 - compiler-errors:match_projection_projections, r=oli-obk
Check def id before calling `match_projection_projections` When I "inlined" `assemble_candidates_from_predicates` into `for_each_item_bound` in #120584, I forgot to copy over the check that actually made sure the def id of the candidate was equal to the def id of the obligation. This means that we normalize goal a bit too often even if it's not productive to do so. This PR adds that def id check back. Fixes #123448
2 parents 23d47db + 43dae69 commit 8d490e3

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

compiler/rustc_trait_selection/src/traits/project.rs

+3
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,9 @@ fn assemble_candidates_from_trait_def<'cx, 'tcx>(
793793
let Some(clause) = clause.as_projection_clause() else {
794794
return ControlFlow::Continue(());
795795
};
796+
if clause.projection_def_id() != obligation.predicate.def_id {
797+
return ControlFlow::Continue(());
798+
}
796799

797800
let is_match =
798801
selcx.infcx.probe(|_| selcx.match_projection_projections(obligation, clause, true));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//@ check-pass
2+
3+
#![recursion_limit = "1024"]
4+
// Really high recursion limit ^
5+
6+
// Test that ensures we're filtering projections by def id before matching
7+
// them in `match_projection_projections`.
8+
9+
use std::ops::{Add, Sub};
10+
11+
pub trait Scalar {}
12+
13+
pub trait VectorCommon: Sized {
14+
type T: Scalar;
15+
}
16+
17+
pub trait VectorOpsByValue<Rhs = Self, Output = Self>:
18+
VectorCommon + Add<Rhs, Output = Output> + Sub<Rhs, Output = Output>
19+
{
20+
}
21+
22+
pub trait VectorView<'a>:
23+
VectorOpsByValue<Self, Self::Owned> + VectorOpsByValue<Self::Owned, Self::Owned>
24+
{
25+
type Owned;
26+
}
27+
28+
pub trait Vector: VectorOpsByValue<Self> + for<'a> VectorOpsByValue<Self::View<'a>> {
29+
type View<'a>: VectorView<'a, T = Self::T, Owned = Self>
30+
where
31+
Self: 'a;
32+
}
33+
34+
pub trait MatrixCommon {
35+
type V: Vector;
36+
}
37+
38+
fn main() {}

0 commit comments

Comments
 (0)