Skip to content

Format a macro in the type position #2238

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

Merged
merged 3 commits into from
Dec 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use expr::{rewrite_pair, rewrite_tuple, rewrite_unary_prefix, wrap_args_with_par
use items::{format_generics_item_list, generics_shape_from_config};
use lists::{definitive_tactic, itemize_list, write_list, ListFormatting, ListTactic, Separator,
SeparatorPlace, SeparatorTactic};
use macros::{rewrite_macro, MacroPosition};
use rewrite::{Rewrite, RewriteContext};
use shape::Shape;
use utils::{colon_spaces, extra_offset, first_line_width, format_abi, format_mutability,
Expand Down Expand Up @@ -726,7 +727,9 @@ impl Rewrite for ast::Ty {
}
ast::TyKind::BareFn(ref bare_fn) => rewrite_bare_fn(bare_fn, self.span, context, shape),
ast::TyKind::Never => Some(String::from("!")),
ast::TyKind::Mac(..) => None,
ast::TyKind::Mac(ref mac) => {
rewrite_macro(mac, None, context, shape, MacroPosition::Expression)
}
ast::TyKind::ImplicitSelf => Some(String::from("")),
ast::TyKind::ImplTrait(ref it) => it.rewrite(context, shape)
.map(|it_str| format!("impl {}", it_str)),
Expand Down
6 changes: 6 additions & 0 deletions tests/source/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,9 @@ fn special_case_macros() {
// assert!
assert!(result, "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')", result, input, expected);
}

// #1209
impl Foo {
/// foo
pub fn foo(&self) -> Bar<foo!( )> {}
}
8 changes: 7 additions & 1 deletion tests/target/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ fn main() {
20, 21, 22);

// #1092
chain!(input, a:take!(max_size), || []);
chain!(input, a: take!(max_size), || []);
}

impl X {
Expand Down Expand Up @@ -284,3 +284,9 @@ fn special_case_macros() {
result, input, expected
);
}

// #1209
impl Foo {
/// foo
pub fn foo(&self) -> Bar<foo!()> {}
}