From 320d049e876579cd5c57be17e791a519f9b852a0 Mon Sep 17 00:00:00 2001 From: Chris Midgley Date: Tue, 20 Jul 2021 20:13:08 +0100 Subject: [PATCH 1/4] Add long explanation for E0722 --- compiler/rustc_error_codes/src/error_codes.rs | 2 +- .../src/error_codes/E0722.md | 24 +++++++++++++++++++ .../feature-gate-optimize_attribute.stderr | 3 ++- 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 compiler/rustc_error_codes/src/error_codes/E0722.md diff --git a/compiler/rustc_error_codes/src/error_codes.rs b/compiler/rustc_error_codes/src/error_codes.rs index df162f8dce026..902c7c4787323 100644 --- a/compiler/rustc_error_codes/src/error_codes.rs +++ b/compiler/rustc_error_codes/src/error_codes.rs @@ -418,6 +418,7 @@ E0716: include_str!("./error_codes/E0716.md"), E0718: include_str!("./error_codes/E0718.md"), E0719: include_str!("./error_codes/E0719.md"), E0720: include_str!("./error_codes/E0720.md"), +E0722: include_str!("./error_codes/E0722.md"), E0724: include_str!("./error_codes/E0724.md"), E0725: include_str!("./error_codes/E0725.md"), E0727: include_str!("./error_codes/E0727.md"), @@ -634,7 +635,6 @@ E0783: include_str!("./error_codes/E0783.md"), E0711, // a feature has been declared with conflicting stability attributes E0717, // rustc_promotable without stability attribute // E0721, // `await` keyword - E0722, // Malformed `#[optimize]` attribute // E0723, unstable feature in `const` context E0726, // non-explicit (not `'_`) elided lifetime in unsupported position // E0738, // Removed; errored on `#[track_caller] fn`s in `extern "Rust" { ... }`. diff --git a/compiler/rustc_error_codes/src/error_codes/E0722.md b/compiler/rustc_error_codes/src/error_codes/E0722.md new file mode 100644 index 0000000000000..4a687d7428805 --- /dev/null +++ b/compiler/rustc_error_codes/src/error_codes/E0722.md @@ -0,0 +1,24 @@ +The `optimize` attribute was malformed. + +Erroneous code example: + +```compile_fail,E0722 +#![feature(optimize_attribute)] + +#[optimize(something)] // error: invalid argument +pub fn something() {} + +fn main() {} +``` + +The `#[optimize]` attribute should be used as follows: + +- `#[optimize(size)]` -- instructs the optimization pipeline to generate code + that's smaller rather than faster + +- `#[optimize(speed)]` -- instructs the optimization pipeline to generate code + that's faster rather than smaller + +See [RFC 2412] for more details. + +[RFC 2412]: https://rust-lang.github.io/rfcs/2412-optimize-attr.html diff --git a/src/test/ui/feature-gates/feature-gate-optimize_attribute.stderr b/src/test/ui/feature-gates/feature-gate-optimize_attribute.stderr index 50ce6427e8b58..a3ced35155f37 100644 --- a/src/test/ui/feature-gates/feature-gate-optimize_attribute.stderr +++ b/src/test/ui/feature-gates/feature-gate-optimize_attribute.stderr @@ -51,4 +51,5 @@ LL | #[optimize(banana)] error: aborting due to 6 previous errors -For more information about this error, try `rustc --explain E0658`. +Some errors have detailed explanations: E0658, E0722. +For more information about an error, try `rustc --explain E0658`. From e09d78260908436e6bc1691f23cda2ee8382545a Mon Sep 17 00:00:00 2001 From: Chris Midgley Date: Wed, 21 Jul 2021 10:29:20 +0100 Subject: [PATCH 2/4] add working code example --- compiler/rustc_error_codes/src/error_codes/E0722.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/compiler/rustc_error_codes/src/error_codes/E0722.md b/compiler/rustc_error_codes/src/error_codes/E0722.md index 4a687d7428805..1513c4ce0594d 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0722.md +++ b/compiler/rustc_error_codes/src/error_codes/E0722.md @@ -19,6 +19,16 @@ The `#[optimize]` attribute should be used as follows: - `#[optimize(speed)]` -- instructs the optimization pipeline to generate code that's faster rather than smaller +For example: +``` +#![feature(optimize_attribute)] + +#[optimize(size)] +pub fn something() {} + +fn main() {} +``` + See [RFC 2412] for more details. [RFC 2412]: https://rust-lang.github.io/rfcs/2412-optimize-attr.html From adc5de601f9e860f00638f078f3a4d4e6ae4c73d Mon Sep 17 00:00:00 2001 From: Chris Midgley Date: Wed, 21 Jul 2021 10:57:27 +0100 Subject: [PATCH 3/4] docs: remove spurious main functions --- compiler/rustc_error_codes/src/error_codes/E0722.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/compiler/rustc_error_codes/src/error_codes/E0722.md b/compiler/rustc_error_codes/src/error_codes/E0722.md index 1513c4ce0594d..fe2b6d27457f5 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0722.md +++ b/compiler/rustc_error_codes/src/error_codes/E0722.md @@ -7,8 +7,6 @@ Erroneous code example: #[optimize(something)] // error: invalid argument pub fn something() {} - -fn main() {} ``` The `#[optimize]` attribute should be used as follows: @@ -25,8 +23,6 @@ For example: #[optimize(size)] pub fn something() {} - -fn main() {} ``` See [RFC 2412] for more details. From b24d4915b895fab1528ee5081edaa94e951b523e Mon Sep 17 00:00:00 2001 From: Chris Midgley Date: Wed, 21 Jul 2021 10:58:35 +0100 Subject: [PATCH 4/4] docs: add newline before example --- compiler/rustc_error_codes/src/error_codes/E0722.md | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/rustc_error_codes/src/error_codes/E0722.md b/compiler/rustc_error_codes/src/error_codes/E0722.md index fe2b6d27457f5..570717a92bd79 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0722.md +++ b/compiler/rustc_error_codes/src/error_codes/E0722.md @@ -18,6 +18,7 @@ The `#[optimize]` attribute should be used as follows: that's faster rather than smaller For example: + ``` #![feature(optimize_attribute)]