Rollup merge of #118914 - compiler-errors:eager-alias-relate, r=lcnr
Unconditionally register alias-relate in projection goal Follow-up to #118725, which subtly broke closure signature inference on combinators like `Result::map` which I noticed in syn. Essentially, instead of using `eq` which will eagerly infer `?1 := <?2 as Trait>::Assoc`, we can directly emit an alias-relate goal, which will stay ambiguous for as long as `?2` is ambiguous. This also more closely models the conceptual framing that projects-to acts like an alias-relate when solving, and like a normalizes-to when in a param env. r? lcnr
This commit is contained in:
commit
accaea2795
@ -8,16 +8,28 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
goal: Goal<'tcx, ProjectionPredicate<'tcx>>,
|
goal: Goal<'tcx, ProjectionPredicate<'tcx>>,
|
||||||
) -> QueryResult<'tcx> {
|
) -> QueryResult<'tcx> {
|
||||||
match goal.predicate.term.unpack() {
|
let tcx = self.tcx();
|
||||||
ty::TermKind::Ty(term) => {
|
let projection_term = match goal.predicate.term.unpack() {
|
||||||
let alias = goal.predicate.projection_ty.to_ty(self.tcx());
|
ty::TermKind::Ty(_) => goal.predicate.projection_ty.to_ty(tcx).into(),
|
||||||
self.eq(goal.param_env, alias, term)?;
|
ty::TermKind::Const(_) => ty::Const::new_unevaluated(
|
||||||
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
|
tcx,
|
||||||
}
|
ty::UnevaluatedConst::new(
|
||||||
// FIXME(associated_const_equality): actually do something here.
|
goal.predicate.projection_ty.def_id,
|
||||||
ty::TermKind::Const(_) => {
|
goal.predicate.projection_ty.args,
|
||||||
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
|
),
|
||||||
}
|
tcx.type_of(goal.predicate.projection_ty.def_id)
|
||||||
}
|
.instantiate(tcx, goal.predicate.projection_ty.args),
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
};
|
||||||
|
self.add_goal(goal.with(
|
||||||
|
tcx,
|
||||||
|
ty::PredicateKind::AliasRelate(
|
||||||
|
projection_term,
|
||||||
|
goal.predicate.term,
|
||||||
|
ty::AliasRelationDirection::Equate,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
21
tests/ui/traits/next-solver/closure-signature-inference-2.rs
Normal file
21
tests/ui/traits/next-solver/closure-signature-inference-2.rs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// compile-flags: -Znext-solver
|
||||||
|
// check-pass
|
||||||
|
|
||||||
|
fn map<T: Default, U, F: FnOnce(T) -> U>(f: F) {
|
||||||
|
f(T::default());
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
map::<i32, _ /* ?U */, _ /* ?F */>(|x| x.to_string());
|
||||||
|
// PREVIOUSLY when confirming the `map` call, we register:
|
||||||
|
//
|
||||||
|
// (1.) ?F: FnOnce<(i32,)>
|
||||||
|
// (2.) <?F as FnOnce<(i32,)>>::Output projects-to ?U
|
||||||
|
//
|
||||||
|
// While (1.) is ambiguous, (2.) immediately gets processed
|
||||||
|
// and we infer `?U := <?F as FnOnce<(i32,)>>::Output`.
|
||||||
|
//
|
||||||
|
// Thus, the only pending obligation that remains is (1.).
|
||||||
|
// Since it is a trait obligation, we don't use it to deduce
|
||||||
|
// the closure signature, and we fail!
|
||||||
|
}
|
15
tests/ui/traits/next-solver/closure-signature-inference.rs
Normal file
15
tests/ui/traits/next-solver/closure-signature-inference.rs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// compile-flags: -Znext-solver
|
||||||
|
// check-pass
|
||||||
|
|
||||||
|
struct A;
|
||||||
|
impl A {
|
||||||
|
fn hi(self) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn hello() -> Result<(A,), ()> {
|
||||||
|
Err(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let x = hello().map(|(x,)| x.hi());
|
||||||
|
}
|
@ -1,8 +1,18 @@
|
|||||||
error[E0284]: type annotations needed: cannot satisfy `<<Rigid as IdHigherRankedBound>::Assoc as WithAssoc<<Wrapper<Leaf> as Id>::Assoc>>::Assoc normalizes-to <<Leaf as WithAssoc<_>>::Assoc as Id>::Assoc`
|
error[E0284]: type annotations needed
|
||||||
--> $DIR/generalize-proj-new-universe-index-2.rs:74:5
|
--> $DIR/generalize-proj-new-universe-index-2.rs:74:5
|
||||||
|
|
|
|
||||||
LL | bound::<<Rigid as IdHigherRankedBound>::Assoc, <Wrapper<Leaf> as Id>::Assoc, _>()
|
LL | bound::<<Rigid as IdHigherRankedBound>::Assoc, <Wrapper<Leaf> as Id>::Assoc, _>()
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot satisfy `<<Rigid as IdHigherRankedBound>::Assoc as WithAssoc<<Wrapper<Leaf> as Id>::Assoc>>::Assoc normalizes-to <<Leaf as WithAssoc<_>>::Assoc as Id>::Assoc`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `V` declared on the function `bound`
|
||||||
|
|
|
||||||
|
= note: cannot satisfy `<<Rigid as IdHigherRankedBound>::Assoc as WithAssoc<<Wrapper<Leaf> as Id>::Assoc>>::Assoc == _`
|
||||||
|
note: required by a bound in `bound`
|
||||||
|
--> $DIR/generalize-proj-new-universe-index-2.rs:69:21
|
||||||
|
|
|
||||||
|
LL | fn bound<T: ?Sized, U: ?Sized, V: ?Sized>()
|
||||||
|
| ----- required by a bound in this function
|
||||||
|
LL | where
|
||||||
|
LL | T: WithAssoc<U, Assoc = V>,
|
||||||
|
| ^^^^^^^^^ required by this bound in `bound`
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user