mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-12 20:16:49 +00:00
Allow attributes on expressions
This commit is contained in:
parent
8ac3fc36cc
commit
99c2eab5ac
19
src/expr.rs
19
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<String> {
|
||||
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, RHS>(lhs: &LHS,
|
||||
|
@ -103,3 +103,11 @@ fn issue_1555() {
|
||||
"65454654654654654654654655464",
|
||||
"4");
|
||||
}
|
||||
|
||||
fn issue1178() {
|
||||
macro_rules! foo {
|
||||
(#[$attr:meta] $name:ident) => {}
|
||||
}
|
||||
|
||||
foo!(#[doc = "bar"] baz);
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
@ -108,3 +108,11 @@ fn issue_1555() {
|
||||
"65454654654654654654654655464",
|
||||
"4");
|
||||
}
|
||||
|
||||
fn issue1178() {
|
||||
macro_rules! foo {
|
||||
(#[$attr:meta] $name:ident) => {}
|
||||
}
|
||||
|
||||
foo!(#[doc = "bar"] baz);
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user