Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: clippy fixes #49

Merged
merged 2 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use ara_source::loader::SourceLoader;

fn main() -> io::Result<()> {
let manifest = env::var("CARGO_MANIFEST_DIR").unwrap();
let root = format!("{}/tests/samples/", manifest);
let root = format!("{manifest}/tests/samples/");

let mut entries = read_dir(&root)?
.flatten()
Expand Down
4 changes: 2 additions & 2 deletions src/lexer/byte_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl std::fmt::Display for ByteString {
match b {
0 => write!(f, "\\0")?,
b'\n' | b'\r' | b'\t' => write!(f, "{}", b.escape_ascii())?,
0x01..=0x19 | 0x7f..=0xff => write!(f, "\\x{:02x}", b)?,
0x01..=0x19 | 0x7f..=0xff => write!(f, "\\x{b:02x}")?,
_ => write!(f, "{}", b as char)?,
}
}
Expand All @@ -95,7 +95,7 @@ impl std::fmt::Debug for ByteString {
match b {
0 => write!(f, "\\0")?,
b'\n' | b'\r' | b'\t' => write!(f, "{}", b.escape_ascii())?,
0x01..=0x19 | 0x7f..=0xff => write!(f, "\\x{:02x}", b)?,
0x01..=0x19 | 0x7f..=0xff => write!(f, "\\x{b:02x}")?,
_ => write!(f, "{}", b as char)?,
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lexer/issue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@ impl ::std::fmt::Display for LexerIssueCode {

impl From<LexerIssueCode> for String {
fn from(code: LexerIssueCode) -> String {
format!("{}", code)
format!("{code}")
}
}
4 changes: 2 additions & 2 deletions src/lexer/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ impl Display for TokenKind {
| Self::MultiLineComment
| Self::HashMarkComment
| Self::DocumentComment => {
return write!(f, "{:?}", self);
return write!(f, "{self:?}");
}
Self::Where => "where",
Self::Async => "async",
Expand Down Expand Up @@ -422,6 +422,6 @@ impl Display for TokenKind {
Self::TraitConstant => "__TRAIT__",
};

write!(f, "{}", s)
write!(f, "{s}")
}
}
4 changes: 2 additions & 2 deletions src/parser/internal/expression/precedence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl Precedence {
DoubleDot => Ok(Self::Range),
_ => crate::parser_bail!(
state,
unreachable_code(format!("unexpected precedence for operator {:?}", kind))
unreachable_code(format!("unexpected precedence for operator {kind:?}"))
),
}
}
Expand All @@ -86,7 +86,7 @@ impl Precedence {
Arrow | QuestionArrow | DoubleColon => Ok(Self::ObjectAccess),
_ => crate::parser_bail!(
state,
unreachable_code(format!("unexpected precedence for operator {:?}", kind))
unreachable_code(format!("unexpected precedence for operator {kind:?}"))
),
}
}
Expand Down
25 changes: 8 additions & 17 deletions src/parser/issue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,7 @@ pub(crate) fn reserved_keyword_cannot_be_used_for_type_name(
) -> Issue {
Issue::error(
ParserIssueCode::ReservedKeywordCannotBeUsedForTypeName,
format!(
"reserved keyword `{}` cannot be used as a type name",
identifier,
),
format!("reserved keyword `{identifier}` cannot be used as a type name",),
)
.with_source(
state.source.name(),
Expand All @@ -312,10 +309,7 @@ pub(crate) fn reserved_keyword_cannot_be_used_for_constant_name(
) -> Issue {
Issue::error(
ParserIssueCode::ReservedKeywordCannotBeUsedForConstantName,
format!(
"reserved keyword `{}` cannot be used as a constant name",
identifier,
),
format!("reserved keyword `{identifier}` cannot be used as a constant name",),
)
.with_source(
state.source.name(),
Expand All @@ -330,10 +324,7 @@ pub(crate) fn type_cannot_be_used_in_current_context(
) -> Issue {
Issue::error(
ParserIssueCode::TypeCannotBeUsedInCurrentContext,
format!(
"type `{}` cannot be used in the current context",
identifier,
),
format!("type `{identifier}` cannot be used in the current context",),
)
.with_source(
state.source.name(),
Expand Down Expand Up @@ -375,7 +366,7 @@ pub(crate) fn invalid_enum_backing_type(
) -> Issue {
Issue::error(
ParserIssueCode::InvalidEnumBackingType,
format!("invalid enum backing type `{}`", backing_identifier),
format!("invalid enum backing type `{backing_identifier}`"),
)
.with_source(
state.source.name(),
Expand Down Expand Up @@ -408,7 +399,7 @@ pub(crate) fn unexpected_token<T: ToString>(
};

let message = if expected.is_empty() {
format!("unexpected {}", found_name)
format!("unexpected {found_name}")
} else {
let expected: Vec<String> = expected
.iter()
Expand All @@ -418,7 +409,7 @@ pub(crate) fn unexpected_token<T: ToString>(
if s.starts_with("a ") || s.starts_with("an ") {
s
} else {
format!("`{}`", s)
format!("`{s}`")
}
})
.collect();
Expand All @@ -432,7 +423,7 @@ pub(crate) fn unexpected_token<T: ToString>(
expected.join(", or ")
};

format!("unexpected {}, expected {}", found_name, expected)
format!("unexpected {found_name}, expected {expected}")
};

Issue::error(ParserIssueCode::UnexpectedToken, message).with_source(
Expand All @@ -450,6 +441,6 @@ impl ::std::fmt::Display for ParserIssueCode {

impl From<ParserIssueCode> for String {
fn from(code: ParserIssueCode) -> Self {
format!("{}", code)
format!("{code}")
}
}
2 changes: 1 addition & 1 deletion src/parser/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl<'a> State<'a> {

pub fn named<T: Display + ?Sized>(&self, name: &T) -> String {
if let Some(namespace) = &self.namespace {
format!("{}\\{}", namespace, name)
format!("{namespace}\\{name}")
} else {
name.to_string()
}
Expand Down
16 changes: 8 additions & 8 deletions src/tree/definition/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ impl Node for TypeDefinition {
impl std::fmt::Display for TypeDefinition {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match &self {
Self::Identifier(inner) => write!(f, "{}", inner),
Self::Nullable(_, inner) => write!(f, "?{}", inner),
Self::Identifier(inner) => write!(f, "{inner}"),
Self::Nullable(_, inner) => write!(f, "?{inner}"),
Self::Union(inner) => write!(
f,
"{}",
Expand Down Expand Up @@ -433,11 +433,11 @@ impl std::fmt::Display for TypeDefinition {
FloatingPointTypeDefinition::F32(_) => write!(f, "f32"),
},
Self::String(_) => write!(f, "string"),
Self::Dict(_, template) => write!(f, "dict{}", template),
Self::Vec(_, template) => write!(f, "vec{}", template),
Self::Iterable(_, template) => write!(f, "iterable{}", template),
Self::Class(_, template) => write!(f, "class{}", template),
Self::Interface(_, template) => write!(f, "interface{}", template),
Self::Dict(_, template) => write!(f, "dict{template}"),
Self::Vec(_, template) => write!(f, "vec{template}"),
Self::Iterable(_, template) => write!(f, "iterable{template}"),
Self::Class(_, template) => write!(f, "class{template}"),
Self::Interface(_, template) => write!(f, "interface{template}"),
Self::Object(_) => write!(f, "object"),
Self::Mixed(_) => write!(f, "mixed"),
Self::NonNull(_) => write!(f, "nonnull"),
Expand All @@ -457,7 +457,7 @@ impl std::fmt::Display for TypeDefinition {
Self::Parenthesized {
type_definition, ..
} => {
write!(f, "({})", type_definition)
write!(f, "({type_definition})")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/tree/identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl std::fmt::Display for TemplatedIdentifier {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.name)?;
if let Some(templates) = &self.templates {
write!(f, "{}", templates)?;
write!(f, "{templates}")?;
}

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use ara_source::loader::SourceLoader;
#[test]
fn test_fixtures() -> io::Result<()> {
let manifest = env::var("CARGO_MANIFEST_DIR").unwrap();
let root = format!("{}/tests/samples/", manifest);
let root = format!("{manifest}/tests/samples/");

let mut entries = read_dir(&root)?
.flatten()
Expand Down Expand Up @@ -64,7 +64,7 @@ fn test_fixtures() -> io::Result<()> {

assert_str_eq!(
expected_error,
format!("{}", error),
format!("{error}"),
"error mismatch for sample `{}`",
source_map.sources[0].name()
);
Expand Down