mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Rollup merge of #153061 - cyrgani:box-tests-2, r=Kivooeo
cleanup `tests/ui/box`, part 2 Followup to rust-lang/rust#152868. I merged some of the slightly less trivial tests into `basic-operations.rs` and deleted several others entirely. r? @Kivooeo (since you claimed the last one, but feel free to reassign) Part of https://github.com/rust-lang/rust/issues/133895.
This commit is contained in:
@@ -1,24 +0,0 @@
|
||||
//@ run-pass
|
||||
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
#![allow(dead_code, unused_variables)]
|
||||
|
||||
// Tests that the new `box` syntax works with unique pointers.
|
||||
|
||||
struct Structure {
|
||||
x: isize,
|
||||
y: isize,
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let y: Box<isize> = Box::new(2);
|
||||
let b: Box<isize> = Box::new(1 + 2);
|
||||
let c = Box::new(3 + 4);
|
||||
|
||||
let s: Box<Structure> = Box::new(Structure {
|
||||
x: 3,
|
||||
y: 4,
|
||||
});
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
//@ run-pass
|
||||
|
||||
fn main() {
|
||||
let _a = Box::new(1);
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
//! A collection of very old tests of basic `Box` functionality.
|
||||
//@ run-pass
|
||||
|
||||
fn deref_mut() {
|
||||
let mut i: Box<_> = Box::new(0);
|
||||
*i = 1;
|
||||
assert_eq!(*i, 1);
|
||||
}
|
||||
|
||||
// Tests for if as expressions returning boxed types
|
||||
fn box_if() {
|
||||
let rs: Box<_> = if true { Box::new(100) } else { Box::new(101) };
|
||||
assert_eq!(*rs, 100);
|
||||
}
|
||||
|
||||
fn cmp() {
|
||||
let i: Box<_> = Box::new(100);
|
||||
assert_eq!(i, Box::new(100));
|
||||
assert!(i < Box::new(101));
|
||||
assert!(i <= Box::new(100));
|
||||
assert!(i > Box::new(99));
|
||||
assert!(i >= Box::new(99));
|
||||
}
|
||||
|
||||
fn autoderef_field() {
|
||||
struct J {
|
||||
j: isize,
|
||||
}
|
||||
|
||||
let i: Box<_> = Box::new(J { j: 100 });
|
||||
assert_eq!(i.j, 100);
|
||||
}
|
||||
|
||||
fn assign_copy() {
|
||||
let mut i: Box<_> = Box::new(1);
|
||||
// Should be a copy
|
||||
let mut j;
|
||||
j = i.clone();
|
||||
*i = 2;
|
||||
*j = 3;
|
||||
assert_eq!(*i, 2);
|
||||
assert_eq!(*j, 3);
|
||||
}
|
||||
|
||||
fn arg_mut() {
|
||||
fn f(i: &mut Box<isize>) {
|
||||
*i = Box::new(200);
|
||||
}
|
||||
let mut i = Box::new(100);
|
||||
f(&mut i);
|
||||
assert_eq!(*i, 200);
|
||||
}
|
||||
|
||||
fn assign_generic() {
|
||||
fn f<T>(t: T) -> T {
|
||||
let t1 = t;
|
||||
t1
|
||||
}
|
||||
|
||||
let t = f::<Box<_>>(Box::new(100));
|
||||
assert_eq!(t, Box::new(100));
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
deref_mut();
|
||||
box_if();
|
||||
cmp();
|
||||
autoderef_field();
|
||||
assign_copy();
|
||||
arg_mut();
|
||||
assign_generic();
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
//@ run-pass
|
||||
|
||||
// Tests for if as expressions returning boxed types
|
||||
fn test_box() {
|
||||
let rs: Box<_> = if true { Box::new(100) } else { Box::new(101) };
|
||||
assert_eq!(*rs, 100);
|
||||
}
|
||||
|
||||
pub fn main() { test_box(); }
|
||||
@@ -1,12 +0,0 @@
|
||||
//@ run-pass
|
||||
|
||||
pub fn main() {
|
||||
let mut i: Box<_> = Box::new(1);
|
||||
// Should be a copy
|
||||
let mut j;
|
||||
j = i.clone();
|
||||
*i = 2;
|
||||
*j = 3;
|
||||
assert_eq!(*i, 2);
|
||||
assert_eq!(*j, 3);
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
//@ run-pass
|
||||
#![allow(unused_assignments)]
|
||||
|
||||
pub fn main() {
|
||||
let i: Box<_> = Box::new(1);
|
||||
let mut j: Box<_> = Box::new(2);
|
||||
// Should drop the previous value of j
|
||||
j = i;
|
||||
assert_eq!(*j, 1);
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
//@ run-pass
|
||||
|
||||
fn f<T>(t: T) -> T {
|
||||
let t1 = t;
|
||||
t1
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let t = f::<Box<_>>(Box::new(100));
|
||||
assert_eq!(t, Box::new(100));
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
//@ run-pass
|
||||
|
||||
struct J { j: isize }
|
||||
|
||||
pub fn main() {
|
||||
let i: Box<_> = Box::new(J {
|
||||
j: 100
|
||||
});
|
||||
assert_eq!(i.j, 100);
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
//@ run-pass
|
||||
|
||||
pub fn main() {
|
||||
let i: Box<_> = Box::new(vec![100]);
|
||||
assert_eq!((*i)[0], 100);
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
//@ run-pass
|
||||
#![allow(unused_allocation)]
|
||||
|
||||
pub fn main() {
|
||||
let i: Box<_> = Box::new(100);
|
||||
assert_eq!(i, Box::new(100));
|
||||
assert!(i < Box::new(101));
|
||||
assert!(i <= Box::new(100));
|
||||
assert!(i > Box::new(99));
|
||||
assert!(i >= Box::new(99));
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
//@ run-pass
|
||||
|
||||
pub fn main() {
|
||||
let mut i: Box<_> = Box::new(1);
|
||||
// Should be a copy
|
||||
let mut j = i.clone();
|
||||
*i = 2;
|
||||
*j = 3;
|
||||
assert_eq!(*i, 2);
|
||||
assert_eq!(*j, 3);
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
//@ run-pass
|
||||
|
||||
fn f(i: &mut Box<isize>) {
|
||||
*i = Box::new(200);
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let mut i = Box::new(100);
|
||||
f(&mut i);
|
||||
assert_eq!(*i, 200);
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
//@ run-pass
|
||||
|
||||
pub fn main() {
|
||||
let vect : Vec<Box<_>> = vec![Box::new(100)];
|
||||
assert_eq!(vect[0], Box::new(100));
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
//@ run-pass
|
||||
|
||||
#![allow(unused_variables)]
|
||||
|
||||
pub fn main() {
|
||||
let i: Box<_> = Box::new(100);
|
||||
let j: Box<_> = Box::new(200);
|
||||
let j = i;
|
||||
assert_eq!(*j, 100);
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
//@ run-pass
|
||||
|
||||
pub fn main() {
|
||||
let mut i: Box<_> = Box::new(0);
|
||||
*i = 1;
|
||||
assert_eq!(*i, 1);
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
//@ run-pass
|
||||
//@ needs-unwind
|
||||
//@ needs-threads
|
||||
//@ ignore-backends: gcc
|
||||
|
||||
use std::thread;
|
||||
|
||||
fn f() {
|
||||
let _a: Box<_> = Box::new(0);
|
||||
panic!();
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let t = thread::spawn(f);
|
||||
drop(t.join());
|
||||
}
|
||||
Reference in New Issue
Block a user