diff --git a/tests/ui/cfg/nested-cfg-attr-conditional-compilation.rs b/tests/ui/cfg/nested-cfg-attr-conditional-compilation.rs new file mode 100644 index 0000000000000..7618e83a64290 --- /dev/null +++ b/tests/ui/cfg/nested-cfg-attr-conditional-compilation.rs @@ -0,0 +1,18 @@ +//! Test that nested `cfg_attr` attributes work correctly for conditional compilation. +//! This checks that `cfg_attr` can be arbitrarily deeply nested and that the +//! expansion works from outside to inside, eventually applying the innermost +//! conditional compilation directive. +//! +//! In this test, `cfg_attr(all(), cfg_attr(all(), cfg(false)))` should expand to: +//! 1. `cfg_attr(all(), cfg(false))` (outer cfg_attr applied) +//! 2. `cfg(false)` (inner cfg_attr applied) +//! 3. Function `f` is excluded from compilation +//! +//! Added in . + +#[cfg_attr(all(), cfg_attr(all(), cfg(false)))] +fn f() {} + +fn main() { + f() //~ ERROR cannot find function `f` in this scope +} diff --git a/tests/ui/nested-cfg-attrs.stderr b/tests/ui/cfg/nested-cfg-attr-conditional-compilation.stderr similarity index 61% rename from tests/ui/nested-cfg-attrs.stderr rename to tests/ui/cfg/nested-cfg-attr-conditional-compilation.stderr index 16c2930714353..ddb8ea1e13ae5 100644 --- a/tests/ui/nested-cfg-attrs.stderr +++ b/tests/ui/cfg/nested-cfg-attr-conditional-compilation.stderr @@ -1,8 +1,8 @@ error[E0425]: cannot find function `f` in this scope - --> $DIR/nested-cfg-attrs.rs:4:13 + --> $DIR/nested-cfg-attr-conditional-compilation.rs:17:5 | -LL | fn main() { f() } - | ^ not found in this scope +LL | f() + | ^ not found in this scope error: aborting due to 1 previous error diff --git a/tests/ui/closures/many-closures.rs b/tests/ui/closures/many-closures.rs new file mode 100644 index 0000000000000..c96ef5544c22e --- /dev/null +++ b/tests/ui/closures/many-closures.rs @@ -0,0 +1,47 @@ +//! Test that the compiler can handle code bases with a high number of closures. +//! This is particularly important for the MinGW toolchain which has a limit of +//! 2^15 weak symbols per binary. This test creates 2^12 closures (256 functions +//! with 16 closures each) to check the compiler handles this correctly. +//! +//! Regression test for . +//! See also . + +//@ run-pass + +// Make sure we don't optimize anything away: +//@ compile-flags: -C no-prepopulate-passes -Cpasses=name-anon-globals + +/// Macro for exponential expansion - creates 2^n copies of the given macro call +macro_rules! go_bacterial { + ($mac:ident) => ($mac!()); + ($mac:ident 1 $($t:tt)*) => ( + go_bacterial!($mac $($t)*); + go_bacterial!($mac $($t)*); + ) +} + +/// Creates and immediately calls a closure +macro_rules! create_closure { + () => { + (move || {})() + }; +} + +/// Creates a function containing 16 closures (2^4) +macro_rules! create_function_with_closures { + () => { + { + fn function_with_closures() { + // Create 16 closures using exponential expansion: 2^4 = 16 + go_bacterial!(create_closure 1 1 1 1); + } + let _ = function_with_closures(); + } + } +} + +fn main() { + // Create 2^8 = 256 functions, each containing 16 closures, + // resulting in 2^12 = 4096 closures total. + go_bacterial!(create_function_with_closures 1 1 1 1 1 1 1 1); +} diff --git a/tests/ui/fn/mutable-function-parameters.rs b/tests/ui/fn/mutable-function-parameters.rs new file mode 100644 index 0000000000000..5045a783f0492 --- /dev/null +++ b/tests/ui/fn/mutable-function-parameters.rs @@ -0,0 +1,24 @@ +//! Test that function and closure parameters marked as `mut` can be mutated +//! within the function body. + +//@ run-pass + +fn f(mut y: Box) { + *y = 5; + assert_eq!(*y, 5); +} + +fn g() { + let frob = |mut q: Box| { + *q = 2; + assert_eq!(*q, 2); + }; + let w = Box::new(37); + frob(w); +} + +pub fn main() { + let z = Box::new(17); + f(z); + g(); +} diff --git a/tests/ui/generics/generic-params-nested-fn-scope-error.rs b/tests/ui/generics/generic-params-nested-fn-scope-error.rs new file mode 100644 index 0000000000000..eaf514da33763 --- /dev/null +++ b/tests/ui/generics/generic-params-nested-fn-scope-error.rs @@ -0,0 +1,14 @@ +//! Test that generic parameters from an outer function are not accessible +//! in nested functions. + +fn foo(v: Vec) -> U { + fn bar(w: [U]) -> U { + //~^ ERROR can't use generic parameters from outer item + //~| ERROR can't use generic parameters from outer item + return w[0]; + } + + return bar(v); +} + +fn main() {} diff --git a/tests/ui/nested-ty-params.stderr b/tests/ui/generics/generic-params-nested-fn-scope-error.stderr similarity index 62% rename from tests/ui/nested-ty-params.stderr rename to tests/ui/generics/generic-params-nested-fn-scope-error.stderr index 7ca65b421b25f..7fd1069c651fa 100644 --- a/tests/ui/nested-ty-params.stderr +++ b/tests/ui/generics/generic-params-nested-fn-scope-error.stderr @@ -1,19 +1,19 @@ error[E0401]: can't use generic parameters from outer item - --> $DIR/nested-ty-params.rs:2:16 + --> $DIR/generic-params-nested-fn-scope-error.rs:5:16 | -LL | fn hd(v: Vec ) -> U { - | - type parameter from outer item -LL | fn hd1(w: [U]) -> U { return w[0]; } +LL | fn foo(v: Vec) -> U { + | - type parameter from outer item +LL | fn bar(w: [U]) -> U { | - ^ use of generic parameter from outer item | | | help: try introducing a local generic parameter here: `` error[E0401]: can't use generic parameters from outer item - --> $DIR/nested-ty-params.rs:2:23 + --> $DIR/generic-params-nested-fn-scope-error.rs:5:23 | -LL | fn hd(v: Vec ) -> U { - | - type parameter from outer item -LL | fn hd1(w: [U]) -> U { return w[0]; } +LL | fn foo(v: Vec) -> U { + | - type parameter from outer item +LL | fn bar(w: [U]) -> U { | - ^ use of generic parameter from outer item | | | help: try introducing a local generic parameter here: `` diff --git a/tests/ui/mut-function-arguments.rs b/tests/ui/mut-function-arguments.rs deleted file mode 100644 index 01c264fce0389..0000000000000 --- a/tests/ui/mut-function-arguments.rs +++ /dev/null @@ -1,19 +0,0 @@ -//@ run-pass - -fn f(mut y: Box) { - *y = 5; - assert_eq!(*y, 5); -} - -fn g() { - let frob = |mut q: Box| { *q = 2; assert_eq!(*q, 2); }; - let w = Box::new(37); - frob(w); - -} - -pub fn main() { - let z = Box::new(17); - f(z); - g(); -} diff --git a/tests/ui/mutual-recursion-group.rs b/tests/ui/mutual-recursion-group.rs deleted file mode 100644 index f83150af7dc85..0000000000000 --- a/tests/ui/mutual-recursion-group.rs +++ /dev/null @@ -1,15 +0,0 @@ -//@ run-pass - -#![allow(non_camel_case_types)] -#![allow(dead_code)] - - -enum colour { red, green, blue, } - -enum tree { children(Box), leaf(colour), } - -enum list { cons(Box, Box), nil, } - -enum small_list { kons(isize, Box), neel, } - -pub fn main() { } diff --git a/tests/ui/myriad-closures.rs b/tests/ui/myriad-closures.rs deleted file mode 100644 index 541d27d5de407..0000000000000 --- a/tests/ui/myriad-closures.rs +++ /dev/null @@ -1,39 +0,0 @@ -//@ run-pass -// This test case tests whether we can handle code bases that contain a high -// number of closures, something that needs special handling in the MingGW -// toolchain. -// See https://github.com/rust-lang/rust/issues/34793 for more information. - -// Make sure we don't optimize anything away: -//@ compile-flags: -C no-prepopulate-passes -Cpasses=name-anon-globals - -// Expand something exponentially -macro_rules! go_bacterial { - ($mac:ident) => ($mac!()); - ($mac:ident 1 $($t:tt)*) => ( - go_bacterial!($mac $($t)*); - go_bacterial!($mac $($t)*); - ) -} - -macro_rules! mk_closure { - () => ((move || {})()) -} - -macro_rules! mk_fn { - () => { - { - fn function() { - // Make 16 closures - go_bacterial!(mk_closure 1 1 1 1); - } - let _ = function(); - } - } -} - -fn main() { - // Make 2^8 functions, each containing 16 closures, - // resulting in 2^12 closures overall. - go_bacterial!(mk_fn 1 1 1 1 1 1 1 1); -} diff --git a/tests/ui/nested-block-comment.rs b/tests/ui/nested-block-comment.rs deleted file mode 100644 index 008df27e0e2a2..0000000000000 --- a/tests/ui/nested-block-comment.rs +++ /dev/null @@ -1,11 +0,0 @@ -//@ run-pass - -/* This test checks that nested comments are supported - - /* - This should not panic - */ -*/ - -pub fn main() { -} diff --git a/tests/ui/nested-cfg-attrs.rs b/tests/ui/nested-cfg-attrs.rs deleted file mode 100644 index 941807a84310e..0000000000000 --- a/tests/ui/nested-cfg-attrs.rs +++ /dev/null @@ -1,4 +0,0 @@ -#[cfg_attr(all(), cfg_attr(all(), cfg(false)))] -fn f() {} - -fn main() { f() } //~ ERROR cannot find function `f` in this scope diff --git a/tests/ui/nested-class.rs b/tests/ui/nested-class.rs deleted file mode 100644 index f84ab40dd1d41..0000000000000 --- a/tests/ui/nested-class.rs +++ /dev/null @@ -1,25 +0,0 @@ -//@ run-pass - -#![allow(non_camel_case_types)] - -pub fn main() { - struct b { - i: isize, - } - - impl b { - fn do_stuff(&self) -> isize { return 37; } - } - - fn b(i:isize) -> b { - b { - i: i - } - } - - // fn b(x:isize) -> isize { panic!(); } - - let z = b(42); - assert_eq!(z.i, 42); - assert_eq!(z.do_stuff(), 37); -} diff --git a/tests/ui/nested-ty-params.rs b/tests/ui/nested-ty-params.rs deleted file mode 100644 index c00c3bc337230..0000000000000 --- a/tests/ui/nested-ty-params.rs +++ /dev/null @@ -1,9 +0,0 @@ -fn hd(v: Vec ) -> U { - fn hd1(w: [U]) -> U { return w[0]; } - //~^ ERROR can't use generic parameters from outer item - //~| ERROR can't use generic parameters from outer item - - return hd1(v); -} - -fn main() {} diff --git a/tests/ui/parser/nested-block-comments.rs b/tests/ui/parser/nested-block-comments.rs new file mode 100644 index 0000000000000..8fe778963619c --- /dev/null +++ b/tests/ui/parser/nested-block-comments.rs @@ -0,0 +1,34 @@ +//! Test that nested block comments are properly supported by the parser. +//! +//! See . + +//@ run-pass + +/* This test checks that nested comments are supported + + /* This is a nested comment + /* And this is even more deeply nested */ + Back to the first level of nesting + */ + + /* Another nested comment at the same level */ +*/ + +/* Additional test cases for nested comments */ + +#[rustfmt::skip] +/* + /* Level 1 + /* Level 2 + /* Level 3 */ + */ + */ +*/ + +pub fn main() { + // Check that code after nested comments works correctly + let _x = 42; + + /* Even inline /* nested */ comments work */ + let _y = /* nested /* comment */ test */ 100; +} diff --git a/tests/ui/resolve/resolve-same-name-struct.rs b/tests/ui/resolve/resolve-same-name-struct.rs new file mode 100644 index 0000000000000..1bea0938e3da0 --- /dev/null +++ b/tests/ui/resolve/resolve-same-name-struct.rs @@ -0,0 +1,29 @@ +//! Test that name resolution works correctly when a struct and its constructor +//! function have the same name within a nested scope. This checks that the +//! compiler can distinguish between type names and value names in the same +//! namespace. + +//@ run-pass + +struct Point { + i: isize, +} + +impl Point { + fn get_value(&self) -> isize { + return 37; + } +} + +// Constructor function with the same name as the struct +#[allow(non_snake_case)] +fn Point(i: isize) -> Point { + Point { i } +} + +pub fn main() { + // Test that we can use the constructor function + let point = Point(42); + assert_eq!(point.i, 42); + assert_eq!(point.get_value(), 37); +} diff --git a/tests/ui/type/mutually-recursive-types.rs b/tests/ui/type/mutually-recursive-types.rs new file mode 100644 index 0000000000000..5472e1582218e --- /dev/null +++ b/tests/ui/type/mutually-recursive-types.rs @@ -0,0 +1,47 @@ +//! Test that mutually recursive type definitions are properly handled by the compiler. +//! This checks that types can reference each other in their definitions through +//! `Box` indirection, creating cycles in the type dependency graph. + +//@ run-pass + +#[derive(Debug, PartialEq)] +enum Colour { + Red, + Green, + Blue, +} + +#[derive(Debug, PartialEq)] +enum Tree { + Children(Box), + Leaf(Colour), +} + +#[derive(Debug, PartialEq)] +enum List { + Cons(Box, Box), + Nil, +} + +#[derive(Debug, PartialEq)] +enum SmallList { + Kons(isize, Box), + Neel, +} + +pub fn main() { + // Construct and test all variants of Colour + let _ = Tree::Leaf(Colour::Red); + + let _ = Tree::Leaf(Colour::Green); + + let _ = Tree::Leaf(Colour::Blue); + + let _ = List::Nil; + + let _ = Tree::Children(Box::new(List::Nil)); + + let _ = List::Cons(Box::new(Tree::Leaf(Colour::Blue)), Box::new(List::Nil)); + + let _ = SmallList::Kons(42, Box::new(SmallList::Neel)); +}