diff --git a/build.rs b/build.rs index bb438f0c5..96aa2273a 100644 --- a/build.rs +++ b/build.rs @@ -14,6 +14,6 @@ fn main() -> std::io::Result<()> { version.micro.unwrap_or(0) ); let magic_number = env_magic_number(); - println!("cargo:rustc-env=PYTHON_MAGIC_NUMBER={}", magic_number); + println!("cargo:rustc-env=PYTHON_MAGIC_NUMBER={magic_number}"); Ok(()) } diff --git a/crates/els/hover.rs b/crates/els/hover.rs index fbbe6e3a0..54c7fc2f4 100644 --- a/crates/els/hover.rs +++ b/crates/els/hover.rs @@ -84,7 +84,7 @@ impl Server { let relative = relative .strip_prefix(self.erg_path.to_str().unwrap()) .unwrap_or(relative); - format!("# {}, line {line}\n", relative) + format!("# {relative}, line {line}\n") }; // display the definition line if vi.kind.is_defined() { diff --git a/crates/els/server.rs b/crates/els/server.rs index 504e4868c..94ff3ae4d 100644 --- a/crates/els/server.rs +++ b/crates/els/server.rs @@ -201,7 +201,7 @@ impl Server { if res.len() != 2 { return Err(io::Error::new( io::ErrorKind::InvalidData, - format!("Header '{}' is malformed", buffer), + format!("Header '{buffer}' is malformed"), )); } let header_name = res[0].to_lowercase(); @@ -217,7 +217,7 @@ impl Server { if header_value != "utf8" && header_value != "utf-8" { return Err(io::Error::new( io::ErrorKind::InvalidData, - format!("Content type '{}' is invalid", header_value), + format!("Content type '{header_value}' is invalid"), )); } } @@ -291,7 +291,7 @@ impl Server { self.check_file(uri, &code) } // "textDocument/didChange" - _ => Self::send_log(format!("received notification: {}", method)), + _ => Self::send_log(format!("received notification: {method}")), } } diff --git a/crates/erg_common/config.rs b/crates/erg_common/config.rs index c904239ce..6d8e1c3f0 100644 --- a/crates/erg_common/config.rs +++ b/crates/erg_common/config.rs @@ -618,7 +618,7 @@ USAGE: } _ => { let path = PathBuf::from_str(&arg[..]) - .unwrap_or_else(|_| panic!("invalid file path: {}", arg)); + .unwrap_or_else(|_| panic!("invalid file path: {arg}")); let path = normalize_path(path); cfg.input = Input::File(path); if let Some("--") = args.next().as_ref().map(|s| &s[..]) { diff --git a/crates/erg_common/error.rs b/crates/erg_common/error.rs index fc402de4b..668aa064e 100644 --- a/crates/erg_common/error.rs +++ b/crates/erg_common/error.rs @@ -374,10 +374,7 @@ fn format_context( let (vbreak, vbar) = chars.gutters(); let offset = format!("{} {} ", &" ".repeat(max_digit), vbreak); for (i, lineno) in (ln_begin..=ln_end).enumerate() { - context.push_str_with_color( - &format!("{: { let (_, vbar) = chars.gutters(); let mut cxt = StyledStrings::default(); - cxt.push_str_with_color(&format!(" ? {} ", vbar), gutter_color); + cxt.push_str_with_color(&format!(" ? {vbar} "), gutter_color); cxt.push_str(&other.reread()); cxt.push_str("\n"); for msg in self.msg.iter() { diff --git a/crates/erg_common/style.rs b/crates/erg_common/style.rs index 07b824e0e..64db7a54a 100644 --- a/crates/erg_common/style.rs +++ b/crates/erg_common/style.rs @@ -348,7 +348,7 @@ impl StyledString { } impl std::fmt::Display for StyledString { - fn fmt<'a>(&self, f: &mut std::fmt::Formatter<'a>) -> std::fmt::Result { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match (self.color, self.attribute) { (None, None) => write!(f, "{}", self.text), (None, Some(attr)) => write!(f, "{}{}{}", attr.as_str(), self.text, ATTR_RESET), @@ -493,7 +493,7 @@ impl StyledStrings { impl std::fmt::Display for StyledStrings { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { for text in self.texts.iter() { - write!(f, "{}", text)?; + write!(f, "{text}")?; } Ok(()) } @@ -563,6 +563,6 @@ mod tests { Color::Red, Attribute::Reversed, ); - println!("{}", texts); + println!("{texts}"); } } diff --git a/crates/erg_compiler/context/initialize/const_func.rs b/crates/erg_compiler/context/initialize/const_func.rs index 92ef96eca..58a5e7cc7 100644 --- a/crates/erg_compiler/context/initialize/const_func.rs +++ b/crates/erg_compiler/context/initialize/const_func.rs @@ -290,7 +290,7 @@ pub fn __range_getitem__(mut args: ValueArgs, _ctx: &Context) -> EvalValueResult } else { Err(ErrorCore::new( vec![SubMessage::only_loc(Location::Unknown)], - format!("Index out of range: {}", index), + format!("Index out of range: {index}"), line!() as usize, ErrorKind::IndexError, Location::Unknown, diff --git a/crates/erg_compiler/context/initialize/mod.rs b/crates/erg_compiler/context/initialize/mod.rs index 748fec6b3..1c1d54ab8 100644 --- a/crates/erg_compiler/context/initialize/mod.rs +++ b/crates/erg_compiler/context/initialize/mod.rs @@ -780,7 +780,7 @@ impl Context { muty: Mutability, ) { if self.patches.contains_key(name) { - panic!("{} has already been registered", name); + panic!("{name} has already been registered"); } else { let name = VarName::from_static(name); let vi = VarInfo::new( diff --git a/crates/erg_compiler/error/lower.rs b/crates/erg_compiler/error/lower.rs index de339061a..900524bee 100644 --- a/crates/erg_compiler/error/lower.rs +++ b/crates/erg_compiler/error/lower.rs @@ -127,8 +127,8 @@ impl LowerError { found_t: &Type, ) -> Self { let name = StyledString::new(readable_name(name), Some(WARN), None); - let expect = StyledString::new(format!("{}", spec_t), Some(HINT), Some(ATTR)); - let found = StyledString::new(format!("{}", found_t), Some(ERR), Some(ATTR)); + let expect = StyledString::new(format!("{spec_t}"), Some(HINT), Some(ATTR)); + let found = StyledString::new(format!("{found_t}"), Some(ERR), Some(ATTR)); Self::new( ErrorCore::new( vec![SubMessage::only_loc(loc)], @@ -522,7 +522,7 @@ impl LowerError { caused_by: S, ) -> Self { let name = StyledString::new(name, Some(ERR), Some(ATTR)); - let superclass = StyledString::new(format!("{}", superclass), Some(WARN), Some(ATTR)); + let superclass = StyledString::new(format!("{superclass}"), Some(WARN), Some(ATTR)); let hint = Some( switch_lang!( "japanese" => { @@ -854,7 +854,7 @@ impl LowerError { hint: Option, ) -> Self { let name = StyledString::new(name, Some(WARN), Some(ATTR)); - let found = StyledString::new(format!("{}", cast_to), Some(ERR), Some(ATTR)); + let found = StyledString::new(format!("{cast_to}"), Some(ERR), Some(ATTR)); Self::new( ErrorCore::new( vec![SubMessage::ambiguous_new(loc, vec![], hint)], diff --git a/crates/erg_compiler/error/tycheck.rs b/crates/erg_compiler/error/tycheck.rs index 07a78e2bc..e9c945d5d 100644 --- a/crates/erg_compiler/error/tycheck.rs +++ b/crates/erg_compiler/error/tycheck.rs @@ -127,7 +127,7 @@ impl TyCheckError { ), None => "".to_owned(), }; - let name = StyledString::new(format!("{}{}", name, ord), Some(WARN), Some(ATTR)); + let name = StyledString::new(format!("{name}{ord}"), Some(WARN), Some(ATTR)); let mut expct = StyledStrings::default(); switch_lang!( "japanese" => expct.push_str("予期した型: "), @@ -135,7 +135,7 @@ impl TyCheckError { "traditional_chinese" => expct.push_str("預期: "), "english" => expct.push_str("expected: "), ); - expct.push_str_with_color_and_attribute(format!("{}", expect), HINT, ATTR); + expct.push_str_with_color_and_attribute(format!("{expect}"), HINT, ATTR); let mut fnd = StyledStrings::default(); switch_lang!( @@ -144,7 +144,7 @@ impl TyCheckError { "traditional_chinese" => fnd.push_str("但找到: "), "english" =>fnd.push_str("but found: "), ); - fnd.push_str_with_color_and_attribute(format!("{}", found), ERR, ATTR); + fnd.push_str_with_color_and_attribute(format!("{found}"), ERR, ATTR); Self::new( ErrorCore::new( vec![SubMessage::ambiguous_new( @@ -183,7 +183,7 @@ impl TyCheckError { "traditional_chinese" => expct.push_str("預期: "), "english" => expct.push_str("expected: "), ); - expct.push_str_with_color_and_attribute(format!("{}", expect), HINT, ATTR); + expct.push_str_with_color_and_attribute(format!("{expect}"), HINT, ATTR); let mut fnd = StyledStrings::default(); switch_lang!( @@ -192,7 +192,7 @@ impl TyCheckError { "traditional_chinese" => fnd.push_str("但找到: "), "english" =>fnd.push_str("but found: "), ); - fnd.push_str_with_color_and_attribute(format!("{}", found), ERR, ATTR); + fnd.push_str_with_color_and_attribute(format!("{found}"), ERR, ATTR); Self::new( ErrorCore::new( @@ -257,7 +257,7 @@ impl TyCheckError { "traditional_chinese" => expct.push_str("預期: "), "english" => expct.push_str("expected: "), ); - expct.push_str_with_color_and_attribute(format!("{}", expect), HINT, ATTR); + expct.push_str_with_color_and_attribute(format!("{expect}"), HINT, ATTR); let mut fnd = StyledStrings::default(); switch_lang!( @@ -266,7 +266,7 @@ impl TyCheckError { "traditional_chinese" => fnd.push_str("但找到: "), "english" =>fnd.push_str("but found: "), ); - fnd.push_str_with_color_and_attribute(format!("{}", found), ERR, ATTR); + fnd.push_str_with_color_and_attribute(format!("{found}"), ERR, ATTR); Self::new( ErrorCore::new( @@ -305,7 +305,7 @@ impl TyCheckError { "traditional_chinese" => expct.push_str("預期: "), "english" => expct.push_str("expected: "), ); - expct.push_str_with_color_and_attribute(format!("{}", expect), HINT, ATTR); + expct.push_str_with_color_and_attribute(format!("{expect}"), HINT, ATTR); let mut fnd = StyledStrings::default(); switch_lang!( @@ -314,7 +314,7 @@ impl TyCheckError { "traditional_chinese" => fnd.push_str("但找到: "), "english" =>fnd.push_str("but found: "), ); - fnd.push_str_with_color_and_attribute(format!("{}", found), ERR, ATTR); + fnd.push_str_with_color_and_attribute(format!("{found}"), ERR, ATTR); Self::new( ErrorCore::new( @@ -433,9 +433,9 @@ impl TyCheckError { kw_args_len: usize, ) -> Self { let name = readable_name(callee_name); - let expect = StyledString::new(format!("{}", params_len), Some(HINT), Some(ATTR)); - let pos_args_len = StyledString::new(format!("{}", pos_args_len), Some(ERR), Some(ATTR)); - let kw_args_len = StyledString::new(format!("{}", kw_args_len), Some(ERR), Some(ATTR)); + let expect = StyledString::new(format!("{params_len}"), Some(HINT), Some(ATTR)); + let pos_args_len = StyledString::new(format!("{pos_args_len}"), Some(ERR), Some(ATTR)); + let kw_args_len = StyledString::new(format!("{kw_args_len}"), Some(ERR), Some(ATTR)); Self::new( ErrorCore::new( vec![SubMessage::only_loc(loc)], @@ -576,7 +576,7 @@ passed keyword args: {kw_args_len}" "traditional_chinese" => lhs_typ.push_str("左邊: "), "english" => lhs_typ.push_str("lhs: "), ); - lhs_typ.push_str_with_color_and_attribute(format!("{}", lhs_t), WARN, ATTR); + lhs_typ.push_str_with_color_and_attribute(format!("{lhs_t}"), WARN, ATTR); let mut rhs_typ = StyledStrings::default(); switch_lang!( "japanese" => rhs_typ.push_str("右辺: "), @@ -584,7 +584,7 @@ passed keyword args: {kw_args_len}" "traditional_chinese" => rhs_typ.push_str("右邊: "), "english" => rhs_typ.push_str("rhs: "), ); - rhs_typ.push_str_with_color_and_attribute(format!("{}", rhs_t), WARN, ATTR); + rhs_typ.push_str_with_color_and_attribute(format!("{rhs_t}"), WARN, ATTR); Self::new( ErrorCore::new( vec![SubMessage::ambiguous_new( @@ -622,7 +622,7 @@ passed keyword args: {kw_args_len}" "traditional_chinese" => lhs_typ.push_str("左邊: "), "english" => lhs_typ.push_str("lhs: "), ); - lhs_typ.push_str_with_color_and_attribute(format!("{}", lhs_t), WARN, ATTR); + lhs_typ.push_str_with_color_and_attribute(format!("{lhs_t}"), WARN, ATTR); let mut rhs_typ = StyledStrings::default(); switch_lang!( "japanese" => rhs_typ.push_str("右辺: "), @@ -630,7 +630,7 @@ passed keyword args: {kw_args_len}" "traditional_chinese" => rhs_typ.push_str("右邊: "), "english" => rhs_typ.push_str("rhs: "), ); - rhs_typ.push_str_with_color_and_attribute(format!("{}", rhs_t), WARN, ATTR); + rhs_typ.push_str_with_color_and_attribute(format!("{rhs_t}"), WARN, ATTR); Self::new( ErrorCore::new( vec![SubMessage::ambiguous_new( @@ -668,7 +668,7 @@ passed keyword args: {kw_args_len}" "simplified_chinese" =>sub_type.push_str("子類型:"), "english" => sub_type.push_str("subtype: "), ); - sub_type.push_str_with_color_and_attribute(format!("{}", sub_t), HINT, ATTR); + sub_type.push_str_with_color_and_attribute(format!("{sub_t}"), HINT, ATTR); let mut sup_type = StyledStrings::default(); switch_lang!( @@ -677,7 +677,7 @@ passed keyword args: {kw_args_len}" "simplified_chinese" => sup_type.push_str("父類型: "), "english" =>sup_type.push_str("supertype: "), ); - sup_type.push_str_with_color_and_attribute(format!("{}", sup_t), ERR, ATTR); + sup_type.push_str_with_color_and_attribute(format!("{sup_t}"), ERR, ATTR); let hint = switch_lang!( "japanese" => "型推論が失敗している可能性があります。型を明示的に指定してみてください。", "simplified_chinese" => "可能是编译器推断失败。请尝试明确指定类型。", @@ -720,7 +720,7 @@ passed keyword args: {kw_args_len}" "traditional_chinese" => lhs_uni.push_str("左邊: "), "english" => lhs_uni.push_str("lhs: "), ); - lhs_uni.push_str_with_color_and_attribute(format!("{}", lhs), HINT, ATTR); + lhs_uni.push_str_with_color_and_attribute(format!("{lhs}"), HINT, ATTR); let mut rhs_uni = StyledStrings::default(); switch_lang!( "japanese" => rhs_uni.push_str("右辺: "), @@ -728,7 +728,7 @@ passed keyword args: {kw_args_len}" "traditional_chinese" => rhs_uni.push_str("右邊: "), "english" => rhs_uni.push_str("rhs: "), ); - rhs_uni.push_str_with_color_and_attribute(format!("{}", rhs), ERR, ATTR); + rhs_uni.push_str_with_color_and_attribute(format!("{rhs}"), ERR, ATTR); Self::new( ErrorCore::new( vec![SubMessage::ambiguous_new( @@ -854,23 +854,23 @@ passed keyword args: {kw_args_len}" let mut expct = StyledStrings::default(); switch_lang!( "japanese" => { - expct.push_str_with_color_and_attribute(format!("{}", trait_type), ACCENT, ATTR); + expct.push_str_with_color_and_attribute(format!("{trait_type}"), ACCENT, ATTR); expct.push_str("で宣言された型: "); }, "simplified_chinese" => { - expct.push_str_with_color_and_attribute(format!("{}", trait_type), ACCENT, ATTR); + expct.push_str_with_color_and_attribute(format!("{trait_type}"), ACCENT, ATTR); expct.push_str("中声明的类型: "); }, "traditional_chinese" => { - expct.push_str_with_color_and_attribute(format!("{}", trait_type), ACCENT, ATTR); + expct.push_str_with_color_and_attribute(format!("{trait_type}"), ACCENT, ATTR); expct.push_str("中聲明的類型: "); }, "english" => { expct.push_str("declared in "); - expct.push_str_with_color(format!("{}: ", trait_type), ACCENT); + expct.push_str_with_color(format!("{trait_type}: "), ACCENT); }, ); - expct.push_str_with_color(format!("{}", expect), HINT); + expct.push_str_with_color(format!("{expect}"), HINT); let mut fnd = StyledStrings::default(); switch_lang!( "japanese" => fnd.push_str("与えられた型: "), @@ -878,7 +878,7 @@ passed keyword args: {kw_args_len}" "traditional_chinese" => fnd.push_str("但找到: "), "english" => fnd.push_str("but found: "), ); - fnd.push_str_with_color(format!("{}", found), ERR); + fnd.push_str_with_color(format!("{found}"), ERR); let member_name = StyledStr::new(member_name, Some(WARN), Some(ATTR)); Self::new( ErrorCore::new( diff --git a/crates/erg_compiler/hir.rs b/crates/erg_compiler/hir.rs index babebe87b..fc0e1d856 100644 --- a/crates/erg_compiler/hir.rs +++ b/crates/erg_compiler/hir.rs @@ -394,7 +394,7 @@ impl NestedDisplay for Identifier { } } if let Some(qn) = &self.qual_name { - write!(f, "(qual_name: {})", qn)?; + write!(f, "(qual_name: {qn})")?; } if self.vi.t != Type::Uninited { write!(f, "(: {})", self.vi.t)?; diff --git a/crates/erg_compiler/ty/codeobj.rs b/crates/erg_compiler/ty/codeobj.rs index 3aa7391e0..27a97e926 100644 --- a/crates/erg_compiler/ty/codeobj.rs +++ b/crates/erg_compiler/ty/codeobj.rs @@ -489,7 +489,7 @@ impl CodeObj { fn read_instr_308(&self, op: &u8, arg: &u8, idx: usize, instrs: &mut String) { let op308 = Opcode308::from(*op); let s_op = op308.to_string(); - write!(instrs, "{:>15} {:<25}", idx, s_op).unwrap(); + write!(instrs, "{idx:>15} {s_op:<25}").unwrap(); if let Ok(op) = CommonOpcode::try_from(*op) { self.dump_additional_info(op, arg, idx, instrs); } @@ -531,7 +531,7 @@ impl CodeObj { fn read_instr_310(&self, op: &u8, arg: &u8, idx: usize, instrs: &mut String) { let op310 = Opcode310::from(*op); let s_op = op310.to_string(); - write!(instrs, "{:>15} {:<25}", idx, s_op).unwrap(); + write!(instrs, "{idx:>15} {s_op:<25}").unwrap(); if let Ok(op) = CommonOpcode::try_from(*op) { self.dump_additional_info(op, arg, idx, instrs); } diff --git a/crates/erg_compiler/ty/deserialize.rs b/crates/erg_compiler/ty/deserialize.rs index 3970d70b1..aa64648f9 100644 --- a/crates/erg_compiler/ty/deserialize.rs +++ b/crates/erg_compiler/ty/deserialize.rs @@ -258,10 +258,10 @@ impl Deserializer { 0, fn_name!(), switch_lang!( - "japanese" => format!("このオブジェクトは復元できません: {}", other), - "simplified_chinese" => format!("无法反序列化此对象: {}", other), - "traditional_chinese" => format!("無法反序列化此對象: {}", other), - "english" => format!("cannot deserialize this object: {}", other), + "japanese" => format!("このオブジェクトは復元できません: {other}"), + "simplified_chinese" => format!("无法反序列化此对象: {other}"), + "traditional_chinese" => format!("無法反序列化此對象: {other}"), + "english" => format!("cannot deserialize this object: {other}"), ), )), } diff --git a/crates/erg_compiler/ty/mod.rs b/crates/erg_compiler/ty/mod.rs index f8bda602d..47364d808 100644 --- a/crates/erg_compiler/ty/mod.rs +++ b/crates/erg_compiler/ty/mod.rs @@ -149,13 +149,13 @@ impl fmt::Display for ParamTy { match self { Self::Pos { name, ty } => { if let Some(name) = name { - write!(f, "{}", name)?; + write!(f, "{name}")?; } - write!(f, ": {}", ty) + write!(f, ": {ty}") } - Self::Kw { name, ty } => write!(f, "{}: {}", name, ty), + Self::Kw { name, ty } => write!(f, "{name}: {ty}"), Self::KwWithDefault { name, ty, default } => { - write!(f, "{}: {} := {}", name, ty, default) + write!(f, "{name}: {ty} := {default}") } } } @@ -397,7 +397,7 @@ impl LimitedDisplay for RefinementType { write!(f, "{{")?; for pred in self.preds.iter() { let (_, rhs) = enum_unwrap!(pred, Predicate::Equal { lhs, rhs }); - write!(f, "{}, ", rhs)?; + write!(f, "{rhs}, ")?; } write!(f, "}}")?; if cfg!(feature = "debug") { diff --git a/crates/erg_compiler/ty/typaram.rs b/crates/erg_compiler/ty/typaram.rs index 14157d8f6..a668375f9 100644 --- a/crates/erg_compiler/ty/typaram.rs +++ b/crates/erg_compiler/ty/typaram.rs @@ -246,16 +246,16 @@ impl LimitedDisplay for TyParam { Self::Type(t) => t.limited_fmt(f, limit - 1), Self::FreeVar(fv) => fv.limited_fmt(f, limit - 1), Self::UnaryOp { op, val } => { - write!(f, "{}", op)?; + write!(f, "{op}")?; val.limited_fmt(f, limit - 1) } Self::BinOp { op, lhs, rhs } => { lhs.limited_fmt(f, limit - 1)?; - write!(f, " {} ", op)?; + write!(f, " {op} ")?; rhs.limited_fmt(f, limit - 1) } Self::App { name, args } => { - write!(f, "{}", name)?; + write!(f, "{name}")?; write!(f, "(")?; for (i, arg) in args.iter().enumerate() { if i > 0 { @@ -270,10 +270,10 @@ impl LimitedDisplay for TyParam { write!(f, "_: ")?; t.limited_fmt(f, limit - 1) } - Self::Mono(name) => write!(f, "{}", name), + Self::Mono(name) => write!(f, "{name}"), Self::Proj { obj, attr } => { - write!(f, "{}.", obj)?; - write!(f, "{}", attr) + write!(f, "{obj}.")?; + write!(f, "{attr}") } Self::Array(arr) => { write!(f, "[")?; diff --git a/crates/erg_compiler/ty/value.rs b/crates/erg_compiler/ty/value.rs index 33f9d9afd..c5357e486 100644 --- a/crates/erg_compiler/ty/value.rs +++ b/crates/erg_compiler/ty/value.rs @@ -455,7 +455,7 @@ impl fmt::Debug for ValueObj { if i != 0 { write!(f, ", ")?; } - write!(f, "{}: {}", k, v)?; + write!(f, "{k}: {v}")?; } write!(f, "}}") } @@ -977,7 +977,7 @@ impl ValueObj { (Self::Int(l), Self::Float(r)) => Some(Self::Float(l as f64 - r)), (Self::Nat(l), Self::Float(r)) => Some(Self::Float(l as f64 - r)), (Self::Float(l), Self::Int(r)) => Some(Self::Float(l - r as f64)), - (Self::Str(l), Self::Str(r)) => Some(Self::Str(Str::from(format!("{}{}", l, r)))), + (Self::Str(l), Self::Str(r)) => Some(Self::Str(Str::from(format!("{l}{r}")))), (inf @ (Self::Inf | Self::NegInf), _) | (_, inf @ (Self::Inf | Self::NegInf)) => { Some(inf) } diff --git a/crates/erg_parser/ast.rs b/crates/erg_parser/ast.rs index a9d068a11..9b283355d 100644 --- a/crates/erg_parser/ast.rs +++ b/crates/erg_parser/ast.rs @@ -553,7 +553,7 @@ impl NestedDisplay for ArrayComprehension { fn fmt_nest(&self, f: &mut fmt::Formatter<'_>, _level: usize) -> fmt::Result { let mut generators = String::new(); for (name, gen) in self.generators.iter() { - write!(generators, "{} <- {}, ", name, gen).unwrap(); + write!(generators, "{name} <- {gen}, ")?; } write!( f, @@ -890,7 +890,7 @@ impl NestedDisplay for MixedRecord { fn fmt_nest(&self, f: &mut fmt::Formatter<'_>, _level: usize) -> fmt::Result { write!(f, "{{")?; for attr in self.attrs.iter() { - write!(f, "{}; ", attr)?; + write!(f, "{attr}; ")?; } write!(f, "}}") } @@ -1063,7 +1063,7 @@ impl NestedDisplay for Call { write!(f, "{}", self.obj)?; } if let Some(attr_name) = self.attr_name.as_ref() { - write!(f, "{}", attr_name)?; + write!(f, "{attr_name}")?; } if self.args.is_empty() { write!(f, "()") @@ -2654,11 +2654,11 @@ impl NestedDisplay for VarPattern { fn fmt_nest(&self, f: &mut fmt::Formatter<'_>, _level: usize) -> fmt::Result { match self { Self::Discard(_) => write!(f, "_"), - Self::Ident(ident) => write!(f, "{}", ident), - Self::Array(a) => write!(f, "{}", a), - Self::Tuple(t) => write!(f, "{}", t), - Self::Record(r) => write!(f, "{}", r), - Self::DataPack(d) => write!(f, "{}", d), + Self::Ident(ident) => write!(f, "{ident}"), + Self::Array(a) => write!(f, "{a}"), + Self::Tuple(t) => write!(f, "{t}"), + Self::Record(r) => write!(f, "{r}"), + Self::DataPack(d) => write!(f, "{d}"), } } } @@ -2921,14 +2921,14 @@ pub enum ParamPattern { impl NestedDisplay for ParamPattern { fn fmt_nest(&self, f: &mut fmt::Formatter<'_>, _level: usize) -> fmt::Result { match self { - Self::Discard(tok) => write!(f, "{}", tok), - Self::VarName(var_name) => write!(f, "{}", var_name), - Self::Lit(lit) => write!(f, "{}", lit), - Self::Array(array) => write!(f, "{}", array), - Self::Tuple(tuple) => write!(f, "{}", tuple), - Self::Record(record) => write!(f, "{}", record), - Self::Ref(var_name) => write!(f, "ref {}", var_name), - Self::RefMut(var_name) => write!(f, "ref! {}", var_name), + Self::Discard(tok) => write!(f, "{tok}"), + Self::VarName(var_name) => write!(f, "{var_name}"), + Self::Lit(lit) => write!(f, "{lit}"), + Self::Array(array) => write!(f, "{array}"), + Self::Tuple(tuple) => write!(f, "{tuple}"), + Self::Record(record) => write!(f, "{record}"), + Self::Ref(var_name) => write!(f, "ref {var_name}"), + Self::RefMut(var_name) => write!(f, "ref! {var_name}"), } } } diff --git a/crates/erg_parser/error.rs b/crates/erg_parser/error.rs index 5c68eeaa9..6eb31f02f 100644 --- a/crates/erg_parser/error.rs +++ b/crates/erg_parser/error.rs @@ -239,22 +239,22 @@ impl LexError { let expect = switch_lang!( "japanese" => { expect.push_str("期待された構文: "); - expect.push_str_with_color(&format!("!{}", lit), HINT); + expect.push_str_with_color(&format!("!{lit}"), HINT); expect }, "simplified_chinese" => { expect.push_str("预期语法: "); - expect.push_str_with_color(&format!("!{}", lit), HINT); + expect.push_str_with_color(&format!("!{lit}"), HINT); expect }, "traditional_chinese" => { expect.push_str("預期語法: "); - expect.push_str_with_color(&format!("!{}", lit), HINT); + expect.push_str_with_color(&format!("!{lit}"), HINT); expect }, "english" => { expect.push_str("expected: "); - expect.push_str_with_color(&format!("!{}", lit), HINT); + expect.push_str_with_color(&format!("!{lit}"), HINT); expect }, ) @@ -263,22 +263,22 @@ impl LexError { let found = switch_lang!( "japanese" => { found.push_str("見つかった構文: "); - found.push_str_with_color(&format!("{}!", lit), ERR); + found.push_str_with_color(&format!("{lit}!"), ERR); found }, "simplified_chinese" => { found.push_str("找到语法: "); - found.push_str_with_color(&format!("{}!", lit), ERR); + found.push_str_with_color(&format!("{lit}!"), ERR); found }, "traditional_chinese" => { found.push_str("找到語法: "); - found.push_str_with_color(&format!("{}!", lit), ERR); + found.push_str_with_color(&format!("{lit}!"), ERR); found }, "english" => { found.push_str("but found: "); - found.push_str_with_color(&format!("{}!", lit), ERR); + found.push_str_with_color(&format!("{lit}!"), ERR); found }, ) diff --git a/crates/erg_parser/lex.rs b/crates/erg_parser/lex.rs index 19e61ee49..26e76072d 100644 --- a/crates/erg_parser/lex.rs +++ b/crates/erg_parser/lex.rs @@ -393,10 +393,10 @@ impl Lexer /*<'a>*/ { } let comment = self.emit_token(Illegal, &s); let hint = switch_lang!( - "japanese" => format!("`]#`の数があと{}個必要です", nest_level), - "simplified_chinese" => format!("需要{}个`]#`", nest_level), - "traditional_chinese" => format!("需要{}個`]#`", nest_level), - "english" => format!("{} `]#`(s) are needed", nest_level), + "japanese" => format!("`]#`の数があと{nest_level}個必要です"), + "simplified_chinese" => format!("需要{nest_level}个`]#`"), + "traditional_chinese" => format!("需要{nest_level}個`]#`"), + "english" => format!("{nest_level} `]#`(s) are needed"), ); Err(LexError::syntax_error( line!() as usize, @@ -731,10 +731,10 @@ impl Lexer /*<'a>*/ { line!() as usize, token.loc(), switch_lang!( - "japanese" => format!("不正なエスケープシーケンスです: \\{}", ch), - "simplified_chinese" => format!("不合法的转义序列: \\{}", ch), - "traditional_chinese" => format!("不合法的轉義序列: \\{}", ch), - "english" => format!("illegal escape sequence: \\{}", ch), + "japanese" => format!("不正なエスケープシーケンスです: \\{ch}"), + "simplified_chinese" => format!("不合法的转义序列: \\{ch}"), + "traditional_chinese" => format!("不合法的轉義序列: \\{ch}"), + "english" => format!("illegal escape sequence: \\{ch}"), ), None, )