diff options
| author | Kivooeo <Kivooeo123@gmail.com> | 2025-06-13 02:30:47 +0500 |
|---|---|---|
| committer | Kivooeo <Kivooeo123@gmail.com> | 2025-07-01 16:26:57 +0500 |
| commit | 1daba456361d0bbac3d0bd9e0f11b7784d20ebe5 (patch) | |
| tree | 40d1ff4258c3d46b8f8568ee2ab35b481adaf6dc | |
| parent | 3b57db4d87ea589ec05e2c7543fb6ad2df41795f (diff) | |
| download | rust-1daba456361d0bbac3d0bd9e0f11b7784d20ebe5.tar.gz rust-1daba456361d0bbac3d0bd9e0f11b7784d20ebe5.zip | |
cleaned up some tests
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 14b6c0f3581..ea30e8c839f 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<Output = u32> + '_ { //~^ 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 52dd14ccb0a..5beca58e13c 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<Output = u32> + '_ { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `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 6e07895f1d3..29fba147909 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<isize> } +struct A { + _a: Box<isize>, +} pub fn main() { - fn invoke<F>(f: F) where F: FnOnce() { f(); } + fn invoke<F>(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 4a166b97bda..f5b99d87f09 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<T, F>(s: String, mut f: F) -> T where F: FnMut(String) -> T { - while false { - let r = f(s); - return (r); +fn apply<T, F>(s: String, mut f: F) -> T +where + F: FnMut(String) -> T +{ + fn g<T, F>(s: String, mut f: F) -> T + where + F: FnMut(String) -> T + { + f(s) } - panic!(); -} -fn apply<T, F>(s: String, mut f: F) -> T where F: FnMut(String) -> T { - fn g<T, F>(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 23c263c9805..2c3e349437d 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<isize> } +struct A { + _a: Box<isize>, +} fn foo() -> Box<dyn FnMut() -> 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 94d89f88f47..7e46425612f 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<T> 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 58dffba861d..a6645018da4 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 eb2aef9cee1..463e0f50e53 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<T: for<'r> Encodable<JsonEncoder<'r>>>( - object: &T, -) -> Result<String, ()> { +// This function uses higher-ranked trait bounds, which previously caused ICE +fn encode_json<T: for<'r> Encodable<JsonEncoder<'r>>>(object: &T) -> Result<String, ()> { let s = String::new(); { let mut encoder = JsonEncoder(PhantomData); @@ -37,13 +34,15 @@ fn encode_json<T: for<'r> Encodable<JsonEncoder<'r>>>( Ok(s) } +// Structure with HRTB constraint that was problematic struct Foo<T: for<'a> Encodable<JsonEncoder<'a>>> { v: T, } +// Drop implementation that exercises the HRTB bounds impl<T: for<'a> Encodable<JsonEncoder<'a>>> Drop for Foo<T> { 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 dd2925aa53f..1e9a9caa5fc 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 f1c2ee8e550..88b8b9da56b 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 1c8c417e88c..5b79521a35e 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 |
