about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-03-15 10:14:55 +0100
committerGitHub <noreply@github.com>2024-03-15 10:14:55 +0100
commitee940f87fce4e91a52eaa713d27d2abc8a9933d6 (patch)
treecbee48468f93c098ad41a6bf8595992aedffc948 /tests
parent42af99383a987aec281aef4e1e38220e81acfd62 (diff)
parent571f945713468f24e4f937d48828d1d8155911f2 (diff)
downloadrust-ee940f87fce4e91a52eaa713d27d2abc8a9933d6.tar.gz
rust-ee940f87fce4e91a52eaa713d27d2abc8a9933d6.zip
Rollup merge of #122523 - compiler-errors:ensure-associated-types, r=oli-obk
Ensure RPITITs are created before def-id freezing

From the test:

```rust
// `ty::Error` in a trait ref will silence any missing item errors, but will also
// prevent the `associated_items` query from being called before def ids are frozen.
```

Essentially, the code that checks that `impl`s have all their items (`check_impl_items_against_trait`) is also (implicitly) responsible for fetching the `associated_items` query before, but since we early return here:
https://github.com/rust-lang/rust/blob/c2901f543577af99b9cb708f5c0d28525eb7f08f/compiler/rustc_hir_analysis/src/check/check.rs#L732-L737
...that means that this never happens for trait refs that reference errors.

Fixes #122518
r? oli-obk
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/impl-trait/in-trait/ensure-rpitits-are-created-before-freezing.rs13
-rw-r--r--tests/ui/impl-trait/in-trait/ensure-rpitits-are-created-before-freezing.stderr9
2 files changed, 22 insertions, 0 deletions
diff --git a/tests/ui/impl-trait/in-trait/ensure-rpitits-are-created-before-freezing.rs b/tests/ui/impl-trait/in-trait/ensure-rpitits-are-created-before-freezing.rs
new file mode 100644
index 00000000000..35a6acca52c
--- /dev/null
+++ b/tests/ui/impl-trait/in-trait/ensure-rpitits-are-created-before-freezing.rs
@@ -0,0 +1,13 @@
+trait Iterable {
+    type Item;
+    fn iter(&self) -> impl Sized;
+}
+
+// `ty::Error` in a trait ref will silence any missing item errors, but will also
+// prevent the `associated_items` query from being called before def ids are frozen.
+impl Iterable for Missing {
+//~^ ERROR cannot find type `Missing` in this scope
+    fn iter(&self) -> Self::Item {}
+}
+
+fn main() {}
diff --git a/tests/ui/impl-trait/in-trait/ensure-rpitits-are-created-before-freezing.stderr b/tests/ui/impl-trait/in-trait/ensure-rpitits-are-created-before-freezing.stderr
new file mode 100644
index 00000000000..c172787e6ef
--- /dev/null
+++ b/tests/ui/impl-trait/in-trait/ensure-rpitits-are-created-before-freezing.stderr
@@ -0,0 +1,9 @@
+error[E0412]: cannot find type `Missing` in this scope
+  --> $DIR/ensure-rpitits-are-created-before-freezing.rs:8:19
+   |
+LL | impl Iterable for Missing {
+   |                   ^^^^^^^ not found in this scope
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0412`.