Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Default trait for Arena type #32

Merged
merged 1 commit into from
Jul 31, 2019

Conversation

lo48576
Copy link
Contributor

@lo48576 lo48576 commented Jul 31, 2019

Default is implemented manually for Arena, but not using #[derive(Default)].
This is because #[derive(Default)] adds unnecessary trait bound T: Default automatically (see rust-lang/rust#26925).

Additionally, this change suppresses clippy lint to recommend deriving Default for simple new() method.
Clippy complains about that for previous code:

$ cargo clippy
warning: you should consider deriving a `Default` implementation for `arena::Arena<T>`
  --> src/arena.rs:41:5
   |
41 | /     pub fn new() -> Arena<T> {
42 | |         Arena { nodes: Vec::new() }
43 | |     }
   | |_____^
   |
   = note: #[warn(clippy::new_without_default)] on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default
help: try this
   |
35 | #[derive(Default)]
   |

    Finished dev [unoptimized + debuginfo] target(s) in 0.27s
$

`Default` is implemented manually for `Arena`, but not using
`#[derive(Default)]`.
This is because `#[derive(Default)]` adds unnecessary trait bound
`T: Default` automatically (see rust-lang/rust#26925).
Copy link
Owner

@saschagrunert saschagrunert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@saschagrunert saschagrunert merged commit 4f461cd into saschagrunert:master Jul 31, 2019
@lo48576 lo48576 deleted the feature/arena-default branch July 31, 2019 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants