From 3b57db4d87ea589ec05e2c7543fb6ad2df41795f Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 1 Jul 2025 06:59:49 +0000 Subject: [PATCH 1/2] Give some UI tests more apropriate names Prepare for rework done by the rest of RUST-142440. Co-authored-by: Kivooeo --- src/tools/tidy/src/issues.txt | 4 ---- .../impl-future-escaping-bound-vars-ice.rs} | 0 .../impl-future-escaping-bound-vars-ice.stderr} | 0 .../closure-capture-after-clone.rs} | 0 .../closure-last-use-move.rs} | 0 .../closure-upvar-last-use-analysis.rs} | 0 .../auxiliary/cross-crate-refcell-match.rs} | 0 tests/ui/{ => cross-crate}/auxiliary/kinds_in_metadata.rs | 0 .../cross-crate-refcell-match.rs} | 0 .../metadata-trait-serialization.rs} | 0 .../higher-ranked-encoding.rs} | 0 .../{item-name-overload.rs => modules/mod-same-item-names.rs} | 0 .../inherent-impl-primitive-types-error.rs} | 0 .../inherent-impl-primitive-types-error.stderr} | 0 14 files changed, 4 deletions(-) rename tests/ui/{issues-71798.rs => async-await/impl-future-escaping-bound-vars-ice.rs} (100%) rename tests/ui/{issues-71798.stderr => async-await/impl-future-escaping-bound-vars-ice.stderr} (100%) rename tests/ui/{last-use-is-capture.rs => closures/closure-capture-after-clone.rs} (100%) rename tests/ui/{last-use-in-block.rs => closures/closure-last-use-move.rs} (100%) rename tests/ui/{last-use-in-cap-clause.rs => closures/closure-upvar-last-use-analysis.rs} (100%) rename tests/ui/{auxiliary/issue-16822.rs => cross-crate/auxiliary/cross-crate-refcell-match.rs} (100%) rename tests/ui/{ => cross-crate}/auxiliary/kinds_in_metadata.rs (100%) rename tests/ui/{issue-16822.rs => cross-crate/cross-crate-refcell-match.rs} (100%) rename tests/ui/{kinds-in-metadata.rs => cross-crate/metadata-trait-serialization.rs} (100%) rename tests/ui/{issue-15924.rs => higher-ranked/higher-ranked-encoding.rs} (100%) rename tests/ui/{item-name-overload.rs => modules/mod-same-item-names.rs} (100%) rename tests/ui/{kinds-of-primitive-impl.rs => type/inherent-impl-primitive-types-error.rs} (100%) rename tests/ui/{kinds-of-primitive-impl.stderr => type/inherent-impl-primitive-types-error.stderr} (100%) diff --git a/src/tools/tidy/src/issues.txt b/src/tools/tidy/src/issues.txt index 18da874dbef2e..0966c3d79356d 100644 --- a/src/tools/tidy/src/issues.txt +++ b/src/tools/tidy/src/issues.txt @@ -276,7 +276,6 @@ ui/auto-traits/issue-23080-2.rs ui/auto-traits/issue-23080.rs ui/auto-traits/issue-83857-ub.rs ui/auto-traits/issue-84075.rs -ui/auxiliary/issue-16822.rs ui/bench/issue-32062.rs ui/binding/issue-40402-1.rs ui/binding/issue-40402-2.rs @@ -1368,9 +1367,6 @@ ui/infinite/issue-41731-infinite-macro-println.rs ui/intrinsics/issue-28575.rs ui/intrinsics/issue-84297-reifying-copy.rs ui/invalid/issue-114435-layout-type-err.rs -ui/issue-15924.rs -ui/issue-16822.rs -ui/issues-71798.rs ui/issues/auxiliary/issue-11224.rs ui/issues/auxiliary/issue-11508.rs ui/issues/auxiliary/issue-11529.rs diff --git a/tests/ui/issues-71798.rs b/tests/ui/async-await/impl-future-escaping-bound-vars-ice.rs similarity index 100% rename from tests/ui/issues-71798.rs rename to tests/ui/async-await/impl-future-escaping-bound-vars-ice.rs diff --git a/tests/ui/issues-71798.stderr b/tests/ui/async-await/impl-future-escaping-bound-vars-ice.stderr similarity index 100% rename from tests/ui/issues-71798.stderr rename to tests/ui/async-await/impl-future-escaping-bound-vars-ice.stderr diff --git a/tests/ui/last-use-is-capture.rs b/tests/ui/closures/closure-capture-after-clone.rs similarity index 100% rename from tests/ui/last-use-is-capture.rs rename to tests/ui/closures/closure-capture-after-clone.rs diff --git a/tests/ui/last-use-in-block.rs b/tests/ui/closures/closure-last-use-move.rs similarity index 100% rename from tests/ui/last-use-in-block.rs rename to tests/ui/closures/closure-last-use-move.rs diff --git a/tests/ui/last-use-in-cap-clause.rs b/tests/ui/closures/closure-upvar-last-use-analysis.rs similarity index 100% rename from tests/ui/last-use-in-cap-clause.rs rename to tests/ui/closures/closure-upvar-last-use-analysis.rs diff --git a/tests/ui/auxiliary/issue-16822.rs b/tests/ui/cross-crate/auxiliary/cross-crate-refcell-match.rs similarity index 100% rename from tests/ui/auxiliary/issue-16822.rs rename to tests/ui/cross-crate/auxiliary/cross-crate-refcell-match.rs diff --git a/tests/ui/auxiliary/kinds_in_metadata.rs b/tests/ui/cross-crate/auxiliary/kinds_in_metadata.rs similarity index 100% rename from tests/ui/auxiliary/kinds_in_metadata.rs rename to tests/ui/cross-crate/auxiliary/kinds_in_metadata.rs diff --git a/tests/ui/issue-16822.rs b/tests/ui/cross-crate/cross-crate-refcell-match.rs similarity index 100% rename from tests/ui/issue-16822.rs rename to tests/ui/cross-crate/cross-crate-refcell-match.rs diff --git a/tests/ui/kinds-in-metadata.rs b/tests/ui/cross-crate/metadata-trait-serialization.rs similarity index 100% rename from tests/ui/kinds-in-metadata.rs rename to tests/ui/cross-crate/metadata-trait-serialization.rs diff --git a/tests/ui/issue-15924.rs b/tests/ui/higher-ranked/higher-ranked-encoding.rs similarity index 100% rename from tests/ui/issue-15924.rs rename to tests/ui/higher-ranked/higher-ranked-encoding.rs diff --git a/tests/ui/item-name-overload.rs b/tests/ui/modules/mod-same-item-names.rs similarity index 100% rename from tests/ui/item-name-overload.rs rename to tests/ui/modules/mod-same-item-names.rs diff --git a/tests/ui/kinds-of-primitive-impl.rs b/tests/ui/type/inherent-impl-primitive-types-error.rs similarity index 100% rename from tests/ui/kinds-of-primitive-impl.rs rename to tests/ui/type/inherent-impl-primitive-types-error.rs diff --git a/tests/ui/kinds-of-primitive-impl.stderr b/tests/ui/type/inherent-impl-primitive-types-error.stderr similarity index 100% rename from tests/ui/kinds-of-primitive-impl.stderr rename to tests/ui/type/inherent-impl-primitive-types-error.stderr From 1daba456361d0bbac3d0bd9e0f11b7784d20ebe5 Mon Sep 17 00:00:00 2001 From: Kivooeo Date: Fri, 13 Jun 2025 02:30:47 +0500 Subject: [PATCH 2/2] cleaned up some tests --- .../impl-future-escaping-bound-vars-ice.rs | 4 ++ ...impl-future-escaping-bound-vars-ice.stderr | 4 +- .../closures/closure-capture-after-clone.rs | 40 ++++++++++++++---- tests/ui/closures/closure-last-use-move.rs | 42 ++++++++++++------- .../closure-upvar-last-use-analysis.rs | 27 +++++++++--- .../cross-crate/cross-crate-refcell-match.rs | 22 ++++++++-- .../metadata-trait-serialization.rs | 5 +-- .../higher-ranked/higher-ranked-encoding.rs | 15 ++++--- tests/ui/modules/mod-same-item-names.rs | 11 +++-- .../inherent-impl-primitive-types-error.rs | 10 +++-- ...inherent-impl-primitive-types-error.stderr | 10 ++--- 11 files changed, 130 insertions(+), 60 deletions(-) diff --git a/tests/ui/async-await/impl-future-escaping-bound-vars-ice.rs b/tests/ui/async-await/impl-future-escaping-bound-vars-ice.rs index 14b6c0f35812f..ea30e8c839f77 100644 --- a/tests/ui/async-await/impl-future-escaping-bound-vars-ice.rs +++ b/tests/ui/async-await/impl-future-escaping-bound-vars-ice.rs @@ -1,3 +1,7 @@ +//! Regression test for issue https://github.com/rust-lang/rust/issues/71798 +// ICE with escaping bound variables when impl Future + '_ +// returns non-Future type combined with syntax errors + fn test_ref(x: &u32) -> impl std::future::Future + '_ { //~^ ERROR `u32` is not a future *x diff --git a/tests/ui/async-await/impl-future-escaping-bound-vars-ice.stderr b/tests/ui/async-await/impl-future-escaping-bound-vars-ice.stderr index 52dd14ccb0a14..5beca58e13c77 100644 --- a/tests/ui/async-await/impl-future-escaping-bound-vars-ice.stderr +++ b/tests/ui/async-await/impl-future-escaping-bound-vars-ice.stderr @@ -1,11 +1,11 @@ error[E0425]: cannot find value `u` in this scope - --> $DIR/issues-71798.rs:7:24 + --> $DIR/impl-future-escaping-bound-vars-ice.rs:11:24 | LL | let _ = test_ref & u; | ^ not found in this scope error[E0277]: `u32` is not a future - --> $DIR/issues-71798.rs:1:25 + --> $DIR/impl-future-escaping-bound-vars-ice.rs:5:25 | LL | fn test_ref(x: &u32) -> impl std::future::Future + '_ { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `u32` is not a future diff --git a/tests/ui/closures/closure-capture-after-clone.rs b/tests/ui/closures/closure-capture-after-clone.rs index 6e07895f1d301..29fba147909b4 100644 --- a/tests/ui/closures/closure-capture-after-clone.rs +++ b/tests/ui/closures/closure-capture-after-clone.rs @@ -1,13 +1,39 @@ -//@ run-pass +//! Regression test for issue #1399 +//! +//! This tests that when a variable is used (via clone) and then later +//! captured by a closure, the last-use analysis doesn't incorrectly optimize +//! the earlier use as a "last use" and perform an invalid move. +//! +//! The sequence being tested: +//! 1. Create variable `k` +//! 2. Use `k.clone()` for some purpose +//! 3. Later capture `k` in a closure +//! +//! The analysis must not treat step 2 as the "last use" since step 3 needs `k`. +//! +//! See: https://github.com/rust-lang/rust/issues/1399 -#![allow(dead_code)] -// Make sure #1399 stays fixed +//@ run-pass -struct A { a: Box } +struct A { + _a: Box, +} pub fn main() { - fn invoke(f: F) where F: FnOnce() { f(); } + fn invoke(f: F) + where + F: FnOnce(), + { + f(); + } + let k: Box<_> = 22.into(); - let _u = A {a: k.clone()}; - invoke(|| println!("{}", k.clone()) ) + + // This clone should NOT be treated as "last use" of k + // even though k is not used again until the closure + let _u = A { _a: k.clone() }; + + // Here k is actually captured by the closure + // The last-use analyzer must have accounted for this when processing the clone above + invoke(|| println!("{}", k.clone())); } diff --git a/tests/ui/closures/closure-last-use-move.rs b/tests/ui/closures/closure-last-use-move.rs index 4a166b97bda4b..f5b99d87f0918 100644 --- a/tests/ui/closures/closure-last-use-move.rs +++ b/tests/ui/closures/closure-last-use-move.rs @@ -1,21 +1,33 @@ -//@ run-pass - -#![allow(dead_code)] -#![allow(unused_parens)] -// Issue #1818 +//! Regression test for issue #1818 +//! last-use analysis in closures should allow moves instead of requiring copies. +//! +//! The original issue was that the compiler incorrectly flagged certain return values +//! in anonymous functions/closures as requiring copies of non-copyable values, when +//! they should have been treated as moves (since they were the last use of the value). +//! +//! See: https://github.com/rust-lang/rust/issues/1818 +//@ run-pass -fn lp(s: String, mut f: F) -> T where F: FnMut(String) -> T { - while false { - let r = f(s); - return (r); +fn apply(s: String, mut f: F) -> T +where + F: FnMut(String) -> T +{ + fn g(s: String, mut f: F) -> T + where + F: FnMut(String) -> T + { + f(s) } - panic!(); -} -fn apply(s: String, mut f: F) -> T where F: FnMut(String) -> T { - fn g(s: String, mut f: F) -> T where F: FnMut(String) -> T {f(s)} - g(s, |v| { let r = f(v); r }) + g(s, |v| { + let r = f(v); + r // This should be a move, not requiring copy + }) } -pub fn main() {} +pub fn main() { + // Actually test the functionality + let result = apply(String::from("test"), |s| s.len()); + assert_eq!(result, 4); +} diff --git a/tests/ui/closures/closure-upvar-last-use-analysis.rs b/tests/ui/closures/closure-upvar-last-use-analysis.rs index 23c263c98058f..2c3e349437dc1 100644 --- a/tests/ui/closures/closure-upvar-last-use-analysis.rs +++ b/tests/ui/closures/closure-upvar-last-use-analysis.rs @@ -1,14 +1,29 @@ -//@ run-pass +//! Regression test for issue #1399 +//! +//! This tests that the compiler's last-use analysis correctly handles variables +//! that are captured by closures (upvars). The original issue was that the analysis +//! would incorrectly optimize variable usage as "last use" and perform moves, even when +//! the variable was later needed by a closure that captured it. +//! +//! See: https://github.com/rust-lang/rust/issues/1399 -#![allow(dead_code)] -// Make sure #1399 stays fixed +//@ run-pass -struct A { a: Box } +struct A { + _a: Box, +} fn foo() -> Box isize + 'static> { let k: Box<_> = Box::new(22); - let _u = A {a: k.clone()}; - let result = || 22; + + // This use of k.clone() should not be treated as a "last use" + // even though the closure below doesn't actually capture k + let _u = A { _a: k.clone() }; + + // The closure doesn't actually use k, but the analyzer needs to handle + // the potential capture scenario correctly + let result = || 22; + Box::new(result) } diff --git a/tests/ui/cross-crate/cross-crate-refcell-match.rs b/tests/ui/cross-crate/cross-crate-refcell-match.rs index 94d89f88f4705..7e46425612f33 100644 --- a/tests/ui/cross-crate/cross-crate-refcell-match.rs +++ b/tests/ui/cross-crate/cross-crate-refcell-match.rs @@ -1,12 +1,24 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/16822 +// +//! ICE when using RefCell::borrow_mut() +//! inside match statement with cross-crate generics. +//! +//! The bug occurred when: +//! - A library defines a generic struct with RefCell and uses borrow_mut() in match +//! - Main crate implements the library trait for its own type +//! - Cross-crate generic constraint causes type inference issues +//! +//! The problematic match statement is in the auxiliary file, this file triggers it. + //@ run-pass -//@ aux-build:issue-16822.rs +//@ aux-build:cross-crate-refcell-match.rs -extern crate issue_16822 as lib; +extern crate cross_crate_refcell_match as lib; use std::cell::RefCell; struct App { - i: isize + i: isize, } impl lib::Update for App { @@ -15,8 +27,10 @@ impl lib::Update for App { } } -fn main(){ +fn main() { let app = App { i: 5 }; let window = lib::Window { data: RefCell::new(app) }; + // This specific pattern (RefCell::borrow_mut in match with cross-crate generics) + // caused the ICE in the original issue window.update(1); } diff --git a/tests/ui/cross-crate/metadata-trait-serialization.rs b/tests/ui/cross-crate/metadata-trait-serialization.rs index 58dffba861d57..a6645018da4ae 100644 --- a/tests/ui/cross-crate/metadata-trait-serialization.rs +++ b/tests/ui/cross-crate/metadata-trait-serialization.rs @@ -1,12 +1,11 @@ +//! Test that trait information (like Copy) is correctly serialized in crate metadata + //@ run-pass //@ aux-build:kinds_in_metadata.rs - /* Any copyright is dedicated to the Public Domain. * http://creativecommons.org/publicdomain/zero/1.0/ */ -// Tests that metadata serialization works for the `Copy` kind. - extern crate kinds_in_metadata; use kinds_in_metadata::f; diff --git a/tests/ui/higher-ranked/higher-ranked-encoding.rs b/tests/ui/higher-ranked/higher-ranked-encoding.rs index eb2aef9cee12b..463e0f50e5379 100644 --- a/tests/ui/higher-ranked/higher-ranked-encoding.rs +++ b/tests/ui/higher-ranked/higher-ranked-encoding.rs @@ -1,9 +1,7 @@ -//@ run-pass +//! Regression test for https://github.com/rust-lang/rust/issues/15924 -#![allow(unused_imports)] -#![allow(unused_must_use)] +//@ run-pass -use std::fmt; use std::marker::PhantomData; trait Encoder { @@ -26,9 +24,8 @@ impl Encoder for JsonEncoder<'_> { type Error = (); } -fn encode_json Encodable>>( - object: &T, -) -> Result { +// This function uses higher-ranked trait bounds, which previously caused ICE +fn encode_json Encodable>>(object: &T) -> Result { let s = String::new(); { let mut encoder = JsonEncoder(PhantomData); @@ -37,13 +34,15 @@ fn encode_json Encodable>>( Ok(s) } +// Structure with HRTB constraint that was problematic struct Foo Encodable>> { v: T, } +// Drop implementation that exercises the HRTB bounds impl Encodable>> Drop for Foo { fn drop(&mut self) { - encode_json(&self.v); + let _ = encode_json(&self.v); } } diff --git a/tests/ui/modules/mod-same-item-names.rs b/tests/ui/modules/mod-same-item-names.rs index dd2925aa53fe4..1e9a9caa5fc5d 100644 --- a/tests/ui/modules/mod-same-item-names.rs +++ b/tests/ui/modules/mod-same-item-names.rs @@ -1,16 +1,15 @@ +//! Test that items with identical names can coexist in different modules + //@ run-pass #![allow(dead_code)] - - - mod foo { - pub fn baz() { } + pub fn baz() {} } mod bar { - pub fn baz() { } + pub fn baz() {} } -pub fn main() { } +pub fn main() {} diff --git a/tests/ui/type/inherent-impl-primitive-types-error.rs b/tests/ui/type/inherent-impl-primitive-types-error.rs index f1c2ee8e5506e..88b8b9da56b8e 100644 --- a/tests/ui/type/inherent-impl-primitive-types-error.rs +++ b/tests/ui/type/inherent-impl-primitive-types-error.rs @@ -1,16 +1,18 @@ +//! Test that inherent impl blocks cannot be defined for primitive types + impl u8 { -//~^ error: cannot define inherent `impl` for primitive types + //~^ ERROR: cannot define inherent `impl` for primitive types pub const B: u8 = 0; } impl str { -//~^ error: cannot define inherent `impl` for primitive types + //~^ ERROR: cannot define inherent `impl` for primitive types fn foo() {} fn bar(self) {} //~ ERROR: size for values of type `str` cannot be known } impl char { -//~^ error: cannot define inherent `impl` for primitive types + //~^ ERROR: cannot define inherent `impl` for primitive types pub const B: u8 = 0; pub const C: u8 = 0; fn foo() {} @@ -19,7 +21,7 @@ impl char { struct MyType; impl &MyType { -//~^ error: cannot define inherent `impl` for primitive types + //~^ ERROR: cannot define inherent `impl` for primitive types pub fn for_ref(self) {} } diff --git a/tests/ui/type/inherent-impl-primitive-types-error.stderr b/tests/ui/type/inherent-impl-primitive-types-error.stderr index 1c8c417e88c1f..5b79521a35e77 100644 --- a/tests/ui/type/inherent-impl-primitive-types-error.stderr +++ b/tests/ui/type/inherent-impl-primitive-types-error.stderr @@ -1,5 +1,5 @@ error[E0390]: cannot define inherent `impl` for primitive types - --> $DIR/kinds-of-primitive-impl.rs:1:1 + --> $DIR/inherent-impl-primitive-types-error.rs:3:1 | LL | impl u8 { | ^^^^^^^ @@ -7,7 +7,7 @@ LL | impl u8 { = help: consider using an extension trait instead error[E0390]: cannot define inherent `impl` for primitive types - --> $DIR/kinds-of-primitive-impl.rs:6:1 + --> $DIR/inherent-impl-primitive-types-error.rs:8:1 | LL | impl str { | ^^^^^^^^ @@ -15,7 +15,7 @@ LL | impl str { = help: consider using an extension trait instead error[E0390]: cannot define inherent `impl` for primitive types - --> $DIR/kinds-of-primitive-impl.rs:12:1 + --> $DIR/inherent-impl-primitive-types-error.rs:14:1 | LL | impl char { | ^^^^^^^^^ @@ -23,7 +23,7 @@ LL | impl char { = help: consider using an extension trait instead error[E0390]: cannot define inherent `impl` for primitive types - --> $DIR/kinds-of-primitive-impl.rs:21:1 + --> $DIR/inherent-impl-primitive-types-error.rs:23:1 | LL | impl &MyType { | ^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | impl &MyType { = note: you could also try moving the reference to uses of `MyType` (such as `self`) within the implementation error[E0277]: the size for values of type `str` cannot be known at compilation time - --> $DIR/kinds-of-primitive-impl.rs:9:12 + --> $DIR/inherent-impl-primitive-types-error.rs:11:12 | LL | fn bar(self) {} | ^^^^ doesn't have a size known at compile-time