mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-28 20:16:58 +03:00
Merge pull request #2258 from topecongiro/issue-819
Format macro in pattern position
This commit is contained in:
@@ -50,6 +50,7 @@ pub enum MacroPosition {
|
||||
Item,
|
||||
Statement,
|
||||
Expression,
|
||||
Pat,
|
||||
}
|
||||
|
||||
impl MacroStyle {
|
||||
|
||||
+2
-2
@@ -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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) => (),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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
|
||||
) => (),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user