Skip to content

Commit

Permalink
Fix warns
Browse files Browse the repository at this point in the history
  • Loading branch information
mtshiba committed Jan 27, 2023
1 parent 0019147 commit 44781cb
Show file tree
Hide file tree
Showing 19 changed files with 96 additions and 99 deletions.
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
2 changes: 1 addition & 1 deletion crates/els/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl<Checker: BuildRunnable> Server<Checker> {
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() {
Expand Down
6 changes: 3 additions & 3 deletions crates/els/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl<Checker: BuildRunnable> Server<Checker> {
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();
Expand All @@ -217,7 +217,7 @@ impl<Checker: BuildRunnable> Server<Checker> {
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"),
));
}
}
Expand Down Expand Up @@ -291,7 +291,7 @@ impl<Checker: BuildRunnable> Server<Checker> {
self.check_file(uri, &code)
}
// "textDocument/didChange"
_ => Self::send_log(format!("received notification: {}", method)),
_ => Self::send_log(format!("received notification: {method}")),
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/erg_common/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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[..]) {
Expand Down
9 changes: 3 additions & 6 deletions crates/erg_common/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,7 @@ fn format_context<E: ErrorDisplay + ?Sized>(
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!("{:<max_digit$} {vbar} ", lineno, vbar = vbar),
gutter_color,
);
context.push_str_with_color(&format!("{lineno:<max_digit$} {vbar} "), gutter_color);
context.push_str(codes.get(i).unwrap_or(&String::new()));
context.push_str("\n");
context.push_str_with_color(&offset, gutter_color);
Expand Down Expand Up @@ -578,7 +575,7 @@ impl SubMessage {
.remove(0)
};
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("\n");
for msg in self.msg.iter() {
Expand All @@ -597,7 +594,7 @@ impl SubMessage {
other => {
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() {
Expand Down
6 changes: 3 additions & 3 deletions crates/erg_common/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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(())
}
Expand Down Expand Up @@ -563,6 +563,6 @@ mod tests {
Color::Red,
Attribute::Reversed,
);
println!("{}", texts);
println!("{texts}");
}
}
2 changes: 1 addition & 1 deletion crates/erg_compiler/context/initialize/const_func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion crates/erg_compiler/context/initialize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions crates/erg_compiler/error/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)],
Expand Down Expand Up @@ -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" => {
Expand Down Expand Up @@ -854,7 +854,7 @@ impl LowerError {
hint: Option<String>,
) -> 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)],
Expand Down
52 changes: 26 additions & 26 deletions crates/erg_compiler/error/tycheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ 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("予期した型: "),
"simplified_chinese" =>expct.push_str("预期: "),
"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!(
Expand All @@ -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(
Expand Down Expand Up @@ -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!(
Expand All @@ -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(
Expand Down Expand Up @@ -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!(
Expand All @@ -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(
Expand Down Expand Up @@ -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!(
Expand All @@ -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(
Expand Down Expand Up @@ -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)],
Expand Down Expand Up @@ -576,15 +576,15 @@ 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("右辺: "),
"simplified_chinese" => rhs_typ.push_str("右边: "),
"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(
Expand Down Expand Up @@ -622,15 +622,15 @@ 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("右辺: "),
"simplified_chinese" => rhs_typ.push_str("右边: "),
"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(
Expand Down Expand Up @@ -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!(
Expand All @@ -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" => "可能是编译器推断失败。请尝试明确指定类型。",
Expand Down Expand Up @@ -720,15 +720,15 @@ 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("右辺: "),
"simplified_chinese" => rhs_uni.push_str("右边: "),
"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(
Expand Down Expand Up @@ -854,31 +854,31 @@ 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("与えられた型: "),
"simplified_chinese" => fnd.push_str("但找到: "),
"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(
Expand Down
2 changes: 1 addition & 1 deletion crates/erg_compiler/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
4 changes: 2 additions & 2 deletions crates/erg_compiler/ty/codeobj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
Loading

0 comments on commit 44781cb

Please sign in to comment.