Skip to content

Commit 31032ec

Browse files
committed
Add projection obligations when comparing impl too
1 parent 5c6a7e7 commit 31032ec

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,16 @@ fn compare_method_predicate_entailment<'tcx>(
342342
continue;
343343
};
344344
for obligation in obligations {
345+
debug!(?obligation);
345346
match obligation.predicate.kind().skip_binder() {
347+
// We need to register Projection oblgiations too, because we may end up with
348+
// an implied `X::Item: 'a`, which gets desugared into `X::Item = ?0`, `?0: 'a`.
349+
// If we only register the region outlives obligation, this leads to an unconstrained var.
350+
// See `implied_bounds_entailment_alias_var` test.
346351
ty::PredicateKind::Clause(
347-
ty::ClauseKind::RegionOutlives(..) | ty::ClauseKind::TypeOutlives(..),
352+
ty::ClauseKind::RegionOutlives(..)
353+
| ty::ClauseKind::TypeOutlives(..)
354+
| ty::ClauseKind::Projection(..),
348355
) => ocx.register_obligation(obligation),
349356
ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(arg)) => {
350357
if wf_args_seen.insert(arg) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// check-pass
2+
3+
trait Data {
4+
type Elem;
5+
}
6+
7+
impl<F, S: Data<Elem = F>> Data for ArrayBase<S> {
8+
type Elem = F;
9+
}
10+
11+
struct DatasetIter<'a, R: Data> {
12+
data: &'a R::Elem,
13+
}
14+
15+
pub struct ArrayBase<S> {
16+
data: S,
17+
}
18+
19+
trait Trait {
20+
type Item;
21+
fn next() -> Option<Self::Item>;
22+
}
23+
24+
impl<'a, D: Data> Trait for DatasetIter<'a, ArrayBase<D>> {
25+
type Item = ();
26+
27+
fn next() -> Option<Self::Item> {
28+
None
29+
}
30+
}
31+
32+
fn main() {}

0 commit comments

Comments
 (0)