From 6ca9b43ea9f50d5e77dc0f8d4d62283017b3f1b0 Mon Sep 17 00:00:00 2001 From: Kivooeo Date: Sun, 29 Jun 2025 21:04:41 +0500 Subject: [PATCH 1/2] moved test files --- .../nested-cfg-attr-conditional-compilation.rs} | 0 .../nested-cfg-attr-conditional-compilation.stderr} | 0 tests/ui/{myriad-closures.rs => closures/many-closures.rs} | 0 .../mutable-function-parameters.rs} | 0 .../generic-params-nested-fn-scope-error.rs} | 0 .../generic-params-nested-fn-scope-error.stderr} | 0 .../{nested-block-comment.rs => parser/nested-block-comments.rs} | 0 tests/ui/{nested-class.rs => resolve/resolve-same-name-struct.rs} | 0 .../mutually-recursive-types.rs} | 0 9 files changed, 0 insertions(+), 0 deletions(-) rename tests/ui/{nested-cfg-attrs.rs => cfg/nested-cfg-attr-conditional-compilation.rs} (100%) rename tests/ui/{nested-cfg-attrs.stderr => cfg/nested-cfg-attr-conditional-compilation.stderr} (100%) rename tests/ui/{myriad-closures.rs => closures/many-closures.rs} (100%) rename tests/ui/{mut-function-arguments.rs => fn/mutable-function-parameters.rs} (100%) rename tests/ui/{nested-ty-params.rs => generics/generic-params-nested-fn-scope-error.rs} (100%) rename tests/ui/{nested-ty-params.stderr => generics/generic-params-nested-fn-scope-error.stderr} (100%) rename tests/ui/{nested-block-comment.rs => parser/nested-block-comments.rs} (100%) rename tests/ui/{nested-class.rs => resolve/resolve-same-name-struct.rs} (100%) rename tests/ui/{mutual-recursion-group.rs => type/mutually-recursive-types.rs} (100%) diff --git a/tests/ui/nested-cfg-attrs.rs b/tests/ui/cfg/nested-cfg-attr-conditional-compilation.rs similarity index 100% rename from tests/ui/nested-cfg-attrs.rs rename to tests/ui/cfg/nested-cfg-attr-conditional-compilation.rs diff --git a/tests/ui/nested-cfg-attrs.stderr b/tests/ui/cfg/nested-cfg-attr-conditional-compilation.stderr similarity index 100% rename from tests/ui/nested-cfg-attrs.stderr rename to tests/ui/cfg/nested-cfg-attr-conditional-compilation.stderr diff --git a/tests/ui/myriad-closures.rs b/tests/ui/closures/many-closures.rs similarity index 100% rename from tests/ui/myriad-closures.rs rename to tests/ui/closures/many-closures.rs diff --git a/tests/ui/mut-function-arguments.rs b/tests/ui/fn/mutable-function-parameters.rs similarity index 100% rename from tests/ui/mut-function-arguments.rs rename to tests/ui/fn/mutable-function-parameters.rs diff --git a/tests/ui/nested-ty-params.rs b/tests/ui/generics/generic-params-nested-fn-scope-error.rs similarity index 100% rename from tests/ui/nested-ty-params.rs rename to tests/ui/generics/generic-params-nested-fn-scope-error.rs diff --git a/tests/ui/nested-ty-params.stderr b/tests/ui/generics/generic-params-nested-fn-scope-error.stderr similarity index 100% rename from tests/ui/nested-ty-params.stderr rename to tests/ui/generics/generic-params-nested-fn-scope-error.stderr diff --git a/tests/ui/nested-block-comment.rs b/tests/ui/parser/nested-block-comments.rs similarity index 100% rename from tests/ui/nested-block-comment.rs rename to tests/ui/parser/nested-block-comments.rs diff --git a/tests/ui/nested-class.rs b/tests/ui/resolve/resolve-same-name-struct.rs similarity index 100% rename from tests/ui/nested-class.rs rename to tests/ui/resolve/resolve-same-name-struct.rs diff --git a/tests/ui/mutual-recursion-group.rs b/tests/ui/type/mutually-recursive-types.rs similarity index 100% rename from tests/ui/mutual-recursion-group.rs rename to tests/ui/type/mutually-recursive-types.rs From f12120d2bd237ffbf03c8de027513a8d0bc63616 Mon Sep 17 00:00:00 2001 From: Kivooeo Date: Sun, 29 Jun 2025 21:05:19 +0500 Subject: [PATCH 2/2] cleaned up some tests --- ...nested-cfg-attr-conditional-compilation.rs | 16 ++++++- ...ed-cfg-attr-conditional-compilation.stderr | 6 +-- tests/ui/closures/many-closures.rs | 38 +++++++++------ tests/ui/fn/mutable-function-parameters.rs | 9 +++- .../generic-params-nested-fn-scope-error.rs | 15 ++++-- ...eneric-params-nested-fn-scope-error.stderr | 16 +++---- tests/ui/parser/nested-block-comments.rs | 27 ++++++++++- tests/ui/resolve/resolve-same-name-struct.rs | 40 ++++++++-------- tests/ui/type/mutually-recursive-types.rs | 46 ++++++++++++++++--- 9 files changed, 152 insertions(+), 61 deletions(-) diff --git a/tests/ui/cfg/nested-cfg-attr-conditional-compilation.rs b/tests/ui/cfg/nested-cfg-attr-conditional-compilation.rs index 941807a84310e..7618e83a64290 100644 --- a/tests/ui/cfg/nested-cfg-attr-conditional-compilation.rs +++ b/tests/ui/cfg/nested-cfg-attr-conditional-compilation.rs @@ -1,4 +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 +fn main() { + f() //~ ERROR cannot find function `f` in this scope +} diff --git a/tests/ui/cfg/nested-cfg-attr-conditional-compilation.stderr b/tests/ui/cfg/nested-cfg-attr-conditional-compilation.stderr index 16c2930714353..ddb8ea1e13ae5 100644 --- a/tests/ui/cfg/nested-cfg-attr-conditional-compilation.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 index 541d27d5de407..c96ef5544c22e 100644 --- a/tests/ui/closures/many-closures.rs +++ b/tests/ui/closures/many-closures.rs @@ -1,13 +1,17 @@ +//! 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 -// 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 for exponential expansion - creates 2^n copies of the given macro call macro_rules! go_bacterial { ($mac:ident) => ($mac!()); ($mac:ident 1 $($t:tt)*) => ( @@ -16,24 +20,28 @@ macro_rules! go_bacterial { ) } -macro_rules! mk_closure { - () => ((move || {})()) +/// Creates and immediately calls a closure +macro_rules! create_closure { + () => { + (move || {})() + }; } -macro_rules! mk_fn { +/// Creates a function containing 16 closures (2^4) +macro_rules! create_function_with_closures { () => { { - fn function() { - // Make 16 closures - go_bacterial!(mk_closure 1 1 1 1); + fn function_with_closures() { + // Create 16 closures using exponential expansion: 2^4 = 16 + go_bacterial!(create_closure 1 1 1 1); } - let _ = function(); + let _ = function_with_closures(); } } } 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); + // 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 index 01c264fce0389..5045a783f0492 100644 --- a/tests/ui/fn/mutable-function-parameters.rs +++ b/tests/ui/fn/mutable-function-parameters.rs @@ -1,3 +1,6 @@ +//! Test that function and closure parameters marked as `mut` can be mutated +//! within the function body. + //@ run-pass fn f(mut y: Box) { @@ -6,10 +9,12 @@ fn f(mut y: Box) { } fn g() { - let frob = |mut q: Box| { *q = 2; assert_eq!(*q, 2); }; + let frob = |mut q: Box| { + *q = 2; + assert_eq!(*q, 2); + }; let w = Box::new(37); frob(w); - } pub fn main() { diff --git a/tests/ui/generics/generic-params-nested-fn-scope-error.rs b/tests/ui/generics/generic-params-nested-fn-scope-error.rs index c00c3bc337230..eaf514da33763 100644 --- a/tests/ui/generics/generic-params-nested-fn-scope-error.rs +++ b/tests/ui/generics/generic-params-nested-fn-scope-error.rs @@ -1,9 +1,14 @@ -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 +//! Test that generic parameters from an outer function are not accessible +//! in nested functions. - return hd1(v); +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/generics/generic-params-nested-fn-scope-error.stderr b/tests/ui/generics/generic-params-nested-fn-scope-error.stderr index 7ca65b421b25f..7fd1069c651fa 100644 --- a/tests/ui/generics/generic-params-nested-fn-scope-error.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/parser/nested-block-comments.rs b/tests/ui/parser/nested-block-comments.rs index 008df27e0e2a2..8fe778963619c 100644 --- a/tests/ui/parser/nested-block-comments.rs +++ b/tests/ui/parser/nested-block-comments.rs @@ -1,11 +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 should not panic + /* 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 index f84ab40dd1d41..1bea0938e3da0 100644 --- a/tests/ui/resolve/resolve-same-name-struct.rs +++ b/tests/ui/resolve/resolve-same-name-struct.rs @@ -1,25 +1,29 @@ -//@ run-pass - -#![allow(non_camel_case_types)] +//! 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. -pub fn main() { - struct b { - i: isize, - } +//@ run-pass - impl b { - fn do_stuff(&self) -> isize { return 37; } - } +struct Point { + i: isize, +} - fn b(i:isize) -> b { - b { - i: i - } +impl Point { + fn get_value(&self) -> isize { + return 37; } +} - // fn b(x:isize) -> isize { panic!(); } +// Constructor function with the same name as the struct +#[allow(non_snake_case)] +fn Point(i: isize) -> Point { + Point { i } +} - let z = b(42); - assert_eq!(z.i, 42); - assert_eq!(z.do_stuff(), 37); +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 index f83150af7dc85..5472e1582218e 100644 --- a/tests/ui/type/mutually-recursive-types.rs +++ b/tests/ui/type/mutually-recursive-types.rs @@ -1,15 +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 -#![allow(non_camel_case_types)] -#![allow(dead_code)] +#[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); -enum colour { red, green, blue, } + let _ = Tree::Leaf(Colour::Blue); -enum tree { children(Box), leaf(colour), } + let _ = List::Nil; -enum list { cons(Box, Box), nil, } + let _ = Tree::Children(Box::new(List::Nil)); -enum small_list { kons(isize, Box), neel, } + let _ = List::Cons(Box::new(Tree::Leaf(Colour::Blue)), Box::new(List::Nil)); -pub fn main() { } + let _ = SmallList::Kons(42, Box::new(SmallList::Neel)); +}