Skip to content

Commit 0b1ae20

Browse files
committed
Fix dogfood tests by adding type annotations
1 parent 2d4d39d commit 0b1ae20

File tree

9 files changed

+27
-26
lines changed

9 files changed

+27
-26
lines changed

clippy_dev/src/new_lint.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::clippy_project_root;
22
use indoc::{formatdoc, writedoc};
3+
use std::fmt;
34
use std::fmt::Write as _;
45
use std::fs::{self, OpenOptions};
56
use std::io::prelude::*;
@@ -256,7 +257,7 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
256257
)
257258
});
258259

259-
let _ = write!(result, "{}", get_lint_declaration(&name_upper, category));
260+
let _: fmt::Result = write!(result, "{}", get_lint_declaration(&name_upper, category));
260261

261262
result.push_str(&if enable_msrv {
262263
formatdoc!(
@@ -353,7 +354,7 @@ fn create_lint_for_ty(lint: &LintData<'_>, enable_msrv: bool, ty: &str) -> io::R
353354
let mut lint_file_contents = String::new();
354355

355356
if enable_msrv {
356-
let _ = writedoc!(
357+
let _: fmt::Result = writedoc!(
357358
lint_file_contents,
358359
r#"
359360
use clippy_utils::msrvs::{{self, Msrv}};
@@ -373,7 +374,7 @@ fn create_lint_for_ty(lint: &LintData<'_>, enable_msrv: bool, ty: &str) -> io::R
373374
name_upper = name_upper,
374375
);
375376
} else {
376-
let _ = writedoc!(
377+
let _: fmt::Result = writedoc!(
377378
lint_file_contents,
378379
r#"
379380
use rustc_lint::{{{context_import}, LintContext}};
@@ -521,7 +522,7 @@ fn setup_mod_file(path: &Path, lint: &LintData<'_>) -> io::Result<&'static str>
521522
.chain(std::iter::once(&*lint_name_upper))
522523
.filter(|s| !s.is_empty())
523524
{
524-
let _ = write!(new_arr_content, "\n {ident},");
525+
let _: fmt::Result = write!(new_arr_content, "\n {ident},");
525526
}
526527
new_arr_content.push('\n');
527528

clippy_dev/src/update_lints.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use itertools::Itertools;
55
use rustc_lexer::{tokenize, unescape, LiteralKind, TokenKind};
66
use std::collections::{HashMap, HashSet};
77
use std::ffi::OsStr;
8-
use std::fmt::Write;
8+
use std::fmt::{self, Write};
99
use std::fs::{self, OpenOptions};
1010
use std::io::{self, Read, Seek, SeekFrom, Write as _};
1111
use std::ops::Range;
@@ -691,7 +691,7 @@ fn gen_deprecated(lints: &[DeprecatedLint]) -> String {
691691
let mut output = GENERATED_FILE_COMMENT.to_string();
692692
output.push_str("{\n");
693693
for lint in lints {
694-
let _ = write!(
694+
let _: fmt::Result = write!(
695695
output,
696696
concat!(
697697
" store.register_removed(\n",
@@ -726,7 +726,7 @@ fn gen_declared_lints<'a>(
726726
if !is_public {
727727
output.push_str(" #[cfg(feature = \"internal\")]\n");
728728
}
729-
let _ = writeln!(output, " crate::{module_name}::{lint_name}_INFO,");
729+
let _: fmt::Result = writeln!(output, " crate::{module_name}::{lint_name}_INFO,");
730730
}
731731
output.push_str("];\n");
732732

clippy_lints/src/entry.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use clippy_utils::{
66
source::{reindent_multiline, snippet_indent, snippet_with_applicability, snippet_with_context},
77
SpanlessEq,
88
};
9-
use core::fmt::Write;
9+
use core::fmt::{self, Write};
1010
use rustc_errors::Applicability;
1111
use rustc_hir::{
1212
hir_id::HirIdSet,
@@ -536,7 +536,7 @@ impl<'tcx> InsertSearchResults<'tcx> {
536536
if is_expr_used_or_unified(cx.tcx, insertion.call) {
537537
write_wrapped(&mut res, insertion, ctxt, app);
538538
} else {
539-
let _ = write!(
539+
let _: fmt::Result = write!(
540540
res,
541541
"e.insert({})",
542542
snippet_with_context(cx, insertion.value.span, ctxt, "..", app).0
@@ -552,7 +552,7 @@ impl<'tcx> InsertSearchResults<'tcx> {
552552
(
553553
self.snippet(cx, span, app, |res, insertion, ctxt, app| {
554554
// Insertion into a map would return `Some(&mut value)`, but the entry returns `&mut value`
555-
let _ = write!(
555+
let _: fmt::Result = write!(
556556
res,
557557
"Some(e.insert({}))",
558558
snippet_with_context(cx, insertion.value.span, ctxt, "..", app).0
@@ -566,7 +566,7 @@ impl<'tcx> InsertSearchResults<'tcx> {
566566
(
567567
self.snippet(cx, span, app, |res, insertion, ctxt, app| {
568568
// Insertion into a map would return `None`, but the entry returns a mutable reference.
569-
let _ = if is_expr_final_block_expr(cx.tcx, insertion.call) {
569+
let _: fmt::Result = if is_expr_final_block_expr(cx.tcx, insertion.call) {
570570
write!(
571571
res,
572572
"e.insert({});\n{}None",

clippy_lints/src/inconsistent_struct_constructor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_hir::{self as hir, ExprKind};
77
use rustc_lint::{LateContext, LateLintPass};
88
use rustc_session::{declare_lint_pass, declare_tool_lint};
99
use rustc_span::symbol::Symbol;
10-
use std::fmt::Write as _;
10+
use std::fmt::{self, Write as _};
1111

1212
declare_clippy_lint! {
1313
/// ### What it does
@@ -90,7 +90,7 @@ impl<'tcx> LateLintPass<'tcx> for InconsistentStructConstructor {
9090
let mut fields_snippet = String::new();
9191
let (last_ident, idents) = ordered_fields.split_last().unwrap();
9292
for ident in idents {
93-
let _ = write!(fields_snippet, "{ident}, ");
93+
let _: fmt::Result = write!(fields_snippet, "{ident}, ");
9494
}
9595
fields_snippet.push_str(&last_ident.to_string());
9696

clippy_lints/src/literal_representation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ impl DecimalLiteralRepresentation {
484484
then {
485485
let hex = format!("{val:#X}");
486486
let num_lit = NumericLiteral::new(&hex, num_lit.suffix, false);
487-
let _ = Self::do_lint(num_lit.integer).map_err(|warning_type| {
487+
let _: Result<(), ()> = Self::do_lint(num_lit.integer).map_err(|warning_type| {
488488
warning_type.display(num_lit.format(), cx, span);
489489
});
490490
}

clippy_lints/src/module_style.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ fn process_paths_for_mod_files<'a>(
134134
mod_folders: &mut FxHashSet<&'a OsStr>,
135135
) {
136136
let mut comp = path.components().rev().peekable();
137-
let _ = comp.next();
137+
let _: Option<_> = comp.next();
138138
if path.ends_with("mod.rs") {
139139
mod_folders.insert(comp.peek().map(|c| c.as_os_str()).unwrap_or_default());
140140
}

clippy_utils/src/numeric_literal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ impl<'a> NumericLiteral<'a> {
186186
// The exponent may have a sign, output it early, otherwise it will be
187187
// treated as a digit
188188
if digits.clone().next() == Some('-') {
189-
let _ = digits.next();
189+
let _: Option<char> = digits.next();
190190
output.push('-');
191191
}
192192

clippy_utils/src/sugg.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_middle::mir::{FakeReadCause, Mutability};
2020
use rustc_middle::ty;
2121
use rustc_span::source_map::{BytePos, CharPos, Pos, Span, SyntaxContext};
2222
use std::borrow::Cow;
23-
use std::fmt::{Display, Write as _};
23+
use std::fmt::{self, Display, Write as _};
2424
use std::ops::{Add, Neg, Not, Sub};
2525

2626
/// A helper type to build suggestion correctly handling parentheses.
@@ -932,7 +932,7 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
932932
if cmt.place.projections.is_empty() {
933933
// handle item without any projection, that needs an explicit borrowing
934934
// i.e.: suggest `&x` instead of `x`
935-
let _ = write!(self.suggestion_start, "{start_snip}&{ident_str}");
935+
let _: fmt::Result = write!(self.suggestion_start, "{start_snip}&{ident_str}");
936936
} else {
937937
// cases where a parent `Call` or `MethodCall` is using the item
938938
// i.e.: suggest `.contains(&x)` for `.find(|x| [1, 2, 3].contains(x)).is_none()`
@@ -947,7 +947,7 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
947947
// given expression is the self argument and will be handled completely by the compiler
948948
// i.e.: `|x| x.is_something()`
949949
ExprKind::MethodCall(_, self_expr, ..) if self_expr.hir_id == cmt.hir_id => {
950-
let _ = write!(self.suggestion_start, "{start_snip}{ident_str_with_proj}");
950+
let _: fmt::Result = write!(self.suggestion_start, "{start_snip}{ident_str_with_proj}");
951951
self.next_pos = span.hi();
952952
return;
953953
},
@@ -1055,7 +1055,7 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
10551055
}
10561056
}
10571057

1058-
let _ = write!(self.suggestion_start, "{start_snip}{replacement_str}");
1058+
let _: fmt::Result = write!(self.suggestion_start, "{start_snip}{replacement_str}");
10591059
}
10601060
self.next_pos = span.hi();
10611061
}

lintcheck/src/main.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ use crate::recursive::LintcheckServer;
1717
use std::collections::{HashMap, HashSet};
1818
use std::env;
1919
use std::env::consts::EXE_SUFFIX;
20-
use std::fmt::Write as _;
20+
use std::fmt::{self, Write as _};
2121
use std::fs;
22-
use std::io::ErrorKind;
22+
use std::io::{self, ErrorKind};
2323
use std::path::{Path, PathBuf};
2424
use std::process::Command;
2525
use std::sync::atomic::{AtomicUsize, Ordering};
@@ -145,8 +145,8 @@ impl ClippyWarning {
145145
}
146146

147147
let mut output = String::from("| ");
148-
let _ = write!(output, "[`{file_with_pos}`]({file}#L{})", self.line);
149-
let _ = write!(output, r#" | `{:<50}` | "{}" |"#, self.lint_type, self.message);
148+
let _: fmt::Result = write!(output, "[`{file_with_pos}`]({file}#L{})", self.line);
149+
let _: fmt::Result = write!(output, r#" | `{:<50}` | "{}" |"#, self.lint_type, self.message);
150150
output.push('\n');
151151
output
152152
} else {
@@ -632,7 +632,7 @@ fn main() {
632632
.unwrap();
633633

634634
let server = config.recursive.then(|| {
635-
let _ = fs::remove_dir_all("target/lintcheck/shared_target_dir/recursive");
635+
let _: io::Result<()> = fs::remove_dir_all("target/lintcheck/shared_target_dir/recursive");
636636

637637
LintcheckServer::spawn(recursive_options)
638638
});
@@ -689,7 +689,7 @@ fn main() {
689689
write!(text, "{}", all_msgs.join("")).unwrap();
690690
text.push_str("\n\n### ICEs:\n");
691691
for (cratename, msg) in &ices {
692-
let _ = write!(text, "{cratename}: '{msg}'");
692+
let _: fmt::Result = write!(text, "{cratename}: '{msg}'");
693693
}
694694

695695
println!("Writing logs to {}", config.lintcheck_results_path.display());

0 commit comments

Comments
 (0)