diff --git a/src/tools/tidy/src/issues.txt b/src/tools/tidy/src/issues.txt index 3e9d79224fdde..a3aca3110eb2b 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 @@ -1371,9 +1370,6 @@ ui/intrinsics/issue-28575.rs ui/intrinsics/issue-84297-reifying-copy.rs ui/invalid/issue-114435-layout-type-err.rs ui/issue-11881.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 51% rename from tests/ui/issues-71798.rs rename to tests/ui/async-await/impl-future-escaping-bound-vars-ice.rs index 14b6c0f35812f..ea30e8c839f77 100644 --- a/tests/ui/issues-71798.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/issues-71798.stderr b/tests/ui/async-await/impl-future-escaping-bound-vars-ice.stderr similarity index 85% rename from tests/ui/issues-71798.stderr rename to tests/ui/async-await/impl-future-escaping-bound-vars-ice.stderr index 52dd14ccb0a14..5beca58e13c77 100644 --- a/tests/ui/issues-71798.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 new file mode 100644 index 0000000000000..d1b4f5407d2c8 --- /dev/null +++ b/tests/ui/closures/closure-capture-after-clone.rs @@ -0,0 +1,39 @@ +//! Regression test for issue #1399 +//! +//! This test ensures that when a variable is used (via clone) and then later +//! captured by a closure, the last-use analyzer 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 analyzer must not treat step 2 as the "last use" since step 3 needs `k`. +//! +//! See: https://github.com/rust-lang/rust/issues/1399 + +//@ run-pass + +struct A { + _a: Box +} + +pub fn main() { + fn invoke(f: F) + where + F: FnOnce() + { + f(); + } + + let k: Box<_> = 22.into(); + + // 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 new file mode 100644 index 0000000000000..f5b99d87f0918 --- /dev/null +++ b/tests/ui/closures/closure-last-use-move.rs @@ -0,0 +1,33 @@ +//! 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 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 // This should be a move, not requiring copy + }) +} + +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 new file mode 100644 index 0000000000000..bf6d39c80e3ed --- /dev/null +++ b/tests/ui/closures/closure-upvar-last-use-analysis.rs @@ -0,0 +1,32 @@ +//! Regression test for issue #1399 +//! +//! This test ensures that the compiler's last-use analysis correctly handles variables +//! that are captured by closures (upvars). The original issue was that the analyzer +//! 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 + +//@ run-pass + +struct A { + _a: Box +} + +fn foo() -> Box isize + 'static> { + let k: Box<_> = Box::new(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) +} + +pub fn main() { + assert_eq!(foo()(), 22); +} 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/cross-crate/cross-crate-refcell-match.rs b/tests/ui/cross-crate/cross-crate-refcell-match.rs new file mode 100644 index 0000000000000..737ce6f1be3fe --- /dev/null +++ b/tests/ui/cross-crate/cross-crate-refcell-match.rs @@ -0,0 +1,39 @@ +//! 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. +//! Original error: assertion failed in ty.rs:2481 during type inference. + +//@ run-pass +//@ aux-build:cross-crate-refcell-match.rs + +extern crate cross_crate_refcell_match as lib; + +use std::cell::RefCell; + +struct App { + i: isize, +} + +impl lib::Update for App { + fn update(&mut self) { + self.i += 1; + } +} + +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 new file mode 100644 index 0000000000000..c33754ff07d92 --- /dev/null +++ b/tests/ui/cross-crate/metadata-trait-serialization.rs @@ -0,0 +1,12 @@ +//! Test that trait information (like Copy) is correctly serialized in crate metadata + +//@ run-pass +//@ aux-build:kinds_in_metadata.rs + +extern crate kinds_in_metadata; + +use kinds_in_metadata::f; + +pub fn main() { + f::(); +} diff --git a/tests/ui/issue-15924.rs b/tests/ui/issue-15924.rs deleted file mode 100644 index eb2aef9cee12b..0000000000000 --- a/tests/ui/issue-15924.rs +++ /dev/null @@ -1,52 +0,0 @@ -//@ run-pass - -#![allow(unused_imports)] -#![allow(unused_must_use)] - -use std::fmt; -use std::marker::PhantomData; - -trait Encoder { - type Error; -} - -trait Encodable { - fn encode(&self, s: &mut S) -> Result<(), S::Error>; -} - -impl Encodable for i32 { - fn encode(&self, _s: &mut S) -> Result<(), S::Error> { - Ok(()) - } -} - -struct JsonEncoder<'a>(PhantomData<&'a mut ()>); - -impl Encoder for JsonEncoder<'_> { - type Error = (); -} - -fn encode_json Encodable>>( - object: &T, -) -> Result { - let s = String::new(); - { - let mut encoder = JsonEncoder(PhantomData); - object.encode(&mut encoder)?; - } - Ok(s) -} - -struct Foo Encodable>> { - v: T, -} - -impl Encodable>> Drop for Foo { - fn drop(&mut self) { - encode_json(&self.v); - } -} - -fn main() { - let _ = Foo { v: 10 }; -} diff --git a/tests/ui/issue-16822.rs b/tests/ui/issue-16822.rs deleted file mode 100644 index 94d89f88f4705..0000000000000 --- a/tests/ui/issue-16822.rs +++ /dev/null @@ -1,22 +0,0 @@ -//@ run-pass -//@ aux-build:issue-16822.rs - -extern crate issue_16822 as lib; - -use std::cell::RefCell; - -struct App { - i: isize -} - -impl lib::Update for App { - fn update(&mut self) { - self.i += 1; - } -} - -fn main(){ - let app = App { i: 5 }; - let window = lib::Window { data: RefCell::new(app) }; - window.update(1); -} diff --git a/tests/ui/item-name-overload.rs b/tests/ui/item-name-overload.rs deleted file mode 100644 index dd2925aa53fe4..0000000000000 --- a/tests/ui/item-name-overload.rs +++ /dev/null @@ -1,16 +0,0 @@ -//@ run-pass - -#![allow(dead_code)] - - - - -mod foo { - pub fn baz() { } -} - -mod bar { - pub fn baz() { } -} - -pub fn main() { } diff --git a/tests/ui/kinds-in-metadata.rs b/tests/ui/kinds-in-metadata.rs deleted file mode 100644 index 58dffba861d57..0000000000000 --- a/tests/ui/kinds-in-metadata.rs +++ /dev/null @@ -1,16 +0,0 @@ -//@ 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; - -pub fn main() { - f::(); -} diff --git a/tests/ui/kinds-of-primitive-impl.rs b/tests/ui/kinds-of-primitive-impl.rs deleted file mode 100644 index f1c2ee8e5506e..0000000000000 --- a/tests/ui/kinds-of-primitive-impl.rs +++ /dev/null @@ -1,26 +0,0 @@ -impl u8 { -//~^ error: cannot define inherent `impl` for primitive types - pub const B: u8 = 0; -} - -impl str { -//~^ 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 - pub const B: u8 = 0; - pub const C: u8 = 0; - fn foo() {} - fn bar(self) {} -} - -struct MyType; -impl &MyType { -//~^ error: cannot define inherent `impl` for primitive types - pub fn for_ref(self) {} -} - -fn main() {} diff --git a/tests/ui/last-use-in-block.rs b/tests/ui/last-use-in-block.rs deleted file mode 100644 index 4a166b97bda4b..0000000000000 --- a/tests/ui/last-use-in-block.rs +++ /dev/null @@ -1,21 +0,0 @@ -//@ run-pass - -#![allow(dead_code)] -#![allow(unused_parens)] -// Issue #1818 - - -fn lp(s: String, mut f: F) -> T where F: FnMut(String) -> T { - while false { - let r = f(s); - return (r); - } - 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 }) -} - -pub fn main() {} diff --git a/tests/ui/last-use-in-cap-clause.rs b/tests/ui/last-use-in-cap-clause.rs deleted file mode 100644 index 23c263c98058f..0000000000000 --- a/tests/ui/last-use-in-cap-clause.rs +++ /dev/null @@ -1,17 +0,0 @@ -//@ run-pass - -#![allow(dead_code)] -// Make sure #1399 stays fixed - -struct A { a: Box } - -fn foo() -> Box isize + 'static> { - let k: Box<_> = Box::new(22); - let _u = A {a: k.clone()}; - let result = || 22; - Box::new(result) -} - -pub fn main() { - assert_eq!(foo()(), 22); -} diff --git a/tests/ui/last-use-is-capture.rs b/tests/ui/last-use-is-capture.rs deleted file mode 100644 index 6e07895f1d301..0000000000000 --- a/tests/ui/last-use-is-capture.rs +++ /dev/null @@ -1,13 +0,0 @@ -//@ run-pass - -#![allow(dead_code)] -// Make sure #1399 stays fixed - -struct A { a: Box } - -pub fn main() { - fn invoke(f: F) where F: FnOnce() { f(); } - let k: Box<_> = 22.into(); - let _u = A {a: k.clone()}; - invoke(|| println!("{}", k.clone()) ) -} diff --git a/tests/ui/modules/mod-same-item-names.rs b/tests/ui/modules/mod-same-item-names.rs new file mode 100644 index 0000000000000..1e9a9caa5fc5d --- /dev/null +++ b/tests/ui/modules/mod-same-item-names.rs @@ -0,0 +1,15 @@ +//! Test that items with identical names can coexist in different modules + +//@ run-pass + +#![allow(dead_code)] + +mod foo { + pub fn baz() {} +} + +mod bar { + pub fn baz() {} +} + +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 new file mode 100644 index 0000000000000..1f7dac46b0a77 --- /dev/null +++ b/tests/ui/type/inherent-impl-primitive-types-error.rs @@ -0,0 +1,28 @@ +//! Test that inherent impl blocks cannot be defined for primitive types + +impl u8 { + //~^ error: cannot define inherent `impl` for primitive types + pub const B: u8 = 0; +} + +impl str { + //~^ 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 + pub const B: u8 = 0; + pub const C: u8 = 0; + fn foo() {} + fn bar(self) {} +} + +struct MyType; +impl &MyType { + //~^ error: cannot define inherent `impl` for primitive types + pub fn for_ref(self) {} +} + +fn main() {} diff --git a/tests/ui/kinds-of-primitive-impl.stderr b/tests/ui/type/inherent-impl-primitive-types-error.stderr similarity index 83% rename from tests/ui/kinds-of-primitive-impl.stderr rename to tests/ui/type/inherent-impl-primitive-types-error.stderr index 1c8c417e88c1f..5b79521a35e77 100644 --- a/tests/ui/kinds-of-primitive-impl.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