Skip to content

Commit

Permalink
review: fix nits and move panic safety tests to the correct place
Browse files Browse the repository at this point in the history
  • Loading branch information
poliorcetics committed Sep 25, 2020
1 parent 5be843f commit a61b963
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 24 deletions.
3 changes: 1 addition & 2 deletions library/alloc/tests/boxed.rs
@@ -1,3 +1,4 @@
use std::cell::Cell;
use std::mem::MaybeUninit;
use std::ptr::NonNull;

Expand Down Expand Up @@ -52,8 +53,6 @@ fn box_clone_from_ptr_stability() {

#[test]
fn box_deref_lval() {
use std::cell::Cell;

let x = Box::new(Cell::new(5));
x.set(1000);
assert_eq!(x.get(), 1000);
Expand Down
21 changes: 10 additions & 11 deletions library/alloc/tests/fmt.rs
@@ -1,5 +1,4 @@
#![deny(warnings)]
#![allow(unused_must_use)]

use std::cell::RefCell;
use std::fmt::{self, Write};
Expand Down Expand Up @@ -241,15 +240,15 @@ fn test_format_macro_interface() {
#[test]
fn test_write() {
let mut buf = String::new();
write!(&mut buf, "{}", 3);
let _ = write!(&mut buf, "{}", 3);
{
let w = &mut buf;
write!(w, "{foo}", foo = 4);
write!(w, "{}", "hello");
writeln!(w, "{}", "line");
writeln!(w, "{foo}", foo = "bar");
w.write_char('☃');
w.write_str("str");
let _ = write!(w, "{foo}", foo = 4);
let _ = write!(w, "{}", "hello");
let _ = writeln!(w, "{}", "line");
let _ = writeln!(w, "{foo}", foo = "bar");
let _ = w.write_char('☃');
let _ = w.write_str("str");
}

t!(buf, "34helloline\nbar\n☃str");
Expand All @@ -273,9 +272,9 @@ fn test_format_args() {
let mut buf = String::new();
{
let w = &mut buf;
write!(w, "{}", format_args!("{}", 1));
write!(w, "{}", format_args!("test"));
write!(w, "{}", format_args!("{test}", test = 3));
let _ = write!(w, "{}", format_args!("{}", 1));
let _ = write!(w, "{}", format_args!("test"));
let _ = write!(w, "{}", format_args!("{test}", test = 3));
}
let s = buf;
t!(s, "1test3");
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/fmt/mod.rs
Expand Up @@ -2238,5 +2238,6 @@ impl<T: ?Sized + Debug> Debug for UnsafeCell<T> {
}
}

// If you expected tests to be here, look instead at the ui/ifmt.rs test,
// If you expected tests to be here, look instead at the core/tests/fmt.rs file,
// it's a lot easier than creating all of the rt::Piece structures here.
// There are also tests in the alloc crate, for those that need allocations.
1 change: 0 additions & 1 deletion library/core/tests/lib.rs
Expand Up @@ -78,7 +78,6 @@ mod nonzero;
mod num;
mod ops;
mod option;
mod panic_safe;
mod pattern;
mod ptr;
mod result;
Expand Down
3 changes: 1 addition & 2 deletions library/core/tests/option.rs
@@ -1,3 +1,4 @@
use core::cell::Cell;
use core::clone::Clone;
use core::mem;
use core::ops::DerefMut;
Expand Down Expand Up @@ -375,8 +376,6 @@ fn option_const() {

#[test]
fn test_unwrap_drop() {
use std::cell::Cell;

struct Dtor<'a> {
x: &'a Cell<isize>,
}
Expand Down
3 changes: 1 addition & 2 deletions library/core/tests/slice.rs
@@ -1,3 +1,4 @@
use core::cell::Cell;
use core::result::Result::{Err, Ok};

#[test]
Expand Down Expand Up @@ -1983,8 +1984,6 @@ fn test_is_sorted() {

#[test]
fn test_slice_run_destructors() {
use core::cell::Cell;

// Make sure that destructors get run on slice literals
struct Foo<'a> {
x: &'a Cell<isize>,
Expand Down
3 changes: 3 additions & 0 deletions library/std/src/panic.rs
Expand Up @@ -411,3 +411,6 @@ pub fn catch_unwind<F: FnOnce() -> R + UnwindSafe, R>(f: F) -> Result<R> {
pub fn resume_unwind(payload: Box<dyn Any + Send>) -> ! {
panicking::rust_panic_without_hook(payload)
}

#[cfg(test)]
mod tests;
@@ -1,9 +1,9 @@
#![allow(dead_code)]

use std::cell::RefCell;
use std::panic::{AssertUnwindSafe, UnwindSafe};
use std::rc::Rc;
use std::sync::{Arc, Mutex, RwLock};
use crate::cell::RefCell;
use crate::panic::{AssertUnwindSafe, UnwindSafe};
use crate::rc::Rc;
use crate::sync::{Arc, Mutex, RwLock};

struct Foo {
a: i32,
Expand All @@ -12,7 +12,7 @@ struct Foo {
fn assert<T: UnwindSafe + ?Sized>() {}

#[test]
fn test_panic_safety_traits() {
fn panic_safety_traits() {
assert::<i32>();
assert::<&i32>();
assert::<*mut i32>();
Expand Down

0 comments on commit a61b963

Please sign in to comment.