Merge pull request #3056 from mikerite/fix-2927

Fix #2927
This commit is contained in:
Oliver Schneider 2018-08-16 08:20:51 +02:00 committed by GitHub
commit 07c2e61436
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 37 additions and 46 deletions

View file

@ -173,18 +173,22 @@ pub mod write;
pub mod zero_div_zero;
// end lints modules, do not remove this comment, its used in `update_lints`
use crate::utils::conf::Conf;
mod reexport {
crate use syntax::ast::{Name, NodeId};
}
pub fn register_pre_expansion_lints(session: &rustc::session::Session, store: &mut rustc::lint::LintStore) {
pub fn register_pre_expansion_lints(session: &rustc::session::Session, store: &mut rustc::lint::LintStore, conf: &Conf) {
store.register_pre_expansion_pass(Some(session), box write::Pass);
store.register_pre_expansion_pass(Some(session), box redundant_field_names::RedundantFieldNames);
store.register_pre_expansion_pass(Some(session), box non_expressive_names::NonExpressiveNames {
single_char_binding_names_threshold: conf.single_char_binding_names_threshold,
});
}
#[rustfmt::skip]
pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>) {
let conf = match utils::conf::file_from_args(reg.args()) {
pub fn read_conf(reg: &rustc_plugin::Registry<'_>) -> Conf {
match utils::conf::file_from_args(reg.args()) {
Ok(file_name) => {
// if the user specified a file, it must exist, otherwise default to `clippy.toml` but
// do not require the file to exist
@ -226,8 +230,11 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>) {
.emit();
toml::from_str("").expect("we never error on empty config files")
}
};
}
}
#[rustfmt::skip]
pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
let mut store = reg.sess.lint_store.borrow_mut();
store.register_removed(
"should_assert_eq",
@ -329,9 +336,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>) {
reg.register_late_lint_pass(box derive::Derive);
reg.register_late_lint_pass(box types::CharLitAsU8);
reg.register_late_lint_pass(box vec::Pass);
reg.register_early_lint_pass(box non_expressive_names::NonExpressiveNames {
single_char_binding_names_threshold: conf.single_char_binding_names_threshold,
});
reg.register_late_lint_pass(box drop_forget_ref::Pass);
reg.register_late_lint_pass(box empty_enum::EmptyEnum);
reg.register_late_lint_pass(box types::AbsurdExtremeComparisons);
@ -347,9 +351,9 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>) {
reg.register_late_lint_pass(box overflow_check_conditional::OverflowCheckConditional);
reg.register_late_lint_pass(box unused_label::UnusedLabel);
reg.register_late_lint_pass(box new_without_default::NewWithoutDefault);
reg.register_late_lint_pass(box blacklisted_name::BlackListedName::new(conf.blacklisted_names));
reg.register_late_lint_pass(box blacklisted_name::BlackListedName::new(conf.blacklisted_names.clone()));
reg.register_late_lint_pass(box functions::Functions::new(conf.too_many_arguments_threshold));
reg.register_early_lint_pass(box doc::Doc::new(conf.doc_valid_idents));
reg.register_early_lint_pass(box doc::Doc::new(conf.doc_valid_idents.clone()));
reg.register_late_lint_pass(box neg_multiply::NegMultiply);
reg.register_early_lint_pass(box unsafe_removed_from_name::UnsafeNameRemoval);
reg.register_late_lint_pass(box mem_forget::MemForget);

View file

@ -5,7 +5,7 @@ use syntax::symbol::LocalInternedString;
use syntax::ast::*;
use syntax::attr;
use syntax::visit::{walk_block, walk_expr, walk_pat, Visitor};
use crate::utils::{in_macro, span_lint, span_lint_and_then};
use crate::utils::{span_lint, span_lint_and_then};
/// **What it does:** Checks for names that are very similar and thus confusing.
///
@ -147,9 +147,6 @@ impl<'a, 'tcx, 'b> SimilarNamesNameVisitor<'a, 'tcx, 'b> {
}
}
fn check_name(&mut self, span: Span, name: Name) {
if in_macro(span) {
return;
}
let interned_name = name.as_str();
if interned_name.chars().any(char::is_uppercase) {
return;
@ -309,6 +306,9 @@ impl<'a, 'tcx> Visitor<'tcx> for SimilarNamesLocalVisitor<'a, 'tcx> {
fn visit_item(&mut self, _: &Item) {
// do not recurse into inner items
}
fn visit_mac(&mut self, _mac: &Mac) {
// do not check macs
}
}
impl EarlyLintPass for NonExpressiveNames {
@ -323,7 +323,6 @@ impl EarlyLintPass for NonExpressiveNames {
do_check(self, cx, &item.attrs, &sig.decl, blk);
}
}
}
fn do_check(lint: &mut NonExpressiveNames, cx: &EarlyContext<'_>, attrs: &[Attribute], decl: &FnDecl, blk: &Block) {

View file

@ -96,7 +96,9 @@ pub fn main() {
.span,
);
registry.args_hidden = Some(Vec::new());
clippy_lints::register_plugins(&mut registry);
let conf = clippy_lints::read_conf(&registry);
clippy_lints::register_plugins(&mut registry, &conf);
let rustc_plugin::registry::Registry {
early_lint_passes,
@ -118,7 +120,7 @@ pub fn main() {
for (name, to) in lint_groups {
ls.register_group(Some(sess), true, name, to);
}
clippy_lints::register_pre_expansion_lints(sess, &mut ls);
clippy_lints::register_pre_expansion_lints(sess, &mut ls, &conf);
sess.plugin_llvm_passes.borrow_mut().extend(llvm_passes);
sess.plugin_attributes.borrow_mut().extend(attributes);

View file

@ -25,7 +25,8 @@ pub fn plugin_registrar(reg: &mut Registry<'_>) {
}
});
clippy_lints::register_plugins(reg);
let conf = clippy_lints::read_conf(reg);
clippy_lints::register_plugins(reg, &conf);
}
// only exists to let the dogfood integration test works.

View file

@ -1,7 +1,7 @@
#![warn(clippy,similar_names)]
#![allow(unused)]
#![allow(unused, println_empty_string)]
struct Foo {
@ -142,6 +142,11 @@ fn underscores_and_numbers() {
let _1_ok= 1;
}
fn issue2927() {
let args = 1;
format!("{:?}", 2);
}
struct Bar;
impl Bar {

View file

@ -1,23 +1,3 @@
error: using `println!("")`
--> $DIR/non_expressive_names.rs:60:14
|
60 | _ => println!(""),
| ^^^^^^^^^^^^ help: replace it with: `println!()`
|
= note: `-D println-empty-string` implied by `-D warnings`
error: using `println!("")`
--> $DIR/non_expressive_names.rs:128:18
|
128 | 1 => println!(""),
| ^^^^^^^^^^^^ help: replace it with: `println!()`
error: using `println!("")`
--> $DIR/non_expressive_names.rs:132:18
|
132 | 1 => println!(""),
| ^^^^^^^^^^^^ help: replace it with: `println!()`
error: binding's name is too similar to existing binding
--> $DIR/non_expressive_names.rs:18:9
|
@ -170,22 +150,22 @@ error: consider choosing a more descriptive name
| ^^^^^^^
error: consider choosing a more descriptive name
--> $DIR/non_expressive_names.rs:149:13
--> $DIR/non_expressive_names.rs:154:13
|
149 | let _1 = 1;
154 | let _1 = 1;
| ^^
error: consider choosing a more descriptive name
--> $DIR/non_expressive_names.rs:150:13
--> $DIR/non_expressive_names.rs:155:13
|
150 | let ____1 = 1;
155 | let ____1 = 1;
| ^^^^^
error: consider choosing a more descriptive name
--> $DIR/non_expressive_names.rs:151:13
--> $DIR/non_expressive_names.rs:156:13
|
151 | let __1___2 = 12;
156 | let __1___2 = 12;
| ^^^^^^^
error: aborting due to 20 previous errors
error: aborting due to 17 previous errors