cleaned up some tests
This commit is contained in:
parent
c68032fd4c
commit
ff005610d5
10 changed files with 112 additions and 96 deletions
|
|
@ -1,37 +0,0 @@
|
|||
#![feature(never_type)]
|
||||
|
||||
fn loop_break_return() -> i32 {
|
||||
let loop_value = loop { break return 0 }; // ok
|
||||
}
|
||||
|
||||
fn loop_break_loop() -> i32 {
|
||||
let loop_value = loop { break loop {} }; // ok
|
||||
}
|
||||
|
||||
fn loop_break_break() -> i32 { //~ ERROR mismatched types
|
||||
let loop_value = loop { break break };
|
||||
}
|
||||
|
||||
fn loop_break_return_2() -> i32 {
|
||||
let loop_value = loop { break { return 0; () } }; // ok
|
||||
}
|
||||
|
||||
enum Void {}
|
||||
|
||||
fn get_void() -> Void {
|
||||
panic!()
|
||||
}
|
||||
|
||||
fn loop_break_void() -> i32 { //~ ERROR mismatched types
|
||||
let loop_value = loop { break get_void() };
|
||||
}
|
||||
|
||||
fn get_never() -> ! {
|
||||
panic!()
|
||||
}
|
||||
|
||||
fn loop_break_never() -> i32 {
|
||||
let loop_value = loop { break get_never() }; // ok
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
//@ run-pass
|
||||
|
||||
fn foo(x: &mut Box<u8>) {
|
||||
*x = Box::new(5);
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
foo(&mut Box::new(4));
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
#![feature(unboxed_closures, tuple_trait)]
|
||||
|
||||
use std::io::Read;
|
||||
|
||||
fn to_fn_once<A:std::marker::Tuple,F:FnOnce<A>>(f: F) -> F { f }
|
||||
|
||||
fn main() {
|
||||
let x = 1;
|
||||
to_fn_once(move|| { x = 2; });
|
||||
//~^ ERROR: cannot assign to `x`, as it is not declared as mutable
|
||||
|
||||
let s = std::io::stdin();
|
||||
to_fn_once(move|| { s.read_to_end(&mut Vec::new()); });
|
||||
//~^ ERROR: cannot borrow `s` as mutable, as it is not declared as mutable
|
||||
}
|
||||
23
tests/ui/closures/closure-immut-capture-error.rs
Normal file
23
tests/ui/closures/closure-immut-capture-error.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
//! Tests that mutation of captured immutable variables in closures are not permitted.
|
||||
|
||||
#![feature(unboxed_closures, tuple_trait)]
|
||||
|
||||
use std::io::Read;
|
||||
|
||||
fn to_fn_once<A: std::marker::Tuple, F: FnOnce<A>>(f: F) -> F {
|
||||
f
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = 1;
|
||||
to_fn_once(move || {
|
||||
x = 2;
|
||||
//~^ ERROR: cannot assign to `x`, as it is not declared as mutable
|
||||
});
|
||||
|
||||
let s = std::io::stdin();
|
||||
to_fn_once(move || {
|
||||
s.read_to_end(&mut Vec::new());
|
||||
//~^ ERROR: cannot borrow `s` as mutable, as it is not declared as mutable
|
||||
});
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
error[E0594]: cannot assign to `x`, as it is not declared as mutable
|
||||
--> $DIR/cannot-mutate-captured-non-mut-var.rs:9:25
|
||||
--> $DIR/closure-immut-capture-error.rs:14:9
|
||||
|
|
||||
LL | to_fn_once(move|| { x = 2; });
|
||||
| ^^^^^ cannot assign
|
||||
LL | x = 2;
|
||||
| ^^^^^ cannot assign
|
||||
|
|
||||
help: consider changing this to be mutable
|
||||
|
|
||||
|
|
@ -10,10 +10,10 @@ LL | let mut x = 1;
|
|||
| +++
|
||||
|
||||
error[E0596]: cannot borrow `s` as mutable, as it is not declared as mutable
|
||||
--> $DIR/cannot-mutate-captured-non-mut-var.rs:13:25
|
||||
--> $DIR/closure-immut-capture-error.rs:20:9
|
||||
|
|
||||
LL | to_fn_once(move|| { s.read_to_end(&mut Vec::new()); });
|
||||
| ^ cannot borrow as mutable
|
||||
LL | s.read_to_end(&mut Vec::new());
|
||||
| ^ cannot borrow as mutable
|
||||
|
|
||||
help: consider changing this to be mutable
|
||||
|
|
||||
13
tests/ui/codegen/rvalue-mut-ref-box-drop.rs
Normal file
13
tests/ui/codegen/rvalue-mut-ref-box-drop.rs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
//! Tests cleanup of a temporary `Box` rvalue passed as a mutable reference.
|
||||
//!
|
||||
//! - Issue: <https://github.com/rust-lang/rust/issues/7972>.
|
||||
|
||||
//@ run-pass
|
||||
|
||||
fn foo(x: &mut Box<u8>) {
|
||||
*x = Box::new(5);
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
foo(&mut Box::new(4));
|
||||
}
|
||||
56
tests/ui/loops/loop-break-never-type-mismatch.rs
Normal file
56
tests/ui/loops/loop-break-never-type-mismatch.rs
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
//! Tests type mismatches with `break` and diverging types in loops
|
||||
|
||||
#![feature(never_type)]
|
||||
|
||||
fn loop_break_return() -> i32 {
|
||||
let loop_value = loop {
|
||||
break return 0;
|
||||
}; // ok
|
||||
}
|
||||
|
||||
fn loop_break_loop() -> i32 {
|
||||
let loop_value = loop {
|
||||
break loop {};
|
||||
}; // ok
|
||||
}
|
||||
|
||||
fn loop_break_break() -> i32 {
|
||||
//~^ ERROR mismatched types
|
||||
let loop_value = loop {
|
||||
break break;
|
||||
};
|
||||
}
|
||||
|
||||
fn loop_break_return_2() -> i32 {
|
||||
let loop_value = loop {
|
||||
break {
|
||||
return 0;
|
||||
()
|
||||
};
|
||||
}; // ok
|
||||
}
|
||||
|
||||
enum Void {}
|
||||
|
||||
fn get_void() -> Void {
|
||||
panic!()
|
||||
}
|
||||
|
||||
fn loop_break_void() -> i32 {
|
||||
//~^ ERROR mismatched types
|
||||
let loop_value = loop {
|
||||
break get_void();
|
||||
};
|
||||
}
|
||||
|
||||
fn get_never() -> ! {
|
||||
panic!()
|
||||
}
|
||||
|
||||
fn loop_break_never() -> i32 {
|
||||
let loop_value = loop {
|
||||
break get_never();
|
||||
}; // ok
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
error[E0308]: mismatched types
|
||||
--> $DIR/break-diverging-value.rs:11:26
|
||||
--> $DIR/loop-break-never-type-mismatch.rs:17:26
|
||||
|
|
||||
LL | fn loop_break_break() -> i32 {
|
||||
| ---------------- ^^^ expected `i32`, found `()`
|
||||
|
|
@ -7,7 +7,7 @@ LL | fn loop_break_break() -> i32 {
|
|||
| implicitly returns `()` as its body has no tail or `return` expression
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/break-diverging-value.rs:25:25
|
||||
--> $DIR/loop-break-never-type-mismatch.rs:39:25
|
||||
|
|
||||
LL | fn loop_break_void() -> i32 {
|
||||
| --------------- ^^^ expected `i32`, found `()`
|
||||
|
|
@ -1,14 +1,13 @@
|
|||
//! Tests cleanup behavior of the built-in `Clone` impl for tuples during unwinding.
|
||||
|
||||
//@ run-pass
|
||||
//@ needs-unwind
|
||||
|
||||
#![allow(unused_variables)]
|
||||
#![allow(unused_imports)]
|
||||
|
||||
// Test that builtin implementations of `Clone` cleanup everything
|
||||
// in case of unwinding.
|
||||
|
||||
use std::thread;
|
||||
use std::rc::Rc;
|
||||
use std::thread;
|
||||
|
||||
struct S(Rc<()>);
|
||||
|
||||
|
|
@ -28,34 +27,20 @@ fn main() {
|
|||
// Unwinding with tuples...
|
||||
let ccounter = counter.clone();
|
||||
let result = std::panic::catch_unwind(move || {
|
||||
let _ = (
|
||||
S(ccounter.clone()),
|
||||
S(ccounter.clone()),
|
||||
S(ccounter.clone()),
|
||||
S(ccounter)
|
||||
).clone();
|
||||
let _ =
|
||||
(S(ccounter.clone()), S(ccounter.clone()), S(ccounter.clone()), S(ccounter)).clone();
|
||||
});
|
||||
|
||||
assert!(result.is_err());
|
||||
assert_eq!(
|
||||
1,
|
||||
Rc::strong_count(&counter)
|
||||
);
|
||||
assert_eq!(1, Rc::strong_count(&counter));
|
||||
|
||||
// ... and with arrays.
|
||||
let ccounter = counter.clone();
|
||||
let child = std::panic::catch_unwind(move || {
|
||||
let _ = [
|
||||
S(ccounter.clone()),
|
||||
S(ccounter.clone()),
|
||||
S(ccounter.clone()),
|
||||
S(ccounter)
|
||||
].clone();
|
||||
let _ =
|
||||
[S(ccounter.clone()), S(ccounter.clone()), S(ccounter.clone()), S(ccounter)].clone();
|
||||
});
|
||||
|
||||
assert!(child.is_err());
|
||||
assert_eq!(
|
||||
1,
|
||||
Rc::strong_count(&counter)
|
||||
);
|
||||
assert_eq!(1, Rc::strong_count(&counter));
|
||||
}
|
||||
|
|
@ -1,13 +1,13 @@
|
|||
//! Tests that type parameters with the `Copy` are implicitly copyable.
|
||||
|
||||
//@ run-pass
|
||||
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
// Tests that type parameters with the `Copy` are implicitly copyable.
|
||||
|
||||
#![allow(dead_code)]
|
||||
|
||||
fn can_copy_copy<T:Copy>(v: T) {
|
||||
fn can_copy_copy<T: Copy>(v: T) {
|
||||
let _a = v;
|
||||
let _b = v;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue