From 74657a4a1a8b18bed905bd997aa390a90a3b943f Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Sat, 28 Jun 2025 18:59:25 -0500 Subject: Move some UI tests to more apropriate directories Prepare for rework done in the rest of [PR143118]. [PR143118]: https://www.github.com/rust-lang/rust/pull/143118 Co-authored-by: Kivooeo --- tests/ui/resolve/struct-function-same-name.rs | 32 +++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tests/ui/resolve/struct-function-same-name.rs (limited to 'tests/ui/resolve/struct-function-same-name.rs') diff --git a/tests/ui/resolve/struct-function-same-name.rs b/tests/ui/resolve/struct-function-same-name.rs new file mode 100644 index 00000000000..338a3156a9a --- /dev/null +++ b/tests/ui/resolve/struct-function-same-name.rs @@ -0,0 +1,32 @@ +//@ run-pass + +#![allow(non_snake_case)] +trait Product { + fn product(&self) -> isize; +} + +struct Foo { + x: isize, + y: isize, +} + +impl Foo { + pub fn sum(&self) -> isize { + self.x + self.y + } +} + +impl Product for Foo { + fn product(&self) -> isize { + self.x * self.y + } +} + +fn Foo(x: isize, y: isize) -> Foo { + Foo { x: x, y: y } +} + +pub fn main() { + let foo = Foo(3, 20); + println!("{} {}", foo.sum(), foo.product()); +} -- cgit 1.4.1-3-g733a5 From 580bc128441236345a5f3d5022af5a60091451ac Mon Sep 17 00:00:00 2001 From: Kivooeo Date: Fri, 27 Jun 2025 20:45:19 +0500 Subject: cleaned up some tests --- .../ui-test-missing-annotations-detection.rs | 9 ++++--- tests/ui/derives/derive-Debug-enum-variants.rs | 31 ++++++++++++++-------- tests/ui/fmt/debug-single-call.rs | 7 +++-- tests/ui/linkage-attr/link-section-placement.rs | 3 ++- tests/ui/log-err-phi.rs | 7 ----- tests/ui/resolve/struct-function-same-name.rs | 4 ++- tests/ui/resolve/type-param-local-var-shadowing.rs | 9 +++++-- 7 files changed, 43 insertions(+), 27 deletions(-) delete mode 100644 tests/ui/log-err-phi.rs (limited to 'tests/ui/resolve/struct-function-same-name.rs') diff --git a/tests/ui/compiletest-self-test/ui-test-missing-annotations-detection.rs b/tests/ui/compiletest-self-test/ui-test-missing-annotations-detection.rs index 2a73e49e172..3a110bdad35 100644 --- a/tests/ui/compiletest-self-test/ui-test-missing-annotations-detection.rs +++ b/tests/ui/compiletest-self-test/ui-test-missing-annotations-detection.rs @@ -1,6 +1,9 @@ -//@ should-fail +//! Regression test checks UI tests without error annotations are detected as failing. +//! +//! This tests that when we forget to use any `//~ ERROR` comments whatsoever, +//! the test doesn't succeed +//! Originally created in https://github.com/rust-lang/rust/pull/56244 -// this test ensures that when we forget to use -// any `//~ ERROR` comments whatsoever, that the test doesn't succeed +//@ should-fail fn main() {} diff --git a/tests/ui/derives/derive-Debug-enum-variants.rs b/tests/ui/derives/derive-Debug-enum-variants.rs index cb82cb4878a..26f527f7664 100644 --- a/tests/ui/derives/derive-Debug-enum-variants.rs +++ b/tests/ui/derives/derive-Debug-enum-variants.rs @@ -1,21 +1,30 @@ +//! Test that `#[derive(Debug)]` for enums correctly formats variant names. + //@ run-pass -#![allow(non_camel_case_types)] -#![allow(dead_code)] #[derive(Debug)] -enum foo { - a(usize), - b(String), - c, +enum Foo { + A(usize), + C, } #[derive(Debug)] -enum bar { - d, e, f +enum Bar { + D, } pub fn main() { - assert_eq!("a(22)".to_string(), format!("{:?}", foo::a(22))); - assert_eq!("c".to_string(), format!("{:?}", foo::c)); - assert_eq!("d".to_string(), format!("{:?}", bar::d)); + // Test variant with data + let foo_a = Foo::A(22); + assert_eq!("A(22)".to_string(), format!("{:?}", foo_a)); + + if let Foo::A(value) = foo_a { + println!("Value: {}", value); // This needs to remove #[allow(dead_code)] + } + + // Test unit variant + assert_eq!("C".to_string(), format!("{:?}", Foo::C)); + + // Test unit variant from different enum + assert_eq!("D".to_string(), format!("{:?}", Bar::D)); } diff --git a/tests/ui/fmt/debug-single-call.rs b/tests/ui/fmt/debug-single-call.rs index bb8c29694b5..b59a766c71a 100644 --- a/tests/ui/fmt/debug-single-call.rs +++ b/tests/ui/fmt/debug-single-call.rs @@ -1,9 +1,12 @@ +//! Test that Debug::fmt is called exactly once during formatting. +//! +//! This is a regression test for PR https://github.com/rust-lang/rust/pull/10715 + //@ run-pass //@ needs-threads use std::cell::Cell; -use std::fmt; -use std::thread; +use std::{fmt, thread}; struct Foo(Cell); diff --git a/tests/ui/linkage-attr/link-section-placement.rs b/tests/ui/linkage-attr/link-section-placement.rs index a8de8c2e1e7..6a143bfedb4 100644 --- a/tests/ui/linkage-attr/link-section-placement.rs +++ b/tests/ui/linkage-attr/link-section-placement.rs @@ -1,8 +1,9 @@ +//! Test placement of functions and statics in custom link sections + //@ run-pass // FIXME(static_mut_refs): Do not allow `static_mut_refs` lint #![allow(static_mut_refs)] - #![allow(non_upper_case_globals)] #[cfg(not(target_vendor = "apple"))] #[link_section = ".moretext"] diff --git a/tests/ui/log-err-phi.rs b/tests/ui/log-err-phi.rs deleted file mode 100644 index 1bb97758782..00000000000 --- a/tests/ui/log-err-phi.rs +++ /dev/null @@ -1,7 +0,0 @@ -//@ run-pass - -pub fn main() { - if false { - println!("{}", "foobar"); - } -} diff --git a/tests/ui/resolve/struct-function-same-name.rs b/tests/ui/resolve/struct-function-same-name.rs index 338a3156a9a..bb2837d7ca6 100644 --- a/tests/ui/resolve/struct-function-same-name.rs +++ b/tests/ui/resolve/struct-function-same-name.rs @@ -1,3 +1,5 @@ +//! Test that a struct and function can have the same name +//! //@ run-pass #![allow(non_snake_case)] @@ -23,7 +25,7 @@ impl Product for Foo { } fn Foo(x: isize, y: isize) -> Foo { - Foo { x: x, y: y } + Foo { x, y } } pub fn main() { diff --git a/tests/ui/resolve/type-param-local-var-shadowing.rs b/tests/ui/resolve/type-param-local-var-shadowing.rs index f858369f7ce..e08379e2acf 100644 --- a/tests/ui/resolve/type-param-local-var-shadowing.rs +++ b/tests/ui/resolve/type-param-local-var-shadowing.rs @@ -1,8 +1,13 @@ +//! Test that items in subscopes correctly shadow type parameters and local variables +//! +//! Regression test for https://github.com/rust-lang/rust/issues/23880 + //@ run-pass -// Tests that items in subscopes can shadow type parameters and local variables (see issue #23880). #![allow(unused)] -struct Foo { x: Box } +struct Foo { + x: Box, +} impl Foo { fn foo(&self) { type Bar = i32; -- cgit 1.4.1-3-g733a5