Skip to content

Commit a61b963

Browse files
committed
review: fix nits and move panic safety tests to the correct place
1 parent 5be843f commit a61b963

File tree

8 files changed

+23
-24
lines changed

8 files changed

+23
-24
lines changed

library/alloc/tests/boxed.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::cell::Cell;
12
use std::mem::MaybeUninit;
23
use std::ptr::NonNull;
34

@@ -52,8 +53,6 @@ fn box_clone_from_ptr_stability() {
5253

5354
#[test]
5455
fn box_deref_lval() {
55-
use std::cell::Cell;
56-
5756
let x = Box::new(Cell::new(5));
5857
x.set(1000);
5958
assert_eq!(x.get(), 1000);

library/alloc/tests/fmt.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![deny(warnings)]
2-
#![allow(unused_must_use)]
32

43
use std::cell::RefCell;
54
use std::fmt::{self, Write};
@@ -241,15 +240,15 @@ fn test_format_macro_interface() {
241240
#[test]
242241
fn test_write() {
243242
let mut buf = String::new();
244-
write!(&mut buf, "{}", 3);
243+
let _ = write!(&mut buf, "{}", 3);
245244
{
246245
let w = &mut buf;
247-
write!(w, "{foo}", foo = 4);
248-
write!(w, "{}", "hello");
249-
writeln!(w, "{}", "line");
250-
writeln!(w, "{foo}", foo = "bar");
251-
w.write_char('☃');
252-
w.write_str("str");
246+
let _ = write!(w, "{foo}", foo = 4);
247+
let _ = write!(w, "{}", "hello");
248+
let _ = writeln!(w, "{}", "line");
249+
let _ = writeln!(w, "{foo}", foo = "bar");
250+
let _ = w.write_char('☃');
251+
let _ = w.write_str("str");
253252
}
254253

255254
t!(buf, "34helloline\nbar\n☃str");
@@ -273,9 +272,9 @@ fn test_format_args() {
273272
let mut buf = String::new();
274273
{
275274
let w = &mut buf;
276-
write!(w, "{}", format_args!("{}", 1));
277-
write!(w, "{}", format_args!("test"));
278-
write!(w, "{}", format_args!("{test}", test = 3));
275+
let _ = write!(w, "{}", format_args!("{}", 1));
276+
let _ = write!(w, "{}", format_args!("test"));
277+
let _ = write!(w, "{}", format_args!("{test}", test = 3));
279278
}
280279
let s = buf;
281280
t!(s, "1test3");

library/core/src/fmt/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2238,5 +2238,6 @@ impl<T: ?Sized + Debug> Debug for UnsafeCell<T> {
22382238
}
22392239
}
22402240

2241-
// If you expected tests to be here, look instead at the ui/ifmt.rs test,
2241+
// If you expected tests to be here, look instead at the core/tests/fmt.rs file,
22422242
// it's a lot easier than creating all of the rt::Piece structures here.
2243+
// There are also tests in the alloc crate, for those that need allocations.

library/core/tests/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ mod nonzero;
7878
mod num;
7979
mod ops;
8080
mod option;
81-
mod panic_safe;
8281
mod pattern;
8382
mod ptr;
8483
mod result;

library/core/tests/option.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use core::cell::Cell;
12
use core::clone::Clone;
23
use core::mem;
34
use core::ops::DerefMut;
@@ -375,8 +376,6 @@ fn option_const() {
375376

376377
#[test]
377378
fn test_unwrap_drop() {
378-
use std::cell::Cell;
379-
380379
struct Dtor<'a> {
381380
x: &'a Cell<isize>,
382381
}

library/core/tests/slice.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use core::cell::Cell;
12
use core::result::Result::{Err, Ok};
23

34
#[test]
@@ -1983,8 +1984,6 @@ fn test_is_sorted() {
19831984

19841985
#[test]
19851986
fn test_slice_run_destructors() {
1986-
use core::cell::Cell;
1987-
19881987
// Make sure that destructors get run on slice literals
19891988
struct Foo<'a> {
19901989
x: &'a Cell<isize>,

library/std/src/panic.rs

+3
Original file line numberDiff line numberDiff line change
@@ -411,3 +411,6 @@ pub fn catch_unwind<F: FnOnce() -> R + UnwindSafe, R>(f: F) -> Result<R> {
411411
pub fn resume_unwind(payload: Box<dyn Any + Send>) -> ! {
412412
panicking::rust_panic_without_hook(payload)
413413
}
414+
415+
#[cfg(test)]
416+
mod tests;

library/core/tests/panic_safe.rs renamed to library/std/src/panic/tests.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#![allow(dead_code)]
22

3-
use std::cell::RefCell;
4-
use std::panic::{AssertUnwindSafe, UnwindSafe};
5-
use std::rc::Rc;
6-
use std::sync::{Arc, Mutex, RwLock};
3+
use crate::cell::RefCell;
4+
use crate::panic::{AssertUnwindSafe, UnwindSafe};
5+
use crate::rc::Rc;
6+
use crate::sync::{Arc, Mutex, RwLock};
77

88
struct Foo {
99
a: i32,
@@ -12,7 +12,7 @@ struct Foo {
1212
fn assert<T: UnwindSafe + ?Sized>() {}
1313

1414
#[test]
15-
fn test_panic_safety_traits() {
15+
fn panic_safety_traits() {
1616
assert::<i32>();
1717
assert::<&i32>();
1818
assert::<*mut i32>();

0 commit comments

Comments
 (0)