-
Notifications
You must be signed in to change notification settings - Fork 172
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
Ban direct indexing #369
Ban direct indexing #369
Conversation
note for reviewers: we are manually adding |
// Allowed since it's actually better to panic during chain setup when there is an error | ||
#![allow(clippy::unwrap_used)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, nice to allow this in tests, benchmarks, and some node stuff like this
T::Currency::reserve(&who, id.deposit - old_deposit)?; | ||
T::Currency::hold( | ||
&HoldReason::RegistryIdentity.into(), | ||
&who, | ||
id.deposit - old_deposit, | ||
)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason to do the currency -> fungible migration here? Seems unrelated to direct indexing and I think you need a migration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should have gone into the 1.0 branch, but I forgot to commit it and now i'm rolling into this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gregzaitsev is this what you were referring to a while back ? I remember we had some conversation about it. #353
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯 awesome
assert_eq!(x.len(), y.len()); | ||
let n = x.len(); | ||
let mut result: Vec<I32F32> = vec![I32F32::from_num(0); n]; | ||
for i in 0..n { | ||
if y[i] != 0 { | ||
result[i] = x[i] / y[i]; | ||
} | ||
} | ||
result | ||
x.iter() | ||
.zip(y) | ||
.map(|(x_i, y_i)| { | ||
if *y_i != 0 { | ||
x_i / y_i | ||
} else { | ||
I32F32::from_num(0) | ||
} | ||
}) | ||
.collect() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
This PR resolves #278 by enabling CI to detect direct indexing and calls to
unwrap
.