Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
Long overdue.
  • Loading branch information
michaeljones committed Oct 23, 2022
1 parent 21f39e7 commit 9ec1497
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::parser::ParserError;
use crate::renderer::RenderError;
use crate::scanner::{Range, ScanError, Token};

#[derive(Debug, PartialEq, Clone)]
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct Source {
pub filename: String,
pub contents: String,
Expand Down Expand Up @@ -108,7 +108,7 @@ pub fn write<W: termcolor::WriteColor>(writer: &mut W, error: Error) {
}
ParserError::FunctionWithinStatement(range) => explain_with_source(
writer,
&format!("Functions must be declared at the top level."),
"Functions must be declared at the top level.",
source,
range,
),
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn convert(prog_name: &str, file_path: &std::path::Path) -> Result<(), ()> {
let from_file_name = file_path
.file_name()
.map(|name| name.to_string_lossy().into_owned())
.unwrap_or(String::from("unknown"));
.unwrap_or_else(|| String::from("unknown"));

let result = std::fs::read_to_string(file_path)
.map_err(|err| Error::IO(err, file_path.to_path_buf()))
Expand Down Expand Up @@ -89,7 +89,7 @@ fn main() {
if opt.verbose {
println!("Converting {}", path.display());
}
Some(convert(NAME, &path.to_path_buf()))
Some(convert(NAME, path))
} else {
None
}
Expand Down
6 changes: 3 additions & 3 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ fn parse_inner(tokens: &mut TokenIter, in_statement: bool) -> Result<Vec<Node>,
})
.unwrap_or_else(|| pub_range.clone());
if in_statement {
return Err(ParserError::FunctionWithinStatement(range.clone()));
return Err(ParserError::FunctionWithinStatement(range));
}
let node = parse_function(tokens, Visibility::Public)?;
ast.push(node);
Expand Down Expand Up @@ -343,8 +343,8 @@ fn trim_trailing_newline(nodes: Vec<Node>) -> Vec<Node> {
} else {
Some(Node::Text(
text.strip_suffix('\n')
.map(|str| String::from(str))
.unwrap_or(text.to_string()),
.map(String::from)
.unwrap_or_else(|| text.to_string()),
))
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ fn render_lines(iter: &mut NodeIter) -> Result<Context, RenderError> {
iter.next();
builder_lines.push_str(&format!(
" let builder = string_builder.append(builder, \"{}\")\n",
text.replace("\"", "\\\"")
text.replace('\"', "\\\"")
));

// We have some kind of content if the text is not only whitespace. We don't need
Expand Down
2 changes: 1 addition & 1 deletion src/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub type Position = usize;

type Iter<'a> = std::iter::Peekable<GraphemeIndices<'a>>;

#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Token {
Text(String),
OpenLine,
Expand Down

0 comments on commit 9ec1497

Please sign in to comment.