From d7e9ab26a505096693366f2905bb0795dd2d6f06 Mon Sep 17 00:00:00 2001 From: nikoraefu Date: Sun, 22 Jan 2023 01:55:09 +0100 Subject: [PATCH] make clippy happy --- components/dada-execute/src/heap_graph/graphviz.rs | 10 +++++----- components/dada-execute/src/machine/stringify.rs | 10 +++++----- components/dada-execute/src/step.rs | 5 ++--- components/dada-ir/src/code/bir.rs | 12 ++++++------ components/dada-ir/src/code/validated.rs | 14 +++++++------- components/dada-ir/src/signature.rs | 2 +- components/dada-lang/src/test_harness.rs | 6 +++--- components/dada-lex/src/lex.rs | 2 +- components/dada-parse/src/parser/expr.rs | 4 +--- components/dada-parse/src/parser/items.rs | 10 +++------- components/dada-parse/src/parser/ty.rs | 4 ++-- components/dada-parse/src/tokens.rs | 1 + components/dada-validate/src/validate/validator.rs | 2 +- .../src/validate/validator/string_literals.rs | 2 +- components/dada-web/src/lib.rs | 6 +++--- 15 files changed, 42 insertions(+), 48 deletions(-) diff --git a/components/dada-execute/src/heap_graph/graphviz.rs b/components/dada-execute/src/heap_graph/graphviz.rs index bd5ce7cb..3ae853f8 100644 --- a/components/dada-execute/src/heap_graph/graphviz.rs +++ b/components/dada-execute/src/heap_graph/graphviz.rs @@ -170,9 +170,9 @@ impl HeapGraph { Ok(()) } - fn find_lessor_place<'w>( + fn find_lessor_place( &self, - w: &'w GraphvizWriter<'_>, + w: &GraphvizWriter<'_>, permission: PermissionNode, ) -> Vec { if let Some(place) = w.permissions.get(&permission) { @@ -289,8 +289,8 @@ impl HeapGraph { edge: ValueEdgeTarget, ) -> eyre::Result<()> { if !self.value_edge_target_did_change(w, edge) { - w.println(&format!("color = {UNCHANGED:?},"))?; - w.println(&format!("fontcolor = {UNCHANGED:?},"))?; + w.println(format!("color = {UNCHANGED:?},"))?; + w.println(format!("fontcolor = {UNCHANGED:?},"))?; } Ok(()) @@ -317,7 +317,7 @@ impl HeapGraph { .map(|i| Some(i.name.to_string(db))) .collect(), - ObjectType::RustThunk(_) => (0..num_fields).map(|i| Some(format!("{}", i))).collect(), + ObjectType::RustThunk(_) => (0..num_fields).map(|i| Some(format!("{i}"))).collect(), ObjectType::Reservation => vec![Some("reserved".to_string())], } diff --git a/components/dada-execute/src/machine/stringify.rs b/components/dada-execute/src/machine/stringify.rs index 788494e8..fce2f081 100644 --- a/components/dada-execute/src/machine/stringify.rs +++ b/components/dada-execute/src/machine/stringify.rs @@ -26,11 +26,11 @@ pub(crate) impl DefaultStringify for T { ); match &self[object] { ObjectData::String(s) => s.to_string(), - ObjectData::Bool(v) => format!("{}", v), - ObjectData::SignedInt(v) => format!("{}_i", v), - ObjectData::Float(v) => format!("{}", v), - ObjectData::UnsignedInt(v) => format!("{}_u", v), - ObjectData::Int(v) => format!("{}", v), + ObjectData::Bool(v) => format!("{v}"), + ObjectData::SignedInt(v) => format!("{v}_i"), + ObjectData::Float(v) => format!("{v}"), + ObjectData::UnsignedInt(v) => format!("{v}_u"), + ObjectData::Int(v) => format!("{v}"), ObjectData::Unit(_) => "()".to_string(), ObjectData::Intrinsic(i) => i.as_str(db).to_string(), ObjectData::Function(f) => f.name(db).as_str(db).to_string(), diff --git a/components/dada-execute/src/step.rs b/components/dada-execute/src/step.rs index 08e14b9d..3881465a 100644 --- a/components/dada-execute/src/step.rs +++ b/components/dada-execute/src/step.rs @@ -506,13 +506,12 @@ impl<'me> Stepper<'me> { let class_span = class.name_span(db).anchor_to(db, class); error!( span, - "the class `{}` has no field named `{}`", - class_name, + "the class `{class_name}` has no field named `{}`", name.as_str(db) ) .secondary_label( class_span, - &format!("the class `{}` is declared here", class_name), + format!("the class `{class_name}` is declared here"), ) .eyre(db) } diff --git a/components/dada-ir/src/code/bir.rs b/components/dada-ir/src/code/bir.rs index 31b59b74..68a8d450 100644 --- a/components/dada-ir/src/code/bir.rs +++ b/components/dada-ir/src/code/bir.rs @@ -465,12 +465,12 @@ pub enum ExprData { impl DebugWithDb> for ExprData { fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &InIrDb<'_, Bir>) -> std::fmt::Result { match self { - ExprData::BooleanLiteral(b) => write!(f, "{}", b), - ExprData::IntegerLiteral(w) => write!(f, "{}", w), - ExprData::UnsignedIntegerLiteral(w) => write!(f, "{}", w), - ExprData::SignedIntegerLiteral(w) => write!(f, "{}", w), + ExprData::BooleanLiteral(b) => write!(f, "{b}"), + ExprData::IntegerLiteral(w) => write!(f, "{w}"), + ExprData::UnsignedIntegerLiteral(w) => write!(f, "{w}"), + ExprData::SignedIntegerLiteral(w) => write!(f, "{w}"), ExprData::StringLiteral(w) => write!(f, "{:?}", w.as_str(db.db())), - ExprData::FloatLiteral(w) => write!(f, "{}", w), + ExprData::FloatLiteral(w) => write!(f, "{w}"), ExprData::IntoShared(e) => write!(f, "{:?}.share", e.debug(db)), ExprData::Share(p) => write!(f, "{:?}.share", p.debug(db)), ExprData::Lease(p) => write!(f, "{:?}.lease", p.debug(db)), @@ -531,7 +531,7 @@ impl DebugWithDb> for PlaceData { PlaceData::LocalVariable(v) => write!(f, "{:?}", v.debug(db)), PlaceData::Function(func) => write!(f, "{:?}", func.debug(db.db())), PlaceData::Class(class) => write!(f, "{:?}", class.debug(db.db())), - PlaceData::Intrinsic(intrinsic) => write!(f, "{:?}", intrinsic), + PlaceData::Intrinsic(intrinsic) => write!(f, "{intrinsic:?}"), PlaceData::Dot(p, id) => write!(f, "{:?}.{}", p.debug(db), id.as_str(db.db())), } } diff --git a/components/dada-ir/src/code/validated.rs b/components/dada-ir/src/code/validated.rs index 5a803cba..36ebae7a 100644 --- a/components/dada-ir/src/code/validated.rs +++ b/components/dada-ir/src/code/validated.rs @@ -215,7 +215,7 @@ id!(pub struct Expr); impl DebugWithDb> for Expr { fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &InIrDb<'_, Tree>) -> std::fmt::Result { - let name = format!("{:?}", self); + let name = format!("{self:?}"); f.debug_tuple(&name) .field(&self.data(db.tables()).debug(db)) .field(&db.origins()[*self]) @@ -325,10 +325,10 @@ impl ExprData { let id = id.map(u32::from); match self { ExprData::BooleanLiteral(v) => std::fmt::Debug::fmt(v, f), - ExprData::IntegerLiteral(v) => write!(f, "{}", v), - ExprData::UnsignedIntegerLiteral(v) => write!(f, "{}", v), - ExprData::SignedIntegerLiteral(v) => write!(f, "{}", v), - ExprData::FloatLiteral(v) => write!(f, "{}", v), + ExprData::IntegerLiteral(v) => write!(f, "{v}"), + ExprData::UnsignedIntegerLiteral(v) => write!(f, "{v}"), + ExprData::SignedIntegerLiteral(v) => write!(f, "{v}"), + ExprData::FloatLiteral(v) => write!(f, "{v}"), ExprData::StringLiteral(v) => std::fmt::Debug::fmt(&v.as_str(db.db()), f), ExprData::Await(expr) => f.debug_tuple("Await").field(&expr.debug(db)).finish(), ExprData::Call(expr, args) => f @@ -410,7 +410,7 @@ id!(pub struct Place); impl DebugWithDb> for Place { fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &InIrDb<'_, Tree>) -> std::fmt::Result { - let name = format!("{:?}", self); + let name = format!("{self:?}"); f.debug_tuple(&name) .field(&self.data(db.tables()).debug(db)) .field(&db.origins()[*self]) @@ -447,7 +447,7 @@ id!(pub struct TargetPlace); impl DebugWithDb> for TargetPlace { fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &InIrDb<'_, Tree>) -> std::fmt::Result { - let name = format!("{:?}", self); + let name = format!("{self:?}"); f.debug_tuple(&name) .field(&self.data(db.tables()).debug(db)) .field(&db.origins()[*self]) diff --git a/components/dada-ir/src/signature.rs b/components/dada-ir/src/signature.rs index 59349b0a..1d46884f 100644 --- a/components/dada-ir/src/signature.rs +++ b/components/dada-ir/src/signature.rs @@ -237,7 +237,7 @@ impl DebugWithDb for Permission { fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &dyn crate::Db) -> std::fmt::Result { match self { Permission::Known(v) => v.fmt(f, db), - Permission::Parameter(v) => write!(f, "{:?}", v), + Permission::Parameter(v) => write!(f, "{v:?}"), } } } diff --git a/components/dada-lang/src/test_harness.rs b/components/dada-lang/src/test_harness.rs index 1fa2d563..e30ac37e 100644 --- a/components/dada-lang/src/test_harness.rs +++ b/components/dada-lang/src/test_harness.rs @@ -235,7 +235,7 @@ impl Options { &expected_diagnostics.compile, &mut errors, )?; - self.bless_debug_file(format!("{:#?}", diagnostics), &path.join("lsp.debug"))?; + self.bless_debug_file(format!("{diagnostics:#?}"), &path.join("lsp.debug"))?; errors.into_result() } @@ -884,7 +884,7 @@ fn expected_queries(path: &Path) -> eyre::Result> { // The column comes from the position of the `^`. let given_line_number: u32 = parse_line_number(line_number, &c["line"])?; let given_column_number: u32 = str::parse(&c["column"]) - .with_context(|| format!("in query on line {}", line_number))?; + .with_context(|| format!("in query on line {line_number}"))?; let query_kind = match &c["kind"] { "HeapGraph" => QueryKind::HeapGraph, @@ -925,7 +925,7 @@ fn parse_line_number(current_line_number: u32, line: &str) -> eyre::Result }; let parsed: u32 = - str::parse(number).with_context(|| format!("in query on line {}", current_line_number))?; + str::parse(number).with_context(|| format!("in query on line {current_line_number}"))?; #[allow(clippy::comparison_chain)] Ok(if sign == 0 { parsed diff --git a/components/dada-lex/src/lex.rs b/components/dada-lex/src/lex.rs index d3a3d53e..df6e1308 100644 --- a/components/dada-lex/src/lex.rs +++ b/components/dada-lex/src/lex.rs @@ -44,7 +44,7 @@ pub fn closing_delimiter(ch: char) -> char { '(' => ')', '[' => ']', '{' => '}', - _ => panic!("not a delimiter: {:?}", ch), + _ => panic!("not a delimiter: {ch:?}"), } } diff --git a/components/dada-parse/src/parser/expr.rs b/components/dada-parse/src/parser/expr.rs index b0963440..b16afd1d 100644 --- a/components/dada-parse/src/parser/expr.rs +++ b/components/dada-parse/src/parser/expr.rs @@ -433,9 +433,7 @@ impl CodeParser<'_, '_> { fn parse_required_sub_expr(&mut self, token_tree: TokenTree) -> Expr { let db = self.db; self.with_sub_parser(token_tree, |sub_parser| sub_parser.parse_only_expr()) - .or_report_error_at(self, token_tree.span(db), || { - "expected expression here".to_string() - }) + .or_report_error_at(self, token_tree.span(db), || "expected expression here") .or_dummy_expr(self) } diff --git a/components/dada-parse/src/parser/items.rs b/components/dada-parse/src/parser/items.rs index cf8f3afe..f8abcfa0 100644 --- a/components/dada-parse/src/parser/items.rs +++ b/components/dada-parse/src/parser/items.rs @@ -97,9 +97,7 @@ impl<'db> Parser<'db> { .or_report_error(&mut signature_parser, || "expected a class name")?; let parameters = signature_parser .parse_parameter_list() - .or_report_error(&mut signature_parser, || { - "expected class parameters".to_string() - })?; + .or_report_error(&mut signature_parser, || "expected class parameters")?; let signature = syntax::Signature::new( name, fn_decl, @@ -137,9 +135,7 @@ impl<'db> Parser<'db> { let fn_kw = signature_parser.parse_fn().unwrap(); // we peeked above, it should be there let name = signature_parser .parse_name() - .or_report_error(&mut signature_parser, || { - "expected function name".to_string() - })?; + .or_report_error(&mut signature_parser, || "expected function name")?; let parameters = signature_parser .parse_parameter_list() .or_report_error(&mut signature_parser, || { @@ -148,7 +144,7 @@ impl<'db> Parser<'db> { let return_type = signature_parser.parse_return_type(); let (_, body_tokens) = self .delimited('{') - .or_report_error(self, || "expected function body".to_string())?; + .or_report_error(self, || "expected function body")?; let code = UnparsedCode::new(body_tokens); let signature = syntax::Signature::new( name, diff --git a/components/dada-parse/src/parser/ty.rs b/components/dada-parse/src/parser/ty.rs index f8b3b8ba..5cbbe9d0 100644 --- a/components/dada-parse/src/parser/ty.rs +++ b/components/dada-parse/src/parser/ty.rs @@ -11,8 +11,8 @@ impl CodeParser<'_, '_> { let Some(colon_span) = self.eat_op(Op::Colon) else { return None }; let opt_ty = self.parse_ty(); if opt_ty.is_none() { - self.error_at_current_token(&"expected type after `:`".to_string()) - .secondary_label(colon_span, "`:` is here".to_string()) + self.error_at_current_token("expected type after `:`") + .secondary_label(colon_span, "`:` is here") .emit(self.db); } opt_ty diff --git a/components/dada-parse/src/tokens.rs b/components/dada-parse/src/tokens.rs index 57d261dc..f2571b9d 100644 --- a/components/dada-parse/src/tokens.rs +++ b/components/dada-parse/src/tokens.rs @@ -101,6 +101,7 @@ impl<'me> Tokens<'me> { /// Span of the previously consumed token (or `Span::start` otherwise). /// Does not include any skipped tokens. + #[allow(clippy::misnamed_getters)] pub(crate) fn last_span(&self) -> Span { self.last_not_skipped_span } diff --git a/components/dada-validate/src/validate/validator.rs b/components/dada-validate/src/validate/validator.rs index 7fe679ac..a7b3b58f 100644 --- a/components/dada-validate/src/validate/validator.rs +++ b/components/dada-validate/src/validate/validator.rs @@ -249,7 +249,7 @@ impl<'me> Validator<'me> { }, _ => parse_error( self, - format!("`{}` is not a valid integer suffxi", suffix_str), + format!("`{suffix_str}` is not a valid integer suffxi"), ), } } diff --git a/components/dada-validate/src/validate/validator/string_literals.rs b/components/dada-validate/src/validate/validator/string_literals.rs index 460f86c2..a5b65139 100644 --- a/components/dada-validate/src/validate/validator/string_literals.rs +++ b/components/dada-validate/src/validate/validator/string_literals.rs @@ -58,7 +58,7 @@ impl Validator<'_> { '"' => '\"', '{' => '{', '}' => '}', - _ => panic!("not a escape: {:?}", ch), + _ => panic!("not a escape: {ch:?}"), } } } diff --git a/components/dada-web/src/lib.rs b/components/dada-web/src/lib.rs index db3130c9..064d2ce2 100644 --- a/components/dada-web/src/lib.rs +++ b/components/dada-web/src/lib.rs @@ -92,7 +92,7 @@ impl DadaCompiler { self.output = String::new(); for item in self.db.items(self.input_file) { if let Some(tree) = self.db.debug_syntax_tree(item) { - let _ = write!(self.output, "{:#?}", tree); + let _ = write!(self.output, "{tree:#?}"); self.output.push('\n'); } } @@ -104,7 +104,7 @@ impl DadaCompiler { self.output = String::new(); for item in self.db.items(self.input_file) { if let Some(tree) = self.db.debug_validated_tree(item) { - let _ = write!(self.output, "{:#?}", tree); + let _ = write!(self.output, "{tree:#?}"); self.output.push('\n'); } } @@ -116,7 +116,7 @@ impl DadaCompiler { self.output = String::new(); for item in self.db.items(self.input_file) { if let Some(tree) = self.db.debug_bir(item) { - let _ = write!(self.output, "{:#?}", tree); + let _ = write!(self.output, "{tree:#?}"); self.output.push('\n'); } }