Zero warnings on Windows and Linux, clippy included (W-02, L-02)
rustc and clippy are clean for the whole workspace, every target, on both. clippy --fix moved test modules last and took the shorter forms; long types got named aliases; ElyTree's form takes its title and button words as one pair. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c96d39a342
commit
9c9f9ab8f9
26 files changed
+73
-60
No files matched your search
@@ -365,7 +365,7 @@ fn a_macro_file_opens_in_risk_mode_and_saves_only_as_a_copy() {
|
||||
);
|
||||
cx.update(|app| {
|
||||
assert!(
|
||||
!docs.read(app).active_tab().expect("a tab").risk.is_some(),
|
||||
docs.read(app).active_tab().expect("a tab").risk.is_none(),
|
||||
"the DOCX copy holds no macros"
|
||||
)
|
||||
});
|
||||
|
||||
@@ -236,7 +236,8 @@ impl Viewer {
|
||||
}
|
||||
|
||||
fn protect_rows(&self, on: bool, user: &Entity<TextInput>, owner: &Entity<TextInput>, allow: u32, this: &Entity<Self>, cx: &mut Context<Self>) -> AnyElement {
|
||||
let set = |change: Box<dyn Fn(&mut bool, &mut u32, bool)>| {
|
||||
type Change = Box<dyn Fn(&mut bool, &mut u32, bool)>;
|
||||
let set = |change: Change| {
|
||||
let this = this.clone();
|
||||
move |value: bool, _: &mut Window, cx: &mut App| {
|
||||
this.update(cx, |viewer, cx| {
|
||||
|
||||
@@ -57,12 +57,11 @@ impl PdfView {
|
||||
self.off(
|
||||
move |worker| {
|
||||
let fields = worker.signatures(doc, &path)?;
|
||||
Ok(fields.into_iter().map(|field| {
|
||||
Ok(Iterator::collect::<Vec<_>>(fields.into_iter().map(|field| {
|
||||
let chain = field.signed.as_ref().map(|signed| signed.certs.clone()).filter(|certs| !certs.is_empty());
|
||||
let trust = chain.map(|chain| trust::check(&chain).map_err(|error| error.to_string()));
|
||||
Checked { field, trust }
|
||||
}))
|
||||
.map(Iterator::collect::<Vec<_>>)
|
||||
})))
|
||||
},
|
||||
move |view, read: io::Result<Vec<Checked>>, cx| {
|
||||
view.reading_signatures = false;
|
||||
|
||||
@@ -76,7 +76,7 @@ fn a_damaged_file_opens_repaired_and_saves_as_a_new_file() {
|
||||
bytes.truncate(at);
|
||||
bytes.extend_from_slice(b"startxref\n9\n%%EOF\n");
|
||||
std::fs::write(&path, &bytes).expect("writes");
|
||||
let (viewer, cx) = windowed(&mut cx, dir.path(), &[path.clone()], true);
|
||||
let (viewer, cx) = windowed(&mut cx, dir.path(), std::slice::from_ref(&path), true);
|
||||
let view = shown(cx, &viewer);
|
||||
assert_eq!(cx.update(|_, app| viewer.read(app).active_tab().and_then(|tab| tab.risk)), Some(ely_office::Risk::Repaired));
|
||||
assert!(cx.update(|_, app| view.read(app).repair.as_ref().is_some_and(|report| !report.is_empty())));
|
||||
@@ -158,7 +158,7 @@ fn a_picture_that_breaks_as_it_draws_stops_an_overwrite() {
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let (path, bytes) = broken_picture(dir.path(), 792.0, 600.0);
|
||||
let (viewer, cx) = windowed(&mut cx, dir.path(), &[path.clone()], true);
|
||||
let (viewer, cx) = windowed(&mut cx, dir.path(), std::slice::from_ref(&path), true);
|
||||
shown(cx, &viewer);
|
||||
settle(cx, |app| viewer.read(app).active_tab().and_then(|tab| tab.risk) == Some(ely_office::Risk::Repaired));
|
||||
let id = cx.update(|_, app| viewer.read(app).core.tabs[0].id);
|
||||
@@ -184,7 +184,7 @@ fn a_picture_never_drawn_is_checked_before_an_overwrite() {
|
||||
let path = dir.path().join("long.pdf");
|
||||
worker.save(doc, &path).expect("saves");
|
||||
let bytes = std::fs::read(&path).expect("reads");
|
||||
let (viewer, cx) = windowed(&mut cx, dir.path(), &[path.clone()], true);
|
||||
let (viewer, cx) = windowed(&mut cx, dir.path(), std::slice::from_ref(&path), true);
|
||||
shown(cx, &viewer);
|
||||
for _ in 0..10 {
|
||||
super::frames(cx);
|
||||
|
||||
@@ -212,7 +212,7 @@ fn reopening_the_dialog_checks_the_file_as_it_is_now() {
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let path = signed(dir.path());
|
||||
let (viewer, cx) = windowed(&mut cx, dir.path(), &[path.clone()], true);
|
||||
let (viewer, cx) = windowed(&mut cx, dir.path(), std::slice::from_ref(&path), true);
|
||||
let view = shown(cx, &viewer);
|
||||
let digest = |cx: &mut VisualTestContext| {
|
||||
cx.update(|_, app| viewer.update(app, |viewer, cx| viewer.show_signatures(true, cx)));
|
||||
|
||||
@@ -69,7 +69,7 @@ impl Host for Viewer {
|
||||
}
|
||||
|
||||
fn read_at(&self, tab: u64, cx: &gpui::App) -> Option<ely_pdf_engine::Doc> {
|
||||
self.tab(tab).map(|tab| tab.view.read(cx).doc.clone())
|
||||
self.tab(tab).map(|tab| tab.view.read(cx).doc)
|
||||
}
|
||||
|
||||
fn observed(&mut self, id: u64, view: &Entity<PdfView>, cx: &mut Context<Self>) {
|
||||
|
||||
@@ -45,8 +45,11 @@ pub struct Making {
|
||||
picture: Option<(PathBuf, f32)>,
|
||||
}
|
||||
|
||||
/// Points of each stroke.
|
||||
type Strokes = Vec<Vec<(f32, f32)>>;
|
||||
|
||||
/// Strokes moved to the corner, the longer side 1.
|
||||
pub fn fitted(strokes: &[Vec<(f32, f32)>]) -> Option<(Vec<Vec<(f32, f32)>>, f32)> {
|
||||
pub fn fitted(strokes: &[Vec<(f32, f32)>]) -> Option<(Strokes, f32)> {
|
||||
if strokes.iter().all(|stroke| stroke.len() < 2) {
|
||||
return None;
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ mod tests {
|
||||
_ => None,
|
||||
});
|
||||
let names: Vec<_> = names.collect();
|
||||
(names.iter().any(|name| *name == media), names.len())
|
||||
(names.contains(&media), names.len())
|
||||
});
|
||||
assert_eq!(offered, ely_platform::media::BUILT);
|
||||
assert!(total >= 11, "the rest stay: {total}");
|
||||
|
||||
@@ -419,6 +419,8 @@ fn frozen_index(state: Option<&str>) -> Option<u32> {
|
||||
(index > 0).then_some(index)
|
||||
}
|
||||
|
||||
impl Zooming for Book {}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
@@ -428,5 +430,3 @@ mod tests {
|
||||
assert_eq!(super::frozen_index(None), None);
|
||||
}
|
||||
}
|
||||
|
||||
impl Zooming for Book {}
|
||||
@@ -251,8 +251,7 @@ impl Tree {
|
||||
let (title, go) = (label("tree.branch.title"), label("tree.branch.create"));
|
||||
Some(self.form(
|
||||
"tree-new-branch",
|
||||
title,
|
||||
go,
|
||||
(title, go),
|
||||
rows,
|
||||
Some(toggle.into_any_element()),
|
||||
dismiss,
|
||||
@@ -271,7 +270,7 @@ impl Tree {
|
||||
div().w_full().child(Input::new(message)),
|
||||
);
|
||||
let (title, go) = (label("tree.tag.title"), label("tree.tag.create"));
|
||||
Some(self.form("tree-new-tag", title, go, rows, None, dismiss, cx))
|
||||
Some(self.form("tree-new-tag", (title, go), rows, None, dismiss, cx))
|
||||
}
|
||||
Ask::Rename { old, name, .. } => {
|
||||
let label = |key: &str| text(cx, key, &[]);
|
||||
@@ -283,7 +282,7 @@ impl Tree {
|
||||
text(cx, "tree.rename.title", &[("name", old)]),
|
||||
label("tree.rename.go"),
|
||||
);
|
||||
Some(self.form("tree-rename", title, go, rows, None, dismiss, cx))
|
||||
Some(self.form("tree-rename", (title, go), rows, None, dismiss, cx))
|
||||
}
|
||||
Ask::Stash { .. }
|
||||
| Ask::Remote { .. }
|
||||
@@ -347,8 +346,7 @@ impl Tree {
|
||||
pub(crate) fn form(
|
||||
&self,
|
||||
id: &'static str,
|
||||
title: gpui::SharedString,
|
||||
go: gpui::SharedString,
|
||||
(title, go): (gpui::SharedString, gpui::SharedString),
|
||||
rows: DescriptionList,
|
||||
extra: Option<AnyElement>,
|
||||
dismiss: impl Fn(&mut Window, &mut App) + 'static,
|
||||
|
||||
@@ -56,7 +56,7 @@ impl Tree {
|
||||
},
|
||||
);
|
||||
let (title, go) = (label("tree.stash.title"), label("tree.stash.go"));
|
||||
self.form("tree-stash", title, go, rows, Some(extra), dismiss, cx)
|
||||
self.form("tree-stash", (title, go), rows, Some(extra), dismiss, cx)
|
||||
}
|
||||
Ask::Remote { old, name, url, .. } => {
|
||||
let rows = DescriptionList::new()
|
||||
@@ -73,7 +73,7 @@ impl Tree {
|
||||
None => label("tree.remote.add"),
|
||||
};
|
||||
let go = label("tree.remote.save");
|
||||
self.form("tree-remote", title, go, rows, None, dismiss, cx)
|
||||
self.form("tree-remote", (title, go), rows, None, dismiss, cx)
|
||||
}
|
||||
Ask::Worktree {
|
||||
path, branch, new, ..
|
||||
@@ -90,7 +90,7 @@ impl Tree {
|
||||
let shown = path.display().to_string();
|
||||
let title = text(cx, "tree.worktree.title", &[("path", &shown)]);
|
||||
let go = label("tree.worktree.go");
|
||||
self.form("tree-worktree", title, go, rows, Some(extra), dismiss, cx)
|
||||
self.form("tree-worktree", (title, go), rows, Some(extra), dismiss, cx)
|
||||
}
|
||||
Ask::Force { repo, plan } => {
|
||||
let lost = match plan.lost.len() {
|
||||
|
||||
@@ -150,11 +150,10 @@ impl Tree {
|
||||
(self.amend, self.draft) = (false, None);
|
||||
self.fill("", "", cx);
|
||||
}
|
||||
} else if let Some(opened) = self.opened_mut(id) {
|
||||
if commit::message(&opened.held.subject, &opened.held.body) == message {
|
||||
} else if let Some(opened) = self.opened_mut(id)
|
||||
&& commit::message(&opened.held.subject, &opened.held.body) == message {
|
||||
opened.held = Held::default();
|
||||
}
|
||||
}
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
|
||||
@@ -253,7 +253,7 @@ impl Tree {
|
||||
pub fn search(&mut self, cx: &mut Context<Self>) {
|
||||
let Some(id) = self.active else { return };
|
||||
let text = self.search.read(cx).text().trim().to_string();
|
||||
let query = (!text.is_empty()).then(|| Query {
|
||||
let query = (!text.is_empty()).then_some(Query {
|
||||
find: self.find,
|
||||
text,
|
||||
});
|
||||
|
||||
@@ -195,10 +195,8 @@ impl Tree {
|
||||
/// Pick, revert, or branch or tag at this commit.
|
||||
fn commit_actions(&self, detail: &Detail, cx: &mut Context<Self>) -> AnyElement {
|
||||
let (id, parents) = (detail.id.clone(), detail.parents.len());
|
||||
let acts: [(
|
||||
&str,
|
||||
Box<dyn Fn(&mut Tree, &mut gpui::Window, &mut Context<Tree>)>,
|
||||
); 4] = [
|
||||
type Act = Box<dyn Fn(&mut Tree, &mut gpui::Window, &mut Context<Tree>)>;
|
||||
let acts: [(&str, Act); 4] = [
|
||||
("tree.commit.pick_it", {
|
||||
let id = id.clone();
|
||||
Box::new(move |tree, _, cx| tree.cherry_pick(&id, parents, cx))
|
||||
|
||||
@@ -13,6 +13,9 @@ use crate::{
|
||||
tree::Tree,
|
||||
};
|
||||
|
||||
/// A commit and its added and removed line counts.
|
||||
type Row = (Commit, Option<(usize, usize)>);
|
||||
|
||||
pub enum Look {
|
||||
FileLog {
|
||||
repo: u64,
|
||||
@@ -20,7 +23,7 @@ pub enum Look {
|
||||
serial: u64,
|
||||
path: String,
|
||||
touches: Option<Result<Vec<Touch>, String>>,
|
||||
rows: Rc<Vec<(Commit, Option<(usize, usize)>)>>,
|
||||
rows: Rc<Vec<Row>>,
|
||||
picked: Option<usize>,
|
||||
view: Option<Result<View, String>>,
|
||||
},
|
||||
|
||||
@@ -18,7 +18,7 @@ pub fn records(bytes: &[u8], n: usize) -> io::Result<Vec<Vec<&str>>> {
|
||||
if fields.last() == Some(&"") {
|
||||
fields.pop();
|
||||
}
|
||||
if fields.len() % n != 0 {
|
||||
if !fields.len().is_multiple_of(n) {
|
||||
return Err(bad(text));
|
||||
}
|
||||
Ok(fields.chunks(n).map(<[&str]>::to_vec).collect())
|
||||
|
||||
@@ -53,7 +53,9 @@ pub(crate) fn committed(dir: &Path) -> PathBuf {
|
||||
root
|
||||
}
|
||||
|
||||
fn paths(files: &[Changed]) -> Vec<(&str, GitStatus, Option<(usize, usize)>)> {
|
||||
type Listed<'a> = (&'a str, GitStatus, Option<(usize, usize)>);
|
||||
|
||||
fn paths(files: &[Changed]) -> Vec<Listed<'_>> {
|
||||
files
|
||||
.iter()
|
||||
.map(|file| (file.path.as_ref(), file.status, file.lines))
|
||||
|
||||
@@ -273,19 +273,6 @@ pub fn outward(uri: &str) -> bool {
|
||||
.any(|scheme| uri.get(..scheme.len()).is_some_and(|head| head.eq_ignore_ascii_case(scheme)))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod outward_tests {
|
||||
#[test]
|
||||
fn web_and_mail_go_out_in_any_case() {
|
||||
for uri in ["https://a.example/", "HTTPS://a.example/", "Http://a.example/", "MAILTO:x@a.example"] {
|
||||
assert!(super::outward(uri), "{uri}");
|
||||
}
|
||||
for uri in ["ftp://a.example/", "file:///etc/passwd", "javascript:alert(1)", "httpsx://a", "ht", "\u{e9}https://"] {
|
||||
assert!(!super::outward(uri), "{uri}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A localized message.
|
||||
pub fn text(cx: &App, key: &str, args: &[(&str, &str)]) -> SharedString {
|
||||
ely_ui::i18n::text(cx, key, args)
|
||||
@@ -402,3 +389,16 @@ pub trait Tabs: Host {
|
||||
}
|
||||
|
||||
impl<H: Host> Tabs for H {}
|
||||
|
||||
#[cfg(test)]
|
||||
mod outward_tests {
|
||||
#[test]
|
||||
fn web_and_mail_go_out_in_any_case() {
|
||||
for uri in ["https://a.example/", "HTTPS://a.example/", "Http://a.example/", "MAILTO:x@a.example"] {
|
||||
assert!(super::outward(uri), "{uri}");
|
||||
}
|
||||
for uri in ["ftp://a.example/", "file:///etc/passwd", "javascript:alert(1)", "httpsx://a", "ht", "\u{e9}https://"] {
|
||||
assert!(!super::outward(uri), "{uri}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -205,11 +205,12 @@ fn big_png(path: &Path, side: u32) {
|
||||
let mut raw = Vec::new();
|
||||
let mut seed = 7u32;
|
||||
for _ in 0..side {
|
||||
raw.push(0);
|
||||
for _ in 0..side * 3 {
|
||||
// Each row: filter byte none, then its noise.
|
||||
let noise = (0..side * 3).map(|_| {
|
||||
seed = seed.wrapping_mul(1_103_515_245).wrapping_add(12_345);
|
||||
raw.push((seed >> 16) as u8);
|
||||
}
|
||||
(seed >> 16) as u8
|
||||
});
|
||||
raw.extend(std::iter::once(0).chain(noise));
|
||||
}
|
||||
// zlib with stored blocks; Adler-32 at the end.
|
||||
let mut zlib = vec![0x78, 0x01];
|
||||
@@ -246,7 +247,7 @@ fn a_failed_open_keeps_no_memory() {
|
||||
};
|
||||
// MuPDF's 256 MB store fills first; then nothing grows.
|
||||
for _ in 0..70 {
|
||||
let refused = worker.open(&png).err().expect("not a PDF");
|
||||
let refused = worker.open(&png).expect_err("not a PDF");
|
||||
assert!(refused.to_string().contains("not a PDF"), "{refused}");
|
||||
}
|
||||
let before = rss(worker.pid());
|
||||
|
||||
@@ -26,7 +26,7 @@ fn platform() -> String {
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn platform() -> String {
|
||||
resolve_env(|key| env::value(key))
|
||||
resolve_env(env::value)
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
|
||||
@@ -155,8 +155,11 @@ pub fn install_as(locale: &'static str, cx: &mut App) {
|
||||
);
|
||||
}
|
||||
|
||||
/// Keys and messages of one language.
|
||||
type Catalog = Vec<(&'static str, &'static str)>;
|
||||
|
||||
/// The English and Chinese catalogs, every module's messages.
|
||||
fn catalogs() -> (Vec<(&'static str, &'static str)>, Vec<(&'static str, &'static str)>) {
|
||||
fn catalogs() -> (Catalog, Catalog) {
|
||||
let en: Vec<_> = EN
|
||||
.iter()
|
||||
.chain(office::EN)
|
||||
|
||||
@@ -18,10 +18,13 @@ use gpui::{AnyElement, App, Context, IntoElement, SharedString, WeakEntity};
|
||||
use super::window::SettingsView;
|
||||
use crate::i18n::text;
|
||||
|
||||
/// Each kind's size, and whether a clear waits.
|
||||
type Usage = Vec<(Kind, u64, bool)>;
|
||||
|
||||
/// Last read sizes and limits; a clear waiting or failed.
|
||||
#[derive(Default)]
|
||||
pub(crate) struct Storage {
|
||||
usage: Option<Result<Vec<(Kind, u64, bool)>, SharedString>>,
|
||||
usage: Option<Result<Usage, SharedString>>,
|
||||
limits: Option<Result<Limits, SharedString>>,
|
||||
/// A clear waiting for the user's yes.
|
||||
confirming: Option<Kind>,
|
||||
|
||||
@@ -179,7 +179,7 @@ impl Probe {
|
||||
cx.background_executor()
|
||||
.timer(Duration::from_millis(500))
|
||||
.await;
|
||||
let _ = view.update(cx, |view, _| view.run_js("report('edited')"));
|
||||
view.update(cx, |view, _| view.run_js("report('edited')"));
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
|
||||
@@ -284,7 +284,7 @@ pub fn start(data: &Path, cx: &mut App) -> Result<()> {
|
||||
let why = held(&cache).unwrap_or_else(|| "CEF did not initialize".into());
|
||||
log::error!("web: {why}");
|
||||
*FAILED.lock().expect("the start lock") = Some(why);
|
||||
cx.update(|cx| crate::view::deliver(cx));
|
||||
cx.update(crate::view::deliver);
|
||||
return;
|
||||
}
|
||||
log::info!("web: CEF started, cache {}", cache.display());
|
||||
@@ -310,7 +310,7 @@ pub fn start(data: &Path, cx: &mut App) -> Result<()> {
|
||||
run_later();
|
||||
make_browsers();
|
||||
do_message_loop_work();
|
||||
cx.update(|cx| crate::view::deliver(cx));
|
||||
cx.update(crate::view::deliver);
|
||||
// As cefclient: CEF does not ask for all work.
|
||||
due = Some(FALLBACK);
|
||||
}
|
||||
|
||||
@@ -314,7 +314,7 @@ wrap_load_handler! {
|
||||
failed_url: Option<&CefString>,
|
||||
) {
|
||||
// A stopped load is no failure; a fenced one is.
|
||||
if !frame.is_some_and(|frame| frame.is_main() == 1) || error_code == Errorcode::ABORTED {
|
||||
if frame.is_none_or(|frame| frame.is_main() != 1) || error_code == Errorcode::ABORTED {
|
||||
return;
|
||||
}
|
||||
let text = error_text.map(CefString::to_string).unwrap_or_default();
|
||||
|
||||
@@ -64,9 +64,12 @@ pub struct WebView {
|
||||
/// Shown instead of the page until reloaded.
|
||||
fault: Option<String>,
|
||||
/// Takes a paste before the page; true when it did.
|
||||
pub(crate) paste: Option<std::rc::Rc<dyn Fn(&mut Window, &mut App) -> bool>>,
|
||||
pub(crate) paste: Option<Paste>,
|
||||
}
|
||||
|
||||
/// Takes a paste before the page; true when it did.
|
||||
pub(crate) type Paste = std::rc::Rc<dyn Fn(&mut Window, &mut App) -> bool>;
|
||||
|
||||
impl EventEmitter<Event> for WebView {}
|
||||
|
||||
impl Focusable for WebView {
|
||||
|
||||
Reference in new issue
Block a user