Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
a54bfcf
Use safe FFI for various functions in codegen_llvm
oli-obk Feb 21, 2025
d4379d2
Remove an unnecessary lifetime
oli-obk Feb 24, 2025
bfd88ce
Avoid some duplication between SimpleCx and CodegenCx
oli-obk Feb 24, 2025
75356b7
Generalize `BackendTypes` over `GenericCx`
oli-obk Feb 24, 2025
840e31b
Generalize BaseTypeCodegenMethods
oli-obk Feb 24, 2025
396baa7
Make allocator shim creation mostly use safe code
oli-obk Feb 24, 2025
29440b8
Remove an unused lifetime param
oli-obk Feb 24, 2025
241c83f
Deduplicate more functions between `SimpleCx` and `CodegenCx`
oli-obk Feb 24, 2025
f16f64b
Remove inherent function that has a trait method duplicate of a commo…
oli-obk Feb 24, 2025
3565603
Use a safe wrapper around an LLVM FFI function
oli-obk Feb 24, 2025
553828c
Mark more LLVM FFI as safe
oli-obk Feb 24, 2025
d7ed32b
Suggest struct or union to add generic that impls trait
xizheyin Mar 5, 2025
7e199b1
Add ui test: suggest-struct-or-union-add-generic-impl-trait.rs
xizheyin Mar 6, 2025
0cf8dbc
Add ergonomic_clones feature flag
spastorino Oct 29, 2024
05c5164
Implement .use keyword as an alias of clone
spastorino Oct 2, 2024
81a926c
Use closure parse code
spastorino Nov 1, 2024
57cb498
Generate the right MIR for by use closures
spastorino Dec 17, 2024
dcdfd55
Add UseCloned trait related code
spastorino Dec 11, 2024
60b6470
Fix clippy
spastorino Dec 26, 2024
8c456cb
Fix rustfmt
spastorino Dec 27, 2024
4cbca77
Separate closures, async and dotuse tests in directories
spastorino Dec 27, 2024
38b4746
Support nested use closures
spastorino Feb 10, 2025
7c17bf8
Add tests
spastorino Feb 10, 2025
292aa87
Fix use closure parsing error message
spastorino Feb 11, 2025
6eb6ff6
Allow to mutate use captures
spastorino Feb 14, 2025
aa58439
Fail gracefully if mutating on a use closure and the closure it not d…
spastorino Feb 14, 2025
18d689c
Add more tests
spastorino Feb 14, 2025
edcbc9b
Add a code example as comment in init_capture_kind_for_place
spastorino Feb 20, 2025
b43b700
Account for UseCloned on expr_use_visitor
spastorino Feb 20, 2025
2f48fce
Change feature flag error to be ergonomic clones are experimental
spastorino Feb 21, 2025
4e6407a
Give a better error message on async use in edition 2015
spastorino Feb 21, 2025
65d65e5
Parse and allow const use closures
spastorino Feb 21, 2025
1702c00
Make captures in ByUse context be always ty::UpvarCapture::ByUse
spastorino Feb 21, 2025
a68db7e
Add examples in stdlib demonstrating the use syntax
spastorino Feb 24, 2025
42b8b13
Add some code comments
spastorino Mar 6, 2025
5a6d00c
Add allow(incomplete_features) to alloc
spastorino Mar 6, 2025
d7104dc
Make feature flag incomplete
spastorino Mar 6, 2025
d2bde63
Add slight variation to feature-gate ergonomic clones test
spastorino Mar 7, 2025
69aafd2
tests: fix some typos in comment
tcpdumppy Mar 7, 2025
872ac73
Move `visit_id` calls.
nnethercote Mar 7, 2025
8a98124
Factor out repeated `visit_id` calls.
nnethercote Mar 7, 2025
e7bea57
Fix a typo in the crashtest output.
nnethercote Mar 4, 2025
7943932
Pass `Option<Symbol>` to `def_path_data`/`create_def` methods.
nnethercote Mar 4, 2025
af92a33
Make synthetic RPITIT assoc ty name handling more rigorous.
nnethercote Mar 4, 2025
f5a143f
Rollup merge of #134797 - spastorino:ergonomic-ref-counting-1, r=niko…
matthiaskrgr Mar 7, 2025
63c548d
Rollup merge of #137549 - oli-obk:llvm-ffi, r=davidtwco
matthiaskrgr Mar 7, 2025
0defc4f
Rollup merge of #137977 - nnethercote:less-kw-Empty-1, r=spastorino
matthiaskrgr Mar 7, 2025
e70adad
Rollup merge of #138042 - xizheyin:issue-135759, r=nnethercote
matthiaskrgr Mar 7, 2025
282a37f
Rollup merge of #138141 - tcpdumppy:master, r=compiler-errors
matthiaskrgr Mar 7, 2025
b772fa6
Rollup merge of #138150 - nnethercote:streamline-intravisit-visit_id,…
matthiaskrgr Mar 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests
  • Loading branch information
spastorino committed Mar 6, 2025
commit 7c17bf8e824aefcc4272168f1cbda21c1683dcbe
9 changes: 9 additions & 0 deletions tests/ui/ergonomic-clones/async/local-type.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 15 additions & 0 deletions tests/ui/ergonomic-clones/async/local-type.stderr
Original file line number Diff line number Diff line change
@@ -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`.
14 changes: 14 additions & 0 deletions tests/ui/ergonomic-clones/closure/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,18 @@ fn ergonomic_clone_closure_use_cloned() -> Foo {
f
}

fn ergonomic_clone_closure_copy() -> i32 {
let i = 1;

let i1 = use || {
i
};

let i2 = use || {
i
};

i
}

fn main() {}
13 changes: 13 additions & 0 deletions tests/ui/ergonomic-clones/closure/fn-once.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 16 additions & 0 deletions tests/ui/ergonomic-clones/closure/fn-once.stderr
Original file line number Diff line number Diff line change
@@ -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 changes: 8 additions & 0 deletions tests/ui/ergonomic-clones/closure/local-type.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 15 additions & 0 deletions tests/ui/ergonomic-clones/closure/local-type.stderr
Original file line number Diff line number Diff line change
@@ -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 changes: 18 additions & 0 deletions tests/ui/ergonomic-clones/closure/once-move-out-on-heap.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 23 additions & 0 deletions tests/ui/ergonomic-clones/closure/parse.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 34 additions & 0 deletions tests/ui/ergonomic-clones/closure/parse.stderr
Original file line number Diff line number Diff line change
@@ -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 changes: 27 additions & 0 deletions tests/ui/ergonomic-clones/closure/print-verbose.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 20 additions & 0 deletions tests/ui/ergonomic-clones/closure/print-verbose.stderr
Original file line number Diff line number Diff line change
@@ -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 changes: 25 additions & 0 deletions tests/ui/ergonomic-clones/closure/print.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 20 additions & 0 deletions tests/ui/ergonomic-clones/closure/print.stderr
Original file line number Diff line number Diff line change
@@ -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 changes: 9 additions & 0 deletions tests/ui/ergonomic-clones/closure/with-binders.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//@ edition:2021
//@ check-pass

#![feature(closure_lifetime_binder)]
#![feature(ergonomic_clones)]

fn main() {
for<'a> use || -> () {};
}
38 changes: 38 additions & 0 deletions tests/ui/ergonomic-clones/dotuse/parse.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 53 additions & 0 deletions tests/ui/ergonomic-clones/dotuse/parse.stderr
Original file line number Diff line number Diff line change
@@ -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`.