mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-12 08:36:03 +00:00
Format inner and outer attributes separately.
Actually just skips inner attributes, because its a pain to track them, and lets missed spans handle them. Closes #413
This commit is contained in:
parent
8880c0e5d3
commit
6600cd341a
@ -270,7 +270,7 @@ impl<'a, 'v> visit::Visitor<'v> for FmtVisitor<'a> {
|
||||
}
|
||||
|
||||
impl<'a> FmtVisitor<'a> {
|
||||
pub fn from_codemap<'b>(codemap: &'b CodeMap, config: &'b Config) -> FmtVisitor<'b> {
|
||||
pub fn from_codemap(codemap: &'a CodeMap, config: &'a Config) -> FmtVisitor<'a> {
|
||||
FmtVisitor {
|
||||
codemap: codemap,
|
||||
buffer: StringBuffer::new(),
|
||||
@ -301,21 +301,29 @@ impl<'a> FmtVisitor<'a> {
|
||||
return false;
|
||||
}
|
||||
|
||||
let first = &attrs[0];
|
||||
if utils::contains_skip(attrs) {
|
||||
return true;
|
||||
}
|
||||
|
||||
let outers: Vec<_> = attrs.iter()
|
||||
.filter(|a| a.node.style == ast::AttrStyle::Outer)
|
||||
.map(|a| a.clone())
|
||||
.collect();
|
||||
if outers.is_empty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
let first = &outers[0];
|
||||
self.format_missing_with_indent(first.span.lo);
|
||||
|
||||
if utils::contains_skip(attrs) {
|
||||
true
|
||||
} else {
|
||||
let rewrite = attrs.rewrite(&self.get_context(),
|
||||
self.config.max_width - self.block_indent.width(),
|
||||
self.block_indent)
|
||||
.unwrap();
|
||||
self.buffer.push_str(&rewrite);
|
||||
let last = attrs.last().unwrap();
|
||||
self.last_pos = last.span.hi;
|
||||
false
|
||||
}
|
||||
let rewrite = outers.rewrite(&self.get_context(),
|
||||
self.config.max_width - self.block_indent.width(),
|
||||
self.block_indent)
|
||||
.unwrap();
|
||||
self.buffer.push_str(&rewrite);
|
||||
let last = outers.last().unwrap();
|
||||
self.last_pos = last.span.hi;
|
||||
false
|
||||
}
|
||||
|
||||
fn format_mod(&mut self, m: &ast::Mod, s: Span, ident: ast::Ident) {
|
||||
|
@ -87,3 +87,9 @@ fn main() {
|
||||
let _ = move || 42;
|
||||
let _ = || unsafe { abort() };
|
||||
}
|
||||
|
||||
// With inner attributes.
|
||||
fn inner() {
|
||||
#![inline]
|
||||
x
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user