Fix dogfood tests by adding type annotations

This commit is contained in:
Jirka Vebr 2023-02-16 13:29:38 +01:00
parent 2d4d39de53
commit 0b1ae20365
No known key found for this signature in database
GPG key ID: 5D98B205D843DF83
9 changed files with 27 additions and 26 deletions

View file

@ -1,5 +1,6 @@
use crate::clippy_project_root; use crate::clippy_project_root;
use indoc::{formatdoc, writedoc}; use indoc::{formatdoc, writedoc};
use std::fmt;
use std::fmt::Write as _; use std::fmt::Write as _;
use std::fs::{self, OpenOptions}; use std::fs::{self, OpenOptions};
use std::io::prelude::*; use std::io::prelude::*;
@ -256,7 +257,7 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
) )
}); });
let _ = write!(result, "{}", get_lint_declaration(&name_upper, category)); let _: fmt::Result = write!(result, "{}", get_lint_declaration(&name_upper, category));
result.push_str(&if enable_msrv { result.push_str(&if enable_msrv {
formatdoc!( formatdoc!(
@ -353,7 +354,7 @@ fn create_lint_for_ty(lint: &LintData<'_>, enable_msrv: bool, ty: &str) -> io::R
let mut lint_file_contents = String::new(); let mut lint_file_contents = String::new();
if enable_msrv { if enable_msrv {
let _ = writedoc!( let _: fmt::Result = writedoc!(
lint_file_contents, lint_file_contents,
r#" r#"
use clippy_utils::msrvs::{{self, Msrv}}; use clippy_utils::msrvs::{{self, Msrv}};
@ -373,7 +374,7 @@ fn create_lint_for_ty(lint: &LintData<'_>, enable_msrv: bool, ty: &str) -> io::R
name_upper = name_upper, name_upper = name_upper,
); );
} else { } else {
let _ = writedoc!( let _: fmt::Result = writedoc!(
lint_file_contents, lint_file_contents,
r#" r#"
use rustc_lint::{{{context_import}, LintContext}}; use rustc_lint::{{{context_import}, LintContext}};
@ -521,7 +522,7 @@ fn setup_mod_file(path: &Path, lint: &LintData<'_>) -> io::Result<&'static str>
.chain(std::iter::once(&*lint_name_upper)) .chain(std::iter::once(&*lint_name_upper))
.filter(|s| !s.is_empty()) .filter(|s| !s.is_empty())
{ {
let _ = write!(new_arr_content, "\n {ident},"); let _: fmt::Result = write!(new_arr_content, "\n {ident},");
} }
new_arr_content.push('\n'); new_arr_content.push('\n');

View file

@ -5,7 +5,7 @@ use itertools::Itertools;
use rustc_lexer::{tokenize, unescape, LiteralKind, TokenKind}; use rustc_lexer::{tokenize, unescape, LiteralKind, TokenKind};
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::ffi::OsStr; use std::ffi::OsStr;
use std::fmt::Write; use std::fmt::{self, Write};
use std::fs::{self, OpenOptions}; use std::fs::{self, OpenOptions};
use std::io::{self, Read, Seek, SeekFrom, Write as _}; use std::io::{self, Read, Seek, SeekFrom, Write as _};
use std::ops::Range; use std::ops::Range;
@ -691,7 +691,7 @@ fn gen_deprecated(lints: &[DeprecatedLint]) -> String {
let mut output = GENERATED_FILE_COMMENT.to_string(); let mut output = GENERATED_FILE_COMMENT.to_string();
output.push_str("{\n"); output.push_str("{\n");
for lint in lints { for lint in lints {
let _ = write!( let _: fmt::Result = write!(
output, output,
concat!( concat!(
" store.register_removed(\n", " store.register_removed(\n",
@ -726,7 +726,7 @@ fn gen_declared_lints<'a>(
if !is_public { if !is_public {
output.push_str(" #[cfg(feature = \"internal\")]\n"); output.push_str(" #[cfg(feature = \"internal\")]\n");
} }
let _ = writeln!(output, " crate::{module_name}::{lint_name}_INFO,"); let _: fmt::Result = writeln!(output, " crate::{module_name}::{lint_name}_INFO,");
} }
output.push_str("];\n"); output.push_str("];\n");

View file

@ -6,7 +6,7 @@ use clippy_utils::{
source::{reindent_multiline, snippet_indent, snippet_with_applicability, snippet_with_context}, source::{reindent_multiline, snippet_indent, snippet_with_applicability, snippet_with_context},
SpanlessEq, SpanlessEq,
}; };
use core::fmt::Write; use core::fmt::{self, Write};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::{ use rustc_hir::{
hir_id::HirIdSet, hir_id::HirIdSet,
@ -536,7 +536,7 @@ impl<'tcx> InsertSearchResults<'tcx> {
if is_expr_used_or_unified(cx.tcx, insertion.call) { if is_expr_used_or_unified(cx.tcx, insertion.call) {
write_wrapped(&mut res, insertion, ctxt, app); write_wrapped(&mut res, insertion, ctxt, app);
} else { } else {
let _ = write!( let _: fmt::Result = write!(
res, res,
"e.insert({})", "e.insert({})",
snippet_with_context(cx, insertion.value.span, ctxt, "..", app).0 snippet_with_context(cx, insertion.value.span, ctxt, "..", app).0
@ -552,7 +552,7 @@ impl<'tcx> InsertSearchResults<'tcx> {
( (
self.snippet(cx, span, app, |res, insertion, ctxt, app| { self.snippet(cx, span, app, |res, insertion, ctxt, app| {
// Insertion into a map would return `Some(&mut value)`, but the entry returns `&mut value` // Insertion into a map would return `Some(&mut value)`, but the entry returns `&mut value`
let _ = write!( let _: fmt::Result = write!(
res, res,
"Some(e.insert({}))", "Some(e.insert({}))",
snippet_with_context(cx, insertion.value.span, ctxt, "..", app).0 snippet_with_context(cx, insertion.value.span, ctxt, "..", app).0
@ -566,7 +566,7 @@ impl<'tcx> InsertSearchResults<'tcx> {
( (
self.snippet(cx, span, app, |res, insertion, ctxt, app| { self.snippet(cx, span, app, |res, insertion, ctxt, app| {
// Insertion into a map would return `None`, but the entry returns a mutable reference. // Insertion into a map would return `None`, but the entry returns a mutable reference.
let _ = if is_expr_final_block_expr(cx.tcx, insertion.call) { let _: fmt::Result = if is_expr_final_block_expr(cx.tcx, insertion.call) {
write!( write!(
res, res,
"e.insert({});\n{}None", "e.insert({});\n{}None",

View file

@ -7,7 +7,7 @@ use rustc_hir::{self as hir, ExprKind};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::symbol::Symbol; use rustc_span::symbol::Symbol;
use std::fmt::Write as _; use std::fmt::{self, Write as _};
declare_clippy_lint! { declare_clippy_lint! {
/// ### What it does /// ### What it does
@ -90,7 +90,7 @@ impl<'tcx> LateLintPass<'tcx> for InconsistentStructConstructor {
let mut fields_snippet = String::new(); let mut fields_snippet = String::new();
let (last_ident, idents) = ordered_fields.split_last().unwrap(); let (last_ident, idents) = ordered_fields.split_last().unwrap();
for ident in idents { for ident in idents {
let _ = write!(fields_snippet, "{ident}, "); let _: fmt::Result = write!(fields_snippet, "{ident}, ");
} }
fields_snippet.push_str(&last_ident.to_string()); fields_snippet.push_str(&last_ident.to_string());

View file

@ -484,7 +484,7 @@ impl DecimalLiteralRepresentation {
then { then {
let hex = format!("{val:#X}"); let hex = format!("{val:#X}");
let num_lit = NumericLiteral::new(&hex, num_lit.suffix, false); let num_lit = NumericLiteral::new(&hex, num_lit.suffix, false);
let _ = Self::do_lint(num_lit.integer).map_err(|warning_type| { let _: Result<(), ()> = Self::do_lint(num_lit.integer).map_err(|warning_type| {
warning_type.display(num_lit.format(), cx, span); warning_type.display(num_lit.format(), cx, span);
}); });
} }

View file

@ -134,7 +134,7 @@ fn process_paths_for_mod_files<'a>(
mod_folders: &mut FxHashSet<&'a OsStr>, mod_folders: &mut FxHashSet<&'a OsStr>,
) { ) {
let mut comp = path.components().rev().peekable(); let mut comp = path.components().rev().peekable();
let _ = comp.next(); let _: Option<_> = comp.next();
if path.ends_with("mod.rs") { if path.ends_with("mod.rs") {
mod_folders.insert(comp.peek().map(|c| c.as_os_str()).unwrap_or_default()); mod_folders.insert(comp.peek().map(|c| c.as_os_str()).unwrap_or_default());
} }

View file

@ -186,7 +186,7 @@ impl<'a> NumericLiteral<'a> {
// The exponent may have a sign, output it early, otherwise it will be // The exponent may have a sign, output it early, otherwise it will be
// treated as a digit // treated as a digit
if digits.clone().next() == Some('-') { if digits.clone().next() == Some('-') {
let _ = digits.next(); let _: Option<char> = digits.next();
output.push('-'); output.push('-');
} }

View file

@ -20,7 +20,7 @@ use rustc_middle::mir::{FakeReadCause, Mutability};
use rustc_middle::ty; use rustc_middle::ty;
use rustc_span::source_map::{BytePos, CharPos, Pos, Span, SyntaxContext}; use rustc_span::source_map::{BytePos, CharPos, Pos, Span, SyntaxContext};
use std::borrow::Cow; use std::borrow::Cow;
use std::fmt::{Display, Write as _}; use std::fmt::{self, Display, Write as _};
use std::ops::{Add, Neg, Not, Sub}; use std::ops::{Add, Neg, Not, Sub};
/// A helper type to build suggestion correctly handling parentheses. /// A helper type to build suggestion correctly handling parentheses.
@ -932,7 +932,7 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
if cmt.place.projections.is_empty() { if cmt.place.projections.is_empty() {
// handle item without any projection, that needs an explicit borrowing // handle item without any projection, that needs an explicit borrowing
// i.e.: suggest `&x` instead of `x` // i.e.: suggest `&x` instead of `x`
let _ = write!(self.suggestion_start, "{start_snip}&{ident_str}"); let _: fmt::Result = write!(self.suggestion_start, "{start_snip}&{ident_str}");
} else { } else {
// cases where a parent `Call` or `MethodCall` is using the item // cases where a parent `Call` or `MethodCall` is using the item
// i.e.: suggest `.contains(&x)` for `.find(|x| [1, 2, 3].contains(x)).is_none()` // 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> {
// given expression is the self argument and will be handled completely by the compiler // given expression is the self argument and will be handled completely by the compiler
// i.e.: `|x| x.is_something()` // i.e.: `|x| x.is_something()`
ExprKind::MethodCall(_, self_expr, ..) if self_expr.hir_id == cmt.hir_id => { ExprKind::MethodCall(_, self_expr, ..) if self_expr.hir_id == cmt.hir_id => {
let _ = write!(self.suggestion_start, "{start_snip}{ident_str_with_proj}"); let _: fmt::Result = write!(self.suggestion_start, "{start_snip}{ident_str_with_proj}");
self.next_pos = span.hi(); self.next_pos = span.hi();
return; return;
}, },
@ -1055,7 +1055,7 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
} }
} }
let _ = write!(self.suggestion_start, "{start_snip}{replacement_str}"); let _: fmt::Result = write!(self.suggestion_start, "{start_snip}{replacement_str}");
} }
self.next_pos = span.hi(); self.next_pos = span.hi();
} }

View file

@ -17,9 +17,9 @@ use crate::recursive::LintcheckServer;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::env; use std::env;
use std::env::consts::EXE_SUFFIX; use std::env::consts::EXE_SUFFIX;
use std::fmt::Write as _; use std::fmt::{self, Write as _};
use std::fs; use std::fs;
use std::io::ErrorKind; use std::io::{self, ErrorKind};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::process::Command; use std::process::Command;
use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::atomic::{AtomicUsize, Ordering};
@ -145,8 +145,8 @@ impl ClippyWarning {
} }
let mut output = String::from("| "); let mut output = String::from("| ");
let _ = write!(output, "[`{file_with_pos}`]({file}#L{})", self.line); let _: fmt::Result = write!(output, "[`{file_with_pos}`]({file}#L{})", self.line);
let _ = write!(output, r#" | `{:<50}` | "{}" |"#, self.lint_type, self.message); let _: fmt::Result = write!(output, r#" | `{:<50}` | "{}" |"#, self.lint_type, self.message);
output.push('\n'); output.push('\n');
output output
} else { } else {
@ -632,7 +632,7 @@ fn main() {
.unwrap(); .unwrap();
let server = config.recursive.then(|| { let server = config.recursive.then(|| {
let _ = fs::remove_dir_all("target/lintcheck/shared_target_dir/recursive"); let _: io::Result<()> = fs::remove_dir_all("target/lintcheck/shared_target_dir/recursive");
LintcheckServer::spawn(recursive_options) LintcheckServer::spawn(recursive_options)
}); });
@ -689,7 +689,7 @@ fn main() {
write!(text, "{}", all_msgs.join("")).unwrap(); write!(text, "{}", all_msgs.join("")).unwrap();
text.push_str("\n\n### ICEs:\n"); text.push_str("\n\n### ICEs:\n");
for (cratename, msg) in &ices { for (cratename, msg) in &ices {
let _ = write!(text, "{cratename}: '{msg}'"); let _: fmt::Result = write!(text, "{cratename}: '{msg}'");
} }
println!("Writing logs to {}", config.lintcheck_results_path.display()); println!("Writing logs to {}", config.lintcheck_results_path.display());