summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@gnome.org>2023-02-08 18:12:52 -0600
committerFederico Mena Quintero <federico@gnome.org>2023-02-08 18:27:48 -0600
commitb9ea0da2bd659b5f7834e25c2474f67556d7934d (patch)
treee2d5ddbc906ea4dbcee73d661f36978492f120bc
parent4c6e4c83d090a023e02ce2afeea412c0a7850b8f (diff)
downloadlibrsvg-b9ea0da2bd659b5f7834e25c2474f67556d7934d.tar.gz
clippy: use variables directly in format strings
Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/792>
-rw-r--r--src/accept_language.rs10
-rw-r--r--src/bin/rsvg-bench.rs4
-rw-r--r--src/bin/rsvg-convert.rs31
-rw-r--r--src/c_api/handle.rs18
-rw-r--r--src/c_api/pixbuf_utils.rs6
-rw-r--r--src/cond.rs2
-rw-r--r--src/document.rs10
-rw-r--r--src/error.rs38
-rw-r--r--src/filter.rs2
-rw-r--r--src/filters/error.rs8
-rw-r--r--src/layout.rs2
-rw-r--r--src/length.rs2
-rw-r--r--src/node.rs2
-rw-r--r--src/xml/mod.rs13
14 files changed, 60 insertions, 88 deletions
diff --git a/src/accept_language.rs b/src/accept_language.rs
index 08e125e9..2abaae7f 100644
--- a/src/accept_language.rs
+++ b/src/accept_language.rs
@@ -68,7 +68,7 @@ impl fmt::Display for AcceptLanguageError {
match self {
Self::NoElements => write!(f, "no language tags in list"),
Self::InvalidCharacters => write!(f, "invalid characters in language list"),
- Self::InvalidLanguageTag(e) => write!(f, "invalid language tag: {}", e),
+ Self::InvalidLanguageTag(e) => write!(f, "invalid language tag: {e}"),
Self::InvalidWeight => write!(f, "invalid q= weight"),
}
}
@@ -188,16 +188,12 @@ impl LanguageTags {
let str_locale_range = locale_range.as_ref();
let locale_tag = LanguageTag::from_str(str_locale_range).map_err(|e| {
- format!(
- "invalid language tag \"{}\" in locale: {}",
- str_locale_range, e
- )
+ format!("invalid language tag \"{str_locale_range}\" in locale: {e}")
})?;
if !locale_tag.is_language_range() {
return Err(format!(
- "language tag \"{}\" is not a language range",
- locale_tag
+ "language tag \"{locale_tag}\" is not a language range"
));
}
diff --git a/src/bin/rsvg-bench.rs b/src/bin/rsvg-bench.rs
index b641eaa4..e9e8a96b 100644
--- a/src/bin/rsvg-bench.rs
+++ b/src/bin/rsvg-bench.rs
@@ -136,7 +136,7 @@ fn render_to_cairo(opt: &Opt, handle: &librsvg::SvgHandle) -> Result<(), Process
match (opt.hard_failures, renderer.render_document(&cr, &viewport)) {
(_, Ok(_)) => Ok(()),
(false, Err(e)) => {
- println!("could not render: {}", e);
+ println!("could not render: {e}");
Ok(())
}
(true, Err(e)) => Err(e.into()),
@@ -255,7 +255,7 @@ fn main() {
match run(&opt) {
Ok(_) => (),
Err(e) => {
- eprintln!("{}", e);
+ eprintln!("{e}");
process::exit(1);
}
}
diff --git a/src/bin/rsvg-convert.rs b/src/bin/rsvg-convert.rs
index 4895c2d4..70d32747 100644
--- a/src/bin/rsvg-convert.rs
+++ b/src/bin/rsvg-convert.rs
@@ -49,7 +49,7 @@ impl From<cairo::Error> for Error {
Librsvg currently cannot render to images bigger than that.\n\
Please specify a smaller size.",
)),
- e => Self(format!("{}", e)),
+ e => Self(format!("{e}")),
}
}
}
@@ -58,7 +58,7 @@ macro_rules! impl_error_from {
($err:ty) => {
impl From<$err> for Error {
fn from(e: $err) -> Self {
- Self(format!("{}", e))
+ Self(format!("{e}"))
}
}
};
@@ -1035,7 +1035,7 @@ fn parse_args() -> Result<Converter, Error> {
if let Some(shell) = matches.get_one::<Shell>("completion").copied() {
let mut cmd = build_cli();
- eprintln!("Generating completion file for {}", shell);
+ eprintln!("Generating completion file for {shell}");
print_completions(shell, &mut cmd);
std::process::exit(0);
}
@@ -1064,7 +1064,7 @@ fn parse_args() -> Result<Converter, Error> {
Some(s) => AcceptLanguage::parse(s)
.map(Language::AcceptLanguage)
.map_err(|e| {
- let desc = format!("{}", e);
+ let desc = format!("{e}");
clap::Error::raw(clap::error::ErrorKind::InvalidValue, desc)
})?,
};
@@ -1082,7 +1082,7 @@ fn parse_args() -> Result<Converter, Error> {
if id.starts_with('#') {
id.clone()
} else {
- format!("#{}", id)
+ format!("#{id}")
}
};
@@ -1171,7 +1171,7 @@ fn parse_resolution(v: &str) -> Result<Resolution, String> {
match v.parse::<f64>() {
Ok(res) if res > 0.0 => Ok(Resolution(res)),
Ok(_) => Err(String::from("Invalid resolution")),
- Err(e) => Err(format!("{}", e)),
+ Err(e) => Err(format!("{e}")),
}
}
@@ -1182,7 +1182,7 @@ fn parse_zoom_factor(v: &str) -> Result<ZoomFactor, String> {
match v.parse::<f64>() {
Ok(res) if res > 0.0 => Ok(ZoomFactor(res)),
Ok(_) => Err(String::from("Invalid zoom factor")),
- Err(e) => Err(format!("{}", e)),
+ Err(e) => Err(format!("{e}")),
}
}
@@ -1217,10 +1217,7 @@ fn parse_background_color(s: &str) -> Result<Option<Color>, String> {
match s {
"none" | "None" => Ok(None),
_ => <Color as Parse>::parse_str(s).map(Some).map_err(|_| {
- format!(
- "Invalid value: The argument '{}' can not be parsed as a CSS color value",
- s
- )
+ format!("Invalid value: The argument '{s}' can not be parsed as a CSS color value")
}),
}
}
@@ -1236,19 +1233,13 @@ fn is_absolute_unit(u: LengthUnit) -> bool {
fn parse_length<N: Normalize, V: Validate>(s: &str) -> Result<CssLength<N, V>, String> {
<CssLength<N, V> as Parse>::parse_str(s)
- .map_err(|_| {
- format!(
- "Invalid value: The argument '{}' can not be parsed as a length",
- s
- )
- })
+ .map_err(|_| format!("Invalid value: The argument '{s}' can not be parsed as a length"))
.and_then(|l| {
if is_absolute_unit(l.unit) {
Ok(l)
} else {
Err(format!(
- "Invalid value '{}': supported units are px, in, cm, mm, pt, pc",
- s
+ "Invalid value '{s}': supported units are px, in, cm, mm, pt, pc"
))
}
})
@@ -1256,7 +1247,7 @@ fn parse_length<N: Normalize, V: Validate>(s: &str) -> Result<CssLength<N, V>, S
fn main() {
if let Err(e) = parse_args().and_then(|converter| converter.convert()) {
- std::eprintln!("{}", e);
+ std::eprintln!("{e}");
std::process::exit(1);
}
}
diff --git a/src/c_api/handle.rs b/src/c_api/handle.rs
index 77602f19..1698cc17 100644
--- a/src/c_api/handle.rs
+++ b/src/c_api/handle.rs
@@ -1153,7 +1153,7 @@ impl<E: fmt::Display> IntoGError for Result<(), E> {
Ok(()) => true.into_glib(),
Err(e) => {
- set_gerror(session, error, 0, &format!("{}", e));
+ set_gerror(session, error, 0, &format!("{e}"));
false.into_glib()
}
}
@@ -1492,7 +1492,7 @@ pub unsafe extern "C" fn rsvg_handle_new_from_gfile_sync(
Ok(()) => raw_handle,
Err(e) => {
- set_gerror(&session, error, 0, &format!("{}", e));
+ set_gerror(&session, error, 0, &format!("{e}"));
gobject_ffi::g_object_unref(raw_handle as *mut _);
ptr::null_mut()
}
@@ -1533,7 +1533,7 @@ pub unsafe extern "C" fn rsvg_handle_new_from_stream_sync(
Ok(()) => raw_handle,
Err(e) => {
- set_gerror(&session, error, 0, &format!("{}", e));
+ set_gerror(&session, error, 0, &format!("{e}"));
gobject_ffi::g_object_unref(raw_handle as *mut _);
ptr::null_mut()
}
@@ -1631,12 +1631,7 @@ pub unsafe extern "C" fn rsvg_handle_set_stylesheet(
match str::from_utf8(s) {
Ok(s) => s,
Err(e) => {
- set_gerror(
- &session,
- error,
- 0,
- &format!("CSS is not valid UTF-8: {}", e),
- );
+ set_gerror(&session, error, 0, &format!("CSS is not valid UTF-8: {e}"));
return false.into_glib();
}
}
@@ -1979,10 +1974,7 @@ fn check_cairo_context(cr: *mut cairo::ffi::cairo_t) -> Result<cairo::Context, R
} else {
let status: cairo::Error = status.into();
- let msg = format!(
- "cannot render on a cairo_t with a failure status (status={:?})",
- status,
- );
+ let msg = format!("cannot render on a cairo_t with a failure status (status={status:?})");
rsvg_g_warning(&msg);
diff --git a/src/c_api/pixbuf_utils.rs b/src/c_api/pixbuf_utils.rs
index cc0efe05..710f2c4b 100644
--- a/src/c_api/pixbuf_utils.rs
+++ b/src/c_api/pixbuf_utils.rs
@@ -156,7 +156,7 @@ unsafe fn pixbuf_from_file_with_size_mode(
let handle = match Loader::new_with_session(session.clone()).read_path(path) {
Ok(handle) => handle,
Err(e) => {
- set_gerror(&session, error, 0, &format!("{}", e));
+ set_gerror(&session, error, 0, &format!("{e}"));
return ptr::null_mut();
}
};
@@ -167,7 +167,7 @@ unsafe fn pixbuf_from_file_with_size_mode(
let (document_width, document_height) = match renderer.legacy_document_size() {
Ok(dim) => dim,
Err(e) => {
- set_gerror(&session, error, 0, &format!("{}", e));
+ set_gerror(&session, error, 0, &format!("{e}"));
return ptr::null_mut();
}
};
@@ -184,7 +184,7 @@ unsafe fn pixbuf_from_file_with_size_mode(
)
.map(|pixbuf| pixbuf.to_glib_full())
.unwrap_or_else(|e| {
- set_gerror(&session, error, 0, &format!("{}", e));
+ set_gerror(&session, error, 0, &format!("{e}"));
ptr::null_mut()
})
}
diff --git a/src/cond.rs b/src/cond.rs
index 04c01042..57e4817c 100644
--- a/src/cond.rs
+++ b/src/cond.rs
@@ -113,7 +113,7 @@ impl SystemLanguage {
.map(str::trim)
.map(|s| {
LanguageTag::from_str(s).map_err(|e| {
- ValueErrorKind::parse_error(&format!("invalid language tag: \"{}\"", e))
+ ValueErrorKind::parse_error(&format!("invalid language tag \"{s}\": {e}"))
})
})
.collect::<Result<Vec<LanguageTag>, _>>();
diff --git a/src/document.rs b/src/document.rs
index 711982f8..0327e769 100644
--- a/src/document.rs
+++ b/src/document.rs
@@ -64,8 +64,8 @@ impl NodeId {
impl fmt::Display for NodeId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
- NodeId::Internal(id) => write!(f, "#{}", id),
- NodeId::External(url, id) => write!(f, "{}#{}", url, id),
+ NodeId::Internal(id) => write!(f, "#{id}"),
+ NodeId::External(url, id) => write!(f, "{url}#{id}"),
}
}
}
@@ -330,9 +330,9 @@ fn image_loading_error_from_cairo(status: cairo::Error, aurl: &AllowedUrl) -> Lo
let url = human_readable_url(aurl);
match status {
- cairo::Error::NoMemory => LoadingError::OutOfMemory(format!("loading image: {}", url)),
- cairo::Error::InvalidSize => LoadingError::Other(format!("image too big: {}", url)),
- _ => LoadingError::Other(format!("cairo error: {}", status)),
+ cairo::Error::NoMemory => LoadingError::OutOfMemory(format!("loading image: {url}")),
+ cairo::Error::InvalidSize => LoadingError::Other(format!("image too big: {url}")),
+ _ => LoadingError::Other(format!("cairo error: {status}")),
}
}
diff --git a/src/error.rs b/src/error.rs
index 9ec4b355..62c8e757 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -50,9 +50,9 @@ impl fmt::Display for ValueErrorKind {
match *self {
ValueErrorKind::UnknownProperty => write!(f, "unknown property name"),
- ValueErrorKind::Parse(ref s) => write!(f, "parse error: {}", s),
+ ValueErrorKind::Parse(ref s) => write!(f, "parse error: {s}"),
- ValueErrorKind::Value(ref s) => write!(f, "invalid value: {}", s),
+ ValueErrorKind::Value(ref s) => write!(f, "invalid value: {s}"),
}
}
}
@@ -142,7 +142,7 @@ impl From<DefsLookupErrorKind> for RenderingError {
fn from(e: DefsLookupErrorKind) -> RenderingError {
match e {
DefsLookupErrorKind::NotFound => RenderingError::IdNotFound,
- _ => RenderingError::InvalidId(format!("{}", e)),
+ _ => RenderingError::InvalidId(format!("{e}")),
}
}
}
@@ -152,18 +152,18 @@ impl error::Error for RenderingError {}
impl fmt::Display for RenderingError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
- RenderingError::Rendering(ref s) => write!(f, "rendering error: {}", s),
- RenderingError::LimitExceeded(ref l) => write!(f, "{}", l),
+ RenderingError::Rendering(ref s) => write!(f, "rendering error: {s}"),
+ RenderingError::LimitExceeded(ref l) => write!(f, "{l}"),
RenderingError::IdNotFound => write!(f, "element id not found"),
- RenderingError::InvalidId(ref s) => write!(f, "invalid id: {:?}", s),
- RenderingError::OutOfMemory(ref s) => write!(f, "out of memory: {}", s),
+ RenderingError::InvalidId(ref s) => write!(f, "invalid id: {s:?}"),
+ RenderingError::OutOfMemory(ref s) => write!(f, "out of memory: {s}"),
}
}
}
impl From<cairo::Error> for RenderingError {
fn from(e: cairo::Error) -> RenderingError {
- RenderingError::Rendering(format!("{:?}", e))
+ RenderingError::Rendering(format!("{e:?}"))
}
}
@@ -197,14 +197,14 @@ pub enum AcquireError {
impl fmt::Display for AcquireError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
- AcquireError::LinkNotFound(ref frag) => write!(f, "link not found: {}", frag),
+ AcquireError::LinkNotFound(ref frag) => write!(f, "link not found: {frag}"),
AcquireError::InvalidLinkType(ref frag) => {
- write!(f, "link {} is to object of invalid type", frag)
+ write!(f, "link \"{frag}\" is to object of invalid type")
}
AcquireError::CircularReference(ref node) => {
- write!(f, "circular reference in node {}", node)
+ write!(f, "circular reference in node {node}")
}
AcquireError::MaxReferencesExceeded => {
@@ -326,7 +326,7 @@ pub enum AllowedUrlError {
impl fmt::Display for AllowedUrlError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
- AllowedUrlError::UrlParseError(e) => write!(f, "URL parse error: {}", e),
+ AllowedUrlError::UrlParseError(e) => write!(f, "URL parse error: {e}"),
AllowedUrlError::BaseRequired => write!(f, "base required"),
AllowedUrlError::DifferentUriSchemes => write!(f, "different URI schemes"),
AllowedUrlError::DisallowedScheme => write!(f, "disallowed scheme"),
@@ -452,14 +452,14 @@ impl error::Error for LoadingError {}
impl fmt::Display for LoadingError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
- LoadingError::XmlParseError(ref s) => write!(f, "XML parse error: {}", s),
- LoadingError::OutOfMemory(ref s) => write!(f, "out of memory: {}", s),
+ LoadingError::XmlParseError(ref s) => write!(f, "XML parse error: {s}"),
+ LoadingError::OutOfMemory(ref s) => write!(f, "out of memory: {s}"),
LoadingError::BadUrl => write!(f, "invalid URL"),
LoadingError::BadCss => write!(f, "invalid CSS"),
LoadingError::NoSvgRoot => write!(f, "XML does not have <svg> root"),
- LoadingError::Io(ref s) => write!(f, "I/O error: {}", s),
- LoadingError::LimitExceeded(ref l) => write!(f, "{}", l),
- LoadingError::Other(ref s) => write!(f, "{}", s),
+ LoadingError::Io(ref s) => write!(f, "I/O error: {s}"),
+ LoadingError::LimitExceeded(ref l) => write!(f, "{l}"),
+ LoadingError::Other(ref s) => write!(f, "{s}"),
}
}
}
@@ -468,7 +468,7 @@ impl From<glib::Error> for LoadingError {
fn from(e: glib::Error) -> LoadingError {
// FIXME: this is somewhat fishy; not all GError are I/O errors, but in librsvg
// most GError do come from gio. Some come from GdkPixbufLoader, though.
- LoadingError::Io(format!("{}", e))
+ LoadingError::Io(format!("{e}"))
}
}
@@ -476,7 +476,7 @@ impl From<IoError> for LoadingError {
fn from(e: IoError) -> LoadingError {
match e {
IoError::BadDataUrl => LoadingError::BadUrl,
- IoError::Glib(e) => LoadingError::Io(format!("{}", e)),
+ IoError::Glib(e) => LoadingError::Io(format!("{e}")),
}
}
}
diff --git a/src/filter.rs b/src/filter.rs
index 259a5b18..ebab3099 100644
--- a/src/filter.rs
+++ b/src/filter.rs
@@ -188,7 +188,7 @@ fn extract_filter_from_filter_node(
let elt = primitive_node.borrow_element();
let effect = elt.as_filter_effect().unwrap();
- let primitive_name = format!("{}", primitive_node);
+ let primitive_name = format!("{primitive_node}");
let primitive_values = elt.get_computed_values();
let params = NormalizeParams::new(primitive_values, primitive_view_params);
diff --git a/src/filters/error.rs b/src/filters/error.rs
index 9fe58420..1b1f9bc1 100644
--- a/src/filters/error.rs
+++ b/src/filters/error.rs
@@ -37,12 +37,12 @@ impl fmt::Display for FilterError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
FilterError::InvalidInput => write!(f, "invalid value of the `in` attribute"),
- FilterError::InvalidParameter(ref s) => write!(f, "invalid parameter value: {}", s),
+ FilterError::InvalidParameter(ref s) => write!(f, "invalid parameter value: {s}"),
FilterError::BadInputSurfaceStatus(ref status) => {
- write!(f, "invalid status of the input surface: {}", status)
+ write!(f, "invalid status of the input surface: {status}")
}
- FilterError::CairoError(ref status) => write!(f, "Cairo error: {}", status),
- FilterError::Rendering(ref e) => write!(f, "Rendering error: {}", e),
+ FilterError::CairoError(ref status) => write!(f, "Cairo error: {status}"),
+ FilterError::Rendering(ref e) => write!(f, "Rendering error: {e}"),
FilterError::LightingInputTooSmall => write!(
f,
"lighting filter input surface is too small (less than 2×2 pixels)"
diff --git a/src/layout.rs b/src/layout.rs
index f0c79c4f..7e9cf2c7 100644
--- a/src/layout.rs
+++ b/src/layout.rs
@@ -143,7 +143,7 @@ impl StackingContext {
transform: Transform,
values: &ComputedValues,
) -> StackingContext {
- let element_name = format!("{}", element);
+ let element_name = format!("{element}");
let opacity;
let filter;
diff --git a/src/length.rs b/src/length.rs
index 13b9ae74..2f2d57f9 100644
--- a/src/length.rs
+++ b/src/length.rs
@@ -526,7 +526,7 @@ impl fmt::Display for LengthUnit {
LengthUnit::Pc => "pc",
};
- write!(f, "{}", unit)
+ write!(f, "{unit}")
}
}
diff --git a/src/node.rs b/src/node.rs
index 69861258..c83dcfd8 100644
--- a/src/node.rs
+++ b/src/node.rs
@@ -80,7 +80,7 @@ impl fmt::Display for NodeData {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
NodeData::Element(ref e) => {
- write!(f, "{}", e)?;
+ write!(f, "{e}")?;
}
NodeData::Text(_) => {
write!(f, "Chars")?;
diff --git a/src/xml/mod.rs b/src/xml/mod.rs
index c745ef6d..010862e5 100644
--- a/src/xml/mod.rs
+++ b/src/xml/mod.rs
@@ -534,8 +534,7 @@ impl XmlState {
Some("text") => self.acquire_text(&aurl, encoding),
Some(v) => Err(AcquireError::FatalError(format!(
- "unknown 'parse' attribute value: \"{}\"",
- v
+ "unknown 'parse' attribute value: \"{v}\""
))),
}
} else {
@@ -557,19 +556,13 @@ impl XmlState {
let encoding = encoding.unwrap_or("utf-8");
let encoder = encoding_from_whatwg_label(encoding).ok_or_else(|| {
- AcquireError::FatalError(format!(
- "unknown encoding \"{}\" for \"{}\"",
- encoding, aurl
- ))
+ AcquireError::FatalError(format!("unknown encoding \"{encoding}\" for \"{aurl}\""))
})?;
let utf8_data = encoder
.decode(&binary.data, DecoderTrap::Strict)
.map_err(|e| {
- AcquireError::FatalError(format!(
- "could not convert contents of \"{}\" from character encoding \"{}\": {}",
- aurl, encoding, e
- ))
+ AcquireError::FatalError(format!("could not convert contents of \"{aurl}\" from character encoding \"{encoding}\": {e}"))
})?;
self.element_creation_characters(&utf8_data);