about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>2022-11-22 16:36:36 +0530
committerGitHub <noreply@github.com>2022-11-22 16:36:36 +0530
commit680ba90f9698741dab669c8151acb8d022d06617 (patch)
tree430945ced3e669e3d57f16eee0b9161b55cc7b02 /src
parenta78c9bee4d9d51a3891bd8ecae1f28a93b83653b (diff)
parentdf5f247a5c5432fc85a84cafb8461fafd01cf6ae (diff)
downloadrust-680ba90f9698741dab669c8151acb8d022d06617.tar.gz
rust-680ba90f9698741dab669c8151acb8d022d06617.zip
Rollup merge of #104295 - compiler-errors:rpitit-generics-parity, r=eholk
Check generics parity before collecting return-position `impl Trait`s in trait

The only thing is that this duplicates the error message for number of generics mismatch, but we already deduplicate that error message in Cargo. I could add a flag to delay the error if the reviewer cares.

Fixes #104281

Also drive-by adds a few comments to the `collect_trait_impl_trait_tys` method, and removes an unused argument from `compare_number_of_generics`.
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/impl-trait/in-trait/trait-more-generics-than-impl.rs17
-rw-r--r--src/test/ui/impl-trait/in-trait/trait-more-generics-than-impl.stderr12
2 files changed, 29 insertions, 0 deletions
diff --git a/src/test/ui/impl-trait/in-trait/trait-more-generics-than-impl.rs b/src/test/ui/impl-trait/in-trait/trait-more-generics-than-impl.rs
new file mode 100644
index 00000000000..0bbe50ea6fd
--- /dev/null
+++ b/src/test/ui/impl-trait/in-trait/trait-more-generics-than-impl.rs
@@ -0,0 +1,17 @@
+#![feature(return_position_impl_trait_in_trait)]
+#![allow(incomplete_features)]
+
+struct S;
+
+trait Foo {
+    fn bar<T>() -> impl Sized;
+}
+
+impl Foo for S {
+    fn bar() -> impl Sized {}
+    //~^ ERROR method `bar` has 0 type parameters but its trait declaration has 1 type parameter
+}
+
+fn main() {
+    S::bar();
+}
diff --git a/src/test/ui/impl-trait/in-trait/trait-more-generics-than-impl.stderr b/src/test/ui/impl-trait/in-trait/trait-more-generics-than-impl.stderr
new file mode 100644
index 00000000000..8ff54cad951
--- /dev/null
+++ b/src/test/ui/impl-trait/in-trait/trait-more-generics-than-impl.stderr
@@ -0,0 +1,12 @@
+error[E0049]: method `bar` has 0 type parameters but its trait declaration has 1 type parameter
+  --> $DIR/trait-more-generics-than-impl.rs:11:11
+   |
+LL |     fn bar<T>() -> impl Sized;
+   |            - expected 1 type parameter
+...
+LL |     fn bar() -> impl Sized {}
+   |           ^ found 0 type parameters
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0049`.