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,
kind: TokenKind::Unspecified,
};
return Err(CompileError {
kind: Internal { message },
token,
});
return Err(CompileError::new(token, Internal { message }));
}
self.stack.pop();

View File

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

View File

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

View File

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

View File

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

View File

@ -21,14 +21,14 @@ impl PlatformInterface for Platform {
use std::os::unix::fs::PermissionsExt;
// get current permissions
let mut permissions = fs::metadata(&path)?.permissions();
let mut permissions = fs::metadata(path)?.permissions();
// set the execute bit
let current_mode = permissions.mode();
permissions.set_mode(current_mode | 0o100);
// 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> {

View File

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

View File

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

View File

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