Merge pull request #3403 from rtfeldman/clippy-1.62

updates for clippy 1.62
This commit is contained in:
Richard Feldman 2022-07-05 18:26:52 -04:00 committed by GitHub
commit cd2cf045fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 73 additions and 56 deletions

View file

@ -3,7 +3,7 @@ use indexmap::IndexMap;
use roc_mono::layout::UnionLayout;
use roc_target::{Architecture, TargetInfo};
use std::convert::TryInto;
use std::fmt::Display;
use std::fmt::{Display, Write};
pub static TEMPLATE: &[u8] = include_bytes!("../templates/template.rs");
pub static HEADER: &[u8] = include_bytes!("../templates/header.rs");
@ -95,24 +95,32 @@ pub fn emit(types_and_targets: &[(Types, TargetInfo)]) -> String {
1 => {
let arch = arch_to_str(targets.get(0).unwrap().architecture);
buf.push_str(&format!("#[cfg(target_arch = \"{arch}\")]"));
write!(buf, "#[cfg(target_arch = \"{arch}\")]").unwrap();
}
_ => {
// We should never have a decl recorded with 0 targets!
debug_assert_ne!(targets.len(), 0);
let alternatives = targets
.iter()
.map(|target_info| {
format!(
"{indent}{INDENT}target_arch = \"{}\"",
arch_to_str(target_info.architecture)
)
})
.collect::<Vec<_>>()
.join(",\n");
let mut it = targets.iter().peekable();
buf.push_str(&format!("#[cfg(any(\n{alternatives}\n{indent}))]"));
writeln!(buf, "#[cfg(any(").unwrap();
while let Some(target_info) = it.next() {
write!(
buf,
"{indent}{INDENT}target_arch = \"{}\"",
arch_to_str(target_info.architecture)
)
.unwrap();
if it.peek().is_some() {
buf.push_str(",\n");
} else {
buf.push('\n');
}
}
write!(buf, "{indent}))]").unwrap();
}
}
@ -365,16 +373,18 @@ pub struct {name} {{
if let Some(payload_id) = opt_payload_id {
let payload_type = types.get_type(*payload_id);
buf.push_str(&format!("{INDENT}{tag_name}: "));
write!(buf, "{INDENT}{tag_name}: ").unwrap();
if payload_type.has_pointer(types) {
// types with pointers need ManuallyDrop
// because rust unions don't (and can't)
// know how to drop them automatically!
buf.push_str(&format!(
"core::mem::ManuallyDrop<{}>,\n",
writeln!(
buf,
"core::mem::ManuallyDrop<{}>,",
type_name(*payload_id, types)
));
)
.unwrap();
} else {
buf.push_str(&type_name(*payload_id, types));
buf.push_str(",\n");
@ -392,9 +402,7 @@ pub struct {name} {{
// (Do this even if theoretically shouldn't be necessary, since
// there's no runtime cost and it more explicitly syncs the
// union's size with what we think it should be.)
buf.push_str(&format!(
"{INDENT}_sizer: [u8; {size_rounded_to_alignment}],\n"
));
writeln!(buf, "{INDENT}_sizer: [u8; {size_rounded_to_alignment}],").unwrap();
}
buf.push('}');
@ -1154,9 +1162,7 @@ fn write_impl_tags<
write_indents(indentations + 1, buf);
buf.push_str(&format!(
"{discriminant_name}::{tag_name} => {branch_str}\n"
));
writeln!(buf, "{discriminant_name}::{tag_name} => {branch_str}").unwrap();
}
write_indents(indentations, buf);
@ -1192,18 +1198,18 @@ fn add_enumeration<I: ExactSizeIterator<Item = S>, S: AsRef<str> + Display>(
);
for (index, tag_name) in tags.enumerate() {
buf.push_str(&format!("{INDENT}{tag_name} = {index},\n"));
writeln!(buf, "{INDENT}{tag_name} = {index},").unwrap();
write_indents(3, &mut debug_buf);
debug_buf.push_str(&format!(
"Self::{tag_name} => f.write_str(\"{name}::{tag_name}\"),\n"
));
writeln!(
debug_buf,
"Self::{tag_name} => f.write_str(\"{name}::{tag_name}\"),"
)
.unwrap();
}
buf.push_str(&format!(
"}}\n\n{debug_buf}{INDENT}{INDENT}}}\n{INDENT}}}\n}}"
));
write!(buf, "}}\n\n{debug_buf}{INDENT}{INDENT}}}\n{INDENT}}}\n}}").unwrap();
add_decl(impls, None, target_info, buf);
}
@ -1237,7 +1243,7 @@ fn add_struct<S: Display>(
format!("{label}")
};
buf.push_str(&format!("{INDENT}pub {label}: {type_str},\n",));
writeln!(buf, "{INDENT}pub {label}: {type_str},",).unwrap();
}
buf.push('}');

View file

@ -14,11 +14,15 @@ use target_lexicon::Triple;
use tempfile::Builder;
fn report_timing(buf: &mut String, label: &str, duration: Duration) {
buf.push_str(&format!(
" {:9.3} ms {}\n",
use std::fmt::Write;
writeln!(
buf,
" {:9.3} ms {}",
duration.as_secs_f64() * 1000.0,
label,
));
)
.unwrap()
}
pub struct BuiltFile {

View file

@ -19,6 +19,7 @@ use roc_ast::{
};
use roc_utils::{index_of, slice_get};
use std::fmt;
use std::fmt::Write;
#[derive(Debug)]
pub enum MarkupNode {
@ -376,7 +377,7 @@ pub fn tree_as_string(root_node_id: MarkNodeId, mark_node_pool: &SlowPool) -> St
let node = mark_node_pool.get(root_node_id);
full_string.push_str(&format!("{} mn_id {}\n", node, root_node_id));
writeln!(full_string, "{} mn_id {}\n", node, root_node_id).unwrap();
tree_as_string_helper(node, 1, &mut full_string, mark_node_pool);
@ -390,16 +391,16 @@ fn tree_as_string_helper(
mark_node_pool: &SlowPool,
) {
for child_id in node.get_children_ids() {
let child = mark_node_pool.get(child_id);
let child_str = format!("{}", mark_node_pool.get(child_id)).replace('\n', "\\n");
let mut full_str = std::iter::repeat("|--- ")
.take(level)
.collect::<Vec<&str>>()
.join("")
.to_owned();
let child = mark_node_pool.get(child_id);
let child_str = format!("{}", mark_node_pool.get(child_id)).replace('\n', "\\n");
full_str.push_str(&format!("{} mn_id {}\n", child_str, child_id));
writeln!(full_str, "{} mn_id {}", child_str, child_id).unwrap();
tree_string.push_str(&full_str);

View file

@ -1,4 +1,5 @@
use crate::markup::{mark_id_ast_id_map::MarkIdAstIdMap, nodes::MarkupNode};
use std::fmt::Write;
pub type MarkNodeId = usize;
@ -54,14 +55,16 @@ impl SlowPool {
child_str = format!("children: {:?}", node_children);
}
ret_str.push_str(&format!(
write!(
ret_str,
"{}: {} ({}) ast_id {:?} {}",
mark_node_id,
node.node_type_as_string(),
node.get_content(),
ast_node_id.parse::<usize>().unwrap(),
child_str
));
)
.unwrap();
}
ret_str

View file

@ -29,7 +29,7 @@ impl Length {
} else if self.0 > 0 {
Kind::Interned(self.0 as usize)
} else {
Kind::Generated(self.0.abs() as usize)
Kind::Generated(self.0.unsigned_abs() as usize)
}
}

View file

@ -106,7 +106,7 @@ impl<'a> From<&'a str> for ModuleName {
}
}
impl<'a> From<IdentStr> for ModuleName {
impl From<IdentStr> for ModuleName {
fn from(string: IdentStr) -> Self {
Self(string.as_str().into())
}
@ -152,7 +152,7 @@ impl<'a> From<&'a str> for ForeignSymbol {
}
}
impl<'a> From<String> for ForeignSymbol {
impl From<String> for ForeignSymbol {
fn from(string: String) -> Self {
Self(string.into())
}
@ -174,7 +174,7 @@ impl<'a> From<&'a str> for Uppercase {
}
}
impl<'a> From<String> for Uppercase {
impl From<String> for Uppercase {
fn from(string: String) -> Self {
Self(string.into())
}
@ -198,7 +198,7 @@ impl<'a> From<&'a Lowercase> for &'a str {
}
}
impl<'a> From<String> for Lowercase {
impl From<String> for Lowercase {
fn from(string: String) -> Self {
Self(string.into())
}

View file

@ -181,7 +181,10 @@ impl fmt::Debug for Symbol {
// might be used in a panic error message, and if we panick
// while we're already panicking it'll kill the process
// without printing any of the errors!
println!("DEBUG INFO: Failed to acquire lock for Debug reading from DEBUG_IDENT_IDS_BY_MODULE_ID, presumably because a thread panicked: {:?}", err);
use std::io::Write;
let mut stderr = std::io::stderr();
writeln!(stderr, "DEBUG INFO: Failed to acquire lock for Debug reading from DEBUG_IDENT_IDS_BY_MODULE_ID, presumably because a thread panicked: {:?}", err).unwrap();
fallback_debug_fmt(*self, f)
}

View file

@ -1451,7 +1451,7 @@ macro_rules! word1_check_indent {
($word:expr, $word_problem:expr, $min_indent:expr, $indent_problem:expr) => {
and!(
word1($word, $word_problem),
crate::parser::check_indent($min_indent, $indent_problem)
$crate::parser::check_indent($min_indent, $indent_problem)
)
};
}

View file

@ -6,6 +6,7 @@ use crate::types::{name_type_var, RecordField, Uls};
use roc_collections::all::MutMap;
use roc_module::ident::{Lowercase, TagName};
use roc_module::symbol::{Interns, ModuleId, Symbol};
use std::fmt::Write;
pub static WILDCARD: &str = "*";
static EMPTY_RECORD: &str = "{}";
@ -1145,9 +1146,7 @@ fn write_flat_type<'a>(
)
})
}
Erroneous(problem) => {
buf.push_str(&format!("<Type Mismatch: {:?}>", problem));
}
Erroneous(problem) => write!(buf, "<Type Mismatch: {:?}>", problem).unwrap(),
}
}

View file

@ -11,6 +11,7 @@ use roc_module::low_level::LowLevel;
use roc_module::symbol::{Interns, ModuleId, Symbol};
use roc_region::all::{Loc, Region};
use std::fmt;
use std::fmt::Write;
pub const TYPE_NUM: &str = "Num";
pub const TYPE_INTEGER: &str = "Integer";
@ -2299,7 +2300,7 @@ fn write_debug_error_type_help(error_type: ErrorType, buf: &mut String, parens:
buf.push('(');
}
buf.push_str(name.as_str());
buf.push_str(&format!(" has {:?}", symbol));
write!(buf, "has {:?}", symbol).unwrap();
if write_parens {
buf.push(')');
}
@ -2310,7 +2311,7 @@ fn write_debug_error_type_help(error_type: ErrorType, buf: &mut String, parens:
if write_parens {
buf.push('(');
}
buf.push_str(&format!("{:?}", symbol));
write!(buf, "{:?}", symbol).unwrap();
for arg in arguments {
buf.push(' ');
@ -2355,7 +2356,7 @@ fn write_debug_error_type_help(error_type: ErrorType, buf: &mut String, parens:
if write_parens {
buf.push('(');
}
buf.push_str(&format!("{:?}", symbol));
write!(buf, "{:?}", symbol).unwrap();
for arg in arguments {
buf.push(' ');
@ -2434,7 +2435,7 @@ fn write_debug_error_type_help(error_type: ErrorType, buf: &mut String, parens:
let mut it = tags.into_iter().peekable();
while let Some((tag, args)) = it.next() {
buf.push_str(&format!("{:?}", tag));
write!(buf, "{:?}", tag).unwrap();
for arg in args {
buf.push(' ');
write_debug_error_type_help(arg, buf, Parens::InTypeParam);
@ -2453,7 +2454,7 @@ fn write_debug_error_type_help(error_type: ErrorType, buf: &mut String, parens:
let mut it = tags.into_iter().peekable();
while let Some((tag, args)) = it.next() {
buf.push_str(&format!("{:?}", tag));
write!(buf, "{:?}", tag).unwrap();
for arg in args {
buf.push(' ');
write_debug_error_type_help(arg, buf, Parens::Unnecessary);