Skip to content

tests/ui: A New Order [18/N] #143202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions tests/ui/cfg/nested-cfg-attr-conditional-compilation.rs
Original file line number Diff line number Diff line change
@@ -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 <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
}
Original file line number Diff line number Diff line change
@@ -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

Expand Down
47 changes: 47 additions & 0 deletions tests/ui/closures/many-closures.rs
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/rust-lang/rust/issues/34793>.
//! See also <https://github.com/rust-lang/rust/pull/34830>.

//@ 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);
}
24 changes: 24 additions & 0 deletions tests/ui/fn/mutable-function-parameters.rs
Original file line number Diff line number Diff line change
@@ -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<isize>) {
*y = 5;
assert_eq!(*y, 5);
}

fn g() {
let frob = |mut q: Box<isize>| {
*q = 2;
assert_eq!(*q, 2);
};
let w = Box::new(37);
frob(w);
}

pub fn main() {
let z = Box::new(17);
f(z);
g();
}
14 changes: 14 additions & 0 deletions tests/ui/generics/generic-params-nested-fn-scope-error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//! Test that generic parameters from an outer function are not accessible
//! in nested functions.

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() {}
Original file line number Diff line number Diff line change
@@ -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>`
Expand Down
19 changes: 0 additions & 19 deletions tests/ui/mut-function-arguments.rs

This file was deleted.

15 changes: 0 additions & 15 deletions tests/ui/mutual-recursion-group.rs

This file was deleted.

39 changes: 0 additions & 39 deletions tests/ui/myriad-closures.rs

This file was deleted.

11 changes: 0 additions & 11 deletions tests/ui/nested-block-comment.rs

This file was deleted.

4 changes: 0 additions & 4 deletions tests/ui/nested-cfg-attrs.rs

This file was deleted.

25 changes: 0 additions & 25 deletions tests/ui/nested-class.rs

This file was deleted.

9 changes: 0 additions & 9 deletions tests/ui/nested-ty-params.rs

This file was deleted.

34 changes: 34 additions & 0 deletions tests/ui/parser/nested-block-comments.rs
Original file line number Diff line number Diff line change
@@ -0,0 +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 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;
}
29 changes: 29 additions & 0 deletions tests/ui/resolve/resolve-same-name-struct.rs
Original file line number Diff line number Diff line change
@@ -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);
}
47 changes: 47 additions & 0 deletions tests/ui/type/mutually-recursive-types.rs
Original file line number Diff line number Diff line change
@@ -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<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);

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));
}
Loading