1 #![deny(clippy::if_same_then_else, clippy::branches_sharing_code)]
3 #![allow(clippy::equatable_if_let, clippy::uninlined_format_args)]
5 // This tests the branches_sharing_code lint at the end of blocks
15 // Same but not moveable due to `start_value`
18 // The rest is self contained and moveable => Only lint the rest
20 println!("Block end!");
23 println!("Branch II");
27 // Same but not moveable due to `start_value`
30 // The rest is self contained and moveable => Only lint the rest
32 println!("Block end!");
38 println!("The index is: 6");
40 println!("Same end of block");
42 println!("The index is: 4");
44 // We should only get a lint trigger for the last statement
45 println!("This is also eq with the else block");
46 println!("Same end of block");
48 println!("This is also eq with the else block");
49 println!("Same end of block");
52 // Use of outer scope value
53 let outer_scope_value = "I'm outside the if block";
55 let z = "How are you";
56 println!("I'm a local because I use the value `z`: `{}`", z);
59 "I'm moveable because I know: `outer_scope_value`: '{}'",
64 println!("I'm a local because I use the value `z`: `{}`", z);
67 "I'm moveable because I know: `outer_scope_value`: '{}'",
76 println!("Hello World");
78 println!("Hello World");
83 /// Simple examples where the move can cause some problems due to moved values
84 fn simple_but_suggestion_is_invalid() {
88 let later_used_value = 17;
91 let later_used_value = "A string value";
92 println!("{}", later_used_value);
94 let later_used_value = "A string value";
95 println!("{}", later_used_value);
96 // I'm expecting a note about this
98 println!("{}", later_used_value);
102 let simple_examples = "I now identify as a &str :)";
103 println!("This is the new simple_example: {}", simple_examples);
105 println!("Separator print statement");
107 let simple_examples = "I now identify as a &str :)";
108 println!("This is the new simple_example: {}", simple_examples);
113 /// Tests where the blocks are not linted due to the used value scope
114 fn not_moveable_due_to_value_scope() {
117 // Using a local value in the moved code
120 println!("y is: `{}`", y);
123 println!("y is: `{}`", y);
126 // Using a local value in the expression
128 let mut result = x + 1;
130 println!("1. Doing some calculations");
131 println!("2. Some more calculations");
132 println!("3. Setting result");
136 let mut result = x - 1;
138 println!("1. Doing some calculations");
139 println!("2. Some more calculations");
140 println!("3. Setting result");
147 println!("z1: {}", z1);
150 println!("z2: {}", z2);
155 println!("z1: {}", z1);
158 println!("z2: {}", z2);
164 /// This should add a note to the lint msg since the moved expression is not `()`
165 fn added_note_for_expression_use() -> u32 {
184 fn test_suggestion_with_weird_formatting() {
189 // The error message still looks weird tbh but this is the best I can do
190 // for weird formatting
191 if x == 17 { b = 1; a = 0x99; } else { a = 0x99; }
210 fn fp_if_let_issue7054() {
211 // This shouldn't trigger the lint
213 let _x = if let true = true {
216 string = "x".to_owned();
219 string = "y".to_owned();