about summary refs log tree commit diff
diff options
context:
space:
mode:
authorlcnr <rust@lcnr.de>2024-04-02 13:20:03 +0200
committerlcnr <rust@lcnr.de>2024-04-04 07:47:22 +0200
commitd99c775febff75f578437504fed69c9f4df5e92d (patch)
treec437b52a3d92ac80f078f50b300063ef5e2201a9
parent0accf4ec4c07d23aa86f6a97aeb8797941abc30e (diff)
downloadrust-d99c775febff75f578437504fed69c9f4df5e92d.tar.gz
rust-d99c775febff75f578437504fed69c9f4df5e92d.zip
unconstrained `NormalizesTo` term for opaques
-rw-r--r--compiler/rustc_trait_selection/src/solve/alias_relate.rs20
-rw-r--r--compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs10
-rw-r--r--compiler/rustc_trait_selection/src/solve/normalizes_to/opaque_types.rs6
-rw-r--r--tests/ui/generic-associated-types/ambig-hr-projection-issue-93340.next.stderr23
-rw-r--r--tests/ui/generic-associated-types/ambig-hr-projection-issue-93340.old.stderr2
-rw-r--r--tests/ui/generic-associated-types/ambig-hr-projection-issue-93340.rs1
-rw-r--r--tests/ui/impl-trait/recursive-coroutine-boxed.next.stderr28
-rw-r--r--tests/ui/impl-trait/recursive-coroutine-boxed.rs6
8 files changed, 54 insertions, 42 deletions
diff --git a/compiler/rustc_trait_selection/src/solve/alias_relate.rs b/compiler/rustc_trait_selection/src/solve/alias_relate.rs
index e081a9100e2..f36c2cd94ad 100644
--- a/compiler/rustc_trait_selection/src/solve/alias_relate.rs
+++ b/compiler/rustc_trait_selection/src/solve/alias_relate.rs
@@ -23,7 +23,6 @@
 
 use super::EvalCtxt;
 use rustc_infer::traits::query::NoSolution;
-use rustc_infer::traits::solve::GoalSource;
 use rustc_middle::traits::solve::{Certainty, Goal, QueryResult};
 use rustc_middle::ty::{self, Ty};
 
@@ -147,25 +146,18 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
             return None;
         }
 
-        let ty::Alias(kind, alias) = *ty.kind() else {
+        let ty::Alias(_, alias) = *ty.kind() else {
             return Some(ty);
         };
 
         match self.commit_if_ok(|this| {
             let tcx = this.tcx();
             let normalized_ty = this.next_ty_infer();
-            let normalizes_to = ty::NormalizesTo { alias, term: normalized_ty.into() };
-            match kind {
-                ty::AliasKind::Opaque => {
-                    // HACK: Unlike for associated types, `normalizes-to` for opaques
-                    // is currently not treated as a function. We do not erase the
-                    // expected term.
-                    this.add_goal(GoalSource::Misc, Goal::new(tcx, param_env, normalizes_to));
-                }
-                ty::AliasKind::Projection | ty::AliasKind::Inherent | ty::AliasKind::Weak => {
-                    this.add_normalizes_to_goal(Goal::new(tcx, param_env, normalizes_to))
-                }
-            }
+            this.add_normalizes_to_goal(Goal::new(
+                tcx,
+                param_env,
+                ty::NormalizesTo { alias, term: normalized_ty.into() },
+            ));
             this.try_evaluate_added_goals()?;
             Ok(this.resolve_vars_if_possible(normalized_ty))
         }) {
diff --git a/compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs b/compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs
index d8aeadd07b3..4a968c5ae97 100644
--- a/compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs
+++ b/compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs
@@ -30,14 +30,9 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
         &mut self,
         goal: Goal<'tcx, NormalizesTo<'tcx>>,
     ) -> QueryResult<'tcx> {
-        let def_id = goal.predicate.def_id();
-        let def_kind = self.tcx().def_kind(def_id);
-        match def_kind {
-            DefKind::OpaqueTy => return self.normalize_opaque_type(goal),
-            _ => self.set_is_normalizes_to_goal(),
-        }
-
+        self.set_is_normalizes_to_goal();
         debug_assert!(self.term_is_fully_unconstrained(goal));
+        let def_id = goal.predicate.def_id();
         match self.tcx().def_kind(def_id) {
             DefKind::AssocTy | DefKind::AssocConst => {
                 match self.tcx().associated_item(def_id).container {
@@ -52,6 +47,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
             }
             DefKind::AnonConst => self.normalize_anon_const(goal),
             DefKind::TyAlias => self.normalize_weak_type(goal),
+            DefKind::OpaqueTy => self.normalize_opaque_type(goal),
             kind => bug!("unknown DefKind {} in normalizes-to goal: {goal:#?}", kind.descr(def_id)),
         }
     }
diff --git a/compiler/rustc_trait_selection/src/solve/normalizes_to/opaque_types.rs b/compiler/rustc_trait_selection/src/solve/normalizes_to/opaque_types.rs
index 356c3776c04..9fdb280cdc6 100644
--- a/compiler/rustc_trait_selection/src/solve/normalizes_to/opaque_types.rs
+++ b/compiler/rustc_trait_selection/src/solve/normalizes_to/opaque_types.rs
@@ -58,12 +58,6 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
                     }
                 }
 
-                let expected = self.structurally_normalize_ty(goal.param_env, expected)?;
-                if expected.is_ty_var() {
-                    return self
-                        .evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS);
-                }
-
                 // Otherwise, define a new opaque type
                 self.insert_hidden_type(opaque_type_key, goal.param_env, expected)?;
                 self.add_item_bounds_for_hidden_type(
diff --git a/tests/ui/generic-associated-types/ambig-hr-projection-issue-93340.next.stderr b/tests/ui/generic-associated-types/ambig-hr-projection-issue-93340.next.stderr
index 06ffff057f9..6aad0f91cf5 100644
--- a/tests/ui/generic-associated-types/ambig-hr-projection-issue-93340.next.stderr
+++ b/tests/ui/generic-associated-types/ambig-hr-projection-issue-93340.next.stderr
@@ -1,5 +1,5 @@
 error[E0283]: type annotations needed
-  --> $DIR/ambig-hr-projection-issue-93340.rs:16:5
+  --> $DIR/ambig-hr-projection-issue-93340.rs:17:5
    |
 LL |     cmp_eq
    |     ^^^^^^ cannot infer type of the type parameter `A` declared on the function `cmp_eq`
@@ -16,13 +16,13 @@ LL |     cmp_eq::<A, B, O>
    |           +++++++++++
 
 error[E0275]: overflow evaluating the requirement `impl for<'a, 'b> Fn(<A as Scalar>::RefType<'a>, <B as Scalar>::RefType<'b>) -> O == for<'a, 'b> fn(..., ...) -> ... {cmp_eq::<..., ..., ...>}`
-  --> $DIR/ambig-hr-projection-issue-93340.rs:16:5
+  --> $DIR/ambig-hr-projection-issue-93340.rs:17:5
    |
 LL |     cmp_eq
    |     ^^^^^^
 
 error[E0275]: overflow evaluating the requirement `impl for<'a, 'b> Fn(<A as Scalar>::RefType<'a>, <B as Scalar>::RefType<'b>) -> O == for<'a, 'b> fn(..., ...) -> ... {cmp_eq::<..., ..., ...>}`
-  --> $DIR/ambig-hr-projection-issue-93340.rs:16:5
+  --> $DIR/ambig-hr-projection-issue-93340.rs:17:5
    |
 LL |     cmp_eq
    |     ^^^^^^
@@ -35,14 +35,25 @@ error[E0275]: overflow evaluating the requirement `for<'a, 'b> fn(<O as Scalar>:
 LL |   ) -> impl Fn(A::RefType<'_>, B::RefType<'_>) -> O {
    |  ___________________________________________________^
 LL | |
-LL | |     cmp_eq
-LL | |
 LL | |
+LL | |     cmp_eq
+...  |
 LL | |
 LL | | }
    | |_^
 
-error: aborting due to 4 previous errors
+error[E0275]: overflow evaluating the requirement `impl for<'a, 'b> Fn(<A as Scalar>::RefType<'a>, <B as Scalar>::RefType<'b>) -> O: Sized`
+  --> $DIR/ambig-hr-projection-issue-93340.rs:14:6
+   |
+LL | ) -> impl Fn(A::RefType<'_>, B::RefType<'_>) -> O {
+   |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL |     cmp_eq
+   |     ------ this returned value is of type `for<'a, 'b> fn(<O as Scalar>::RefType<'a>, <_ as Scalar>::RefType<'b>) -> _ {cmp_eq::<O, _, _>}`
+   |
+   = note: the return type of a function must have a statically known size
+
+error: aborting due to 5 previous errors
 
 Some errors have detailed explanations: E0275, E0283.
 For more information about an error, try `rustc --explain E0275`.
diff --git a/tests/ui/generic-associated-types/ambig-hr-projection-issue-93340.old.stderr b/tests/ui/generic-associated-types/ambig-hr-projection-issue-93340.old.stderr
index df2ec4ab182..941c8a65f15 100644
--- a/tests/ui/generic-associated-types/ambig-hr-projection-issue-93340.old.stderr
+++ b/tests/ui/generic-associated-types/ambig-hr-projection-issue-93340.old.stderr
@@ -1,5 +1,5 @@
 error[E0283]: type annotations needed
-  --> $DIR/ambig-hr-projection-issue-93340.rs:16:5
+  --> $DIR/ambig-hr-projection-issue-93340.rs:17:5
    |
 LL |     cmp_eq
    |     ^^^^^^ cannot infer type of the type parameter `A` declared on the function `cmp_eq`
diff --git a/tests/ui/generic-associated-types/ambig-hr-projection-issue-93340.rs b/tests/ui/generic-associated-types/ambig-hr-projection-issue-93340.rs
index 4d8ea9d8d48..2093f9b604b 100644
--- a/tests/ui/generic-associated-types/ambig-hr-projection-issue-93340.rs
+++ b/tests/ui/generic-associated-types/ambig-hr-projection-issue-93340.rs
@@ -13,6 +13,7 @@ fn cmp_eq<'a, 'b, A: Scalar, B: Scalar, O: Scalar>(a: A::RefType<'a>, b: B::RefT
 fn build_expression<A: Scalar, B: Scalar, O: Scalar>(
 ) -> impl Fn(A::RefType<'_>, B::RefType<'_>) -> O {
     //[next]~^ ERROR overflow evaluating the requirement
+    //[next]~| ERROR overflow evaluating the requirement
     cmp_eq
     //~^ ERROR type annotations needed
     //[next]~| ERROR overflow evaluating the requirement
diff --git a/tests/ui/impl-trait/recursive-coroutine-boxed.next.stderr b/tests/ui/impl-trait/recursive-coroutine-boxed.next.stderr
index 755d12d7448..c0b399746ea 100644
--- a/tests/ui/impl-trait/recursive-coroutine-boxed.next.stderr
+++ b/tests/ui/impl-trait/recursive-coroutine-boxed.next.stderr
@@ -1,5 +1,5 @@
 error[E0282]: type annotations needed
-  --> $DIR/recursive-coroutine-boxed.rs:12:23
+  --> $DIR/recursive-coroutine-boxed.rs:14:23
    |
 LL |         let mut gen = Box::pin(foo());
    |                       ^^^^^^^^ cannot infer type of the type parameter `T` declared on the struct `Box`
@@ -12,12 +12,28 @@ help: consider specifying the generic argument
 LL |         let mut gen = Box::<T>::pin(foo());
    |                          +++++
 
-error[E0282]: type annotations needed
-  --> $DIR/recursive-coroutine-boxed.rs:9:13
+error[E0308]: mismatched types
+  --> $DIR/recursive-coroutine-boxed.rs:13:5
+   |
+LL |   fn foo() -> impl Coroutine<Yield = (), Return = ()> {
+   |               ---------------------------------------
+   |               |
+   |               the expected opaque type
+   |               expected `impl Coroutine<Yield = (), Return = ()>` because of return type
+...
+LL | /     || {
+LL | |         let mut gen = Box::pin(foo());
+LL | |
+LL | |         let mut r = gen.as_mut().resume(());
+...  |
+LL | |         }
+LL | |     }
+   | |_____^ types differ
    |
-LL | fn foo() -> impl Coroutine<Yield = (), Return = ()> {
-   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for opaque type `impl Coroutine<Yield = (), Return = ()>`
+   = note: expected opaque type `impl Coroutine<Yield = (), Return = ()>`
+                found coroutine `{coroutine@$DIR/recursive-coroutine-boxed.rs:13:5: 13:7}`
 
 error: aborting due to 2 previous errors
 
-For more information about this error, try `rustc --explain E0282`.
+Some errors have detailed explanations: E0282, E0308.
+For more information about an error, try `rustc --explain E0282`.
diff --git a/tests/ui/impl-trait/recursive-coroutine-boxed.rs b/tests/ui/impl-trait/recursive-coroutine-boxed.rs
index 3b8ffb92090..02c75be0f3a 100644
--- a/tests/ui/impl-trait/recursive-coroutine-boxed.rs
+++ b/tests/ui/impl-trait/recursive-coroutine-boxed.rs
@@ -7,8 +7,10 @@
 use std::ops::{Coroutine, CoroutineState};
 
 fn foo() -> impl Coroutine<Yield = (), Return = ()> {
-    //[next]~^ ERROR type annotations needed
-    || {
+    // FIXME(-Znext-solver): this fails with a mismatched types as the
+    // hidden type of the opaque ends up as {type error}. We should not
+    // emit errors for such goals.
+    || { //[next]~ ERROR mismatched types
         let mut gen = Box::pin(foo());
         //[next]~^ ERROR type annotations needed
         let mut r = gen.as_mut().resume(());