Add tests
This commit is contained in:
parent
38b4746d82
commit
7c17bf8e82
17 changed files with 357 additions and 0 deletions
9
tests/ui/ergonomic-clones/async/local-type.rs
Normal file
9
tests/ui/ergonomic-clones/async/local-type.rs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
// Check that using the parameter name in its type does not ICE.
|
||||||
|
//@ edition:2018
|
||||||
|
|
||||||
|
#![feature(ergonomic_clones)]
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let _ = async use |x: x| x; //~ ERROR expected type
|
||||||
|
let _ = async use |x: bool| -> x { x }; //~ ERROR expected type
|
||||||
|
}
|
15
tests/ui/ergonomic-clones/async/local-type.stderr
Normal file
15
tests/ui/ergonomic-clones/async/local-type.stderr
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
error[E0573]: expected type, found local variable `x`
|
||||||
|
--> $DIR/local-type.rs:7:27
|
||||||
|
|
|
||||||
|
LL | let _ = async use |x: x| x;
|
||||||
|
| ^ not a type
|
||||||
|
|
||||||
|
error[E0573]: expected type, found local variable `x`
|
||||||
|
--> $DIR/local-type.rs:8:36
|
||||||
|
|
|
||||||
|
LL | let _ = async use |x: bool| -> x { x };
|
||||||
|
| ^ not a type
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0573`.
|
|
@ -40,4 +40,18 @@ fn ergonomic_clone_closure_use_cloned() -> Foo {
|
||||||
f
|
f
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn ergonomic_clone_closure_copy() -> i32 {
|
||||||
|
let i = 1;
|
||||||
|
|
||||||
|
let i1 = use || {
|
||||||
|
i
|
||||||
|
};
|
||||||
|
|
||||||
|
let i2 = use || {
|
||||||
|
i
|
||||||
|
};
|
||||||
|
|
||||||
|
i
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
13
tests/ui/ergonomic-clones/closure/fn-once.rs
Normal file
13
tests/ui/ergonomic-clones/closure/fn-once.rs
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
#![feature(ergonomic_clones)]
|
||||||
|
|
||||||
|
fn get_closure() -> Box<dyn Fn() -> Vec<u8>> {
|
||||||
|
let vec = vec![1u8, 2u8];
|
||||||
|
|
||||||
|
let closure = use || { //~ ERROR expected a closure
|
||||||
|
vec
|
||||||
|
};
|
||||||
|
|
||||||
|
Box::new(closure)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
16
tests/ui/ergonomic-clones/closure/fn-once.stderr
Normal file
16
tests/ui/ergonomic-clones/closure/fn-once.stderr
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
error[E0525]: expected a closure that implements the `Fn` trait, but this closure only implements `FnOnce`
|
||||||
|
--> $DIR/fn-once.rs:6:19
|
||||||
|
|
|
||||||
|
LL | let closure = use || {
|
||||||
|
| ^^^^^^ this closure implements `FnOnce`, not `Fn`
|
||||||
|
LL | vec
|
||||||
|
| --- closure is `FnOnce` because it moves the variable `vec` out of its environment
|
||||||
|
...
|
||||||
|
LL | Box::new(closure)
|
||||||
|
| ----------------- the requirement to implement `Fn` derives from here
|
||||||
|
|
|
||||||
|
= note: required for the cast from `Box<{closure@$DIR/fn-once.rs:6:19: 6:25}>` to `Box<(dyn Fn() -> Vec<u8> + 'static)>`
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0525`.
|
8
tests/ui/ergonomic-clones/closure/local-type.rs
Normal file
8
tests/ui/ergonomic-clones/closure/local-type.rs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
// Check that using the parameter name in its type does not ICE.
|
||||||
|
|
||||||
|
#![feature(ergonomic_clones)]
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let _ = use |x: x| x; //~ ERROR expected type
|
||||||
|
let _ = use |x: bool| -> x { x }; //~ ERROR expected type
|
||||||
|
}
|
15
tests/ui/ergonomic-clones/closure/local-type.stderr
Normal file
15
tests/ui/ergonomic-clones/closure/local-type.stderr
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
error[E0573]: expected type, found local variable `x`
|
||||||
|
--> $DIR/local-type.rs:6:21
|
||||||
|
|
|
||||||
|
LL | let _ = use |x: x| x;
|
||||||
|
| ^ not a type
|
||||||
|
|
||||||
|
error[E0573]: expected type, found local variable `x`
|
||||||
|
--> $DIR/local-type.rs:7:30
|
||||||
|
|
|
||||||
|
LL | let _ = use |x: bool| -> x { x };
|
||||||
|
| ^ not a type
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0573`.
|
18
tests/ui/ergonomic-clones/closure/once-move-out-on-heap.rs
Normal file
18
tests/ui/ergonomic-clones/closure/once-move-out-on-heap.rs
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
//@ run-pass
|
||||||
|
// Testing guarantees provided by once functions.
|
||||||
|
|
||||||
|
#![feature(ergonomic_clones)]
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
fn foo<F: FnOnce()>(blk: F) {
|
||||||
|
blk();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn main() {
|
||||||
|
let x = Arc::new(true);
|
||||||
|
foo(use || {
|
||||||
|
assert!(*x);
|
||||||
|
drop(x);
|
||||||
|
});
|
||||||
|
}
|
23
tests/ui/ergonomic-clones/closure/parse.rs
Normal file
23
tests/ui/ergonomic-clones/closure/parse.rs
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#![feature(ergonomic_clones)]
|
||||||
|
|
||||||
|
fn parse1() {
|
||||||
|
|| use {
|
||||||
|
//~^ ERROR expected one of `async`, `|`, or `||`, found `{`
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse2() {
|
||||||
|
move use || {
|
||||||
|
//~^ ERROR expected one of `async`, `|`, or `||`, found keyword `use`
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse3() {
|
||||||
|
use move || {
|
||||||
|
//~^ ERROR expected identifier, found keyword `move`
|
||||||
|
//~| ERROR expected one of `::`, `;`, or `as`, found `||`
|
||||||
|
// FIXME ideally we should error like in the previous example
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
34
tests/ui/ergonomic-clones/closure/parse.stderr
Normal file
34
tests/ui/ergonomic-clones/closure/parse.stderr
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
error: expected one of `async`, `|`, or `||`, found `{`
|
||||||
|
--> $DIR/parse.rs:4:12
|
||||||
|
|
|
||||||
|
LL | || use {
|
||||||
|
| -- ^ expected one of `async`, `|`, or `||`
|
||||||
|
| |
|
||||||
|
| while parsing the body of this closure
|
||||||
|
|
|
||||||
|
help: you might have meant to open the body of the closure, instead of enclosing the closure in a block
|
||||||
|
|
|
||||||
|
LL ~ fn parse1()
|
||||||
|
LL ~ || { use {
|
||||||
|
|
|
||||||
|
|
||||||
|
error: expected one of `async`, `|`, or `||`, found keyword `use`
|
||||||
|
--> $DIR/parse.rs:10:10
|
||||||
|
|
|
||||||
|
LL | move use || {
|
||||||
|
| ^^^ expected one of `async`, `|`, or `||`
|
||||||
|
|
||||||
|
error: expected identifier, found keyword `move`
|
||||||
|
--> $DIR/parse.rs:16:9
|
||||||
|
|
|
||||||
|
LL | use move || {
|
||||||
|
| ^^^^ expected identifier, found keyword
|
||||||
|
|
||||||
|
error: expected one of `::`, `;`, or `as`, found `||`
|
||||||
|
--> $DIR/parse.rs:16:14
|
||||||
|
|
|
||||||
|
LL | use move || {
|
||||||
|
| ^^ expected one of `::`, `;`, or `as`
|
||||||
|
|
||||||
|
error: aborting due to 4 previous errors
|
||||||
|
|
27
tests/ui/ergonomic-clones/closure/print-verbose.rs
Normal file
27
tests/ui/ergonomic-clones/closure/print-verbose.rs
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
//@ compile-flags: -Zverbose-internals
|
||||||
|
|
||||||
|
#![feature(ergonomic_clones)]
|
||||||
|
|
||||||
|
fn to_fn_once<F: FnOnce()>(f: F) -> F {
|
||||||
|
f
|
||||||
|
}
|
||||||
|
|
||||||
|
fn f<T: std::fmt::Display>(y: T) {
|
||||||
|
struct Foo<U: std::fmt::Display> {
|
||||||
|
x: U,
|
||||||
|
};
|
||||||
|
|
||||||
|
let foo = Foo { x: "x" };
|
||||||
|
|
||||||
|
let c = to_fn_once(use || {
|
||||||
|
println!("{} {}", foo.x, y);
|
||||||
|
});
|
||||||
|
|
||||||
|
c();
|
||||||
|
c();
|
||||||
|
//~^ ERROR use of moved value
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
f("S");
|
||||||
|
}
|
20
tests/ui/ergonomic-clones/closure/print-verbose.stderr
Normal file
20
tests/ui/ergonomic-clones/closure/print-verbose.stderr
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
error[E0382]: use of moved value: `c`
|
||||||
|
--> $DIR/print-verbose.rs:21:5
|
||||||
|
|
|
||||||
|
LL | let c = to_fn_once(use || {
|
||||||
|
| - 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<&'?9 str>, T)}`, which does not implement the `Copy` trait
|
||||||
|
...
|
||||||
|
LL | c();
|
||||||
|
| --- `c` moved due to this call
|
||||||
|
LL | c();
|
||||||
|
| ^ value used here after move
|
||||||
|
|
|
||||||
|
note: this value implements `FnOnce`, which causes it to be moved when called
|
||||||
|
--> $DIR/print-verbose.rs:20:5
|
||||||
|
|
|
||||||
|
LL | c();
|
||||||
|
| ^
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0382`.
|
25
tests/ui/ergonomic-clones/closure/print.rs
Normal file
25
tests/ui/ergonomic-clones/closure/print.rs
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
#![feature(ergonomic_clones)]
|
||||||
|
|
||||||
|
fn to_fn_once<F: FnOnce()>(f: F) -> F {
|
||||||
|
f
|
||||||
|
}
|
||||||
|
|
||||||
|
fn f<T: std::fmt::Display>(y: T) {
|
||||||
|
struct Foo<U: std::fmt::Display> {
|
||||||
|
x: U,
|
||||||
|
};
|
||||||
|
|
||||||
|
let foo = Foo { x: "x" };
|
||||||
|
|
||||||
|
let c = to_fn_once(use || {
|
||||||
|
println!("{} {}", foo.x, y);
|
||||||
|
});
|
||||||
|
|
||||||
|
c();
|
||||||
|
c();
|
||||||
|
//~^ ERROR use of moved value
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
f("S");
|
||||||
|
}
|
20
tests/ui/ergonomic-clones/closure/print.stderr
Normal file
20
tests/ui/ergonomic-clones/closure/print.stderr
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
error[E0382]: use of moved value: `c`
|
||||||
|
--> $DIR/print.rs:19:5
|
||||||
|
|
|
||||||
|
LL | let c = to_fn_once(use || {
|
||||||
|
| - move occurs because `c` has type `{closure@$DIR/print.rs:14:24: 14:30}`, which does not implement the `Copy` trait
|
||||||
|
...
|
||||||
|
LL | c();
|
||||||
|
| --- `c` moved due to this call
|
||||||
|
LL | c();
|
||||||
|
| ^ value used here after move
|
||||||
|
|
|
||||||
|
note: this value implements `FnOnce`, which causes it to be moved when called
|
||||||
|
--> $DIR/print.rs:18:5
|
||||||
|
|
|
||||||
|
LL | c();
|
||||||
|
| ^
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0382`.
|
9
tests/ui/ergonomic-clones/closure/with-binders.rs
Normal file
9
tests/ui/ergonomic-clones/closure/with-binders.rs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
//@ edition:2021
|
||||||
|
//@ check-pass
|
||||||
|
|
||||||
|
#![feature(closure_lifetime_binder)]
|
||||||
|
#![feature(ergonomic_clones)]
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
for<'a> use || -> () {};
|
||||||
|
}
|
38
tests/ui/ergonomic-clones/dotuse/parse.rs
Normal file
38
tests/ui/ergonomic-clones/dotuse/parse.rs
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
#![feature(ergonomic_clones)]
|
||||||
|
|
||||||
|
fn parse1() {
|
||||||
|
1.use!;
|
||||||
|
//~^ ERROR: expected one of `.`, `;`, `?`, `}`, or an operator, found `!`
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse2() {
|
||||||
|
1.use!(2);
|
||||||
|
//~^ ERROR: expected one of `.`, `;`, `?`, `}`, or an operator, found `!`
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse3() {
|
||||||
|
1.use 2;
|
||||||
|
//~^ ERROR: expected one of `.`, `;`, `?`, `}`, or an operator, found `2`
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse4() {
|
||||||
|
1.use? 2;
|
||||||
|
//~^ ERROR: expected one of `.`, `;`, `?`, `}`, or an operator, found `2`
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse5() {
|
||||||
|
1.use();
|
||||||
|
//~^ ERROR: incorrect use of `use`
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse6() {
|
||||||
|
1.use(2);
|
||||||
|
//~^ ERROR: expected function, found `{integer}` [E0618]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse7() {
|
||||||
|
1.use { 2 };
|
||||||
|
//~^ ERROR: expected one of `.`, `;`, `?`, `}`, or an operator, found `{`
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
53
tests/ui/ergonomic-clones/dotuse/parse.stderr
Normal file
53
tests/ui/ergonomic-clones/dotuse/parse.stderr
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
error: expected one of `.`, `;`, `?`, `}`, or an operator, found `!`
|
||||||
|
--> $DIR/parse.rs:4:10
|
||||||
|
|
|
||||||
|
LL | 1.use!;
|
||||||
|
| ^ expected one of `.`, `;`, `?`, `}`, or an operator
|
||||||
|
|
||||||
|
error: expected one of `.`, `;`, `?`, `}`, or an operator, found `!`
|
||||||
|
--> $DIR/parse.rs:9:10
|
||||||
|
|
|
||||||
|
LL | 1.use!(2);
|
||||||
|
| ^ expected one of `.`, `;`, `?`, `}`, or an operator
|
||||||
|
|
||||||
|
error: expected one of `.`, `;`, `?`, `}`, or an operator, found `2`
|
||||||
|
--> $DIR/parse.rs:14:11
|
||||||
|
|
|
||||||
|
LL | 1.use 2;
|
||||||
|
| ^ expected one of `.`, `;`, `?`, `}`, or an operator
|
||||||
|
|
||||||
|
error: expected one of `.`, `;`, `?`, `}`, or an operator, found `2`
|
||||||
|
--> $DIR/parse.rs:19:12
|
||||||
|
|
|
||||||
|
LL | 1.use? 2;
|
||||||
|
| ^ expected one of `.`, `;`, `?`, `}`, or an operator
|
||||||
|
|
||||||
|
error: incorrect use of `use`
|
||||||
|
--> $DIR/parse.rs:24:10
|
||||||
|
|
|
||||||
|
LL | 1.use();
|
||||||
|
| ^^
|
||||||
|
|
|
||||||
|
help: `use` is not a method call, remove the parentheses
|
||||||
|
|
|
||||||
|
LL - 1.use();
|
||||||
|
LL + 1.use;
|
||||||
|
|
|
||||||
|
|
||||||
|
error: expected one of `.`, `;`, `?`, `}`, or an operator, found `{`
|
||||||
|
--> $DIR/parse.rs:34:11
|
||||||
|
|
|
||||||
|
LL | 1.use { 2 };
|
||||||
|
| ^ expected one of `.`, `;`, `?`, `}`, or an operator
|
||||||
|
|
||||||
|
error[E0618]: expected function, found `{integer}`
|
||||||
|
--> $DIR/parse.rs:29:5
|
||||||
|
|
|
||||||
|
LL | 1.use(2);
|
||||||
|
| ^^^^^---
|
||||||
|
| |
|
||||||
|
| call expression requires function
|
||||||
|
|
||||||
|
error: aborting due to 7 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0618`.
|
Loading…
Add table
Add a link
Reference in a new issue