diff options
| author | Santiago Pastorino <spastorino@gmail.com> | 2024-10-29 17:11:57 -0300 |
|---|---|---|
| committer | Santiago Pastorino <spastorino@gmail.com> | 2025-03-06 17:58:30 -0300 |
| commit | 0cf8dbc96c7c3c454779fe59e8e7019a3e37d5b6 (patch) | |
| tree | 8ce432be87442d5b9c2333fbdea2739babbb932f | |
| parent | 4559163ccb500affc424fb9228dae5003672ffc7 (diff) | |
Add ergonomic_clones feature flag
| -rw-r--r-- | compiler/rustc_ast_passes/src/feature_gate.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_feature/src/unstable.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_span/src/symbol.rs | 1 | ||||
| -rw-r--r-- | tests/ui/feature-gates/feature-gate-ergonomic-clones.rs | 20 | ||||
| -rw-r--r-- | tests/ui/feature-gates/feature-gate-ergonomic-clones.stderr | 26 |
5 files changed, 50 insertions, 0 deletions
diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index de11fe770c5..0e798169af8 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -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"); diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index 841d3084185..ccfdd93e993 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -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. diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 522bccb1acb..3357e085a7d 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -859,6 +859,7 @@ symbols! { eprint_macro, eprintln_macro, eq, + ergonomic_clones, ermsb_target_feature, exact_div, except, diff --git a/tests/ui/feature-gates/feature-gate-ergonomic-clones.rs b/tests/ui/feature-gates/feature-gate-ergonomic-clones.rs new file mode 100644 index 00000000000..37c2dc132e8 --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-ergonomic-clones.rs @@ -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() {} diff --git a/tests/ui/feature-gates/feature-gate-ergonomic-clones.stderr b/tests/ui/feature-gates/feature-gate-ergonomic-clones.stderr new file mode 100644 index 00000000000..9edefb775b4 --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-ergonomic-clones.stderr @@ -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`. |
