diff --git a/.travis.yml b/.travis.yml index c0fefbbbb28..8eef98030de 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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: - | diff --git a/Configurations.md b/Configurations.md index 07a336d93fa..9c0d9481b50 100644 --- a/Configurations.md +++ b/Configurations.md @@ -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"); diff --git a/README.md b/README.md index 6dc437fd27f..b5a4bc7bbc5 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/rustfmt.toml b/rustfmt.toml index e69de29bb2d..9b935b0a287 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -0,0 +1,2 @@ +error_on_line_overflow = true +error_on_unformatted = true diff --git a/src/attr.rs b/src/attr.rs index 894b99815b4..e754144a727 100644 --- a/src/attr.rs +++ b/src/attr.rs @@ -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 { 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 { // 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 { }; 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 { // 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) } }) } diff --git a/src/comment.rs b/src/comment.rs index 0b6c818e59e..f850c0bba44 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -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); diff --git a/src/lib.rs b/src/lib.rs index c50c45fbd36..46cb952a0cb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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>, + file_error_map: Rc>>>, } 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) { + 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>, ) -> 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( 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, + F: FnMut(&FileName, &mut String, &[(usize, usize)], &FormatReport) -> Result, { let mut result = FileMap::new(); // diff mode: check if any files are differing @@ -360,7 +391,8 @@ fn format_ast( .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( ::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( } }; - 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 = 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( )); 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()); } diff --git a/src/rewrite.rs b/src/rewrite.rs index 7eb8c18bbe6..7c7bb060fd3 100644 --- a/src/rewrite.rs +++ b/src/rewrite.rs @@ -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, pub snippet_provider: &'a SnippetProvider<'a>, + pub report: FormatReport, } impl<'a> RewriteContext<'a> { diff --git a/src/test/mod.rs b/src/test/mod.rs index 4de69296e9f..b538519ec0b 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -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 diff --git a/src/utils.rs b/src/utils.rs index ca8a7ad7814..991ebf16bf2 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -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]) } diff --git a/src/visitor.rs b/src/visitor.rs index 7f042b1a11b..ec1890035a7 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -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(), } } } diff --git a/tests/config/skip_children.toml b/tests/config/skip_children.toml index 49f37a88dfb..f52930d50b6 100644 --- a/tests/config/skip_children.toml +++ b/tests/config/skip_children.toml @@ -1 +1 @@ -skip_children = true \ No newline at end of file +skip_children = true diff --git a/tests/source/attrib.rs b/tests/source/attrib.rs index d5c244a9bf8..409e5f5a4a9 100644 --- a/tests/source/attrib.rs +++ b/tests/source/attrib.rs @@ -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() {} + diff --git a/tests/source/comment4.rs b/tests/source/comment4.rs index ff1445378d7..f53a8a4a1fe 100644 --- a/tests/source/comment4.rs +++ b/tests/source/comment4.rs @@ -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] = []; diff --git a/tests/source/configs/struct_field_align_threshold/20.rs b/tests/source/configs/struct_field_align_threshold/20.rs index e68340b027d..229817e1405 100644 --- a/tests/source/configs/struct_field_align_threshold/20.rs +++ b/tests/source/configs/struct_field_align_threshold/20.rs @@ -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 diff --git a/tests/source/configs/use_field_init_shorthand/false.rs b/tests/source/configs/use_field_init_shorthand/false.rs index 16ce740f1b9..4c2eb1de179 100644 --- a/tests/source/configs/use_field_init_shorthand/false.rs +++ b/tests/source/configs/use_field_init_shorthand/false.rs @@ -13,7 +13,7 @@ fn main() { y: y, #[attr] z: z, - #[rustfmt_skip] + #[rustfmt::skip] skipped: skipped, }; } diff --git a/tests/source/configs/use_field_init_shorthand/true.rs b/tests/source/configs/use_field_init_shorthand/true.rs index 1e36c6cff35..dcde28d74e0 100644 --- a/tests/source/configs/use_field_init_shorthand/true.rs +++ b/tests/source/configs/use_field_init_shorthand/true.rs @@ -13,7 +13,7 @@ fn main() { y: y, #[attr] z: z, - #[rustfmt_skip] + #[rustfmt::skip] skipped: skipped, }; } diff --git a/tests/source/enum.rs b/tests/source/enum.rs index 64e15110609..654fc3a836d 100644 --- a/tests/source/enum.rs +++ b/tests/source/enum.rs @@ -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] diff --git a/tests/source/issue-1124.rs b/tests/source/issue-1124.rs index 69aa1bb1c59..5c5eb369161 100644 --- a/tests/source/issue-1124.rs +++ b/tests/source/issue-1124.rs @@ -13,4 +13,4 @@ use x; -use a; \ No newline at end of file +use a; diff --git a/tests/source/match.rs b/tests/source/match.rs index 31034f49402..d1664ca9f37 100644 --- a/tests/source/match.rs +++ b/tests/source/match.rs @@ -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, }; diff --git a/tests/source/multiple.rs b/tests/source/multiple.rs index 68cfacfcb4b..c26df03edda 100644 --- a/tests/source/multiple.rs +++ b/tests/source/multiple.rs @@ -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; diff --git a/tests/source/structs.rs b/tests/source/structs.rs index 25070aef34c..56471f1d7e4 100644 --- a/tests/source/structs.rs +++ b/tests/source/structs.rs @@ -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 diff --git a/tests/source/trait.rs b/tests/source/trait.rs index b3cf4dae721..9f0c73694bf 100644 --- a/tests/source/trait.rs +++ b/tests/source/trait.rs @@ -89,7 +89,7 @@ trait FooBar = trait AAAAAAAAAAAAAAAAAA = BBBBBBBBBBBBBBBBBBB + CCCCCCCCCCCCCCCCCCCCCCCCCCCCC + DDDDDDDDDDDDDDDDDDD; trait AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA = FooBar; trait AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA = FooBar; -#[rustfmt_skip] +#[rustfmt::skip] trait FooBar = Foo + Bar; diff --git a/tests/source/unions.rs b/tests/source/unions.rs index fc2908e2d9e..730ba980abb 100644 --- a/tests/source/unions.rs +++ b/tests/source/unions.rs @@ -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 diff --git a/tests/target/attrib.rs b/tests/target/attrib.rs index 45dc4ea8ba9..b0b8ea89f82 100644 --- a/tests/target/attrib.rs +++ b/tests/target/attrib.rs @@ -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() {} diff --git a/tests/target/comment4.rs b/tests/target/comment4.rs index e07abf74a81..e2ef7de978f 100644 --- a/tests/target/comment4.rs +++ b/tests/target/comment4.rs @@ -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] = []; diff --git a/tests/target/configs/struct_field_align_threshold/20.rs b/tests/target/configs/struct_field_align_threshold/20.rs index f6ee4ed1f0a..f952775f5f2 100644 --- a/tests/target/configs/struct_field_align_threshold/20.rs +++ b/tests/target/configs/struct_field_align_threshold/20.rs @@ -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] diff --git a/tests/target/configs/use_field_init_shorthand/false.rs b/tests/target/configs/use_field_init_shorthand/false.rs index dcebe0b6f1d..74330446886 100644 --- a/tests/target/configs/use_field_init_shorthand/false.rs +++ b/tests/target/configs/use_field_init_shorthand/false.rs @@ -9,7 +9,7 @@ fn main() { y: y, #[attr] z: z, - #[rustfmt_skip] + #[rustfmt::skip] skipped: skipped, }; } diff --git a/tests/target/configs/use_field_init_shorthand/true.rs b/tests/target/configs/use_field_init_shorthand/true.rs index ad78093ee8e..8b80e81534b 100644 --- a/tests/target/configs/use_field_init_shorthand/true.rs +++ b/tests/target/configs/use_field_init_shorthand/true.rs @@ -9,7 +9,7 @@ fn main() { y, #[attr] z, - #[rustfmt_skip] + #[rustfmt::skip] skipped: skipped, }; } diff --git a/tests/target/enum.rs b/tests/target/enum.rs index e429e45287e..b19b6997826 100644 --- a/tests/target/enum.rs +++ b/tests/target/enum.rs @@ -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] diff --git a/tests/target/fn.rs b/tests/target/fn.rs index b78a8b5b21e..66a6e9082de 100644 --- a/tests/target/fn.rs +++ b/tests/target/fn.rs @@ -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 } diff --git a/tests/target/match.rs b/tests/target/match.rs index fe565f4c154..7ed49c61f1d 100644 --- a/tests/target/match.rs +++ b/tests/target/match.rs @@ -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, }; diff --git a/tests/target/multiple.rs b/tests/target/multiple.rs index 446b4357de3..832567fdf7e 100644 --- a/tests/target/multiple.rs +++ b/tests/target/multiple.rs @@ -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; diff --git a/tests/target/skip.rs b/tests/target/skip.rs index 11d1d69e91a..6c9737a3377 100644 --- a/tests/target/skip.rs +++ b/tests/target/skip.rs @@ -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 )] diff --git a/tests/target/skip_mod.rs b/tests/target/skip_mod.rs index 38ece8f070d..d770ab349f4 100644 --- a/tests/target/skip_mod.rs +++ b/tests/target/skip_mod.rs @@ -1,3 +1,3 @@ -#![rustfmt_skip] +#![rustfmt::skip] use a :: b ; diff --git a/tests/target/structs.rs b/tests/target/structs.rs index 7f9ef1e6164..368650bb6a8 100644 --- a/tests/target/structs.rs +++ b/tests/target/structs.rs @@ -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] diff --git a/tests/target/trait.rs b/tests/target/trait.rs index ed7d3bc56f1..a6bc2d89689 100644 --- a/tests/target/trait.rs +++ b/tests/target/trait.rs @@ -127,7 +127,7 @@ trait AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA D, E, > = FooBar; -#[rustfmt_skip] +#[rustfmt::skip] trait FooBar = Foo + Bar; diff --git a/tests/target/unions.rs b/tests/target/unions.rs index 6de682297af..386ceb3836c 100644 --- a/tests/target/unions.rs +++ b/tests/target/unions.rs @@ -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]