Skip to content

Commit

Permalink
Update MSRV to Rust 1.70.0 (emilk#3310)
Browse files Browse the repository at this point in the history
* Update to Rust 1.70

* Fix renamed clippy lint

* Use let-else more

* Code cleanup

* Remove derelict Safety comments

* Enable more clippy lints
  • Loading branch information
emilk authored Sep 6, 2023
1 parent 707ca04 commit 82704be
Show file tree
Hide file tree
Showing 52 changed files with 102 additions and 87 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.67.0
toolchain: 1.70.0

- name: Install packages (Linux)
if: runner.os == 'Linux'
Expand Down Expand Up @@ -87,7 +87,7 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.67.0
toolchain: 1.70.0
targets: wasm32-unknown-unknown

- run: sudo apt-get update && sudo apt-get install libgtk-3-dev
Expand Down Expand Up @@ -145,7 +145,7 @@ jobs:
- uses: actions/checkout@v4
- uses: EmbarkStudios/cargo-deny-action@v1
with:
rust-version: "1.67.0"
rust-version: "1.70.0"
log-level: error
command: check
arguments: --target ${{ matrix.target }}
Expand All @@ -160,7 +160,7 @@ jobs:

- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.67.0
toolchain: 1.70.0
targets: aarch64-linux-android

- name: Set up cargo cache
Expand All @@ -178,7 +178,7 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.67.0
toolchain: 1.70.0

- name: Set up cargo cache
uses: Swatinem/rust-cache@v2
Expand Down
37 changes: 31 additions & 6 deletions Cranky.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
# https://github.com/ericseppanen/cargo-cranky
# cargo install cargo-cranky && cargo cranky
# See also clippy.toml

deny = ["unsafe_code"]
deny = [
"unsafe_code",
# Disabled waiting on https://github.com/rust-lang/rust-clippy/issues/9602
#"clippy::self_named_module_files",
]

warn = [
"clippy::all",
"clippy::as_ptr_cast_mut",
"clippy::await_holding_lock",
"clippy::bool_to_int_with_if",
"clippy::char_lit_as_u8",
"clippy::checked_conversions",
"clippy::clear_with_drain",
"clippy::cloned_instead_of_copied",
"clippy::dbg_macro",
"clippy::debug_assert_with_mut_call",
"clippy::derive_partial_eq_without_eq",
"clippy::disallowed_methods",
"clippy::disallowed_script_idents",
"clippy::disallowed_macros", # See clippy.toml
"clippy::disallowed_methods", # See clippy.toml
"clippy::disallowed_names", # See clippy.toml
"clippy::disallowed_script_idents", # See clippy.toml
"clippy::disallowed_types", # See clippy.toml
"clippy::doc_link_with_quotes",
"clippy::doc_markdown",
"clippy::empty_enum",
Expand All @@ -32,6 +42,7 @@ warn = [
"clippy::fn_params_excessive_bools",
"clippy::fn_to_numeric_cast_any",
"clippy::from_iter_instead_of_collect",
"clippy::get_unwrap",
"clippy::if_let_mutex",
"clippy::implicit_clone",
"clippy::imprecise_flops",
Expand All @@ -42,14 +53,17 @@ warn = [
"clippy::iter_on_empty_collections",
"clippy::iter_on_single_items",
"clippy::large_digit_groups",
"clippy::large_include_file",
"clippy::large_stack_arrays",
"clippy::large_types_passed_by_value",
"clippy::let_unit_value",
"clippy::linkedlist",
"clippy::lossy_float_literal",
"clippy::macro_use_imports",
"clippy::manual_assert",
"clippy::manual_clamp",
"clippy::manual_instant_elapsed",
"clippy::manual_let_else",
"clippy::manual_ok_or",
"clippy::manual_string_new",
"clippy::map_err_ignore",
Expand Down Expand Up @@ -81,24 +95,32 @@ warn = [
"clippy::rest_pat_in_fully_bound_structs",
"clippy::same_functions_in_if_condition",
"clippy::semicolon_if_nothing_returned",
"clippy::significant_drop_tightening",
"clippy::single_match_else",
"clippy::str_to_string",
"clippy::string_add_assign",
"clippy::string_add",
"clippy::string_lit_as_bytes",
"clippy::string_to_string",
"clippy::suspicious_command_arg_space",
"clippy::suspicious_xor_used_as_pow",
"clippy::todo",
"clippy::trailing_empty_array",
"clippy::trait_duplication_in_bounds",
"clippy::unchecked_duration_subtraction",
"clippy::unimplemented",
"clippy::uninlined_format_args",
"clippy::unnecessary_box_returns",
"clippy::unnecessary_safety_doc",
"clippy::unnecessary_struct_initialization",
"clippy::unnecessary_wraps",
"clippy::unnested_or_patterns",
"clippy::unused_peekable",
"clippy::unused_rounding",
"clippy::unused_self",
"clippy::useless_transmute",
"clippy::verbose_file_reads",
"clippy::wildcard_dependencies",
"clippy::zero_sized_map_values",
"elided_lifetimes_in_paths",
"future_incompatible",
Expand All @@ -114,11 +136,14 @@ warn = [
]

allow = [
"clippy::manual_range_contains", # This one is just annoying
"clippy::manual_range_contains", # this one is just worse imho

# Some of these we should try to put in "warn":
"clippy::type_complexity",
# TODO(emilk): enable more of these lints:
"clippy::let_underscore_untyped",
"clippy::missing_assert_message",
"clippy::undocumented_unsafe_blocks",
"clippy::unwrap_used",
"clippy::wildcard_imports",
"trivial_casts",
"unsafe_op_in_unsafe_fn", # `unsafe_op_in_unsafe_fn` may become the default in future Rust versions: https://github.com/rust-lang/rust/issues/71668
"unused_qualifications",
Expand Down
7 changes: 4 additions & 3 deletions clippy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# -----------------------------------------------------------------------------
# Section identical to scripts/clippy_wasm/clippy.toml:

msrv = "1.67"
msrv = "1.70"

allow-unwrap-in-tests = true

Expand All @@ -14,9 +14,10 @@ avoid-breaking-exported-api = false
max-fn-params-bools = 2 # TODO(emilk): decrease this to 1

# https://rust-lang.github.io/rust-clippy/master/index.html#/large_include_file
max-include-file-size = 100000
max-include-file-size = 1000000

too-many-lines-threshold = 100
# https://rust-lang.github.io/rust-clippy/master/index.html#/type_complexity
type-complexity-threshold = 350

# -----------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion crates/ecolor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = [
]
description = "Color structs and color conversion utilities"
edition = "2021"
rust-version = "1.67"
rust-version = "1.70"
homepage = "https://github.com/emilk/egui"
license = "MIT OR Apache-2.0"
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion crates/ecolor/src/rgba.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub(crate) fn f32_hash<H: std::hash::Hasher>(state: &mut H, f: f32) {
}
}

#[allow(clippy::derive_hash_xor_eq)]
#[allow(clippy::derived_hash_with_manual_eq)]
impl std::hash::Hash for Rgba {
#[inline]
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
Expand Down
2 changes: 1 addition & 1 deletion crates/eframe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.22.0"
authors = ["Emil Ernerfeldt <[email protected]>"]
description = "egui framework - write GUI apps that compiles to web and/or natively"
edition = "2021"
rust-version = "1.67"
rust-version = "1.70"
homepage = "https://github.com/emilk/egui/tree/master/crates/eframe"
license = "MIT OR Apache-2.0"
readme = "README.md"
Expand Down
1 change: 0 additions & 1 deletion crates/eframe/src/web/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ pub fn pos_from_touch_event(
// search for the touch we previously used for the position
// (unfortunately, `event.touches()` is not a rust collection):
(0..event.touches().length())
.into_iter()
.map(|i| event.touches().get(i).unwrap())
.find(|touch| egui::TouchId::from(touch.identifier()) == *touch_id_for_pos)
} else {
Expand Down
4 changes: 1 addition & 3 deletions crates/eframe/src/web/web_painter_wgpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,7 @@ impl WebPainter for WebPainterWgpu {
) -> Result<(), JsValue> {
let size_in_pixels = [self.canvas.width(), self.canvas.height()];

let render_state = if let Some(render_state) = &self.render_state {
render_state
} else {
let Some(render_state) = &self.render_state else {
return Err(JsValue::from_str(
"Can't paint, wgpu renderer was already disposed",
));
Expand Down
2 changes: 1 addition & 1 deletion crates/egui-wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ authors = [
"Emil Ernerfeldt <[email protected]>",
]
edition = "2021"
rust-version = "1.67"
rust-version = "1.70"
homepage = "https://github.com/emilk/egui/tree/master/crates/egui-wgpu"
license = "MIT OR Apache-2.0"
readme = "README.md"
Expand Down
4 changes: 1 addition & 3 deletions crates/egui-wgpu/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,7 @@ impl Renderer {
}
}
Primitive::Callback(callback) => {
let cbfn = if let Some(c) = callback.callback.downcast_ref::<Callback>() {
c
} else {
let Some(cbfn) = callback.callback.downcast_ref::<Callback>() else {
// We already warned in the `prepare` callback
continue;
};
Expand Down
6 changes: 0 additions & 6 deletions crates/egui-wgpu/src/winit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,6 @@ impl Painter {
/// [`set_window`](Self::set_window) may be called with `Some(window)` as soon as you have a
/// valid [`winit::window::Window`].
///
/// # Safety
///
/// The raw Window handle associated with the given `window` must be a valid object to create a
/// surface upon and must remain valid for the lifetime of the created surface. (The surface may
/// be cleared by passing `None`).
///
/// # Errors
/// If the provided wgpu configuration does not match an available device.
pub async fn set_window(
Expand Down
2 changes: 1 addition & 1 deletion crates/egui-winit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.22.0"
authors = ["Emil Ernerfeldt <[email protected]>"]
description = "Bindings for using egui with winit"
edition = "2021"
rust-version = "1.67"
rust-version = "1.70"
homepage = "https://github.com/emilk/egui/tree/master/crates/egui-winit"
license = "MIT OR Apache-2.0"
readme = "README.md"
Expand Down
4 changes: 0 additions & 4 deletions crates/egui-winit/src/clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ pub struct Clipboard {

impl Clipboard {
/// Construct a new instance
///
/// # Safety
///
/// The returned `Clipboard` must not outlive the input `_display_target`.
pub fn new(_display_target: &dyn HasRawDisplayHandle) -> Self {
Self {
#[cfg(all(feature = "arboard", not(target_os = "android")))]
Expand Down
4 changes: 0 additions & 4 deletions crates/egui-winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ pub struct State {

impl State {
/// Construct a new instance
///
/// # Safety
///
/// The returned `State` must not outlive the input `display_target`.
pub fn new(display_target: &dyn HasRawDisplayHandle) -> Self {
let egui_input = egui::RawInput {
focused: false, // winit will tell us when we have focus
Expand Down
6 changes: 2 additions & 4 deletions crates/egui-winit/src/window_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,10 @@ fn clamp_pos_to_monitors<E>(
let monitors = event_loop.available_monitors();

// default to primary monitor, in case the correct monitor was disconnected.
let mut active_monitor = if let Some(active_monitor) = event_loop
let Some(mut active_monitor) = event_loop
.primary_monitor()
.or_else(|| event_loop.available_monitors().next())
{
active_monitor
} else {
else {
return; // no monitors 🤷
};

Expand Down
2 changes: 1 addition & 1 deletion crates/egui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.22.0"
authors = ["Emil Ernerfeldt <[email protected]>"]
description = "An easy-to-use immediate mode GUI that runs on both web and native"
edition = "2021"
rust-version = "1.67"
rust-version = "1.70"
homepage = "https://github.com/emilk/egui"
license = "MIT OR Apache-2.0"
readme = "../../README.md"
Expand Down
4 changes: 3 additions & 1 deletion crates/egui/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,9 @@ impl Focus {
}
});

let current_rect = *self.focus_widgets_cache.get(&focus_id).unwrap();
let Some(current_rect) = self.focus_widgets_cache.get(&focus_id) else {
return None;
};

let mut best_score = std::f32::INFINITY;
let mut best_id = None;
Expand Down
2 changes: 1 addition & 1 deletion crates/egui_demo_app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.22.0"
authors = ["Emil Ernerfeldt <[email protected]>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.67"
rust-version = "1.70"
publish = false
default-run = "egui_demo_app"

Expand Down
2 changes: 1 addition & 1 deletion crates/egui_demo_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.22.0"
authors = ["Emil Ernerfeldt <[email protected]>"]
description = "Example library for egui"
edition = "2021"
rust-version = "1.67"
rust-version = "1.70"
homepage = "https://github.com/emilk/egui/tree/master/crates/egui_demo_lib"
license = "MIT OR Apache-2.0"
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion crates/egui_extras/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ authors = [
]
description = "Extra functionality and widgets for the egui GUI library"
edition = "2021"
rust-version = "1.67"
rust-version = "1.70"
homepage = "https://github.com/emilk/egui"
license = "MIT OR Apache-2.0"
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion crates/egui_glium/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.22.0"
authors = ["Emil Ernerfeldt <[email protected]>"]
description = "Bindings for using egui natively using the glium library"
edition = "2021"
rust-version = "1.67"
rust-version = "1.70"
homepage = "https://github.com/emilk/egui/tree/master/crates/egui_glium"
license = "MIT OR Apache-2.0"
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion crates/egui_glow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.22.0"
authors = ["Emil Ernerfeldt <[email protected]>"]
description = "Bindings for using egui natively using the glow library"
edition = "2021"
rust-version = "1.67"
rust-version = "1.70"
homepage = "https://github.com/emilk/egui/tree/master/crates/egui_glow"
license = "MIT OR Apache-2.0"
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion crates/egui_plot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ authors = [
]
description = "Immediate mode plotting for the egui GUI library"
edition = "2021"
rust-version = "1.67"
rust-version = "1.70"
homepage = "https://github.com/emilk/egui"
license = "MIT OR Apache-2.0"
readme = "README.md"
Expand Down
5 changes: 2 additions & 3 deletions crates/egui_plot/src/axis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,8 @@ impl AxisWidget {

// --- add ticks ---
let font_id = TextStyle::Body.resolve(ui.style());
let transform = match self.transform {
Some(t) => t,
None => return response,
let Some(transform) = self.transform else {
return response;
};

for step in self.steps.iter() {
Expand Down
1 change: 1 addition & 0 deletions crates/egui_plot/src/items/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Contains items that can be added to a plot.
#![allow(clippy::type_complexity)] // TODO(emilk): simplify some of the callback types with type aliases

use std::ops::RangeInclusive;

Expand Down
Loading

0 comments on commit 82704be

Please sign in to comment.