about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorKivooeo <Kivooeo123@gmail.com>2025-06-29 21:05:19 +0500
committerKivooeo <Kivooeo123@gmail.com>2025-07-01 15:29:29 +0500
commitf12120d2bd237ffbf03c8de027513a8d0bc63616 (patch)
tree3350a7cbd9079d31f145865734ed4de151c91133 /tests
parent6ca9b43ea9f50d5e77dc0f8d4d62283017b3f1b0 (diff)
downloadrust-f12120d2bd237ffbf03c8de027513a8d0bc63616.tar.gz
rust-f12120d2bd237ffbf03c8de027513a8d0bc63616.zip
cleaned up some tests
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/cfg/nested-cfg-attr-conditional-compilation.rs16
-rw-r--r--tests/ui/cfg/nested-cfg-attr-conditional-compilation.stderr6
-rw-r--r--tests/ui/closures/many-closures.rs38
-rw-r--r--tests/ui/fn/mutable-function-parameters.rs9
-rw-r--r--tests/ui/generics/generic-params-nested-fn-scope-error.rs15
-rw-r--r--tests/ui/generics/generic-params-nested-fn-scope-error.stderr16
-rw-r--r--tests/ui/parser/nested-block-comments.rs27
-rw-r--r--tests/ui/resolve/resolve-same-name-struct.rs40
-rw-r--r--tests/ui/type/mutually-recursive-types.rs46
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 941807a8431..7618e83a642 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 <https://github.com/rust-lang/rust/pull/34216>.
+
 #[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 16c29307143..ddb8ea1e13a 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 541d27d5de4..c96ef5544c2 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 <https://github.com/rust-lang/rust/issues/34793>.
+//! See also <https://github.com/rust-lang/rust/pull/34830>.
+
 //@ 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 01c264fce03..5045a783f04 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<isize>) {
@@ -6,10 +9,12 @@ fn f(mut y: Box<isize>) {
 }
 
 fn g() {
-    let frob = |mut q: Box<isize>| { *q = 2; assert_eq!(*q, 2); };
+    let frob = |mut q: Box<isize>| {
+        *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 c00c3bc3372..eaf514da337 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<U>(v: Vec<U> ) -> 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<U>(v: Vec<U>) -> 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 7ca65b421b2..7fd1069c651 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<U>(v: Vec<U> ) -> U {
-   |       - type parameter from outer item
-LL |     fn hd1(w: [U]) -> U { return w[0]; }
+LL | fn foo<U>(v: Vec<U>) -> 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: `<U>`
 
 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<U>(v: Vec<U> ) -> U {
-   |       - type parameter from outer item
-LL |     fn hd1(w: [U]) -> U { return w[0]; }
+LL | fn foo<U>(v: Vec<U>) -> 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: `<U>`
diff --git a/tests/ui/parser/nested-block-comments.rs b/tests/ui/parser/nested-block-comments.rs
index 008df27e0e2..8fe77896361 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 <https://github.com/rust-lang/rust/issues/66>.
+
 //@ 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 f84ab40dd1d..1bea0938e3d 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 f83150af7dc..5472e158221 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<List>),
+    Leaf(Colour),
+}
+
+#[derive(Debug, PartialEq)]
+enum List {
+    Cons(Box<Tree>, Box<List>),
+    Nil,
+}
+
+#[derive(Debug, PartialEq)]
+enum SmallList {
+    Kons(isize, Box<SmallList>),
+    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<list>), leaf(colour), }
+    let _ = List::Nil;
 
-enum list { cons(Box<tree>, Box<list>), nil, }
+    let _ = Tree::Children(Box::new(List::Nil));
 
-enum small_list { kons(isize, Box<small_list>), 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));
+}