Merge pull request #2258 from topecongiro/issue-819

Format macro in pattern position
This commit is contained in:
Nick Cameron
2017-12-11 08:54:02 +13:00
committed by GitHub
4 changed files with 33 additions and 2 deletions
+1
View File
@@ -50,6 +50,7 @@ pub enum MacroPosition {
Item,
Statement,
Expression,
Pat,
}
impl MacroStyle {
+2 -2
View File
@@ -19,6 +19,7 @@
wrap_struct_field, PairParts};
use lists::{itemize_list, shape_for_tactic, struct_lit_formatting, struct_lit_shape,
struct_lit_tactic, write_list, DefinitiveListTactic, SeparatorPlace, SeparatorTactic};
use macros::{rewrite_macro, MacroPosition};
use rewrite::{Rewrite, RewriteContext};
use shape::Shape;
use types::{rewrite_path, PathContext};
@@ -121,8 +122,7 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
PatKind::Struct(ref path, ref fields, ellipsis) => {
rewrite_struct_pat(path, fields, ellipsis, self.span, context, shape)
}
// FIXME(#819) format pattern macros.
PatKind::Mac(..) => Some(context.snippet(self.span).to_owned()),
PatKind::Mac(ref mac) => rewrite_macro(mac, None, context, shape, MacroPosition::Pat),
}
}
}
+16
View File
@@ -284,3 +284,19 @@ impl Foo {
/// foo
pub fn foo(&self) -> Bar<foo!( )> {}
}
// #819
fn macro_in_pattern_position () {
let x = match y {
foo!( ) => (),
bar!( a, b,
c) => (),
bar!(a
, b
, c
,) => (),
baz!( 1 + 2 + 3, quux.kaas( )
) => (),
quux!(AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA, BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB) => (),
};
}
+14
View File
@@ -808,3 +808,17 @@ impl Foo {
/// foo
pub fn foo(&self) -> Bar<foo!()> {}
}
// #819
fn macro_in_pattern_position() {
let x = match y {
foo!() => (),
bar!(a, b, c) => (),
bar!(a, b, c,) => (),
baz!(1 + 2 + 3, quux.kaas()) => (),
quux!(
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
) => (),
};
}