about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>2022-06-11 07:42:13 +0200
committerGitHub <noreply@github.com>2022-06-11 07:42:13 +0200
commit59c2ff532d588d5268256578982e5c2cf7d15dad (patch)
treea8c94e6ec077546f7295ed2df3abdf337987137c /src/test
parentf1f44b9e4d405f9361ee5ade3e0656b34d9bd1b1 (diff)
parentd6b28f377cedada86c67cedc28fee4c925841a6d (diff)
downloadrust-59c2ff532d588d5268256578982e5c2cf7d15dad.tar.gz
rust-59c2ff532d588d5268256578982e5c2cf7d15dad.zip
Rollup merge of #97703 - lcnr:post-89862, r=estebank
some additional `need_type_info.rs` cleanup

also fixes #97698, fixes #97806

cc `@estebank`
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/const-generics/defaults/rp_impl_trait_fail.rs4
-rw-r--r--src/test/ui/const-generics/defaults/rp_impl_trait_fail.stderr8
-rw-r--r--src/test/ui/const-generics/defaults/trait_objects_fail.rs2
-rw-r--r--src/test/ui/const-generics/defaults/trait_objects_fail.stderr6
-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/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
12 files changed, 164 insertions, 10 deletions
diff --git a/src/test/ui/const-generics/defaults/rp_impl_trait_fail.rs b/src/test/ui/const-generics/defaults/rp_impl_trait_fail.rs
index 308c121a941..f633e56b0ec 100644
--- a/src/test/ui/const-generics/defaults/rp_impl_trait_fail.rs
+++ b/src/test/ui/const-generics/defaults/rp_impl_trait_fail.rs
@@ -15,12 +15,12 @@ impl Traitor<1, 2> for u64 {}
 
 
 fn uwu<const N: u8>() -> impl Traitor<N> {
-    //~^ error: the trait bound `u32: Traitor<N, N>` is not satisfied
+    //~^ error: the trait bound `u32: Traitor<N>` is not satisfied
     1_u32
 }
 
 fn owo() -> impl Traitor {
-    //~^ error: the trait bound `u64: Traitor<1_u8, 1_u8>` is not satisfied
+    //~^ error: the trait bound `u64: Traitor` is not satisfied
     1_u64
 }
 
diff --git a/src/test/ui/const-generics/defaults/rp_impl_trait_fail.stderr b/src/test/ui/const-generics/defaults/rp_impl_trait_fail.stderr
index 8031da28ca1..cbe4a4ac0d6 100644
--- a/src/test/ui/const-generics/defaults/rp_impl_trait_fail.stderr
+++ b/src/test/ui/const-generics/defaults/rp_impl_trait_fail.stderr
@@ -6,21 +6,21 @@ LL | fn rawr() -> impl Trait {
    |
    = help: the trait `Trait` is implemented for `Uwu<N>`
 
-error[E0277]: the trait bound `u32: Traitor<N, N>` is not satisfied
+error[E0277]: the trait bound `u32: Traitor<N>` is not satisfied
   --> $DIR/rp_impl_trait_fail.rs:17:26
    |
 LL | fn uwu<const N: u8>() -> impl Traitor<N> {
-   |                          ^^^^^^^^^^^^^^^ the trait `Traitor<N, N>` is not implemented for `u32`
+   |                          ^^^^^^^^^^^^^^^ the trait `Traitor<N>` is not implemented for `u32`
    |
    = help: the following other types implement trait `Traitor<N, M>`:
              <u32 as Traitor<N, 2_u8>>
              <u64 as Traitor<1_u8, 2_u8>>
 
-error[E0277]: the trait bound `u64: Traitor<1_u8, 1_u8>` is not satisfied
+error[E0277]: the trait bound `u64: Traitor` is not satisfied
   --> $DIR/rp_impl_trait_fail.rs:22:13
    |
 LL | fn owo() -> impl Traitor {
-   |             ^^^^^^^^^^^^ the trait `Traitor<1_u8, 1_u8>` is not implemented for `u64`
+   |             ^^^^^^^^^^^^ the trait `Traitor` is not implemented for `u64`
    |
    = help: the following other types implement trait `Traitor<N, M>`:
              <u32 as Traitor<N, 2_u8>>
diff --git a/src/test/ui/const-generics/defaults/trait_objects_fail.rs b/src/test/ui/const-generics/defaults/trait_objects_fail.rs
index 7ba12d02b6e..5e779d2e8de 100644
--- a/src/test/ui/const-generics/defaults/trait_objects_fail.rs
+++ b/src/test/ui/const-generics/defaults/trait_objects_fail.rs
@@ -26,5 +26,5 @@ fn main() {
     foo(&10_u32);
     //~^ error: the trait bound `u32: Trait` is not satisfied
     bar(&true);
-    //~^ error: the trait bound `bool: Traitor<{_: u8}, {_: u8}>` is not satisfied
+    //~^ error: the trait bound `bool: Traitor<{_: u8}>` is not satisfied
 }
diff --git a/src/test/ui/const-generics/defaults/trait_objects_fail.stderr b/src/test/ui/const-generics/defaults/trait_objects_fail.stderr
index 7f8a1f742d8..60dc96f675a 100644
--- a/src/test/ui/const-generics/defaults/trait_objects_fail.stderr
+++ b/src/test/ui/const-generics/defaults/trait_objects_fail.stderr
@@ -9,16 +9,16 @@ LL |     foo(&10_u32);
    = help: the trait `Trait<2_u8>` is implemented for `u32`
    = note: required for the cast to the object type `dyn Trait`
 
-error[E0277]: the trait bound `bool: Traitor<{_: u8}, {_: u8}>` is not satisfied
+error[E0277]: the trait bound `bool: Traitor<{_: u8}>` is not satisfied
   --> $DIR/trait_objects_fail.rs:28:9
    |
 LL |     bar(&true);
-   |     --- ^^^^^ the trait `Traitor<{_: u8}, {_: u8}>` is not implemented for `bool`
+   |     --- ^^^^^ the trait `Traitor<{_: u8}>` is not implemented for `bool`
    |     |
    |     required by a bound introduced by this call
    |
    = help: the trait `Traitor<2_u8, 3_u8>` is implemented for `bool`
-   = note: required for the cast to the object type `dyn Traitor<{_: u8}, {_: u8}>`
+   = note: required for the cast to the object type `dyn Traitor<{_: u8}>`
 
 error: aborting due to 2 previous errors
 
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 00000000000..72e0e74f323
--- /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 00000000000..b79d34affa2
--- /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/self-ty-in-path.rs b/src/test/ui/inference/need_type_info/self-ty-in-path.rs
new file mode 100644
index 00000000000..768a8cc3778
--- /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 00000000000..04b521dbdb3
--- /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 00000000000..0ed02ddc5f3
--- /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 00000000000..6161690df50
--- /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 00000000000..f921b046b6c
--- /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 00000000000..a33f49baf54
--- /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`.