1 #![allow(dead_code, clippy::equatable_if_let)]
2 #![deny(clippy::if_same_then_else, clippy::branches_sharing_code)]
4 // This tests the branches_sharing_code lint at the end of blocks
14 // Same but not moveable due to `start_value`
17 // The rest is self contained and moveable => Only lint the rest
19 println!("Block end!");
22 println!("Branch II");
26 // Same but not moveable due to `start_value`
29 // The rest is self contained and moveable => Only lint the rest
31 println!("Block end!");
37 println!("The index is: 6");
39 println!("Same end of block");
41 println!("The index is: 4");
43 // We should only get a lint trigger for the last statement
44 println!("This is also eq with the else block");
45 println!("Same end of block");
47 println!("This is also eq with the else block");
48 println!("Same end of block");
51 // Use of outer scope value
52 let outer_scope_value = "I'm outside the if block";
54 let z = "How are you";
55 println!("I'm a local because I use the value `z`: `{}`", z);
58 "I'm moveable because I know: `outer_scope_value`: '{}'",
63 println!("I'm a local because I use the value `z`: `{}`", z);
66 "I'm moveable because I know: `outer_scope_value`: '{}'",
75 println!("Hello World");
77 println!("Hello World");
82 /// Simple examples where the move can cause some problems due to moved values
83 fn simple_but_suggestion_is_invalid() {
87 let later_used_value = 17;
90 let later_used_value = "A string value";
91 println!("{}", later_used_value);
93 let later_used_value = "A string value";
94 println!("{}", later_used_value);
95 // I'm expecting a note about this
97 println!("{}", later_used_value);
101 let simple_examples = "I now identify as a &str :)";
102 println!("This is the new simple_example: {}", simple_examples);
104 println!("Separator print statement");
106 let simple_examples = "I now identify as a &str :)";
107 println!("This is the new simple_example: {}", simple_examples);
112 /// Tests where the blocks are not linted due to the used value scope
113 fn not_moveable_due_to_value_scope() {
116 // Using a local value in the moved code
119 println!("y is: `{}`", y);
122 println!("y is: `{}`", y);
125 // Using a local value in the expression
127 let mut result = x + 1;
129 println!("1. Doing some calculations");
130 println!("2. Some more calculations");
131 println!("3. Setting result");
135 let mut result = x - 1;
137 println!("1. Doing some calculations");
138 println!("2. Some more calculations");
139 println!("3. Setting result");
146 println!("z1: {}", z1);
149 println!("z2: {}", z2);
154 println!("z1: {}", z1);
157 println!("z2: {}", z2);
163 /// This should add a note to the lint msg since the moved expression is not `()`
164 fn added_note_for_expression_use() -> u32 {
183 fn test_suggestion_with_weird_formatting() {
188 // The error message still looks weird tbh but this is the best I can do
189 // for weird formatting
190 if x == 17 { b = 1; a = 0x99; } else { a = 0x99; }
209 fn fp_if_let_issue7054() {
210 // This shouldn't trigger the lint
212 let _x = if let true = true {
215 string = "x".to_owned();
218 string = "y".to_owned();