Skip to content

Commit d46ba30

Browse files
committed
cleaned up some tests
1 parent c68032f commit d46ba30

10 files changed

+112
-96
lines changed

tests/ui/break-diverging-value.rs

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

tests/ui/cancel-clean-via-immediate-rvalue-ref.rs

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

tests/ui/cannot-mutate-captured-non-mut-var.rs

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//! Tests that mutation of captured immutable variables in closures are not permitted.
2+
3+
#![feature(unboxed_closures, tuple_trait)]
4+
5+
use std::io::Read;
6+
7+
fn to_fn_once<A: std::marker::Tuple, F: FnOnce<A>>(f: F) -> F {
8+
f
9+
}
10+
11+
fn main() {
12+
let x = 1;
13+
to_fn_once(move || {
14+
x = 2;
15+
//~^ ERROR: cannot assign to `x`, as it is not declared as mutable
16+
});
17+
18+
let s = std::io::stdin();
19+
to_fn_once(move || {
20+
s.read_to_end(&mut Vec::new());
21+
//~^ ERROR: cannot borrow `s` as mutable, as it is not declared as mutable
22+
});
23+
}

tests/ui/cannot-mutate-captured-non-mut-var.stderr renamed to tests/ui/closures/closure-immut-capture-error.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
error[E0594]: cannot assign to `x`, as it is not declared as mutable
2-
--> $DIR/cannot-mutate-captured-non-mut-var.rs:9:25
2+
--> $DIR/closure-immut-capture-error.rs:14:9
33
|
4-
LL | to_fn_once(move|| { x = 2; });
5-
| ^^^^^ cannot assign
4+
LL | x = 2;
5+
| ^^^^^ cannot assign
66
|
77
help: consider changing this to be mutable
88
|
99
LL | let mut x = 1;
1010
| +++
1111

1212
error[E0596]: cannot borrow `s` as mutable, as it is not declared as mutable
13-
--> $DIR/cannot-mutate-captured-non-mut-var.rs:13:25
13+
--> $DIR/closure-immut-capture-error.rs:20:9
1414
|
15-
LL | to_fn_once(move|| { s.read_to_end(&mut Vec::new()); });
16-
| ^ cannot borrow as mutable
15+
LL | s.read_to_end(&mut Vec::new());
16+
| ^ cannot borrow as mutable
1717
|
1818
help: consider changing this to be mutable
1919
|
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//! Tests cleanup of a temporary `Box` rvalue passed as a mutable reference.
2+
//!
3+
//! - Issue: <https://github.com/rust-lang/rust/issues/7972>.
4+
5+
//@ run-pass
6+
7+
fn foo(x: &mut Box<u8>) {
8+
*x = Box::new(5);
9+
}
10+
11+
pub fn main() {
12+
foo(&mut Box::new(4));
13+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//! Tests type mismatches with `break` and diverging types in loops
2+
3+
#![feature(never_type)]
4+
5+
fn loop_break_return() -> i32 {
6+
let loop_value = loop {
7+
break return 0;
8+
}; // ok
9+
}
10+
11+
fn loop_break_loop() -> i32 {
12+
let loop_value = loop {
13+
break loop {};
14+
}; // ok
15+
}
16+
17+
fn loop_break_break() -> i32 {
18+
//~^ ERROR mismatched types
19+
let loop_value = loop {
20+
break break;
21+
};
22+
}
23+
24+
fn loop_break_return_2() -> i32 {
25+
let loop_value = loop {
26+
break {
27+
return 0;
28+
()
29+
};
30+
}; // ok
31+
}
32+
33+
enum Void {}
34+
35+
fn get_void() -> Void {
36+
panic!()
37+
}
38+
39+
fn loop_break_void() -> i32 {
40+
//~^ ERROR mismatched types
41+
let loop_value = loop {
42+
break get_void();
43+
};
44+
}
45+
46+
fn get_never() -> ! {
47+
panic!()
48+
}
49+
50+
fn loop_break_never() -> i32 {
51+
let loop_value = loop {
52+
break get_never();
53+
}; // ok
54+
}
55+
56+
fn main() {}

tests/ui/break-diverging-value.stderr renamed to tests/ui/loops/loop-break-never-type-mismatch.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error[E0308]: mismatched types
2-
--> $DIR/break-diverging-value.rs:11:26
2+
--> $DIR/loop-break-never-type-mismatch.rs:17:26
33
|
44
LL | fn loop_break_break() -> i32 {
55
| ---------------- ^^^ expected `i32`, found `()`
66
| |
77
| implicitly returns `()` as its body has no tail or `return` expression
88

99
error[E0308]: mismatched types
10-
--> $DIR/break-diverging-value.rs:25:25
10+
--> $DIR/loop-break-never-type-mismatch.rs:39:25
1111
|
1212
LL | fn loop_break_void() -> i32 {
1313
| --------------- ^^^ expected `i32`, found `()`
Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1+
//! Tests cleanup behavior of the built-in `Clone` impl for tuples during unwinding.
2+
13
//@ run-pass
24
//@ needs-unwind
35

46
#![allow(unused_variables)]
57
#![allow(unused_imports)]
68

7-
// Test that builtin implementations of `Clone` cleanup everything
8-
// in case of unwinding.
9-
10-
use std::thread;
119
use std::rc::Rc;
10+
use std::thread;
1211

1312
struct S(Rc<()>);
1413

@@ -28,34 +27,20 @@ fn main() {
2827
// Unwinding with tuples...
2928
let ccounter = counter.clone();
3029
let result = std::panic::catch_unwind(move || {
31-
let _ = (
32-
S(ccounter.clone()),
33-
S(ccounter.clone()),
34-
S(ccounter.clone()),
35-
S(ccounter)
36-
).clone();
30+
let _ =
31+
(S(ccounter.clone()), S(ccounter.clone()), S(ccounter.clone()), S(ccounter)).clone();
3732
});
3833

3934
assert!(result.is_err());
40-
assert_eq!(
41-
1,
42-
Rc::strong_count(&counter)
43-
);
35+
assert_eq!(1, Rc::strong_count(&counter));
4436

4537
// ... and with arrays.
4638
let ccounter = counter.clone();
4739
let child = std::panic::catch_unwind(move || {
48-
let _ = [
49-
S(ccounter.clone()),
50-
S(ccounter.clone()),
51-
S(ccounter.clone()),
52-
S(ccounter)
53-
].clone();
40+
let _ =
41+
[S(ccounter.clone()), S(ccounter.clone()), S(ccounter.clone()), S(ccounter)].clone();
5442
});
5543

5644
assert!(child.is_err());
57-
assert_eq!(
58-
1,
59-
Rc::strong_count(&counter)
60-
);
45+
assert_eq!(1, Rc::strong_count(&counter));
6146
}

tests/ui/can-copy-pod.rs renamed to tests/ui/traits/copy-trait-implicit-copy.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
//! Tests that type parameters with the `Copy` are implicitly copyable.
2+
13
//@ run-pass
24

35
/* Any copyright is dedicated to the Public Domain.
46
* http://creativecommons.org/publicdomain/zero/1.0/ */
57

6-
// Tests that type parameters with the `Copy` are implicitly copyable.
7-
88
#![allow(dead_code)]
99

10-
fn can_copy_copy<T:Copy>(v: T) {
10+
fn can_copy_copy<T: Copy>(v: T) {
1111
let _a = v;
1212
let _b = v;
1313
}

0 commit comments

Comments
 (0)