-
Notifications
You must be signed in to change notification settings - Fork 888
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
Support let-chains #5910
Merged
Merged
Support let-chains #5910
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 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 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,121 @@ | ||
fn main() { | ||
if let x = x && x {} | ||
|
||
if xxx && let x = x {} | ||
|
||
if aaaaaaaaaaaaaaaaaaaaa && aaaaaaaaaaaaaaa && aaaaaaaaa && let Some(x) = xxxxxxxxxxxx && aaaaaaa && let None = aaaaaaaaaa {} | ||
|
||
if aaaaaaaaaaaaaaaaaaaaa && aaaaaaaaaaaaaaa || aaaaaaaaa && let Some(x) = xxxxxxxxxxxx && aaaaaaa && let None = aaaaaaaaaa {} | ||
|
||
if let Some(Struct { x:TS(1,2) }) = path::to::<_>(hehe) | ||
&& let [Simple, people] = /* get ready */ create_universe(/* hi */ GreatPowers).initialize_badminton().populate_swamps() && | ||
let everybody = (Loops { hi /*hi*/ , ..loopy() }) || summons::triumphantly() { todo!() } | ||
|
||
if let XXXXXXXXX { xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyy, zzzzzzzzzzzzz} = xxxxxxx() | ||
&& let Foo = bar() { todo!() } | ||
} | ||
|
||
fn test_single_line_let_chain() { | ||
// first item in let-chain is an ident | ||
if a && let Some(b) = foo() { | ||
} | ||
|
||
// first item in let-chain is a unary ! with an ident | ||
let unary_not = if !from_hir_call | ||
&& let Some(p) = parent | ||
{ | ||
}; | ||
|
||
// first item in let-chain is a unary * with an ident | ||
let unary_deref = if *some_deref | ||
&& let Some(p) = parent | ||
{ | ||
}; | ||
|
||
// first item in let-chain is a unary - (neg) with an ident | ||
let unary_neg = if -some_ident | ||
&& let Some(p) = parent | ||
{ | ||
}; | ||
|
||
// first item in let-chain is a try (?) with an ident | ||
let try_ = if some_try? | ||
&& let Some(p) = parent | ||
{ | ||
}; | ||
|
||
// first item in let-chain is an ident wrapped in parens | ||
let in_parens = if (some_ident) | ||
&& let Some(p) = parent | ||
{ | ||
}; | ||
|
||
// first item in let-chain is a ref & with an ident | ||
let _ref = if &some_ref | ||
&& let Some(p) = parent | ||
{ | ||
}; | ||
|
||
// first item in let-chain is a ref &mut with an ident | ||
let mut_ref = if &mut some_ref | ||
&& let Some(p) = parent | ||
{ | ||
}; | ||
|
||
// chain unary ref and try | ||
let chain_of_unary_ref_and_try = if !&*some_ref? | ||
&& let Some(p) = parent { | ||
}; | ||
} | ||
|
||
fn test_multi_line_let_chain() { | ||
// Can only single line the let-chain if the first item is an ident | ||
if let Some(x) = y && a { | ||
|
||
} | ||
|
||
// More than one let-chain must be formatted on multiple lines | ||
if let Some(x) = y && let Some(a) = b { | ||
|
||
} | ||
|
||
// The ident isn't long enough so we don't wrap the first let-chain | ||
if a && let Some(x) = y && let Some(a) = b { | ||
|
||
} | ||
|
||
// The ident is long enough so both let-chains are wrapped | ||
if aaa && let Some(x) = y && let Some(a) = b { | ||
|
||
} | ||
|
||
// function call | ||
if a() && let Some(x) = y { | ||
|
||
} | ||
|
||
// bool literal | ||
if true && let Some(x) = y { | ||
|
||
} | ||
|
||
// cast to a bool | ||
if 1 as bool && let Some(x) = y { | ||
|
||
} | ||
|
||
// matches! macro call | ||
if matches!(a, some_type) && let Some(x) = y { | ||
|
||
} | ||
|
||
// block expression returning bool | ||
if { true } && let Some(x) = y { | ||
|
||
} | ||
|
||
// field access | ||
if a.x && let Some(x) = y { | ||
|
||
} | ||
} |
This file contains 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 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,128 @@ | ||
fn main() { | ||
if let x = x | ||
&& x | ||
{} | ||
|
||
if xxx && let x = x {} | ||
|
||
if aaaaaaaaaaaaaaaaaaaaa | ||
&& aaaaaaaaaaaaaaa | ||
&& aaaaaaaaa | ||
&& let Some(x) = xxxxxxxxxxxx | ||
&& aaaaaaa | ||
&& let None = aaaaaaaaaa | ||
{} | ||
|
||
if aaaaaaaaaaaaaaaaaaaaa && aaaaaaaaaaaaaaa | ||
|| aaaaaaaaa | ||
&& let Some(x) = xxxxxxxxxxxx | ||
&& aaaaaaa | ||
&& let None = aaaaaaaaaa | ||
{} | ||
|
||
if let Some(Struct { x: TS(1, 2) }) = path::to::<_>(hehe) | ||
&& let [Simple, people] = /* get ready */ | ||
create_universe(/* hi */ GreatPowers) | ||
.initialize_badminton() | ||
.populate_swamps() | ||
&& let everybody = (Loops { | ||
hi, /*hi*/ | ||
..loopy() | ||
}) | ||
|| summons::triumphantly() | ||
{ | ||
todo!() | ||
} | ||
|
||
if let XXXXXXXXX { | ||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, | ||
yyyyyyyyyyyyy, | ||
zzzzzzzzzzzzz, | ||
} = xxxxxxx() | ||
&& let Foo = bar() | ||
{ | ||
todo!() | ||
} | ||
} | ||
|
||
fn test_single_line_let_chain() { | ||
// first item in let-chain is an ident | ||
if a && let Some(b) = foo() {} | ||
|
||
// first item in let-chain is a unary ! with an ident | ||
let unary_not = if !from_hir_call && let Some(p) = parent {}; | ||
|
||
// first item in let-chain is a unary * with an ident | ||
let unary_deref = if *some_deref && let Some(p) = parent {}; | ||
|
||
// first item in let-chain is a unary - (neg) with an ident | ||
let unary_neg = if -some_ident && let Some(p) = parent {}; | ||
|
||
// first item in let-chain is a try (?) with an ident | ||
let try_ = if some_try? && let Some(p) = parent {}; | ||
|
||
// first item in let-chain is an ident wrapped in parens | ||
let in_parens = if (some_ident) && let Some(p) = parent {}; | ||
|
||
// first item in let-chain is a ref & with an ident | ||
let _ref = if &some_ref && let Some(p) = parent {}; | ||
|
||
// first item in let-chain is a ref &mut with an ident | ||
let mut_ref = if &mut some_ref && let Some(p) = parent {}; | ||
|
||
// chain unary ref and try | ||
let chain_of_unary_ref_and_try = if !&*some_ref? && let Some(p) = parent {}; | ||
} | ||
|
||
fn test_multi_line_let_chain() { | ||
// Can only single line the let-chain if the first item is an ident | ||
if let Some(x) = y | ||
&& a | ||
{} | ||
|
||
// More than one let-chain must be formatted on multiple lines | ||
if let Some(x) = y | ||
&& let Some(a) = b | ||
{} | ||
|
||
// The ident isn't long enough so we don't wrap the first let-chain | ||
if a && let Some(x) = y | ||
&& let Some(a) = b | ||
{} | ||
|
||
// The ident is long enough so both let-chains are wrapped | ||
if aaa | ||
&& let Some(x) = y | ||
&& let Some(a) = b | ||
{} | ||
|
||
// function call | ||
if a() | ||
&& let Some(x) = y | ||
{} | ||
|
||
// bool literal | ||
if true | ||
&& let Some(x) = y | ||
{} | ||
|
||
// cast to a bool | ||
if 1 as bool | ||
&& let Some(x) = y | ||
{} | ||
|
||
// matches! macro call | ||
if matches!(a, some_type) | ||
&& let Some(x) = y | ||
{} | ||
|
||
// block expression returning bool | ||
if { true } | ||
&& let Some(x) = y | ||
{} | ||
|
||
// field access | ||
if a.x | ||
&& let Some(x) = y | ||
{} | ||
} |
This file contains 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
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.
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.
@calebcartwright yup, though this seems to be the only test for it (pulled from the original PR). Do we want to support if-let guard formatting with this one or should we hold off on that until a future PR?