Skip to content

Commit a854db7

Browse files
Kivooeotgross35
authored andcommitted
cleaned up some tests
1 parent 774bf12 commit a854db7

11 files changed

+130
-60
lines changed

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/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: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,39 @@
1-
//@ run-pass
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
215
3-
#![allow(dead_code)]
4-
// Make sure #1399 stays fixed
16+
//@ run-pass
517

6-
struct A { a: Box<isize> }
18+
struct A {
19+
_a: Box<isize>,
20+
}
721

822
pub fn main() {
9-
fn invoke<F>(f: F) where F: FnOnce() { f(); }
23+
fn invoke<F>(f: F)
24+
where
25+
F: FnOnce(),
26+
{
27+
f();
28+
}
29+
1030
let k: Box<_> = 22.into();
11-
let _u = A {a: k.clone()};
12-
invoke(|| println!("{}", k.clone()) )
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()));
1339
}
Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,33 @@
1-
//@ run-pass
2-
3-
#![allow(dead_code)]
4-
#![allow(unused_parens)]
5-
// Issue #1818
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
69
10+
//@ run-pass
711

8-
fn lp<T, F>(s: String, mut f: F) -> T where F: FnMut(String) -> T {
9-
while false {
10-
let r = f(s);
11-
return (r);
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)
1221
}
13-
panic!();
14-
}
1522

16-
fn apply<T, F>(s: String, mut f: F) -> T where F: FnMut(String) -> T {
17-
fn g<T, F>(s: String, mut f: F) -> T where F: FnMut(String) -> T {f(s)}
18-
g(s, |v| { let r = f(v); r })
23+
g(s, |v| {
24+
let r = f(v);
25+
r // This should be a move, not requiring copy
26+
})
1927
}
2028

21-
pub fn main() {}
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+
}

tests/ui/closures/closure-upvar-last-use-analysis.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
1-
//@ run-pass
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
29
3-
#![allow(dead_code)]
4-
// Make sure #1399 stays fixed
10+
//@ run-pass
511

6-
struct A { a: Box<isize> }
12+
struct A {
13+
_a: Box<isize>,
14+
}
715

816
fn foo() -> Box<dyn FnMut() -> isize + 'static> {
917
let k: Box<_> = Box::new(22);
10-
let _u = A {a: k.clone()};
11-
let result = || 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+
1227
Box::new(result)
1328
}
1429

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
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+
113
//@ run-pass
2-
//@ aux-build:issue-16822.rs
14+
//@ aux-build:cross-crate-refcell-match.rs
315

4-
extern crate issue_16822 as lib;
16+
extern crate cross_crate_refcell_match as lib;
517

618
use std::cell::RefCell;
719

820
struct App {
9-
i: isize
21+
i: isize,
1022
}
1123

1224
impl lib::Update for App {
@@ -15,8 +27,10 @@ impl lib::Update for App {
1527
}
1628
}
1729

18-
fn main(){
30+
fn main() {
1931
let app = App { i: 5 };
2032
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
2135
window.update(1);
2236
}

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/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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1+
//! Test that items with identical names can coexist in different modules
2+
13
//@ run-pass
24

35
#![allow(dead_code)]
46

5-
6-
7-
87
mod foo {
9-
pub fn baz() { }
8+
pub fn baz() {}
109
}
1110

1211
mod bar {
13-
pub fn baz() { }
12+
pub fn baz() {}
1413
}
1514

16-
pub fn main() { }
15+
pub fn main() {}

tests/ui/type/inherent-impl-primitive-types-error.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1+
//! Test that inherent impl blocks cannot be defined for primitive types
2+
13
impl u8 {
2-
//~^ error: cannot define inherent `impl` for primitive types
4+
//~^ ERROR: cannot define inherent `impl` for primitive types
35
pub const B: u8 = 0;
46
}
57

68
impl str {
7-
//~^ error: cannot define inherent `impl` for primitive types
9+
//~^ ERROR: cannot define inherent `impl` for primitive types
810
fn foo() {}
911
fn bar(self) {} //~ ERROR: size for values of type `str` cannot be known
1012
}
1113

1214
impl char {
13-
//~^ error: cannot define inherent `impl` for primitive types
15+
//~^ ERROR: cannot define inherent `impl` for primitive types
1416
pub const B: u8 = 0;
1517
pub const C: u8 = 0;
1618
fn foo() {}
@@ -19,7 +21,7 @@ impl char {
1921

2022
struct MyType;
2123
impl &MyType {
22-
//~^ error: cannot define inherent `impl` for primitive types
24+
//~^ ERROR: cannot define inherent `impl` for primitive types
2325
pub fn for_ref(self) {}
2426
}
2527

tests/ui/type/inherent-impl-primitive-types-error.stderr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
error[E0390]: cannot define inherent `impl` for primitive types
2-
--> $DIR/kinds-of-primitive-impl.rs:1:1
2+
--> $DIR/inherent-impl-primitive-types-error.rs:3:1
33
|
44
LL | impl u8 {
55
| ^^^^^^^
66
|
77
= help: consider using an extension trait instead
88

99
error[E0390]: cannot define inherent `impl` for primitive types
10-
--> $DIR/kinds-of-primitive-impl.rs:6:1
10+
--> $DIR/inherent-impl-primitive-types-error.rs:8:1
1111
|
1212
LL | impl str {
1313
| ^^^^^^^^
1414
|
1515
= help: consider using an extension trait instead
1616

1717
error[E0390]: cannot define inherent `impl` for primitive types
18-
--> $DIR/kinds-of-primitive-impl.rs:12:1
18+
--> $DIR/inherent-impl-primitive-types-error.rs:14:1
1919
|
2020
LL | impl char {
2121
| ^^^^^^^^^
2222
|
2323
= help: consider using an extension trait instead
2424

2525
error[E0390]: cannot define inherent `impl` for primitive types
26-
--> $DIR/kinds-of-primitive-impl.rs:21:1
26+
--> $DIR/inherent-impl-primitive-types-error.rs:23:1
2727
|
2828
LL | impl &MyType {
2929
| ^^^^^^^^^^^^
@@ -32,7 +32,7 @@ LL | impl &MyType {
3232
= note: you could also try moving the reference to uses of `MyType` (such as `self`) within the implementation
3333

3434
error[E0277]: the size for values of type `str` cannot be known at compilation time
35-
--> $DIR/kinds-of-primitive-impl.rs:9:12
35+
--> $DIR/inherent-impl-primitive-types-error.rs:11:12
3636
|
3737
LL | fn bar(self) {}
3838
| ^^^^ doesn't have a size known at compile-time

0 commit comments

Comments
 (0)