Skip to content

tests/ui: A New Order [19/N] #143210

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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions tests/ui/closures/basic-closure-syntax.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//! Test basic closure syntax and usage with generic functions.
//!
//! This test checks that closure syntax works correctly for:
//! - Closures with parameters and return values
//! - Closures without parameters (both expression and block forms)
//! - Integration with generic functions and FnOnce trait bounds

//@ run-pass

fn f<F>(i: isize, f: F) -> isize
where
F: FnOnce(isize) -> isize,
{
f(i)
}

fn g<G>(_g: G)
where
G: FnOnce(),
{
}

pub fn main() {
// Closure with parameter that returns the same value
assert_eq!(f(10, |a| a), 10);

// Closure without parameters - expression form
g(|| ());

// Test closure reuse in generic context
assert_eq!(f(10, |a| a), 10);

// Closure without parameters - block form
g(|| {});
}
32 changes: 32 additions & 0 deletions tests/ui/generics/newtype-with-generics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//! Test newtype pattern with generic parameters.

//@ run-pass

#[derive(Clone)]
struct MyVec<T>(Vec<T>);

fn extract_inner_vec<T: Clone>(wrapper: MyVec<T>) -> Vec<T> {
let MyVec(inner_vec) = wrapper;
inner_vec.clone()
}

fn get_first_element<T>(wrapper: MyVec<T>) -> T {
let MyVec(inner_vec) = wrapper;
inner_vec.into_iter().next().unwrap()
}

pub fn main() {
let my_vec = MyVec(vec![1, 2, 3]);
let cloned_vec = my_vec.clone();

// Test extracting inner vector
let extracted = extract_inner_vec(cloned_vec);
assert_eq!(extracted[1], 2);

// Test getting first element
assert_eq!(get_first_element(my_vec.clone()), 1);

// Test direct destructuring
let MyVec(inner) = my_vec;
assert_eq!(inner[2], 3);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
//! Test basic trait implementation syntax for both simple and generic types.

//@ run-pass

use std::fmt;

struct Thingy {
x: isize,
y: isize
y: isize,
}

impl fmt::Debug for Thingy {
Expand All @@ -14,10 +16,10 @@ impl fmt::Debug for Thingy {
}

struct PolymorphicThingy<T> {
x: T
x: T,
}

impl<T:fmt::Debug> fmt::Debug for PolymorphicThingy<T> {
impl<T: fmt::Debug> fmt::Debug for PolymorphicThingy<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", self.x)
}
Expand Down
5 changes: 0 additions & 5 deletions tests/ui/new-import-syntax.rs

This file was deleted.

7 changes: 0 additions & 7 deletions tests/ui/new-style-constants.rs

This file was deleted.

14 changes: 0 additions & 14 deletions tests/ui/newlambdas.rs

This file was deleted.

27 changes: 0 additions & 27 deletions tests/ui/newtype-polymorphic.rs

This file was deleted.

23 changes: 0 additions & 23 deletions tests/ui/newtype.rs

This file was deleted.

18 changes: 0 additions & 18 deletions tests/ui/no_send-enum.rs

This file was deleted.

23 changes: 0 additions & 23 deletions tests/ui/no_send-enum.stderr

This file was deleted.

9 changes: 0 additions & 9 deletions tests/ui/no_send-rc.rs

This file was deleted.

22 changes: 0 additions & 22 deletions tests/ui/no_send-rc.stderr

This file was deleted.

16 changes: 0 additions & 16 deletions tests/ui/no_share-enum.rs

This file was deleted.

23 changes: 0 additions & 23 deletions tests/ui/no_share-enum.stderr

This file was deleted.

14 changes: 0 additions & 14 deletions tests/ui/no_share-struct.rs

This file was deleted.

18 changes: 0 additions & 18 deletions tests/ui/no_share-struct.stderr

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
//! Test ES6-style Unicode escape sequences in string literals.
//!
//! Regression test for RFC 446 implementation.
//! See <https://github.com/rust-lang/rust/pull/19480>.

//@ run-pass

pub fn main() {
// Basic Unicode escape - snowman character
let s = "\u{2603}";
assert_eq!(s, "☃");

Expand Down
25 changes: 25 additions & 0 deletions tests/ui/structs/basic-newtype-pattern.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//! Test basic newtype pattern functionality.

//@ run-pass

#[derive(Copy, Clone)]
struct Counter(CounterData);

#[derive(Copy, Clone)]
struct CounterData {
compute: fn(Counter) -> isize,
val: isize,
}

fn compute_value(counter: Counter) -> isize {
let Counter(data) = counter;
data.val + 20
}

pub fn main() {
let my_counter = Counter(CounterData { compute: compute_value, val: 30 });

// Test destructuring and function pointer call
let Counter(data) = my_counter;
assert_eq!((data.compute)(my_counter), 50);
}
22 changes: 22 additions & 0 deletions tests/ui/traits/enum-negative-send-impl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//! Test that enums inherit Send/!Send properties from their variants.
//!
//! Uses the unstable `negative_impls` feature to explicitly opt-out of Send.
#![feature(negative_impls)]

use std::marker::Send;

struct NoSend;
impl !Send for NoSend {}

enum Container {
WithNoSend(NoSend),
}

fn requires_send<T: Send>(_: T) {}

fn main() {
let container = Container::WithNoSend(NoSend);
requires_send(container);
//~^ ERROR `NoSend` cannot be sent between threads safely
}
Loading
Loading