Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix single_use_lifetimes in Masonry #744

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion masonry/src/app_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub trait AppDriver {
fn on_start(&mut self, state: &mut MasonryState) {}
}

impl<'a> DriverCtx<'a> {
impl DriverCtx<'_> {
// TODO - Add method to create timer

/// Return a [`WidgetMut`] to the root widget.
Expand Down
4 changes: 2 additions & 2 deletions masonry/src/contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ impl_context_method!(MutateCtx<'_>, EventCtx<'_>, UpdateCtx<'_>, {

// --- MARK: WIDGET_MUT ---
// Methods to get a child WidgetMut from a parent.
impl<'a> MutateCtx<'a> {
impl MutateCtx<'_> {
/// Return a [`WidgetMut`] to a child widget.
pub fn get_mut<'c, Child: Widget>(
&'c mut self,
Expand Down Expand Up @@ -1296,7 +1296,7 @@ impl<Ctx: IsContext, W> RawWrapperMut<'_, Ctx, W> {
}
}

impl<'a, Ctx: IsContext, W> Drop for RawWrapperMut<'a, Ctx, W> {
impl<Ctx: IsContext, W> Drop for RawWrapperMut<'_, Ctx, W> {
fn drop(&mut self) {
self.parent_widget_state
.merge_up(self.ctx.get_widget_state());
Expand Down
1 change: 0 additions & 1 deletion masonry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@
#![expect(let_underscore_drop, reason = "Deferred: Noisy")]
#![expect(missing_debug_implementations, reason = "Deferred: Noisy")]
#![expect(unused_qualifications, reason = "Deferred: Noisy")]
#![expect(single_use_lifetimes, reason = "Deferred: Noisy")]
#![expect(clippy::exhaustive_enums, reason = "Deferred: Noisy")]
#![expect(clippy::match_same_arms, reason = "Deferred: Noisy")]
#![expect(clippy::cast_possible_truncation, reason = "Deferred: Noisy")]
Expand Down
4 changes: 4 additions & 0 deletions masonry/src/paint_scene_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ pub struct UnitPoint {
v: f64,
}

#[expect(
single_use_lifetimes,
reason = "Anonymous lifetimes in `impl Trait` are unstable"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we link to the rustc issue for this lint false positive here?

Copy link
Contributor Author

@PoignardAzur PoignardAzur Nov 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can see, there's no tracking issue and no documentation beside https://dev-doc.rust-lang.org/unstable-book/language-features/anonymous-lifetime-in-impl-trait.html

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. rust-lang/rust#129255 was the first result for single_use_lifetimes in rust-lang/rust.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, right, I looked for the wrong thing.

)]
pub fn stroke<'b>(
scene: &mut Scene,
path: &impl Shape,
Expand Down
2 changes: 1 addition & 1 deletion masonry/src/text/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ impl<'a> StringCursor<'a> {
}
}

impl<'a> StringCursor<'a> {
impl StringCursor<'_> {
/// Set cursor position.
pub(crate) fn set(&mut self, position: usize) {
self.position = position;
Expand Down
16 changes: 8 additions & 8 deletions masonry/src/tree_arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,21 @@ pub struct ArenaMapMut<'a> {

// -- MARK: IMPLS ---

impl<'a, Item> Clone for ArenaRef<'a, Item> {
impl<Item> Clone for ArenaRef<'_, Item> {
fn clone(&self) -> Self {
*self
}
}

impl<'a, Item> Copy for ArenaRef<'a, Item> {}
impl<Item> Copy for ArenaRef<'_, Item> {}

impl<'a, Item> Clone for ArenaRefChildren<'a, Item> {
impl<Item> Clone for ArenaRefChildren<'_, Item> {
fn clone(&self) -> Self {
*self
}
}

impl<'a, Item> Copy for ArenaRefChildren<'a, Item> {}
impl<Item> Copy for ArenaRefChildren<'_, Item> {}

impl<Item> TreeArena<Item> {
/// Create an empty tree.
Expand Down Expand Up @@ -213,15 +213,15 @@ impl<Item> TreeNode<Item> {
}
}

impl<'a, Item> ArenaRef<'a, Item> {
impl<Item> ArenaRef<'_, Item> {
/// Id of the item this handle is associated with.
pub fn id(&self) -> u64 {
// ArenaRefChildren always has an id when it's a member of ArenaRef
self.children.id.unwrap()
}
}

impl<'a, Item> ArenaMut<'a, Item> {
impl<Item> ArenaMut<'_, Item> {
/// Id of the item this handle is associated with.
pub fn id(&self) -> u64 {
// ArenaMutChildren always has an id when it's a member of ArenaMut
Expand Down Expand Up @@ -486,7 +486,7 @@ impl<'a, Item> ArenaMutChildren<'a, Item> {
}
}

impl<'a> ArenaMapRef<'a> {
impl ArenaMapRef<'_> {
/// Construct the path of items from the given item to the root of the tree.
///
/// The path is in order from the bottom to the top, starting at the given item and ending at
Expand Down Expand Up @@ -519,7 +519,7 @@ impl<'a> ArenaMapRef<'a> {
path
}
}
impl<'a> ArenaMapMut<'a> {
impl ArenaMapMut<'_> {
/// Returns a shared handle equivalent to this one.
pub fn reborrow(&self) -> ArenaMapRef<'_> {
ArenaMapRef {
Expand Down
4 changes: 2 additions & 2 deletions masonry/src/widget/widget_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl<W: Widget> Drop for WidgetMut<'_, W> {
}
}

impl<'w, W: Widget> WidgetMut<'w, W> {
impl<W: Widget> WidgetMut<'_, W> {
/// Get a `WidgetMut` for the same underlying widget with a shorter lifetime.
pub fn reborrow_mut(&mut self) -> WidgetMut<'_, W> {
let widget = &mut self.widget;
Expand All @@ -49,7 +49,7 @@ impl<'w, W: Widget> WidgetMut<'w, W> {
}
}

impl<'a> WidgetMut<'a, Box<dyn Widget>> {
impl WidgetMut<'_, Box<dyn Widget>> {
/// Attempt to downcast to `WidgetMut` of concrete Widget type.
pub fn try_downcast<W2: Widget>(&mut self) -> Option<WidgetMut<'_, W2>> {
Some(WidgetMut {
Expand Down
8 changes: 4 additions & 4 deletions masonry/src/widget/widget_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct WidgetRef<'w, W: Widget + ?Sized> {
// --- TRAIT IMPLS ---

#[allow(clippy::non_canonical_clone_impl)]
impl<'w, W: Widget + ?Sized> Clone for WidgetRef<'w, W> {
impl<W: Widget + ?Sized> Clone for WidgetRef<'_, W> {
fn clone(&self) -> Self {
Self {
ctx: self.ctx,
Expand All @@ -37,9 +37,9 @@ impl<'w, W: Widget + ?Sized> Clone for WidgetRef<'w, W> {
}
}

impl<'w, W: Widget + ?Sized> Copy for WidgetRef<'w, W> {}
impl<W: Widget + ?Sized> Copy for WidgetRef<'_, W> {}

impl<'w, W: Widget + ?Sized> std::fmt::Debug for WidgetRef<'w, W> {
impl<W: Widget + ?Sized> std::fmt::Debug for WidgetRef<'_, W> {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let widget_name = self.widget.short_type_name();
let display_name = if let Some(debug_text) = self.widget.get_debug_text() {
Expand All @@ -62,7 +62,7 @@ impl<'w, W: Widget + ?Sized> std::fmt::Debug for WidgetRef<'w, W> {
}
}

impl<'w, W: Widget + ?Sized> Deref for WidgetRef<'w, W> {
impl<W: Widget + ?Sized> Deref for WidgetRef<'_, W> {
type Target = W;

fn deref(&self) -> &Self::Target {
Expand Down