From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- src/test/ui/inference/need_type_info/channel.rs | 19 ++++++++++++ .../ui/inference/need_type_info/channel.stderr | 25 +++++++++++++++ .../ui/inference/need_type_info/concrete-impl.rs | 16 ++++++++++ .../inference/need_type_info/concrete-impl.stderr | 33 ++++++++++++++++++++ .../expr-struct-type-relative-enum.rs | 21 +++++++++++++ .../expr-struct-type-relative-enum.stderr | 14 +++++++++ .../expr-struct-type-relative-gat.rs | 21 +++++++++++++ .../expr-struct-type-relative-gat.stderr | 9 ++++++ .../need_type_info/expr-struct-type-relative.rs | 21 +++++++++++++ .../expr-struct-type-relative.stderr | 14 +++++++++ .../ui/inference/need_type_info/self-ty-in-path.rs | 13 ++++++++ .../need_type_info/self-ty-in-path.stderr | 14 +++++++++ .../need_type_info/type-alias-indirect.rs | 18 +++++++++++ .../need_type_info/type-alias-indirect.stderr | 9 ++++++ src/test/ui/inference/need_type_info/type-alias.rs | 36 ++++++++++++++++++++++ .../ui/inference/need_type_info/type-alias.stderr | 15 +++++++++ 16 files changed, 298 insertions(+) create mode 100644 src/test/ui/inference/need_type_info/channel.rs create mode 100644 src/test/ui/inference/need_type_info/channel.stderr create mode 100644 src/test/ui/inference/need_type_info/concrete-impl.rs create mode 100644 src/test/ui/inference/need_type_info/concrete-impl.stderr create mode 100644 src/test/ui/inference/need_type_info/expr-struct-type-relative-enum.rs create mode 100644 src/test/ui/inference/need_type_info/expr-struct-type-relative-enum.stderr create mode 100644 src/test/ui/inference/need_type_info/expr-struct-type-relative-gat.rs create mode 100644 src/test/ui/inference/need_type_info/expr-struct-type-relative-gat.stderr create mode 100644 src/test/ui/inference/need_type_info/expr-struct-type-relative.rs create mode 100644 src/test/ui/inference/need_type_info/expr-struct-type-relative.stderr create mode 100644 src/test/ui/inference/need_type_info/self-ty-in-path.rs create mode 100644 src/test/ui/inference/need_type_info/self-ty-in-path.stderr create mode 100644 src/test/ui/inference/need_type_info/type-alias-indirect.rs create mode 100644 src/test/ui/inference/need_type_info/type-alias-indirect.stderr create mode 100644 src/test/ui/inference/need_type_info/type-alias.rs create mode 100644 src/test/ui/inference/need_type_info/type-alias.stderr (limited to 'src/test/ui/inference/need_type_info') 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::(); + | +++++ + +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::(); + | +++++ + +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 { + fn method() {} +} + +struct One; +struct Two; +struct Struct; + +impl Ambiguous for Struct {} +impl Ambiguous for Struct {} + +fn main() { + >::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 | >::method(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `Self` declared on the trait `Ambiguous` + | +help: consider specifying the generic argument + | +LL | >::method(); + | ~~~~~ + +error[E0283]: type annotations needed + --> $DIR/concrete-impl.rs:13:5 + | +LL | >::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 for Struct {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | impl Ambiguous for Struct {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +help: consider specifying the generic argument + | +LL | >::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() {} + +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::(); + | +++++ + +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; + + fn baz(); +} + +enum Bar { + Simple {}, + Generic(T), +} + +impl Foo for u8 { + type Output = Bar; + 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() {} + +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::(); + | +++++ + +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); + +impl TestErr { + fn func_a() {} + + 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::(); + | +++++ + +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); +impl Ty { + fn new() {} +} + +type IndirectAlias = Ty>; +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); +impl Ty { + fn new() {} +} + +type DirectAlias = Ty; +fn direct_alias() { + DirectAlias::new() + //~^ ERROR type annotations needed +} + +type IndirectAlias = Ty>; +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); +impl TyDefault { + fn new() {} +} + +type DirectButWithDefaultAlias = TyDefault; +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`. -- cgit v1.2.3