diff --git a/tests/ui/stdlib-unit-tests/builtin-clone.rs b/library/std/tests/builtin-clone.rs similarity index 69% rename from tests/ui/stdlib-unit-tests/builtin-clone.rs rename to library/std/tests/builtin-clone.rs index 47c00ede0e971..66b57130c954b 100644 --- a/tests/ui/stdlib-unit-tests/builtin-clone.rs +++ b/library/std/tests/builtin-clone.rs @@ -1,4 +1,3 @@ -//@ run-pass // Test that `Clone` is correctly implemented for builtin types. // Also test that cloning an array or a tuple is done right, i.e. // each component is cloned. @@ -7,7 +6,7 @@ fn test_clone(arg: T) { let _ = arg.clone(); } -fn foo() { } +fn foo() {} #[derive(Debug, PartialEq, Eq)] struct S(i32); @@ -18,7 +17,8 @@ impl Clone for S { } } -fn main() { +#[test] +fn builtin_clone() { test_clone(foo); test_clone([1; 56]); test_clone((1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)); @@ -27,19 +27,7 @@ fn main() { let b = [S(1), S(2), S(3)]; assert_eq!(b, a.clone()); - let a = ( - (S(1), S(0)), - ( - (S(0), S(0), S(1)), - S(0) - ) - ); - let b = ( - (S(2), S(1)), - ( - (S(1), S(1), S(2)), - S(1) - ) - ); + let a = ((S(1), S(0)), ((S(0), S(0), S(1)), S(0))); + let b = ((S(2), S(1)), ((S(1), S(1), S(2)), S(1))); assert_eq!(b, a.clone()); } diff --git a/library/std/tests/eq-multidispatch.rs b/library/std/tests/eq-multidispatch.rs new file mode 100644 index 0000000000000..96e440f85e0ac --- /dev/null +++ b/library/std/tests/eq-multidispatch.rs @@ -0,0 +1,51 @@ +#[derive(PartialEq, Debug)] +struct Bar; +#[derive(Debug)] +struct Baz; +#[derive(Debug)] +struct Foo; +#[derive(Debug)] +struct Fu; + +impl PartialEq for Baz { + fn eq(&self, _: &Baz) -> bool { + true + } +} + +impl PartialEq for Foo { + fn eq(&self, _: &Fu) -> bool { + true + } +} + +impl PartialEq for Fu { + fn eq(&self, _: &Foo) -> bool { + true + } +} + +impl PartialEq for Foo { + fn eq(&self, _: &Bar) -> bool { + false + } +} + +impl PartialEq for Bar { + fn eq(&self, _: &Foo) -> bool { + false + } +} + +#[test] +fn eq_multidispatch() { + assert!(Bar != Foo); + assert!(Foo != Bar); + + assert_eq!(Bar, Bar); + + assert_eq!(Baz, Baz); + + assert_eq!(Foo, Fu); + assert_eq!(Fu, Foo); +} diff --git a/tests/ui/stdlib-unit-tests/istr.rs b/library/std/tests/istr.rs similarity index 82% rename from tests/ui/stdlib-unit-tests/istr.rs rename to library/std/tests/istr.rs index f6298919425d1..9a127ae803e77 100644 --- a/tests/ui/stdlib-unit-tests/istr.rs +++ b/library/std/tests/istr.rs @@ -1,5 +1,4 @@ -//@ run-pass - +#[test] fn test_stack_assign() { let s: String = "a".to_string(); println!("{}", s.clone()); @@ -9,8 +8,12 @@ fn test_stack_assign() { assert!((s != u)); } -fn test_heap_lit() { "a big string".to_string(); } +#[test] +fn test_heap_lit() { + "a big string".to_string(); +} +#[test] fn test_heap_assign() { let s: String = "a big ol' string".to_string(); let t: String = "a big ol' string".to_string(); @@ -19,11 +22,13 @@ fn test_heap_assign() { assert!((s != u)); } +#[test] fn test_heap_log() { let s = "a big ol' string".to_string(); println!("{}", s); } +#[test] fn test_append() { let mut s = String::new(); s.push_str("a"); @@ -41,11 +46,3 @@ fn test_append() { s.push_str("&tea"); assert_eq!(s, "coffee&tea"); } - -pub fn main() { - test_stack_assign(); - test_heap_lit(); - test_heap_assign(); - test_heap_log(); - test_append(); -} diff --git a/tests/ui/stdlib-unit-tests/log-knows-the-names-of-variants-in-std.rs b/library/std/tests/log-knows-the-names-of-variants-in-std.rs similarity index 85% rename from tests/ui/stdlib-unit-tests/log-knows-the-names-of-variants-in-std.rs rename to library/std/tests/log-knows-the-names-of-variants-in-std.rs index 8f351b2b40b6f..118bee620185c 100644 --- a/tests/ui/stdlib-unit-tests/log-knows-the-names-of-variants-in-std.rs +++ b/library/std/tests/log-knows-the-names-of-variants-in-std.rs @@ -1,18 +1,18 @@ -//@ run-pass - #![allow(non_camel_case_types)] #![allow(dead_code)] + #[derive(Clone, Debug)] enum foo { - a(usize), - b(String), + a(usize), + b(String), } fn check_log(exp: String, v: T) { assert_eq!(exp, format!("{:?}", v)); } -pub fn main() { +#[test] +fn log_knows_the_names_of_variants_in_std() { let mut x = Some(foo::a(22)); let exp = "Some(a(22))".to_string(); let act = format!("{:?}", x); diff --git a/tests/ui/stdlib-unit-tests/minmax-stability-issue-23687.rs b/library/std/tests/minmax-stability-issue-23687.rs similarity index 96% rename from tests/ui/stdlib-unit-tests/minmax-stability-issue-23687.rs rename to library/std/tests/minmax-stability-issue-23687.rs index bf42347df0bf4..119c520de8f05 100644 --- a/tests/ui/stdlib-unit-tests/minmax-stability-issue-23687.rs +++ b/library/std/tests/minmax-stability-issue-23687.rs @@ -1,12 +1,10 @@ -//@ run-pass - -use std::fmt::Debug; use std::cmp::{self, Ordering}; +use std::fmt::Debug; #[derive(Debug, Copy, Clone, PartialEq, Eq)] struct Foo { n: u8, - name: &'static str + name: &'static str, } impl PartialOrd for Foo { @@ -21,7 +19,8 @@ impl Ord for Foo { } } -fn main() { +#[test] +fn minmax_stability() { let a = Foo { n: 4, name: "a" }; let b = Foo { n: 4, name: "b" }; let c = Foo { n: 8, name: "c" }; diff --git a/tests/ui/stdlib-unit-tests/seq-compare.rs b/library/std/tests/seq-compare.rs similarity index 95% rename from tests/ui/stdlib-unit-tests/seq-compare.rs rename to library/std/tests/seq-compare.rs index 1be0569e17c09..221f1c7cabde5 100644 --- a/tests/ui/stdlib-unit-tests/seq-compare.rs +++ b/library/std/tests/seq-compare.rs @@ -1,6 +1,5 @@ -//@ run-pass - -pub fn main() { +#[test] +fn seq_compare() { assert!(("hello".to_string() < "hellr".to_string())); assert!(("hello ".to_string() > "hello".to_string())); assert!(("hello".to_string() != "there".to_string())); diff --git a/tests/ui/std/slice-from-array-issue-113238.rs b/library/std/tests/slice-from-array-issue-113238.rs similarity index 90% rename from tests/ui/std/slice-from-array-issue-113238.rs rename to library/std/tests/slice-from-array-issue-113238.rs index 44f2d7a9478b6..97aba4fec01e0 100644 --- a/tests/ui/std/slice-from-array-issue-113238.rs +++ b/library/std/tests/slice-from-array-issue-113238.rs @@ -1,9 +1,8 @@ -//@ check-pass - // This intends to use the unsizing coercion from array to slice, but it only // works if we resolve `<&[u8]>::from` as the reflexive `From for T`. In // #113238, we found that gimli had added its own `From for &[u8]` // that affected all `std/backtrace` users. -fn main() { +#[test] +fn slice_from_array() { let _ = <&[u8]>::from(&[]); } diff --git a/tests/ui/stdlib-unit-tests/issue-21058.rs b/library/std/tests/type-name-unsized.rs similarity index 63% rename from tests/ui/stdlib-unit-tests/issue-21058.rs rename to library/std/tests/type-name-unsized.rs index 0e04f1e21b8b3..2974668b2ce71 100644 --- a/tests/ui/stdlib-unit-tests/issue-21058.rs +++ b/library/std/tests/type-name-unsized.rs @@ -1,10 +1,13 @@ -//@ run-pass #![allow(dead_code)] use std::fmt::Debug; struct NT(str); -struct DST { a: u32, b: str } + +struct DST { + a: u32, + b: str, +} macro_rules! check { (val: $ty_of:expr, $expected:expr) => { @@ -15,23 +18,24 @@ macro_rules! check { }; } -fn main() { - // type_name should support unsized types +/// Tests that [`std::any::type_name`] supports unsized types. +#[test] +fn type_name_unsized() { check!([u8], "[u8]"); check!(str, "str"); check!(dyn Send, "dyn core::marker::Send"); - check!(NT, "issue_21058::NT"); - check!(DST, "issue_21058::DST"); + check!(NT, "type_name_unsized::NT"); + check!(DST, "type_name_unsized::DST"); check!(&i32, "&i32"); check!(&'static i32, "&i32"); check!((i32, u32), "(i32, u32)"); - check!(val: foo(), "issue_21058::Foo"); - check!(val: Foo::new, "issue_21058::Foo::new"); + check!(val: foo(), "type_name_unsized::Foo"); + check!(val: Foo::new, "type_name_unsized::Foo::new"); check!(val: ::fmt, - "::fmt" + "::fmt" ); - check!(val: || {}, "issue_21058::main::{{closure}}"); + check!(val: || {}, "type_name_unsized::type_name_unsized::{{closure}}"); bar::(); } @@ -56,7 +60,9 @@ fn type_name_of_val(_: T) -> &'static str { struct Foo; impl Foo { - fn new() -> Self { Foo } + fn new() -> Self { + Foo + } } fn foo() -> impl Debug { diff --git a/tests/ui/stdlib-unit-tests/volatile-fat-ptr.rs b/library/std/tests/volatile-fat-ptr.rs similarity index 90% rename from tests/ui/stdlib-unit-tests/volatile-fat-ptr.rs rename to library/std/tests/volatile-fat-ptr.rs index ef227a9134dd6..b005c12c6187b 100644 --- a/tests/ui/stdlib-unit-tests/volatile-fat-ptr.rs +++ b/library/std/tests/volatile-fat-ptr.rs @@ -1,10 +1,10 @@ -//@ run-pass - #![allow(stable_features)] #![feature(volatile)] + use std::ptr::{read_volatile, write_volatile}; -fn main() { +#[test] +fn volatile_fat_ptr() { let mut x: &'static str = "test"; unsafe { let a = read_volatile(&x); diff --git a/src/tools/tidy/src/issues.txt b/src/tools/tidy/src/issues.txt index 4f02a61f7bc7b..a931782e8ccbe 100644 --- a/src/tools/tidy/src/issues.txt +++ b/src/tools/tidy/src/issues.txt @@ -3862,7 +3862,6 @@ ui/statics/issue-91050-1.rs ui/statics/issue-91050-2.rs ui/std/issue-3563-3.rs ui/std/issue-81357-unsound-file-methods.rs -ui/stdlib-unit-tests/issue-21058.rs ui/structs-enums/enum-rec/issue-17431-6.rs ui/structs-enums/enum-rec/issue-17431-7.rs ui/structs-enums/issue-103869.rs diff --git a/tests/ui/stdlib-unit-tests/eq-multidispatch.rs b/tests/ui/stdlib-unit-tests/eq-multidispatch.rs deleted file mode 100644 index 4a991624e349d..0000000000000 --- a/tests/ui/stdlib-unit-tests/eq-multidispatch.rs +++ /dev/null @@ -1,30 +0,0 @@ -//@ run-pass - -#[derive(PartialEq, Debug)] -struct Bar; -#[derive(Debug)] -struct Baz; -#[derive(Debug)] -struct Foo; -#[derive(Debug)] -struct Fu; - -impl PartialEq for Baz { fn eq(&self, _: &Baz) -> bool { true } } - -impl PartialEq for Foo { fn eq(&self, _: &Fu) -> bool { true } } -impl PartialEq for Fu { fn eq(&self, _: &Foo) -> bool { true } } - -impl PartialEq for Foo { fn eq(&self, _: &Bar) -> bool { false } } -impl PartialEq for Bar { fn eq(&self, _: &Foo) -> bool { false } } - -fn main() { - assert!(Bar != Foo); - assert!(Foo != Bar); - - assert_eq!(Bar, Bar); - - assert_eq!(Baz, Baz); - - assert_eq!(Foo, Fu); - assert_eq!(Fu, Foo); -}