Fix issues reported by nightly clippy (#1336)

This commit is contained in:
Greg Shuflin 2022-09-11 01:41:24 -07:00 committed by GitHub
parent b4d6000dd2
commit 7b7efcabc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 49 additions and 52 deletions

View File

@ -45,10 +45,7 @@ impl<'src: 'run, 'run> AssignmentResolver<'src, 'run> {
length: 0, length: 0,
kind: TokenKind::Unspecified, kind: TokenKind::Unspecified,
}; };
return Err(CompileError { return Err(CompileError::new(token, Internal { message }));
kind: Internal { message },
token,
});
} }
self.stack.pop(); self.stack.pop();

View File

@ -3,20 +3,27 @@ use super::*;
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub(crate) struct CompileError<'src> { pub(crate) struct CompileError<'src> {
pub(crate) token: Token<'src>, pub(crate) token: Token<'src>,
pub(crate) kind: CompileErrorKind<'src>, pub(crate) kind: Box<CompileErrorKind<'src>>,
} }
impl<'src> CompileError<'src> { impl<'src> CompileError<'src> {
pub(crate) fn context(&self) -> Token<'src> { pub(crate) fn context(&self) -> Token<'src> {
self.token self.token
} }
pub(crate) fn new(token: Token<'src>, kind: CompileErrorKind<'src>) -> CompileError<'src> {
Self {
token,
kind: Box::new(kind),
}
}
} }
impl Display for CompileError<'_> { impl Display for CompileError<'_> {
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> { fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
use CompileErrorKind::*; use CompileErrorKind::*;
match &self.kind { match &*self.kind {
AliasShadowsRecipe { alias, recipe_line } => { AliasShadowsRecipe { alias, recipe_line } => {
write!( write!(
f, f,

View File

@ -257,7 +257,7 @@ impl<'src> Justfile<'src> {
let mut ran = BTreeSet::new(); let mut ran = BTreeSet::new();
for (recipe, arguments) in grouped { for (recipe, arguments) in grouped {
self.run_recipe(&context, recipe, arguments, &dotenv, search, &mut ran)?; Self::run_recipe(&context, recipe, arguments, &dotenv, search, &mut ran)?;
} }
Ok(()) Ok(())
@ -276,7 +276,6 @@ impl<'src> Justfile<'src> {
} }
fn run_recipe( fn run_recipe(
&self,
context: &RecipeContext<'src, '_>, context: &RecipeContext<'src, '_>,
recipe: &Recipe<'src>, recipe: &Recipe<'src>,
arguments: &[&str], arguments: &[&str],
@ -314,7 +313,7 @@ impl<'src> Justfile<'src> {
.map(|argument| evaluator.evaluate_expression(argument)) .map(|argument| evaluator.evaluate_expression(argument))
.collect::<RunResult<Vec<String>>>()?; .collect::<RunResult<Vec<String>>>()?;
self.run_recipe( Self::run_recipe(
context, context,
recipe, recipe,
&arguments.iter().map(String::as_ref).collect::<Vec<&str>>(), &arguments.iter().map(String::as_ref).collect::<Vec<&str>>(),
@ -336,7 +335,7 @@ impl<'src> Justfile<'src> {
evaluated.push(evaluator.evaluate_expression(argument)?); evaluated.push(evaluator.evaluate_expression(argument)?);
} }
self.run_recipe( Self::run_recipe(
context, context,
recipe, recipe,
&evaluated.iter().map(String::as_ref).collect::<Vec<&str>>(), &evaluated.iter().map(String::as_ref).collect::<Vec<&str>>(),

View File

@ -209,12 +209,12 @@ impl<'src> Lexer<'src> {
length: 0, length: 0,
kind: Unspecified, kind: Unspecified,
}; };
CompileError { CompileError::new(
kind: CompileErrorKind::Internal { token,
CompileErrorKind::Internal {
message: message.into(), message: message.into(),
}, },
token, )
}
} }
/// Create a compilation error with `kind` /// Create a compilation error with `kind`
@ -245,14 +245,11 @@ impl<'src> Lexer<'src> {
length, length,
}; };
CompileError { token, kind } CompileError::new(token, kind)
} }
fn unterminated_interpolation_error(interpolation_start: Token<'src>) -> CompileError<'src> { fn unterminated_interpolation_error(interpolation_start: Token<'src>) -> CompileError<'src> {
CompileError { CompileError::new(interpolation_start, UnterminatedInterpolation)
token: interpolation_start,
kind: UnterminatedInterpolation,
}
} }
/// True if `text` could be an identifier /// True if `text` could be an identifier
@ -796,7 +793,7 @@ impl<'src> Lexer<'src> {
let mut escape = false; let mut escape = false;
loop { loop {
if self.next == None { if self.next.is_none() {
return Err(self.error(kind.unterminated_error_kind())); return Err(self.error(kind.unterminated_error_kind()));
} else if kind.processes_escape_sequences() && self.next_is('\\') && !escape { } else if kind.processes_escape_sequences() && self.next_is('\\') && !escape {
escape = true; escape = true;
@ -993,7 +990,7 @@ mod tests {
column, column,
length, length,
}, },
kind, kind: Box::new(kind),
}; };
assert_eq!(have, want); assert_eq!(have, want);
} }
@ -2276,20 +2273,19 @@ mod tests {
fn presume_error() { fn presume_error() {
let compile_error = Lexer::new("!").presume('-').unwrap_err(); let compile_error = Lexer::new("!").presume('-').unwrap_err();
assert_matches!( assert_matches!(
compile_error, compile_error.token,
CompileError { Token {
token: Token { offset: 0,
offset: 0, line: 0,
line: 0, column: 0,
column: 0, length: 0,
length: 0, src: "!",
src: "!", kind: Unspecified,
kind: Unspecified, }
}, );
kind: Internal { assert_matches!(&*compile_error.kind,
ref message, Internal { ref message }
}, if message == "Lexer presumed character `-`"
} if message == "Lexer presumed character `-`"
); );
assert_eq!( assert_eq!(

View File

@ -39,7 +39,7 @@ fn load_from_file(path: &Path) -> RunResult<'static, BTreeMap<String, String>> {
// https://github.com/dotenv-rs/dotenv/issues/13 // https://github.com/dotenv-rs/dotenv/issues/13
#![allow(deprecated)] #![allow(deprecated)]
let iter = dotenv::from_path_iter(&path)?; let iter = dotenv::from_path_iter(path)?;
let mut dotenv = BTreeMap::new(); let mut dotenv = BTreeMap::new();
for result in iter { for result in iter {
let (key, value) = result?; let (key, value) = result?;

View File

@ -396,10 +396,11 @@ impl<'tokens, 'src> Parser<'tokens, 'src> {
/// Parse an expression, e.g. `1 + 2` /// Parse an expression, e.g. `1 + 2`
fn parse_expression(&mut self) -> CompileResult<'src, Expression<'src>> { fn parse_expression(&mut self) -> CompileResult<'src, Expression<'src>> {
if self.depth == if cfg!(windows) { 48 } else { 256 } { if self.depth == if cfg!(windows) { 48 } else { 256 } {
return Err(CompileError { let token = self.next()?;
token: self.next()?, return Err(CompileError::new(
kind: CompileErrorKind::ParsingRecursionDepthExceeded, token,
}); CompileErrorKind::ParsingRecursionDepthExceeded,
));
} }
self.depth += 1; self.depth += 1;
@ -904,7 +905,7 @@ mod tests {
column, column,
length, length,
}, },
kind, kind: Box::new(kind),
}; };
assert_eq!(have, want); assert_eq!(have, want);
} }

View File

@ -21,14 +21,14 @@ impl PlatformInterface for Platform {
use std::os::unix::fs::PermissionsExt; use std::os::unix::fs::PermissionsExt;
// get current permissions // get current permissions
let mut permissions = fs::metadata(&path)?.permissions(); let mut permissions = fs::metadata(path)?.permissions();
// set the execute bit // set the execute bit
let current_mode = permissions.mode(); let current_mode = permissions.mode();
permissions.set_mode(current_mode | 0o100); permissions.set_mode(current_mode | 0o100);
// set the new permissions // set the new permissions
fs::set_permissions(&path, permissions) fs::set_permissions(path, permissions)
} }
fn signal_from_exit_status(exit_status: process::ExitStatus) -> Option<i32> { fn signal_from_exit_status(exit_status: process::ExitStatus) -> Option<i32> {

View File

@ -84,12 +84,9 @@ impl StringKind {
} }
pub(crate) fn from_token_start(token_start: &str) -> Option<Self> { pub(crate) fn from_token_start(token_start: &str) -> Option<Self> {
for &kind in Self::ALL { Self::ALL
if token_start.starts_with(kind.delimiter()) { .iter()
return Some(kind); .find(|&&kind| token_start.starts_with(kind.delimiter()))
} .copied()
}
None
} }
} }

View File

@ -79,7 +79,7 @@ pub(crate) fn analysis_error(
column, column,
length, length,
}, },
kind, kind: Box::new(kind),
}; };
assert_eq!(have, want); assert_eq!(have, want);
} }

View File

@ -16,7 +16,7 @@ impl<'src> Token<'src> {
} }
pub(crate) fn error(&self, kind: CompileErrorKind<'src>) -> CompileError<'src> { pub(crate) fn error(&self, kind: CompileErrorKind<'src>) -> CompileError<'src> {
CompileError { token: *self, kind } CompileError::new(*self, kind)
} }
} }