Skip to content

Commit

Permalink
Enable and fix a bunch more lints
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Jul 11, 2022
1 parent e76c919 commit 898f480
Show file tree
Hide file tree
Showing 21 changed files with 65 additions and 48 deletions.
16 changes: 16 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ rustflags = [
"-Wclippy::dbg_macro",
"-Wclippy::debug_assert_with_mut_call",
"-Wclippy::disallowed_methods",
"-Wclippy::disallowed_script_idents",
"-Wclippy::doc_markdown",
"-Wclippy::empty_enum",
"-Wclippy::enum_glob_use",
Expand All @@ -23,10 +24,12 @@ rustflags = [
"-Wclippy::flat_map_option",
"-Wclippy::float_cmp_const",
"-Wclippy::fn_params_excessive_bools",
"-Wclippy::fn_to_numeric_cast_any",
"-Wclippy::from_iter_instead_of_collect",
"-Wclippy::if_let_mutex",
"-Wclippy::implicit_clone",
"-Wclippy::imprecise_flops",
"-Wclippy::index_refutable_slice",
"-Wclippy::inefficient_to_string",
"-Wclippy::invalid_upcast_comparisons",
"-Wclippy::iter_not_returning_iterator",
Expand Down Expand Up @@ -56,6 +59,8 @@ rustflags = [
"-Wclippy::needless_continue",
"-Wclippy::needless_for_each",
"-Wclippy::needless_pass_by_value",
"-Wclippy::negative_feature_names",
"-Wclippy::nonstandard_macro_braces",
"-Wclippy::option_option",
"-Wclippy::path_buf_push_overwrite",
"-Wclippy::ptr_as_ptr",
Expand All @@ -65,13 +70,16 @@ rustflags = [
"-Wclippy::same_functions_in_if_condition",
"-Wclippy::semicolon_if_nothing_returned",
"-Wclippy::single_match_else",
"-Wclippy::str_to_string",
"-Wclippy::string_add_assign",
"-Wclippy::string_add",
"-Wclippy::string_lit_as_bytes",
"-Wclippy::string_to_string",
"-Wclippy::todo",
"-Wclippy::trailing_empty_array",
"-Wclippy::trait_duplication_in_bounds",
"-Wclippy::unimplemented",
"-Wclippy::unnecessary_wraps",
"-Wclippy::unnested_or_patterns",
"-Wclippy::unused_self",
"-Wclippy::useless_transmute",
Expand All @@ -81,4 +89,12 @@ rustflags = [
"-Wnonstandard_style",
"-Wrust_2018_idioms",
"-Wrustdoc::missing_crate_level_docs",
"-Wsemicolon_in_expressions_from_macros",
"-Wtrivial_numeric_casts",
"-Wunused_extern_crates",
"-Wunused_import_braces",
# "-Wclippy::cloned_instead_of_copied",
# "-Wclippy::mod_module_files",
# "-Wtrivial_casts",
# "-Wunused_qualifications",
]
2 changes: 1 addition & 1 deletion eframe/src/epi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ impl Theme {

// ----------------------------------------------------------------------------

/// WebGl Context options
/// `WebGl` Context options
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub enum WebGlContextOption {
Expand Down
4 changes: 2 additions & 2 deletions egui-winit/src/window_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ impl WindowSettings {
Self {
position,
inner_size_points: Some(egui::vec2(
inner_size_points.width as f32,
inner_size_points.height as f32,
inner_size_points.width,
inner_size_points.height,
)),
}
}
Expand Down
8 changes: 5 additions & 3 deletions egui/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct ContextImpl {
repaint_after: std::time::Duration,
/// While positive, keep requesting repaints. Decrement at the end of each frame.
repaint_requests: u32,
request_repaint_callbacks: Option<Box<dyn Fn() + Send + Sync>>,
request_repaint_callback: Option<Box<dyn Fn() + Send + Sync>>,
requested_repaint_last_frame: bool,
}

Expand Down Expand Up @@ -570,7 +570,7 @@ impl Context {
// request two frames of repaint, just to cover some corner cases (frame delays):
let mut ctx = self.write();
ctx.repaint_requests = 2;
if let Some(callback) = &ctx.request_repaint_callbacks {
if let Some(callback) = &ctx.request_repaint_callback {
(callback)();
}
}
Expand Down Expand Up @@ -611,9 +611,11 @@ impl Context {
/// For integrations: this callback will be called when an egui user calls [`Self::request_repaint`].
///
/// This lets you wake up a sleeping UI thread.
///
/// Note that only one callback can be set. Any new call overrides the previous callback.
pub fn set_request_repaint_callback(&self, callback: impl Fn() + Send + Sync + 'static) {
let callback = Box::new(callback);
self.write().request_repaint_callbacks = Some(callback);
self.write().request_repaint_callback = Some(callback);
}

/// Tell `egui` which fonts to use.
Expand Down
12 changes: 6 additions & 6 deletions egui/src/util/id_type_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,19 +316,19 @@ use crate::Id;
///
/// // `b` associated with an f64 and a `&'static str`
/// map.insert_persisted(b, 13.37);
/// map.insert_temp(b, "Hello World".to_string());
/// map.insert_temp(b, "Hello World".to_owned());
///
/// // we can retrieve all four values:
/// assert_eq!(map.get_temp::<f64>(a), Some(3.14));
/// assert_eq!(map.get_temp::<i32>(a), Some(42));
/// assert_eq!(map.get_temp::<f64>(b), Some(13.37));
/// assert_eq!(map.get_temp::<String>(b), Some("Hello World".to_string()));
/// assert_eq!(map.get_temp::<String>(b), Some("Hello World".to_owned()));
///
/// // we can retrieve them like so also:
/// assert_eq!(map.get_persisted::<f64>(a), Some(3.14));
/// assert_eq!(map.get_persisted::<i32>(a), Some(42));
/// assert_eq!(map.get_persisted::<f64>(b), Some(13.37));
/// assert_eq!(map.get_temp::<String>(b), Some("Hello World".to_string()));
/// assert_eq!(map.get_temp::<String>(b), Some("Hello World".to_owned()));
/// ```
#[derive(Clone, Debug, Default)]
// We store use `id XOR typeid` as a key, so we don't need to hash again!
Expand Down Expand Up @@ -574,19 +574,19 @@ fn test_two_id_x_two_types() {

// `b` associated with an f64 and a `&'static str`
map.insert_persisted(b, 13.37);
map.insert_temp(b, "Hello World".to_string());
map.insert_temp(b, "Hello World".to_owned());

// we can retrieve all four values:
assert_eq!(map.get_temp::<f64>(a), Some(3.14));
assert_eq!(map.get_temp::<i32>(a), Some(42));
assert_eq!(map.get_temp::<f64>(b), Some(13.37));
assert_eq!(map.get_temp::<String>(b), Some("Hello World".to_string()));
assert_eq!(map.get_temp::<String>(b), Some("Hello World".to_owned()));

// we can retrieve them like so also:
assert_eq!(map.get_persisted::<f64>(a), Some(3.14));
assert_eq!(map.get_persisted::<i32>(a), Some(42));
assert_eq!(map.get_persisted::<f64>(b), Some(13.37));
assert_eq!(map.get_temp::<String>(b), Some("Hello World".to_string()));
assert_eq!(map.get_temp::<String>(b), Some("Hello World".to_owned()));
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion egui/src/widgets/drag_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ impl<'a> Widget for DragValue<'a> {
.then(|| drag_state.last_dragged_value)
.flatten();
let stored_value = stored_value.unwrap_or(value);
let stored_value = stored_value + delta_value as f64;
let stored_value = stored_value + delta_value;

let aim_delta = aim_rad * speed;
let rounded_new_value = emath::smart_aim::best_in_range_f64(
Expand Down
5 changes: 2 additions & 3 deletions egui/src/widgets/plot/items/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -837,8 +837,7 @@ impl PlotItem for Points {
stem_stroke.width *= 2.0;
}

let y_reference =
stems.map(|y| transform.position_from_value(&Value::new(0.0, y)).y as f32);
let y_reference = stems.map(|y| transform.position_from_value(&Value::new(0.0, y)).y);

series
.values
Expand Down Expand Up @@ -1619,7 +1618,7 @@ fn add_rulers_and_text(

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

if show_values {
text.push_str(&elem.default_values_format(plot.transform));
Expand Down
2 changes: 1 addition & 1 deletion egui/src/widgets/plot/legend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl LegendWidget {
.filter(|item| !item.name().is_empty())
.for_each(|item| {
entries
.entry(item.name().to_string())
.entry(item.name().to_owned())
.and_modify(|entry| {
if entry.color != item.color() {
// Multiple items with different colors
Expand Down
2 changes: 1 addition & 1 deletion egui/src/widgets/plot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ impl Plot {
/// if !name.is_empty() {
/// format!("{}: {:.*}%", name, 1, value.y)
/// } else {
/// "".to_string()
/// "".to_owned()
/// }
/// })
/// .show(ui, |plot_ui| plot_ui.line(line));
Expand Down
2 changes: 1 addition & 1 deletion egui/src/widgets/progress_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl Widget for ProgressBar {

if animate {
let n_points = 20;
let start_angle = ui.input().time as f64 * 360f64.to_radians();
let start_angle = ui.input().time * std::f64::consts::TAU;
let end_angle = start_angle + 240f64.to_radians() * ui.input().time.sin();
let circle_radius = rounding - 2.0;
let points: Vec<Pos2> = (0..n_points)
Expand Down
2 changes: 1 addition & 1 deletion egui/src/widgets/spinner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl Widget for Spinner {

let radius = (rect.height() / 2.0) - 2.0;
let n_points = 20;
let start_angle = ui.input().time as f64 * 360f64.to_radians();
let start_angle = ui.input().time * std::f64::consts::TAU;
let end_angle = start_angle + 240f64.to_radians() * ui.input().time.sin();
let points: Vec<Pos2> = (0..n_points)
.map(|i| {
Expand Down
6 changes: 2 additions & 4 deletions egui_demo_app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ mod wrap_app;
pub use wrap_app::WrapApp;

/// Time of day as seconds since midnight. Used for clock in demo app.
pub(crate) fn seconds_since_midnight() -> Option<f64> {
pub(crate) fn seconds_since_midnight() -> f64 {
use chrono::Timelike;
let time = chrono::Local::now().time();
let seconds_since_midnight =
time.num_seconds_from_midnight() as f64 + 1e-9 * (time.nanosecond() as f64);
Some(seconds_since_midnight)
time.num_seconds_from_midnight() as f64 + 1e-9 * (time.nanosecond() as f64)
}

// ----------------------------------------------------------------------------
Expand Down
13 changes: 6 additions & 7 deletions egui_demo_app/src/wrap_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ impl eframe::App for FractalClockApp {
egui::CentralPanel::default()
.frame(egui::Frame::dark_canvas(&ctx.style()))
.show(ctx, |ui| {
self.fractal_clock.ui(ui, crate::seconds_since_midnight());
self.fractal_clock
.ui(ui, Some(crate::seconds_since_midnight()));
});
}
}
Expand Down Expand Up @@ -287,12 +288,10 @@ impl WrapApp {
ui.with_layout(egui::Layout::right_to_left(), |ui| {
if false {
// TODO(emilk): fix the overlap on small screens
if let Some(seconds_since_midnight) = crate::seconds_since_midnight() {
if clock_button(ui, seconds_since_midnight).clicked() {
self.state.selected_anchor = "clock".to_owned();
if frame.is_web() {
ui.output().open_url("#clock");
}
if clock_button(ui, crate::seconds_since_midnight()).clicked() {
self.state.selected_anchor = "clock".to_owned();
if frame.is_web() {
ui.output().open_url("#clock");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion egui_demo_lib/src/demo/drag_and_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl super::View for DragAndDropDemo {

let response = response.context_menu(|ui| {
if ui.button("New Item").clicked() {
self.columns[col_idx].push("New Item".to_string());
self.columns[col_idx].push("New Item".to_owned());
ui.close_menu();
}
});
Expand Down
2 changes: 1 addition & 1 deletion egui_demo_lib/src/demo/misc_demo_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ fn text_layout_ui(
ui.label("Overflow character");
});

let mut job = LayoutJob::single_section(LOREM_IPSUM.to_string(), TextFormat::default());
let mut job = LayoutJob::single_section(LOREM_IPSUM.to_owned(), TextFormat::default());
job.wrap = TextWrapping {
max_rows: *max_rows,
break_anywhere: *break_anywhere,
Expand Down
2 changes: 1 addition & 1 deletion egui_demo_lib/src/demo/plot_demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ impl InteractionDemo {
let coordinate_text = if let Some(coordinate) = pointer_coordinate {
format!("x: {:.02}, y: {:.02}", coordinate.x, coordinate.y)
} else {
"None".to_string()
"None".to_owned()
};
ui.label(format!("pointer coordinate: {}", coordinate_text));
let coordinate_text = format!(
Expand Down
8 changes: 4 additions & 4 deletions egui_glow/src/painter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,10 +684,10 @@ pub fn clear(gl: &glow::Context, screen_size_in_pixels: [u32; 2], clear_color: e
if true {
// verified to be correct on eframe native (on Mac).
gl.clear_color(
clear_color[0] as f32,
clear_color[1] as f32,
clear_color[2] as f32,
clear_color[3] as f32,
clear_color[0],
clear_color[1],
clear_color[2],
clear_color[3],
);
} else {
let clear_color: Color32 = clear_color.into();
Expand Down
2 changes: 1 addition & 1 deletion egui_glow/src/post_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl PostProcess {

let a_pos_loc = gl
.get_attrib_location(program, "a_pos")
.ok_or_else(|| "failed to get location of a_pos".to_string())?;
.ok_or_else(|| "failed to get location of a_pos".to_owned())?;
let vao = crate::vao::VertexArrayObject::new(
&gl,
pos_buffer,
Expand Down
10 changes: 8 additions & 2 deletions emath/src/numeric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,18 @@ macro_rules! impl_numeric_float {

#[inline(always)]
fn to_f64(self) -> f64 {
self as f64
#[allow(trivial_numeric_casts)]
{
self as f64
}
}

#[inline(always)]
fn from_f64(num: f64) -> Self {
num as Self
#[allow(trivial_numeric_casts)]
{
num as Self
}
}
}
};
Expand Down
4 changes: 2 additions & 2 deletions epaint/src/text/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ type FontIndex = usize;
pub struct Font {
fonts: Vec<Arc<FontImpl>>,
/// Lazily calculated.
characters: Option<std::collections::BTreeSet<char>>,
characters: Option<BTreeSet<char>>,
replacement_glyph: (FontIndex, GlyphInfo),
pixels_per_point: f32,
row_height: f32,
Expand Down Expand Up @@ -382,7 +382,7 @@ fn allocate_glyph(
}
});

let offset_in_pixels = vec2(bb.min.x as f32, scale_in_pixels + bb.min.y as f32);
let offset_in_pixels = vec2(bb.min.x, scale_in_pixels + bb.min.y);
let offset = offset_in_pixels / pixels_per_point + y_offset * Vec2::Y;
UvRect {
offset,
Expand Down
7 changes: 2 additions & 5 deletions epaint/src/texture_atlas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,8 @@ impl TextureAtlas {
for dx in -hw..=hw {
for dy in -hw..=hw {
let distance_to_center = ((dx * dx + dy * dy) as f32).sqrt();
let coverage = remap_clamp(
distance_to_center,
(r as f32 - 0.5)..=(r as f32 + 0.5),
1.0..=0.0,
);
let coverage =
remap_clamp(distance_to_center, (r - 0.5)..=(r + 0.5), 1.0..=0.0);
image[((x as i32 + hw + dx) as usize, (y as i32 + hw + dy) as usize)] =
coverage;
}
Expand Down

0 comments on commit 898f480

Please sign in to comment.