Skip to content

Commit

Permalink
refactor: clippy::return_self_not_must_use (#974)
Browse files Browse the repository at this point in the history
  • Loading branch information
EdJoPaTo authored and joshka committed Mar 4, 2024
1 parent 3cd4369 commit ab951fa
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -76,6 +76,7 @@ items_after_statements = "warn"
missing_const_for_fn = "warn"
needless_for_each = "warn"
needless_pass_by_value = "warn"
return_self_not_must_use = "warn"
semicolon_if_nothing_returned = "warn"
trivially_copy_pass_by_ref = "warn"
use_self = "warn"
Expand Down
2 changes: 2 additions & 0 deletions src/layout/layout.rs
Expand Up @@ -391,6 +391,7 @@ impl Layout {
/// # use ratatui::layout::{Flex, Layout, Constraint::*};
/// let layout = Layout::horizontal([Length(20), Length(20), Length(20)]).flex(Flex::Legacy);
/// ```
#[must_use = "method moves the value of self and returns the modified value"]
pub const fn flex(mut self, flex: Flex) -> Self {
self.flex = flex;
self
Expand All @@ -415,6 +416,7 @@ impl Layout {
///
/// - If the layout has only one item, the spacing will not be applied.
/// - Spacing will not be applied for [`Flex::SpaceAround`] and [`Flex::SpaceBetween`]
#[must_use = "method moves the value of self and returns the modified value"]
pub const fn spacing(mut self, spacing: u16) -> Self {
self.spacing = spacing;
self
Expand Down
5 changes: 5 additions & 0 deletions src/layout/rect.rs
Expand Up @@ -111,6 +111,7 @@ impl Rect {
/// Returns a new `Rect` inside the current one, with the given margin on each side.
///
/// If the margin is larger than the `Rect`, the returned `Rect` will have no area.
#[must_use = "method returns the modified value"]
pub fn inner(self, margin: &Margin) -> Self {
let doubled_margin_horizontal = margin.horizontal.saturating_mul(2);
let doubled_margin_vertical = margin.vertical.saturating_mul(2);
Expand All @@ -135,6 +136,7 @@ impl Rect {
/// - Positive `y` moves the whole `Rect` to the bottom, negative to the top.
///
/// See [`Offset`] for details.
#[must_use = "method returns the modified value"]
pub fn offset(self, offset: Offset) -> Self {
Self {
x: i32::from(self.x)
Expand All @@ -148,6 +150,7 @@ impl Rect {
}

/// Returns a new `Rect` that contains both the current one and the given one.
#[must_use = "method returns the modified value"]
pub fn union(self, other: Self) -> Self {
let x1 = min(self.x, other.x);
let y1 = min(self.y, other.y);
Expand All @@ -164,6 +167,7 @@ impl Rect {
/// Returns a new `Rect` that is the intersection of the current one and the given one.
///
/// If the two `Rect`s do not intersect, the returned `Rect` will have no area.
#[must_use = "method returns the modified value"]
pub fn intersection(self, other: Self) -> Self {
let x1 = max(self.x, other.x);
let y1 = max(self.y, other.y);
Expand Down Expand Up @@ -227,6 +231,7 @@ impl Rect {
/// let rect = Rect::new(0, 0, 100, 100).clamp(area);
/// # }
/// ```
#[must_use = "method returns the modified value"]
pub fn clamp(self, other: Self) -> Self {
let width = self.width.min(other.width);
let height = self.height.min(other.height);
Expand Down
1 change: 1 addition & 0 deletions src/widgets/barchart.rs
Expand Up @@ -118,6 +118,7 @@ impl<'a> BarChart<'a> {
/// .data(&[("B0", 0), ("B1", 2), ("B2", 4), ("B3", 3)])
/// .data(BarGroup::default().bars(&[Bar::default().value(10), Bar::default().value(20)]));
/// ```
#[must_use = "method moves the value of self and returns the modified value"]
pub fn data(mut self, data: impl Into<BarGroup<'a>>) -> BarChart<'a> {
let group: BarGroup = data.into();
if !group.bars.is_empty() {
Expand Down
1 change: 1 addition & 0 deletions src/widgets/block.rs
Expand Up @@ -234,6 +234,7 @@ impl<'a> Block<'a> {
/// - [`Block::title_style`]
/// - [`Block::title_alignment`]
/// - [`Block::title_position`]
#[must_use = "method moves the value of self and returns the modified value"]
pub fn title<T>(mut self, title: T) -> Block<'a>
where
T: Into<Title<'a>>,
Expand Down
1 change: 1 addition & 0 deletions src/widgets/block/title.rs
Expand Up @@ -87,6 +87,7 @@ pub enum Position {

impl<'a> Title<'a> {
/// Set the title content.
#[must_use = "method moves the value of self and returns the modified value"]
pub fn content<T>(mut self, content: T) -> Title<'a>
where
T: Into<Line<'a>>,
Expand Down
5 changes: 5 additions & 0 deletions src/widgets/calendar.rs
Expand Up @@ -46,6 +46,7 @@ impl<'a, DS: DateStyler> Monthly<'a, DS> {
///
/// `style` accepts any type that is convertible to [`Style`] (e.g. [`Style`], [`Color`], or
/// your own type that implements [`Into<Style>`]).
#[must_use = "method moves the value of self and returns the modified value"]
pub fn show_surrounding<S: Into<Style>>(mut self, style: S) -> Self {
self.show_surrounding = Some(style.into());
self
Expand All @@ -55,6 +56,7 @@ impl<'a, DS: DateStyler> Monthly<'a, DS> {
///
/// `style` accepts any type that is convertible to [`Style`] (e.g. [`Style`], [`Color`], or
/// your own type that implements [`Into<Style>`]).
#[must_use = "method moves the value of self and returns the modified value"]
pub fn show_weekdays_header<S: Into<Style>>(mut self, style: S) -> Self {
self.show_weekday = Some(style.into());
self
Expand All @@ -64,6 +66,7 @@ impl<'a, DS: DateStyler> Monthly<'a, DS> {
///
/// `style` accepts any type that is convertible to [`Style`] (e.g. [`Style`], [`Color`], or
/// your own type that implements [`Into<Style>`]).
#[must_use = "method moves the value of self and returns the modified value"]
pub fn show_month_header<S: Into<Style>>(mut self, style: S) -> Self {
self.show_month = Some(style.into());
self
Expand All @@ -73,12 +76,14 @@ impl<'a, DS: DateStyler> Monthly<'a, DS> {
///
/// `style` accepts any type that is convertible to [`Style`] (e.g. [`Style`], [`Color`], or
/// your own type that implements [`Into<Style>`]).
#[must_use = "method moves the value of self and returns the modified value"]
pub fn default_style<S: Into<Style>>(mut self, style: S) -> Self {
self.default_style = style.into();
self
}

/// Render the calendar within a [Block]
#[must_use = "method moves the value of self and returns the modified value"]
pub fn block(mut self, block: Block<'a>) -> Self {
self.block = Some(block);
self
Expand Down
1 change: 1 addition & 0 deletions src/widgets/canvas.rs
Expand Up @@ -744,6 +744,7 @@ where
/// .marker(symbols::Marker::Block)
/// .paint(|ctx| {});
/// ```
#[must_use = "method moves the value of self and returns the modified value"]
pub const fn marker(mut self, marker: symbols::Marker) -> Canvas<'a, F> {
self.marker = marker;
self
Expand Down
1 change: 1 addition & 0 deletions src/widgets/gauge.rs
Expand Up @@ -316,6 +316,7 @@ impl<'a> LineGauge<'a> {
///
/// With `LineGauge`, labels are only on the left, see [`Gauge`] for a centered label.
/// If the label is not defined, it is the percentage filled.
#[must_use = "method moves the value of self and returns the modified value"]
pub fn label<T>(mut self, label: T) -> Self
where
T: Into<Line<'a>>,
Expand Down
1 change: 1 addition & 0 deletions src/widgets/table/table.rs
Expand Up @@ -557,6 +557,7 @@ impl<'a> Table<'a> {
/// ];
/// let table = Table::new(Vec::<Row>::new(), widths).flex(Flex::Legacy);
/// ```
#[must_use = "method moves the value of self and returns the modified value"]
pub const fn flex(mut self, flex: Flex) -> Self {
self.flex = flex;
self
Expand Down
4 changes: 4 additions & 0 deletions src/widgets/tabs.rs
Expand Up @@ -160,6 +160,7 @@ impl<'a> Tabs<'a> {
/// # use ratatui::{prelude::*, widgets::Tabs};
/// let tabs = Tabs::new(vec!["Tab 1", "Tab 2"]).divider("-");
/// ```
#[must_use = "method moves the value of self and returns the modified value"]
pub fn divider<T>(mut self, divider: T) -> Tabs<'a>
where
T: Into<Span<'a>>,
Expand All @@ -184,6 +185,7 @@ impl<'a> Tabs<'a> {
/// # use ratatui::{prelude::*, widgets::Tabs};
/// let tabs = Tabs::new(vec!["Tab 1", "Tab 2"]).padding("", "");
/// ```
#[must_use = "method moves the value of self and returns the modified value"]
pub fn padding<T, U>(mut self, left: T, right: U) -> Tabs<'a>
where
T: Into<Line<'a>>,
Expand All @@ -205,6 +207,7 @@ impl<'a> Tabs<'a> {
/// # use ratatui::{prelude::*, widgets::Tabs};
/// let tabs = Tabs::new(vec!["Tab 1", "Tab 2"]).padding_left("->");
/// ```
#[must_use = "method moves the value of self and returns the modified value"]
pub fn padding_left<T>(mut self, padding: T) -> Tabs<'a>
where
T: Into<Line<'a>>,
Expand All @@ -224,6 +227,7 @@ impl<'a> Tabs<'a> {
/// # use ratatui::{prelude::*, widgets::Tabs};
/// let tabs = Tabs::new(vec!["Tab 1", "Tab 2"]).padding_right("<-");
/// ```
#[must_use = "method moves the value of self and returns the modified value"]
pub fn padding_right<T>(mut self, padding: T) -> Tabs<'a>
where
T: Into<Line<'a>>,
Expand Down

0 comments on commit ab951fa

Please sign in to comment.