diff options
| author | Nadrieril <nadrieril+git@gmail.com> | 2024-11-24 22:57:33 +0100 |
|---|---|---|
| committer | Nadrieril <nadrieril+git@gmail.com> | 2024-11-24 22:57:33 +0100 |
| commit | 483f9e258055bcd37c162cbf2af24aa7450ab0ea (patch) | |
| tree | f069c99d5a5e062861418823f71fd87c7e847aa3 | |
| parent | 962c0140c71f07642a7c39243c8a9a314dd26ba5 (diff) | |
| download | rust-483f9e258055bcd37c162cbf2af24aa7450ab0ea.tar.gz rust-483f9e258055bcd37c162cbf2af24aa7450ab0ea.zip | |
Fix rustfmt according to review
| -rw-r--r-- | src/tools/rustfmt/src/patterns.rs | 4 | ||||
| -rw-r--r-- | src/tools/rustfmt/tests/target/guard_patterns.rs | 12 |
2 files changed, 14 insertions, 2 deletions
diff --git a/src/tools/rustfmt/src/patterns.rs b/src/tools/rustfmt/src/patterns.rs index 7bc699b07b0..7b4730eadc8 100644 --- a/src/tools/rustfmt/src/patterns.rs +++ b/src/tools/rustfmt/src/patterns.rs @@ -339,9 +339,9 @@ impl Rewrite for Pat { .max_width_error(shape.width, self.span)?, ) .map(|inner_pat| format!("({})", inner_pat)), - PatKind::Err(_) => Err(RewriteError::Unknown), + PatKind::Guard(..) => Ok(context.snippet(self.span).to_string()), PatKind::Deref(_) => Err(RewriteError::Unknown), - PatKind::Guard(..) => Err(RewriteError::Unknown), + PatKind::Err(_) => Err(RewriteError::Unknown), } } } diff --git a/src/tools/rustfmt/tests/target/guard_patterns.rs b/src/tools/rustfmt/tests/target/guard_patterns.rs new file mode 100644 index 00000000000..2e4667b916c --- /dev/null +++ b/src/tools/rustfmt/tests/target/guard_patterns.rs @@ -0,0 +1,12 @@ +#![feature(guard_patterns)] + +fn main() { + match user.subscription_plan() { + (Plan::Regular if user.credit() >= 100) | (Plan::Premium if user.credit() >= 80) => { + // Complete the transaction. + } + _ => { + // The user doesn't have enough credit, return an error message. + } + } +} |
