fixes for numerous clippy warnings

This commit is contained in:
Marijn Schouten
2025-09-19 14:00:29 +00:00
parent 2f4dfc753f
commit 54b15a66d8
8 changed files with 32 additions and 36 deletions

View File

@@ -206,7 +206,7 @@ impl Callbacks for TimePassesCallbacks {
// time because it will mess up the --print output. See #64339.
//
self.time_passes = (config.opts.prints.is_empty() && config.opts.unstable_opts.time_passes)
.then(|| config.opts.unstable_opts.time_passes_format);
.then_some(config.opts.unstable_opts.time_passes_format);
config.opts.trimmed_def_paths = true;
}
}
@@ -439,8 +439,9 @@ fn make_input(early_dcx: &EarlyDiagCtxt, free_matches: &[String]) -> Option<Inpu
"when UNSTABLE_RUSTDOC_TEST_PATH is set \
UNSTABLE_RUSTDOC_TEST_LINE also needs to be set",
);
let line = isize::from_str_radix(&line, 10)
.expect("UNSTABLE_RUSTDOC_TEST_LINE needs to be an number");
let line = line
.parse::<isize>()
.expect("UNSTABLE_RUSTDOC_TEST_LINE needs to be a number");
FileName::doc_test_source_code(PathBuf::from(path), line)
}
Err(_) => FileName::anon_source_code(&input),
@@ -474,8 +475,7 @@ fn handle_explain(early_dcx: &EarlyDiagCtxt, registry: Registry, code: &str, col
let mut text = String::new();
// Slice off the leading newline and print.
for line in description.lines() {
let indent_level =
line.find(|c: char| !c.is_whitespace()).unwrap_or_else(|| line.len());
let indent_level = line.find(|c: char| !c.is_whitespace()).unwrap_or(line.len());
let dedented_line = &line[indent_level..];
if dedented_line.starts_with("```") {
is_in_code_block = !is_in_code_block;
@@ -547,7 +547,7 @@ fn show_md_content_with_pager(content: &str, color: ColorConfig) {
// The pager failed. Try to print pretty output to stdout.
if let Some((bufwtr, mdbuf)) = &pretty_data
&& bufwtr.print(&mdbuf).is_ok()
&& bufwtr.print(mdbuf).is_ok()
{
return;
}
@@ -598,8 +598,7 @@ fn process_rlink(sess: &Session, compiler: &interface::Compiler) {
fn list_metadata(sess: &Session, metadata_loader: &dyn MetadataLoader) {
match sess.io.input {
Input::File(ref ifile) => {
let path = &(*ifile);
Input::File(ref path) => {
let mut v = Vec::new();
locator::list_file_metadata(
&sess.target,
@@ -833,7 +832,7 @@ fn print_crate_info(
SupportedCrateTypes => {
let supported_crate_types = CRATE_TYPES
.iter()
.filter(|(_, crate_type)| !invalid_output_for_target(&sess, *crate_type))
.filter(|(_, crate_type)| !invalid_output_for_target(sess, *crate_type))
.filter(|(_, crate_type)| *crate_type != CrateType::Sdylib)
.map(|(crate_type_sym, _)| *crate_type_sym)
.collect::<BTreeSet<_>>();
@@ -1434,7 +1433,7 @@ pub fn install_ice_hook(bug_report_url: &'static str, extra_info: fn(&DiagCtxt))
eprintln!();
if let Some(ice_path) = ice_path()
&& let Ok(mut out) = File::options().create(true).append(true).open(&ice_path)
&& let Ok(mut out) = File::options().create(true).append(true).open(ice_path)
{
// The current implementation always returns `Some`.
let location = info.location().unwrap();
@@ -1510,7 +1509,7 @@ fn report_ice(
let file = if let Some(path) = ice_path() {
// Create the ICE dump target file.
match crate::fs::File::options().create(true).append(true).open(&path) {
match crate::fs::File::options().create(true).append(true).open(path) {
Ok(mut file) => {
dcx.emit_note(session_diagnostics::IcePath { path: path.clone() });
if FIRST_PANIC.swap(false, Ordering::SeqCst) {

View File

@@ -14,7 +14,7 @@ macro_rules! safe_println {
}
pub(crate) fn print(args: fmt::Arguments<'_>) {
if let Err(_) = io::stdout().write_fmt(args) {
if io::stdout().write_fmt(args).is_err() {
rustc_errors::FatalError.raise();
}
}