Skip to content

Commit bf5910d

Browse files
committed
cleaned up some tests
1 parent 4b6c3d9 commit bf5910d

13 files changed

+152
-97
lines changed
Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,35 @@
1-
//@ run-pass
2-
// Tests for the new |args| expr lambda syntax
1+
//! Test basic closure syntax and usage with generic functions.
2+
//!
3+
//! This test checks that closure syntax works correctly for:
4+
//! - Closures with parameters and return values
5+
//! - Closures without parameters (both expression and block forms)
6+
//! - Integration with generic functions and FnOnce trait bounds
37
8+
//@ run-pass
49

5-
fn f<F>(i: isize, f: F) -> isize where F: FnOnce(isize) -> isize { f(i) }
10+
fn f<F>(i: isize, f: F) -> isize
11+
where
12+
F: FnOnce(isize) -> isize,
13+
{
14+
f(i)
15+
}
616

7-
fn g<G>(_g: G) where G: FnOnce() { }
17+
fn g<G>(_g: G)
18+
where
19+
G: FnOnce(),
20+
{
21+
}
822

923
pub fn main() {
24+
// Closure with parameter that returns the same value
1025
assert_eq!(f(10, |a| a), 10);
11-
g(||());
26+
27+
// Closure without parameters - expression form
28+
g(|| ());
29+
30+
// Test closure reuse in generic context
1231
assert_eq!(f(10, |a| a), 10);
13-
g(||{});
32+
33+
// Closure without parameters - block form
34+
g(|| {});
1435
}
Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
1-
//@ run-pass
2-
3-
#![allow(non_camel_case_types)]
1+
//! Test newtype pattern with generic parameters.
42
3+
//@ run-pass
54

65
#[derive(Clone)]
7-
struct myvec<X>(Vec<X> );
6+
struct MyVec<T>(Vec<T>);
87

9-
fn myvec_deref<X:Clone>(mv: myvec<X>) -> Vec<X> {
10-
let myvec(v) = mv;
11-
return v.clone();
8+
fn extract_inner_vec<T: Clone>(wrapper: MyVec<T>) -> Vec<T> {
9+
let MyVec(inner_vec) = wrapper;
10+
inner_vec.clone()
1211
}
1312

14-
fn myvec_elt<X>(mv: myvec<X>) -> X {
15-
let myvec(v) = mv;
16-
return v.into_iter().next().unwrap();
13+
fn get_first_element<T>(wrapper: MyVec<T>) -> T {
14+
let MyVec(inner_vec) = wrapper;
15+
inner_vec.into_iter().next().unwrap()
1716
}
1817

1918
pub fn main() {
20-
let mv = myvec(vec![1, 2, 3]);
21-
let mv_clone = mv.clone();
22-
let mv_clone = myvec_deref(mv_clone);
23-
assert_eq!(mv_clone[1], 2);
24-
assert_eq!(myvec_elt(mv.clone()), 1);
25-
let myvec(v) = mv;
26-
assert_eq!(v[2], 3);
19+
let my_vec = MyVec(vec![1, 2, 3]);
20+
let cloned_vec = my_vec.clone();
21+
22+
// Test extracting inner vector
23+
let extracted = extract_inner_vec(cloned_vec);
24+
assert_eq!(extracted[1], 2);
25+
26+
// Test getting first element
27+
assert_eq!(get_first_element(my_vec.clone()), 1);
28+
29+
// Test direct destructuring
30+
let MyVec(inner) = my_vec;
31+
assert_eq!(inner[2], 3);
2732
}

tests/ui/impl-trait/basic-trait-impl.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
//! Test basic trait implementation syntax for both simple and generic types.
2+
13
//@ run-pass
24

35
use std::fmt;
46

57
struct Thingy {
68
x: isize,
7-
y: isize
9+
y: isize,
810
}
911

1012
impl fmt::Debug for Thingy {
@@ -14,10 +16,10 @@ impl fmt::Debug for Thingy {
1416
}
1517

1618
struct PolymorphicThingy<T> {
17-
x: T
19+
x: T,
1820
}
1921

20-
impl<T:fmt::Debug> fmt::Debug for PolymorphicThingy<T> {
22+
impl<T: fmt::Debug> fmt::Debug for PolymorphicThingy<T> {
2123
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2224
write!(f, "{:?}", self.x)
2325
}

tests/ui/parser/unicode-escape-sequences.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
//! Test ES6-style Unicode escape sequences in string literals.
2+
//!
3+
//! Regression test for RFC 446 implementation.
4+
//! See <https://github.com/rust-lang/rust/pull/19480>.
5+
16
//@ run-pass
27

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1+
//! Test basic newtype pattern functionality.
2+
13
//@ run-pass
24

3-
#![allow(non_camel_case_types)]
45
#[derive(Copy, Clone)]
5-
struct mytype(Mytype);
6+
struct Counter(CounterData);
67

78
#[derive(Copy, Clone)]
8-
struct Mytype {
9-
compute: fn(mytype) -> isize,
9+
struct CounterData {
10+
compute: fn(Counter) -> isize,
1011
val: isize,
1112
}
1213

13-
fn compute(i: mytype) -> isize {
14-
let mytype(m) = i;
15-
return m.val + 20;
14+
fn compute_value(counter: Counter) -> isize {
15+
let Counter(data) = counter;
16+
data.val + 20
1617
}
1718

1819
pub fn main() {
19-
let myval = mytype(Mytype{compute: compute, val: 30});
20-
println!("{}", compute(myval));
21-
let mytype(m) = myval;
22-
assert_eq!((m.compute)(myval), 50);
20+
let my_counter = Counter(CounterData { compute: compute_value, val: 30 });
21+
22+
// Test destructuring and function pointer call
23+
let Counter(data) = my_counter;
24+
assert_eq!((data.compute)(my_counter), 50);
2325
}
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1+
//! Test that enums inherit Send/!Send properties from their variants.
2+
//!
3+
//! Uses the unstable `negative_impls` feature to explicitly opt-out of Send.
4+
15
#![feature(negative_impls)]
26

37
use std::marker::Send;
48

59
struct NoSend;
610
impl !Send for NoSend {}
711

8-
enum Foo {
9-
A(NoSend)
12+
enum Container {
13+
WithNoSend(NoSend),
1014
}
1115

12-
fn bar<T: Send>(_: T) {}
16+
fn requires_send<T: Send>(_: T) {}
1317

1418
fn main() {
15-
let x = Foo::A(NoSend);
16-
bar(x);
19+
let container = Container::WithNoSend(NoSend);
20+
requires_send(container);
1721
//~^ ERROR `NoSend` cannot be sent between threads safely
1822
}

tests/ui/traits/enum-negative-send-impl.stderr

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
error[E0277]: `NoSend` cannot be sent between threads safely
2-
--> $DIR/no_send-enum.rs:16:9
2+
--> $DIR/enum-negative-send-impl.rs:20:19
33
|
4-
LL | bar(x);
5-
| --- ^ `NoSend` cannot be sent between threads safely
4+
LL | requires_send(container);
5+
| ------------- ^^^^^^^^^ `NoSend` cannot be sent between threads safely
66
| |
77
| required by a bound introduced by this call
88
|
9-
= help: within `Foo`, the trait `Send` is not implemented for `NoSend`
10-
note: required because it appears within the type `Foo`
11-
--> $DIR/no_send-enum.rs:8:6
9+
= help: within `Container`, the trait `Send` is not implemented for `NoSend`
10+
note: required because it appears within the type `Container`
11+
--> $DIR/enum-negative-send-impl.rs:12:6
1212
|
13-
LL | enum Foo {
14-
| ^^^
15-
note: required by a bound in `bar`
16-
--> $DIR/no_send-enum.rs:12:11
13+
LL | enum Container {
14+
| ^^^^^^^^^
15+
note: required by a bound in `requires_send`
16+
--> $DIR/enum-negative-send-impl.rs:16:21
1717
|
18-
LL | fn bar<T: Send>(_: T) {}
19-
| ^^^^ required by this bound in `bar`
18+
LL | fn requires_send<T: Send>(_: T) {}
19+
| ^^^^ required by this bound in `requires_send`
2020

2121
error: aborting due to 1 previous error
2222

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1+
//! Test that enums inherit Sync/!Sync properties from their variants.
2+
//!
3+
//! Uses the unstable `negative_impls` feature to explicitly opt-out of Sync.
4+
15
#![feature(negative_impls)]
26

37
use std::marker::Sync;
48

59
struct NoSync;
610
impl !Sync for NoSync {}
711

8-
enum Foo { A(NoSync) }
12+
enum Container {
13+
WithNoSync(NoSync),
14+
}
915

10-
fn bar<T: Sync>(_: T) {}
16+
fn requires_sync<T: Sync>(_: T) {}
1117

1218
fn main() {
13-
let x = Foo::A(NoSync);
14-
bar(x);
19+
let container = Container::WithNoSync(NoSync);
20+
requires_sync(container);
1521
//~^ ERROR `NoSync` cannot be shared between threads safely [E0277]
1622
}

tests/ui/traits/enum-negative-sync-impl.stderr

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
error[E0277]: `NoSync` cannot be shared between threads safely
2-
--> $DIR/no_share-enum.rs:14:9
2+
--> $DIR/enum-negative-sync-impl.rs:20:19
33
|
4-
LL | bar(x);
5-
| --- ^ `NoSync` cannot be shared between threads safely
4+
LL | requires_sync(container);
5+
| ------------- ^^^^^^^^^ `NoSync` cannot be shared between threads safely
66
| |
77
| required by a bound introduced by this call
88
|
9-
= help: within `Foo`, the trait `Sync` is not implemented for `NoSync`
10-
note: required because it appears within the type `Foo`
11-
--> $DIR/no_share-enum.rs:8:6
9+
= help: within `Container`, the trait `Sync` is not implemented for `NoSync`
10+
note: required because it appears within the type `Container`
11+
--> $DIR/enum-negative-sync-impl.rs:12:6
1212
|
13-
LL | enum Foo { A(NoSync) }
14-
| ^^^
15-
note: required by a bound in `bar`
16-
--> $DIR/no_share-enum.rs:10:11
13+
LL | enum Container {
14+
| ^^^^^^^^^
15+
note: required by a bound in `requires_sync`
16+
--> $DIR/enum-negative-sync-impl.rs:16:21
1717
|
18-
LL | fn bar<T: Sync>(_: T) {}
19-
| ^^^^ required by this bound in `bar`
18+
LL | fn requires_sync<T: Sync>(_: T) {}
19+
| ^^^^ required by this bound in `requires_sync`
2020

2121
error: aborting due to 1 previous error
2222

tests/ui/traits/rc-not-send.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
//! Test that `Rc<T>` does not implement `Send`.
2+
13
use std::rc::Rc;
24

3-
fn bar<T: Send>(_: T) {}
5+
fn requires_send<T: Send>(_: T) {}
46

57
fn main() {
6-
let x = Rc::new(5);
7-
bar(x);
8+
let rc_value = Rc::new(5);
9+
requires_send(rc_value);
810
//~^ ERROR `Rc<{integer}>` cannot be sent between threads safely
911
}

tests/ui/traits/rc-not-send.stderr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
error[E0277]: `Rc<{integer}>` cannot be sent between threads safely
2-
--> $DIR/no_send-rc.rs:7:9
2+
--> $DIR/rc-not-send.rs:9:19
33
|
4-
LL | bar(x);
5-
| --- ^ `Rc<{integer}>` cannot be sent between threads safely
4+
LL | requires_send(rc_value);
5+
| ------------- ^^^^^^^^ `Rc<{integer}>` cannot be sent between threads safely
66
| |
77
| required by a bound introduced by this call
88
|
99
= help: the trait `Send` is not implemented for `Rc<{integer}>`
10-
note: required by a bound in `bar`
11-
--> $DIR/no_send-rc.rs:3:11
10+
note: required by a bound in `requires_send`
11+
--> $DIR/rc-not-send.rs:5:21
1212
|
13-
LL | fn bar<T: Send>(_: T) {}
14-
| ^^^^ required by this bound in `bar`
13+
LL | fn requires_send<T: Send>(_: T) {}
14+
| ^^^^ required by this bound in `requires_send`
1515
help: consider dereferencing here
1616
|
17-
LL | bar(*x);
18-
| +
17+
LL | requires_send(*rc_value);
18+
| +
1919

2020
error: aborting due to 1 previous error
2121

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1+
//! Test negative Sync implementation on structs.
2+
//!
3+
//! Uses the unstable `negative_impls` feature to explicitly opt-out of Sync.
4+
15
#![feature(negative_impls)]
26

37
use std::marker::Sync;
48

5-
struct Foo { a: isize }
6-
impl !Sync for Foo {}
9+
struct NotSync {
10+
value: isize,
11+
}
12+
13+
impl !Sync for NotSync {}
714

8-
fn bar<T: Sync>(_: T) {}
15+
fn requires_sync<T: Sync>(_: T) {}
916

1017
fn main() {
11-
let x = Foo { a: 5 };
12-
bar(x);
13-
//~^ ERROR `Foo` cannot be shared between threads safely [E0277]
18+
let not_sync = NotSync { value: 5 };
19+
requires_sync(not_sync);
20+
//~^ ERROR `NotSync` cannot be shared between threads safely [E0277]
1421
}

tests/ui/traits/struct-negative-sync-impl.stderr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
error[E0277]: `Foo` cannot be shared between threads safely
2-
--> $DIR/no_share-struct.rs:12:9
1+
error[E0277]: `NotSync` cannot be shared between threads safely
2+
--> $DIR/struct-negative-sync-impl.rs:19:19
33
|
4-
LL | bar(x);
5-
| --- ^ `Foo` cannot be shared between threads safely
4+
LL | requires_sync(not_sync);
5+
| ------------- ^^^^^^^^ `NotSync` cannot be shared between threads safely
66
| |
77
| required by a bound introduced by this call
88
|
9-
= help: the trait `Sync` is not implemented for `Foo`
10-
note: required by a bound in `bar`
11-
--> $DIR/no_share-struct.rs:8:11
9+
= help: the trait `Sync` is not implemented for `NotSync`
10+
note: required by a bound in `requires_sync`
11+
--> $DIR/struct-negative-sync-impl.rs:15:21
1212
|
13-
LL | fn bar<T: Sync>(_: T) {}
14-
| ^^^^ required by this bound in `bar`
13+
LL | fn requires_sync<T: Sync>(_: T) {}
14+
| ^^^^ required by this bound in `requires_sync`
1515

1616
error: aborting due to 1 previous error
1717

0 commit comments

Comments
 (0)