Skip to content

Commit f107252

Browse files
Rollup merge of #143202 - Kivooeo:tf18, r=tgross35
`tests/ui`: A New Order [18/N] > [!NOTE] > > Intermediate commits are intended to help review, but will be squashed prior to merge. Some `tests/ui/` housekeeping, to trim down number of tests directly under `tests/ui/`. Part of #133895. r? `@tgross35`
2 parents 2f119da + f12120d commit f107252

16 files changed

+224
-133
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//! Test that nested `cfg_attr` attributes work correctly for conditional compilation.
2+
//! This checks that `cfg_attr` can be arbitrarily deeply nested and that the
3+
//! expansion works from outside to inside, eventually applying the innermost
4+
//! conditional compilation directive.
5+
//!
6+
//! In this test, `cfg_attr(all(), cfg_attr(all(), cfg(false)))` should expand to:
7+
//! 1. `cfg_attr(all(), cfg(false))` (outer cfg_attr applied)
8+
//! 2. `cfg(false)` (inner cfg_attr applied)
9+
//! 3. Function `f` is excluded from compilation
10+
//!
11+
//! Added in <https://github.com/rust-lang/rust/pull/34216>.
12+
13+
#[cfg_attr(all(), cfg_attr(all(), cfg(false)))]
14+
fn f() {}
15+
16+
fn main() {
17+
f() //~ ERROR cannot find function `f` in this scope
18+
}

tests/ui/nested-cfg-attrs.stderr renamed to tests/ui/cfg/nested-cfg-attr-conditional-compilation.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0425]: cannot find function `f` in this scope
2-
--> $DIR/nested-cfg-attrs.rs:4:13
2+
--> $DIR/nested-cfg-attr-conditional-compilation.rs:17:5
33
|
4-
LL | fn main() { f() }
5-
| ^ not found in this scope
4+
LL | f()
5+
| ^ not found in this scope
66

77
error: aborting due to 1 previous error
88

tests/ui/closures/many-closures.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//! Test that the compiler can handle code bases with a high number of closures.
2+
//! This is particularly important for the MinGW toolchain which has a limit of
3+
//! 2^15 weak symbols per binary. This test creates 2^12 closures (256 functions
4+
//! with 16 closures each) to check the compiler handles this correctly.
5+
//!
6+
//! Regression test for <https://github.com/rust-lang/rust/issues/34793>.
7+
//! See also <https://github.com/rust-lang/rust/pull/34830>.
8+
9+
//@ run-pass
10+
11+
// Make sure we don't optimize anything away:
12+
//@ compile-flags: -C no-prepopulate-passes -Cpasses=name-anon-globals
13+
14+
/// Macro for exponential expansion - creates 2^n copies of the given macro call
15+
macro_rules! go_bacterial {
16+
($mac:ident) => ($mac!());
17+
($mac:ident 1 $($t:tt)*) => (
18+
go_bacterial!($mac $($t)*);
19+
go_bacterial!($mac $($t)*);
20+
)
21+
}
22+
23+
/// Creates and immediately calls a closure
24+
macro_rules! create_closure {
25+
() => {
26+
(move || {})()
27+
};
28+
}
29+
30+
/// Creates a function containing 16 closures (2^4)
31+
macro_rules! create_function_with_closures {
32+
() => {
33+
{
34+
fn function_with_closures() {
35+
// Create 16 closures using exponential expansion: 2^4 = 16
36+
go_bacterial!(create_closure 1 1 1 1);
37+
}
38+
let _ = function_with_closures();
39+
}
40+
}
41+
}
42+
43+
fn main() {
44+
// Create 2^8 = 256 functions, each containing 16 closures,
45+
// resulting in 2^12 = 4096 closures total.
46+
go_bacterial!(create_function_with_closures 1 1 1 1 1 1 1 1);
47+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//! Test that function and closure parameters marked as `mut` can be mutated
2+
//! within the function body.
3+
4+
//@ run-pass
5+
6+
fn f(mut y: Box<isize>) {
7+
*y = 5;
8+
assert_eq!(*y, 5);
9+
}
10+
11+
fn g() {
12+
let frob = |mut q: Box<isize>| {
13+
*q = 2;
14+
assert_eq!(*q, 2);
15+
};
16+
let w = Box::new(37);
17+
frob(w);
18+
}
19+
20+
pub fn main() {
21+
let z = Box::new(17);
22+
f(z);
23+
g();
24+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//! Test that generic parameters from an outer function are not accessible
2+
//! in nested functions.
3+
4+
fn foo<U>(v: Vec<U>) -> U {
5+
fn bar(w: [U]) -> U {
6+
//~^ ERROR can't use generic parameters from outer item
7+
//~| ERROR can't use generic parameters from outer item
8+
return w[0];
9+
}
10+
11+
return bar(v);
12+
}
13+
14+
fn main() {}

tests/ui/nested-ty-params.stderr renamed to tests/ui/generics/generic-params-nested-fn-scope-error.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
error[E0401]: can't use generic parameters from outer item
2-
--> $DIR/nested-ty-params.rs:2:16
2+
--> $DIR/generic-params-nested-fn-scope-error.rs:5:16
33
|
4-
LL | fn hd<U>(v: Vec<U> ) -> U {
5-
| - type parameter from outer item
6-
LL | fn hd1(w: [U]) -> U { return w[0]; }
4+
LL | fn foo<U>(v: Vec<U>) -> U {
5+
| - type parameter from outer item
6+
LL | fn bar(w: [U]) -> U {
77
| - ^ use of generic parameter from outer item
88
| |
99
| help: try introducing a local generic parameter here: `<U>`
1010

1111
error[E0401]: can't use generic parameters from outer item
12-
--> $DIR/nested-ty-params.rs:2:23
12+
--> $DIR/generic-params-nested-fn-scope-error.rs:5:23
1313
|
14-
LL | fn hd<U>(v: Vec<U> ) -> U {
15-
| - type parameter from outer item
16-
LL | fn hd1(w: [U]) -> U { return w[0]; }
14+
LL | fn foo<U>(v: Vec<U>) -> U {
15+
| - type parameter from outer item
16+
LL | fn bar(w: [U]) -> U {
1717
| - ^ use of generic parameter from outer item
1818
| |
1919
| help: try introducing a local generic parameter here: `<U>`

tests/ui/mut-function-arguments.rs

Lines changed: 0 additions & 19 deletions
This file was deleted.

tests/ui/mutual-recursion-group.rs

Lines changed: 0 additions & 15 deletions
This file was deleted.

tests/ui/myriad-closures.rs

Lines changed: 0 additions & 39 deletions
This file was deleted.

tests/ui/nested-block-comment.rs

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)