* refactor(yew-macro): ignore `dead_code` for `Lint::lint` if not `cfg(yew_lints)`

`dead_code` has become more precise in recent toolchains.

* refactor(yew): stop using `static mut` hack to get static reference to an empty `Vec<VNode>`

The old code triggered `static_mut_refs` lint in the latest stable
toolchain.

* refactor(yew): ignore `clippy::to_string_trait_impl` for `impl ToString for Classes`

* perf(yew,yew-router): use `const {}` syntax for `thread_local!`

Addresses `clippy::thread_local_initializer_can_be_made_const`.
May provide performance benefits.

* refactor(yew): remove `yew::html::component::lifecycle::Stateful::as_any_mut`

Addresses `dead_code` lint.

* refactor(yew): ignore `clippy::incompatible_msrv` for `TopologicalQueue::pop_topmost` if Rust version >= 1.66

The use of `BTreeMap::pop_first` (stabilized in 1.66) is already gated by
`#[rustversion(since(1.66))]` hence we can ignore this warning.

* refactor(yew): gate `yew::html::component::lifecycle::Stateful::{rendered,props_changed}` by `cfg(feature = "csr")`

Addresses `dead_code` lint.

* test(website-test): ignore `clippy::needless_doctest_main`

* doc(examples): replace `clone` + assignment with `clone_from`

Addresses `clippy::assigning_clones` lint.
This commit is contained in:
Tomoaki Kawada 2024-07-25 12:39:38 +09:00 committed by GitHub
parent dbdd3b78e1
commit af68646258
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 14 additions and 12 deletions

View File

@ -73,7 +73,7 @@ impl Component for App {
.filter(|e| self.state.filter.fits(e)) .filter(|e| self.state.filter.fits(e))
.nth(idx) .nth(idx)
.unwrap(); .unwrap();
self.state.edit_value = entry.description.clone(); self.state.edit_value.clone_from(&entry.description);
self.state.clear_all_edit(); self.state.clear_all_edit();
self.state.toggle_edit(idx); self.state.toggle_edit(idx);
} }

View File

@ -12,6 +12,7 @@ use crate::props::{ElementProps, Prop};
/// use `proc-macro-error` (and the `emit_warning!` macro) to produce a warning. At present, these /// use `proc-macro-error` (and the `emit_warning!` macro) to produce a warning. At present, these
/// are only emitted on nightly. /// are only emitted on nightly.
pub trait Lint { pub trait Lint {
#[cfg_attr(not(yew_lints), allow(dead_code))]
fn lint(element: &HtmlElement); fn lint(element: &HtmlElement);
} }

View File

@ -8,7 +8,7 @@ pub(crate) fn strip_slash_suffix(path: &str) -> &str {
static BASE_URL_LOADED: std::sync::Once = std::sync::Once::new(); static BASE_URL_LOADED: std::sync::Once = std::sync::Once::new();
thread_local! { thread_local! {
static BASE_URL: RefCell<Option<String>> = RefCell::new(None); static BASE_URL: RefCell<Option<String>> = const { RefCell::new(None) };
} }
// This exists so we can cache the base url. It costs us a `to_string` call instead of a DOM API // This exists so we can cache the base url. It costs us a `to_string` call instead of a DOM API

View File

@ -165,6 +165,7 @@ impl IntoIterator for &Classes {
} }
} }
#[allow(clippy::to_string_trait_impl)]
impl ToString for Classes { impl ToString for Classes {
fn to_string(&self) -> String { fn to_string(&self) -> String {
let mut iter = self.set.iter().cloned(); let mut iter = self.set.iter().cloned();

View File

@ -148,16 +148,17 @@ where
/// methods. /// methods.
pub(crate) trait Stateful { pub(crate) trait Stateful {
fn view(&self) -> HtmlResult; fn view(&self) -> HtmlResult;
#[cfg(feature = "csr")]
fn rendered(&mut self, first_render: bool); fn rendered(&mut self, first_render: bool);
fn destroy(&mut self); fn destroy(&mut self);
fn any_scope(&self) -> AnyScope; fn any_scope(&self) -> AnyScope;
fn flush_messages(&mut self) -> bool; fn flush_messages(&mut self) -> bool;
#[cfg(feature = "csr")]
fn props_changed(&mut self, props: Rc<dyn Any>) -> bool; fn props_changed(&mut self, props: Rc<dyn Any>) -> bool;
fn as_any(&self) -> &dyn Any; fn as_any(&self) -> &dyn Any;
fn as_any_mut(&mut self) -> &mut dyn Any;
#[cfg(feature = "hydration")] #[cfg(feature = "hydration")]
fn creation_mode(&self) -> RenderMode; fn creation_mode(&self) -> RenderMode;
@ -171,6 +172,7 @@ where
self.component.view(&self.context) self.component.view(&self.context)
} }
#[cfg(feature = "csr")]
fn rendered(&mut self, first_render: bool) { fn rendered(&mut self, first_render: bool) {
self.component.rendered(&self.context, first_render) self.component.rendered(&self.context, first_render)
} }
@ -199,6 +201,7 @@ where
}) })
} }
#[cfg(feature = "csr")]
fn props_changed(&mut self, props: Rc<dyn Any>) -> bool { fn props_changed(&mut self, props: Rc<dyn Any>) -> bool {
let props = match Rc::downcast::<COMP::Properties>(props) { let props = match Rc::downcast::<COMP::Properties>(props) {
Ok(m) => m, Ok(m) => m,
@ -216,10 +219,6 @@ where
fn as_any(&self) -> &dyn Any { fn as_any(&self) -> &dyn Any {
self self
} }
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
} }
pub(crate) struct ComponentState { pub(crate) struct ComponentState {

View File

@ -8,7 +8,7 @@ use crate::app_handle::AppHandle;
use crate::html::BaseComponent; use crate::html::BaseComponent;
thread_local! { thread_local! {
static PANIC_HOOK_IS_SET: Cell<bool> = Cell::new(false); static PANIC_HOOK_IS_SET: Cell<bool> = const { Cell::new(false) };
} }
/// Set a custom panic hook. /// Set a custom panic hook.

View File

@ -55,6 +55,7 @@ impl TopologicalQueue {
/// Take a single entry, preferring parents over children /// Take a single entry, preferring parents over children
#[rustversion::since(1.66)] #[rustversion::since(1.66)]
#[allow(clippy::incompatible_msrv)]
#[inline] #[inline]
fn pop_topmost(&mut self) -> Option<QueueEntry> { fn pop_topmost(&mut self) -> Option<QueueEntry> {
self.inner.pop_first().map(|(_, v)| v) self.inner.pop_first().map(|(_, v)| v)

View File

@ -45,10 +45,9 @@ impl Deref for VList {
match self.children { match self.children {
Some(ref m) => m, Some(ref m) => m,
None => { None => {
// This is mutable because the Vec<VNode> is not Sync // This can be replaced with `const { &Vec::new() }` in Rust 1.79.
static mut EMPTY: Vec<VNode> = Vec::new(); const EMPTY: &Vec<VNode> = &Vec::new();
// SAFETY: The EMPTY value is always read-only EMPTY
unsafe { &EMPTY }
} }
} }
} }

View File

@ -1,3 +1,4 @@
#![allow(clippy::needless_doctest_main)]
pub mod tutorial; pub mod tutorial;
include!(concat!(env!("OUT_DIR"), "/website_tests.rs")); include!(concat!(env!("OUT_DIR"), "/website_tests.rs"));