Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Removing match on constant #888

Merged
merged 3 commits into from
Apr 9, 2016
Merged

Removing match on constant #888

merged 3 commits into from
Apr 9, 2016

Conversation

tomusdrw
Copy link
Collaborator

@tomusdrw tomusdrw commented Apr 6, 2016

Pattern matching on complex type constants without #[derive(PartialEq)] is being phased-out.

Details:
rust-lang/rfcs#1445

We cannot derive PartialEq because arrays does not implement any traits.

@@ -138,7 +138,7 @@ impl Account {
/// get someone who knows to call `note_code`.
pub fn code(&self) -> Option<&[u8]> {
match self.code_hash {
Some(SHA3_EMPTY) | None if self.code_cache.is_empty() => Some(&self.code_cache),
Some(c) if c == SHA3_EMPTY && self.code_cache.is_empty() => Some(&self.code_cache),
Some(_) if !self.code_cache.is_empty() => Some(&self.code_cache),
None => Some(&self.code_cache),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Does this actually make sense? Before this refactor we were matching None twice:

None if self.code_cache.is_empty() => Some(&self.code_cache),
None => Some(&self.code_cache),

Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like it does not. None matches to Some(&self.code_cache) in all cases
@gavofyork please take a look, might be a bug in the original code.

Copy link
Contributor

Choose a reason for hiding this comment

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

the original code (https://github.com/ethcore/parity/blob/master/ethcore/src/account.rs) was:

Some(c) if c == SHA3_EMPTY  && self.code_cache.is_empty() => Some(&self.code_cache),
Some(_) if !self.code_cache.is_empty() => Some(&self.code_cache),
None => Some(&self.code_cache),
_ => None,

there are no options here which are superfluous.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The code from master already contains this change (was included with #889 - otherwise there was compilation error on nightly).
This is what it looked like before:
https://github.com/ethcore/parity/blob/61420d3c9c64d87ab2c83d972c7d2d812b1d9b72/ethcore/src/account.rs#L141

The logic wasn't different, but there was superfluous | None in first branch.
My question is rather if when this method should return None - currently it's only the case when code_hash == SHA3_EMPTY && !code_cache.is_empty() OR code_hash != SHA3_EMPTY && code_cache.is_empty() - this is correct?

Copy link
Contributor

Choose a reason for hiding this comment

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

Correct (technically, the first is actually a logic error and should properly be either asserted against or an error). The second (i.e. there is definitely some non-empty code, but it isn't presently cached) properly returns None.

@tomusdrw tomusdrw added the A0-pleasereview 🤓 Pull request needs code review. label Apr 6, 2016
@NikVolf NikVolf added A8-looksgood 🦄 Pull request is reviewed well. A4-gotissues 💥 Pull request is reviewed and has significant issues which must be addressed. and removed A0-pleasereview 🤓 Pull request needs code review. A8-looksgood 🦄 Pull request is reviewed well. labels Apr 6, 2016
@arkpar arkpar added A0-pleasereview 🤓 Pull request needs code review. and removed A4-gotissues 💥 Pull request is reviewed and has significant issues which must be addressed. labels Apr 6, 2016
@gavofyork gavofyork added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Apr 9, 2016
@@ -138,7 +138,7 @@ impl Account {
/// get someone who knows to call `note_code`.
pub fn code(&self) -> Option<&[u8]> {
match self.code_hash {
Some(SHA3_EMPTY) | None if self.code_cache.is_empty() => Some(&self.code_cache),
Some(c) if c == SHA3_EMPTY && self.code_cache.is_empty() => Some(&self.code_cache),
Copy link
Contributor

Choose a reason for hiding this comment

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

extra space.

@gavofyork gavofyork added A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. and removed A8-looksgood 🦄 Pull request is reviewed well. labels Apr 9, 2016
@gavofyork
Copy link
Contributor

needs to be resolved.

@gavofyork gavofyork added A7-looksgoodcantmerge 🙄 Pull request is reviewed well, but cannot be merged due to conflicts. and removed A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. labels Apr 9, 2016
Conflicts:
	ethcore/src/account.rs
@tomusdrw tomusdrw merged commit a63be70 into master Apr 9, 2016
@tomusdrw tomusdrw deleted the h256 branch April 9, 2016 09:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A7-looksgoodcantmerge 🙄 Pull request is reviewed well, but cannot be merged due to conflicts.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants