Skip to content

Commit ffa5bed

Browse files
committed
cleaned up some tests
1 parent fd50e10 commit ffa5bed

20 files changed

+203
-137
lines changed

src/tools/tidy/src/issues.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ ui/auto-traits/issue-23080-2.rs
276276
ui/auto-traits/issue-23080.rs
277277
ui/auto-traits/issue-83857-ub.rs
278278
ui/auto-traits/issue-84075.rs
279-
ui/auxiliary/issue-16822.rs
280279
ui/bench/issue-32062.rs
281280
ui/binding/issue-40402-1.rs
282281
ui/binding/issue-40402-2.rs
@@ -1371,9 +1370,6 @@ ui/intrinsics/issue-28575.rs
13711370
ui/intrinsics/issue-84297-reifying-copy.rs
13721371
ui/invalid/issue-114435-layout-type-err.rs
13731372
ui/issue-11881.rs
1374-
ui/issue-15924.rs
1375-
ui/issue-16822.rs
1376-
ui/issues-71798.rs
13771373
ui/issues/auxiliary/issue-11224.rs
13781374
ui/issues/auxiliary/issue-11508.rs
13791375
ui/issues/auxiliary/issue-11529.rs

tests/ui/issues-71798.rs renamed to tests/ui/async-await/impl-future-escaping-bound-vars-ice.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//! Regression test for issue https://github.com/rust-lang/rust/issues/71798
2+
// ICE with escaping bound variables when impl Future + '_
3+
// returns non-Future type combined with syntax errors
4+
15
fn test_ref(x: &u32) -> impl std::future::Future<Output = u32> + '_ {
26
//~^ ERROR `u32` is not a future
37
*x

tests/ui/issues-71798.stderr renamed to tests/ui/async-await/impl-future-escaping-bound-vars-ice.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0425]: cannot find value `u` in this scope
2-
--> $DIR/issues-71798.rs:7:24
2+
--> $DIR/impl-future-escaping-bound-vars-ice.rs:11:24
33
|
44
LL | let _ = test_ref & u;
55
| ^ not found in this scope
66

77
error[E0277]: `u32` is not a future
8-
--> $DIR/issues-71798.rs:1:25
8+
--> $DIR/impl-future-escaping-bound-vars-ice.rs:5:25
99
|
1010
LL | fn test_ref(x: &u32) -> impl std::future::Future<Output = u32> + '_ {
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `u32` is not a future
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//! Regression test for issue #1399
2+
//!
3+
//! This tests that when a variable is used (via clone) and then later
4+
//! captured by a closure, the last-use analysis doesn't incorrectly optimize
5+
//! the earlier use as a "last use" and perform an invalid move.
6+
//!
7+
//! The sequence being tested:
8+
//! 1. Create variable `k`
9+
//! 2. Use `k.clone()` for some purpose
10+
//! 3. Later capture `k` in a closure
11+
//!
12+
//! The analysis must not treat step 2 as the "last use" since step 3 needs `k`.
13+
//!
14+
//! See: https://github.com/rust-lang/rust/issues/1399
15+
16+
//@ run-pass
17+
18+
struct A {
19+
_a: Box<isize>,
20+
}
21+
22+
pub fn main() {
23+
fn invoke<F>(f: F)
24+
where
25+
F: FnOnce(),
26+
{
27+
f();
28+
}
29+
30+
let k: Box<_> = 22.into();
31+
32+
// This clone should NOT be treated as "last use" of k
33+
// even though k is not used again until the closure
34+
let _u = A { _a: k.clone() };
35+
36+
// Here k is actually captured by the closure
37+
// The last-use analyzer must have accounted for this when processing the clone above
38+
invoke(|| println!("{}", k.clone()));
39+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//! Regression test for issue #1818
2+
//! last-use analysis in closures should allow moves instead of requiring copies.
3+
//!
4+
//! The original issue was that the compiler incorrectly flagged certain return values
5+
//! in anonymous functions/closures as requiring copies of non-copyable values, when
6+
//! they should have been treated as moves (since they were the last use of the value).
7+
//!
8+
//! See: https://github.com/rust-lang/rust/issues/1818
9+
10+
//@ run-pass
11+
12+
fn apply<T, F>(s: String, mut f: F) -> T
13+
where
14+
F: FnMut(String) -> T
15+
{
16+
fn g<T, F>(s: String, mut f: F) -> T
17+
where
18+
F: FnMut(String) -> T
19+
{
20+
f(s)
21+
}
22+
23+
g(s, |v| {
24+
let r = f(v);
25+
r // This should be a move, not requiring copy
26+
})
27+
}
28+
29+
pub fn main() {
30+
// Actually test the functionality
31+
let result = apply(String::from("test"), |s| s.len());
32+
assert_eq!(result, 4);
33+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//! Regression test for issue #1399
2+
//!
3+
//! This tests that the compiler's last-use analysis correctly handles variables
4+
//! that are captured by closures (upvars). The original issue was that the analysis
5+
//! would incorrectly optimize variable usage as "last use" and perform moves, even when
6+
//! the variable was later needed by a closure that captured it.
7+
//!
8+
//! See: https://github.com/rust-lang/rust/issues/1399
9+
10+
//@ run-pass
11+
12+
struct A {
13+
_a: Box<isize>,
14+
}
15+
16+
fn foo() -> Box<dyn FnMut() -> isize + 'static> {
17+
let k: Box<_> = Box::new(22);
18+
19+
// This use of k.clone() should not be treated as a "last use"
20+
// even though the closure below doesn't actually capture k
21+
let _u = A { _a: k.clone() };
22+
23+
// The closure doesn't actually use k, but the analyzer needs to handle
24+
// the potential capture scenario correctly
25+
let result = || 22;
26+
27+
Box::new(result)
28+
}
29+
30+
pub fn main() {
31+
assert_eq!(foo()(), 22);
32+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//! Regression test for https://github.com/rust-lang/rust/issues/16822
2+
//
3+
//! ICE when using RefCell::borrow_mut()
4+
//! inside match statement with cross-crate generics.
5+
//!
6+
//! The bug occurred when:
7+
//! - A library defines a generic struct with RefCell<T> and uses borrow_mut() in match
8+
//! - Main crate implements the library trait for its own type
9+
//! - Cross-crate generic constraint causes type inference issues
10+
//!
11+
//! The problematic match statement is in the auxiliary file, this file triggers it.
12+
13+
//@ run-pass
14+
//@ aux-build:cross-crate-refcell-match.rs
15+
16+
extern crate cross_crate_refcell_match as lib;
17+
18+
use std::cell::RefCell;
19+
20+
struct App {
21+
i: isize,
22+
}
23+
24+
impl lib::Update for App {
25+
fn update(&mut self) {
26+
self.i += 1;
27+
}
28+
}
29+
30+
fn main() {
31+
let app = App { i: 5 };
32+
let window = lib::Window { data: RefCell::new(app) };
33+
// This specific pattern (RefCell::borrow_mut in match with cross-crate generics)
34+
// caused the ICE in the original issue
35+
window.update(1);
36+
}

tests/ui/kinds-in-metadata.rs renamed to tests/ui/cross-crate/metadata-trait-serialization.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1+
//! Test that trait information (like Copy) is correctly serialized in crate metadata
2+
13
//@ run-pass
24
//@ aux-build:kinds_in_metadata.rs
35

4-
56
/* Any copyright is dedicated to the Public Domain.
67
* http://creativecommons.org/publicdomain/zero/1.0/ */
78

8-
// Tests that metadata serialization works for the `Copy` kind.
9-
109
extern crate kinds_in_metadata;
1110

1211
use kinds_in_metadata::f;

tests/ui/issue-15924.rs renamed to tests/ui/higher-ranked/higher-ranked-encoding.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
//@ run-pass
1+
//! Regression test for https://github.com/rust-lang/rust/issues/15924
22
3-
#![allow(unused_imports)]
4-
#![allow(unused_must_use)]
3+
//@ run-pass
54

6-
use std::fmt;
75
use std::marker::PhantomData;
86

97
trait Encoder {
@@ -26,9 +24,8 @@ impl Encoder for JsonEncoder<'_> {
2624
type Error = ();
2725
}
2826

29-
fn encode_json<T: for<'r> Encodable<JsonEncoder<'r>>>(
30-
object: &T,
31-
) -> Result<String, ()> {
27+
// This function uses higher-ranked trait bounds, which previously caused ICE
28+
fn encode_json<T: for<'r> Encodable<JsonEncoder<'r>>>(object: &T) -> Result<String, ()> {
3229
let s = String::new();
3330
{
3431
let mut encoder = JsonEncoder(PhantomData);
@@ -37,13 +34,15 @@ fn encode_json<T: for<'r> Encodable<JsonEncoder<'r>>>(
3734
Ok(s)
3835
}
3936

37+
// Structure with HRTB constraint that was problematic
4038
struct Foo<T: for<'a> Encodable<JsonEncoder<'a>>> {
4139
v: T,
4240
}
4341

42+
// Drop implementation that exercises the HRTB bounds
4443
impl<T: for<'a> Encodable<JsonEncoder<'a>>> Drop for Foo<T> {
4544
fn drop(&mut self) {
46-
encode_json(&self.v);
45+
let _ = encode_json(&self.v);
4746
}
4847
}
4948

tests/ui/issue-16822.rs

Lines changed: 0 additions & 22 deletions
This file was deleted.

tests/ui/item-name-overload.rs

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests/ui/kinds-of-primitive-impl.rs

Lines changed: 0 additions & 26 deletions
This file was deleted.

tests/ui/last-use-in-block.rs

Lines changed: 0 additions & 21 deletions
This file was deleted.

tests/ui/last-use-in-cap-clause.rs

Lines changed: 0 additions & 17 deletions
This file was deleted.

tests/ui/last-use-is-capture.rs

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//! Test that items with identical names can coexist in different modules
2+
3+
//@ run-pass
4+
5+
#![allow(dead_code)]
6+
7+
mod foo {
8+
pub fn baz() {}
9+
}
10+
11+
mod bar {
12+
pub fn baz() {}
13+
}
14+
15+
pub fn main() {}

0 commit comments

Comments
 (0)