-
Notifications
You must be signed in to change notification settings - Fork 931
labels on the closure body block can be disappearing #6468
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
Merged
+418
−8
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
beb37b0
chore: add rewrite_last_closure log similar to rewrite_closure
anatawa12 3df8232
fix: labels on the closure body can be disappearing
anatawa12 2b88689
test: add tests for labels on closure block
anatawa12 75c5142
chore: make rewrite_closure_block accept Expr and pass the entire body
anatawa12 2aaec6e
test: fix duplicated test cause
anatawa12 75b1cc4
test: fix typo in test causes
anatawa12 39ebb96
test: remove unnecessary helpers
anatawa12 2cfbf1c
chore: add debug_assert for precondition
anatawa12 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
// _0: in-macro | ||
// _1: last argument in function invocation | ||
// _2: non-last argument in function invocation | ||
// _3: simple expression | ||
|
||
// test0: the cause reported in issue: label is used, and there is usage, multiple statements | ||
pub fn rustfmt_test0_0(condition: bool) { | ||
test_macro!(|transaction| 'block: { | ||
if condition { | ||
break 'block 0; | ||
} | ||
|
||
todo!() | ||
}); | ||
} | ||
|
||
pub fn rustfmt_test0_1(condition: bool) { | ||
test_func(|transaction| 'block: { | ||
if condition { | ||
break 'block 0; | ||
} | ||
|
||
todo!() | ||
}); | ||
} | ||
|
||
pub fn rustfmt_test0_2(condition: bool) { | ||
test_func2(|transaction| 'block: { | ||
if condition { | ||
break 'block 0; | ||
} | ||
|
||
todo!() | ||
}, 0); | ||
} | ||
|
||
pub fn rustfmt_test0_3(condition: bool) { | ||
let x = |transaction| 'block: { | ||
if condition { | ||
break 'block 0; | ||
} | ||
|
||
todo!() | ||
}; | ||
} | ||
|
||
|
||
// test1: label is unused, and there is usage, multiple statements | ||
pub fn rustfmt_test1_0(condition: bool) { | ||
test_macro!(|transaction| 'block: { | ||
if condition { | ||
todo!(""); | ||
} | ||
|
||
todo!() | ||
}); | ||
} | ||
|
||
pub fn rustfmt_test1_1(condition: bool) { | ||
test_func(|transaction| 'block: { | ||
if condition { | ||
todo!(""); | ||
} | ||
|
||
todo!() | ||
}); | ||
} | ||
|
||
pub fn rustfmt_test1_2(condition: bool) { | ||
test_func2(|transaction| 'block: { | ||
if condition { | ||
todo!(""); | ||
} | ||
|
||
todo!() | ||
}, 0); | ||
} | ||
|
||
pub fn rustfmt_test1_3(condition: bool) { | ||
let x = |transaction| 'block: { | ||
if condition { | ||
todo!(""); | ||
} | ||
|
||
todo!() | ||
}; | ||
} | ||
|
||
|
||
|
||
// test2: label is used, single expression | ||
pub fn rustfmt_test2_0(condition: bool) { | ||
test_macro!(|transaction| 'block: { | ||
break 'block 0; | ||
}); | ||
} | ||
|
||
pub fn rustfmt_test2_1(condition: bool) { | ||
test_func(|transaction| 'block: { | ||
break 'block 0; | ||
}); | ||
} | ||
|
||
pub fn rustfmt_test2_2(condition: bool) { | ||
test_func2(|transaction| 'block: { | ||
break 'block 0; | ||
}, 0); | ||
} | ||
|
||
pub fn rustfmt_test2_3(condition: bool) { | ||
let x = |transaction| 'block: { | ||
break 'block 0; | ||
}; | ||
} | ||
|
||
// test3: label is unused, single general multi-line expression | ||
pub fn rustfmt_test3_0(condition: bool) { | ||
test_macro!(|transaction| 'block: { | ||
vec![ | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
0, | ||
] | ||
}); | ||
} | ||
|
||
pub fn rustfmt_test3_1(condition: bool) { | ||
test_func(|transaction| 'block: { | ||
vec![ | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
0, | ||
] | ||
}); | ||
} | ||
|
||
pub fn rustfmt_test3_2(condition: bool) { | ||
test_func2(|transaction| 'block: { | ||
vec![ | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
0, | ||
] | ||
}, 0); | ||
} | ||
|
||
pub fn rustfmt_test3_3(condition: bool) { | ||
let x = |transaction| 'block: { | ||
vec![ | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
0, | ||
] | ||
}; | ||
} | ||
|
||
// test4: label is unused, single block statement-expression | ||
pub fn rustfmt_test4_0(condition: bool) { | ||
test_macro!(|transaction| 'block: { | ||
if condition { | ||
break 'block 1; | ||
} else { | ||
break 'block 0; | ||
} | ||
}); | ||
} | ||
|
||
pub fn rustfmt_test4_1(condition: bool) { | ||
test_func(|transaction| 'block: { | ||
if condition { | ||
break 'block 1; | ||
} else { | ||
break 'block 0; | ||
} | ||
}); | ||
} | ||
|
||
pub fn rustfmt_test4_2(condition: bool) { | ||
test_func2(|transaction| 'block: { | ||
if condition { | ||
break 'block 1; | ||
} else { | ||
break 'block 0; | ||
} | ||
}, 1); | ||
} | ||
|
||
pub fn rustfmt_test4_3(condition: bool) { | ||
let x = |transaction| 'block: { | ||
if condition { | ||
break 'block 1; | ||
} else { | ||
break 'block 0; | ||
} | ||
}; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.