about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/methods/missing-bound-on-tuple.rs39
-rw-r--r--tests/ui/methods/missing-bound-on-tuple.stderr58
-rw-r--r--tests/ui/methods/tuple-suggestions-issue-142488.rs48
-rw-r--r--tests/ui/methods/tuple-suggestions-issue-142488.stderr61
-rw-r--r--tests/ui/traits/vtable/empty-supertrait-with-nonempty-supersupertrait.dump.stderr16
-rw-r--r--tests/ui/traits/vtable/empty-supertrait-with-nonempty-supersupertrait.rs49
-rw-r--r--tests/ui/traits/vtable/multiple-auto.rs50
-rw-r--r--tests/ui/traits/vtable/multiple-auto.stderr46
8 files changed, 270 insertions, 97 deletions
diff --git a/tests/ui/methods/missing-bound-on-tuple.rs b/tests/ui/methods/missing-bound-on-tuple.rs
deleted file mode 100644
index 25deabf5926..00000000000
--- a/tests/ui/methods/missing-bound-on-tuple.rs
+++ /dev/null
@@ -1,39 +0,0 @@
-trait WorksOnDefault {
-    fn do_something() {}
-}
-
-impl<T: Default> WorksOnDefault for T {}
-//~^ NOTE the following trait bounds were not satisfied
-//~| NOTE unsatisfied trait bound introduced here
-
-trait Foo {}
-
-trait WorksOnFoo {
-    fn do_be_do() {}
-}
-
-impl<T: Foo> WorksOnFoo for T {}
-//~^ NOTE the following trait bounds were not satisfied
-//~| NOTE unsatisfied trait bound introduced here
-
-impl<A: Foo, B: Foo, C: Foo> Foo for (A, B, C) {}
-//~^ NOTE `Foo` is implemented for `(i32, u32, String)`
-impl Foo for i32 {}
-impl Foo for &i32 {}
-impl Foo for u32 {}
-impl Foo for String {}
-
-fn main() {
-    let _success = <(i32, u32, String)>::do_something();
-    let _failure = <(i32, &u32, String)>::do_something(); //~ ERROR E0599
-    //~^ NOTE `Default` is implemented for `(i32, u32, String)`
-    //~| NOTE function or associated item cannot be called on
-    let _success = <(i32, u32, String)>::do_be_do();
-    let _failure = <(i32, &u32, String)>::do_be_do(); //~ ERROR E0599
-    //~^ NOTE function or associated item cannot be called on
-    let _success = <(i32, u32, String)>::default();
-    let _failure = <(i32, &u32, String)>::default(); //~ ERROR E0599
-    //~^ NOTE `Default` is implemented for `(i32, u32, String)`
-    //~| NOTE function or associated item cannot be called on
-    //~| NOTE the following trait bounds were not satisfied
-}
diff --git a/tests/ui/methods/missing-bound-on-tuple.stderr b/tests/ui/methods/missing-bound-on-tuple.stderr
deleted file mode 100644
index f3e0897e5e6..00000000000
--- a/tests/ui/methods/missing-bound-on-tuple.stderr
+++ /dev/null
@@ -1,58 +0,0 @@
-error[E0599]: the function or associated item `do_something` exists for tuple `(i32, &u32, String)`, but its trait bounds were not satisfied
-  --> $DIR/missing-bound-on-tuple.rs:28:43
-   |
-LL |     let _failure = <(i32, &u32, String)>::do_something();
-   |                                           ^^^^^^^^^^^^ function or associated item cannot be called on `(i32, &u32, String)` due to unsatisfied trait bounds
-   |
-note: the following trait bounds were not satisfied:
-      `&(i32, &u32, String): Default`
-      `&mut (i32, &u32, String): Default`
-      `(i32, &u32, String): Default`
-  --> $DIR/missing-bound-on-tuple.rs:5:9
-   |
-LL | impl<T: Default> WorksOnDefault for T {}
-   |         ^^^^^^^  --------------     -
-   |         |
-   |         unsatisfied trait bound introduced here
-note: `Default` is implemented for `(i32, u32, String)` but not for `(i32, &u32, String)`
-  --> $SRC_DIR/core/src/tuple.rs:LL:COL
-   = note: this error originates in the macro `tuple_impls` (in Nightly builds, run with -Z macro-backtrace for more info)
-
-error[E0599]: the function or associated item `do_be_do` exists for tuple `(i32, &u32, String)`, but its trait bounds were not satisfied
-  --> $DIR/missing-bound-on-tuple.rs:32:43
-   |
-LL |     let _failure = <(i32, &u32, String)>::do_be_do();
-   |                                           ^^^^^^^^ function or associated item cannot be called on `(i32, &u32, String)` due to unsatisfied trait bounds
-   |
-note: the following trait bounds were not satisfied:
-      `&(i32, &u32, String): Foo`
-      `&mut (i32, &u32, String): Foo`
-      `(i32, &u32, String): Foo`
-  --> $DIR/missing-bound-on-tuple.rs:15:9
-   |
-LL | impl<T: Foo> WorksOnFoo for T {}
-   |         ^^^  ----------     -
-   |         |
-   |         unsatisfied trait bound introduced here
-note: `Foo` is implemented for `(i32, u32, String)` but not for `(i32, &u32, String)`
-  --> $DIR/missing-bound-on-tuple.rs:19:1
-   |
-LL | impl<A: Foo, B: Foo, C: Foo> Foo for (A, B, C) {}
-   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-error[E0599]: the function or associated item `default` exists for tuple `(i32, &u32, String)`, but its trait bounds were not satisfied
-  --> $DIR/missing-bound-on-tuple.rs:35:43
-   |
-LL |     let _failure = <(i32, &u32, String)>::default();
-   |                                           ^^^^^^^ function or associated item cannot be called on `(i32, &u32, String)` due to unsatisfied trait bounds
-   |
-   = note: the following trait bounds were not satisfied:
-           `&u32: Default`
-           which is required by `(i32, &u32, String): Default`
-note: `Default` is implemented for `(i32, u32, String)` but not for `(i32, &u32, String)`
-  --> $SRC_DIR/core/src/tuple.rs:LL:COL
-   = note: this error originates in the macro `tuple_impls` (in Nightly builds, run with -Z macro-backtrace for more info)
-
-error: aborting due to 3 previous errors
-
-For more information about this error, try `rustc --explain E0599`.
diff --git a/tests/ui/methods/tuple-suggestions-issue-142488.rs b/tests/ui/methods/tuple-suggestions-issue-142488.rs
new file mode 100644
index 00000000000..f6c58fce9a1
--- /dev/null
+++ b/tests/ui/methods/tuple-suggestions-issue-142488.rs
@@ -0,0 +1,48 @@
+// Regression test for issue #142488, a diagnostics ICE when trying to suggest missing methods
+// present in similar tuple types.
+// This is a few of the MCVEs from the issues and its many duplicates.
+
+// 1
+fn main() {
+    for a in x {
+        //~^ ERROR: cannot find value `x` in this scope
+        (a,).to_string()
+        //~^ ERROR: the method `to_string` exists for tuple
+    }
+}
+
+// 2
+trait Trait {
+    fn meth(self);
+}
+
+impl<T, U: Trait> Trait for (T, U) {
+    fn meth(self) {}
+}
+
+fn mcve2() {
+    ((), std::collections::HashMap::new()).meth()
+    //~^ ERROR: the method `meth` exists for tuple
+}
+
+// 3
+trait I {}
+
+struct Struct;
+impl I for Struct {}
+
+trait Tr {
+    fn f<A>(self) -> (A,)
+    where
+        Self: Sized,
+    {
+        loop {}
+    }
+}
+
+impl<T> Tr for T where T: I {}
+
+fn mcve3() {
+    Struct.f().f();
+    //~^ ERROR: the method `f` exists for tuple
+}
diff --git a/tests/ui/methods/tuple-suggestions-issue-142488.stderr b/tests/ui/methods/tuple-suggestions-issue-142488.stderr
new file mode 100644
index 00000000000..f9363bb216f
--- /dev/null
+++ b/tests/ui/methods/tuple-suggestions-issue-142488.stderr
@@ -0,0 +1,61 @@
+error[E0425]: cannot find value `x` in this scope
+  --> $DIR/tuple-suggestions-issue-142488.rs:7:14
+   |
+LL |     for a in x {
+   |              ^ not found in this scope
+
+error[E0599]: the method `to_string` exists for tuple `(_,)`, but its trait bounds were not satisfied
+  --> $DIR/tuple-suggestions-issue-142488.rs:9:14
+   |
+LL |         (a,).to_string()
+   |              ^^^^^^^^^ method cannot be called on `(_,)` due to unsatisfied trait bounds
+   |
+   = note: the following trait bounds were not satisfied:
+           `(_,): std::fmt::Display`
+           which is required by `(_,): ToString`
+
+error[E0599]: the method `meth` exists for tuple `((), HashMap<_, _>)`, but its trait bounds were not satisfied
+  --> $DIR/tuple-suggestions-issue-142488.rs:24:44
+   |
+LL |     ((), std::collections::HashMap::new()).meth()
+   |                                            ^^^^ method cannot be called on `((), HashMap<_, _>)` due to unsatisfied trait bounds
+   |
+note: trait bound `HashMap<_, _>: Trait` was not satisfied
+  --> $DIR/tuple-suggestions-issue-142488.rs:19:12
+   |
+LL | impl<T, U: Trait> Trait for (T, U) {
+   |            ^^^^^  -----     ------
+   |            |
+   |            unsatisfied trait bound introduced here
+   = help: items from traits can only be used if the trait is implemented and in scope
+note: `Trait` defines an item `meth`, perhaps you need to implement it
+  --> $DIR/tuple-suggestions-issue-142488.rs:15:1
+   |
+LL | trait Trait {
+   | ^^^^^^^^^^^
+
+error[E0599]: the method `f` exists for tuple `(_,)`, but its trait bounds were not satisfied
+  --> $DIR/tuple-suggestions-issue-142488.rs:46:16
+   |
+LL |     Struct.f().f();
+   |                ^ method cannot be called on `(_,)` due to unsatisfied trait bounds
+   |
+note: the following trait bounds were not satisfied:
+      `&(_,): I`
+      `&mut (_,): I`
+      `(_,): I`
+  --> $DIR/tuple-suggestions-issue-142488.rs:43:27
+   |
+LL | impl<T> Tr for T where T: I {}
+   |         --     -          ^ unsatisfied trait bound introduced here
+   = help: items from traits can only be used if the trait is implemented and in scope
+note: `Tr` defines an item `f`, perhaps you need to implement it
+  --> $DIR/tuple-suggestions-issue-142488.rs:34:1
+   |
+LL | trait Tr {
+   | ^^^^^^^^
+
+error: aborting due to 4 previous errors
+
+Some errors have detailed explanations: E0425, E0599.
+For more information about an error, try `rustc --explain E0425`.
diff --git a/tests/ui/traits/vtable/empty-supertrait-with-nonempty-supersupertrait.dump.stderr b/tests/ui/traits/vtable/empty-supertrait-with-nonempty-supersupertrait.dump.stderr
new file mode 100644
index 00000000000..d90a786498e
--- /dev/null
+++ b/tests/ui/traits/vtable/empty-supertrait-with-nonempty-supersupertrait.dump.stderr
@@ -0,0 +1,16 @@
+error: vtable entries: [
+           MetadataDropInPlace,
+           MetadataSize,
+           MetadataAlign,
+           Method(<dyn OneTwo as One>::one - shim(reify)),
+           Method(<dyn OneTwo as Two>::two - shim(reify)),
+           TraitVPtr(<dyn OneTwo as Two>),
+           TraitVPtr(<dyn OneTwo as TwoAgain>),
+       ]
+  --> $DIR/empty-supertrait-with-nonempty-supersupertrait.rs:40:1
+   |
+LL | type T = dyn OneTwo;
+   | ^^^^^^
+
+error: aborting due to 1 previous error
+
diff --git a/tests/ui/traits/vtable/empty-supertrait-with-nonempty-supersupertrait.rs b/tests/ui/traits/vtable/empty-supertrait-with-nonempty-supersupertrait.rs
new file mode 100644
index 00000000000..507cda63868
--- /dev/null
+++ b/tests/ui/traits/vtable/empty-supertrait-with-nonempty-supersupertrait.rs
@@ -0,0 +1,49 @@
+//@ revisions: run dump
+//@[run] run-pass
+//@[dump] check-fail
+//! Regression test for #145752
+//! Ensure that `OneTwo` contains a vptr for `TwoAgain`
+#![allow(unused)]
+#![cfg_attr(dump, feature(rustc_attrs))]
+
+trait One {
+    fn one(&self) {
+        panic!("don't call this");
+    }
+}
+impl One for () {}
+
+trait Two {
+    fn two(&self) {
+        println!("good");
+    }
+}
+impl Two for () {}
+
+trait TwoAgain: Two {}
+impl<T: Two> TwoAgain for T {}
+
+trait OneTwo: One + TwoAgain {}
+impl<T: One + Two> OneTwo for T {}
+
+fn main() {
+    (&()).two();
+    (&() as &dyn OneTwo).two();
+    (&() as &dyn OneTwo as &dyn Two).two();
+
+    // these two used to panic because they called `one` due to #145752
+    (&() as &dyn OneTwo as &dyn TwoAgain).two();
+    (&() as &dyn OneTwo as &dyn TwoAgain as &dyn Two).two();
+}
+
+#[cfg_attr(dump, rustc_dump_vtable)]
+type T = dyn OneTwo;
+//[dump]~^ ERROR vtable entries: [
+//[dump]~| ERROR            MetadataDropInPlace,
+//[dump]~| ERROR            MetadataSize,
+//[dump]~| ERROR            MetadataAlign,
+//[dump]~| ERROR            Method(<dyn OneTwo as One>::one - shim(reify)),
+//[dump]~| ERROR            Method(<dyn OneTwo as Two>::two - shim(reify)),
+//[dump]~| ERROR            TraitVPtr(<dyn OneTwo as Two>),
+//[dump]~| ERROR            TraitVPtr(<dyn OneTwo as TwoAgain>),
+//[dump]~| ERROR        ]
diff --git a/tests/ui/traits/vtable/multiple-auto.rs b/tests/ui/traits/vtable/multiple-auto.rs
new file mode 100644
index 00000000000..87ee865868b
--- /dev/null
+++ b/tests/ui/traits/vtable/multiple-auto.rs
@@ -0,0 +1,50 @@
+// Related to <https://github.com/rust-lang/rust/issues/113840>
+//
+// This test makes sure that multiple auto traits can reuse the
+// same pointer for upcasting (e.g. `Send`/`Sync`)
+
+#![crate_type = "lib"]
+#![feature(rustc_attrs, auto_traits)]
+
+// Markers
+auto trait M0 {}
+auto trait M1 {}
+auto trait M2 {}
+
+// Just a trait with a method
+trait T {
+    fn method(&self) {}
+}
+
+trait A: M0 + M1 + M2 + T {}
+
+trait B: M0 + M1 + T + M2 {}
+
+trait C: M0 + T + M1 + M2 {}
+
+trait D: T + M0 + M1 + M2 {}
+
+struct S;
+
+impl M0 for S {}
+impl M1 for S {}
+impl M2 for S {}
+impl T for S {}
+
+#[rustc_dump_vtable]
+impl A for S {}
+//~^ ERROR vtable entries
+
+#[rustc_dump_vtable]
+impl B for S {}
+//~^ ERROR vtable entries
+
+#[rustc_dump_vtable]
+impl C for S {}
+//~^ ERROR vtable entries
+
+#[rustc_dump_vtable]
+impl D for S {}
+//~^ ERROR vtable entries
+
+fn main() {}
diff --git a/tests/ui/traits/vtable/multiple-auto.stderr b/tests/ui/traits/vtable/multiple-auto.stderr
new file mode 100644
index 00000000000..0a7c3ebd36d
--- /dev/null
+++ b/tests/ui/traits/vtable/multiple-auto.stderr
@@ -0,0 +1,46 @@
+error: vtable entries: [
+           MetadataDropInPlace,
+           MetadataSize,
+           MetadataAlign,
+           Method(<S as T>::method),
+       ]
+  --> $DIR/multiple-auto.rs:35:1
+   |
+LL | impl A for S {}
+   | ^^^^^^^^^^^^
+
+error: vtable entries: [
+           MetadataDropInPlace,
+           MetadataSize,
+           MetadataAlign,
+           Method(<S as T>::method),
+       ]
+  --> $DIR/multiple-auto.rs:39:1
+   |
+LL | impl B for S {}
+   | ^^^^^^^^^^^^
+
+error: vtable entries: [
+           MetadataDropInPlace,
+           MetadataSize,
+           MetadataAlign,
+           Method(<S as T>::method),
+       ]
+  --> $DIR/multiple-auto.rs:43:1
+   |
+LL | impl C for S {}
+   | ^^^^^^^^^^^^
+
+error: vtable entries: [
+           MetadataDropInPlace,
+           MetadataSize,
+           MetadataAlign,
+           Method(<S as T>::method),
+       ]
+  --> $DIR/multiple-auto.rs:47:1
+   |
+LL | impl D for S {}
+   | ^^^^^^^^^^^^
+
+error: aborting due to 4 previous errors
+