rust-unofficial / patterns

A catalogue of Rust design patterns, anti-patterns and idioms
https://rust-unofficial.github.io/patterns/
Mozilla Public License 2.0
7.84k stars 354 forks source link

Change lints hyphen to underscore #308

Closed hafeoz closed 2 years ago

hafeoz commented 2 years ago

rustc -D nonstandard-style is a valid syntax; #[deny(nonstandard_style)] is also valid. However, #[deny(nonstandard-style)] will cause:

error: expected one of `(`, `,`, `::`, or `=`, found `-`
  --> example/src/lib.rs:12:19
   |
12 | #[deny(nonstandard-style)]
   |                   ^ expected one of `(`, `,`, `::`, or `=`

Which is confusing if someone is trying to copy-paste the code into their own.

MarcoIeni commented 2 years ago

Great, thanks :smile: We could also remove the ,ignore flag by adding an fn main {} at the end of the code block. So that this code block is tested when running mdbook test in the CI.

Here is an example:

```rust
#[deny(bad_style,
       const_err,
       dead_code,
       improper_ctypes,
       non_shorthand_field_patterns,
       no_mangle_generic_items,
       overflowing_literals,
       path_statements,
       patterns_in_fns_without_body,
       private_in_public,
       unconditional_recursion,
       unused,
       unused_allocation,
       unused_comparisons,
       unused_parens,
       while_true)]
fn main() {}

What do you think? :)

hafeoz commented 2 years ago

Great, thanks smile We could also remove the ,ignore flag by adding an fn main {} at the end of the code block. So that this code block is tested when running mdbook test in the CI.

Here is an example:

```rust
#[deny(bad_style,
       const_err,
       dead_code,
       improper_ctypes,
       non_shorthand_field_patterns,
       no_mangle_generic_items,
       overflowing_literals,
       path_statements,
       patterns_in_fns_without_body,
       private_in_public,
       unconditional_recursion,
       unused,
       unused_allocation,
       unused_comparisons,
       unused_parens,
       while_true)]
fn main() {}

What do you think? :)

How about marking the attributes as inner attributes? LIke

#![deny(bad_style, ...)]

By doing this way, we won't need fn main() {} in the code.

MarcoIeni commented 2 years ago

Oh, that's even better, yes!

hafeoz commented 2 years ago

Great, thanks smile We could also remove the ,ignore flag by adding an fn main {} at the end of the code block. So that this code block is tested when running mdbook test in the CI. Here is an example:

```rust
#[deny(bad_style,
       const_err,
       dead_code,
       improper_ctypes,
       non_shorthand_field_patterns,
       no_mangle_generic_items,
       overflowing_literals,
       path_statements,
       patterns_in_fns_without_body,
       private_in_public,
       unconditional_recursion,
       unused,
       unused_allocation,
       unused_comparisons,
       unused_parens,
       while_true)]
fn main() {}

What do you think? :)

How about marking the attributes as inner attributes? LIke

#![deny(bad_style, ...)]

By doing this way, we won't need fn main() {} in the code.

Currently this modification fails to build due to rust-lang/rust#97440

MarcoIeni commented 2 years ago

ok, what do you prefer to do, then? All the proposed solutions work for me. The PR can even be merged as it is now.

hafeoz commented 2 years ago

ok, what do you prefer to do, then? For me, we can also merge this PR as it is.

I'm currently preparing for a PR to fix the ICE. In the meanwhile, maybe we should continue to mark the code block as ignore until the PR is merged?

hafeoz commented 2 years ago

Sounds good to me. Should we merge this? rocket

I have changed lints to inner attributes👍 I think it's ready now