mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-23 03:52:27 +00:00
Merge pull request #3403 from rtfeldman/clippy-1.62
updates for clippy 1.62
This commit is contained in:
commit
cd2cf045fa
10 changed files with 73 additions and 56 deletions
|
@ -3,7 +3,7 @@ use indexmap::IndexMap;
|
||||||
use roc_mono::layout::UnionLayout;
|
use roc_mono::layout::UnionLayout;
|
||||||
use roc_target::{Architecture, TargetInfo};
|
use roc_target::{Architecture, TargetInfo};
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use std::fmt::Display;
|
use std::fmt::{Display, Write};
|
||||||
|
|
||||||
pub static TEMPLATE: &[u8] = include_bytes!("../templates/template.rs");
|
pub static TEMPLATE: &[u8] = include_bytes!("../templates/template.rs");
|
||||||
pub static HEADER: &[u8] = include_bytes!("../templates/header.rs");
|
pub static HEADER: &[u8] = include_bytes!("../templates/header.rs");
|
||||||
|
@ -95,24 +95,32 @@ pub fn emit(types_and_targets: &[(Types, TargetInfo)]) -> String {
|
||||||
1 => {
|
1 => {
|
||||||
let arch = arch_to_str(targets.get(0).unwrap().architecture);
|
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!
|
// We should never have a decl recorded with 0 targets!
|
||||||
debug_assert_ne!(targets.len(), 0);
|
debug_assert_ne!(targets.len(), 0);
|
||||||
|
|
||||||
let alternatives = targets
|
let mut it = targets.iter().peekable();
|
||||||
.iter()
|
|
||||||
.map(|target_info| {
|
|
||||||
format!(
|
|
||||||
"{indent}{INDENT}target_arch = \"{}\"",
|
|
||||||
arch_to_str(target_info.architecture)
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.join(",\n");
|
|
||||||
|
|
||||||
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 {
|
if let Some(payload_id) = opt_payload_id {
|
||||||
let payload_type = types.get_type(*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) {
|
if payload_type.has_pointer(types) {
|
||||||
// types with pointers need ManuallyDrop
|
// types with pointers need ManuallyDrop
|
||||||
// because rust unions don't (and can't)
|
// because rust unions don't (and can't)
|
||||||
// know how to drop them automatically!
|
// know how to drop them automatically!
|
||||||
buf.push_str(&format!(
|
writeln!(
|
||||||
"core::mem::ManuallyDrop<{}>,\n",
|
buf,
|
||||||
|
"core::mem::ManuallyDrop<{}>,",
|
||||||
type_name(*payload_id, types)
|
type_name(*payload_id, types)
|
||||||
));
|
)
|
||||||
|
.unwrap();
|
||||||
} else {
|
} else {
|
||||||
buf.push_str(&type_name(*payload_id, types));
|
buf.push_str(&type_name(*payload_id, types));
|
||||||
buf.push_str(",\n");
|
buf.push_str(",\n");
|
||||||
|
@ -392,9 +402,7 @@ pub struct {name} {{
|
||||||
// (Do this even if theoretically shouldn't be necessary, since
|
// (Do this even if theoretically shouldn't be necessary, since
|
||||||
// there's no runtime cost and it more explicitly syncs the
|
// there's no runtime cost and it more explicitly syncs the
|
||||||
// union's size with what we think it should be.)
|
// union's size with what we think it should be.)
|
||||||
buf.push_str(&format!(
|
writeln!(buf, "{INDENT}_sizer: [u8; {size_rounded_to_alignment}],").unwrap();
|
||||||
"{INDENT}_sizer: [u8; {size_rounded_to_alignment}],\n"
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
buf.push('}');
|
buf.push('}');
|
||||||
|
@ -1154,9 +1162,7 @@ fn write_impl_tags<
|
||||||
|
|
||||||
write_indents(indentations + 1, buf);
|
write_indents(indentations + 1, buf);
|
||||||
|
|
||||||
buf.push_str(&format!(
|
writeln!(buf, "{discriminant_name}::{tag_name} => {branch_str}").unwrap();
|
||||||
"{discriminant_name}::{tag_name} => {branch_str}\n"
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
write_indents(indentations, buf);
|
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() {
|
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);
|
write_indents(3, &mut debug_buf);
|
||||||
|
|
||||||
debug_buf.push_str(&format!(
|
writeln!(
|
||||||
"Self::{tag_name} => f.write_str(\"{name}::{tag_name}\"),\n"
|
debug_buf,
|
||||||
));
|
"Self::{tag_name} => f.write_str(\"{name}::{tag_name}\"),"
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
buf.push_str(&format!(
|
write!(buf, "}}\n\n{debug_buf}{INDENT}{INDENT}}}\n{INDENT}}}\n}}").unwrap();
|
||||||
"}}\n\n{debug_buf}{INDENT}{INDENT}}}\n{INDENT}}}\n}}"
|
|
||||||
));
|
|
||||||
|
|
||||||
add_decl(impls, None, target_info, buf);
|
add_decl(impls, None, target_info, buf);
|
||||||
}
|
}
|
||||||
|
@ -1237,7 +1243,7 @@ fn add_struct<S: Display>(
|
||||||
format!("{label}")
|
format!("{label}")
|
||||||
};
|
};
|
||||||
|
|
||||||
buf.push_str(&format!("{INDENT}pub {label}: {type_str},\n",));
|
writeln!(buf, "{INDENT}pub {label}: {type_str},",).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
buf.push('}');
|
buf.push('}');
|
||||||
|
|
|
@ -14,11 +14,15 @@ use target_lexicon::Triple;
|
||||||
use tempfile::Builder;
|
use tempfile::Builder;
|
||||||
|
|
||||||
fn report_timing(buf: &mut String, label: &str, duration: Duration) {
|
fn report_timing(buf: &mut String, label: &str, duration: Duration) {
|
||||||
buf.push_str(&format!(
|
use std::fmt::Write;
|
||||||
" {:9.3} ms {}\n",
|
|
||||||
|
writeln!(
|
||||||
|
buf,
|
||||||
|
" {:9.3} ms {}",
|
||||||
duration.as_secs_f64() * 1000.0,
|
duration.as_secs_f64() * 1000.0,
|
||||||
label,
|
label,
|
||||||
));
|
)
|
||||||
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct BuiltFile {
|
pub struct BuiltFile {
|
||||||
|
|
|
@ -19,6 +19,7 @@ use roc_ast::{
|
||||||
};
|
};
|
||||||
use roc_utils::{index_of, slice_get};
|
use roc_utils::{index_of, slice_get};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
use std::fmt::Write;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum MarkupNode {
|
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);
|
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);
|
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,
|
mark_node_pool: &SlowPool,
|
||||||
) {
|
) {
|
||||||
for child_id in node.get_children_ids() {
|
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("|--- ")
|
let mut full_str = std::iter::repeat("|--- ")
|
||||||
.take(level)
|
.take(level)
|
||||||
.collect::<Vec<&str>>()
|
.collect::<Vec<&str>>()
|
||||||
.join("")
|
.join("")
|
||||||
.to_owned();
|
.to_owned();
|
||||||
|
|
||||||
let child = mark_node_pool.get(child_id);
|
writeln!(full_str, "{} mn_id {}", child_str, child_id).unwrap();
|
||||||
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));
|
|
||||||
|
|
||||||
tree_string.push_str(&full_str);
|
tree_string.push_str(&full_str);
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use crate::markup::{mark_id_ast_id_map::MarkIdAstIdMap, nodes::MarkupNode};
|
use crate::markup::{mark_id_ast_id_map::MarkIdAstIdMap, nodes::MarkupNode};
|
||||||
|
use std::fmt::Write;
|
||||||
|
|
||||||
pub type MarkNodeId = usize;
|
pub type MarkNodeId = usize;
|
||||||
|
|
||||||
|
@ -54,14 +55,16 @@ impl SlowPool {
|
||||||
child_str = format!("children: {:?}", node_children);
|
child_str = format!("children: {:?}", node_children);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret_str.push_str(&format!(
|
write!(
|
||||||
|
ret_str,
|
||||||
"{}: {} ({}) ast_id {:?} {}",
|
"{}: {} ({}) ast_id {:?} {}",
|
||||||
mark_node_id,
|
mark_node_id,
|
||||||
node.node_type_as_string(),
|
node.node_type_as_string(),
|
||||||
node.get_content(),
|
node.get_content(),
|
||||||
ast_node_id.parse::<usize>().unwrap(),
|
ast_node_id.parse::<usize>().unwrap(),
|
||||||
child_str
|
child_str
|
||||||
));
|
)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
ret_str
|
ret_str
|
||||||
|
|
|
@ -29,7 +29,7 @@ impl Length {
|
||||||
} else if self.0 > 0 {
|
} else if self.0 > 0 {
|
||||||
Kind::Interned(self.0 as usize)
|
Kind::Interned(self.0 as usize)
|
||||||
} else {
|
} else {
|
||||||
Kind::Generated(self.0.abs() as usize)
|
Kind::Generated(self.0.unsigned_abs() as usize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 {
|
fn from(string: IdentStr) -> Self {
|
||||||
Self(string.as_str().into())
|
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 {
|
fn from(string: String) -> Self {
|
||||||
Self(string.into())
|
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 {
|
fn from(string: String) -> Self {
|
||||||
Self(string.into())
|
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 {
|
fn from(string: String) -> Self {
|
||||||
Self(string.into())
|
Self(string.into())
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,7 +181,10 @@ impl fmt::Debug for Symbol {
|
||||||
// might be used in a panic error message, and if we panick
|
// might be used in a panic error message, and if we panick
|
||||||
// while we're already panicking it'll kill the process
|
// while we're already panicking it'll kill the process
|
||||||
// without printing any of the errors!
|
// 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)
|
fallback_debug_fmt(*self, f)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1451,7 +1451,7 @@ macro_rules! word1_check_indent {
|
||||||
($word:expr, $word_problem:expr, $min_indent:expr, $indent_problem:expr) => {
|
($word:expr, $word_problem:expr, $min_indent:expr, $indent_problem:expr) => {
|
||||||
and!(
|
and!(
|
||||||
word1($word, $word_problem),
|
word1($word, $word_problem),
|
||||||
crate::parser::check_indent($min_indent, $indent_problem)
|
$crate::parser::check_indent($min_indent, $indent_problem)
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ use crate::types::{name_type_var, RecordField, Uls};
|
||||||
use roc_collections::all::MutMap;
|
use roc_collections::all::MutMap;
|
||||||
use roc_module::ident::{Lowercase, TagName};
|
use roc_module::ident::{Lowercase, TagName};
|
||||||
use roc_module::symbol::{Interns, ModuleId, Symbol};
|
use roc_module::symbol::{Interns, ModuleId, Symbol};
|
||||||
|
use std::fmt::Write;
|
||||||
|
|
||||||
pub static WILDCARD: &str = "*";
|
pub static WILDCARD: &str = "*";
|
||||||
static EMPTY_RECORD: &str = "{}";
|
static EMPTY_RECORD: &str = "{}";
|
||||||
|
@ -1145,9 +1146,7 @@ fn write_flat_type<'a>(
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Erroneous(problem) => {
|
Erroneous(problem) => write!(buf, "<Type Mismatch: {:?}>", problem).unwrap(),
|
||||||
buf.push_str(&format!("<Type Mismatch: {:?}>", problem));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ use roc_module::low_level::LowLevel;
|
||||||
use roc_module::symbol::{Interns, ModuleId, Symbol};
|
use roc_module::symbol::{Interns, ModuleId, Symbol};
|
||||||
use roc_region::all::{Loc, Region};
|
use roc_region::all::{Loc, Region};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
use std::fmt::Write;
|
||||||
|
|
||||||
pub const TYPE_NUM: &str = "Num";
|
pub const TYPE_NUM: &str = "Num";
|
||||||
pub const TYPE_INTEGER: &str = "Integer";
|
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('(');
|
||||||
}
|
}
|
||||||
buf.push_str(name.as_str());
|
buf.push_str(name.as_str());
|
||||||
buf.push_str(&format!(" has {:?}", symbol));
|
write!(buf, "has {:?}", symbol).unwrap();
|
||||||
if write_parens {
|
if write_parens {
|
||||||
buf.push(')');
|
buf.push(')');
|
||||||
}
|
}
|
||||||
|
@ -2310,7 +2311,7 @@ fn write_debug_error_type_help(error_type: ErrorType, buf: &mut String, parens:
|
||||||
if write_parens {
|
if write_parens {
|
||||||
buf.push('(');
|
buf.push('(');
|
||||||
}
|
}
|
||||||
buf.push_str(&format!("{:?}", symbol));
|
write!(buf, "{:?}", symbol).unwrap();
|
||||||
|
|
||||||
for arg in arguments {
|
for arg in arguments {
|
||||||
buf.push(' ');
|
buf.push(' ');
|
||||||
|
@ -2355,7 +2356,7 @@ fn write_debug_error_type_help(error_type: ErrorType, buf: &mut String, parens:
|
||||||
if write_parens {
|
if write_parens {
|
||||||
buf.push('(');
|
buf.push('(');
|
||||||
}
|
}
|
||||||
buf.push_str(&format!("{:?}", symbol));
|
write!(buf, "{:?}", symbol).unwrap();
|
||||||
|
|
||||||
for arg in arguments {
|
for arg in arguments {
|
||||||
buf.push(' ');
|
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();
|
let mut it = tags.into_iter().peekable();
|
||||||
|
|
||||||
while let Some((tag, args)) = it.next() {
|
while let Some((tag, args)) = it.next() {
|
||||||
buf.push_str(&format!("{:?}", tag));
|
write!(buf, "{:?}", tag).unwrap();
|
||||||
for arg in args {
|
for arg in args {
|
||||||
buf.push(' ');
|
buf.push(' ');
|
||||||
write_debug_error_type_help(arg, buf, Parens::InTypeParam);
|
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();
|
let mut it = tags.into_iter().peekable();
|
||||||
while let Some((tag, args)) = it.next() {
|
while let Some((tag, args)) = it.next() {
|
||||||
buf.push_str(&format!("{:?}", tag));
|
write!(buf, "{:?}", tag).unwrap();
|
||||||
for arg in args {
|
for arg in args {
|
||||||
buf.push(' ');
|
buf.push(' ');
|
||||||
write_debug_error_type_help(arg, buf, Parens::Unnecessary);
|
write_debug_error_type_help(arg, buf, Parens::Unnecessary);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue