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

Fix "variable does not need to be mutable" warning #536

Merged
merged 2 commits into from
Sep 5, 2016
Merged

Fix "variable does not need to be mutable" warning #536

merged 2 commits into from
Sep 5, 2016

Conversation

dtolnay
Copy link
Member

@dtolnay dtolnay commented Sep 2, 2016

Fixes #534.

cc @elidupree


quote_block!(cx, {
let mut state = try!(_serializer.serialize_tuple_struct($type_name, $len));
let $let_mut state = try!(_serializer.serialize_tuple_struct($type_name, $len));
$serialize_stmts
Copy link
Member Author

Choose a reason for hiding this comment

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

@nox suggests rolling this into $serialize_stmts and generating:

let state = try!(...);
let mut state = state;

where the initial call is never mut and $serialize_stmts includes "let mut state = state" if necessary.

Copy link
Member Author

Choose a reason for hiding this comment

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

@nox I think I would rather move in the opposite direction, of making our generated code more straightforward where that can be accomplished easily. See as examples #479 and #538. There are a few reasons that is valuable:

  1. The most straightforward code will give us (and others) the best experience when the generated code needs to be debugged.
  2. The generated code is valuable as a template for implementing Serialize and Deserialize manually with minor modifications.
  3. Convoluted generated code gives people the impression that Serde is hard or Serde codegen is magic and impossible to understand, scaring people away from implementing Serialize and Deserialize manually where necessary.

I'm not saying we need to make the generated code beautiful at the expense of maintainability of serde_codegen, but there is a middle ground and I don't think rolling let mut state = state into $serialize_stmts is the right tradeoff in this case. Thanks for the idea though!

@oli-obk
Copy link
Member

oli-obk commented Sep 5, 2016

@homu r+

homu added a commit that referenced this pull request Sep 5, 2016
Fix "variable does not need to be mutable" warning

Fixes #534.

cc @elidupree
@homu homu merged commit e03deda into master Sep 5, 2016
@dtolnay dtolnay deleted the mutempty branch September 5, 2016 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants