Clear clippy 1.97 lints across bread-theme, bread-utils, bread-polkit

Toolchain drift (clippy 0.1.97): pre-existing on main, all mechanical
and behaviour-preserving.

- bread-theme/gtk.rs: `type AppCssBuilder` alias for the repeated
  `Rc<dyn Fn(&Palette) -> String>` (type_complexity ×4).
- bread-theme/lib.rs: `sort_by_key(|..| Reverse(len))` (unnecessary_sort_by).
- bread-theme/output.rs: `io::Error::other`; struct-init in a test.
- bread-utils/singleton.rs: explicit `.truncate(false)` on the lock file
  open — we only clear it after winning the lock (suspicious_open_options).
- bread-polkit/identity.rs: elide `pick_user` lifetimes.
This commit is contained in:
Breadway 2026-08-31 15:20:15 +08:00
parent 6d9912af56
commit a86c31291b
5 changed files with 24 additions and 15 deletions

View file

@ -37,7 +37,7 @@ pub fn users_from_uids(uids: &[u32], passwd: &str) -> Vec<UnixUser> {
}
/// Prefer the process's own uid when it is in `users`, otherwise the first.
pub fn pick_user<'a>(users: &'a [UnixUser], current_uid: Option<u32>) -> Option<&'a UnixUser> {
pub fn pick_user(users: &[UnixUser], current_uid: Option<u32>) -> Option<&UnixUser> {
if let Some(uid) = current_uid {
if let Some(user) = users.iter().find(|u| u.uid == uid) {
return Some(user);

View file

@ -10,6 +10,10 @@ use std::rc::Rc;
use crate::Palette;
/// Per-widget app-CSS builder: given the resolved palette for the widget's
/// monitor, produce the app stylesheet to layer on top of the theme CSS.
type AppCssBuilder = Rc<dyn Fn(&Palette) -> String>;
/// Above APPLICATION (600) so we beat [`apply_shared`], below USER (800)
/// so `apply_user_css` still wins.
const BIND_PRIORITY: u32 = gtk4::STYLE_PROVIDER_PRIORITY_USER - 10;
@ -162,7 +166,7 @@ struct WidgetBind {
output: String,
theme: CssProvider,
app: Option<CssProvider>,
app_build: Option<Rc<dyn Fn(&Palette) -> String>>,
app_build: Option<AppCssBuilder>,
/// Keep the directory monitor + child model alive for this widget.
_watch: Option<gio::ListModel>,
}
@ -284,7 +288,7 @@ fn watch_root_children(widget: &gtk4::Widget) -> gio::ListModel {
fn bind_window_inner(
widget: &gtk4::Widget,
output: &str,
app_build: Option<Rc<dyn Fn(&Palette) -> String>>,
app_build: Option<AppCssBuilder>,
) {
let key = widget_key(widget);
let palette = crate::load_palette_for(output);
@ -387,7 +391,7 @@ where
bind_window_inner(widget.as_ref(), output, Some(Rc::new(build)));
}
fn attach_enter_monitor(widget: &gtk4::Widget, build: Option<Rc<dyn Fn(&Palette) -> String>>) {
fn attach_enter_monitor(widget: &gtk4::Widget, build: Option<AppCssBuilder>) {
let Some(native) = widget.native() else {
return;
};
@ -408,7 +412,7 @@ fn attach_enter_monitor(widget: &gtk4::Widget, build: Option<Rc<dyn Fn(&Palette)
});
}
fn bind_auto(native: &gtk4::Native, build: Option<Rc<dyn Fn(&Palette) -> String>>) {
fn bind_auto(native: &gtk4::Native, build: Option<AppCssBuilder>) {
let widget = native.upcast_ref::<gtk4::Widget>().clone();
let apply = {

View file

@ -330,7 +330,8 @@ pub fn stylesheet_resolved(p: &Palette) -> String {
/// named colors cannot leak the wrong monitor's accent.
pub(crate) fn resolve_color_names(css: &str, p: &Palette) -> String {
let mut pairs: Vec<(&str, String)> = color_pairs(p).into_iter().collect();
pairs.sort_by(|a, b| b.0.len().cmp(&a.0.len()));
// Longest name first, so `@on-bg` is replaced before `@bg` can match its tail.
pairs.sort_by_key(|(name, _)| std::cmp::Reverse(name.len()));
let mut out = css.to_string();
for (name, value) in pairs {
out = out.replace(&format!("@{name}"), &value);
@ -544,8 +545,10 @@ mod tests {
#[test]
fn stylesheet_resolved_inlines_color4_and_drops_named_refs_in_rules() {
let mut p = Palette::default();
p.color4 = "#7aa2f7".into();
let p = Palette {
color4: "#7aa2f7".into(),
..Default::default()
};
let css = stylesheet_resolved(&p);
assert!(css.contains("#7aa2f7"), "color4 must appear as hex: {css}");
// Rule bodies must not keep named colors — GTK display-global

View file

@ -185,10 +185,7 @@ pub fn palette_from_image(path: &Path) -> std::io::Result<Palette> {
Ok(s) => s,
};
if !status.success() {
return Err(std::io::Error::new(
std::io::ErrorKind::Other,
format!("wal failed with {status}"),
));
return Err(std::io::Error::other(format!("wal failed with {status}")));
}
let json_path = [
@ -299,9 +296,11 @@ mod tests {
#[test]
fn write_output_palette_roundtrips_color4() {
with_runtime_dir(|_| {
let mut p = Palette::default();
p.color4 = "#7aa2f7".into();
p.background = "#ffffff".into();
let p = Palette {
color4: "#7aa2f7".into(),
background: "#ffffff".into(),
..Default::default()
};
write_output_palette("HDMI-A-1", &p).unwrap();
let loaded = load_palette_for("HDMI-A-1");
assert_eq!(loaded.color4, "#7aa2f7");

View file

@ -80,6 +80,9 @@ pub fn try_acquire(app: &str) -> std::io::Result<Acquire> {
.read(true)
.write(true)
.create(true)
// Never truncate on open: an existing lock file may be held by a live
// instance. We only clear it (`set_len(0)`) *after* winning the lock.
.truncate(false)
.open(&path)?;
match file.try_lock() {