Skip to content

Commit 9e53b65

Browse files
committed
Auto merge of #10591 - beetrees:warnings-not-eprintln, r=flip1995
Show multiple clippy.toml warnings with `sess.warn` instead of `eprintln!` Use `sess.warn` to display the multiple clippy.toml warning instead of `eprintln!`. changelog: none
2 parents e903af5 + afdfbf8 commit 9e53b65

File tree

4 files changed

+24
-17
lines changed

4 files changed

+24
-17
lines changed

clippy_lints/src/lib.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -348,13 +348,17 @@ pub fn register_pre_expansion_lints(store: &mut rustc_lint::LintStore, sess: &Se
348348
}
349349

350350
#[doc(hidden)]
351-
pub fn read_conf(sess: &Session, path: &io::Result<Option<PathBuf>>) -> Conf {
351+
pub fn read_conf(sess: &Session, path: &io::Result<(Option<PathBuf>, Vec<String>)>) -> Conf {
352+
if let Ok((_, warnings)) = path {
353+
for warning in warnings {
354+
sess.warn(warning);
355+
}
356+
}
352357
let file_name = match path {
353-
Ok(Some(path)) => path,
354-
Ok(None) => return Conf::default(),
358+
Ok((Some(path), _)) => path,
359+
Ok((None, _)) => return Conf::default(),
355360
Err(error) => {
356-
sess.struct_err(format!("error finding Clippy's configuration file: {error}"))
357-
.emit();
361+
sess.err(format!("error finding Clippy's configuration file: {error}"));
358362
return Conf::default();
359363
},
360364
};

clippy_lints/src/utils/conf.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ define_Conf! {
470470
/// # Errors
471471
///
472472
/// Returns any unexpected filesystem error encountered when searching for the config file
473-
pub fn lookup_conf_file() -> io::Result<Option<PathBuf>> {
473+
pub fn lookup_conf_file() -> io::Result<(Option<PathBuf>, Vec<String>)> {
474474
/// Possible filename to search for.
475475
const CONFIG_FILE_NAMES: [&str; 2] = [".clippy.toml", "clippy.toml"];
476476

@@ -481,6 +481,7 @@ pub fn lookup_conf_file() -> io::Result<Option<PathBuf>> {
481481
.map_or_else(|| PathBuf::from("."), PathBuf::from);
482482

483483
let mut found_config: Option<PathBuf> = None;
484+
let mut warnings = vec![];
484485

485486
loop {
486487
for config_file_name in &CONFIG_FILE_NAMES {
@@ -491,12 +492,12 @@ pub fn lookup_conf_file() -> io::Result<Option<PathBuf>> {
491492
Ok(md) if md.is_dir() => {},
492493
Ok(_) => {
493494
// warn if we happen to find two config files #8323
494-
if let Some(ref found_config_) = found_config {
495-
eprintln!(
496-
"Using config file `{}`\nWarning: `{}` will be ignored.",
497-
found_config_.display(),
498-
config_file.display(),
499-
);
495+
if let Some(ref found_config) = found_config {
496+
warnings.push(format!(
497+
"using config file `{}`, `{}` will be ignored",
498+
found_config.display(),
499+
config_file.display()
500+
));
500501
} else {
501502
found_config = Some(config_file);
502503
}
@@ -506,12 +507,12 @@ pub fn lookup_conf_file() -> io::Result<Option<PathBuf>> {
506507
}
507508

508509
if found_config.is_some() {
509-
return Ok(found_config);
510+
return Ok((found_config, warnings));
510511
}
511512

512513
// If the current directory has no parent, we're done searching.
513514
if !current.pop() {
514-
return Ok(None);
515+
return Ok((None, warnings));
515516
}
516517
}
517518
}

src/driver.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl rustc_driver::Callbacks for ClippyCallbacks {
130130
#[allow(rustc::bad_opt_access)]
131131
fn config(&mut self, config: &mut interface::Config) {
132132
let conf_path = clippy_lints::lookup_conf_file();
133-
let conf_path_string = if let Ok(Some(path)) = &conf_path {
133+
let conf_path_string = if let Ok((Some(path), _)) = &conf_path {
134134
path.to_str().map(String::from)
135135
} else {
136136
None
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
Using config file `$SRC_DIR/.clippy.toml`
2-
Warning: `$SRC_DIR/clippy.toml` will be ignored.
1+
warning: using config file `$SRC_DIR/.clippy.toml`, `$SRC_DIR/clippy.toml` will be ignored
2+
3+
warning: 1 warning emitted
4+

0 commit comments

Comments
 (0)