Skip to content

Commit

Permalink
Update Rust stable to 1.82 and satisfy Clippy. (#2409)
Browse files Browse the repository at this point in the history
Contains one API change:

```
--- pub struct CustomCursor(Arc<HCursor>);
+++ pub struct CustomCursor(Rc<HCursor>);
```
  • Loading branch information
xStrom authored Oct 22, 2024
1 parent e7f49e7 commit 49b5352
Show file tree
Hide file tree
Showing 28 changed files with 81 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ env:
# version like 1.70. Note that we only specify MAJOR.MINOR and not PATCH so that bugfixes still
# come automatically. If the version specified here is no longer the latest stable version,
# then please feel free to submit a PR that adjusts it along with the potential clippy fixes.
RUST_STABLE_VER: "1.76" # In quotes because otherwise 1.70 would be interpreted as 1.7
RUST_STABLE_VER: "1.82" # In quotes because otherwise 1.70 would be interpreted as 1.7

name: CI

Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ You can find its changes [documented below](#083---2023-02-28).

### Changed

- Windows: Custom cursor is now encapsulated by `Rc` instead of `Arc`. ([#2409] by [@xStrom])

### Deprecated

### Removed
Expand Down Expand Up @@ -1241,6 +1243,7 @@ Last release without a changelog :(
[#2378]: https://github.com/linebender/druid/pull/2378
[#2380]: https://github.com/linebender/druid/pull/2380
[#2402]: https://github.com/linebender/druid/pull/2402
[#2409]: https://github.com/linebender/druid/pull/2409

[Unreleased]: https://github.com/linebender/druid/compare/v0.8.3...master
[0.8.3]: https://github.com/linebender/druid/compare/v0.8.2...v0.8.3
Expand Down
8 changes: 7 additions & 1 deletion druid-derive/tests/ignore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ fn ignore_item_without_data_impl() {
use std::path::PathBuf;

#[derive(Clone, Data)]
#[allow(dead_code)]
struct CoolStruct {
len: usize,
#[data(ignore)]
Expand All @@ -35,7 +36,12 @@ fn ignore_item_without_data_impl() {
#[test]
fn tuple_struct() {
#[derive(Clone, Data)]
struct Tup(usize, #[data(ignore)] usize);
struct Tup(
usize,
#[data(ignore)]
#[allow(dead_code)]
usize,
);

let one = Tup(1, 1);
let two = Tup(1, 5);
Expand Down
18 changes: 7 additions & 11 deletions druid-derive/tests/with_same.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ fn same_fn() {

let one = Nanana {
bits: 1.0,
peq: std::f64::NAN,
peq: f64::NAN,
};
let two = Nanana {
bits: 1.0,
peq: std::f64::NAN,
peq: f64::NAN,
};

//according to partialeq, two NaNs are never equal
assert!(!one.same(&two));

let one = Nanana {
bits: std::f64::NAN,
bits: f64::NAN,
peq: 1.0,
};
let two = Nanana {
bits: std::f64::NAN,
bits: f64::NAN,
peq: 1.0,
};

Expand All @@ -51,17 +51,13 @@ fn enums() {
Tri(#[data(same_fn = "same_sign")] f64),
}

let oneone = Hi::One {
bits: std::f64::NAN,
};
let onetwo = Hi::One {
bits: std::f64::NAN,
};
let oneone = Hi::One { bits: f64::NAN };
let onetwo = Hi::One { bits: f64::NAN };
assert!(oneone.same(&onetwo));

let twoone = Hi::Two { bits: -1.1 };
let twotwo = Hi::Two {
bits: std::f64::NEG_INFINITY,
bits: f64::NEG_INFINITY,
};
assert!(twoone.same(&twotwo));

Expand Down
2 changes: 1 addition & 1 deletion druid-shell/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static APPLICATION_CREATED: AtomicBool = AtomicBool::new(false);

thread_local! {
/// A reference object to the current `Application`, if any.
static GLOBAL_APP: RefCell<Option<Application>> = RefCell::new(None);
static GLOBAL_APP: RefCell<Option<Application>> = const { RefCell::new(None) };
}

impl Application {
Expand Down
2 changes: 1 addition & 1 deletion druid-shell/src/backend/mac/text_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ fn decode_nsrange(
range: &NSRange,
start_offset: usize,
) -> Option<Range<usize>> {
if range.location as usize >= i32::max_value() as usize {
if range.location as usize >= i32::MAX as usize {
return None;
}
let start_offset_utf16 = edit_lock.utf8_to_utf16(0..start_offset);
Expand Down
2 changes: 2 additions & 0 deletions druid-shell/src/backend/wayland/outputs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ pub(super) fn current() -> Result<Vec<Meta>, error::Error> {
Ok(result.take())
}

#[allow(dead_code)]
pub trait Wayland {
fn consume<'a>(
&'a mut self,
Expand Down Expand Up @@ -130,6 +131,7 @@ impl From<(i32, i32)> for Position {
}

#[derive(Debug, Default, Clone)]
#[allow(dead_code)]
pub struct Mode {
pub logical: Dimensions,
pub refresh: i32,
Expand Down
2 changes: 1 addition & 1 deletion druid-shell/src/backend/web/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ impl WindowHandle {
Ok(iv) => iv,
Err(_) => {
warn!("Timer duration exceeds 32 bit integer max");
i32::max_value()
i32::MAX
}
};

Expand Down
3 changes: 3 additions & 0 deletions druid-shell/src/backend/windows/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ impl From<HRESULT> for Error {
}

pub trait ToWide {
#[allow(dead_code)]
fn to_wide_sized(&self) -> Vec<u16>;
fn to_wide(&self) -> Vec<u16>;
}
Expand Down Expand Up @@ -147,6 +148,7 @@ type DCompositionCreateDevice = unsafe extern "system" fn(

#[allow(non_snake_case)] // For member fields
pub struct OptionalFunctions {
#[allow(dead_code)]
pub GetDpiForSystem: Option<GetDpiForSystem>,
pub GetDpiForWindow: Option<GetDpiForWindow>,
pub SetProcessDpiAwarenessContext: Option<SetProcessDpiAwarenessContext>,
Expand Down Expand Up @@ -178,6 +180,7 @@ fn load_optional_functions() -> OptionalFunctions {
$min_windows_version
);
} else {
#[allow(clippy::missing_transmute_annotations)]
let function = unsafe { mem::transmute::<_, $function>(function_ptr) };
$function = Some(function);
}
Expand Down
10 changes: 3 additions & 7 deletions druid-shell/src/backend/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub enum PresentStrategy {
/// 1. the system hands a mouse click event to `druid-shell`
/// 2. `druid-shell` calls `WinHandler::mouse_up`
/// 3. after some processing, the `WinHandler` calls `WindowHandle::save_as`, which schedules a
/// deferred op and returns immediately
/// deferred op and returns immediately
/// 4. after some more processing, `WinHandler::mouse_up` returns
/// 5. `druid-shell` displays the "save as" dialog that was requested in step 3.
enum DeferredOp {
Expand Down Expand Up @@ -301,9 +301,7 @@ struct DxgiState {
}

#[derive(Clone, PartialEq, Eq)]
// TODO: Convert this from Arc to Rc when doing a breaking release
#[allow(clippy::arc_with_non_send_sync)]
pub struct CustomCursor(Arc<HCursor>);
pub struct CustomCursor(Rc<HCursor>);

#[derive(PartialEq, Eq)]
struct HCursor(HCURSOR);
Expand Down Expand Up @@ -2479,9 +2477,7 @@ impl WindowHandle {
};
let icon = CreateIconIndirect(&mut icon_info);

// TODO: Convert this from Arc to Rc when doing a breaking release
#[allow(clippy::arc_with_non_send_sync)]
Some(Cursor::Custom(CustomCursor(Arc::new(HCursor(icon)))))
Some(Cursor::Custom(CustomCursor(Rc::new(HCursor(icon)))))
}
} else {
None
Expand Down
2 changes: 1 addition & 1 deletion druid-shell/src/backend/x11/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ fn poll_with_timeout(
break;
} else {
let millis = c_int::try_from(deadline.duration_since(now).as_millis())
.unwrap_or(c_int::max_value() - 1);
.unwrap_or(c_int::MAX - 1);
// The above .as_millis() rounds down. This means we would wake up before the
// deadline is reached. Add one to 'simulate' rounding up instead.
millis + 1
Expand Down
2 changes: 1 addition & 1 deletion druid-shell/src/backend/x11/clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ fn wait_for_event_with_deadline(
// Use poll() to wait for the socket to become readable.
let mut poll_fds = [PollFd::new(conn.as_raw_fd(), PollFlags::POLLIN)];
let poll_timeout = c_int::try_from(deadline.duration_since(now).as_millis())
.unwrap_or(c_int::max_value() - 1)
.unwrap_or(c_int::MAX - 1)
// The above rounds down, but we don't want to wake up to early, so add one
.saturating_add(1);

Expand Down
2 changes: 1 addition & 1 deletion druid-shell/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//! variables. Here is a list of environment variables that `druid-shell` supports:
//!
//! - `DRUID_SHELL_DISABLE_X11_PRESENT`: if this is set and `druid-shell` is using the `x11`
//! backend, it will avoid using the Present extension.
//! backend, it will avoid using the Present extension.

#![warn(rustdoc::broken_intra_doc_links)]
#![allow(clippy::new_without_default)]
Expand Down
10 changes: 5 additions & 5 deletions druid-shell/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,11 @@ pub trait InputHandler {
/// This method also sets the composition range to `None`, and updates the
/// selection:
///
/// - If both the selection's anchor and active are `< range.start`, then
/// nothing is updated. - If both the selection's anchor and active are `>
/// range.end`, then subtract `range.len()` from both, and add `text.len()`.
/// - If neither of the previous two conditions are true, then set both
/// anchor and active to `range.start + text.len()`.
/// - If both the selection's anchor and active are `< range.start`, then nothing is updated.
/// - If both the selection's anchor and active are `> range.end`, then subtract `range.len()`
/// from both, and add `text.len()`.
/// - If neither of the previous two conditions are true, then set both anchor and active to
/// `range.start + text.len()`.
///
/// After the above update, if we increase each end of the selection if
/// necessary to put it on a grapheme cluster boundary.
Expand Down
4 changes: 2 additions & 2 deletions druid-shell/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ impl WindowHandle {

/// Get the DPI scale of the window.
///
/// The returned [`Scale`](crate::Scale) is a copy and thus its information will be stale after
/// The returned [`Scale`] is a copy and thus its information will be stale after
/// the platform DPI changes. This means you should not stash it and rely on it later; it is
/// only guaranteed to be valid for the current pass of the runloop.
// TODO: Can we get rid of the Result/Error for ergonomics?
Expand All @@ -461,7 +461,7 @@ pub struct WindowBuilder(backend::WindowBuilder);
impl WindowBuilder {
/// Create a new `WindowBuilder`.
///
/// Takes the [`Application`](crate::Application) that this window is for.
/// Takes the [`Application`] that this window is for.
pub fn new(app: Application) -> WindowBuilder {
WindowBuilder(backend::WindowBuilder::new(app.backend_app))
}
Expand Down
1 change: 1 addition & 0 deletions druid/src/contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ pub trait ChangeCtx {
/// Convenience trait for invalidation and request methods available on multiple contexts.
///
/// These methods are available on [`EventCtx`], [`LifeCycleCtx`], and [`UpdateCtx`].
#[allow(dead_code)]
pub trait RequestCtx: ChangeCtx {
/// Request a [`paint`] pass. See ['request_paint']
///
Expand Down
2 changes: 1 addition & 1 deletion druid/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ impl<T: 'static> Data for std::mem::Discriminant<T> {
}
}

impl<T: 'static + ?Sized + Data> Data for std::mem::ManuallyDrop<T> {
impl<T: 'static + Data> Data for std::mem::ManuallyDrop<T> {
fn same(&self, other: &Self) -> bool {
(**self).same(&**other)
}
Expand Down
12 changes: 6 additions & 6 deletions druid/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,14 @@ pub enum Event {
/// may be generated from a number of sources:
///
/// - If your application uses menus (either window or context menus)
/// then the [`MenuItem`]s in the menu will each correspond to a `Command`.
/// When the menu item is selected, that [`Command`] will be delivered to
/// the root widget of the appropriate window.
/// then the [`MenuItem`]s in the menu will each correspond to a `Command`.
/// When the menu item is selected, that [`Command`] will be delivered to
/// the root widget of the appropriate window.
/// - If you are doing work in another thread (using an [`ExtEventSink`])
/// then [`Command`]s are the mechanism by which you communicate back to
/// the main thread.
/// then [`Command`]s are the mechanism by which you communicate back to
/// the main thread.
/// - Widgets and other Druid components can send custom [`Command`]s at
/// runtime, via methods such as [`EventCtx::submit_command`].
/// runtime, via methods such as [`EventCtx::submit_command`].
///
/// [`Widget`]: Widget
/// [`EventCtx::submit_command`]: crate::EventCtx::submit_command
Expand Down
4 changes: 2 additions & 2 deletions druid/src/sub_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ impl SubWindowDesc {
/// Creates a subwindow requirement that hosts the provided widget within a sub window host.
/// It will synchronise data updates with the provided parent_id if "sync" is true, and it will expect to be sent
/// SUB_WINDOW_PARENT_TO_HOST commands to update the provided data for the widget.
pub fn new<U, W: Widget<U>>(
pub fn new<U, W>(
parent_id: WidgetId,
window_config: WindowConfig,
widget: W,
data: U,
env: Env,
) -> SubWindowDesc
where
W: 'static,
W: Widget<U> + 'static,
U: Data,
{
let host_id = WidgetId::next();
Expand Down
4 changes: 2 additions & 2 deletions druid/src/tests/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ impl<T: Data> Harness<'_, T> {
/// # Arguments
///
/// * `data` - A structure that matches the type of the widget and that will be
/// passed to the `harness_closure` callback via the `Harness` structure.
/// passed to the `harness_closure` callback via the `Harness` structure.
///
/// * `root` - The widget under test
///
/// * `shape` - The shape of the render_context in the `Harness` structure
///
/// * `harness_closure` - A closure used to interact with the widget under test through the
/// `Harness` structure.
/// `Harness` structure.
///
/// * `render_context_closure` - A closure used to inspect the final render_context via the `TargetGuard` structure.
///
Expand Down
1 change: 1 addition & 0 deletions druid/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub trait ExtendDrain {
/// This function may swap the underlying memory locations,
/// so keep that in mind if one of the collections has a large allocation
/// and it should keep that allocation.
#[allow(dead_code)]
fn extend_drain(&mut self, source: &mut Self);
}

Expand Down
16 changes: 7 additions & 9 deletions druid/src/widget/flex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@ use tracing::{instrument, trace};
/// To experiment with these options, see the `flex` example in `druid/examples`.
///
/// - [`CrossAxisAlignment`] determines how children are positioned on the
/// cross or 'minor' axis. The default is `CrossAxisAlignment::Center`.
/// cross or 'minor' axis. The default is `CrossAxisAlignment::Center`.
///
/// - [`MainAxisAlignment`] determines how children are positioned on the main
/// axis; this is only meaningful if the container has more space on the main
/// axis than is taken up by its children.
/// axis; this is only meaningful if the container has more space on the main
/// axis than is taken up by its children.
///
/// - [`must_fill_main_axis`] determines whether the container is obliged to
/// be maximally large on the major axis, as determined by its own constraints.
/// If this is `true`, then the container must fill the available space on that
/// axis; otherwise it may be smaller if its children are smaller.
/// be maximally large on the major axis, as determined by its own constraints.
/// If this is `true`, then the container must fill the available space on that
/// axis; otherwise it may be smaller if its children are smaller.
///
/// Additional options can be set (or overridden) in the [`FlexParams`].
///
Expand Down Expand Up @@ -676,9 +676,7 @@ impl<T: Data> Widget<T> for Flex<T> {
any_use_baseline |= alignment == CrossAxisAlignment::Baseline;

let old_size = widget.layout_rect().size();
let child_bc =
self.direction
.constraints(&loosened_bc, 0.0, std::f64::INFINITY);
let child_bc = self.direction.constraints(&loosened_bc, 0.0, f64::INFINITY);
let child_size = widget.layout(ctx, &child_bc, data, env);

if child_size.width.is_infinite() {
Expand Down
Loading

0 comments on commit 49b5352

Please sign in to comment.