Skip to content
Merged
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
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ missing_crate_level_docs = "warn"
# See also clippy.toml
[workspace.lints.clippy]
allow_attributes = "warn"
allow_attributes_without_reason = "warn"
as_ptr_cast_mut = "warn"
await_holding_lock = "warn"
bool_to_int_with_if = "warn"
Expand Down Expand Up @@ -133,6 +134,7 @@ expl_impl_clone_on_copy = "warn"
explicit_deref_methods = "warn"
explicit_into_iter_loop = "warn"
explicit_iter_loop = "warn"
expect_used = "warn"
fallible_impl_from = "warn"
filter_map_next = "warn"
flat_map_option = "warn"
Expand Down Expand Up @@ -206,6 +208,7 @@ non_zero_suggestions = "warn"
nonstandard_macro_braces = "warn"
option_as_ref_cloned = "warn"
option_option = "warn"
or_fun_call = "warn"
path_buf_push_overwrite = "warn"
pathbuf_init_then_push = "warn"
precedence_bits = "warn"
Expand Down
1 change: 1 addition & 0 deletions demo/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ impl DemoGallery {

ui.horizontal(|ui| {
ui.label("Tags:");
#[expect(clippy::expect_used, reason = "tags are non-empty strings")]
egui_chip::ChipEditBuilder::new(",")
.expect("failed to create ChipEditBuilder")
.texts(example.tags())
Expand Down
2 changes: 1 addition & 1 deletion egui_plot/src/items/arrows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl<'a> Arrows<'a> {
/// losing the item's state. You should make sure the name passed to
/// [`Self::new`] is unique and stable for each item, or set unique and
/// stable ids explicitly via [`Self::id`].
#[expect(clippy::needless_pass_by_value)]
#[expect(clippy::needless_pass_by_value, reason = "to allow various string types")]
#[inline]
pub fn name(mut self, name: impl ToString) -> Self {
self.base_mut().name = name.to_string();
Expand Down
4 changes: 2 additions & 2 deletions egui_plot/src/items/bar_chart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl BarChart {
/// losing the item's state. You should make sure the name passed to
/// [`Self::new`] is unique and stable for each item, or set unique and
/// stable ids explicitly via [`Self::id`].
#[expect(clippy::needless_pass_by_value)]
#[expect(clippy::needless_pass_by_value, reason = "to allow various string types")]
#[inline]
pub fn name(mut self, name: impl ToString) -> Self {
self.base_mut().name = name.to_string();
Expand Down Expand Up @@ -278,7 +278,7 @@ impl Bar {
}

/// Name of this bar chart element.
#[expect(clippy::needless_pass_by_value)]
#[expect(clippy::needless_pass_by_value, reason = "to allow various string types")]
#[inline]
pub fn name(mut self, name: impl ToString) -> Self {
self.name = name.to_string();
Expand Down
4 changes: 2 additions & 2 deletions egui_plot/src/items/box_plot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl BoxPlot {
/// losing the item's state. You should make sure the name passed to
/// [`Self::new`] is unique and stable for each item, or set unique and
/// stable ids explicitly via [`Self::id`].
#[expect(clippy::needless_pass_by_value)]
#[expect(clippy::needless_pass_by_value, reason = "to allow various string types")]
#[inline]
pub fn name(mut self, name: impl ToString) -> Self {
self.base_mut().name = name.to_string();
Expand Down Expand Up @@ -279,7 +279,7 @@ impl BoxElem {
}

/// Name of this box element.
#[expect(clippy::needless_pass_by_value)]
#[expect(clippy::needless_pass_by_value, reason = "to allow various string types")]
#[inline]
pub fn name(mut self, name: impl ToString) -> Self {
self.name = name.to_string();
Expand Down
2 changes: 1 addition & 1 deletion egui_plot/src/items/filled_area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl FilledArea {
/// Name of this plot item.
///
/// This name will show up in the plot legend, if legends are turned on.
#[expect(clippy::needless_pass_by_value)]
#[expect(clippy::needless_pass_by_value, reason = "to allow various string types")]
#[inline]
pub fn name(mut self, name: impl ToString) -> Self {
self.base_mut().name = name.to_string();
Expand Down
4 changes: 2 additions & 2 deletions egui_plot/src/items/heatmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl Heatmap {
let i_rel: f64 = i as f64 / (resolution - 1) as f64;
if i_rel == 1.0 {
// last element
*color = *base_colors.last().expect("Base colors should not be empty");
*color = base_colors[base_colors.len() - 1];
} else {
let base_index_float: f64 = i_rel * (base_colors.len() - 1) as f64;
let base_index: usize = base_index_float as usize;
Expand Down Expand Up @@ -277,7 +277,7 @@ impl Heatmap {
/// This name will show up in the plot legend, if legends are turned on.
/// Multiple heatmaps may share the same name, in which case they will
/// also share an entry in the legend.
#[expect(clippy::needless_pass_by_value)]
#[expect(clippy::needless_pass_by_value, reason = "to allow various string types")]
#[inline]
pub fn name(mut self, name: impl ToString) -> Self {
self.name = name.to_string();
Expand Down
4 changes: 2 additions & 2 deletions egui_plot/src/items/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl HLine {
/// losing the item's state. You should make sure the name passed to
/// [`Self::new`] is unique and stable for each item, or set unique and
/// stable ids explicitly via [`Self::id`].
#[expect(clippy::needless_pass_by_value)]
#[expect(clippy::needless_pass_by_value, reason = "to allow various string types")]
#[inline]
pub fn name(mut self, name: impl ToString) -> Self {
self.base_mut().name = name.to_string();
Expand Down Expand Up @@ -209,7 +209,7 @@ impl VLine {
/// losing the item's state. You should make sure the name passed to
/// [`Self::new`] is unique and stable for each item, or set unique and
/// stable ids explicitly via [`Self::id`].
#[expect(clippy::needless_pass_by_value)]
#[expect(clippy::needless_pass_by_value, reason = "to allow various string types")]
#[inline]
pub fn name(mut self, name: impl ToString) -> Self {
self.base_mut().name = name.to_string();
Expand Down
7 changes: 5 additions & 2 deletions egui_plot/src/items/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
//! Contains items that can be added to a plot at some plot coordinates.
#![expect(clippy::type_complexity)] // TODO(#163): simplify some of the callback types with type aliases
#![expect(
clippy::type_complexity,
reason = "TODO(#163): simplify some of the callback types with type aliases"
)]

use std::ops::RangeInclusive;

Expand Down Expand Up @@ -234,7 +237,7 @@ fn add_rulers_and_text(
}

// Text
let text = text.unwrap_or({
let text = text.unwrap_or_else(|| {
let mut text = elem.name().to_owned(); // could be empty

if show_values {
Expand Down
2 changes: 1 addition & 1 deletion egui_plot/src/items/plot_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl PlotImage {
/// losing the item's state. You should make sure the name passed to
/// [`Self::new`] is unique and stable for each item, or set unique and
/// stable ids explicitly via [`Self::id`].
#[expect(clippy::needless_pass_by_value)]
#[expect(clippy::needless_pass_by_value, reason = "to allow various string types")]
#[inline]
pub fn name(mut self, name: impl ToString) -> Self {
self.base_mut().name = name.to_string();
Expand Down
2 changes: 1 addition & 1 deletion egui_plot/src/items/points.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl<'a> Points<'a> {
/// losing the item's state. You should make sure the name passed to
/// [`Self::new`] is unique and stable for each item, or set unique and
/// stable ids explicitly via [`Self::id`].
#[expect(clippy::needless_pass_by_value)]
#[expect(clippy::needless_pass_by_value, reason = "to allow various string types")]
#[inline]
pub fn name(mut self, name: impl ToString) -> Self {
self.base_mut().name = name.to_string();
Expand Down
2 changes: 1 addition & 1 deletion egui_plot/src/items/polygon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl<'a> Polygon<'a> {
/// losing the item's state. You should make sure the name passed to
/// [`Self::new`] is unique and stable for each item, or set unique and
/// stable ids explicitly via [`Self::id`].
#[expect(clippy::needless_pass_by_value)]
#[expect(clippy::needless_pass_by_value, reason = "to allow various string types")]
#[inline]
pub fn name(mut self, name: impl ToString) -> Self {
self.base_mut().name = name.to_string();
Expand Down
17 changes: 6 additions & 11 deletions egui_plot/src/items/series.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl<'a> Line<'a> {
/// losing the item's state. You should make sure the name passed to
/// [`Self::new`] is unique and stable for each item, or set unique and
/// stable ids explicitly via [`Self::id`].
#[expect(clippy::needless_pass_by_value)]
#[expect(clippy::needless_pass_by_value, reason = "to allow various string types")]
#[inline]
pub fn name(mut self, name: impl ToString) -> Self {
self.base_mut().name = name.to_string();
Expand Down Expand Up @@ -201,16 +201,11 @@ impl PlotItem for Line<'_> {
let default_fill_color = Rgba::from(stroke.color).to_opaque().multiply(fill_alpha).into();

let fill_color_for_point = |pos| {
if *gradient_fill && self.gradient_color.is_some() {
Rgba::from(self
.gradient_color
.clone()
.expect("Could not find gradient color callback")(
transform.value_from_position(pos),
))
.to_opaque()
.multiply(fill_alpha)
.into()
if *gradient_fill && let Some(gradient_fallback) = &self.gradient_color {
Rgba::from(gradient_fallback(transform.value_from_position(pos)))
.to_opaque()
.multiply(fill_alpha)
.into()
} else {
default_fill_color
}
Expand Down
2 changes: 1 addition & 1 deletion egui_plot/src/items/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl Text {
/// losing the item's state. You should make sure the name passed to
/// [`Self::new`] is unique and stable for each item, or set unique and
/// stable ids explicitly via [`Self::id`].
#[expect(clippy::needless_pass_by_value)]
#[expect(clippy::needless_pass_by_value, reason = "to allow various string types")]
#[inline]
pub fn name(mut self, name: impl ToString) -> Self {
self.base_mut().name = name.to_string();
Expand Down
4 changes: 4 additions & 0 deletions egui_plot/src/overlays/legend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,10 @@ impl Widget for &mut LegendWidget {
}
let mut focus_on_item = None;

#[expect(
clippy::expect_used,
reason = "we checked that entries is not empty when creating the legend"
)]
let response_union = entries
.iter_mut()
.map(|entry| {
Expand Down
2 changes: 1 addition & 1 deletion examples/borrow_points/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl BorrowPointsExample {
.response
}

#[expect(clippy::unused_self)]
#[expect(clippy::unused_self, reason = "required by the example template")]
pub fn show_controls(&self, ui: &mut egui::Ui) -> Response {
ui.scope(|_ui| {}).response
}
Expand Down
6 changes: 3 additions & 3 deletions examples/custom_axes/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl CustomAxesExample {
Line::new("logistic fn", values)
}

#[expect(clippy::needless_pass_by_value)]
#[expect(clippy::needless_pass_by_value, reason = "to allow various range types")]
fn x_grid(input: GridInput) -> Vec<GridMark> {
let mut marks = vec![];

Expand Down Expand Up @@ -58,7 +58,7 @@ impl CustomAxesExample {
marks
}

#[expect(clippy::unused_self)]
#[expect(clippy::unused_self, reason = "required by the example template")]
pub fn show_plot(&self, ui: &mut egui::Ui) -> Response {
const MINS_PER_DAY: f64 = CustomAxesExample::MINS_PER_DAY;
const MINS_PER_H: f64 = CustomAxesExample::MINS_PER_H;
Expand Down Expand Up @@ -137,7 +137,7 @@ impl CustomAxesExample {
.response
}

#[expect(clippy::unused_self)]
#[expect(clippy::unused_self, reason = "required by the example template")]
pub fn show_controls(&self, ui: &mut egui::Ui) -> Response {
ui.label("Zoom in on the X-axis to see hours and minutes")
}
Expand Down
8 changes: 5 additions & 3 deletions examples/heatmap/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ impl HeatmapDemo {
self.palette.pop();
}
});
if ui.button("Push color").clicked() {
self.palette.push(*self.palette.last().expect("Palette is empty"));
if ui.button("Push color").clicked()
&& let Some(last) = self.palette.last()
{
self.palette.push(*last);
}
});
ui.horizontal(|ui| {
Expand All @@ -80,7 +82,7 @@ impl HeatmapDemo {
.response
}

#[expect(clippy::needless_pass_by_ref_mut)]
#[expect(clippy::needless_pass_by_ref_mut, reason = "to allow mutation of self")]
pub fn show_plot(&mut self, ui: &mut egui::Ui) -> Response {
let mut values = Vec::new();
for y in 0..self.rows {
Expand Down
2 changes: 1 addition & 1 deletion examples/items/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl ItemsExample {
.response
}

#[expect(clippy::unused_self)]
#[expect(clippy::unused_self, reason = "required by the example template")]
pub fn show_controls(&self, ui: &mut egui::Ui) -> Response {
// No controls for this example
ui.scope(|_ui| {}).response
Expand Down
2 changes: 1 addition & 1 deletion examples/plot_span/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl PlotSpanDemo {
.response
}

#[expect(clippy::needless_pass_by_ref_mut)]
#[expect(clippy::needless_pass_by_ref_mut, reason = "to allow mutation of self")]
pub fn show_plot(&mut self, ui: &mut egui::Ui) -> Response {
let mut plot = Plot::new("Span Demo");
if self.show_legend {
Expand Down
2 changes: 1 addition & 1 deletion examples/save_plot/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl SavePlotExample {
inner.response
}

#[expect(clippy::unused_self)]
#[expect(clippy::unused_self, reason = "required by the example template")]
pub fn show_controls(&self, ui: &mut egui::Ui) -> Response {
let response = ui.button("Save Plot");
if response.clicked() {
Expand Down
2 changes: 1 addition & 1 deletion examples/save_plot/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![expect(clippy::print_stderr)]
#![expect(clippy::print_stderr, reason = "example template")]
#![doc = include_str!("../README.md")]

use eframe::egui;
Expand Down
Loading