From: Philip Herron <[email protected]>
Fixes Rust-GCC/gccrs#4157
gcc/testsuite/ChangeLog:
* rust/compile/issue-4157-1.rs: New test.
* rust/compile/issue-4157-2.rs: New test.
Signed-off-by: Philip Herron <[email protected]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.
Commit on github:
https://github.com/Rust-GCC/gccrs/commit/05c8d7b0917b04c5129ea9ee74b97cf62d814794
The commit has been mentioned in the following issue(s):
- Rust-GCC/gccrs#4157: https://github.com/Rust-GCC/gccrs/issues/4157
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/4780
gcc/testsuite/rust/compile/issue-4157-1.rs | 22 +++++++++++
gcc/testsuite/rust/compile/issue-4157-2.rs | 43 ++++++++++++++++++++++
2 files changed, 65 insertions(+)
create mode 100644 gcc/testsuite/rust/compile/issue-4157-1.rs
create mode 100644 gcc/testsuite/rust/compile/issue-4157-2.rs
diff --git a/gcc/testsuite/rust/compile/issue-4157-1.rs
b/gcc/testsuite/rust/compile/issue-4157-1.rs
new file mode 100644
index 000000000..9ecb212dd
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-4157-1.rs
@@ -0,0 +1,22 @@
+#![feature(no_core)]
+#![no_core]
+#![feature(lang_items)]
+
+#[lang = "sized"]
+trait Sized {}
+
+struct MyStruct {}
+struct Nested {
+ nested: MyStruct,
+}
+struct Mix2 {
+ nested: (Nested,),
+}
+
+const MIX_2: Mix2 = Mix2 { nested: ((2,),) };
+// { dg-error "mismatched types, expected .Nested. but got" "" { target *-*-*
} .-1 }
+
+fn main() {
+ let f = [0; (MIX_2.nested.0).0];
+ // { dg-error "expected tuple or tuple struct, found .Nested." "" { target
*-*-* } .-1 }
+}
diff --git a/gcc/testsuite/rust/compile/issue-4157-2.rs
b/gcc/testsuite/rust/compile/issue-4157-2.rs
new file mode 100644
index 000000000..9d58cd6ad
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-4157-2.rs
@@ -0,0 +1,43 @@
+#![feature(no_core)]
+#![no_core]
+#![feature(lang_items)]
+
+#[lang = "sized"]
+trait Sized {}
+
+struct MyStruct {
+ field: usize,
+}
+struct Nested {
+ nested: MyStruct,
+}
+struct Mix2 {
+ nested: (Nested,),
+}
+
+const STRUCT: MyStruct = MyStruct { field: 42 };
+const TUP: (usize,) = (43,);
+const NESTED_S: Nested = Nested {
+ nested: MyStruct { field: 5 },
+};
+const NESTED_T: ((usize,),) = ((4,),);
+const MIX_1: ((Nested,),) = ((MyStruct { field: 3 },),);
+// { dg-error "mismatched types, expected .Nested. but got .MyStruct." "" {
target *-*-* } .-1 }
+const MIX_2: Mix2 = Mix2 { nested: ((2,),) };
+// { dg-error "mismatched types, expected .Nested. but got" "" { target *-*-*
} .-1 }
+const INSTANT_1: usize = (MyStruct { field: 1 }).field;
+const INSTANT_2: usize = (4,).0;
+
+fn main() {
+ let h = [0; STRUCT.field];
+ let b = [0; TUP.0];
+ let c = [0; NESTED_S.nested.field];
+ let d = [0; (NESTED_T.0).0];
+ let e = [0; (MIX_1.0).0.nested.field];
+ // { dg-error "failed to resolve TupleIndexExpr receiver" "" { target
*-*-* } .-1 }
+ // { dg-error "expected algebraic data type got .<tyty::error>." "" {
target *-*-* } .-2 }
+ let f = [0; (MIX_2.nested.0).0];
+ // { dg-error "expected tuple or tuple struct, found .Nested." "" { target
*-*-* } .-1 }
+ let g = [0; INSTANT_1];
+ let h = [0; INSTANT_2];
+}
--
2.54.0