Fix warns

This commit is contained in:
Shunsuke Shibayama 2023-01-27 11:10:14 +09:00
parent 0019147007
commit 44781cb030
19 changed files with 96 additions and 99 deletions

View file

@ -14,6 +14,6 @@ fn main() -> std::io::Result<()> {
version.micro.unwrap_or(0) version.micro.unwrap_or(0)
); );
let magic_number = env_magic_number(); 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(()) Ok(())
} }

View file

@ -84,7 +84,7 @@ impl<Checker: BuildRunnable> Server<Checker> {
let relative = relative let relative = relative
.strip_prefix(self.erg_path.to_str().unwrap()) .strip_prefix(self.erg_path.to_str().unwrap())
.unwrap_or(relative); .unwrap_or(relative);
format!("# {}, line {line}\n", relative) format!("# {relative}, line {line}\n")
}; };
// display the definition line // display the definition line
if vi.kind.is_defined() { if vi.kind.is_defined() {

View file

@ -201,7 +201,7 @@ impl<Checker: BuildRunnable> Server<Checker> {
if res.len() != 2 { if res.len() != 2 {
return Err(io::Error::new( return Err(io::Error::new(
io::ErrorKind::InvalidData, io::ErrorKind::InvalidData,
format!("Header '{}' is malformed", buffer), format!("Header '{buffer}' is malformed"),
)); ));
} }
let header_name = res[0].to_lowercase(); let header_name = res[0].to_lowercase();
@ -217,7 +217,7 @@ impl<Checker: BuildRunnable> Server<Checker> {
if header_value != "utf8" && header_value != "utf-8" { if header_value != "utf8" && header_value != "utf-8" {
return Err(io::Error::new( return Err(io::Error::new(
io::ErrorKind::InvalidData, io::ErrorKind::InvalidData,
format!("Content type '{}' is invalid", header_value), format!("Content type '{header_value}' is invalid"),
)); ));
} }
} }
@ -291,7 +291,7 @@ impl<Checker: BuildRunnable> Server<Checker> {
self.check_file(uri, &code) self.check_file(uri, &code)
} }
// "textDocument/didChange" // "textDocument/didChange"
_ => Self::send_log(format!("received notification: {}", method)), _ => Self::send_log(format!("received notification: {method}")),
} }
} }

View file

@ -618,7 +618,7 @@ USAGE:
} }
_ => { _ => {
let path = PathBuf::from_str(&arg[..]) 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); let path = normalize_path(path);
cfg.input = Input::File(path); cfg.input = Input::File(path);
if let Some("--") = args.next().as_ref().map(|s| &s[..]) { if let Some("--") = args.next().as_ref().map(|s| &s[..]) {

View file

@ -374,10 +374,7 @@ fn format_context<E: ErrorDisplay + ?Sized>(
let (vbreak, vbar) = chars.gutters(); let (vbreak, vbar) = chars.gutters();
let offset = format!("{} {} ", &" ".repeat(max_digit), vbreak); let offset = format!("{} {} ", &" ".repeat(max_digit), vbreak);
for (i, lineno) in (ln_begin..=ln_end).enumerate() { for (i, lineno) in (ln_begin..=ln_end).enumerate() {
context.push_str_with_color( context.push_str_with_color(&format!("{lineno:<max_digit$} {vbar} "), gutter_color);
&format!("{:<max_digit$} {vbar} ", lineno, vbar = vbar),
gutter_color,
);
context.push_str(codes.get(i).unwrap_or(&String::new())); context.push_str(codes.get(i).unwrap_or(&String::new()));
context.push_str("\n"); context.push_str("\n");
context.push_str_with_color(&offset, gutter_color); context.push_str_with_color(&offset, gutter_color);
@ -578,7 +575,7 @@ impl SubMessage {
.remove(0) .remove(0)
}; };
let mut cxt = StyledStrings::default(); let mut cxt = StyledStrings::default();
cxt.push_str_with_color(&format!(" {lineno} {} ", vbar), gutter_color); cxt.push_str_with_color(&format!(" {lineno} {vbar} "), gutter_color);
cxt.push_str(&code); cxt.push_str(&code);
cxt.push_str("\n"); cxt.push_str("\n");
for msg in self.msg.iter() { for msg in self.msg.iter() {
@ -597,7 +594,7 @@ impl SubMessage {
other => { other => {
let (_, vbar) = chars.gutters(); let (_, vbar) = chars.gutters();
let mut cxt = StyledStrings::default(); 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(&other.reread());
cxt.push_str("\n"); cxt.push_str("\n");
for msg in self.msg.iter() { for msg in self.msg.iter() {

View file

@ -348,7 +348,7 @@ impl StyledString {
} }
impl std::fmt::Display for 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) { match (self.color, self.attribute) {
(None, None) => write!(f, "{}", self.text), (None, None) => write!(f, "{}", self.text),
(None, Some(attr)) => write!(f, "{}{}{}", attr.as_str(), self.text, ATTR_RESET), (None, Some(attr)) => write!(f, "{}{}{}", attr.as_str(), self.text, ATTR_RESET),
@ -493,7 +493,7 @@ impl StyledStrings {
impl std::fmt::Display for StyledStrings { impl std::fmt::Display for StyledStrings {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
for text in self.texts.iter() { for text in self.texts.iter() {
write!(f, "{}", text)?; write!(f, "{text}")?;
} }
Ok(()) Ok(())
} }
@ -563,6 +563,6 @@ mod tests {
Color::Red, Color::Red,
Attribute::Reversed, Attribute::Reversed,
); );
println!("{}", texts); println!("{texts}");
} }
} }

View file

@ -290,7 +290,7 @@ pub fn __range_getitem__(mut args: ValueArgs, _ctx: &Context) -> EvalValueResult
} else { } else {
Err(ErrorCore::new( Err(ErrorCore::new(
vec![SubMessage::only_loc(Location::Unknown)], vec![SubMessage::only_loc(Location::Unknown)],
format!("Index out of range: {}", index), format!("Index out of range: {index}"),
line!() as usize, line!() as usize,
ErrorKind::IndexError, ErrorKind::IndexError,
Location::Unknown, Location::Unknown,

View file

@ -780,7 +780,7 @@ impl Context {
muty: Mutability, muty: Mutability,
) { ) {
if self.patches.contains_key(name) { if self.patches.contains_key(name) {
panic!("{} has already been registered", name); panic!("{name} has already been registered");
} else { } else {
let name = VarName::from_static(name); let name = VarName::from_static(name);
let vi = VarInfo::new( let vi = VarInfo::new(

View file

@ -127,8 +127,8 @@ impl LowerError {
found_t: &Type, found_t: &Type,
) -> Self { ) -> Self {
let name = StyledString::new(readable_name(name), Some(WARN), None); let name = StyledString::new(readable_name(name), Some(WARN), None);
let expect = StyledString::new(format!("{}", spec_t), Some(HINT), Some(ATTR)); let expect = StyledString::new(format!("{spec_t}"), Some(HINT), Some(ATTR));
let found = StyledString::new(format!("{}", found_t), Some(ERR), Some(ATTR)); let found = StyledString::new(format!("{found_t}"), Some(ERR), Some(ATTR));
Self::new( Self::new(
ErrorCore::new( ErrorCore::new(
vec![SubMessage::only_loc(loc)], vec![SubMessage::only_loc(loc)],
@ -522,7 +522,7 @@ impl LowerError {
caused_by: S, caused_by: S,
) -> Self { ) -> Self {
let name = StyledString::new(name, Some(ERR), Some(ATTR)); 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( let hint = Some(
switch_lang!( switch_lang!(
"japanese" => { "japanese" => {
@ -854,7 +854,7 @@ impl LowerError {
hint: Option<String>, hint: Option<String>,
) -> Self { ) -> Self {
let name = StyledString::new(name, Some(WARN), Some(ATTR)); 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( Self::new(
ErrorCore::new( ErrorCore::new(
vec![SubMessage::ambiguous_new(loc, vec![], hint)], vec![SubMessage::ambiguous_new(loc, vec![], hint)],

View file

@ -127,7 +127,7 @@ impl TyCheckError {
), ),
None => "".to_owned(), 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(); let mut expct = StyledStrings::default();
switch_lang!( switch_lang!(
"japanese" => expct.push_str("予期した型: "), "japanese" => expct.push_str("予期した型: "),
@ -135,7 +135,7 @@ impl TyCheckError {
"traditional_chinese" => expct.push_str("預期: "), "traditional_chinese" => expct.push_str("預期: "),
"english" => expct.push_str("expected: "), "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(); let mut fnd = StyledStrings::default();
switch_lang!( switch_lang!(
@ -144,7 +144,7 @@ impl TyCheckError {
"traditional_chinese" => fnd.push_str("但找到: "), "traditional_chinese" => fnd.push_str("但找到: "),
"english" =>fnd.push_str("but found: "), "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( Self::new(
ErrorCore::new( ErrorCore::new(
vec![SubMessage::ambiguous_new( vec![SubMessage::ambiguous_new(
@ -183,7 +183,7 @@ impl TyCheckError {
"traditional_chinese" => expct.push_str("預期: "), "traditional_chinese" => expct.push_str("預期: "),
"english" => expct.push_str("expected: "), "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(); let mut fnd = StyledStrings::default();
switch_lang!( switch_lang!(
@ -192,7 +192,7 @@ impl TyCheckError {
"traditional_chinese" => fnd.push_str("但找到: "), "traditional_chinese" => fnd.push_str("但找到: "),
"english" =>fnd.push_str("but found: "), "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( Self::new(
ErrorCore::new( ErrorCore::new(
@ -257,7 +257,7 @@ impl TyCheckError {
"traditional_chinese" => expct.push_str("預期: "), "traditional_chinese" => expct.push_str("預期: "),
"english" => expct.push_str("expected: "), "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(); let mut fnd = StyledStrings::default();
switch_lang!( switch_lang!(
@ -266,7 +266,7 @@ impl TyCheckError {
"traditional_chinese" => fnd.push_str("但找到: "), "traditional_chinese" => fnd.push_str("但找到: "),
"english" =>fnd.push_str("but found: "), "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( Self::new(
ErrorCore::new( ErrorCore::new(
@ -305,7 +305,7 @@ impl TyCheckError {
"traditional_chinese" => expct.push_str("預期: "), "traditional_chinese" => expct.push_str("預期: "),
"english" => expct.push_str("expected: "), "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(); let mut fnd = StyledStrings::default();
switch_lang!( switch_lang!(
@ -314,7 +314,7 @@ impl TyCheckError {
"traditional_chinese" => fnd.push_str("但找到: "), "traditional_chinese" => fnd.push_str("但找到: "),
"english" =>fnd.push_str("but found: "), "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( Self::new(
ErrorCore::new( ErrorCore::new(
@ -433,9 +433,9 @@ impl TyCheckError {
kw_args_len: usize, kw_args_len: usize,
) -> Self { ) -> Self {
let name = readable_name(callee_name); let name = readable_name(callee_name);
let expect = StyledString::new(format!("{}", params_len), Some(HINT), 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 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 kw_args_len = StyledString::new(format!("{kw_args_len}"), Some(ERR), Some(ATTR));
Self::new( Self::new(
ErrorCore::new( ErrorCore::new(
vec![SubMessage::only_loc(loc)], vec![SubMessage::only_loc(loc)],
@ -576,7 +576,7 @@ passed keyword args: {kw_args_len}"
"traditional_chinese" => lhs_typ.push_str("左邊: "), "traditional_chinese" => lhs_typ.push_str("左邊: "),
"english" => lhs_typ.push_str("lhs: "), "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(); let mut rhs_typ = StyledStrings::default();
switch_lang!( switch_lang!(
"japanese" => rhs_typ.push_str("右辺: "), "japanese" => rhs_typ.push_str("右辺: "),
@ -584,7 +584,7 @@ passed keyword args: {kw_args_len}"
"traditional_chinese" => rhs_typ.push_str("右邊: "), "traditional_chinese" => rhs_typ.push_str("右邊: "),
"english" => rhs_typ.push_str("rhs: "), "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( Self::new(
ErrorCore::new( ErrorCore::new(
vec![SubMessage::ambiguous_new( vec![SubMessage::ambiguous_new(
@ -622,7 +622,7 @@ passed keyword args: {kw_args_len}"
"traditional_chinese" => lhs_typ.push_str("左邊: "), "traditional_chinese" => lhs_typ.push_str("左邊: "),
"english" => lhs_typ.push_str("lhs: "), "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(); let mut rhs_typ = StyledStrings::default();
switch_lang!( switch_lang!(
"japanese" => rhs_typ.push_str("右辺: "), "japanese" => rhs_typ.push_str("右辺: "),
@ -630,7 +630,7 @@ passed keyword args: {kw_args_len}"
"traditional_chinese" => rhs_typ.push_str("右邊: "), "traditional_chinese" => rhs_typ.push_str("右邊: "),
"english" => rhs_typ.push_str("rhs: "), "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( Self::new(
ErrorCore::new( ErrorCore::new(
vec![SubMessage::ambiguous_new( vec![SubMessage::ambiguous_new(
@ -668,7 +668,7 @@ passed keyword args: {kw_args_len}"
"simplified_chinese" =>sub_type.push_str("子類型:"), "simplified_chinese" =>sub_type.push_str("子類型:"),
"english" => sub_type.push_str("subtype: "), "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(); let mut sup_type = StyledStrings::default();
switch_lang!( switch_lang!(
@ -677,7 +677,7 @@ passed keyword args: {kw_args_len}"
"simplified_chinese" => sup_type.push_str("父類型: "), "simplified_chinese" => sup_type.push_str("父類型: "),
"english" =>sup_type.push_str("supertype: "), "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!( let hint = switch_lang!(
"japanese" => "型推論が失敗している可能性があります。型を明示的に指定してみてください。", "japanese" => "型推論が失敗している可能性があります。型を明示的に指定してみてください。",
"simplified_chinese" => "可能是编译器推断失败。请尝试明确指定类型。", "simplified_chinese" => "可能是编译器推断失败。请尝试明确指定类型。",
@ -720,7 +720,7 @@ passed keyword args: {kw_args_len}"
"traditional_chinese" => lhs_uni.push_str("左邊: "), "traditional_chinese" => lhs_uni.push_str("左邊: "),
"english" => lhs_uni.push_str("lhs: "), "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(); let mut rhs_uni = StyledStrings::default();
switch_lang!( switch_lang!(
"japanese" => rhs_uni.push_str("右辺: "), "japanese" => rhs_uni.push_str("右辺: "),
@ -728,7 +728,7 @@ passed keyword args: {kw_args_len}"
"traditional_chinese" => rhs_uni.push_str("右邊: "), "traditional_chinese" => rhs_uni.push_str("右邊: "),
"english" => rhs_uni.push_str("rhs: "), "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( Self::new(
ErrorCore::new( ErrorCore::new(
vec![SubMessage::ambiguous_new( vec![SubMessage::ambiguous_new(
@ -854,23 +854,23 @@ passed keyword args: {kw_args_len}"
let mut expct = StyledStrings::default(); let mut expct = StyledStrings::default();
switch_lang!( switch_lang!(
"japanese" => { "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("で宣言された型: "); expct.push_str("で宣言された型: ");
}, },
"simplified_chinese" => { "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("中声明的类型: "); expct.push_str("中声明的类型: ");
}, },
"traditional_chinese" => { "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("中聲明的類型: "); expct.push_str("中聲明的類型: ");
}, },
"english" => { "english" => {
expct.push_str("declared in "); 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(); let mut fnd = StyledStrings::default();
switch_lang!( switch_lang!(
"japanese" => fnd.push_str("与えられた型: "), "japanese" => fnd.push_str("与えられた型: "),
@ -878,7 +878,7 @@ passed keyword args: {kw_args_len}"
"traditional_chinese" => fnd.push_str("但找到: "), "traditional_chinese" => fnd.push_str("但找到: "),
"english" => fnd.push_str("but found: "), "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)); let member_name = StyledStr::new(member_name, Some(WARN), Some(ATTR));
Self::new( Self::new(
ErrorCore::new( ErrorCore::new(

View file

@ -394,7 +394,7 @@ impl NestedDisplay for Identifier {
} }
} }
if let Some(qn) = &self.qual_name { if let Some(qn) = &self.qual_name {
write!(f, "(qual_name: {})", qn)?; write!(f, "(qual_name: {qn})")?;
} }
if self.vi.t != Type::Uninited { if self.vi.t != Type::Uninited {
write!(f, "(: {})", self.vi.t)?; write!(f, "(: {})", self.vi.t)?;

View file

@ -489,7 +489,7 @@ impl CodeObj {
fn read_instr_308(&self, op: &u8, arg: &u8, idx: usize, instrs: &mut String) { fn read_instr_308(&self, op: &u8, arg: &u8, idx: usize, instrs: &mut String) {
let op308 = Opcode308::from(*op); let op308 = Opcode308::from(*op);
let s_op = op308.to_string(); 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) { if let Ok(op) = CommonOpcode::try_from(*op) {
self.dump_additional_info(op, arg, idx, instrs); 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) { fn read_instr_310(&self, op: &u8, arg: &u8, idx: usize, instrs: &mut String) {
let op310 = Opcode310::from(*op); let op310 = Opcode310::from(*op);
let s_op = op310.to_string(); 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) { if let Ok(op) = CommonOpcode::try_from(*op) {
self.dump_additional_info(op, arg, idx, instrs); self.dump_additional_info(op, arg, idx, instrs);
} }

View file

@ -258,10 +258,10 @@ impl Deserializer {
0, 0,
fn_name!(), fn_name!(),
switch_lang!( switch_lang!(
"japanese" => format!("このオブジェクトは復元できません: {}", other), "japanese" => format!("このオブジェクトは復元できません: {other}"),
"simplified_chinese" => format!("无法反序列化此对象: {}", other), "simplified_chinese" => format!("无法反序列化此对象: {other}"),
"traditional_chinese" => format!("無法反序列化此對象: {}", other), "traditional_chinese" => format!("無法反序列化此對象: {other}"),
"english" => format!("cannot deserialize this object: {}", other), "english" => format!("cannot deserialize this object: {other}"),
), ),
)), )),
} }

View file

@ -149,13 +149,13 @@ impl fmt::Display for ParamTy {
match self { match self {
Self::Pos { name, ty } => { Self::Pos { name, ty } => {
if let Some(name) = name { 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 } => { 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, "{{")?; write!(f, "{{")?;
for pred in self.preds.iter() { for pred in self.preds.iter() {
let (_, rhs) = enum_unwrap!(pred, Predicate::Equal { lhs, rhs }); let (_, rhs) = enum_unwrap!(pred, Predicate::Equal { lhs, rhs });
write!(f, "{}, ", rhs)?; write!(f, "{rhs}, ")?;
} }
write!(f, "}}")?; write!(f, "}}")?;
if cfg!(feature = "debug") { if cfg!(feature = "debug") {

View file

@ -246,16 +246,16 @@ impl LimitedDisplay for TyParam {
Self::Type(t) => t.limited_fmt(f, limit - 1), Self::Type(t) => t.limited_fmt(f, limit - 1),
Self::FreeVar(fv) => fv.limited_fmt(f, limit - 1), Self::FreeVar(fv) => fv.limited_fmt(f, limit - 1),
Self::UnaryOp { op, val } => { Self::UnaryOp { op, val } => {
write!(f, "{}", op)?; write!(f, "{op}")?;
val.limited_fmt(f, limit - 1) val.limited_fmt(f, limit - 1)
} }
Self::BinOp { op, lhs, rhs } => { Self::BinOp { op, lhs, rhs } => {
lhs.limited_fmt(f, limit - 1)?; lhs.limited_fmt(f, limit - 1)?;
write!(f, " {} ", op)?; write!(f, " {op} ")?;
rhs.limited_fmt(f, limit - 1) rhs.limited_fmt(f, limit - 1)
} }
Self::App { name, args } => { Self::App { name, args } => {
write!(f, "{}", name)?; write!(f, "{name}")?;
write!(f, "(")?; write!(f, "(")?;
for (i, arg) in args.iter().enumerate() { for (i, arg) in args.iter().enumerate() {
if i > 0 { if i > 0 {
@ -270,10 +270,10 @@ impl LimitedDisplay for TyParam {
write!(f, "_: ")?; write!(f, "_: ")?;
t.limited_fmt(f, limit - 1) t.limited_fmt(f, limit - 1)
} }
Self::Mono(name) => write!(f, "{}", name), Self::Mono(name) => write!(f, "{name}"),
Self::Proj { obj, attr } => { Self::Proj { obj, attr } => {
write!(f, "{}.", obj)?; write!(f, "{obj}.")?;
write!(f, "{}", attr) write!(f, "{attr}")
} }
Self::Array(arr) => { Self::Array(arr) => {
write!(f, "[")?; write!(f, "[")?;

View file

@ -455,7 +455,7 @@ impl fmt::Debug for ValueObj {
if i != 0 { if i != 0 {
write!(f, ", ")?; write!(f, ", ")?;
} }
write!(f, "{}: {}", k, v)?; write!(f, "{k}: {v}")?;
} }
write!(f, "}}") write!(f, "}}")
} }
@ -977,7 +977,7 @@ impl ValueObj {
(Self::Int(l), Self::Float(r)) => Some(Self::Float(l as f64 - r)), (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::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::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)) => { (inf @ (Self::Inf | Self::NegInf), _) | (_, inf @ (Self::Inf | Self::NegInf)) => {
Some(inf) Some(inf)
} }

View file

@ -553,7 +553,7 @@ impl NestedDisplay for ArrayComprehension {
fn fmt_nest(&self, f: &mut fmt::Formatter<'_>, _level: usize) -> fmt::Result { fn fmt_nest(&self, f: &mut fmt::Formatter<'_>, _level: usize) -> fmt::Result {
let mut generators = String::new(); let mut generators = String::new();
for (name, gen) in self.generators.iter() { for (name, gen) in self.generators.iter() {
write!(generators, "{} <- {}, ", name, gen).unwrap(); write!(generators, "{name} <- {gen}, ")?;
} }
write!( write!(
f, f,
@ -890,7 +890,7 @@ impl NestedDisplay for MixedRecord {
fn fmt_nest(&self, f: &mut fmt::Formatter<'_>, _level: usize) -> fmt::Result { fn fmt_nest(&self, f: &mut fmt::Formatter<'_>, _level: usize) -> fmt::Result {
write!(f, "{{")?; write!(f, "{{")?;
for attr in self.attrs.iter() { for attr in self.attrs.iter() {
write!(f, "{}; ", attr)?; write!(f, "{attr}; ")?;
} }
write!(f, "}}") write!(f, "}}")
} }
@ -1063,7 +1063,7 @@ impl NestedDisplay for Call {
write!(f, "{}", self.obj)?; write!(f, "{}", self.obj)?;
} }
if let Some(attr_name) = self.attr_name.as_ref() { if let Some(attr_name) = self.attr_name.as_ref() {
write!(f, "{}", attr_name)?; write!(f, "{attr_name}")?;
} }
if self.args.is_empty() { if self.args.is_empty() {
write!(f, "()") write!(f, "()")
@ -2654,11 +2654,11 @@ impl NestedDisplay for VarPattern {
fn fmt_nest(&self, f: &mut fmt::Formatter<'_>, _level: usize) -> fmt::Result { fn fmt_nest(&self, f: &mut fmt::Formatter<'_>, _level: usize) -> fmt::Result {
match self { match self {
Self::Discard(_) => write!(f, "_"), Self::Discard(_) => write!(f, "_"),
Self::Ident(ident) => write!(f, "{}", ident), Self::Ident(ident) => write!(f, "{ident}"),
Self::Array(a) => write!(f, "{}", a), Self::Array(a) => write!(f, "{a}"),
Self::Tuple(t) => write!(f, "{}", t), Self::Tuple(t) => write!(f, "{t}"),
Self::Record(r) => write!(f, "{}", r), Self::Record(r) => write!(f, "{r}"),
Self::DataPack(d) => write!(f, "{}", d), Self::DataPack(d) => write!(f, "{d}"),
} }
} }
} }
@ -2921,14 +2921,14 @@ pub enum ParamPattern {
impl NestedDisplay for ParamPattern { impl NestedDisplay for ParamPattern {
fn fmt_nest(&self, f: &mut fmt::Formatter<'_>, _level: usize) -> fmt::Result { fn fmt_nest(&self, f: &mut fmt::Formatter<'_>, _level: usize) -> fmt::Result {
match self { match self {
Self::Discard(tok) => write!(f, "{}", tok), Self::Discard(tok) => write!(f, "{tok}"),
Self::VarName(var_name) => write!(f, "{}", var_name), Self::VarName(var_name) => write!(f, "{var_name}"),
Self::Lit(lit) => write!(f, "{}", lit), Self::Lit(lit) => write!(f, "{lit}"),
Self::Array(array) => write!(f, "{}", array), Self::Array(array) => write!(f, "{array}"),
Self::Tuple(tuple) => write!(f, "{}", tuple), Self::Tuple(tuple) => write!(f, "{tuple}"),
Self::Record(record) => write!(f, "{}", record), Self::Record(record) => write!(f, "{record}"),
Self::Ref(var_name) => write!(f, "ref {}", var_name), Self::Ref(var_name) => write!(f, "ref {var_name}"),
Self::RefMut(var_name) => write!(f, "ref! {}", var_name), Self::RefMut(var_name) => write!(f, "ref! {var_name}"),
} }
} }
} }

View file

@ -239,22 +239,22 @@ impl LexError {
let expect = switch_lang!( let expect = switch_lang!(
"japanese" => { "japanese" => {
expect.push_str("期待された構文: "); expect.push_str("期待された構文: ");
expect.push_str_with_color(&format!("!{}", lit), HINT); expect.push_str_with_color(&format!("!{lit}"), HINT);
expect expect
}, },
"simplified_chinese" => { "simplified_chinese" => {
expect.push_str("预期语法: "); expect.push_str("预期语法: ");
expect.push_str_with_color(&format!("!{}", lit), HINT); expect.push_str_with_color(&format!("!{lit}"), HINT);
expect expect
}, },
"traditional_chinese" => { "traditional_chinese" => {
expect.push_str("預期語法: "); expect.push_str("預期語法: ");
expect.push_str_with_color(&format!("!{}", lit), HINT); expect.push_str_with_color(&format!("!{lit}"), HINT);
expect expect
}, },
"english" => { "english" => {
expect.push_str("expected: "); expect.push_str("expected: ");
expect.push_str_with_color(&format!("!{}", lit), HINT); expect.push_str_with_color(&format!("!{lit}"), HINT);
expect expect
}, },
) )
@ -263,22 +263,22 @@ impl LexError {
let found = switch_lang!( let found = switch_lang!(
"japanese" => { "japanese" => {
found.push_str("見つかった構文: "); found.push_str("見つかった構文: ");
found.push_str_with_color(&format!("{}!", lit), ERR); found.push_str_with_color(&format!("{lit}!"), ERR);
found found
}, },
"simplified_chinese" => { "simplified_chinese" => {
found.push_str("找到语法: "); found.push_str("找到语法: ");
found.push_str_with_color(&format!("{}!", lit), ERR); found.push_str_with_color(&format!("{lit}!"), ERR);
found found
}, },
"traditional_chinese" => { "traditional_chinese" => {
found.push_str("找到語法: "); found.push_str("找到語法: ");
found.push_str_with_color(&format!("{}!", lit), ERR); found.push_str_with_color(&format!("{lit}!"), ERR);
found found
}, },
"english" => { "english" => {
found.push_str("but found: "); found.push_str("but found: ");
found.push_str_with_color(&format!("{}!", lit), ERR); found.push_str_with_color(&format!("{lit}!"), ERR);
found found
}, },
) )

View file

@ -393,10 +393,10 @@ impl Lexer /*<'a>*/ {
} }
let comment = self.emit_token(Illegal, &s); let comment = self.emit_token(Illegal, &s);
let hint = switch_lang!( let hint = switch_lang!(
"japanese" => format!("`]#`の数があと{}個必要です", nest_level), "japanese" => format!("`]#`の数があと{nest_level}個必要です"),
"simplified_chinese" => format!("需要{}个`]#`", nest_level), "simplified_chinese" => format!("需要{nest_level}个`]#`"),
"traditional_chinese" => format!("需要{}個`]#`", nest_level), "traditional_chinese" => format!("需要{nest_level}個`]#`"),
"english" => format!("{} `]#`(s) are needed", nest_level), "english" => format!("{nest_level} `]#`(s) are needed"),
); );
Err(LexError::syntax_error( Err(LexError::syntax_error(
line!() as usize, line!() as usize,
@ -731,10 +731,10 @@ impl Lexer /*<'a>*/ {
line!() as usize, line!() as usize,
token.loc(), token.loc(),
switch_lang!( switch_lang!(
"japanese" => format!("不正なエスケープシーケンスです: \\{}", ch), "japanese" => format!("不正なエスケープシーケンスです: \\{ch}"),
"simplified_chinese" => format!("不合法的转义序列: \\{}", ch), "simplified_chinese" => format!("不合法的转义序列: \\{ch}"),
"traditional_chinese" => format!("不合法的轉義序列: \\{}", ch), "traditional_chinese" => format!("不合法的轉義序列: \\{ch}"),
"english" => format!("illegal escape sequence: \\{}", ch), "english" => format!("illegal escape sequence: \\{ch}"),
), ),
None, None,
) )