Merge pull request #2703 from nrc/attrs

Use scoped attributes for skip attribute
This commit is contained in:
Nick Cameron 2018-05-15 21:42:43 +12:00 committed by GitHub
commit 45c0b47e6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
38 changed files with 196 additions and 101 deletions

View File

@ -28,9 +28,7 @@ matrix:
- env: INTEGRATION=futures-rs
- env: INTEGRATION=rand
- env: INTEGRATION=failure
- env: INTEGRATION=glob
- env: INTEGRATION=error-chain
- env: INTEGRATION=tempdir
- env: INTEGRATION=bitflags
- env: INTEGRATION=log
allow_failures:
@ -47,6 +45,8 @@ matrix:
- env: INTEGRATION=futures-rs
- env: INTEGRATION=log
- env: INTEGRATION=rand
- env: INTEGRATION=glob
- env: INTEGRATION=tempdir
before_script:
- |

View File

@ -1951,7 +1951,7 @@ lines are found, they are trimmed down to match this integer.
Original Code:
```rust
#![rustfmt_skip]
#![rustfmt::skip]
fn foo() {
println!("a");
@ -2010,7 +2010,7 @@ them, additional blank lines are inserted.
Original Code (rustfmt will not change it with the default value of `0`):
```rust
#![rustfmt_skip]
#![rustfmt::skip]
fn foo() {
println!("a");

View File

@ -174,7 +174,7 @@ See [Configurations.md](Configurations.md) for details.
* For things you do not want rustfmt to mangle, use one of
```rust
#[rustfmt_skip] // requires nightly and #![feature(custom_attribute)] in crate root
#[rustfmt::skip] // requires nightly Rust and #![feature(tool_attributes)] in crate root
#[cfg_attr(rustfmt, rustfmt_skip)] // works in stable
```
* When you run rustfmt, place a file named `rustfmt.toml` or `.rustfmt.toml` in

View File

@ -0,0 +1,2 @@
error_on_line_overflow = true
error_on_unformatted = true

View File

@ -20,6 +20,7 @@
use lists::{itemize_list, write_list, ListFormatting};
use rewrite::{Rewrite, RewriteContext};
use shape::Shape;
use types::{rewrite_path, PathContext};
use utils::{count_newlines, mk_sp};
/// Returns attributes on the given statement.
@ -200,9 +201,11 @@ fn allow_mixed_tactic_for_nested_metaitem_list(list: &[ast::NestedMetaItem]) ->
impl Rewrite for ast::MetaItem {
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
Some(match self.node {
ast::MetaItemKind::Word => String::from(&*self.name().as_str()),
ast::MetaItemKind::Word => {
rewrite_path(context, PathContext::Type, None, &self.ident, shape)?
}
ast::MetaItemKind::List(ref list) => {
let name = self.name().as_str();
let path = rewrite_path(context, PathContext::Type, None, &self.ident, shape)?;
let item_shape = match context.config.indent_style() {
IndentStyle::Block => shape
.block_indent(context.config.tab_spaces())
@ -210,7 +213,7 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
// 1 = `(`, 2 = `]` and `)`
IndentStyle::Visual => shape
.visual_indent(0)
.shrink_left(name.len() + 1)
.shrink_left(path.len() + 1)
.and_then(|s| s.sub_width(2))?,
};
let items = itemize_list(
@ -248,21 +251,21 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
};
let item_str = write_list(&item_vec, &fmt)?;
// 3 = "()" and "]"
let one_line_budget = shape.offset_left(name.len())?.sub_width(3)?.width;
let one_line_budget = shape.offset_left(path.len())?.sub_width(3)?.width;
if context.config.indent_style() == IndentStyle::Visual
|| (!item_str.contains('\n') && item_str.len() <= one_line_budget)
{
format!("{}({})", name, item_str)
format!("{}({})", path, item_str)
} else {
let indent = shape.indent.to_string_with_newline(context.config);
let nested_indent = item_shape.indent.to_string_with_newline(context.config);
format!("{}({}{}{})", name, nested_indent, item_str, indent)
format!("{}({}{}{})", path, nested_indent, item_str, indent)
}
}
ast::MetaItemKind::NameValue(ref literal) => {
let name = self.name().as_str();
let path = rewrite_path(context, PathContext::Type, None, &self.ident, shape)?;
// 3 = ` = `
let lit_shape = shape.shrink_left(name.len() + 3)?;
let lit_shape = shape.shrink_left(path.len() + 3)?;
// `rewrite_literal` returns `None` when `literal` exceeds max
// width. Since a literal is basically unformattable unless it
// is a string literal (and only if `format_strings` is set),
@ -271,7 +274,7 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
// See #2479 for example.
let value = rewrite_literal(context, literal, lit_shape)
.unwrap_or_else(|| context.snippet(literal.span).to_owned());
format!("{} = {}", name, value)
format!("{} = {}", path, value)
}
})
}

View File

@ -1253,7 +1253,7 @@ fn comment_code_slices_three() {
}
#[test]
#[cfg_attr(rustfmt, rustfmt_skip)]
#[rustfmt::skip]
fn format_comments() {
let mut config: ::config::Config = Default::default();
config.set().wrap_comments(true);

View File

@ -8,12 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(custom_attribute)]
#![feature(tool_attributes)]
#![feature(decl_macro)]
// FIXME(cramertj) remove after match_default_bindings merges
#![allow(stable_features)]
#![allow(unused_attributes)]
#![feature(match_default_bindings)]
#![feature(type_ascription)]
#![feature(unicode_internals)]
@ -40,6 +37,7 @@
extern crate toml;
extern crate unicode_segmentation;
use std::cell::RefCell;
use std::collections::HashMap;
use std::fmt;
use std::io::{self, stdout, Write};
@ -50,7 +48,7 @@
use syntax::ast;
pub use syntax::codemap::FileName;
use syntax::codemap::{CodeMap, FilePathMapping};
use syntax::codemap::{CodeMap, FilePathMapping, Span};
use syntax::errors::emitter::{ColorConfig, EmitterWriter};
use syntax::errors::{DiagnosticBuilder, Handler};
use syntax::parse::{self, ParseSess};
@ -128,9 +126,14 @@ pub enum ErrorKind {
// License check has failed
#[fail(display = "license check failed")]
LicenseCheck,
// Used deprecated skip attribute
#[fail(display = "`rustfmt_skip` is deprecated; use `rustfmt::skip`")]
DeprecatedAttr,
// Used a rustfmt:: attribute other than skip
#[fail(display = "invalid attribute")]
BadAttr,
}
// Formatting errors that are identified *after* rustfmt has run.
struct FormattingError {
line: usize,
kind: ErrorKind,
@ -140,11 +143,28 @@ struct FormattingError {
}
impl FormattingError {
fn from_span(span: &Span, codemap: &CodeMap, kind: ErrorKind) -> FormattingError {
FormattingError {
line: codemap.lookup_char_pos(span.lo()).line,
kind,
is_comment: false,
is_string: false,
line_buffer: codemap
.span_to_lines(*span)
.ok()
.and_then(|fl| {
fl.file
.get_line(fl.lines[0].line_index)
.map(|l| l.into_owned())
})
.unwrap_or_else(|| String::new()),
}
}
fn msg_prefix(&self) -> &str {
match self.kind {
ErrorKind::LineOverflow(..) | ErrorKind::TrailingWhitespace => "internal error:",
ErrorKind::LicenseCheck => "error:",
ErrorKind::BadIssue(_) => "warning:",
ErrorKind::LicenseCheck | ErrorKind::BadAttr => "error:",
ErrorKind::BadIssue(_) | ErrorKind::DeprecatedAttr => "warning:",
}
}
@ -161,7 +181,7 @@ fn msg_suffix(&self) -> &str {
fn format_len(&self) -> (usize, usize) {
match self.kind {
ErrorKind::LineOverflow(found, max) => (max, found - max),
ErrorKind::TrailingWhitespace => {
ErrorKind::TrailingWhitespace | ErrorKind::DeprecatedAttr | ErrorKind::BadAttr => {
let trailing_ws_start = self
.line_buffer
.rfind(|c: char| !c.is_whitespace())
@ -177,20 +197,30 @@ fn format_len(&self) -> (usize, usize) {
}
}
#[derive(Clone)]
pub struct FormatReport {
// Maps stringified file paths to their associated formatting errors.
file_error_map: HashMap<FileName, Vec<FormattingError>>,
file_error_map: Rc<RefCell<HashMap<FileName, Vec<FormattingError>>>>,
}
impl FormatReport {
fn new() -> FormatReport {
FormatReport {
file_error_map: HashMap::new(),
file_error_map: Rc::new(RefCell::new(HashMap::new())),
}
}
fn append(&self, f: FileName, mut v: Vec<FormattingError>) {
self.file_error_map
.borrow_mut()
.entry(f)
.and_modify(|fe| fe.append(&mut v))
.or_insert(v);
}
fn warning_count(&self) -> usize {
self.file_error_map
.borrow()
.iter()
.map(|(_, errors)| errors.len())
.sum()
@ -204,7 +234,7 @@ fn print_warnings_fancy(
&self,
mut t: Box<term::Terminal<Output = io::Stderr>>,
) -> Result<(), term::Error> {
for (file, errors) in &self.file_error_map {
for (file, errors) in &*self.file_error_map.borrow() {
for error in errors {
let prefix_space_len = error.line.to_string().len();
let prefix_spaces = " ".repeat(1 + prefix_space_len);
@ -250,7 +280,7 @@ fn print_warnings_fancy(
}
}
if !self.file_error_map.is_empty() {
if !self.file_error_map.borrow().is_empty() {
t.attr(term::Attr::Bold)?;
write!(t, "warning: ")?;
t.reset()?;
@ -274,7 +304,7 @@ fn target_str(space_len: usize, target_len: usize) -> String {
impl fmt::Display for FormatReport {
// Prints all the formatting errors.
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
for (file, errors) in &self.file_error_map {
for (file, errors) in &*self.file_error_map.borrow() {
for error in errors {
let prefix_space_len = error.line.to_string().len();
let prefix_spaces = " ".repeat(1 + prefix_space_len);
@ -313,7 +343,7 @@ fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
)?;
}
}
if !self.file_error_map.is_empty() {
if !self.file_error_map.borrow().is_empty() {
writeln!(
fmt,
"warning: rustfmt may have failed to format. See previous {} errors.",
@ -339,10 +369,11 @@ fn format_ast<F>(
parse_session: &mut ParseSess,
main_file: &FileName,
config: &Config,
report: FormatReport,
mut after_file: F,
) -> Result<(FileMap, bool), io::Error>
where
F: FnMut(&FileName, &mut String, &[(usize, usize)]) -> Result<bool, io::Error>,
F: FnMut(&FileName, &mut String, &[(usize, usize)], &FormatReport) -> Result<bool, io::Error>,
{
let mut result = FileMap::new();
// diff mode: check if any files are differing
@ -360,7 +391,8 @@ fn format_ast<F>(
.file;
let big_snippet = filemap.src.as_ref().unwrap();
let snippet_provider = SnippetProvider::new(filemap.start_pos, big_snippet);
let mut visitor = FmtVisitor::from_codemap(parse_session, config, &snippet_provider);
let mut visitor =
FmtVisitor::from_codemap(parse_session, config, &snippet_provider, report.clone());
// Format inner attributes if available.
if !krate.attrs.is_empty() && path == *main_file {
visitor.skip_empty_lines(filemap.end_pos);
@ -380,8 +412,7 @@ fn format_ast<F>(
::utils::count_newlines(&visitor.buffer)
);
let filename = path.clone();
has_diff |= match after_file(&filename, &mut visitor.buffer, &visitor.skipped_range) {
has_diff |= match after_file(&path, &mut visitor.buffer, &visitor.skipped_range, &report) {
Ok(result) => result,
Err(e) => {
// Create a new error with path_str to help users see which files failed
@ -390,13 +421,13 @@ fn format_ast<F>(
}
};
result.push((filename, visitor.buffer));
result.push((path.clone(), visitor.buffer));
}
Ok((result, has_diff))
}
/// Returns true if the line with the given line number was skipped by `#[rustfmt_skip]`.
/// Returns true if the line with the given line number was skipped by `#[rustfmt::skip]`.
fn is_skipped_line(line_number: usize, skipped_range: &[(usize, usize)]) -> bool {
skipped_range
.iter()
@ -429,7 +460,7 @@ fn format_lines(
name: &FileName,
skipped_range: &[(usize, usize)],
config: &Config,
report: &mut FormatReport,
report: &FormatReport,
) {
let mut trims = vec![];
let mut last_wspace: Option<usize> = None;
@ -543,7 +574,7 @@ fn format_lines(
}
}
report.file_error_map.insert(name.clone(), errors);
report.append(name.clone(), errors);
}
fn parse_input<'sess>(
@ -760,19 +791,20 @@ fn format_input_inner<T: Write>(
));
parse_session.span_diagnostic = Handler::with_emitter(true, false, silent_emitter);
let mut report = FormatReport::new();
let report = FormatReport::new();
let format_result = format_ast(
&krate,
&mut parse_session,
&main_file,
config,
|file_name, file, skipped_range| {
report.clone(),
|file_name, file, skipped_range, report| {
// For some reason, the codemap does not include terminating
// newlines so we must add one on for each file. This is sad.
filemap::append_newline(file);
format_lines(file, file_name, skipped_range, config, &mut report);
format_lines(file, file_name, skipped_range, config, report);
if let Some(ref mut out) = out {
return filemap::write_file(file, file_name, out, config);
@ -975,7 +1007,7 @@ fn test_format_snippet() {
#[test]
fn test_format_code_block_fail() {
#[rustfmt_skip]
#[rustfmt::skip]
let code_block = "this_line_is_100_characters_long_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(x, y, z);";
assert!(format_code_block(code_block, &Config::default()).is_none());
}

View File

@ -16,6 +16,7 @@
use config::{Config, IndentStyle};
use shape::Shape;
use visitor::SnippetProvider;
use FormatReport;
use std::cell::RefCell;
@ -38,6 +39,7 @@ pub struct RewriteContext<'a> {
// When rewriting chain, veto going multi line except the last element
pub force_one_line_chain: RefCell<bool>,
pub snippet_provider: &'a SnippetProvider<'a>,
pub report: FormatReport,
}
impl<'a> RewriteContext<'a> {

View File

@ -704,14 +704,14 @@ fn code_block_valid(&self) -> bool {
// We never expect to not have a code block.
assert!(self.code_block.is_some() && self.code_block_start.is_some());
// See if code block begins with #![rustfmt_skip].
// See if code block begins with #![rustfmt::skip].
let fmt_skip = self
.code_block
.as_ref()
.unwrap()
.split('\n')
.nth(0)
.unwrap_or("") == "#![rustfmt_skip]";
.unwrap_or("") == "#![rustfmt::skip]";
if self.config_name.is_none() && !fmt_skip {
write_message(&format!(
@ -790,7 +790,7 @@ fn formatted_is_idempotent(&self) -> bool {
// - Rust code blocks are identifed by lines beginning with "```rust".
// - One explicit configuration setting is supported per code block.
// - Rust code blocks with no configuration setting are illegal and cause an
// assertion failure, unless the snippet begins with #![rustfmt_skip].
// assertion failure, unless the snippet begins with #![rustfmt::skip].
// - Configuration names in Configurations.md must be in the form of
// "## `NAME`".
// - Configuration values in Configurations.md must be in the form of

View File

@ -22,8 +22,8 @@
use rewrite::RewriteContext;
use shape::Shape;
// When we get scoped annotations, we should have rustfmt::skip.
const SKIP_ANNOTATION: &str = "rustfmt_skip";
pub const DEPR_SKIP_ANNOTATION: &str = "rustfmt_skip";
pub const SKIP_ANNOTATION: &str = "rustfmt::skip";
// Computes the length of a string's last line, minus offset.
pub fn extra_offset(text: &str, shape: Shape) -> usize {
@ -212,7 +212,10 @@ pub fn last_line_extendable(s: &str) -> bool {
#[inline]
fn is_skip(meta_item: &MetaItem) -> bool {
match meta_item.node {
MetaItemKind::Word => meta_item.name() == SKIP_ANNOTATION,
MetaItemKind::Word => {
let path_str = meta_item.ident.to_string();
path_str == SKIP_ANNOTATION || path_str == DEPR_SKIP_ANNOTATION
}
MetaItemKind::List(ref l) => {
meta_item.name() == "cfg_attr" && l.len() == 2 && is_skip_nested(&l[1])
}

View File

@ -26,7 +26,11 @@
use rewrite::{Rewrite, RewriteContext};
use shape::{Indent, Shape};
use spanned::Spanned;
use utils::{self, contains_skip, count_newlines, inner_attributes, mk_sp, ptr_vec_to_ref_vec};
use utils::{
self, contains_skip, count_newlines, inner_attributes, mk_sp, ptr_vec_to_ref_vec,
DEPR_SKIP_ANNOTATION,
};
use {ErrorKind, FormatReport, FormattingError};
use std::cell::RefCell;
@ -66,6 +70,7 @@ pub struct FmtVisitor<'a> {
pub snippet_provider: &'a SnippetProvider<'a>,
pub line_number: usize,
pub skipped_range: Vec<(usize, usize)>,
pub report: FormatReport,
}
impl<'b, 'a: 'b> FmtVisitor<'a> {
@ -552,13 +557,19 @@ pub fn push_skipped_with_span(&mut self, span: Span) {
}
pub fn from_context(ctx: &'a RewriteContext) -> FmtVisitor<'a> {
FmtVisitor::from_codemap(ctx.parse_session, ctx.config, ctx.snippet_provider)
FmtVisitor::from_codemap(
ctx.parse_session,
ctx.config,
ctx.snippet_provider,
ctx.report.clone(),
)
}
pub fn from_codemap(
parse_session: &'a ParseSess,
config: &'a Config,
snippet_provider: &'a SnippetProvider,
report: FormatReport,
) -> FmtVisitor<'a> {
FmtVisitor {
parse_session,
@ -571,6 +582,7 @@ pub fn from_codemap(
snippet_provider,
line_number: 0,
skipped_range: vec![],
report,
}
}
@ -584,6 +596,33 @@ pub fn snippet(&'b self, span: Span) -> &'a str {
// Returns true if we should skip the following item.
pub fn visit_attrs(&mut self, attrs: &[ast::Attribute], style: ast::AttrStyle) -> bool {
for attr in attrs {
if attr.name() == DEPR_SKIP_ANNOTATION {
let file_name = self.codemap.span_to_filename(attr.span);
self.report.append(
file_name,
vec![FormattingError::from_span(
&attr.span,
&self.codemap,
ErrorKind::DeprecatedAttr,
)],
);
} else if attr.path.segments[0].ident.to_string() == "rustfmt" {
if attr.path.segments.len() == 1
|| attr.path.segments[1].ident.to_string() != "skip"
{
let file_name = self.codemap.span_to_filename(attr.span);
self.report.append(
file_name,
vec![FormattingError::from_span(
&attr.span,
&self.codemap,
ErrorKind::BadAttr,
)],
);
}
}
}
if contains_skip(attrs) {
return true;
}
@ -711,6 +750,7 @@ pub fn get_context(&self) -> RewriteContext {
is_if_else_block: RefCell::new(false),
force_one_line_chain: RefCell::new(false),
snippet_provider: self.snippet_provider,
report: self.report.clone(),
}
}
}

View File

@ -1 +1 @@
skip_children = true
skip_children = true

View File

@ -161,3 +161,10 @@ struct A { #[doc = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// #2647
#[cfg(feature = "this_line_is_101_characters_long_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")]
pub fn foo() {}
// path attrs
#[clippy::bar]
#[clippy::bar=foo]
#[clippy::bar(a, b, c)]
pub fn foo() {}

View File

@ -48,5 +48,5 @@ fn debug_function() {
#[link_section=".vectors"]
#[no_mangle] // Test this attribute is preserved.
#[cfg_attr(rustfmt, rustfmt_skip)]
#[cfg_attr(rustfmt, rustfmt::skip)]
pub static ISSUE_1284: [i32; 16] = [];

View File

@ -36,7 +36,7 @@ fn main() {
/// A Doc comment
#[AnAttribute]
pub struct Foo {
#[rustfmt_skip]
#[rustfmt::skip]
f : SomeType, // Comment beside a field
f: SomeType, // Comment beside a field
// Comment on a field
@ -166,7 +166,7 @@ struct Palette { /// A map of indices in the palette to a count of pixels in app
// when the field had attributes
struct FieldsWithAttributes {
// Pre Comment
#[rustfmt_skip] pub host:String, // Post comment BBBBBBBBBBBBBB BBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBBB BBBBBBBBBBB
#[rustfmt::skip] pub host:String, // Post comment BBBBBBBBBBBBBB BBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBBB BBBBBBBBBBB
//Another pre comment
#[attr1]
#[attr2] pub id: usize // CCCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCC CCCCCCCCCCCC

View File

@ -13,7 +13,7 @@ fn main() {
y: y,
#[attr]
z: z,
#[rustfmt_skip]
#[rustfmt::skip]
skipped: skipped,
};
}

View File

@ -13,7 +13,7 @@ fn main() {
y: y,
#[attr]
z: z,
#[rustfmt_skip]
#[rustfmt::skip]
skipped: skipped,
};
}

View File

@ -49,7 +49,7 @@ pub enum EnumWithAttributes {
//This is a pre comment AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
TupleVar(usize, usize, usize), // AAAA AAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
// Pre Comment
#[rustfmt_skip]
#[rustfmt::skip]
SkippedItem(String,String,), // Post-comment
#[another_attr]
#[attr2]

View File

@ -13,4 +13,4 @@
use x;
use a;
use a;

View File

@ -48,7 +48,7 @@ fn foo() {
#[an_attribute]
// Comment after an attribute.
None => 0,
#[rustfmt_skip]
#[rustfmt::skip]
Blurb => { }
};
}
@ -103,7 +103,7 @@ fn matches() {
fn match_skip() {
let _ = match Some(1) {
#[rustfmt_skip]
#[rustfmt::skip]
Some( n ) => n,
None => 1,
};

View File

@ -36,7 +36,7 @@ fn baz<'a: 'b /* comment on 'a */, T: Somsssssssssssssssssssssssssssssssssssssss
#[attr2]#[attr3]extern crate foo;
}
#[rustfmt_skip]
#[rustfmt::skip]
fn qux(a: dadsfa, // Comment 1
b: sdfasdfa, // Comment 2
c: dsfdsafa) // Comment 3
@ -78,7 +78,7 @@ pub trait GraphWalk<'a, N, E> {
/// A Doc comment
#[AnAttribute]
pub struct Foo {
#[rustfmt_skip]
#[rustfmt::skip]
f : SomeType, // Comment beside a field
f : SomeType, // Comment beside a field
// Comment on a field
@ -126,7 +126,7 @@ fn deconstruct(foo: Bar) -> (SocketAddr, Method, Headers,
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA) {
}
#[rustfmt_skip]
#[rustfmt::skip]
mod a{
fn foo(x: T) {
let x: T = dfasdf;

View File

@ -4,7 +4,7 @@
/// A Doc comment
#[AnAttribute]
pub struct Foo {
#[rustfmt_skip]
#[rustfmt::skip]
f : SomeType, // Comment beside a field
f: SomeType, // Comment beside a field
// Comment on a field
@ -139,7 +139,7 @@ struct Palette { /// A map of indices in the palette to a count of pixels in app
// when the field had attributes
struct FieldsWithAttributes {
// Pre Comment
#[rustfmt_skip] pub host:String, // Post comment BBBBBBBBBBBBBB BBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBBB BBBBBBBBBBB
#[rustfmt::skip] pub host:String, // Post comment BBBBBBBBBBBBBB BBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBBB BBBBBBBBBBB
//Another pre comment
#[attr1]
#[attr2] pub id: usize // CCCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCC CCCCCCCCCCCC

View File

@ -89,7 +89,7 @@ trait FooBar <A, B, C>=
trait AAAAAAAAAAAAAAAAAA = BBBBBBBBBBBBBBBBBBB + CCCCCCCCCCCCCCCCCCCCCCCCCCCCC + DDDDDDDDDDDDDDDDDDD;
trait AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA<A, B, C, D, E> = FooBar;
trait AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA<A, B, C, D, E> = FooBar;
#[rustfmt_skip]
#[rustfmt::skip]
trait FooBar = Foo
+ Bar;

View File

@ -4,7 +4,7 @@
/// A Doc comment
#[AnAttribute]
pub union Foo {
#[rustfmt_skip]
#[rustfmt::skip]
f : SomeType, // Comment beside a field
f: SomeType, // Comment beside a field
// Comment on a field
@ -100,7 +100,7 @@ union Palette { /// A map of indices in the palette to a count of pixels in appr
// when the field had attributes
union FieldsWithAttributes {
// Pre Comment
#[rustfmt_skip] pub host:String, // Post comment BBBBBBBBBBBBBB BBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBBB BBBBBBBBBBB
#[rustfmt::skip] pub host:String, // Post comment BBBBBBBBBBBBBB BBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBBB BBBBBBBBBBB
//Another pre comment
#[attr1]
#[attr2] pub id: usize // CCCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCC CCCCCCCCCCCC

View File

@ -171,3 +171,9 @@ struct A {
feature = "this_line_is_101_characters_long_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
)]
pub fn foo() {}
// path attrs
#[clippy::bar]
#[clippy::bar=foo]
#[clippy::bar(a, b, c)]
pub fn foo() {}

View File

@ -47,5 +47,5 @@ fn debug_function() {
#[link_section=".vectors"]
#[no_mangle] // Test this attribute is preserved.
#[cfg_attr(rustfmt, rustfmt_skip)]
#[cfg_attr(rustfmt, rustfmt::skip)]
pub static ISSUE_1284: [i32; 16] = [];

View File

@ -36,7 +36,7 @@ fn main() {
/// A Doc comment
#[AnAttribute]
pub struct Foo {
#[rustfmt_skip]
#[rustfmt::skip]
f : SomeType, // Comment beside a field
f: SomeType, // Comment beside a field
// Comment on a field
@ -171,8 +171,8 @@ struct Palette {
// when the field had attributes
struct FieldsWithAttributes {
// Pre Comment
#[rustfmt_skip] pub host:String, /* Post comment BBBBBBBBBBBBBB BBBBBBBBBBBBBBBB
* BBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBBB BBBBBBBBBBB */
#[rustfmt::skip] pub host:String, /* Post comment BBBBBBBBBBBBBB BBBBBBBBBBBBBBBB
* BBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBBB BBBBBBBBBBB */
// Another pre comment
#[attr1]
#[attr2]

View File

@ -9,7 +9,7 @@ fn main() {
y: y,
#[attr]
z: z,
#[rustfmt_skip]
#[rustfmt::skip]
skipped: skipped,
};
}

View File

@ -9,7 +9,7 @@ fn main() {
y,
#[attr]
z,
#[rustfmt_skip]
#[rustfmt::skip]
skipped: skipped,
};
}

View File

@ -65,7 +65,7 @@ pub enum EnumWithAttributes {
TupleVar(usize, usize, usize), /* AAAA AAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAA
* AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA */
// Pre Comment
#[rustfmt_skip]
#[rustfmt::skip]
SkippedItem(String,String,), // Post-comment
#[another_attr]
#[attr2]

View File

@ -92,7 +92,7 @@ fn inner() {
x
}
#[cfg_attr(rustfmt, rustfmt_skip)]
#[cfg_attr(rustfmt, rustfmt::skip)]
fn foo(a: i32) -> i32 {
// comment
if a > 0 { 1 } else { 2 }

View File

@ -51,7 +51,7 @@ fn foo() {
#[an_attribute]
// Comment after an attribute.
None => 0,
#[rustfmt_skip]
#[rustfmt::skip]
Blurb => { }
};
}
@ -109,7 +109,7 @@ fn matches() {
fn match_skip() {
let _ = match Some(1) {
#[rustfmt_skip]
#[rustfmt::skip]
Some( n ) => n,
None => 1,
};

View File

@ -58,7 +58,7 @@ fn baz<
extern crate foo;
}
#[rustfmt_skip]
#[rustfmt::skip]
fn qux(a: dadsfa, // Comment 1
b: sdfasdfa, // Comment 2
c: dsfdsafa) // Comment 3
@ -103,7 +103,7 @@ pub trait GraphWalk<'a, N, E> {
/// A Doc comment
#[AnAttribute]
pub struct Foo {
#[rustfmt_skip]
#[rustfmt::skip]
f : SomeType, // Comment beside a field
f: SomeType, // Comment beside a field
// Comment on a field
@ -172,7 +172,7 @@ fn deconstruct(
) {
}
#[rustfmt_skip]
#[rustfmt::skip]
mod a{
fn foo(x: T) {
let x: T = dfasdf;

View File

@ -1,10 +1,10 @@
// Test the skip attribute works
#[rustfmt_skip]
#[rustfmt::skip]
fn foo() { badly; formatted; stuff
; }
#[rustfmt_skip]
#[rustfmt::skip]
trait Foo
{
fn foo(
@ -12,13 +12,13 @@ fn foo(
}
impl LateLintPass for UsedUnderscoreBinding {
#[cfg_attr(rustfmt, rustfmt_skip)]
#[cfg_attr(rustfmt, rustfmt::skip)]
fn check_expr() { // comment
}
}
fn issue1346() {
#[cfg_attr(rustfmt, rustfmt_skip)]
#[cfg_attr(rustfmt, rustfmt::skip)]
Box::new(self.inner.call(req).then(move |result| {
match result {
Ok(resp) => Box::new(future::done(Ok(resp))),
@ -32,7 +32,7 @@ fn issue1346() {
fn skip_on_statements() {
// Outside block
#[rustfmt_skip]
#[rustfmt::skip]
{
foo; bar;
// junk
@ -40,13 +40,13 @@ fn skip_on_statements() {
{
// Inside block
#![rustfmt_skip]
#![rustfmt::skip]
foo; bar;
// junk
}
// Semi
#[cfg_attr(rustfmt, rustfmt_skip)]
#[cfg_attr(rustfmt, rustfmt::skip)]
foo(
1, 2, 3, 4,
1, 2,
@ -54,15 +54,15 @@ fn skip_on_statements() {
);
// Local
#[cfg_attr(rustfmt, rustfmt_skip)]
#[cfg_attr(rustfmt, rustfmt::skip)]
let x = foo( a, b , c);
// Item
#[cfg_attr(rustfmt, rustfmt_skip)]
#[cfg_attr(rustfmt, rustfmt::skip)]
use foobar;
// Mac
#[cfg_attr(rustfmt, rustfmt_skip)]
#[cfg_attr(rustfmt, rustfmt::skip)]
vec![
1, 2, 3, 4,
1, 2, 3, 4,
@ -74,12 +74,12 @@ fn skip_on_statements() {
];
// Expr
#[cfg_attr(rustfmt, rustfmt_skip)]
#[cfg_attr(rustfmt, rustfmt::skip)]
foo( a, b , c)
}
// Check that the skip attribute applies to other attributes.
#[rustfmt_skip]
#[rustfmt::skip]
#[cfg
( a , b
)]

View File

@ -1,3 +1,3 @@
#![rustfmt_skip]
#![rustfmt::skip]
use a :: b
;

View File

@ -4,7 +4,7 @@
/// A Doc comment
#[AnAttribute]
pub struct Foo {
#[rustfmt_skip]
#[rustfmt::skip]
f : SomeType, // Comment beside a field
f: SomeType, // Comment beside a field
// Comment on a field
@ -144,8 +144,8 @@ struct Palette {
// when the field had attributes
struct FieldsWithAttributes {
// Pre Comment
#[rustfmt_skip] pub host:String, /* Post comment BBBBBBBBBBBBBB BBBBBBBBBBBBBBBB
* BBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBBB BBBBBBBBBBB */
#[rustfmt::skip] pub host:String, /* Post comment BBBBBBBBBBBBBB BBBBBBBBBBBBBBBB
* BBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBBB BBBBBBBBBBB */
// Another pre comment
#[attr1]
#[attr2]

View File

@ -127,7 +127,7 @@ trait AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
D,
E,
> = FooBar;
#[rustfmt_skip]
#[rustfmt::skip]
trait FooBar = Foo
+ Bar;

View File

@ -4,7 +4,7 @@
/// A Doc comment
#[AnAttribute]
pub union Foo {
#[rustfmt_skip]
#[rustfmt::skip]
f : SomeType, // Comment beside a field
f: SomeType, // Comment beside a field
// Comment on a field
@ -100,8 +100,8 @@ union Palette {
// when the field had attributes
union FieldsWithAttributes {
// Pre Comment
#[rustfmt_skip] pub host:String, /* Post comment BBBBBBBBBBBBBB BBBBBBBBBBBBBBBB
* BBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBBB BBBBBBBBBBB */
#[rustfmt::skip] pub host:String, /* Post comment BBBBBBBBBBBBBB BBBBBBBBBBBBBBBB
* BBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBBB BBBBBBBBBBB */
// Another pre comment
#[attr1]
#[attr2]