Update MSRV to Rust 1.70.0 (#3310)

* Update to Rust 1.70

* Fix renamed clippy lint

* Use let-else more

* Code cleanup

* Remove derelict Safety comments

* Enable more clippy lints
This commit is contained in:
Emil Ernerfeldt 2023-09-06 07:59:24 +02:00 committed by GitHub
parent 707ca04c08
commit 82704bebbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
52 changed files with 102 additions and 87 deletions

View File

@ -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'
@ -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
@ -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 }}
@ -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
@ -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

View File

@ -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",
@ -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",
@ -42,6 +53,7 @@ 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",
@ -49,7 +61,9 @@ warn = [
"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",
@ -81,17 +95,24 @@ 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",
@ -99,6 +120,7 @@ warn = [
"clippy::unused_self",
"clippy::useless_transmute",
"clippy::verbose_file_reads",
"clippy::wildcard_dependencies",
"clippy::zero_sized_map_values",
"elided_lifetimes_in_paths",
"future_incompatible",
@ -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",

View File

@ -3,7 +3,7 @@
# -----------------------------------------------------------------------------
# Section identical to scripts/clippy_wasm/clippy.toml:
msrv = "1.67"
msrv = "1.70"
allow-unwrap-in-tests = true
@ -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
# -----------------------------------------------------------------------------

View File

@ -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"

View File

@ -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) {

View File

@ -4,7 +4,7 @@ version = "0.22.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
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"

View File

@ -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 {

View File

@ -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",
));

View File

@ -8,7 +8,7 @@ authors = [
"Emil Ernerfeldt <emil.ernerfeldt@gmail.com>",
]
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"

View File

@ -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;
};

View File

@ -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(

View File

@ -4,7 +4,7 @@ version = "0.22.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
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"

View File

@ -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")))]

View File

@ -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

View File

@ -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 🤷
};

View File

@ -4,7 +4,7 @@ version = "0.22.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
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"

View File

@ -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;

View File

@ -4,7 +4,7 @@ version = "0.22.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.67"
rust-version = "1.70"
publish = false
default-run = "egui_demo_app"

View File

@ -4,7 +4,7 @@ version = "0.22.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
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"

View File

@ -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"

View File

@ -4,7 +4,7 @@ version = "0.22.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
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"

View File

@ -4,7 +4,7 @@ version = "0.22.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
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"

View File

@ -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"

View File

@ -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() {

View File

@ -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;

View File

@ -4,7 +4,7 @@ version = "0.22.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
description = "Minimal 2D math library for GUI work"
edition = "2021"
rust-version = "1.67"
rust-version = "1.70"
homepage = "https://github.com/emilk/egui/tree/master/crates/emath"
license = "MIT OR Apache-2.0"
readme = "README.md"

View File

@ -360,9 +360,17 @@ impl Rect {
/// Signed distance to the edge of the box.
///
/// Negative inside the box.
///
/// ```
/// # use emath::{pos2, Rect};
/// let rect = Rect::from_min_max(pos2(0.0, 0.0), pos2(1.0, 1.0));
/// assert_eq!(rect.signed_distance_to_pos(pos2(0.50, 0.50)), -0.50);
/// assert_eq!(rect.signed_distance_to_pos(pos2(0.75, 0.50)), -0.25);
/// assert_eq!(rect.signed_distance_to_pos(pos2(1.50, 0.50)), 0.50);
/// ```
pub fn signed_distance_to_pos(&self, pos: Pos2) -> f32 {
let edge_distances = (pos - self.center()).abs() - self.size() * 0.5;
let inside_dist = edge_distances.x.max(edge_distances.y).min(0.0);
let inside_dist = edge_distances.max_elem().min(0.0);
let outside_dist = edge_distances.max(Vec2::ZERO).length();
inside_dist + outside_dist
}

View File

@ -4,7 +4,7 @@ version = "0.22.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
description = "Minimal 2D graphics library for GUI work"
edition = "2021"
rust-version = "1.67"
rust-version = "1.70"
homepage = "https://github.com/emilk/egui/tree/master/crates/epaint"
license = "(MIT OR Apache-2.0) AND OFL-1.1 AND LicenseRef-UFL-1.0" # OFL and UFL used by default_fonts. See https://github.com/emilk/egui/issues/2321
readme = "README.md"

View File

@ -1,4 +1,4 @@
#![allow(clippy::derive_hash_xor_eq)] // We need to impl Hash for f32, but we don't implement Eq, which is fine
#![allow(clippy::derived_hash_with_manual_eq)] // We need to impl Hash for f32, but we don't implement Eq, which is fine
use super::*;

View File

@ -51,7 +51,7 @@ impl FontId {
}
}
#[allow(clippy::derive_hash_xor_eq)]
#[allow(clippy::derived_hash_with_manual_eq)]
impl std::hash::Hash for FontId {
#[inline(always)]
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
@ -552,7 +552,7 @@ impl FontsAndCache {
#[derive(Clone, Copy, Debug, PartialEq)]
struct HashableF32(f32);
#[allow(clippy::derive_hash_xor_eq)]
#[allow(clippy::derived_hash_with_manual_eq)]
impl std::hash::Hash for HashableF32 {
#[inline(always)]
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {

View File

@ -320,9 +320,8 @@ fn replace_last_glyph_with_overflow_character(
job: &LayoutJob,
row: &mut Row,
) {
let overflow_character = match job.wrap.overflow_character {
Some(c) => c,
None => return,
let Some(overflow_character) = job.wrap.overflow_character else {
return;
};
loop {

View File

@ -1,4 +1,4 @@
#![allow(clippy::derive_hash_xor_eq)] // We need to impl Hash for f32, but we don't implement Eq, which is fine
#![allow(clippy::derived_hash_with_manual_eq)] // We need to impl Hash for f32, but we don't implement Eq, which is fine
#![allow(clippy::wrong_self_convention)] // We use `from_` to indicate conversion direction. It's non-diomatic, but makes sense in this context.
use std::ops::Range;

View File

@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.67"
rust-version = "1.70"
publish = false

View File

@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.67"
rust-version = "1.70"
publish = false

View File

@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.67"
rust-version = "1.70"
publish = false

View File

@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["tami5 <kkharji@proton.me>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.67"
rust-version = "1.70"
publish = false

View File

@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.67"
rust-version = "1.70"
publish = false

View File

@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.67"
rust-version = "1.70"
publish = false

View File

@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.67"
rust-version = "1.70"
publish = false

View File

@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.67"
rust-version = "1.70"
publish = false

View File

@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["Maxim Osipenko <maxim1999max@gmail.com>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.67"
rust-version = "1.70"
publish = false

View File

@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.67"
rust-version = "1.70"
publish = false

View File

@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["Jose Palazon <jose@palako.com>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.67"
rust-version = "1.70"
publish = false

View File

@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.67"
rust-version = "1.70"
publish = false

View File

@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.67"
rust-version = "1.70"
publish = false

View File

@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["hacknus <l_stoeckli@bluewin.ch>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.67"
rust-version = "1.70"
publish = false
[dependencies]

View File

@ -7,7 +7,7 @@ authors = [
]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.67"
rust-version = "1.70"
publish = false

View File

@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.67"
rust-version = "1.70"
publish = false

View File

@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.67"
rust-version = "1.70"
publish = false

View File

@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["TicClick <ya@ticclick.ch>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.67"
rust-version = "1.70"
publish = false
[dependencies]

View File

@ -5,6 +5,6 @@
# to the user in the error, instead of "error: invalid channel name '[toolchain]'".
[toolchain]
channel = "1.67.0"
channel = "1.70.0"
components = [ "rustfmt", "clippy" ]
targets = [ "wasm32-unknown-unknown" ]

View File

@ -6,7 +6,7 @@
# -----------------------------------------------------------------------------
# Section identical to the root clippy.toml:
msrv = "1.67"
msrv = "1.70"
allow-unwrap-in-tests = true
@ -17,9 +17,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
# -----------------------------------------------------------------------------