mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-11 16:15:03 +00:00
Merge pull request #1543 from topecongiro/field-attr
Support struct_field_attributes
This commit is contained in:
commit
56515dd4d6
22
src/expr.rs
22
src/expr.rs
@ -1947,19 +1947,25 @@ fn rewrite_field(context: &RewriteContext, field: &ast::Field, shape: Shape) ->
|
||||
expr_shape.offset += overhead;
|
||||
let expr = field.expr.rewrite(context, expr_shape);
|
||||
|
||||
let mut attrs_str = try_opt!((*field.attrs).rewrite(context, shape));
|
||||
if !attrs_str.is_empty() {
|
||||
attrs_str.push_str(&format!("\n{}", shape.indent.to_string(context.config)));
|
||||
};
|
||||
|
||||
match expr {
|
||||
Some(e) => Some(format!("{}{}{}", name, separator, e)),
|
||||
Some(e) => Some(format!("{}{}{}{}", attrs_str, name, separator, e)),
|
||||
None => {
|
||||
let expr_offset = shape.indent.block_indent(context.config);
|
||||
let expr = field
|
||||
.expr
|
||||
.rewrite(context,
|
||||
Shape::legacy(try_opt!(context
|
||||
.config
|
||||
.max_width
|
||||
.checked_sub(expr_offset.width())),
|
||||
expr_offset));
|
||||
expr.map(|s| format!("{}:\n{}{}", name, expr_offset.to_string(&context.config), s))
|
||||
.rewrite(context, Shape::indented(expr_offset, context.config));
|
||||
expr.map(|s| {
|
||||
format!("{}{}:\n{}{}",
|
||||
attrs_str,
|
||||
name,
|
||||
expr_offset.to_string(&context.config),
|
||||
s)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
22
tests/source/struct-field-attributes.rs
Normal file
22
tests/source/struct-field-attributes.rs
Normal file
@ -0,0 +1,22 @@
|
||||
// #1535
|
||||
#![feature(struct_field_attributes)]
|
||||
|
||||
struct Foo {
|
||||
bar: u64,
|
||||
|
||||
#[cfg(test)]
|
||||
qux: u64,
|
||||
}
|
||||
|
||||
fn do_something() -> Foo {
|
||||
Foo {
|
||||
bar: 0,
|
||||
|
||||
#[cfg(test)]
|
||||
qux: 1,
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
do_something();
|
||||
}
|
22
tests/target/struct-field-attributes.rs
Normal file
22
tests/target/struct-field-attributes.rs
Normal file
@ -0,0 +1,22 @@
|
||||
// #1535
|
||||
#![feature(struct_field_attributes)]
|
||||
|
||||
struct Foo {
|
||||
bar: u64,
|
||||
|
||||
#[cfg(test)]
|
||||
qux: u64,
|
||||
}
|
||||
|
||||
fn do_something() -> Foo {
|
||||
Foo {
|
||||
bar: 0,
|
||||
|
||||
#[cfg(test)]
|
||||
qux: 1,
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
do_something();
|
||||
}
|
Loading…
Reference in New Issue
Block a user