Skip to content

Commit

Permalink
Update the CI and pin the Rust toolchain version. (#2398)
Browse files Browse the repository at this point in the history
* Update the CI and pin the Rust toolchain version.

* Update Rust stable toolchain to 1.76.

* Satisfy Clippy on Windows.

* Convert CustomCursor back to Arc to avoid a breaking API change.

* Fix some Linux Clippy issues.

* Fix more Linux Clippy issues.
  • Loading branch information
xStrom authored Feb 23, 2024
1 parent e53a5ab commit f45c892
Show file tree
Hide file tree
Showing 18 changed files with 117 additions and 286 deletions.
332 changes: 76 additions & 256 deletions .github/workflows/ci.yml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "2"
members = [
"druid",
"druid-shell",
Expand Down
3 changes: 1 addition & 2 deletions druid-shell/src/backend/shared/xkb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,7 @@ impl State {
}
// add 1 because we will get a null-terminated string.
let len = usize::try_from(len).unwrap() + 1;
let mut buf: Vec<u8> = Vec::new();
buf.resize(len, 0);
let mut buf: Vec<u8> = vec![0; len];
xkb_state_key_get_utf8(self.state, scancode, buf.as_mut_ptr() as *mut c_char, len);
assert!(buf[buf.len() - 1] == 0);
buf.pop();
Expand Down
2 changes: 1 addition & 1 deletion druid-shell/src/backend/wayland/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ impl Data {

fn current_window_id(&self) -> u64 {
static DEFAULT: u64 = 0_u64;
*self.active_surface_id.borrow().get(0).unwrap_or(&DEFAULT)
*self.active_surface_id.borrow().front().unwrap_or(&DEFAULT)
}

pub(super) fn acquire_current_window(&self) -> Option<WindowHandle> {
Expand Down
2 changes: 1 addition & 1 deletion druid-shell/src/backend/wayland/clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ impl Clipboard {

/// Get a string from the system clipboard, if one is available.
pub fn get_string(&self) -> Option<String> {
vec![Clipboard::UTF8, Clipboard::TEXT, Clipboard::UTF8_STRING]
[Clipboard::UTF8, Clipboard::TEXT, Clipboard::UTF8_STRING]
.iter()
.find_map(
|mimetype| match std::str::from_utf8(&self.inner.receive(*mimetype)?) {
Expand Down
1 change: 0 additions & 1 deletion druid-shell/src/backend/wayland/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,6 @@ impl Manager {
if let Some(windata) = winhandle.data() {
windata.with_handler({
let windata = windata.clone();
let evt = evt;
move |handler| match evt.state {
KeyState::Up => {
handler.key_up(evt.clone());
Expand Down
3 changes: 3 additions & 0 deletions druid-shell/src/backend/wayland/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

//! wayland platform support
// TODO: Remove this and fix the non-Send/Sync Arc issues
#![allow(clippy::arc_with_non_send_sync)]

pub mod application;
pub mod clipboard;
mod display;
Expand Down
6 changes: 3 additions & 3 deletions druid-shell/src/backend/wayland/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ impl WindowBuilder {
}

pub fn build(self) -> Result<WindowHandle, ShellError> {
if matches!(self.menu, Some(_)) {
if self.menu.is_some() {
tracing::warn!("menus unimplemented for wayland");
}

Expand Down Expand Up @@ -552,7 +552,7 @@ pub mod layershell {

let handle = WindowHandle::new(
surface.clone(),
surfaces::surface::Dead::default(),
surfaces::surface::Dead,
surface.clone(),
surface.clone(),
self.appdata.clone(),
Expand Down Expand Up @@ -622,7 +622,7 @@ pub mod popup {

let handle = WindowHandle::new(
surface.clone(),
surfaces::surface::Dead::default(),
surfaces::surface::Dead,
surface.clone(),
surface.clone(),
wappdata,
Expand Down
6 changes: 5 additions & 1 deletion druid-shell/src/backend/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ 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>);

#[derive(PartialEq, Eq)]
Expand Down Expand Up @@ -1076,7 +1078,7 @@ impl WndProc for MyWndProc {
// When maximized, windows still adds offsets for the frame
// so we counteract them here.
let s: *mut NCCALCSIZE_PARAMS = lparam as *mut NCCALCSIZE_PARAMS;
if let Some(mut s) = s.as_mut() {
if let Some(s) = s.as_mut() {
let border = self.get_system_metric(SM_CXPADDEDBORDER);
let frame = self.get_system_metric(SM_CYSIZEFRAME);
s.rgrc[0].top += border + frame;
Expand Down Expand Up @@ -2435,6 +2437,8 @@ 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)))))
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion druid/examples/sub_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ fn build_root_widget() -> impl Widget<HelloState> {
// arrange the two widgets vertically, with some padding
let layout = Flex::column()
.with_child(label)
.with_flex_child(ScreenThing.lens(Unit::default()).padding(5.), 1.)
.with_flex_child(ScreenThing.lens(Unit).padding(5.), 1.)
.with_spacer(VERTICAL_WIDGET_SPACING)
.with_child(textbox)
.with_child(button)
Expand Down
3 changes: 3 additions & 0 deletions druid/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

//! An environment which is passed downward into the widget tree.
// TODO: Figure out if Env really needs to stay Arc, or if it can be switched to Rc
#![allow(clippy::arc_with_non_send_sync)]

use std::any::{self, Any};
use std::borrow::Borrow;
use std::collections::{hash_map::Entry, HashMap};
Expand Down
5 changes: 2 additions & 3 deletions druid/src/sub_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use crate::win_handler::AppState;
use crate::{Data, Point, Widget, WidgetExt, WidgetId, WidgetPod, WindowHandle, WindowId};
use druid_shell::Error;
use std::any::Any;
use std::ops::Deref;
use tracing::{instrument, warn};
// We can't have any type arguments here, as both ends would need to know them
// ahead of time in order to instantiate correctly.
Expand Down Expand Up @@ -70,7 +69,7 @@ impl SubWindowDesc {
app_state: &mut AppState<T>,
) -> Result<WindowHandle, Error> {
let sub_window_root = self.sub_window_root;
let pending = PendingWindow::new(sub_window_root.lens(Unit::default()));
let pending = PendingWindow::new(sub_window_root.lens(Unit));
app_state.build_native_window(self.window_id, pending, self.window_config)
}
}
Expand Down Expand Up @@ -107,7 +106,7 @@ impl<U: Data, W: Widget<U>> Widget<()> for SubWindowHost<U, W> {
let update = cmd.get_unchecked(SUB_WINDOW_PARENT_TO_HOST);
if let Some(data_update) = &update.data {
if let Some(dc) = data_update.downcast_ref::<U>() {
self.data = dc.deref().clone();
self.data = dc.clone();
ctx.request_update();
} else {
warn!("Received a sub window parent to host command that could not be unwrapped. \
Expand Down
2 changes: 2 additions & 0 deletions druid/src/text/input_component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,8 @@ impl<T> Default for TextComponent<T> {

TextComponent {
edit_session: Arc::new(RefCell::new(inner)),
// TODO: Figure out if this needs to stay Arc, or if it can be switched to Rc
#[allow(clippy::arc_with_non_send_sync)]
lock: Arc::new(Cell::new(ImeLock::None)),
has_focus: false,
}
Expand Down
2 changes: 2 additions & 0 deletions druid/src/text/rich_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ impl RichText {
RichText {
buffer,
attrs: Arc::new(attributes),
// TODO: Figure out if this needs to stay Arc, or if it can be switched to Rc
#[allow(clippy::arc_with_non_send_sync)]
links: Arc::new([]),
}
}
Expand Down
25 changes: 11 additions & 14 deletions druid/src/widget/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,12 @@ mod tests {
// the padding color and the middle rows will not have any padding.

// Check that the middle row 400 pix wide is 200 black then 200 white.
let expecting: Vec<u8> = [
vec![0, 0, 0, 255].repeat(200),
vec![255, 255, 255, 255].repeat(200),
]
.concat();
let expecting: Vec<u8> =
[[0, 0, 0, 255].repeat(200), [255, 255, 255, 255].repeat(200)].concat();
assert_eq!(raw_pixels[400 * 300 * 4..400 * 301 * 4], expecting[..]);

// Check that all of the last 100 rows are all the background color.
let expecting: Vec<u8> = vec![41, 41, 41, 255].repeat(400 * 100);
let expecting: Vec<u8> = [41, 41, 41, 255].repeat(400 * 100);
assert_eq!(
raw_pixels[400 * 600 * 4 - 4 * 400 * 100..400 * 600 * 4],
expecting[..]
Expand Down Expand Up @@ -367,20 +364,20 @@ mod tests {

// A middle row of 600 pixels is 100 padding 200 black, 200 white and then 100 padding.
let expecting: Vec<u8> = [
vec![41, 41, 41, 255].repeat(100),
vec![255, 255, 255, 255].repeat(200),
vec![0, 0, 0, 255].repeat(200),
vec![41, 41, 41, 255].repeat(100),
[41, 41, 41, 255].repeat(100),
[255, 255, 255, 255].repeat(200),
[0, 0, 0, 255].repeat(200),
[41, 41, 41, 255].repeat(100),
]
.concat();
assert_eq!(raw_pixels[199 * 600 * 4..200 * 600 * 4], expecting[..]);

// The final row of 600 pixels is 100 padding 200 black, 200 white and then 100 padding.
let expecting: Vec<u8> = [
vec![41, 41, 41, 255].repeat(100),
vec![0, 0, 0, 255].repeat(200),
vec![255, 255, 255, 255].repeat(200),
vec![41, 41, 41, 255].repeat(100),
[41, 41, 41, 255].repeat(100),
[0, 0, 0, 255].repeat(200),
[255, 255, 255, 255].repeat(200),
[41, 41, 41, 255].repeat(100),
]
.concat();
assert_eq!(raw_pixels[399 * 600 * 4..400 * 600 * 4], expecting[..]);
Expand Down
2 changes: 1 addition & 1 deletion druid/src/widget/progress_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct ProgressBar;
impl ProgressBar {
/// Return a new `ProgressBar`.
pub fn new() -> ProgressBar {
Self::default()
Self
}
}

Expand Down
4 changes: 2 additions & 2 deletions druid/src/widget/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ impl<L: Lens<State, In>, In, State> LensScopeTransfer<L, In, State> {
pub fn new(lens: L) -> Self {
LensScopeTransfer {
lens,
phantom_in: PhantomData::default(),
phantom_state: PhantomData::default(),
phantom_in: PhantomData,
phantom_state: PhantomData,
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions druid/src/widget/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ impl std::str::FromStr for SvgData {
};

match Tree::from_str(svg_str, &re_opt.to_ref()) {
// TODO: Figure out if this needs to stay Arc, or if it can be switched to Rc
#[allow(clippy::arc_with_non_send_sync)]
Ok(tree) => Ok(SvgData::new(Arc::new(tree))),
Err(err) => Err(err.into()),
}
Expand Down

0 comments on commit f45c892

Please sign in to comment.