mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 22:54:58 +00:00
Inline all format arguments where possible
This makes code more readale and concise, moving all format arguments like `format!("{}", foo)` into the more compact `format!("{foo}")` form. The change was automatically created with, so there are far less change of an accidental typo. ``` cargo clippy --fix -- -A clippy::all -W clippy::uninlined_format_args ```
This commit is contained in:
parent
1927c2e1d8
commit
e16c76e3c3
180 changed files with 487 additions and 501 deletions
|
@ -142,7 +142,7 @@ impl<D> TyBuilder<D> {
|
|||
match (a.data(Interner), e) {
|
||||
(chalk_ir::GenericArgData::Ty(_), ParamKind::Type)
|
||||
| (chalk_ir::GenericArgData::Const(_), ParamKind::Const(_)) => (),
|
||||
_ => panic!("Mismatched kinds: {:?}, {:?}, {:?}", a, self.vec, self.param_kinds),
|
||||
_ => panic!("Mismatched kinds: {a:?}, {:?}, {:?}", self.vec, self.param_kinds),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,14 +90,14 @@ impl Display for ComputedExpr {
|
|||
ComputedExpr::Literal(l) => match l {
|
||||
Literal::Int(x, _) => {
|
||||
if *x >= 10 {
|
||||
write!(f, "{} ({:#X})", x, x)
|
||||
write!(f, "{x} ({x:#X})")
|
||||
} else {
|
||||
x.fmt(f)
|
||||
}
|
||||
}
|
||||
Literal::Uint(x, _) => {
|
||||
if *x >= 10 {
|
||||
write!(f, "{} ({:#X})", x, x)
|
||||
write!(f, "{x} ({x:#X})")
|
||||
} else {
|
||||
x.fmt(f)
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ fn check_number(ra_fixture: &str, answer: i128) {
|
|||
match r {
|
||||
ComputedExpr::Literal(Literal::Int(r, _)) => assert_eq!(r, answer),
|
||||
ComputedExpr::Literal(Literal::Uint(r, _)) => assert_eq!(r, answer as u128),
|
||||
x => panic!("Expected number but found {:?}", x),
|
||||
x => panic!("Expected number but found {x:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -126,7 +126,7 @@ fn enums() {
|
|||
assert_eq!(name, "E::A");
|
||||
assert_eq!(val, 1);
|
||||
}
|
||||
x => panic!("Expected enum but found {:?}", x),
|
||||
x => panic!("Expected enum but found {x:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -386,7 +386,7 @@ impl HirDisplay for Pat {
|
|||
}
|
||||
subpattern.hir_fmt(f)
|
||||
}
|
||||
PatKind::LiteralBool { value } => write!(f, "{}", value),
|
||||
PatKind::LiteralBool { value } => write!(f, "{value}"),
|
||||
PatKind::Or { pats } => f.write_joined(pats.iter(), " | "),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -372,7 +372,7 @@ impl Constructor {
|
|||
hir_def::AdtId::UnionId(id) => id.into(),
|
||||
}
|
||||
}
|
||||
_ => panic!("bad constructor {:?} for adt {:?}", self, adt),
|
||||
_ => panic!("bad constructor {self:?} for adt {adt:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -176,13 +176,13 @@ impl<'a> HirFormatter<'a> {
|
|||
let mut first = true;
|
||||
for e in iter {
|
||||
if !first {
|
||||
write!(self, "{}", sep)?;
|
||||
write!(self, "{sep}")?;
|
||||
}
|
||||
first = false;
|
||||
|
||||
// Abbreviate multiple omitted types with a single ellipsis.
|
||||
if self.should_truncate() {
|
||||
return write!(self, "{}", TYPE_HINT_TRUNCATION);
|
||||
return write!(self, "{TYPE_HINT_TRUNCATION}");
|
||||
}
|
||||
|
||||
e.hir_fmt(self)?;
|
||||
|
@ -320,7 +320,7 @@ impl<T: HirDisplay + Internable> HirDisplay for Interned<T> {
|
|||
impl HirDisplay for ProjectionTy {
|
||||
fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
|
||||
if f.should_truncate() {
|
||||
return write!(f, "{}", TYPE_HINT_TRUNCATION);
|
||||
return write!(f, "{TYPE_HINT_TRUNCATION}");
|
||||
}
|
||||
|
||||
let trait_ref = self.trait_ref(f.db);
|
||||
|
@ -342,7 +342,7 @@ impl HirDisplay for ProjectionTy {
|
|||
impl HirDisplay for OpaqueTy {
|
||||
fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
|
||||
if f.should_truncate() {
|
||||
return write!(f, "{}", TYPE_HINT_TRUNCATION);
|
||||
return write!(f, "{TYPE_HINT_TRUNCATION}");
|
||||
}
|
||||
|
||||
self.substitution.at(Interner, 0).hir_fmt(f)
|
||||
|
@ -385,7 +385,7 @@ impl HirDisplay for BoundVar {
|
|||
impl HirDisplay for Ty {
|
||||
fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
|
||||
if f.should_truncate() {
|
||||
return write!(f, "{}", TYPE_HINT_TRUNCATION);
|
||||
return write!(f, "{TYPE_HINT_TRUNCATION}");
|
||||
}
|
||||
|
||||
match self.kind(Interner) {
|
||||
|
@ -572,7 +572,7 @@ impl HirDisplay for Ty {
|
|||
hir_def::AdtId::UnionId(it) => f.db.union_data(it).name.clone(),
|
||||
hir_def::AdtId::EnumId(it) => f.db.enum_data(it).name.clone(),
|
||||
};
|
||||
write!(f, "{}", name)?;
|
||||
write!(f, "{name}")?;
|
||||
}
|
||||
DisplayTarget::SourceCode { module_id } => {
|
||||
if let Some(path) = find_path::find_path(
|
||||
|
@ -581,7 +581,7 @@ impl HirDisplay for Ty {
|
|||
module_id,
|
||||
false,
|
||||
) {
|
||||
write!(f, "{}", path)?;
|
||||
write!(f, "{path}")?;
|
||||
} else {
|
||||
return Err(HirDisplayError::DisplaySourceCodeError(
|
||||
DisplaySourceCodeError::PathNotFound,
|
||||
|
@ -737,7 +737,7 @@ impl HirDisplay for Ty {
|
|||
if sig.params().is_empty() {
|
||||
write!(f, "||")?;
|
||||
} else if f.should_truncate() {
|
||||
write!(f, "|{}|", TYPE_HINT_TRUNCATION)?;
|
||||
write!(f, "|{TYPE_HINT_TRUNCATION}|")?;
|
||||
} else {
|
||||
write!(f, "|")?;
|
||||
f.write_joined(sig.params(), ", ")?;
|
||||
|
@ -928,7 +928,7 @@ pub fn write_bounds_like_dyn_trait_with_prefix(
|
|||
default_sized: SizedByDefault,
|
||||
f: &mut HirFormatter<'_>,
|
||||
) -> Result<(), HirDisplayError> {
|
||||
write!(f, "{}", prefix)?;
|
||||
write!(f, "{prefix}")?;
|
||||
if !predicates.is_empty()
|
||||
|| predicates.is_empty() && matches!(default_sized, SizedByDefault::Sized { .. })
|
||||
{
|
||||
|
@ -1056,7 +1056,7 @@ fn fmt_trait_ref(
|
|||
use_as: bool,
|
||||
) -> Result<(), HirDisplayError> {
|
||||
if f.should_truncate() {
|
||||
return write!(f, "{}", TYPE_HINT_TRUNCATION);
|
||||
return write!(f, "{TYPE_HINT_TRUNCATION}");
|
||||
}
|
||||
|
||||
tr.self_type_parameter(Interner).hir_fmt(f)?;
|
||||
|
@ -1083,7 +1083,7 @@ impl HirDisplay for TraitRef {
|
|||
impl HirDisplay for WhereClause {
|
||||
fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
|
||||
if f.should_truncate() {
|
||||
return write!(f, "{}", TYPE_HINT_TRUNCATION);
|
||||
return write!(f, "{TYPE_HINT_TRUNCATION}");
|
||||
}
|
||||
|
||||
match self {
|
||||
|
@ -1197,7 +1197,7 @@ impl HirDisplay for TypeRef {
|
|||
hir_def::type_ref::Mutability::Shared => "*const ",
|
||||
hir_def::type_ref::Mutability::Mut => "*mut ",
|
||||
};
|
||||
write!(f, "{}", mutability)?;
|
||||
write!(f, "{mutability}")?;
|
||||
inner.hir_fmt(f)?;
|
||||
}
|
||||
TypeRef::Reference(inner, lifetime, mutability) => {
|
||||
|
@ -1209,13 +1209,13 @@ impl HirDisplay for TypeRef {
|
|||
if let Some(lifetime) = lifetime {
|
||||
write!(f, "{} ", lifetime.name)?;
|
||||
}
|
||||
write!(f, "{}", mutability)?;
|
||||
write!(f, "{mutability}")?;
|
||||
inner.hir_fmt(f)?;
|
||||
}
|
||||
TypeRef::Array(inner, len) => {
|
||||
write!(f, "[")?;
|
||||
inner.hir_fmt(f)?;
|
||||
write!(f, "; {}]", len)?;
|
||||
write!(f, "; {len}]")?;
|
||||
}
|
||||
TypeRef::Slice(inner) => {
|
||||
write!(f, "[")?;
|
||||
|
@ -1232,7 +1232,7 @@ impl HirDisplay for TypeRef {
|
|||
for index in 0..function_parameters.len() {
|
||||
let (param_name, param_type) = &function_parameters[index];
|
||||
if let Some(name) = param_name {
|
||||
write!(f, "{}: ", name)?;
|
||||
write!(f, "{name}: ")?;
|
||||
}
|
||||
|
||||
param_type.hir_fmt(f)?;
|
||||
|
@ -1408,7 +1408,7 @@ impl HirDisplay for hir_def::path::GenericArg {
|
|||
fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
|
||||
match self {
|
||||
hir_def::path::GenericArg::Type(ty) => ty.hir_fmt(f),
|
||||
hir_def::path::GenericArg::Const(c) => write!(f, "{}", c),
|
||||
hir_def::path::GenericArg::Const(c) => write!(f, "{c}"),
|
||||
hir_def::path::GenericArg::Lifetime(lifetime) => write!(f, "{}", lifetime.name),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -143,7 +143,7 @@ impl chalk_ir::interner::Interner for Interner {
|
|||
|
||||
fn debug_goal(goal: &Goal<Interner>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
|
||||
let goal_data = goal.data(Interner);
|
||||
Some(write!(fmt, "{:?}", goal_data))
|
||||
Some(write!(fmt, "{goal_data:?}"))
|
||||
}
|
||||
|
||||
fn debug_goals(
|
||||
|
|
|
@ -513,7 +513,7 @@ where
|
|||
let mut error_replacer = ErrorReplacer { vars: 0 };
|
||||
let value = match t.clone().try_fold_with(&mut error_replacer, DebruijnIndex::INNERMOST) {
|
||||
Ok(t) => t,
|
||||
Err(_) => panic!("Encountered unbound or inference vars in {:?}", t),
|
||||
Err(_) => panic!("Encountered unbound or inference vars in {t:?}"),
|
||||
};
|
||||
let kinds = (0..error_replacer.vars).map(|_| {
|
||||
chalk_ir::CanonicalVarKind::new(
|
||||
|
|
|
@ -105,7 +105,7 @@ fn check_impl(ra_fixture: &str, allow_none: bool, only_types: bool, display_sour
|
|||
.collect(),
|
||||
);
|
||||
} else {
|
||||
panic!("unexpected annotation: {}", expected);
|
||||
panic!("unexpected annotation: {expected}");
|
||||
}
|
||||
had_annotations = true;
|
||||
}
|
||||
|
@ -181,11 +181,11 @@ fn check_impl(ra_fixture: &str, allow_none: bool, only_types: bool, display_sour
|
|||
expected,
|
||||
adjustments
|
||||
.iter()
|
||||
.map(|Adjustment { kind, .. }| format!("{:?}", kind))
|
||||
.map(|Adjustment { kind, .. }| format!("{kind:?}"))
|
||||
.collect::<Vec<_>>()
|
||||
);
|
||||
} else {
|
||||
panic!("expected {:?} adjustments, found none", expected);
|
||||
panic!("expected {expected:?} adjustments, found none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ fn typing_whitespace_inside_a_function_should_not_invalidate_types() {
|
|||
db.infer(def);
|
||||
});
|
||||
});
|
||||
assert!(format!("{:?}", events).contains("infer"))
|
||||
assert!(format!("{events:?}").contains("infer"))
|
||||
}
|
||||
|
||||
let new_text = "
|
||||
|
@ -46,6 +46,6 @@ fn typing_whitespace_inside_a_function_should_not_invalidate_types() {
|
|||
db.infer(def);
|
||||
});
|
||||
});
|
||||
assert!(!format!("{:?}", events).contains("infer"), "{:#?}", events)
|
||||
assert!(!format!("{events:?}").contains("infer"), "{events:#?}")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -849,7 +849,7 @@ fn main() {
|
|||
//^^^^^^^^^^^^^^^^^ RegisterBlock
|
||||
}
|
||||
"#;
|
||||
let fixture = format!("{}\n//- /foo.rs\n{}", fixture, data);
|
||||
let fixture = format!("{fixture}\n//- /foo.rs\n{data}");
|
||||
|
||||
{
|
||||
let _b = bench("include macro");
|
||||
|
|
|
@ -67,12 +67,12 @@ impl DebugContext<'_> {
|
|||
let trait_ref = projection_ty.trait_ref(self.0);
|
||||
let trait_params = trait_ref.substitution.as_slice(Interner);
|
||||
let self_ty = trait_ref.self_type_parameter(Interner);
|
||||
write!(fmt, "<{:?} as {}", self_ty, trait_name)?;
|
||||
write!(fmt, "<{self_ty:?} as {trait_name}")?;
|
||||
if trait_params.len() > 1 {
|
||||
write!(
|
||||
fmt,
|
||||
"<{}>",
|
||||
trait_params[1..].iter().format_with(", ", |x, f| f(&format_args!("{:?}", x))),
|
||||
trait_params[1..].iter().format_with(", ", |x, f| f(&format_args!("{x:?}"))),
|
||||
)?;
|
||||
}
|
||||
write!(fmt, ">::{}", type_alias_data.name)?;
|
||||
|
@ -83,7 +83,7 @@ impl DebugContext<'_> {
|
|||
write!(
|
||||
fmt,
|
||||
"<{}>",
|
||||
proj_params.iter().format_with(", ", |x, f| f(&format_args!("{:?}", x))),
|
||||
proj_params.iter().format_with(", ", |x, f| f(&format_args!("{x:?}"))),
|
||||
)?;
|
||||
}
|
||||
|
||||
|
@ -105,9 +105,9 @@ impl DebugContext<'_> {
|
|||
}
|
||||
};
|
||||
match def {
|
||||
CallableDefId::FunctionId(_) => write!(fmt, "{{fn {}}}", name),
|
||||
CallableDefId::FunctionId(_) => write!(fmt, "{{fn {name}}}"),
|
||||
CallableDefId::StructId(_) | CallableDefId::EnumVariantId(_) => {
|
||||
write!(fmt, "{{ctor {}}}", name)
|
||||
write!(fmt, "{{ctor {name}}}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -130,7 +130,7 @@ fn solve(
|
|||
|
||||
let mut solve = || {
|
||||
let _ctx = if is_chalk_debug() || is_chalk_print() {
|
||||
Some(panic_context::enter(format!("solving {:?}", goal)))
|
||||
Some(panic_context::enter(format!("solving {goal:?}")))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue