Cargo fmt

This commit is contained in:
Mateusz Mikuła 2019-03-18 12:31:49 +01:00 committed by Mateusz Mikuła
parent 664391c5f8
commit 6cb0605600
3 changed files with 58 additions and 60 deletions

View File

@ -210,27 +210,27 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
if let Some(items) = &attr.meta_item_list() { if let Some(items) = &attr.meta_item_list() {
if let Some(ident) = attr.ident_str() { if let Some(ident) = attr.ident_str() {
match ident { match ident {
"allow" | "warn" | "deny" | "forbid" => { "allow" | "warn" | "deny" | "forbid" => {
check_clippy_lint_names(cx, items); check_clippy_lint_names(cx, items);
}, },
_ => {}, _ => {},
} }
if items.is_empty() || !attr.check_name("deprecated") { if items.is_empty() || !attr.check_name("deprecated") {
return; return;
} }
for item in items { for item in items {
if_chain! { if_chain! {
if let NestedMetaItem::MetaItem(mi) = &item; if let NestedMetaItem::MetaItem(mi) = &item;
if let MetaItemKind::NameValue(lit) = &mi.node; if let MetaItemKind::NameValue(lit) = &mi.node;
if mi.check_name("since"); if mi.check_name("since");
then { then {
check_semver(cx, item.span(), lit); check_semver(cx, item.span(), lit);
}
} }
} }
} }
} }
} }
}
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
if is_relevant_item(cx.tcx, item) { if is_relevant_item(cx.tcx, item) {
@ -244,54 +244,54 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
if let Some(lint_list) = &attr.meta_item_list() { if let Some(lint_list) = &attr.meta_item_list() {
if let Some(ident) = attr.ident_str() { if let Some(ident) = attr.ident_str() {
match ident { match ident {
"allow" | "warn" | "deny" | "forbid" => { "allow" | "warn" | "deny" | "forbid" => {
// whitelist `unused_imports` and `deprecated` for `use` items // whitelist `unused_imports` and `deprecated` for `use` items
// and `unused_imports` for `extern crate` items with `macro_use` // and `unused_imports` for `extern crate` items with `macro_use`
for lint in lint_list { for lint in lint_list {
match item.node { match item.node {
ItemKind::Use(..) => { ItemKind::Use(..) => {
if is_word(lint, "unused_imports") || is_word(lint, "deprecated") { if is_word(lint, "unused_imports") || is_word(lint, "deprecated") {
return; return;
} }
},
ItemKind::ExternCrate(..) => {
if is_word(lint, "unused_imports") && skip_unused_imports {
return;
}
if is_word(lint, "unused_extern_crates") {
return;
}
},
_ => {},
}
}
let line_span = last_line_of_span(cx, attr.span);
if let Some(mut sugg) = snippet_opt(cx, line_span) {
if sugg.contains("#[") {
span_lint_and_then(
cx,
USELESS_ATTRIBUTE,
line_span,
"useless lint attribute",
|db| {
sugg = sugg.replacen("#[", "#![", 1);
db.span_suggestion(
line_span,
"if you just forgot a `!`, use",
sugg,
Applicability::MachineApplicable,
);
}, },
); ItemKind::ExternCrate(..) => {
if is_word(lint, "unused_imports") && skip_unused_imports {
return;
}
if is_word(lint, "unused_extern_crates") {
return;
}
},
_ => {},
}
} }
} let line_span = last_line_of_span(cx, attr.span);
},
_ => {}, if let Some(mut sugg) = snippet_opt(cx, line_span) {
if sugg.contains("#[") {
span_lint_and_then(
cx,
USELESS_ATTRIBUTE,
line_span,
"useless lint attribute",
|db| {
sugg = sugg.replacen("#[", "#![", 1);
db.span_suggestion(
line_span,
"if you just forgot a `!`, use",
sugg,
Applicability::MachineApplicable,
);
},
);
}
}
},
_ => {},
}
} }
} }
} }
}
}, },
_ => {}, _ => {},
} }
@ -527,7 +527,7 @@ impl EarlyLintPass for CfgAttrPass {
if feature_item.check_name("rustfmt"); if feature_item.check_name("rustfmt");
// check for `rustfmt_skip` and `rustfmt::skip` // check for `rustfmt_skip` and `rustfmt::skip`
if let Some(skip_item) = &items[1].meta_item(); if let Some(skip_item) = &items[1].meta_item();
if skip_item.check_name("rustfmt_skip") || if skip_item.check_name("rustfmt_skip") ||
skip_item.path.segments.last().expect("empty path in attribute").ident.name == "skip"; skip_item.path.segments.last().expect("empty path in attribute").ident.name == "skip";
// Only lint outer attributes, because custom inner attributes are unstable // Only lint outer attributes, because custom inner attributes are unstable
// Tracking issue: https://github.com/rust-lang/rust/issues/54726 // Tracking issue: https://github.com/rust-lang/rust/issues/54726

View File

@ -11,9 +11,7 @@ use syntax::{ast, source_map};
use toml; use toml;
/// Gets the configuration file from arguments. /// Gets the configuration file from arguments.
pub fn file_from_args( pub fn file_from_args(args: &[ast::NestedMetaItem]) -> Result<Option<path::PathBuf>, (&'static str, source_map::Span)> {
args: &[ast::NestedMetaItem],
) -> Result<Option<path::PathBuf>, (&'static str, source_map::Span)> {
for arg in args.iter().filter_map(syntax::ast::NestedMetaItem::meta_item) { for arg in args.iter().filter_map(syntax::ast::NestedMetaItem::meta_item) {
if arg.check_name("conf_file") { if arg.check_name("conf_file") {
return match arg.node { return match arg.node {

View File

@ -146,7 +146,7 @@ impl<'tcx> Printer<'tcx, 'tcx> for AbsolutePathPrinter<'_, 'tcx> {
return self.print_def_path(def.did, substs); return self.print_def_path(def.did, substs);
} }
} }
// This shouldn't ever be needed, but just in case: // This shouldn't ever be needed, but just in case:
Ok(vec![match trait_ref { Ok(vec![match trait_ref {
Some(trait_ref) => Symbol::intern(&format!("{:?}", trait_ref)).as_str(), Some(trait_ref) => Symbol::intern(&format!("{:?}", trait_ref)).as_str(),