Advertisement
Guest User

rust-shadowing-bug

a guest
Aug 3rd, 2014
1,920
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1.  
  2. static OVERRIDE: f32 = 300f32;
  3.  
  4. fn main() {
  5. let mut percentage = 100f32;
  6. percentage = percentage.round();
  7. let mut factor = 100f32 / percentage;
  8.  
  9. if OVERRIDE > 200f32 {
  10.  
  11. ///!! shadowing introduces a bug !!///
  12. let mut percentage = OVERRIDE;
  13. //percentage = OVERRIDE; // correct code..
  14.  
  15.  
  16. percentage = percentage.round();
  17. factor = 100f32 / percentage;
  18. }
  19. // do stuff with factor and percentage..
  20. println!("Total is {}", percentage*factor);
  21.  
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement