Skip to content

Commit a55912c

Browse files
committed
Auto merge of #7141 - camsteffen:conf-file, r=flip1995
Remove leftover plugin conf_file code changelog: none Removes dead code that used to support the following syntax: ```rust #![plugin(clippy(conf_file="path/to/clippy's/configuration"))] ``` RLS (and others?) will need to remove the `&[]` from `clippy_lints::read_conf(&[], sess)`. r? `@flip1995`
2 parents ce37099 + 32351d6 commit a55912c

File tree

3 files changed

+31
-69
lines changed

3 files changed

+31
-69
lines changed

clippy_lints/src/lib.rs

+30-45
Original file line numberDiff line numberDiff line change
@@ -399,56 +399,41 @@ pub fn register_pre_expansion_lints(store: &mut rustc_lint::LintStore) {
399399
}
400400

401401
#[doc(hidden)]
402-
pub fn read_conf(args: &[rustc_ast::NestedMetaItem], sess: &Session) -> Conf {
402+
pub fn read_conf(sess: &Session) -> Conf {
403403
use std::path::Path;
404-
match utils::conf::file_from_args(args) {
405-
Ok(file_name) => {
406-
// if the user specified a file, it must exist, otherwise default to `clippy.toml` but
407-
// do not require the file to exist
408-
let file_name = match file_name {
409-
Some(file_name) => file_name,
410-
None => match utils::conf::lookup_conf_file() {
411-
Ok(Some(path)) => path,
412-
Ok(None) => return Conf::default(),
413-
Err(error) => {
414-
sess.struct_err(&format!("error finding Clippy's configuration file: {}", error))
415-
.emit();
416-
return Conf::default();
417-
},
418-
},
419-
};
420-
421-
let file_name = if file_name.is_relative() {
422-
sess.local_crate_source_file
423-
.as_deref()
424-
.and_then(Path::parent)
425-
.unwrap_or_else(|| Path::new(""))
426-
.join(file_name)
427-
} else {
428-
file_name
429-
};
404+
let file_name = match utils::conf::lookup_conf_file() {
405+
Ok(Some(path)) => path,
406+
Ok(None) => return Conf::default(),
407+
Err(error) => {
408+
sess.struct_err(&format!("error finding Clippy's configuration file: {}", error))
409+
.emit();
410+
return Conf::default();
411+
},
412+
};
430413

431-
let (conf, errors) = utils::conf::read(&file_name);
414+
let file_name = if file_name.is_relative() {
415+
sess.local_crate_source_file
416+
.as_deref()
417+
.and_then(Path::parent)
418+
.unwrap_or_else(|| Path::new(""))
419+
.join(file_name)
420+
} else {
421+
file_name
422+
};
432423

433-
// all conf errors are non-fatal, we just use the default conf in case of error
434-
for error in errors {
435-
sess.struct_err(&format!(
436-
"error reading Clippy's configuration file `{}`: {}",
437-
file_name.display(),
438-
error
439-
))
440-
.emit();
441-
}
424+
let (conf, errors) = utils::conf::read(&file_name);
442425

443-
conf
444-
},
445-
Err((err, span)) => {
446-
sess.struct_span_err(span, err)
447-
.span_note(span, "Clippy will use default configuration")
448-
.emit();
449-
Conf::default()
450-
},
426+
// all conf errors are non-fatal, we just use the default conf in case of error
427+
for error in errors {
428+
sess.struct_err(&format!(
429+
"error reading Clippy's configuration file `{}`: {}",
430+
file_name.display(),
431+
error
432+
))
433+
.emit();
451434
}
435+
436+
conf
452437
}
453438

454439
/// Register all lints and lint groups with the rustc plugin registry

clippy_lints/src/utils/conf.rs

-23
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,11 @@
22
33
#![deny(clippy::missing_docs_in_private_items)]
44

5-
use rustc_ast::ast::{LitKind, MetaItemKind, NestedMetaItem};
6-
use rustc_span::source_map;
7-
use source_map::Span;
85
use std::lazy::SyncLazy;
96
use std::path::{Path, PathBuf};
107
use std::sync::Mutex;
118
use std::{env, fmt, fs, io};
129

13-
/// Gets the configuration file from arguments.
14-
pub fn file_from_args(args: &[NestedMetaItem]) -> Result<Option<PathBuf>, (&'static str, Span)> {
15-
for arg in args.iter().filter_map(NestedMetaItem::meta_item) {
16-
if arg.has_name(sym!(conf_file)) {
17-
return match arg.kind {
18-
MetaItemKind::Word | MetaItemKind::List(_) => Err(("`conf_file` must be a named value", arg.span)),
19-
MetaItemKind::NameValue(ref value) => {
20-
if let LitKind::Str(ref file, _) = value.kind {
21-
Ok(Some(file.to_string().into()))
22-
} else {
23-
Err(("`conf_file` value must be a string", value.span))
24-
}
25-
},
26-
};
27-
}
28-
}
29-
30-
Ok(None)
31-
}
32-
3310
/// Error from reading a configuration file.
3411
#[derive(Debug)]
3512
pub enum Error {

src/driver.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl rustc_driver::Callbacks for ClippyCallbacks {
106106
(previous)(sess, lint_store);
107107
}
108108

109-
let conf = clippy_lints::read_conf(&[], sess);
109+
let conf = clippy_lints::read_conf(sess);
110110
clippy_lints::register_plugins(lint_store, sess, &conf);
111111
clippy_lints::register_pre_expansion_lints(lint_store);
112112
clippy_lints::register_renamed(lint_store);

0 commit comments

Comments
 (0)