summaryrefslogtreecommitdiffstats
path: root/src/test/ui/inference/need_type_info
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/inference/need_type_info
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/inference/need_type_info')
-rw-r--r--src/test/ui/inference/need_type_info/channel.rs19
-rw-r--r--src/test/ui/inference/need_type_info/channel.stderr25
-rw-r--r--src/test/ui/inference/need_type_info/concrete-impl.rs16
-rw-r--r--src/test/ui/inference/need_type_info/concrete-impl.stderr33
-rw-r--r--src/test/ui/inference/need_type_info/expr-struct-type-relative-enum.rs21
-rw-r--r--src/test/ui/inference/need_type_info/expr-struct-type-relative-enum.stderr14
-rw-r--r--src/test/ui/inference/need_type_info/expr-struct-type-relative-gat.rs21
-rw-r--r--src/test/ui/inference/need_type_info/expr-struct-type-relative-gat.stderr9
-rw-r--r--src/test/ui/inference/need_type_info/expr-struct-type-relative.rs21
-rw-r--r--src/test/ui/inference/need_type_info/expr-struct-type-relative.stderr14
-rw-r--r--src/test/ui/inference/need_type_info/self-ty-in-path.rs13
-rw-r--r--src/test/ui/inference/need_type_info/self-ty-in-path.stderr14
-rw-r--r--src/test/ui/inference/need_type_info/type-alias-indirect.rs18
-rw-r--r--src/test/ui/inference/need_type_info/type-alias-indirect.stderr9
-rw-r--r--src/test/ui/inference/need_type_info/type-alias.rs36
-rw-r--r--src/test/ui/inference/need_type_info/type-alias.stderr15
16 files changed, 298 insertions, 0 deletions
diff --git a/src/test/ui/inference/need_type_info/channel.rs b/src/test/ui/inference/need_type_info/channel.rs
new file mode 100644
index 000000000..e2ba5a941
--- /dev/null
+++ b/src/test/ui/inference/need_type_info/channel.rs
@@ -0,0 +1,19 @@
+// Test that we suggest specifying the generic argument of `channel`
+// instead of the return type of that function, which is a lot more
+// complex.
+use std::sync::mpsc::channel;
+
+fn no_tuple() {
+ let _data =
+ channel(); //~ ERROR type annotations needed
+}
+
+fn tuple() {
+ let (_sender, _receiver) =
+ channel(); //~ ERROR type annotations needed
+}
+
+fn main() {
+ no_tuple();
+ tuple();
+}
diff --git a/src/test/ui/inference/need_type_info/channel.stderr b/src/test/ui/inference/need_type_info/channel.stderr
new file mode 100644
index 000000000..e33ace033
--- /dev/null
+++ b/src/test/ui/inference/need_type_info/channel.stderr
@@ -0,0 +1,25 @@
+error[E0282]: type annotations needed
+ --> $DIR/channel.rs:8:9
+ |
+LL | channel();
+ | ^^^^^^^ cannot infer type of the type parameter `T` declared on the function `channel`
+ |
+help: consider specifying the generic argument
+ |
+LL | channel::<T>();
+ | +++++
+
+error[E0282]: type annotations needed
+ --> $DIR/channel.rs:13:9
+ |
+LL | channel();
+ | ^^^^^^^ cannot infer type of the type parameter `T` declared on the function `channel`
+ |
+help: consider specifying the generic argument
+ |
+LL | channel::<T>();
+ | +++++
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0282`.
diff --git a/src/test/ui/inference/need_type_info/concrete-impl.rs b/src/test/ui/inference/need_type_info/concrete-impl.rs
new file mode 100644
index 000000000..72e0e74f3
--- /dev/null
+++ b/src/test/ui/inference/need_type_info/concrete-impl.rs
@@ -0,0 +1,16 @@
+trait Ambiguous<A> {
+ fn method() {}
+}
+
+struct One;
+struct Two;
+struct Struct;
+
+impl Ambiguous<One> for Struct {}
+impl Ambiguous<Two> for Struct {}
+
+fn main() {
+ <Struct as Ambiguous<_>>::method();
+ //~^ ERROR type annotations needed
+ //~| ERROR type annotations needed
+}
diff --git a/src/test/ui/inference/need_type_info/concrete-impl.stderr b/src/test/ui/inference/need_type_info/concrete-impl.stderr
new file mode 100644
index 000000000..b79d34aff
--- /dev/null
+++ b/src/test/ui/inference/need_type_info/concrete-impl.stderr
@@ -0,0 +1,33 @@
+error[E0282]: type annotations needed
+ --> $DIR/concrete-impl.rs:13:5
+ |
+LL | <Struct as Ambiguous<_>>::method();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `Self` declared on the trait `Ambiguous`
+ |
+help: consider specifying the generic argument
+ |
+LL | <Struct as Ambiguous::<_>>::method();
+ | ~~~~~
+
+error[E0283]: type annotations needed
+ --> $DIR/concrete-impl.rs:13:5
+ |
+LL | <Struct as Ambiguous<_>>::method();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `Self` declared on the trait `Ambiguous`
+ |
+note: multiple `impl`s satisfying `Struct: Ambiguous<_>` found
+ --> $DIR/concrete-impl.rs:9:1
+ |
+LL | impl Ambiguous<One> for Struct {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | impl Ambiguous<Two> for Struct {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+help: consider specifying the generic argument
+ |
+LL | <Struct as Ambiguous::<_>>::method();
+ | ~~~~~
+
+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/src/test/ui/inference/need_type_info/expr-struct-type-relative-enum.rs b/src/test/ui/inference/need_type_info/expr-struct-type-relative-enum.rs
new file mode 100644
index 000000000..42af9fa8d
--- /dev/null
+++ b/src/test/ui/inference/need_type_info/expr-struct-type-relative-enum.rs
@@ -0,0 +1,21 @@
+trait Foo {
+ type Output;
+
+ fn baz() -> Self::Output;
+}
+
+fn needs_infer<T>() {}
+
+enum Bar {
+ Variant {}
+}
+
+impl Foo for u8 {
+ type Output = Bar;
+ fn baz() -> Self::Output {
+ needs_infer(); //~ ERROR type annotations needed
+ Self::Output::Variant {}
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/inference/need_type_info/expr-struct-type-relative-enum.stderr b/src/test/ui/inference/need_type_info/expr-struct-type-relative-enum.stderr
new file mode 100644
index 000000000..68ecb3813
--- /dev/null
+++ b/src/test/ui/inference/need_type_info/expr-struct-type-relative-enum.stderr
@@ -0,0 +1,14 @@
+error[E0282]: type annotations needed
+ --> $DIR/expr-struct-type-relative-enum.rs:16:9
+ |
+LL | needs_infer();
+ | ^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `needs_infer`
+ |
+help: consider specifying the generic argument
+ |
+LL | needs_infer::<T>();
+ | +++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0282`.
diff --git a/src/test/ui/inference/need_type_info/expr-struct-type-relative-gat.rs b/src/test/ui/inference/need_type_info/expr-struct-type-relative-gat.rs
new file mode 100644
index 000000000..bcd29bb4e
--- /dev/null
+++ b/src/test/ui/inference/need_type_info/expr-struct-type-relative-gat.rs
@@ -0,0 +1,21 @@
+#![feature(generic_associated_types)]
+
+trait Foo {
+ type Output<T>;
+
+ fn baz();
+}
+
+enum Bar<T> {
+ Simple {},
+ Generic(T),
+}
+
+impl Foo for u8 {
+ type Output<T> = Bar<T>;
+ fn baz() {
+ Self::Output::Simple {}; //~ ERROR type annotations needed
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/inference/need_type_info/expr-struct-type-relative-gat.stderr b/src/test/ui/inference/need_type_info/expr-struct-type-relative-gat.stderr
new file mode 100644
index 000000000..65a75b68c
--- /dev/null
+++ b/src/test/ui/inference/need_type_info/expr-struct-type-relative-gat.stderr
@@ -0,0 +1,9 @@
+error[E0282]: type annotations needed
+ --> $DIR/expr-struct-type-relative-gat.rs:17:9
+ |
+LL | Self::Output::Simple {};
+ | ^^^^^^^^^^^^ cannot infer type for type parameter `T` declared on the associated type `Output`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0282`.
diff --git a/src/test/ui/inference/need_type_info/expr-struct-type-relative.rs b/src/test/ui/inference/need_type_info/expr-struct-type-relative.rs
new file mode 100644
index 000000000..c3ece2b16
--- /dev/null
+++ b/src/test/ui/inference/need_type_info/expr-struct-type-relative.rs
@@ -0,0 +1,21 @@
+// regression test for #98598
+
+trait Foo {
+ type Output;
+
+ fn baz() -> Self::Output;
+}
+
+fn needs_infer<T>() {}
+
+struct Bar {}
+
+impl Foo for u8 {
+ type Output = Bar;
+ fn baz() -> Self::Output {
+ needs_infer(); //~ ERROR type annotations needed
+ Self::Output {}
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/inference/need_type_info/expr-struct-type-relative.stderr b/src/test/ui/inference/need_type_info/expr-struct-type-relative.stderr
new file mode 100644
index 000000000..397d8e7be
--- /dev/null
+++ b/src/test/ui/inference/need_type_info/expr-struct-type-relative.stderr
@@ -0,0 +1,14 @@
+error[E0282]: type annotations needed
+ --> $DIR/expr-struct-type-relative.rs:16:9
+ |
+LL | needs_infer();
+ | ^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `needs_infer`
+ |
+help: consider specifying the generic argument
+ |
+LL | needs_infer::<T>();
+ | +++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0282`.
diff --git a/src/test/ui/inference/need_type_info/self-ty-in-path.rs b/src/test/ui/inference/need_type_info/self-ty-in-path.rs
new file mode 100644
index 000000000..768a8cc37
--- /dev/null
+++ b/src/test/ui/inference/need_type_info/self-ty-in-path.rs
@@ -0,0 +1,13 @@
+// Test that we don't ICE when encountering a `Self` in a path.
+struct TestErr<T>(T);
+
+impl<T> TestErr<T> {
+ fn func_a<U>() {}
+
+ fn func_b() {
+ Self::func_a();
+ //~^ ERROR type annotations needed
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/inference/need_type_info/self-ty-in-path.stderr b/src/test/ui/inference/need_type_info/self-ty-in-path.stderr
new file mode 100644
index 000000000..04b521dbd
--- /dev/null
+++ b/src/test/ui/inference/need_type_info/self-ty-in-path.stderr
@@ -0,0 +1,14 @@
+error[E0282]: type annotations needed
+ --> $DIR/self-ty-in-path.rs:8:9
+ |
+LL | Self::func_a();
+ | ^^^^^^^^^^^^ cannot infer type of the type parameter `U` declared on the associated function `func_a`
+ |
+help: consider specifying the generic argument
+ |
+LL | Self::func_a::<U>();
+ | +++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0282`.
diff --git a/src/test/ui/inference/need_type_info/type-alias-indirect.rs b/src/test/ui/inference/need_type_info/type-alias-indirect.rs
new file mode 100644
index 000000000..0ed02ddc5
--- /dev/null
+++ b/src/test/ui/inference/need_type_info/type-alias-indirect.rs
@@ -0,0 +1,18 @@
+// An addition to the `type-alias.rs` test,
+// see the FIXME in that file for why this test
+// exists.
+//
+// If there is none, feel free to remove this test
+// again.
+struct Ty<T>(T);
+impl<T> Ty<T> {
+ fn new() {}
+}
+
+type IndirectAlias<T> = Ty<Box<T>>;
+fn indirect_alias() {
+ IndirectAlias::new();
+ //~^ ERROR type annotations needed
+}
+
+fn main() {}
diff --git a/src/test/ui/inference/need_type_info/type-alias-indirect.stderr b/src/test/ui/inference/need_type_info/type-alias-indirect.stderr
new file mode 100644
index 000000000..6161690df
--- /dev/null
+++ b/src/test/ui/inference/need_type_info/type-alias-indirect.stderr
@@ -0,0 +1,9 @@
+error[E0282]: type annotations needed
+ --> $DIR/type-alias-indirect.rs:14:5
+ |
+LL | IndirectAlias::new();
+ | ^^^^^^^^^^^^^ cannot infer type for type parameter `T` declared on the type alias `IndirectAlias`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0282`.
diff --git a/src/test/ui/inference/need_type_info/type-alias.rs b/src/test/ui/inference/need_type_info/type-alias.rs
new file mode 100644
index 000000000..f921b046b
--- /dev/null
+++ b/src/test/ui/inference/need_type_info/type-alias.rs
@@ -0,0 +1,36 @@
+// Test the inference errors in case the relevant path
+// uses a type alias.
+//
+// Regression test for #97698.
+struct Ty<T>(T);
+impl<T> Ty<T> {
+ fn new() {}
+}
+
+type DirectAlias<T> = Ty<T>;
+fn direct_alias() {
+ DirectAlias::new()
+ //~^ ERROR type annotations needed
+}
+
+type IndirectAlias<T> = Ty<Box<T>>;
+fn indirect_alias() {
+ IndirectAlias::new();
+ // FIXME: This should also emit an error.
+ //
+ // Added it separately as `type-alias-indirect.rs`
+ // where it does error.
+}
+
+struct TyDefault<T, U = u32>(T, U);
+impl<T> TyDefault<T> {
+ fn new() {}
+}
+
+type DirectButWithDefaultAlias<T> = TyDefault<T>;
+fn direct_but_with_default_alias() {
+ DirectButWithDefaultAlias::new();
+ //~^ ERROR type annotations needed
+}
+
+fn main() {}
diff --git a/src/test/ui/inference/need_type_info/type-alias.stderr b/src/test/ui/inference/need_type_info/type-alias.stderr
new file mode 100644
index 000000000..a33f49baf
--- /dev/null
+++ b/src/test/ui/inference/need_type_info/type-alias.stderr
@@ -0,0 +1,15 @@
+error[E0282]: type annotations needed
+ --> $DIR/type-alias.rs:12:5
+ |
+LL | DirectAlias::new()
+ | ^^^^^^^^^^^^^^^^ cannot infer type for type parameter `T`
+
+error[E0282]: type annotations needed
+ --> $DIR/type-alias.rs:32:5
+ |
+LL | DirectButWithDefaultAlias::new();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `T`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0282`.