Skip to content

Commit ac2d7cb

Browse files
authored
Enable more lints (#215)
Enabling some lints for better code quality
1 parent 6f61be4 commit ac2d7cb

File tree

22 files changed

+46
-38
lines changed

22 files changed

+46
-38
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ missing_crate_level_docs = "warn"
102102
# See also clippy.toml
103103
[workspace.lints.clippy]
104104
allow_attributes = "warn"
105+
allow_attributes_without_reason = "warn"
105106
as_ptr_cast_mut = "warn"
106107
await_holding_lock = "warn"
107108
bool_to_int_with_if = "warn"
@@ -133,6 +134,7 @@ expl_impl_clone_on_copy = "warn"
133134
explicit_deref_methods = "warn"
134135
explicit_into_iter_loop = "warn"
135136
explicit_iter_loop = "warn"
137+
expect_used = "warn"
136138
fallible_impl_from = "warn"
137139
filter_map_next = "warn"
138140
flat_map_option = "warn"
@@ -206,6 +208,7 @@ non_zero_suggestions = "warn"
206208
nonstandard_macro_braces = "warn"
207209
option_as_ref_cloned = "warn"
208210
option_option = "warn"
211+
or_fun_call = "warn"
209212
path_buf_push_overwrite = "warn"
210213
pathbuf_init_then_push = "warn"
211214
precedence_bits = "warn"

demo/src/app.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ impl DemoGallery {
131131

132132
ui.horizontal(|ui| {
133133
ui.label("Tags:");
134+
#[expect(clippy::expect_used, reason = "tags are non-empty strings")]
134135
egui_chip::ChipEditBuilder::new(",")
135136
.expect("failed to create ChipEditBuilder")
136137
.texts(example.tags())

egui_plot/src/items/arrows.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl<'a> Arrows<'a> {
4848
/// losing the item's state. You should make sure the name passed to
4949
/// [`Self::new`] is unique and stable for each item, or set unique and
5050
/// stable ids explicitly via [`Self::id`].
51-
#[expect(clippy::needless_pass_by_value)]
51+
#[expect(clippy::needless_pass_by_value, reason = "to allow various string types")]
5252
#[inline]
5353
pub fn name(mut self, name: impl ToString) -> Self {
5454
self.base_mut().name = name.to_string();

egui_plot/src/items/bar_chart.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl BarChart {
138138
/// losing the item's state. You should make sure the name passed to
139139
/// [`Self::new`] is unique and stable for each item, or set unique and
140140
/// stable ids explicitly via [`Self::id`].
141-
#[expect(clippy::needless_pass_by_value)]
141+
#[expect(clippy::needless_pass_by_value, reason = "to allow various string types")]
142142
#[inline]
143143
pub fn name(mut self, name: impl ToString) -> Self {
144144
self.base_mut().name = name.to_string();
@@ -278,7 +278,7 @@ impl Bar {
278278
}
279279

280280
/// Name of this bar chart element.
281-
#[expect(clippy::needless_pass_by_value)]
281+
#[expect(clippy::needless_pass_by_value, reason = "to allow various string types")]
282282
#[inline]
283283
pub fn name(mut self, name: impl ToString) -> Self {
284284
self.name = name.to_string();

egui_plot/src/items/box_plot.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl BoxPlot {
104104
/// losing the item's state. You should make sure the name passed to
105105
/// [`Self::new`] is unique and stable for each item, or set unique and
106106
/// stable ids explicitly via [`Self::id`].
107-
#[expect(clippy::needless_pass_by_value)]
107+
#[expect(clippy::needless_pass_by_value, reason = "to allow various string types")]
108108
#[inline]
109109
pub fn name(mut self, name: impl ToString) -> Self {
110110
self.base_mut().name = name.to_string();
@@ -279,7 +279,7 @@ impl BoxElem {
279279
}
280280

281281
/// Name of this box element.
282-
#[expect(clippy::needless_pass_by_value)]
282+
#[expect(clippy::needless_pass_by_value, reason = "to allow various string types")]
283283
#[inline]
284284
pub fn name(mut self, name: impl ToString) -> Self {
285285
self.name = name.to_string();

egui_plot/src/items/filled_area.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl FilledArea {
9494
/// Name of this plot item.
9595
///
9696
/// This name will show up in the plot legend, if legends are turned on.
97-
#[expect(clippy::needless_pass_by_value)]
97+
#[expect(clippy::needless_pass_by_value, reason = "to allow various string types")]
9898
#[inline]
9999
pub fn name(mut self, name: impl ToString) -> Self {
100100
self.base_mut().name = name.to_string();

egui_plot/src/items/heatmap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl Heatmap {
207207
let i_rel: f64 = i as f64 / (resolution - 1) as f64;
208208
if i_rel == 1.0 {
209209
// last element
210-
*color = *base_colors.last().expect("Base colors should not be empty");
210+
*color = base_colors[base_colors.len() - 1];
211211
} else {
212212
let base_index_float: f64 = i_rel * (base_colors.len() - 1) as f64;
213213
let base_index: usize = base_index_float as usize;
@@ -277,7 +277,7 @@ impl Heatmap {
277277
/// This name will show up in the plot legend, if legends are turned on.
278278
/// Multiple heatmaps may share the same name, in which case they will
279279
/// also share an entry in the legend.
280-
#[expect(clippy::needless_pass_by_value)]
280+
#[expect(clippy::needless_pass_by_value, reason = "to allow various string types")]
281281
#[inline]
282282
pub fn name(mut self, name: impl ToString) -> Self {
283283
self.name = name.to_string();

egui_plot/src/items/line.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl HLine {
7474
/// losing the item's state. You should make sure the name passed to
7575
/// [`Self::new`] is unique and stable for each item, or set unique and
7676
/// stable ids explicitly via [`Self::id`].
77-
#[expect(clippy::needless_pass_by_value)]
77+
#[expect(clippy::needless_pass_by_value, reason = "to allow various string types")]
7878
#[inline]
7979
pub fn name(mut self, name: impl ToString) -> Self {
8080
self.base_mut().name = name.to_string();
@@ -209,7 +209,7 @@ impl VLine {
209209
/// losing the item's state. You should make sure the name passed to
210210
/// [`Self::new`] is unique and stable for each item, or set unique and
211211
/// stable ids explicitly via [`Self::id`].
212-
#[expect(clippy::needless_pass_by_value)]
212+
#[expect(clippy::needless_pass_by_value, reason = "to allow various string types")]
213213
#[inline]
214214
pub fn name(mut self, name: impl ToString) -> Self {
215215
self.base_mut().name = name.to_string();

egui_plot/src/items/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
//! Contains items that can be added to a plot at some plot coordinates.
2-
#![expect(clippy::type_complexity)] // TODO(#163): simplify some of the callback types with type aliases
2+
#![expect(
3+
clippy::type_complexity,
4+
reason = "TODO(#163): simplify some of the callback types with type aliases"
5+
)]
36

47
use std::ops::RangeInclusive;
58

@@ -234,7 +237,7 @@ fn add_rulers_and_text(
234237
}
235238

236239
// Text
237-
let text = text.unwrap_or({
240+
let text = text.unwrap_or_else(|| {
238241
let mut text = elem.name().to_owned(); // could be empty
239242

240243
if show_values {

egui_plot/src/items/plot_image.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl PlotImage {
9191
/// losing the item's state. You should make sure the name passed to
9292
/// [`Self::new`] is unique and stable for each item, or set unique and
9393
/// stable ids explicitly via [`Self::id`].
94-
#[expect(clippy::needless_pass_by_value)]
94+
#[expect(clippy::needless_pass_by_value, reason = "to allow various string types")]
9595
#[inline]
9696
pub fn name(mut self, name: impl ToString) -> Self {
9797
self.base_mut().name = name.to_string();

0 commit comments

Comments
 (0)