Skip to content

Commit 18d4b68

Browse files
Don't emit alias-eq goal if projections are structurally equal after resolving vars
1 parent cca2e53 commit 18d4b68

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

compiler/rustc_infer/src/infer/combine.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,12 @@ impl<'tcx> InferCtxt<'tcx> {
128128
(_, ty::Alias(AliasKind::Projection, _)) | (ty::Alias(AliasKind::Projection, _), _)
129129
if self.tcx.trait_solver_next() =>
130130
{
131-
relation.register_type_relate_obligation(a, b);
131+
// The new solver can be somewhat lazy with resolving nested variables,
132+
// so we want to avoid emitting a trivial alias-eq goal (which becomes
133+
// non-trivial after canonicalization) if the types are identical.
134+
if self.resolve_vars_if_possible(a) != self.resolve_vars_if_possible(b) {
135+
relation.register_type_relate_obligation(a, b);
136+
}
132137
Ok(a)
133138
}
134139

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// compile-flags: -Ztrait-solver=next
2+
// check-pass
3+
4+
use std::{iter, slice};
5+
6+
struct Attr;
7+
8+
fn test<'a, T: Iterator<Item = &'a Attr>>() {}
9+
10+
fn main() {
11+
test::<iter::Filter<slice::Iter<'_, Attr>, fn(&&Attr) -> bool>>();
12+
}

0 commit comments

Comments
 (0)