diff --git a/library/alloc/tests/boxed.rs b/library/alloc/tests/boxed.rs index df13b36e778..6a83f5da87c 100644 --- a/library/alloc/tests/boxed.rs +++ b/library/alloc/tests/boxed.rs @@ -1,3 +1,4 @@ +use std::cell::Cell; use std::mem::MaybeUninit; use std::ptr::NonNull; @@ -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); diff --git a/library/alloc/tests/fmt.rs b/library/alloc/tests/fmt.rs index 6fd6468c3ce..757fddd2418 100644 --- a/library/alloc/tests/fmt.rs +++ b/library/alloc/tests/fmt.rs @@ -1,5 +1,4 @@ #![deny(warnings)] -#![allow(unused_must_use)] use std::cell::RefCell; use std::fmt::{self, Write}; @@ -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"); @@ -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"); diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs index 8558cb5a5e8..c1038ce4260 100644 --- a/library/core/src/fmt/mod.rs +++ b/library/core/src/fmt/mod.rs @@ -2238,5 +2238,6 @@ fn fmt(&self, f: &mut Formatter<'_>) -> Result { } } -// 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. diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index 4211d0e95a9..4db391f3e56 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -78,7 +78,6 @@ mod num; mod ops; mod option; -mod panic_safe; mod pattern; mod ptr; mod result; diff --git a/library/core/tests/option.rs b/library/core/tests/option.rs index bd9a5a6a2cd..ae814efec20 100644 --- a/library/core/tests/option.rs +++ b/library/core/tests/option.rs @@ -1,3 +1,4 @@ +use core::cell::Cell; use core::clone::Clone; use core::mem; use core::ops::DerefMut; @@ -375,8 +376,6 @@ fn option_const() { #[test] fn test_unwrap_drop() { - use std::cell::Cell; - struct Dtor<'a> { x: &'a Cell, } diff --git a/library/core/tests/slice.rs b/library/core/tests/slice.rs index d66d17c1c85..5ef30b1a889 100644 --- a/library/core/tests/slice.rs +++ b/library/core/tests/slice.rs @@ -1,3 +1,4 @@ +use core::cell::Cell; use core::result::Result::{Err, Ok}; #[test] @@ -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, diff --git a/library/std/src/panic.rs b/library/std/src/panic.rs index 18d9c2f11b5..4281867314c 100644 --- a/library/std/src/panic.rs +++ b/library/std/src/panic.rs @@ -411,3 +411,6 @@ pub fn catch_unwind R + UnwindSafe, R>(f: F) -> Result { pub fn resume_unwind(payload: Box) -> ! { panicking::rust_panic_without_hook(payload) } + +#[cfg(test)] +mod tests; diff --git a/library/core/tests/panic_safe.rs b/library/std/src/panic/tests.rs similarity index 86% rename from library/core/tests/panic_safe.rs rename to library/std/src/panic/tests.rs index 3104ba539c3..b37d74011cc 100644 --- a/library/core/tests/panic_safe.rs +++ b/library/std/src/panic/tests.rs @@ -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, @@ -12,7 +12,7 @@ struct Foo { fn assert() {} #[test] -fn test_panic_safety_traits() { +fn panic_safety_traits() { assert::(); assert::<&i32>(); assert::<*mut i32>();