Skip to content

Commit fe5f591

Browse files
committed
Auto merge of #115039 - jackh726:impl_compare_add_alias_obligations, r=aliemjay
Add projection obligations when comparing impl too Fixes #115033 In the test, when we ask for WF obligations of `DatasetIter<'a, ArrayBase<D>>`, we get back two important obligations: `[<D as Data>::Elem -> ?1, ?1: 'a]`. If we don't add the projection obligation, `?1` remains unconstrained. An alternative solution would be to use unnormalized obligations, where we only have one relevant obligation: `<D as Data>::Elem: 'a`. This would leave no inference vars unconstrained.
2 parents b131feb + 31032ec commit fe5f591

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

Diff for: 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)