Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit adda0cd

Browse files
arora-amannull-sleeplogmosier
committed
Add tests for updated closure/generator printing
Co-authored-by: Dhruv Jauhar <dhruvjhr@gmail.com> Co-authored-by: Logan Mosier <logmosier@gmail.com>
1 parent c923da0 commit adda0cd

18 files changed

+409
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
fn to_fn_once<F: FnOnce()>(f: F) -> F {
2+
f
3+
}
4+
5+
fn f<T: std::fmt::Display>(y: T) {
6+
struct Foo<U: std::fmt::Display> {
7+
x: U,
8+
};
9+
10+
let foo = Foo { x: "x" };
11+
12+
let c = to_fn_once(move || {
13+
println!("{} {}", foo.x, y);
14+
});
15+
16+
c();
17+
c();
18+
//~^ ERROR use of moved value
19+
}
20+
21+
fn main() {
22+
f("S");
23+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0382]: use of moved value: `c`
2+
--> $DIR/closure-print-generic-1.rs:17:5
3+
|
4+
LL | let c = to_fn_once(move || {
5+
| - move occurs because `c` has type `[closure@$DIR/closure-print-generic-1.rs:12:24: 14:6]`, which does not implement the `Copy` trait
6+
...
7+
LL | c();
8+
| --- `c` moved due to this call
9+
LL | c();
10+
| ^ value used here after move
11+
|
12+
note: this value implements `FnOnce`, which causes it to be moved when called
13+
--> $DIR/closure-print-generic-1.rs:16:5
14+
|
15+
LL | c();
16+
| ^
17+
18+
error: aborting due to previous error
19+
20+
For more information about this error, try `rustc --explain E0382`.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
mod mod1 {
2+
pub fn f<T: std::fmt::Display>(t: T) {
3+
let x = 20;
4+
5+
let c = || println!("{} {}", t, x);
6+
let c1: () = c;
7+
//~^ ERROR mismatched types
8+
}
9+
}
10+
11+
fn main() {
12+
mod1::f(5i32);
13+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/closure-print-generic-2.rs:6:22
3+
|
4+
LL | let c = || println!("{} {}", t, x);
5+
| -------------------------- the found closure
6+
LL | let c1: () = c;
7+
| -- ^ expected `()`, found closure
8+
| |
9+
| expected due to this
10+
|
11+
= note: expected unit type `()`
12+
found closure `[closure@$DIR/closure-print-generic-2.rs:5:17: 5:43]`
13+
help: use parentheses to call this closure
14+
|
15+
LL | let c1: () = c();
16+
| ^^
17+
18+
error: aborting due to previous error
19+
20+
For more information about this error, try `rustc --explain E0308`.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// compile-flags: -Ztrim-diagnostic-paths=off -Zverbose
2+
3+
mod mod1 {
4+
pub fn f<T: std::fmt::Display>(t: T)
5+
{
6+
let x = 20;
7+
8+
let c = || println!("{} {}", t, x);
9+
let c1 : () = c;
10+
//~^ ERROR mismatched types
11+
}
12+
}
13+
14+
fn main() {
15+
mod1::f(5i32);
16+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/closure-print-generic-trim-off-verbose-2.rs:9:23
3+
|
4+
LL | let c = || println!("{} {}", t, x);
5+
| -------------------------- the found closure
6+
LL | let c1 : () = c;
7+
| -- ^ expected `()`, found closure
8+
| |
9+
| expected due to this
10+
|
11+
= note: expected unit type `()`
12+
found closure `[mod1::f<T>::{closure#0} closure_substs=(unavailable)]`
13+
help: use parentheses to call this closure
14+
|
15+
LL | let c1 : () = c();
16+
| ^^
17+
18+
error: aborting due to previous error
19+
20+
For more information about this error, try `rustc --explain E0308`.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// compile-flags: -Zverbose
2+
3+
fn to_fn_once<F:FnOnce()>(f: F) -> F { f }
4+
5+
fn f<T: std::fmt::Display>(y: T) {
6+
struct Foo<U: std::fmt::Display> {
7+
x: U
8+
};
9+
10+
let foo = Foo{ x: "x" };
11+
12+
let c = to_fn_once(move|| {
13+
println!("{} {}", foo.x, y);
14+
});
15+
16+
c();
17+
c();
18+
//~^ ERROR use of moved value
19+
}
20+
21+
22+
fn main() {
23+
f("S");
24+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0382]: use of moved value: `c`
2+
--> $DIR/closure-print-generic-verbose-1.rs:17:5
3+
|
4+
LL | let c = to_fn_once(move|| {
5+
| - move occurs because `c` has type `[f<T>::{closure#0} closure_kind_ty=i32 closure_sig_as_fn_ptr_ty=extern "rust-call" fn(()) upvar_tys=(Foo<&'_#10r str>, T)]`, which does not implement the `Copy` trait
6+
...
7+
LL | c();
8+
| --- `c` moved due to this call
9+
LL | c();
10+
| ^ value used here after move
11+
|
12+
note: this value implements `FnOnce`, which causes it to be moved when called
13+
--> $DIR/closure-print-generic-verbose-1.rs:16:5
14+
|
15+
LL | c();
16+
| ^
17+
18+
error: aborting due to previous error
19+
20+
For more information about this error, try `rustc --explain E0382`.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// compile-flags: -Zverbose
2+
3+
mod mod1 {
4+
pub fn f<T: std::fmt::Display>(t: T)
5+
{
6+
let x = 20;
7+
8+
let c = || println!("{} {}", t, x);
9+
let c1 : () = c;
10+
//~^ ERROR mismatched types
11+
}
12+
}
13+
14+
fn main() {
15+
mod1::f(5i32);
16+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/closure-print-generic-verbose-2.rs:9:23
3+
|
4+
LL | let c = || println!("{} {}", t, x);
5+
| -------------------------- the found closure
6+
LL | let c1 : () = c;
7+
| -- ^ expected `()`, found closure
8+
| |
9+
| expected due to this
10+
|
11+
= note: expected unit type `()`
12+
found closure `[f<T>::{closure#0} closure_substs=(unavailable)]`
13+
help: use parentheses to call this closure
14+
|
15+
LL | let c1 : () = c();
16+
| ^^
17+
18+
error: aborting due to previous error
19+
20+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)