diff --git a/src/expr.rs b/src/expr.rs index 4c9a55f28c0..a8f1c3a01b5 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -23,7 +23,7 @@ use lists::{write_list, itemize_list, ListFormatting, SeparatorTactic, ListTacti use string::{StringFormat, rewrite_string}; use utils::{extra_offset, last_line_width, wrap_str, binary_search, first_line_width, semicolon_for_stmt, trimmed_last_line_width, left_most_sub_expr, stmt_expr, - colon_spaces}; + colon_spaces, contains_skip}; use visitor::FmtVisitor; use config::{Config, IndentStyle, MultilineStyle, ControlBraceStyle, Style}; use comment::{FindUncommented, rewrite_comment, contains_comment, recover_comment_removed}; @@ -53,7 +53,11 @@ fn format_expr(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -> Option { - let result = match expr.node { + if contains_skip(&*expr.attrs) { + return Some(context.snippet(expr.span)); + } + let attr_rw = (&*expr.attrs).rewrite(context, shape); + let expr_rw = match expr.node { ast::ExprKind::Array(ref expr_vec) => { rewrite_array(expr_vec.iter().map(|e| &**e), mk_sp(context.codemap.span_after(expr.span, "["), expr.span.hi), @@ -251,7 +255,16 @@ fn format_expr(expr: &ast::Expr, shape) } }; - result.and_then(|res| recover_comment_removed(res, expr.span, context, shape)) + match (attr_rw, expr_rw) { + (Some(attr_str), Some(expr_str)) => { + let space = if attr_str.is_empty() { "" } else { " " }; + recover_comment_removed(format!("{}{}{}", attr_str, space, expr_str), + expr.span, + context, + shape) + } + _ => None, + } } pub fn rewrite_pair(lhs: &LHS, diff --git a/tests/source/macros.rs b/tests/source/macros.rs index 85ec41ddb0f..26107fbff01 100644 --- a/tests/source/macros.rs +++ b/tests/source/macros.rs @@ -103,3 +103,11 @@ fn issue_1555() { "65454654654654654654654655464", "4"); } + +fn issue1178() { + macro_rules! foo { + (#[$attr:meta] $name:ident) => {} + } + + foo!(#[doc = "bar"] baz); +} diff --git a/tests/source/skip.rs b/tests/source/skip.rs index 21f080e9aba..d13c8159039 100644 --- a/tests/source/skip.rs +++ b/tests/source/skip.rs @@ -16,3 +16,16 @@ impl LateLintPass for UsedUnderscoreBinding { fn check_expr() { // comment } } + +fn issue1346() { + #[cfg_attr(rustfmt, rustfmt_skip)] + Box::new(self.inner.call(req).then(move |result| { + match result { + Ok(resp) => Box::new(future::done(Ok(resp))), + Err(e) => { + try_error!(clo_stderr, "{}", e); + Box::new(future::err(e)) + } + } + })) +} diff --git a/tests/target/macros.rs b/tests/target/macros.rs index a1fa3f74368..941ae46c6d5 100644 --- a/tests/target/macros.rs +++ b/tests/target/macros.rs @@ -108,3 +108,11 @@ fn issue_1555() { "65454654654654654654654655464", "4"); } + +fn issue1178() { + macro_rules! foo { + (#[$attr:meta] $name:ident) => {} + } + + foo!(#[doc = "bar"] baz); +} diff --git a/tests/target/skip.rs b/tests/target/skip.rs index 21f080e9aba..d13c8159039 100644 --- a/tests/target/skip.rs +++ b/tests/target/skip.rs @@ -16,3 +16,16 @@ impl LateLintPass for UsedUnderscoreBinding { fn check_expr() { // comment } } + +fn issue1346() { + #[cfg_attr(rustfmt, rustfmt_skip)] + Box::new(self.inner.call(req).then(move |result| { + match result { + Ok(resp) => Box::new(future::done(Ok(resp))), + Err(e) => { + try_error!(clo_stderr, "{}", e); + Box::new(future::err(e)) + } + } + })) +}