aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/rust
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite/rust')
-rw-r--r--gcc/testsuite/rust/compile/enum_discriminant2.rs9
-rw-r--r--gcc/testsuite/rust/compile/format_args_extra_comma.rs47
-rw-r--r--gcc/testsuite/rust/compile/macros/mbe/macro-issue3693.rs10
-rw-r--r--gcc/testsuite/rust/compile/macros/mbe/macro-issue3708.rs80
-rw-r--r--gcc/testsuite/rust/compile/macros/mbe/macro-issue3709-1.rs10
-rw-r--r--gcc/testsuite/rust/compile/macros/mbe/macro-issue3709-2.rs81
-rw-r--r--gcc/testsuite/rust/compile/nr2/compile.exp11
-rw-r--r--gcc/testsuite/rust/compile/track_caller.rs6
-rw-r--r--gcc/testsuite/rust/execute/torture/min_specialization2.rs31
-rw-r--r--gcc/testsuite/rust/execute/torture/min_specialization3.rs36
10 files changed, 321 insertions, 0 deletions
diff --git a/gcc/testsuite/rust/compile/enum_discriminant2.rs b/gcc/testsuite/rust/compile/enum_discriminant2.rs
new file mode 100644
index 0000000..351dfbb
--- /dev/null
+++ b/gcc/testsuite/rust/compile/enum_discriminant2.rs
@@ -0,0 +1,9 @@
+fn test() -> isize {
+ 1
+}
+
+enum Foo {
+ Bar = test() // { dg-error "only functions marked as .const." }
+}
+
+fn main() {}
diff --git a/gcc/testsuite/rust/compile/format_args_extra_comma.rs b/gcc/testsuite/rust/compile/format_args_extra_comma.rs
new file mode 100644
index 0000000..fcc435c
--- /dev/null
+++ b/gcc/testsuite/rust/compile/format_args_extra_comma.rs
@@ -0,0 +1,47 @@
+#![feature(rustc_attrs)]
+
+#[rustc_builtin_macro]
+macro_rules! format_args {
+ () => {};
+}
+
+#[lang = "sized"]
+trait Sized {}
+
+pub mod core {
+ pub mod fmt {
+ pub struct Formatter;
+ pub struct Result;
+
+ pub struct Arguments<'a>;
+
+ impl<'a> Arguments<'a> {
+ pub fn new_v1(_: &'a [&'static str], _: &'a [ArgumentV1<'a>]) -> Arguments<'a> {
+ Arguments
+ }
+ }
+
+ pub struct ArgumentV1<'a>;
+
+ impl<'a> ArgumentV1<'a> {
+ pub fn new<'b, T>(_: &'b T, _: fn(&T, &mut Formatter) -> Result) -> ArgumentV1 {
+ ArgumentV1
+ }
+ }
+
+ pub trait Display {
+ fn fmt(&self, _: &mut Formatter) -> Result;
+ }
+
+ impl Display for i32 {
+ fn fmt(&self, _: &mut Formatter) -> Result {
+ // { dg-warning "unused name .self." "" { target *-*-* } .-1 }
+ Result
+ }
+ }
+ }
+}
+
+fn main() {
+ let _formatted = format_args!("extra commas {} {}", 15, 14,);
+}
diff --git a/gcc/testsuite/rust/compile/macros/mbe/macro-issue3693.rs b/gcc/testsuite/rust/compile/macros/mbe/macro-issue3693.rs
new file mode 100644
index 0000000..e990c8b
--- /dev/null
+++ b/gcc/testsuite/rust/compile/macros/mbe/macro-issue3693.rs
@@ -0,0 +1,10 @@
+macro_rules! generate_pattern_iterators {
+ {
+ $(#[$forward_iterator_attribute:meta])*
+ } => {
+ }
+}
+
+generate_pattern_iterators! {
+ /// Created with the method [`split`].
+}
diff --git a/gcc/testsuite/rust/compile/macros/mbe/macro-issue3708.rs b/gcc/testsuite/rust/compile/macros/mbe/macro-issue3708.rs
new file mode 100644
index 0000000..e5b38bb
--- /dev/null
+++ b/gcc/testsuite/rust/compile/macros/mbe/macro-issue3708.rs
@@ -0,0 +1,80 @@
+// { dg-additional-options "-frust-name-resolution-2.0 -frust-compile-until=lowering" }
+
+macro_rules! impl_fn_for_zst {
+ ($(
+ $( #[$attr: meta] )*
+ struct $Name: ident impl$( <$( $lifetime : lifetime ),+> )? Fn =
+ |$( $arg: ident: $ArgTy: ty ),*| -> $ReturnTy: ty
+ $body: block;
+ )+) => {
+ $(
+ $( #[$attr] )*
+ struct $Name;
+
+ impl $( <$( $lifetime ),+> )? Fn<($( $ArgTy, )*)> for $Name {
+ #[inline]
+ extern "rust-call" fn call(&self, ($( $arg, )*): ($( $ArgTy, )*)) -> $ReturnTy {
+ $body
+ }
+ }
+
+ impl $( <$( $lifetime ),+> )? FnMut<($( $ArgTy, )*)> for $Name {
+ #[inline]
+ extern "rust-call" fn call_mut(
+ &mut self,
+ ($( $arg, )*): ($( $ArgTy, )*)
+ ) -> $ReturnTy {
+ Fn::call(&*self, ($( $arg, )*))
+ }
+ }
+
+ impl $( <$( $lifetime ),+> )? FnOnce<($( $ArgTy, )*)> for $Name {
+ type Output = $ReturnTy;
+
+ #[inline]
+ extern "rust-call" fn call_once(self, ($( $arg, )*): ($( $ArgTy, )*)) -> $ReturnTy {
+ Fn::call(&self, ($( $arg, )*))
+ }
+ }
+ )+
+ }
+}
+
+#[lang = "sized"]
+trait Sized {}
+
+#[lang = "copy"]
+trait Copy {}
+
+#[lang = "fn"]
+pub trait Fn<Args>: FnMut<Args> {
+ /// Performs the call operation.
+ #[unstable(feature = "fn_traits", issue = "29625")]
+ extern "rust-call" fn call(&self, args: Args) -> Self::Output;
+}
+
+#[lang = "fn_mut"]
+#[must_use = "closures are lazy and do nothing unless called"]
+pub trait FnMut<Args>: FnOnce<Args> {
+ /// Performs the call operation.
+ #[unstable(feature = "fn_traits", issue = "29625")]
+ extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output;
+}
+
+#[lang = "fn_once"]
+pub trait FnOnce<Args> {
+ /// The returned type after the call operator is used.
+ #[lang = "fn_once_output"]
+ #[stable(feature = "fn_once_output", since = "1.12.0")]
+ type Output;
+
+ /// Performs the call operation.
+ #[unstable(feature = "fn_traits", issue = "29625")]
+ extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
+}
+
+impl_fn_for_zst! {
+ #[derive(Copy)]
+ struct LinesAnyMap impl<'a> Fn = |line: &'a str| -> () {
+ };
+}
diff --git a/gcc/testsuite/rust/compile/macros/mbe/macro-issue3709-1.rs b/gcc/testsuite/rust/compile/macros/mbe/macro-issue3709-1.rs
new file mode 100644
index 0000000..6fc3a31
--- /dev/null
+++ b/gcc/testsuite/rust/compile/macros/mbe/macro-issue3709-1.rs
@@ -0,0 +1,10 @@
+macro_rules! doc_comment {
+ (#[ $attr: meta ]) => {
+ #[$attr]
+ struct Generated; // { dg-warning "never constructed" }
+ };
+}
+
+doc_comment! {
+ /// This is a generated struct
+}
diff --git a/gcc/testsuite/rust/compile/macros/mbe/macro-issue3709-2.rs b/gcc/testsuite/rust/compile/macros/mbe/macro-issue3709-2.rs
new file mode 100644
index 0000000..cfc8ab4
--- /dev/null
+++ b/gcc/testsuite/rust/compile/macros/mbe/macro-issue3709-2.rs
@@ -0,0 +1,81 @@
+// { dg-additional-options "-frust-name-resolution-2.0 -frust-compile-until=lowering" }
+
+macro_rules! impl_fn_for_zst {
+ ($(
+ $( #[$attr: meta] )*
+ struct $Name: ident impl$( <$( $lifetime : lifetime ),+> )? Fn =
+ |$( $arg: ident: $ArgTy: ty ),*| -> $ReturnTy: ty
+ $body: block;
+ )+) => {
+ $(
+ $( #[$attr] )*
+ struct $Name;
+
+ impl $( <$( $lifetime ),+> )? Fn<($( $ArgTy, )*)> for $Name {
+ #[inline]
+ extern "rust-call" fn call(&self, ($( $arg, )*): ($( $ArgTy, )*)) -> $ReturnTy {
+ $body
+ }
+ }
+
+ impl $( <$( $lifetime ),+> )? FnMut<($( $ArgTy, )*)> for $Name {
+ #[inline]
+ extern "rust-call" fn call_mut(
+ &mut self,
+ ($( $arg, )*): ($( $ArgTy, )*)
+ ) -> $ReturnTy {
+ Fn::call(&*self, ($( $arg, )*))
+ }
+ }
+
+ impl $( <$( $lifetime ),+> )? FnOnce<($( $ArgTy, )*)> for $Name {
+ type Output = $ReturnTy;
+
+ #[inline]
+ extern "rust-call" fn call_once(self, ($( $arg, )*): ($( $ArgTy, )*)) -> $ReturnTy {
+ Fn::call(&self, ($( $arg, )*))
+ }
+ }
+ )+
+ }
+}
+
+#[lang = "sized"]
+trait Sized {}
+
+#[lang = "copy"]
+trait Copy {}
+
+#[lang = "fn"]
+pub trait Fn<Args>: FnMut<Args> {
+ /// Performs the call operation.
+ #[unstable(feature = "fn_traits", issue = "29625")]
+ extern "rust-call" fn call(&self, args: Args) -> Self::Output;
+}
+
+#[lang = "fn_mut"]
+#[must_use = "closures are lazy and do nothing unless called"]
+pub trait FnMut<Args>: FnOnce<Args> {
+ /// Performs the call operation.
+ #[unstable(feature = "fn_traits", issue = "29625")]
+ extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output;
+}
+
+#[lang = "fn_once"]
+pub trait FnOnce<Args> {
+ /// The returned type after the call operator is used.
+ #[lang = "fn_once_output"]
+ #[stable(feature = "fn_once_output", since = "1.12.0")]
+ type Output;
+
+ /// Performs the call operation.
+ #[unstable(feature = "fn_traits", issue = "29625")]
+ extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
+}
+
+impl_fn_for_zst! {
+ /// Documentation for the zst
+ #[derive(Copy)]
+ struct LinesAnyMap impl<'a> Fn = |line: &'a str| -> () {
+ };
+}
diff --git a/gcc/testsuite/rust/compile/nr2/compile.exp b/gcc/testsuite/rust/compile/nr2/compile.exp
index 4d91dd0..9e15cdd 100644
--- a/gcc/testsuite/rust/compile/nr2/compile.exp
+++ b/gcc/testsuite/rust/compile/nr2/compile.exp
@@ -19,6 +19,15 @@
# Load support procs.
load_lib rust-dg.exp
+# These tests don't run runtest_file_p consistently if it
+# doesn't return the same values, so disable parallelization
+# of this *.exp file. The first parallel runtest to reach
+# this will run all the tests serially.
+if ![gcc_parallel_test_run_p compile] {
+ return
+}
+gcc_parallel_test_enable 0
+
# Initialize `dg'.
dg-init
@@ -136,3 +145,5 @@ namespace eval rust-nr2-ns {
# All done.
dg-finish
+
+gcc_parallel_test_enable 1
diff --git a/gcc/testsuite/rust/compile/track_caller.rs b/gcc/testsuite/rust/compile/track_caller.rs
new file mode 100644
index 0000000..fd1d842
--- /dev/null
+++ b/gcc/testsuite/rust/compile/track_caller.rs
@@ -0,0 +1,6 @@
+#[track_caller]
+fn foo() {}
+
+fn main() {
+ foo();
+}
diff --git a/gcc/testsuite/rust/execute/torture/min_specialization2.rs b/gcc/testsuite/rust/execute/torture/min_specialization2.rs
new file mode 100644
index 0000000..d3239ee
--- /dev/null
+++ b/gcc/testsuite/rust/execute/torture/min_specialization2.rs
@@ -0,0 +1,31 @@
+#![feature(min_specialization)]
+
+#[lang = "sized"]
+trait Sized {}
+
+trait Foo {
+ fn foo(&self) -> i32;
+}
+
+impl<T> Foo for T {
+ default fn foo(&self) -> i32 { // { dg-warning "unused" }
+ 15
+ }
+}
+
+impl Foo for bool {
+ fn foo(&self) -> i32 {
+ if *self {
+ 1
+ } else {
+ 0
+ }
+ }
+}
+
+fn main() -> i32 {
+ let a = 1.foo() - 15;
+ let b = true.foo() - 1;
+
+ a + b
+}
diff --git a/gcc/testsuite/rust/execute/torture/min_specialization3.rs b/gcc/testsuite/rust/execute/torture/min_specialization3.rs
new file mode 100644
index 0000000..9eccd97
--- /dev/null
+++ b/gcc/testsuite/rust/execute/torture/min_specialization3.rs
@@ -0,0 +1,36 @@
+#![feature(min_specialization)]
+
+#[lang = "sized"]
+trait Sized {}
+
+trait Foo {
+ fn foo(&self) -> i32;
+}
+
+struct Wrap<T>(T);
+
+impl<T> Foo for T {
+ default fn foo(&self) -> i32 {
+ 15
+ }
+}
+
+impl<T> Foo for Wrap<T> {
+ default fn foo(&self) -> i32 {
+ 16
+ }
+}
+
+impl Foo for Wrap<bool> {
+ fn foo(&self) -> i32 {
+ if self.0 {
+ 1
+ } else {
+ 0
+ }
+ }
+}
+
+fn main() -> i32 {
+ Wrap(true).foo() - 1
+}