Add ergonomic_clones feature flag

This commit is contained in:
Santiago Pastorino 2024-10-29 17:11:57 -03:00
parent 4559163ccb
commit 0cf8dbc96c
No known key found for this signature in database
GPG key ID: 8131A24E0C79EFAF
5 changed files with 50 additions and 0 deletions

View file

@ -489,6 +489,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
gate_all!(dyn_star, "`dyn*` trait objects are experimental");
gate_all!(const_closures, "const closures are experimental");
gate_all!(builtin_syntax, "`builtin #` syntax is unstable");
gate_all!(ergonomic_clones, "`.use` calls are experimental");
gate_all!(explicit_tail_calls, "`become` expression is experimental");
gate_all!(generic_const_items, "generic const items are experimental");
gate_all!(guard_patterns, "guard patterns are experimental", "consider using match arm guards");

View file

@ -473,6 +473,8 @@ declare_features! (
(unstable, doc_masked, "1.21.0", Some(44027)),
/// Allows `dyn* Trait` objects.
(incomplete, dyn_star, "1.65.0", Some(102425)),
/// Allows the .use postfix syntax `x.use` and use closures `use |x| { ... }`
(unstable, ergonomic_clones, "CURRENT_RUSTC_VERSION", Some(132290)),
/// Allows exhaustive pattern matching on types that contain uninhabited types.
(unstable, exhaustive_patterns, "1.13.0", Some(51085)),
/// Allows explicit tail calls via `become` expression.

View file

@ -859,6 +859,7 @@ symbols! {
eprint_macro,
eprintln_macro,
eq,
ergonomic_clones,
ermsb_target_feature,
exact_div,
except,

View file

@ -0,0 +1,20 @@
fn ergonomic_clone(x: i32) -> i32 {
x.use
//~^ ERROR expected identifier, found keyword `use`
//~| ERROR `i32` is a primitive type and therefore doesn't have fields [E0610]
}
fn ergonomic_closure_clone() {
let s1 = String::from("hi!");
let s2 = use || {
//~^ ERROR expected expression, found keyword `use`
s1
};
let s3 = use || {
s1
};
}
fn main() {}

View file

@ -0,0 +1,26 @@
error: expected identifier, found keyword `use`
--> $DIR/feature-gate-ergonomic-clones.rs:2:7
|
LL | x.use
| ^^^ expected identifier, found keyword
|
help: escape `use` to use it as an identifier
|
LL | x.r#use
| ++
error: expected expression, found keyword `use`
--> $DIR/feature-gate-ergonomic-clones.rs:10:14
|
LL | let s2 = use || {
| ^^^ expected expression
error[E0610]: `i32` is a primitive type and therefore doesn't have fields
--> $DIR/feature-gate-ergonomic-clones.rs:2:7
|
LL | x.use
| ^^^
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0610`.