Skip to content

Commit

Permalink
Fix clippy for 1.67 (#3100)
Browse files Browse the repository at this point in the history
* Fix clippy for 1.67

* Fix trybuild.
  • Loading branch information
futursolo authored Feb 1, 2023
1 parent 006fbef commit 456a05b
Show file tree
Hide file tree
Showing 38 changed files with 67 additions and 84 deletions.
2 changes: 1 addition & 1 deletion examples/async_clock/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl Component for AsyncComponent {
let joke = self.joke.as_deref().unwrap_or("Loading...");
let fun_score = self
.fun_score
.map(|score| format!("Fun score: {}", score))
.map(|score| format!("Fun score: {score}"))
.unwrap_or_else(|| "Computing...".to_string());

html! {
Expand Down
2 changes: 1 addition & 1 deletion examples/boids/src/boid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl Boid {
let Vector2D { x, y } = self.position + offset;

// Write to string will never fail.
let _ = write!(points, "{:.2},{:.2} ", x, y);
let _ = write!(points, "{x:.2},{y:.2} ");
}

html! { <polygon {points} fill={color} /> }
Expand Down
2 changes: 1 addition & 1 deletion examples/boids/src/slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Component for Slider {
let display_value = if percentage {
format!("{:.p$}%", 100.0 * value, p = precision)
} else {
format!("{:.p$}", value, p = precision)
format!("{value:.precision$}")
};

let id = format!("slider-{}", self.id);
Expand Down
2 changes: 1 addition & 1 deletion examples/communication_child_to_parent/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl Component for Parent {
let msg = format!("My children have been clicked {} times", self.total_clicks);

let last_updated_msg = if let Some(last_updated) = self.last_updated.as_ref() {
format!("The last child that was clicked was {}", last_updated)
format!("The last child that was clicked was {last_updated}")
} else {
"No child has been clicked yet".to_string()
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl Component for GrandParent {
);

let detail_msg = if let Some(last_clicked) = &self.state.last_clicked {
format!("{} was clicked last", last_clicked)
format!("{last_clicked} was clicked last")
} else {
"No one has been clicked yet".to_string()
};
Expand Down Expand Up @@ -135,7 +135,7 @@ impl Component for Child {

fn view(&self, ctx: &Context<Self>) -> Html {
let my_name = ctx.props().name.clone();
let name = format!("{}: ", my_name);
let name = format!("{my_name}: ");

// Here we emit the callback to the grandparent component, whenever the button is clicked.
let onclick = self.state.child_clicked.reform(move |_| (my_name.clone()));
Expand Down
2 changes: 1 addition & 1 deletion examples/function_todomvc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ fn app() -> Html {
}) }
</ul>
<button class="clear-completed" onclick={onclear_completed}>
{ format!("Clear completed ({})", completed) }
{ format!("Clear completed ({completed})") }
</button>
</footer>
</section>
Expand Down
2 changes: 1 addition & 1 deletion examples/futures/src/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub fn render_markdown(src: &str) -> Html {
Event::Rule => add_child!(VTag::new("hr").into()),
Event::SoftBreak => add_child!(VText::new("\n").into()),
Event::HardBreak => add_child!(VTag::new("br").into()),
_ => println!("Unknown event: {:#?}", ev),
_ => println!("Unknown event: {ev:#?}"),
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/js_callback/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn Important() -> Html {
fn use_do_bye() -> SuspensionResult<String> {
let path = WASM_BINDGEN_SNIPPETS_PATH
.get()
.map(|path| format!("{}/js/unimp.js", path))
.map(|path| format!("{path}/js/unimp.js"))
.unwrap();
let s = use_future(|| async move {
let promise = bindings::import(&path);
Expand Down
2 changes: 1 addition & 1 deletion examples/keyed_list/src/person.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl PersonInfo {
let city = CityName(EN).fake::<String>();
let street = StreetName(EN).fake::<String>();

Rc::from(format!("{} {} St., {}, {}", no, street, city, state).as_str())
Rc::from(format!("{no} {street} St., {city}, {state}").as_str())
};

Self {
Expand Down
2 changes: 1 addition & 1 deletion examples/password_strength/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl App {
3 => "Good",
_ => "Great!",
};
format!("Complexity = {}", estimate_text)
format!("Complexity = {estimate_text}")
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/ssr_router/src/bin/ssr_router_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async fn main() {
let handle_error = |e| async move {
(
StatusCode::INTERNAL_SERVER_ERROR,
format!("error occurred: {}", e),
format!("error occurred: {e}"),
)
};

Expand Down
5 changes: 2 additions & 3 deletions packages/yew-macro/src/classes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,11 @@ impl Parse for ClassExpr {
if classes.len() > 1 {
let fix = classes
.into_iter()
.map(|class| format!("\"{}\"", class))
.map(|class| format!("\"{class}\""))
.collect::<Vec<_>>()
.join(", ");
let msg = format!(
"string literals must not contain more than one class (hint: use `{}`)",
fix
"string literals must not contain more than one class (hint: use `{fix}`)"
);

Err(syn::Error::new(lit_str.span(), msg))
Expand Down
2 changes: 1 addition & 1 deletion packages/yew-macro/src/function_component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ impl FunctionComponent {
let component_name = self.component_name();
let (impl_generics, ty_generics, where_clause) = self.generics.split_for_impl();

let component_name_lit = LitStr::new(&format!("{}<_>", component_name), Span::mixed_site());
let component_name_lit = LitStr::new(&format!("{component_name}<_>"), Span::mixed_site());

quote! {
#[automatically_derived]
Expand Down
2 changes: 1 addition & 1 deletion packages/yew-macro/src/html_tree/html_dashed_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl fmt::Display for HtmlDashedName {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.name)?;
for (_, ident) in &self.extended {
write!(f, "-{}", ident)?;
write!(f, "-{ident}")?;
}
Ok(())
}
Expand Down
11 changes: 4 additions & 7 deletions packages/yew-macro/src/html_tree/html_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ impl Parse for HtmlElement {
return Err(syn::Error::new_spanned(
open.to_spanned(),
format!(
"the tag `<{}>` is a void element and cannot have children (hint: \
rewrite this as `<{0}/>`)",
name
"the tag `<{name}>` is a void element and cannot have children (hint: \
rewrite this as `<{name} />`)",
),
));
}
Expand Down Expand Up @@ -324,10 +323,8 @@ impl ToTokens for HtmlElement {
emit_warning!(
dashedname.span(),
format!(
"The tag '{0}' is not matching its normalized form '{1}'. If you want \
to keep this form, change this to a dynamic tag `@{{\"{0}\"}}`.",
dashedname,
name,
"The tag '{dashedname}' is not matching its normalized form '{name}'. If you want \
to keep this form, change this to a dynamic tag `@{{\"{dashedname}\"}}`."
)
)
}
Expand Down
4 changes: 2 additions & 2 deletions packages/yew-macro/src/html_tree/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ impl Lint for AHrefLint {
match href_value.as_ref() {
"#" | "javascript:void(0)" => emit_warning!(
lit.span(),
format!("'{}' is not a suitable value for the `href` attribute. \
format!("'{href_value}' is not a suitable value for the `href` attribute. \
Without a meaningful attribute assistive technologies \
will struggle to understand your webpage. \
https://developer.mozilla.org/en-US/docs/Learn/Accessibility/HTML#onclick_events"
,href_value)),
)),
_ => {}

}
Expand Down
2 changes: 1 addition & 1 deletion packages/yew-macro/src/html_tree/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use syn::Token;
/// The implementation is really silly but I couldn't find another way to do it on stable.
/// This check isn't required to be fully accurate so it's not the end of the world if it breaks.
fn span_eq_hack(a: &Span, b: &Span) -> bool {
format!("{:?}", a) == format!("{:?}", b)
format!("{a:?}") == format!("{b:?}")
}

/// Change all occurrences of span `from` to `to` in the given error.
Expand Down
10 changes: 4 additions & 6 deletions packages/yew-macro/src/props/prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ impl Prop {
syn::Error::new_spanned(
&label,
format!(
"`{}` doesn't have a value. (hint: set the value to `true` or `false` for \
boolean attributes)",
label
"`{label}` doesn't have a value. (hint: set the value to `true` or `false` \
for boolean attributes)"
),
)
})?;
Expand Down Expand Up @@ -132,8 +131,7 @@ fn parse_prop_value(input: &ParseBuffer) -> syn::Result<Expr> {
&expr,
format!(
"the property value must be either a literal or enclosed in braces. Consider \
adding braces around your expression.: {:#?}",
exp
adding braces around your expression.: {exp:#?}"
),
)),
}
Expand Down Expand Up @@ -244,7 +242,7 @@ impl PropList {
if let Some(other_prop) = self.get_by_label(key) {
return Err(syn::Error::new_spanned(
&other_prop.label,
format!("`{}` can only be specified once", key),
format!("`{key}` can only be specified once"),
));
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/yew-macro/tests/html_macro/element-fail.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ error: `ref` can only be specified once
63 | html! { <input ref={()} ref={()} /> };
| ^^^

error: the tag `<input>` is a void element and cannot have children (hint: rewrite this as `<input/>`)
error: the tag `<input>` is a void element and cannot have children (hint: rewrite this as `<input />`)
--> tests/html_macro/element-fail.rs:66:13
|
66 | html! { <input type="text"></input> };
| ^^^^^^^^^^^^^^^^^^^

error: the tag `<iNpUt>` is a void element and cannot have children (hint: rewrite this as `<iNpUt/>`)
error: the tag `<iNpUt>` is a void element and cannot have children (hint: rewrite this as `<iNpUt />`)
--> tests/html_macro/element-fail.rs:68:13
|
68 | html! { <iNpUt type="text"></iNpUt> };
Expand Down
13 changes: 5 additions & 8 deletions packages/yew-router-macro/src/routable_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,13 @@ fn parse_variants_attributes(
0 => {
return Err(syn::Error::new(
variant.span(),
format!(
"{} attribute must be present on every variant",
AT_ATTR_IDENT
),
format!("{AT_ATTR_IDENT} attribute must be present on every variant"),
))
}
_ => {
return Err(syn::Error::new_spanned(
quote! { #(#at_attrs)* },
format!("only one {} attribute must be present", AT_ATTR_IDENT),
format!("only one {AT_ATTR_IDENT} attribute must be present"),
))
}
};
Expand Down Expand Up @@ -117,7 +114,7 @@ fn parse_variants_attributes(
if not_founds.len() > 1 {
return Err(syn::Error::new_spanned(
quote! { #(#not_found_attrs)* },
format!("there can only be one {}", NOT_FOUND_ATTR_IDENT),
format!("there can only be one {NOT_FOUND_ATTR_IDENT}"),
));
}

Expand Down Expand Up @@ -174,8 +171,8 @@ impl Routable {
// :param -> {param}
// *param -> {param}
// so we can pass it to `format!("...", param)`
right = right.replace(&format!(":{}", field), &format!("{{{}}}", field));
right = right.replace(&format!("*{}", field), &format!("{{{}}}", field));
right = right.replace(&format!(":{field}"), &format!("{{{field}}}"));
right = right.replace(&format!("*{field}"), &format!("{{{field}}}"));
}

quote! {
Expand Down
4 changes: 2 additions & 2 deletions packages/yew-router/src/navigator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl Navigator {
if route_s.is_empty() && route_s.is_empty() {
Cow::from("/")
} else {
Cow::from(format!("{}{}", base, route_s))
Cow::from(format!("{base}{route_s}"))
}
}
None => route_s.into(),
Expand All @@ -178,7 +178,7 @@ impl Navigator {
.unwrap_or(path);

if !path.starts_with('/') {
path = format!("/{}", m).into();
path = format!("/{m}").into();
}

path
Expand Down
2 changes: 1 addition & 1 deletion packages/yew-router/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub fn compose_path(pathname: &str, query: &str) -> Option<String> {
let query = query.trim();

if !query.is_empty() {
Some(format!("{}?{}", pathname, query))
Some(format!("{pathname}?{query}"))
} else {
Some(pathname.to_owned())
}
Expand Down
2 changes: 1 addition & 1 deletion packages/yew-router/tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub fn link_href(selector: &str) -> String {
gloo::utils::document()
.query_selector(selector)
.expect("Failed to run query selector")
.unwrap_or_else(|| panic!("No such link: {}", selector))
.unwrap_or_else(|| panic!("No such link: {selector}"))
.get_attribute("href")
.expect("No href attribute")
}
2 changes: 1 addition & 1 deletion packages/yew/src/dom_bundle/btag/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ mod feat_hydration {

let node = fragment
.pop_front()
.unwrap_or_else(|| panic!("expected element of type {}, found EOF.", tag_name));
.unwrap_or_else(|| panic!("expected element of type {tag_name}, found EOF."));

assert_eq!(
node.node_type(),
Expand Down
2 changes: 1 addition & 1 deletion packages/yew/src/dom_bundle/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ mod feat_hydration {
.map(|m| m.tag_name().to_lowercase())
.unwrap_or_else(|| "unknown".to_owned());

format!("{} element node", tag).into()
format!("{tag} element node").into()
}
Node::ATTRIBUTE_NODE => "attribute node".into(),
Node::TEXT_NODE => "text node".into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ where
let data = data.clone();
ctx.next_prepared_state(move |_re_render, buf| -> PreparedStateBase<T, D> {
if let Some(buf) = buf {
let buf = format!("data:application/octet-binary;base64,{}", buf);
let buf = format!("data:application/octet-binary;base64,{buf}");

spawn_local(async move {
let buf = decode_base64(&buf)
Expand Down
2 changes: 1 addition & 1 deletion packages/yew/src/virtual_dom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ mod feat_ssr_hydration {
pub fn name(&self) -> Cow<'static, str> {
match self {
#[cfg(debug_assertions)]
Self::Component(m) => format!("Component({})", m).into(),
Self::Component(m) => format!("Component({m})").into(),
#[cfg(not(debug_assertions))]
Self::Component(_) => "Component".into(),
Self::Suspense => "Suspense".into(),
Expand Down
2 changes: 1 addition & 1 deletion packages/yew/src/virtual_dom/vtag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ mod feat_ssr {
let _ = w.write_str(">");
} else {
// We don't write children of void elements nor closing tags.
debug_assert!(children.is_empty(), "{} cannot have any children!", tag);
debug_assert!(children.is_empty(), "{tag} cannot have any children!");
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions tools/benchmark-ssr/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ fn create_progress(tests: usize, rounds: usize) -> ProgressBar {
ProgressStyle::default_bar()
.template(&format!(
"{{spinner:.green}} {{prefix}} [{{elapsed_precise}}] [{{bar:40.cyan/blue}}] round \
{{msg}}/{}",
rounds
{{msg}}/{rounds}",
))
.expect("failed to parse template")
// .tick_chars("-\\|/")
Expand Down
2 changes: 1 addition & 1 deletion tools/changelog/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl Cli {

let from_ref = match from {
Some(some) => some,
None => format!("refs/tags/{}-v{}", package, latest_version),
None => format!("refs/tags/{package}-v{latest_version}"),
};
(from_ref, next_version)
};
Expand Down
6 changes: 3 additions & 3 deletions tools/changelog/src/create_log_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn create_log_line(
oid: Result<Oid, Error>,
token: Option<String>,
) -> Result<Option<LogLine>> {
println!("Commit oid: {:?}", oid);
println!("Commit oid: {oid:?}");
let oid = oid?;
let commit = repo.find_commit(oid)?;
let commit_first_line = commit
Expand Down Expand Up @@ -69,9 +69,9 @@ pub fn create_log_line(

let issue_labels = GITHUB_ISSUE_LABELS_FETCHER
.lock()
.map_err(|err| anyhow!("Failed to lock GITHUB_ISSUE_LABELS_FETCHER: {}", err))?
.map_err(|err| anyhow!("Failed to lock GITHUB_ISSUE_LABELS_FETCHER: {err}"))?
.fetch_issue_labels(issue_id.clone(), token)
.with_context(|| format!("Could not find GitHub labels for issue: {}", issue_id))?;
.with_context(|| format!("Could not find GitHub labels for issue: {issue_id}"))?;

let is_issue_for_this_package = issue_labels
.iter()
Expand Down
Loading

0 comments on commit 456a05b

Please sign in to comment.