about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2023-07-06 20:11:41 -0700
committerGitHub <noreply@github.com>2023-07-06 20:11:41 -0700
commit901c86364431f62dbe3f88936e2eeb0d48e43fd8 (patch)
tree55aeb62462283cd39784b57a110673aec2f5ab40
parentf1c90985e87f2b144b065b4383ab56657749c372 (diff)
parentc0c155137b7a80452213ffbf991c52b0faa5025b (diff)
downloadrust-901c86364431f62dbe3f88936e2eeb0d48e43fd8.tar.gz
rust-901c86364431f62dbe3f88936e2eeb0d48e43fd8.zip
Rollup merge of #113419 - spastorino:new-rpitit-28, r=compiler-errors
Avoid calling item_name for RPITIT

Fixes #113405

r? `@compiler-errors`
-rw-r--r--compiler/rustc_infer/src/traits/error_reporting/mod.rs8
-rw-r--r--tests/ui/async-await/in-trait/return-not-existing-pair.current.stderr39
-rw-r--r--tests/ui/async-await/in-trait/return-not-existing-pair.next.stderr39
-rw-r--r--tests/ui/async-await/in-trait/return-not-existing-pair.rs19
4 files changed, 102 insertions, 3 deletions
diff --git a/compiler/rustc_infer/src/traits/error_reporting/mod.rs b/compiler/rustc_infer/src/traits/error_reporting/mod.rs
index b5a7d0326a8..9f440f39849 100644
--- a/compiler/rustc_infer/src/traits/error_reporting/mod.rs
+++ b/compiler/rustc_infer/src/traits/error_reporting/mod.rs
@@ -25,9 +25,11 @@ impl<'tcx> InferCtxt<'tcx> {
             "impl has stricter requirements than trait"
         );
 
-        if let Some(span) = self.tcx.hir().span_if_local(trait_item_def_id) {
-            let item_name = self.tcx.item_name(impl_item_def_id.to_def_id());
-            err.span_label(span, format!("definition of `{}` from trait", item_name));
+        if !self.tcx.is_impl_trait_in_trait(trait_item_def_id) {
+            if let Some(span) = self.tcx.hir().span_if_local(trait_item_def_id) {
+                let item_name = self.tcx.item_name(impl_item_def_id.to_def_id());
+                err.span_label(span, format!("definition of `{}` from trait", item_name));
+            }
         }
 
         err.span_label(error_span, format!("impl has extra requirement {}", requirement));
diff --git a/tests/ui/async-await/in-trait/return-not-existing-pair.current.stderr b/tests/ui/async-await/in-trait/return-not-existing-pair.current.stderr
new file mode 100644
index 00000000000..56973a1d11a
--- /dev/null
+++ b/tests/ui/async-await/in-trait/return-not-existing-pair.current.stderr
@@ -0,0 +1,39 @@
+error[E0726]: implicit elided lifetime not allowed here
+  --> $DIR/return-not-existing-pair.rs:12:20
+   |
+LL | impl<'a, 'b, T, U> MyTrait<T> for U {
+   |                    ^^^^^^^^^^ expected lifetime parameters
+   |
+help: indicate the anonymous lifetimes
+   |
+LL | impl<'a, 'b, T, U> MyTrait<'_, '_, T> for U {
+   |                            +++++++
+
+error[E0412]: cannot find type `ConnImpl` in this scope
+  --> $DIR/return-not-existing-pair.rs:8:48
+   |
+LL |     async fn foo(&'a self, key: &'b T) -> (&'a ConnImpl, &'b T);
+   |                                                ^^^^^^^^ not found in this scope
+
+error[E0186]: method `foo` has a `&self` declaration in the trait, but not in the impl
+  --> $DIR/return-not-existing-pair.rs:14:5
+   |
+LL |     async fn foo(&'a self, key: &'b T) -> (&'a ConnImpl, &'b T);
+   |     ------------------------------------------------------------ `&self` used in trait
+...
+LL |     async fn foo(_: T) -> (&'a U, &'b T) {}
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&self` in impl
+
+error[E0308]: mismatched types
+  --> $DIR/return-not-existing-pair.rs:14:42
+   |
+LL |     async fn foo(_: T) -> (&'a U, &'b T) {}
+   |                                          ^^ expected `(&U, &T)`, found `()`
+   |
+   = note:  expected tuple `(&'a U, &'b T)`
+           found unit type `()`
+
+error: aborting due to 4 previous errors
+
+Some errors have detailed explanations: E0186, E0308, E0412, E0726.
+For more information about an error, try `rustc --explain E0186`.
diff --git a/tests/ui/async-await/in-trait/return-not-existing-pair.next.stderr b/tests/ui/async-await/in-trait/return-not-existing-pair.next.stderr
new file mode 100644
index 00000000000..56973a1d11a
--- /dev/null
+++ b/tests/ui/async-await/in-trait/return-not-existing-pair.next.stderr
@@ -0,0 +1,39 @@
+error[E0726]: implicit elided lifetime not allowed here
+  --> $DIR/return-not-existing-pair.rs:12:20
+   |
+LL | impl<'a, 'b, T, U> MyTrait<T> for U {
+   |                    ^^^^^^^^^^ expected lifetime parameters
+   |
+help: indicate the anonymous lifetimes
+   |
+LL | impl<'a, 'b, T, U> MyTrait<'_, '_, T> for U {
+   |                            +++++++
+
+error[E0412]: cannot find type `ConnImpl` in this scope
+  --> $DIR/return-not-existing-pair.rs:8:48
+   |
+LL |     async fn foo(&'a self, key: &'b T) -> (&'a ConnImpl, &'b T);
+   |                                                ^^^^^^^^ not found in this scope
+
+error[E0186]: method `foo` has a `&self` declaration in the trait, but not in the impl
+  --> $DIR/return-not-existing-pair.rs:14:5
+   |
+LL |     async fn foo(&'a self, key: &'b T) -> (&'a ConnImpl, &'b T);
+   |     ------------------------------------------------------------ `&self` used in trait
+...
+LL |     async fn foo(_: T) -> (&'a U, &'b T) {}
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&self` in impl
+
+error[E0308]: mismatched types
+  --> $DIR/return-not-existing-pair.rs:14:42
+   |
+LL |     async fn foo(_: T) -> (&'a U, &'b T) {}
+   |                                          ^^ expected `(&U, &T)`, found `()`
+   |
+   = note:  expected tuple `(&'a U, &'b T)`
+           found unit type `()`
+
+error: aborting due to 4 previous errors
+
+Some errors have detailed explanations: E0186, E0308, E0412, E0726.
+For more information about an error, try `rustc --explain E0186`.
diff --git a/tests/ui/async-await/in-trait/return-not-existing-pair.rs b/tests/ui/async-await/in-trait/return-not-existing-pair.rs
new file mode 100644
index 00000000000..d1b3832d12b
--- /dev/null
+++ b/tests/ui/async-await/in-trait/return-not-existing-pair.rs
@@ -0,0 +1,19 @@
+// edition:2021
+// [next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty
+// revisions: current next
+
+#![feature(async_fn_in_trait)]
+
+trait MyTrait<'a, 'b, T> {
+    async fn foo(&'a self, key: &'b T) -> (&'a ConnImpl, &'b T);
+    //~^ ERROR: cannot find type `ConnImpl` in this scope [E0412]
+}
+
+impl<'a, 'b, T, U> MyTrait<T> for U {
+    //~^ ERROR: implicit elided lifetime not allowed here [E0726]
+    async fn foo(_: T) -> (&'a U, &'b T) {}
+    //~^ ERROR: method `foo` has a `&self` declaration in the trait, but not in the impl [E0186]
+    //~| ERROR: mismatched types [E0308]
+}
+
+fn main() {}