From 74657a4a1a8b18bed905bd997aa390a90a3b943f Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Sat, 28 Jun 2025 18:59:25 -0500 Subject: [PATCH 1/2] 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 --- .../ui-test-missing-annotations-detection.rs} | 0 .../derive-Debug-enum-variants.rs} | 0 .../ui/{logging-only-prints-once.rs => fmt/debug-single-call.rs} | 0 .../{link-section.rs => linkage-attr/link-section-placement.rs} | 0 .../{max-min-classes.rs => resolve/struct-function-same-name.rs} | 0 .../type-param-local-var-shadowing.rs} | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename tests/ui/{loud_ui.rs => compiletest-self-test/ui-test-missing-annotations-detection.rs} (100%) rename tests/ui/{log-knows-the-names-of-variants.rs => derives/derive-Debug-enum-variants.rs} (100%) rename tests/ui/{logging-only-prints-once.rs => fmt/debug-single-call.rs} (100%) rename tests/ui/{link-section.rs => linkage-attr/link-section-placement.rs} (100%) rename tests/ui/{max-min-classes.rs => resolve/struct-function-same-name.rs} (100%) rename tests/ui/{lexical-scoping.rs => resolve/type-param-local-var-shadowing.rs} (100%) diff --git a/tests/ui/loud_ui.rs b/tests/ui/compiletest-self-test/ui-test-missing-annotations-detection.rs similarity index 100% rename from tests/ui/loud_ui.rs rename to tests/ui/compiletest-self-test/ui-test-missing-annotations-detection.rs diff --git a/tests/ui/log-knows-the-names-of-variants.rs b/tests/ui/derives/derive-Debug-enum-variants.rs similarity index 100% rename from tests/ui/log-knows-the-names-of-variants.rs rename to tests/ui/derives/derive-Debug-enum-variants.rs diff --git a/tests/ui/logging-only-prints-once.rs b/tests/ui/fmt/debug-single-call.rs similarity index 100% rename from tests/ui/logging-only-prints-once.rs rename to tests/ui/fmt/debug-single-call.rs diff --git a/tests/ui/link-section.rs b/tests/ui/linkage-attr/link-section-placement.rs similarity index 100% rename from tests/ui/link-section.rs rename to tests/ui/linkage-attr/link-section-placement.rs diff --git a/tests/ui/max-min-classes.rs b/tests/ui/resolve/struct-function-same-name.rs similarity index 100% rename from tests/ui/max-min-classes.rs rename to tests/ui/resolve/struct-function-same-name.rs diff --git a/tests/ui/lexical-scoping.rs b/tests/ui/resolve/type-param-local-var-shadowing.rs similarity index 100% rename from tests/ui/lexical-scoping.rs rename to tests/ui/resolve/type-param-local-var-shadowing.rs From 580bc128441236345a5f3d5022af5a60091451ac Mon Sep 17 00:00:00 2001 From: Kivooeo Date: Fri, 27 Jun 2025 20:45:19 +0500 Subject: [PATCH 2/2] cleaned up some tests --- .../ui-test-missing-annotations-detection.rs | 9 ++++-- .../ui/derives/derive-Debug-enum-variants.rs | 31 ++++++++++++------- tests/ui/fmt/debug-single-call.rs | 7 +++-- .../ui/linkage-attr/link-section-placement.rs | 3 +- tests/ui/log-err-phi.rs | 7 ----- tests/ui/resolve/struct-function-same-name.rs | 4 ++- .../resolve/type-param-local-var-shadowing.rs | 9 ++++-- 7 files changed, 43 insertions(+), 27 deletions(-) delete mode 100644 tests/ui/log-err-phi.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 2a73e49e17206..3a110bdad3523 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 cb82cb4878a11..26f527f766411 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 bb8c29694b52a..b59a766c71a5a 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 a8de8c2e1e77d..6a143bfedb451 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 1bb97758782b0..0000000000000 --- 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 338a3156a9a93..bb2837d7ca6f9 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 f858369f7ce7e..e08379e2acff9 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;