about summary refs log tree commit diff
diff options
context:
space:
mode:
authorlcnr <rust@lcnr.de>2023-07-20 10:40:59 +0200
committerlcnr <rust@lcnr.de>2023-07-20 12:01:34 +0200
commit2062f2ca8261b521caa9c34c195bf472dcb59e98 (patch)
tree961243d2584ecf7455f25d568edc3bf445a412dd
parent7c97a76b76120bd982762a982d4254ece32c43dc (diff)
downloadrust-2062f2ca8261b521caa9c34c195bf472dcb59e98.tar.gz
rust-2062f2ca8261b521caa9c34c195bf472dcb59e98.zip
review
-rw-r--r--compiler/rustc_trait_selection/src/solve/assembly/mod.rs8
-rw-r--r--tests/ui/traits/new-solver/assembly/assemble-normalizing-self-ty-impl-ambiguity.rs2
-rw-r--r--tests/ui/traits/new-solver/assembly/assemble-normalizing-self-ty-impl-ambiguity.stderr23
-rw-r--r--tests/ui/traits/new-solver/dont-normalize-proj-with-error.rs22
-rw-r--r--tests/ui/traits/new-solver/dont-normalize-proj-with-error.stderr9
5 files changed, 37 insertions, 27 deletions
diff --git a/compiler/rustc_trait_selection/src/solve/assembly/mod.rs b/compiler/rustc_trait_selection/src/solve/assembly/mod.rs
index 68e931aac8c..b661ff481a0 100644
--- a/compiler/rustc_trait_selection/src/solve/assembly/mod.rs
+++ b/compiler/rustc_trait_selection/src/solve/assembly/mod.rs
@@ -311,7 +311,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
         goal: Goal<'tcx, G>,
     ) -> Vec<Candidate<'tcx>> {
         debug_assert_eq!(goal, self.resolve_vars_if_possible(goal));
-        if let Some(ambig) = self.self_ty_infer_ambiguity_hack(goal) {
+        if let Some(ambig) = self.assemble_self_ty_infer_ambiguity_response(goal) {
             return ambig;
         }
 
@@ -324,13 +324,13 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
         candidates
     }
 
-    /// HACK: `_: Trait` is ambiguous, because it may be satisfied via a builtin rule,
+    /// `?0: Trait` is ambiguous, because it may be satisfied via a builtin rule,
     /// object bound, alias bound, etc. We are unable to determine this until we can at
     /// least structurally resolve the type one layer.
     ///
     /// It would also require us to consider all impls of the trait, which is both pretty
     /// bad for perf and would also constrain the self type if there is just a single impl.
-    fn self_ty_infer_ambiguity_hack<G: GoalKind<'tcx>>(
+    fn assemble_self_ty_infer_ambiguity_response<G: GoalKind<'tcx>>(
         &mut self,
         goal: Goal<'tcx, G>,
     ) -> Option<Vec<Candidate<'tcx>>> {
@@ -353,7 +353,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
         goal: Goal<'tcx, G>,
     ) -> Vec<Candidate<'tcx>> {
         debug_assert_eq!(goal, self.resolve_vars_if_possible(goal));
-        if let Some(ambig) = self.self_ty_infer_ambiguity_hack(goal) {
+        if let Some(ambig) = self.assemble_self_ty_infer_ambiguity_response(goal) {
             return ambig;
         }
 
diff --git a/tests/ui/traits/new-solver/assembly/assemble-normalizing-self-ty-impl-ambiguity.rs b/tests/ui/traits/new-solver/assembly/assemble-normalizing-self-ty-impl-ambiguity.rs
index 727ce84ba35..826e8c1e0b1 100644
--- a/tests/ui/traits/new-solver/assembly/assemble-normalizing-self-ty-impl-ambiguity.rs
+++ b/tests/ui/traits/new-solver/assembly/assemble-normalizing-self-ty-impl-ambiguity.rs
@@ -1,7 +1,9 @@
 // compile-flags: -Ztrait-solver=next
+// check-pass
 
 // Checks that we do not get ambiguity by considering an impl
 // multiple times if we're able to normalize the self type.
+
 trait Trait<'a> {}
 
 impl<'a, T: 'a> Trait<'a> for T {}
diff --git a/tests/ui/traits/new-solver/assembly/assemble-normalizing-self-ty-impl-ambiguity.stderr b/tests/ui/traits/new-solver/assembly/assemble-normalizing-self-ty-impl-ambiguity.stderr
deleted file mode 100644
index 91b635b35eb..00000000000
--- a/tests/ui/traits/new-solver/assembly/assemble-normalizing-self-ty-impl-ambiguity.stderr
+++ /dev/null
@@ -1,23 +0,0 @@
-error[E0283]: type annotations needed: cannot satisfy `<T as Id>::Assoc: Trait<'_>`
-  --> $DIR/assemble-normalizing-self-ty-impl-ambiguity.rs:19:5
-   |
-LL |     impls_trait::<<T as Id>::Assoc>();
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-   |
-   = note: cannot satisfy `<T as Id>::Assoc: Trait<'_>`
-note: required by a bound in `impls_trait`
-  --> $DIR/assemble-normalizing-self-ty-impl-ambiguity.rs:9:23
-   |
-LL | fn impls_trait<'a, T: Trait<'a>>() {}
-   |                       ^^^^^^^^^ required by this bound in `impls_trait`
-
-error[E0282]: type annotations needed
-  --> $DIR/assemble-normalizing-self-ty-impl-ambiguity.rs:24:5
-   |
-LL |     impls_trait::<<<() as Id>::Assoc as Id>::Assoc>();
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `impls_trait`
-
-error: aborting due to 2 previous errors
-
-Some errors have detailed explanations: E0282, E0283.
-For more information about an error, try `rustc --explain E0282`.
diff --git a/tests/ui/traits/new-solver/dont-normalize-proj-with-error.rs b/tests/ui/traits/new-solver/dont-normalize-proj-with-error.rs
new file mode 100644
index 00000000000..19a6fa990ff
--- /dev/null
+++ b/tests/ui/traits/new-solver/dont-normalize-proj-with-error.rs
@@ -0,0 +1,22 @@
+// compile-flags: -Ztrait-solver=next
+
+// Test that we don't incorrectly leak unconstrained inference variables
+// if the projection contained an error. This caused an ICE in writeback.
+
+trait Mirror {
+    type Assoc: ?Sized;
+}
+
+struct Wrapper<T: ?Sized>(T);
+impl<T: ?Sized> Mirror for Wrapper<T> {
+    type Assoc = T;
+}
+
+fn mirror<W: Mirror>(_: W) -> Box<W::Assoc> { todo!() }
+
+fn type_error() -> TypeError { todo!() }
+//~^ ERROR cannot find type `TypeError` in this scope
+
+fn main() {
+    let x = mirror(type_error());
+}
diff --git a/tests/ui/traits/new-solver/dont-normalize-proj-with-error.stderr b/tests/ui/traits/new-solver/dont-normalize-proj-with-error.stderr
new file mode 100644
index 00000000000..5a7459ec1fd
--- /dev/null
+++ b/tests/ui/traits/new-solver/dont-normalize-proj-with-error.stderr
@@ -0,0 +1,9 @@
+error[E0412]: cannot find type `TypeError` in this scope
+  --> $DIR/dont-normalize-proj-with-error.rs:17:20
+   |
+LL | fn type_error() -> TypeError { todo!() }
+   |                    ^^^^^^^^^ not found in this scope
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0412`.