diff options
Diffstat (limited to 'gcc/testsuite/rust/compile')
28 files changed, 383 insertions, 29 deletions
diff --git a/gcc/testsuite/rust/compile/enum_discriminant1.rs b/gcc/testsuite/rust/compile/enum_discriminant1.rs new file mode 100644 index 0000000..32092b2 --- /dev/null +++ b/gcc/testsuite/rust/compile/enum_discriminant1.rs @@ -0,0 +1,7 @@ +enum Foo { + Bar = 3 + 12, +} + +fn test() -> Foo { // { dg-warning "function is never used" } + return Foo::Bar; +}
\ No newline at end of file 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/feature.rs b/gcc/testsuite/rust/compile/feature.rs index f743f92..6f428f0 100644 --- a/gcc/testsuite/rust/compile/feature.rs +++ b/gcc/testsuite/rust/compile/feature.rs @@ -2,5 +2,7 @@ #![feature(AA)] //{ dg-error "unknown feature .AA." } #![feature(iamcrabby)] // { dg-error "unknown feature .iamcrabby." } #![feature(nonexistent_gccrs_feature)] // { dg-error "unknown feature .nonexistent_gccrs_feature." } +// ErrorCode - E0556 +#![feature] // { dg-error "malformed .feature. attribute input" } 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/invalid_label_name.rs b/gcc/testsuite/rust/compile/invalid_label_name.rs index 5c850da..66e40a6 100644 --- a/gcc/testsuite/rust/compile/invalid_label_name.rs +++ b/gcc/testsuite/rust/compile/invalid_label_name.rs @@ -1,20 +1,24 @@ +// { dg-additional-options "-frust-name-resolution-2.0" } pub fn function() { 'continue: loop { // { dg-error "invalid label name .'continue." "" { target *-*-* } .-1 } break 'extern; // { dg-error "invalid label name .'extern." "" { target *-*-* } .-1 } + // { dg-error "use of undeclared label .'extern." "" { target *-*-* } .-2 } } 'break: loop { // { dg-error "invalid label name .'break." "" { target *-*-* } .-1 } break 'for; // { dg-error "invalid label name .'for." "" { target *-*-* } .-1 } + // { dg-error "use of undeclared label .'for." "" { target *-*-* } .-2 } } 'crate: loop { // { dg-error "invalid label name .'crate." "" { target *-*-* } .-1 } break 'loop; // { dg-error "invalid label name .'loop." "" { target *-*-* } .-1 } + // { dg-error "use of undeclared label .'loop." "" { target *-*-* } .-2 } } 'a: loop { diff --git a/gcc/testsuite/rust/compile/issue-2812.rs b/gcc/testsuite/rust/compile/issue-2812.rs index 173259b..0de1738 100644 --- a/gcc/testsuite/rust/compile/issue-2812.rs +++ b/gcc/testsuite/rust/compile/issue-2812.rs @@ -1,4 +1,4 @@ // { dg-additional-options "-frust-compile-until=astvalidation" } fn foo_1(&self); -fn foo_1(&mut self); -fn foo_1(self); +fn foo_2(&mut self); +fn foo_3(self); diff --git a/gcc/testsuite/rust/compile/issue-3625.rs b/gcc/testsuite/rust/compile/issue-3625.rs new file mode 100644 index 0000000..91e0dc9 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3625.rs @@ -0,0 +1,2 @@ +type A = crate::A; +// { dg-error "failed to resolve type path segment: .A." "" { target *-*-* } .-2 } diff --git a/gcc/testsuite/rust/compile/issue-3643.rs b/gcc/testsuite/rust/compile/issue-3643.rs new file mode 100644 index 0000000..bed9ffc --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3643.rs @@ -0,0 +1,4 @@ +fn foo() { + let x: usize<foo>; + // { dg-error "generic arguments are not allowed for this type .E0109." "" { target *-*-* } .-1 } +} diff --git a/gcc/testsuite/rust/compile/issue-3646.rs b/gcc/testsuite/rust/compile/issue-3646.rs new file mode 100644 index 0000000..80693cb --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3646.rs @@ -0,0 +1,7 @@ +trait Foo { + type T; + fn foo() -> Foo<main>; + // { dg-error "generic arguments are not allowed for this type .E0109." "" { target *-*-* } .-1 } +} + +fn main() {} diff --git a/gcc/testsuite/rust/compile/issue-3647.rs b/gcc/testsuite/rust/compile/issue-3647.rs new file mode 100644 index 0000000..51d9478d --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3647.rs @@ -0,0 +1,7 @@ +#![allow(dead_code)] +type A = fn(); + +type B = for<'static> fn(); +// { dg-error "invalid lifetime parameter name: .static. .E0262." "" { target *-*-* } .-1 } + +pub fn main() {} diff --git a/gcc/testsuite/rust/compile/issue-3648.rs b/gcc/testsuite/rust/compile/issue-3648.rs new file mode 100644 index 0000000..52ecbbf --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3648.rs @@ -0,0 +1,8 @@ +struct B; // { dg-warning "struct is never constructed" } + +impl B { + fn main() {} + // { dg-warning "associated function is never used" "" { target *-*-* } .-1 } +} + +fn main() {} diff --git a/gcc/testsuite/rust/compile/issue-3654.rs b/gcc/testsuite/rust/compile/issue-3654.rs new file mode 100644 index 0000000..923488e --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3654.rs @@ -0,0 +1,3 @@ +type Meeshka = Mow<!>; +// { dg-error "generic arguments are not allowed for this type .E0109." "" { target *-*-* } .-1 } +type Mow = &'static fn(!) -> !; diff --git a/gcc/testsuite/rust/compile/issue-3656.rs b/gcc/testsuite/rust/compile/issue-3656.rs new file mode 100644 index 0000000..e0bec2f --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3656.rs @@ -0,0 +1,10 @@ +enum Foo { + Bar(isize), +} + +fn main() { + match Foo::Bar(205) { + Foo { i } => (), + // { dg-error "expected struct, variant or union type, found enum .Foo. .E0574." "" { target *-*-* } .-1 } + } +} diff --git a/gcc/testsuite/rust/compile/issue-3657.rs b/gcc/testsuite/rust/compile/issue-3657.rs new file mode 100644 index 0000000..978f3ce --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3657.rs @@ -0,0 +1,8 @@ +struct Foo<'_>(&'_ u8); + +impl Foo<'a> { + // { dg-error "unresolved lifetime" "" { target *-*-* } .-1 } + fn x() {} +} + +fn x() {} diff --git a/gcc/testsuite/rust/compile/issue-3663.rs b/gcc/testsuite/rust/compile/issue-3663.rs new file mode 100644 index 0000000..0f0559c --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3663.rs @@ -0,0 +1,6 @@ +pub trait TypeFn {} + +impl TypeFn for Output<{ 42 }> { + // { dg-error "could not resolve type path .Output. .E0412." "" { target *-*-* } .-1 } + type Output = (); +} diff --git a/gcc/testsuite/rust/compile/issue-3665.rs b/gcc/testsuite/rust/compile/issue-3665.rs new file mode 100644 index 0000000..d66a81f --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3665.rs @@ -0,0 +1,6 @@ +pub const uint_val: usize = 1; +pub const uint_expr: usize = 1 << uint_val; + +pub fn test() -> usize { + uint_expr +} diff --git a/gcc/testsuite/rust/compile/issue-3667.rs b/gcc/testsuite/rust/compile/issue-3667.rs new file mode 100644 index 0000000..e72069c --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3667.rs @@ -0,0 +1,24 @@ +// { dg-options "-w" } +#![feature(raw_ref_op)] + +const pq1: () = { + let mut x = 2; + &raw mut x; +}; //~ mutable reference + +static B: () = { + let mut x = 2; + &raw mut x; +}; //~ mutable reference + +static mut C: () = { + let mut x = 2; + &raw mut x; +}; //~ mutable reference + +const fn foo() { + let mut x = 0; + let y = &raw mut x; //~ mutable reference +} + +fn main() {} diff --git a/gcc/testsuite/rust/compile/issue-3671.rs b/gcc/testsuite/rust/compile/issue-3671.rs new file mode 100644 index 0000000..e800d53 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3671.rs @@ -0,0 +1,2 @@ +impl Self<0> {} +// { dg-error "could not resolve type path" "" { target *-*-* } .-1 } 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/macros/mbe/macro6.rs b/gcc/testsuite/rust/compile/macros/mbe/macro6.rs index 9c54a67..bbaaa25 100644 --- a/gcc/testsuite/rust/compile/macros/mbe/macro6.rs +++ b/gcc/testsuite/rust/compile/macros/mbe/macro6.rs @@ -1,6 +1,6 @@ macro_rules! zero_or_one { ($($a:literal)?) => { - f(); + 1 + 2; } } diff --git a/gcc/testsuite/rust/compile/min_specialization1.rs b/gcc/testsuite/rust/compile/min_specialization1.rs new file mode 100644 index 0000000..d38167e --- /dev/null +++ b/gcc/testsuite/rust/compile/min_specialization1.rs @@ -0,0 +1,15 @@ +#![feature(min_specialization)] + +pub trait Foo { + fn foo(&self) -> bool { + false + } +} + +pub struct Bar; + +impl Foo for Bar { + default fn foo(&self) -> bool { // { dg-warning "unused" } + true + } +} diff --git a/gcc/testsuite/rust/compile/nr2/compile.exp b/gcc/testsuite/rust/compile/nr2/compile.exp index 35637f1..4d91dd0 100644 --- a/gcc/testsuite/rust/compile/nr2/compile.exp +++ b/gcc/testsuite/rust/compile/nr2/compile.exp @@ -47,18 +47,22 @@ namespace eval rust-nr2-ns { set tests_expect_ok "" set tests_expect_err "" + set compile_dir [list {*}[file split $srcdir] {*}[file split $subdir]] + set compile_dir [lreplace $compile_dir end end] + foreach test_dir $test_dirs { - set directory [list {*}[file split $srcdir] {*}[file split $subdir]] - set directory [lreplace $directory end end] - set directory [list {*}$directory {*}$test_dir] - foreach test [lsort [glob -nocomplain -tails -directory [file join {*}$directory] *.rs]] { + foreach test [lsort [glob -nocomplain -tails -directory [file join {*}$compile_dir {*}$test_dir] *.rs]] { # use '/' as the path seperator for entries in the exclude file set test_lbl [join [list {*}$test_dir $test] "/"] set idx [lsearch -exact -sorted $exclude $test_lbl] if {$idx == -1} { - lappend tests_expect_ok [file join {*}$directory $test] + if {[runtest_file_p $runtests [file join {*}$compile_dir {*}$test_dir $test]]} { + lappend tests_expect_ok [list {*}$test_dir $test] + } } else { - lappend tests_expect_err [file join {*}$directory $test] + if {[runtest_file_p $runtests [file join {*}$compile_dir {*}$test_dir $test]]} { + lappend tests_expect_err [list {*}$test_dir $test] + } set exclude [lreplace $exclude $idx $idx] } } @@ -83,10 +87,10 @@ namespace eval rust-nr2-ns { variable record_test_out switch $type { FAIL { - lappend record_test_out "$type: $msg" + lappend record_test_out [list $type $msg] } XPASS { - lappend record_test_out "$type: $msg" + lappend record_test_out [list $type $msg] } } } @@ -109,23 +113,23 @@ namespace eval rust-nr2-ns { # check for unexpected failures foreach test $tests_expect_ok { - set fails [try_test $test] + set fails [try_test [file join {*}$compile_dir {*}$test]] if {[llength $fails] != 0} { foreach ent $fails { - record_test FAIL "$test: nr2 failure: $ent" + record_test [lindex $ent 0] "on nr2: [lindex $ent 1]" } } else { - record_test PASS "$test: nr2 success" + record_test PASS "[file join {*}$test] on nr2" } } #check for unexpected successes foreach test $tests_expect_err { - set fails [try_test $test] + set fails [try_test [file join {*}$compile_dir {*}$test]] if {[llength $fails] == 0} { - record_test XPASS "$test: nr2 unexpectedly passed" + record_test XPASS "[file join {*}$test] on nr2" } else { - record_test XFAIL "$test: nr2 was rightfully excluded" + record_test XFAIL "[file join {*}$test] on nr2 was rightfully excluded" } } } diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude index 19bf6f8..4772517 100644 --- a/gcc/testsuite/rust/compile/nr2/exclude +++ b/gcc/testsuite/rust/compile/nr2/exclude @@ -1,11 +1,8 @@ canonical_paths1.rs cfg1.rs generics9.rs -issue-2043.rs -issue-2812.rs issue-3315-2.rs lookup_err1.rs -macros/mbe/macro6.rs multiple_bindings1.rs multiple_bindings2.rs privacy5.rs @@ -13,21 +10,16 @@ privacy8.rs pub_restricted_1.rs pub_restricted_2.rs pub_restricted_3.rs -undeclared_label.rs use_1.rs -while_break_expr.rs issue-2905-2.rs -issue-266.rs derive_clone_enum3.rs derive-debug1.rs derive-default1.rs -issue-3402-1.rs -issue-3403.rs derive-eq-invalid.rs derive-hash1.rs torture/alt_patterns1.rs -torture/loop4.rs -torture/loop8.rs torture/name_resolve1.rs issue-3568.rs +issue-3663.rs +issue-3671.rs # please don't delete the trailing newline 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/compile/undeclared_label.rs b/gcc/testsuite/rust/compile/undeclared_label.rs index 6efa2d9..9aa0553 100644 --- a/gcc/testsuite/rust/compile/undeclared_label.rs +++ b/gcc/testsuite/rust/compile/undeclared_label.rs @@ -2,12 +2,12 @@ #![allow(unused)] fn resolve_label_continue() -> () { loop { - continue 'a; // { dg-error "use of undeclared label .a. in .continue." } + continue 'a; // { dg-error "use of undeclared label .'a." } } } fn resolve_label_break() -> () { loop { - break 'crabby; // { dg-error "use of undeclared label .crabby. in .break." } + break 'crabby; // { dg-error "use of undeclared label .'crabby." } } } fn main() { |