From 929d632b541cb52c23e1b768bb8c3f88bf9b5955 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 13 Dec 2023 14:11:09 +0000 Subject: Unconditionally register alias-relate in projection goal --- .../src/solve/project_goals.rs | 34 +++++++++++++++------- .../projection/param-env-trait-candidate-1.rs | 14 --------- .../projection/param-env-trait-candidate-2.rs | 29 ------------------ .../next-solver/closure-signature-inference-2.rs | 21 +++++++++++++ .../next-solver/closure-signature-inference.rs | 15 ++++++++++ .../generalize-proj-new-universe-index-2.stderr | 14 +++++++-- .../projection/param-env-trait-candidate-1.rs | 14 +++++++++ .../projection/param-env-trait-candidate-2.rs | 29 ++++++++++++++++++ 8 files changed, 114 insertions(+), 56 deletions(-) delete mode 100644 tests/ui/traits/new-solver/projection/param-env-trait-candidate-1.rs delete mode 100644 tests/ui/traits/new-solver/projection/param-env-trait-candidate-2.rs create mode 100644 tests/ui/traits/next-solver/closure-signature-inference-2.rs create mode 100644 tests/ui/traits/next-solver/closure-signature-inference.rs create mode 100644 tests/ui/traits/next-solver/projection/param-env-trait-candidate-1.rs create mode 100644 tests/ui/traits/next-solver/projection/param-env-trait-candidate-2.rs diff --git a/compiler/rustc_trait_selection/src/solve/project_goals.rs b/compiler/rustc_trait_selection/src/solve/project_goals.rs index 0b80969c307..d0e92a54ceb 100644 --- a/compiler/rustc_trait_selection/src/solve/project_goals.rs +++ b/compiler/rustc_trait_selection/src/solve/project_goals.rs @@ -8,16 +8,28 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { &mut self, goal: Goal<'tcx, ProjectionPredicate<'tcx>>, ) -> QueryResult<'tcx> { - match goal.predicate.term.unpack() { - ty::TermKind::Ty(term) => { - let alias = goal.predicate.projection_ty.to_ty(self.tcx()); - self.eq(goal.param_env, alias, term)?; - self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) - } - // FIXME(associated_const_equality): actually do something here. - ty::TermKind::Const(_) => { - self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) - } - } + let tcx = self.tcx(); + let projection_term = match goal.predicate.term.unpack() { + ty::TermKind::Ty(_) => goal.predicate.projection_ty.to_ty(tcx).into(), + ty::TermKind::Const(_) => ty::Const::new_unevaluated( + tcx, + ty::UnevaluatedConst::new( + goal.predicate.projection_ty.def_id, + goal.predicate.projection_ty.args, + ), + 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) } } diff --git a/tests/ui/traits/new-solver/projection/param-env-trait-candidate-1.rs b/tests/ui/traits/new-solver/projection/param-env-trait-candidate-1.rs deleted file mode 100644 index b337c067374..00000000000 --- a/tests/ui/traits/new-solver/projection/param-env-trait-candidate-1.rs +++ /dev/null @@ -1,14 +0,0 @@ -// check-pass -// compile-flags: -Znext-solver - -// See https://github.com/rust-lang/trait-system-refactor-initiative/issues/1 -// a minimization of a pattern in core. -fn next, U>(t: &mut T) -> Option { - t.next() -} - -fn foo(t: &mut T) { - let _: Option = next(t); -} - -fn main() {} diff --git a/tests/ui/traits/new-solver/projection/param-env-trait-candidate-2.rs b/tests/ui/traits/new-solver/projection/param-env-trait-candidate-2.rs deleted file mode 100644 index db8dc1eb9be..00000000000 --- a/tests/ui/traits/new-solver/projection/param-env-trait-candidate-2.rs +++ /dev/null @@ -1,29 +0,0 @@ -// check-pass -// compile-flags: -Znext-solver - -// See https://github.com/rust-lang/trait-system-refactor-initiative/issues/1, -// a minimization of a pattern in core. - -trait Iterator { - type Item; -} - -struct Flatten(I); - -impl Iterator for Flatten -where - I: Iterator, -{ - type Item = U; -} - -fn needs_iterator() {} - -fn environment() -where - J: Iterator, -{ - needs_iterator::>(); -} - -fn main() {} diff --git a/tests/ui/traits/next-solver/closure-signature-inference-2.rs b/tests/ui/traits/next-solver/closure-signature-inference-2.rs new file mode 100644 index 00000000000..8fece7ba91f --- /dev/null +++ b/tests/ui/traits/next-solver/closure-signature-inference-2.rs @@ -0,0 +1,21 @@ +// compile-flags: -Znext-solver +// check-pass + +fn map U>(f: F) { + f(T::default()); +} + +fn main() { + map::(|x| x.to_string()); + // PREVIOUSLY when confirming the `map` call, we register: + // + // (1.) ?F: FnOnce<(i32,)> + // (2.) >::Output projects-to ?U + // + // While (1.) is ambiguous, (2.) immediately gets processed + // and we infer `?U := >::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! +} diff --git a/tests/ui/traits/next-solver/closure-signature-inference.rs b/tests/ui/traits/next-solver/closure-signature-inference.rs new file mode 100644 index 00000000000..355fc790229 --- /dev/null +++ b/tests/ui/traits/next-solver/closure-signature-inference.rs @@ -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()); +} diff --git a/tests/ui/traits/next-solver/generalize/generalize-proj-new-universe-index-2.stderr b/tests/ui/traits/next-solver/generalize/generalize-proj-new-universe-index-2.stderr index e4922b0c3e9..4548ab1e297 100644 --- a/tests/ui/traits/next-solver/generalize/generalize-proj-new-universe-index-2.stderr +++ b/tests/ui/traits/next-solver/generalize/generalize-proj-new-universe-index-2.stderr @@ -1,8 +1,18 @@ -error[E0284]: type annotations needed: cannot satisfy `<::Assoc as WithAssoc< as Id>::Assoc>>::Assoc normalizes-to <>::Assoc as Id>::Assoc` +error[E0284]: type annotations needed --> $DIR/generalize-proj-new-universe-index-2.rs:74:5 | LL | bound::<::Assoc, as Id>::Assoc, _>() - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot satisfy `<::Assoc as WithAssoc< as Id>::Assoc>>::Assoc normalizes-to <>::Assoc as Id>::Assoc` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `V` declared on the function `bound` + | + = note: cannot satisfy `<::Assoc as WithAssoc< as Id>::Assoc>>::Assoc == _` +note: required by a bound in `bound` + --> $DIR/generalize-proj-new-universe-index-2.rs:69:21 + | +LL | fn bound() + | ----- required by a bound in this function +LL | where +LL | T: WithAssoc, + | ^^^^^^^^^ required by this bound in `bound` error: aborting due to 1 previous error diff --git a/tests/ui/traits/next-solver/projection/param-env-trait-candidate-1.rs b/tests/ui/traits/next-solver/projection/param-env-trait-candidate-1.rs new file mode 100644 index 00000000000..b337c067374 --- /dev/null +++ b/tests/ui/traits/next-solver/projection/param-env-trait-candidate-1.rs @@ -0,0 +1,14 @@ +// check-pass +// compile-flags: -Znext-solver + +// See https://github.com/rust-lang/trait-system-refactor-initiative/issues/1 +// a minimization of a pattern in core. +fn next, U>(t: &mut T) -> Option { + t.next() +} + +fn foo(t: &mut T) { + let _: Option = next(t); +} + +fn main() {} diff --git a/tests/ui/traits/next-solver/projection/param-env-trait-candidate-2.rs b/tests/ui/traits/next-solver/projection/param-env-trait-candidate-2.rs new file mode 100644 index 00000000000..db8dc1eb9be --- /dev/null +++ b/tests/ui/traits/next-solver/projection/param-env-trait-candidate-2.rs @@ -0,0 +1,29 @@ +// check-pass +// compile-flags: -Znext-solver + +// See https://github.com/rust-lang/trait-system-refactor-initiative/issues/1, +// a minimization of a pattern in core. + +trait Iterator { + type Item; +} + +struct Flatten(I); + +impl Iterator for Flatten +where + I: Iterator, +{ + type Item = U; +} + +fn needs_iterator() {} + +fn environment() +where + J: Iterator, +{ + needs_iterator::>(); +} + +fn main() {} -- cgit 1.4.1-3-g733a5