Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadrieril committed Dec 7, 2024
1 parent 483f9e2 commit 2459dbb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1710,10 +1710,12 @@ impl<'a> State<'a> {
}
}
PatKind::Guard(subpat, condition) => {
self.popen();
self.print_pat(subpat);
self.space();
self.word_space("if");
self.print_expr(condition, FixupContext::default());
self.pclose();
}
PatKind::Slice(elts) => {
self.word("[");
Expand Down
20 changes: 20 additions & 0 deletions tests/ui/pattern/rfc-3637-guard-patterns/macro-rules.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//@ run-pass
//! Tests that the addition of guard patterns does not change the behavior of the `pat` macro
//! fragment.
#![feature(guard_patterns)]
#![allow(incomplete_features)]

macro_rules! has_guard {
($p:pat) => {
false
};
($p:pat if $e:expr) => {
true
};
}

fn main() {
assert_eq!(has_guard!(Some(_)), false);
assert_eq!(has_guard!(Some(_) if true), true);
assert_eq!(has_guard!((Some(_) if true)), false);
}

0 comments on commit 2459dbb

Please sign in to comment.