about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-11-08 10:08:44 +0000
committerbors <bors@rust-lang.org>2023-11-08 10:08:44 +0000
commitfab1054e1742790c22ccc92a625736d658363677 (patch)
treedb086ac22ee6f267a7e7899460d7155f14d00eff /tests
parent750c2ecd1503fe7ff39e41603977d12de33417d8 (diff)
parent97c9d8f405e1b93bf69334b239f89d92d28847a0 (diff)
downloadrust-fab1054e1742790c22ccc92a625736d658363677.tar.gz
rust-fab1054e1742790c22ccc92a625736d658363677.zip
Auto merge of #117542 - compiler-errors:only-normalize-predicate, r=lcnr
Only use `normalize_param_env` when normalizing predicate in `check_item_bounds`

Only use the `normalize_param_env` when normalizing the item bound predicate in `check_item_bounds`, instead of using it when processing this obligation as well. This causes <BUG> to reoccur, but hopefully with better caching in the future, we can fix this would having such bad effects on perf.

This PR also fixes #117598. It turns out that the GAT predicate that we install is actually wrong -- given code like:

```
impl<'r> HasValueRef<'r> for Any {
    type Database = Any;
}
```

We currently generate a predicate that looks like `<Any as HasValueRef<'r>>::Database = Any`, where `'r` is an early-bound variable. Really this GAT assumption should be universally quantified over the impl's args, i.e. `for<'r> <Any as HasValueRef<'r>>::Database = Any`, but then we'd need the binder to also include all the WC of the impl as well, which we don't support yet, lol.
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/generic-associated-types/assume-gat-normalization-for-nested-goals.rs2
-rw-r--r--tests/ui/generic-associated-types/assume-gat-normalization-for-nested-goals.stderr24
-rw-r--r--tests/ui/generic-associated-types/higher-ranked-self-impl-requirement.rs20
-rw-r--r--tests/ui/traits/new-solver/specialization-transmute.rs2
-rw-r--r--tests/ui/traits/new-solver/specialization-transmute.stderr11
-rw-r--r--tests/ui/traits/new-solver/specialization-unconstrained.rs2
-rw-r--r--tests/ui/traits/new-solver/specialization-unconstrained.stderr11
7 files changed, 65 insertions, 7 deletions
diff --git a/tests/ui/generic-associated-types/assume-gat-normalization-for-nested-goals.rs b/tests/ui/generic-associated-types/assume-gat-normalization-for-nested-goals.rs
index 7b168707239..e2d51c6649a 100644
--- a/tests/ui/generic-associated-types/assume-gat-normalization-for-nested-goals.rs
+++ b/tests/ui/generic-associated-types/assume-gat-normalization-for-nested-goals.rs
@@ -1,4 +1,4 @@
-// check-pass
+// known-bug: #117606
 
 #![feature(associated_type_defaults)]
 
diff --git a/tests/ui/generic-associated-types/assume-gat-normalization-for-nested-goals.stderr b/tests/ui/generic-associated-types/assume-gat-normalization-for-nested-goals.stderr
new file mode 100644
index 00000000000..abad0f25c0f
--- /dev/null
+++ b/tests/ui/generic-associated-types/assume-gat-normalization-for-nested-goals.stderr
@@ -0,0 +1,24 @@
+error[E0277]: the trait bound `<Self as Foo>::Bar<()>: Eq<i32>` is not satisfied
+  --> $DIR/assume-gat-normalization-for-nested-goals.rs:6:30
+   |
+LL |     type Bar<T>: Baz<Self> = i32;
+   |                              ^^^ the trait `Eq<i32>` is not implemented for `<Self as Foo>::Bar<()>`
+   |
+note: required for `i32` to implement `Baz<Self>`
+  --> $DIR/assume-gat-normalization-for-nested-goals.rs:13:23
+   |
+LL | impl<T: Foo + ?Sized> Baz<T> for i32 where T::Bar<()>: Eq<i32> {}
+   |                       ^^^^^^     ^^^                   ------- unsatisfied trait bound introduced here
+note: required by a bound in `Foo::Bar`
+  --> $DIR/assume-gat-normalization-for-nested-goals.rs:6:18
+   |
+LL |     type Bar<T>: Baz<Self> = i32;
+   |                  ^^^^^^^^^ required by this bound in `Foo::Bar`
+help: consider further restricting the associated type
+   |
+LL | trait Foo where <Self as Foo>::Bar<()>: Eq<i32> {
+   |           +++++++++++++++++++++++++++++++++++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/generic-associated-types/higher-ranked-self-impl-requirement.rs b/tests/ui/generic-associated-types/higher-ranked-self-impl-requirement.rs
new file mode 100644
index 00000000000..5ef9437c968
--- /dev/null
+++ b/tests/ui/generic-associated-types/higher-ranked-self-impl-requirement.rs
@@ -0,0 +1,20 @@
+// check-pass
+
+trait Database: for<'r> HasValueRef<'r, Database = Self> {}
+
+trait HasValueRef<'r> {
+    type Database: Database;
+}
+
+struct Any;
+
+impl Database for Any {}
+
+impl<'r> HasValueRef<'r> for Any {
+    // Make sure we don't have issues when the GAT assumption
+    // `<Any as HasValue<'r>>::Database = Any` isn't universally
+    // parameterized over `'r`.
+    type Database = Any;
+}
+
+fn main() {}
diff --git a/tests/ui/traits/new-solver/specialization-transmute.rs b/tests/ui/traits/new-solver/specialization-transmute.rs
index f6b19e7adf5..fac7d76f8cf 100644
--- a/tests/ui/traits/new-solver/specialization-transmute.rs
+++ b/tests/ui/traits/new-solver/specialization-transmute.rs
@@ -10,7 +10,7 @@ trait Default {
 }
 
 impl<T> Default for T {
-    default type Id = T;
+    default type Id = T; //~ ERROR type annotations needed
     // This will be fixed by #111994
     fn intu(&self) -> &Self::Id { //~ ERROR type annotations needed
         self
diff --git a/tests/ui/traits/new-solver/specialization-transmute.stderr b/tests/ui/traits/new-solver/specialization-transmute.stderr
index 09b1405fefb..18965a465b3 100644
--- a/tests/ui/traits/new-solver/specialization-transmute.stderr
+++ b/tests/ui/traits/new-solver/specialization-transmute.stderr
@@ -16,6 +16,13 @@ LL |     fn intu(&self) -> &Self::Id {
    |
    = note: cannot satisfy `<T as Default>::Id == _`
 
-error: aborting due to previous error; 1 warning emitted
+error[E0282]: type annotations needed
+  --> $DIR/specialization-transmute.rs:13:23
+   |
+LL |     default type Id = T;
+   |                       ^ cannot infer type for associated type `<T as Default>::Id`
+
+error: aborting due to 2 previous errors; 1 warning emitted
 
-For more information about this error, try `rustc --explain E0284`.
+Some errors have detailed explanations: E0282, E0284.
+For more information about an error, try `rustc --explain E0282`.
diff --git a/tests/ui/traits/new-solver/specialization-unconstrained.rs b/tests/ui/traits/new-solver/specialization-unconstrained.rs
index 02150689ee5..7fd753109be 100644
--- a/tests/ui/traits/new-solver/specialization-unconstrained.rs
+++ b/tests/ui/traits/new-solver/specialization-unconstrained.rs
@@ -11,7 +11,7 @@ trait Default {
 }
 
 impl<T> Default for T {
-   default type Id = T;
+   default type Id = T; //~ ERROR type annotations needed
 }
 
 fn test<T: Default<Id = U>, U>() {}
diff --git a/tests/ui/traits/new-solver/specialization-unconstrained.stderr b/tests/ui/traits/new-solver/specialization-unconstrained.stderr
index 910925cbaeb..ed4dafa1484 100644
--- a/tests/ui/traits/new-solver/specialization-unconstrained.stderr
+++ b/tests/ui/traits/new-solver/specialization-unconstrained.stderr
@@ -20,6 +20,13 @@ note: required by a bound in `test`
 LL | fn test<T: Default<Id = U>, U>() {}
    |                    ^^^^^^ required by this bound in `test`
 
-error: aborting due to previous error; 1 warning emitted
+error[E0282]: type annotations needed
+  --> $DIR/specialization-unconstrained.rs:14:22
+   |
+LL |    default type Id = T;
+   |                      ^ cannot infer type for associated type `<T as Default>::Id`
+
+error: aborting due to 2 previous errors; 1 warning emitted
 
-For more information about this error, try `rustc --explain E0284`.
+Some errors have detailed explanations: E0282, E0284.
+For more information about an error, try `rustc --explain E0282`.