diff options
Diffstat (limited to 'gcc/testsuite/rust/compile')
51 files changed, 557 insertions, 67 deletions
diff --git a/gcc/testsuite/rust/compile/black_box.rs b/gcc/testsuite/rust/compile/black_box.rs new file mode 100644 index 0000000..80615af --- /dev/null +++ b/gcc/testsuite/rust/compile/black_box.rs @@ -0,0 +1,28 @@ +// { dg-options "-fdump-tree-gimple" } +#![feature(rustc_attrs)] + +#[lang = "sized"] +pub trait Sized {} + +#[rustc_builtin_macro] +macro_rules! llvm_asm { + () => {}; +} + +pub fn black_box<T>(mut dummy: T) -> T { + unsafe { + // { dg-final { scan-tree-dump-times {memory} 1 gimple } } + llvm_asm!("" : : "r"(&mut dummy) : "memory" : "volatile"); + } + + dummy +} + +fn my_function(a: i32) -> i32 { + a +} + +fn main() { + let dummy: i32 = 42; + let _ = black_box(my_function(dummy)); +} diff --git a/gcc/testsuite/rust/compile/derive-debug1.rs b/gcc/testsuite/rust/compile/derive-debug1.rs index 2596a37..cf2187d 100644 --- a/gcc/testsuite/rust/compile/derive-debug1.rs +++ b/gcc/testsuite/rust/compile/derive-debug1.rs @@ -15,7 +15,7 @@ mod core { struct Formatter; // { dg-warning "is never constructed" } struct Error; // { dg-warning "is never constructed" } - type Result = core::result::Result<(), Error>; + type Result = crate::core::result::Result<(), Error>; trait Debug { fn fmt(&self, fmt: &mut Formatter) -> Result; 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/generics9.rs b/gcc/testsuite/rust/compile/generics9.rs index 3c787aa..56c6198 100644 --- a/gcc/testsuite/rust/compile/generics9.rs +++ b/gcc/testsuite/rust/compile/generics9.rs @@ -1,5 +1,6 @@ +// { dg-additional-options "-frust-name-resolution-2.0" } struct Foo<A, B = (A, B)>(A, B); -// { dg-error "could not resolve type path .B." "" { target *-*-* } .-1 } +// { dg-error "type parameters with a default cannot use forward declared identifiers" "" { target *-*-* } .-1 } fn main() { let a: Foo<bool>; 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-3530-1.rs b/gcc/testsuite/rust/compile/issue-3530-1.rs new file mode 100644 index 0000000..b38b5cd --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3530-1.rs @@ -0,0 +1,2 @@ +#[repr(i32)] +enum NightsWatch {} // { dg-error "unsupported representation for zero-variant enum" } diff --git a/gcc/testsuite/rust/compile/issue-3530-2.rs b/gcc/testsuite/rust/compile/issue-3530-2.rs new file mode 100644 index 0000000..7432730 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3530-2.rs @@ -0,0 +1,2 @@ +#[repr(C)] +enum NightsWatch {} // { dg-error "unsupported representation for zero-variant enum" } diff --git a/gcc/testsuite/rust/compile/issue-3568.rs b/gcc/testsuite/rust/compile/issue-3568.rs index 222a174..fef43b5 100644 --- a/gcc/testsuite/rust/compile/issue-3568.rs +++ b/gcc/testsuite/rust/compile/issue-3568.rs @@ -4,4 +4,4 @@ mod foo { } pub use foo::super::foo::S as T; -// { dg-error ".super. can only be used in start position" "" { target *-*-* } .-1 } +// { dg-error ".super. in paths can only be used in start position" "" { target *-*-* } .-1 } diff --git a/gcc/testsuite/rust/compile/issue-3581-1.rs b/gcc/testsuite/rust/compile/issue-3581-1.rs new file mode 100644 index 0000000..eb2f5f0 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3581-1.rs @@ -0,0 +1,12 @@ +enum Foo { + Bar, +} + +struct Baz; + +fn main() { + Foo::Bar.a; + // { dg-error "no field .a. on type .Foo. .E0609." "" { target *-*-* } .-1 } + Baz.a; + // { dg-error "no field .a. on type .Baz. .E0609." "" { target *-*-* } .-1 } +} diff --git a/gcc/testsuite/rust/compile/issue-3581-2.rs b/gcc/testsuite/rust/compile/issue-3581-2.rs new file mode 100644 index 0000000..5059784 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3581-2.rs @@ -0,0 +1,9 @@ +enum A { + X { inner: i32 }, + Y, +} + +pub fn test() { + let _ = A::Y.inner; + // { dg-error "no field .inner. on type .A. .E0609." "" { target *-*-* } .-1 } +} diff --git a/gcc/testsuite/rust/compile/issue-3612.rs b/gcc/testsuite/rust/compile/issue-3612.rs new file mode 100644 index 0000000..5256d0a --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3612.rs @@ -0,0 +1,7 @@ +trait _St1 { + pub const UNDERFLOW: *const u16 = unsafe { [0u16; 1].as_ptr().offset(isize::MIN) }; + // { dg-error "no method named .as_ptr. found in the current scope .E0599." "" { target *-*-* } .-1 } + // { dg-error "failed to resolve receiver in MethodCallExpr" "" { target *-*-* } .-2 } +} + +fn main() {} 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-3628.rs b/gcc/testsuite/rust/compile/issue-3628.rs new file mode 100644 index 0000000..5f59789 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3628.rs @@ -0,0 +1,10 @@ +pub enum Enum { + Variant1(isize), +} + +impl Enum { + fn static_meth_enum() -> Enum { + Enum { x: 1 } + // { dg-error "expected a struct, variant or union type, found enum .Enum. .E0574." "" { target *-*-* } .-1 } + } +} 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-3649.rs b/gcc/testsuite/rust/compile/issue-3649.rs new file mode 100644 index 0000000..b85b193 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3649.rs @@ -0,0 +1,2 @@ +struct T(Box<>); +// { dg-error "could not resolve type path .Box. .E0412." "" { target *-*-* } .-1 } diff --git a/gcc/testsuite/rust/compile/issue-3652.rs b/gcc/testsuite/rust/compile/issue-3652.rs new file mode 100644 index 0000000..537ca9f --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3652.rs @@ -0,0 +1,7 @@ +trait Foo { + type T; + fn foo() -> T<<Self as Foo>::T>; + // { dg-error "could not resolve type path .T. .E0412." "" { target *-*-* } .-1 } +} + +fn foo() {} 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-3662.rs b/gcc/testsuite/rust/compile/issue-3662.rs new file mode 100644 index 0000000..88baa2e --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3662.rs @@ -0,0 +1,8 @@ +pub fn rlib() { + let _ = ((-1 as i8) << 8 - 1) as f32; + let _ = 0u8 as char; + let _ = true > false; + let _ = true >= false; + let _ = true < false; + let _ = true >= false; +} 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-3664.rs b/gcc/testsuite/rust/compile/issue-3664.rs new file mode 100644 index 0000000..c52a758 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3664.rs @@ -0,0 +1,5 @@ +const ARR: [usize; 1] = [2]; + +pub fn l8() { + let _ = 5 << ARR[0]; +} 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/issue-3711.rs b/gcc/testsuite/rust/compile/issue-3711.rs new file mode 100644 index 0000000..a3f9c39 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3711.rs @@ -0,0 +1,17 @@ +#[lang = "sized"] +pub trait Sized {} + +#[lang = "fn_once"] +pub trait FnOnce<Args> { + #[lang = "fn_once_output"] + type Output; + + extern "rust-call" fn call_once(self, args: Args) -> Self::Output; +} + +fn returns_closure() -> _ { + // { dg-error "the type placeholder ._. is not allowed within types on item signatures .E0121." "" { target *-*-* } .-1 } + || 0 +} + +fn main() {} diff --git a/gcc/testsuite/rust/compile/issue-402.rs b/gcc/testsuite/rust/compile/issue-402.rs new file mode 100644 index 0000000..2c99fc8 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-402.rs @@ -0,0 +1,14 @@ +#[lang = "sized"] +pub trait Sized {} + +struct GenericStruct<T>(T, usize); + +pub fn test() -> GenericStruct<_> { + // { dg-error "the type placeholder ._. is not allowed within types on item signatures .E0121." "" { target *-*-* } .-1 } + GenericStruct(1, 2) +} + +fn square(num: i32) -> _ { + // { dg-error "the type placeholder ._. is not allowed within types on item signatures .E0121." "" { target *-*-* } .-1 } + num * num +} diff --git a/gcc/testsuite/rust/compile/macros/mbe/macro-issue2983_2984.rs b/gcc/testsuite/rust/compile/macros/mbe/macro-issue2983_2984.rs index 637d572..eeae6eb 100644 --- a/gcc/testsuite/rust/compile/macros/mbe/macro-issue2983_2984.rs +++ b/gcc/testsuite/rust/compile/macros/mbe/macro-issue2983_2984.rs @@ -18,10 +18,9 @@ fn main() { // Error let _ = ReadDir { + // { dg-error "unknown field .end_of_stream_but_different. .E0560." "" { target *-*-* } .-1 } inner: 14, end_of_stream: false, - end_of_stream_but_different: false, // { dg-error "failed to resolve type for field" } - // { dg-error "unknown field" "" { target *-*-* } .-1 } - // { dg-prune-output "compilation terminated" } + end_of_stream_but_different: false, }; } 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/multiple_bindings1.rs b/gcc/testsuite/rust/compile/multiple_bindings1.rs index e73dc2a..8a2e18c 100644 --- a/gcc/testsuite/rust/compile/multiple_bindings1.rs +++ b/gcc/testsuite/rust/compile/multiple_bindings1.rs @@ -1,29 +1,38 @@ +#[lang = "sized"] +pub trait Sized {} + +#[lang = "fn_once"] +trait FnOnce<Args> { + type Output; + + fn call_once(self, args: Args) -> Self::Output; +} + fn f1(i: i32, i: i32) {} // { dg-error "identifier .i. is bound more than once in the same parameter list .E0415." "" { target *-*-* } .-1 } trait Foo { - fn f2(i: i32, i: i32) {} - // { dg-error "identifier .i. is bound more than once in the same parameter list .E0415." "" { target *-*-* } .-1 } + fn f2(i: i32, i: i32) {} + // { dg-error "identifier .i. is bound more than once in the same parameter list .E0415." "" { target *-*-* } .-1 } } trait Bar { - fn f3(i: i32, j: i32) {} + fn f3(i: i32, j: i32) {} } struct S; impl S { - fn f4(i: i32, i: i32) {} - // { dg-error "identifier .i. is bound more than once in the same parameter list .E0415." "" { target *-*-* } .-1 } + fn f4(i: i32, i: i32) {} + // { dg-error "identifier .i. is bound more than once in the same parameter list .E0415." "" { target *-*-* } .-1 } } impl Bar for S { - fn f3(i: i32, i: i32) {} - // { dg-error "identifier .i. is bound more than once in the same parameter list .E0415." "" { target *-*-* } .-1 } + fn f3(i: i32, i: i32) {} + // { dg-error "identifier .i. is bound more than once in the same parameter list .E0415." "" { target *-*-* } .-1 } } fn main() { - let _ = |i, i| {}; - // { dg-error "identifier .i. is bound more than once in the same parameter list .E0415." "" { target *-*-* } .-1 } + let _ = |i, i| {}; + // { dg-error "identifier .i. is bound more than once in the same parameter list .E0415." "" { target *-*-* } .-1 } } - diff --git a/gcc/testsuite/rust/compile/name_resolution9.rs b/gcc/testsuite/rust/compile/name_resolution9.rs index 93adb46..792b3bd 100644 --- a/gcc/testsuite/rust/compile/name_resolution9.rs +++ b/gcc/testsuite/rust/compile/name_resolution9.rs @@ -6,11 +6,11 @@ pub mod foo { super::super::super::foo!(); // { dg-error "too many leading .super. keywords" } // { dg-error "could not resolve macro invocation" "" { target *-*-* } .-1 } - super::crate::foo!(); // { dg-error "leading path segment .crate. can only be used" } + super::crate::foo!(); // { dg-error ".crate. in paths can only be used" } // { dg-error "could not resolve macro invocation" "" { target *-*-* } .-1 } - crate::foo::bar::super::foo!(); // { dg-error "leading path segment .super. can only be used" } + crate::foo::bar::super::foo!(); // { dg-error ".super. in paths can only be used" } // { dg-error "could not resolve macro invocation" "" { target *-*-* } .-1 } } } diff --git a/gcc/testsuite/rust/compile/nonexistent-field.rs b/gcc/testsuite/rust/compile/nonexistent-field.rs index e20c49d..9bcfb2f 100644 --- a/gcc/testsuite/rust/compile/nonexistent-field.rs +++ b/gcc/testsuite/rust/compile/nonexistent-field.rs @@ -6,7 +6,7 @@ fn main() { let s = StructWithFields { x: 0 }; s.foo; - // { dg-error "no field .foo. on type .StructWithFields.StructWithFields .x.u32... .E0609." "" { target *-*-* } .-1 } + // { dg-error "no field .foo. on type .StructWithFields. .E0609." "" { target *-*-* } .-1 } let numbers = (1, 2, 3); numbers.3; diff --git a/gcc/testsuite/rust/compile/nr2/compile.exp b/gcc/testsuite/rust/compile/nr2/compile.exp index 35637f1..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 @@ -47,18 +56,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 +96,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,26 +122,28 @@ 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" } } } # All done. dg-finish + +gcc_parallel_test_enable 1 diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude index 19bf6f8..c020e36 100644 --- a/gcc/testsuite/rust/compile/nr2/exclude +++ b/gcc/testsuite/rust/compile/nr2/exclude @@ -1,33 +1,17 @@ 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 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 +issue-3652.rs +issue-3649.rs # please don't delete the trailing newline diff --git a/gcc/testsuite/rust/compile/self-path2.rs b/gcc/testsuite/rust/compile/self-path2.rs index 6441c33..d955ed0 100644 --- a/gcc/testsuite/rust/compile/self-path2.rs +++ b/gcc/testsuite/rust/compile/self-path2.rs @@ -11,11 +11,11 @@ fn baz() { crate::bar(); crate::self::foo(); - // { dg-error "leading path segment .self. can only be used at the beginning of a path" "" { target *-*-* } .-1 } + // { dg-error ".self. in paths can only be used in start position" "" { target *-*-* } .-1 } } type a = foo; type b = crate::foo; type c = self::foo; type d = crate::self::foo; -// { dg-error "leading path segment .self. can only be used at the beginning of a path" "" { target *-*-* } .-1 } +// { dg-error ".self. in paths can only be used in start position" "" { target *-*-* } .-1 } diff --git a/gcc/testsuite/rust/compile/struct_init1.rs b/gcc/testsuite/rust/compile/struct_init1.rs index 1875fb4..38f6f38 100644 --- a/gcc/testsuite/rust/compile/struct_init1.rs +++ b/gcc/testsuite/rust/compile/struct_init1.rs @@ -4,7 +4,7 @@ struct Foo { } fn main() { - let a = Foo { 0: 10.0, 1: 20.0 }; // { dg-error "failed to resolve type for field" } - // { dg-error "unknown field" "" { target *-*-* } .-1 } - // { dg-prune-output "compilation terminated" } + let a = Foo { 0: 10.0, 1: 20.0 }; + // { dg-error "unknown field .0. .E0560." "" { target *-*-* } .-1 } + // { dg-error "unknown field .1. .E0560." "" { target *-*-* } .-2 } } 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() { diff --git a/gcc/testsuite/rust/compile/use_1.rs b/gcc/testsuite/rust/compile/use_1.rs index 94b9632..e8e2037 100644 --- a/gcc/testsuite/rust/compile/use_1.rs +++ b/gcc/testsuite/rust/compile/use_1.rs @@ -1,7 +1,8 @@ +// { dg-additional-options "-frust-name-resolution-2.0" } mod frob {} -use foo::bar::baz; // { dg-error "cannot find simple path segment .foo." } -use frob::ulator; // { dg-error "cannot find simple path segment .ulator." } +use foo::bar::baz; // { dg-error "unresolved import .foo::bar::baz." } +use frob::ulator; // { dg-error "unresolved import .frob::ulator." } mod sain { mod doux {} @@ -9,8 +10,8 @@ mod sain { mod dron {} } -use not_sain::*; // { dg-error "cannot find simple path segment .not_sain." } +use not_sain::*; // { dg-error "unresolved import .not_sain." } use sain::*; use sain::{doux, dron}; -use sain::{doux, dron, graal}; // { dg-error "cannot find simple path segment .graal." } +use sain::{doux, dron, graal}; // { dg-error "unresolved import .sain::graal." } |