From 1a9b0536a284fc6576f2a32f9313d5172f0e3ecb Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Sun, 5 May 2024 15:02:50 +0200 Subject: [PATCH] Rust 1.78 (#11314) Notable things I've had to fix due to 1.78: - Better detection of unused items - New clippy lint (`assigning_clones`) that points out places where assignment operations with clone rhs could be replaced with more performant `clone_into` Release Notes: - N/A --- Dockerfile | 2 +- crates/assistant2/src/ui/composer.rs | 2 +- crates/client/src/client.rs | 2 +- crates/client/src/telemetry.rs | 2 +- crates/collab/src/api.rs | 7 -- .../incoming_call_notification.rs | 5 -- crates/editor/src/display_map/fold_map.rs | 23 ----- crates/editor/src/editor.rs | 24 +----- crates/editor/src/selections_collection.rs | 2 +- crates/git/src/blame.rs | 20 +++-- crates/gpui/src/app/async_context.rs | 5 +- crates/gpui/src/app/test_context.rs | 5 +- crates/gpui/src/elements/div.rs | 5 +- crates/gpui/src/platform.rs | 16 ---- .../src/platform/cosmic_text/text_system.rs | 11 --- crates/gpui/src/platform/linux/platform.rs | 22 ----- .../gpui/src/platform/linux/wayland/window.rs | 13 --- crates/gpui/src/platform/linux/x11/window.rs | 13 --- crates/gpui/src/platform/mac/platform.rs | 24 +----- crates/gpui/src/platform/mac/text_system.rs | 85 +------------------ crates/gpui/src/platform/mac/window.rs | 44 ---------- crates/gpui/src/platform/test/platform.rs | 20 +---- crates/gpui/src/platform/test/text_system.rs | 9 -- crates/gpui/src/platform/test/window.rs | 12 --- .../gpui/src/platform/windows/direct_write.rs | 10 --- crates/gpui/src/platform/windows/platform.rs | 20 ----- crates/gpui/src/platform/windows/window.rs | 15 ---- crates/gpui/src/window.rs | 12 ++- crates/language/src/buffer.rs | 2 +- crates/language/src/language.rs | 2 +- crates/language/src/outline.rs | 2 +- crates/live_kit_server/build.rs | 1 + crates/search/src/buffer_search.rs | 4 - crates/search/src/project_search.rs | 9 -- crates/theme/src/settings.rs | 2 +- crates/theme_importer/src/main.rs | 1 - crates/theme_importer/src/util.rs | 11 --- crates/workspace/src/toolbar.rs | 12 --- crates/workspace/src/workspace.rs | 2 +- crates/zed/src/reliability.rs | 2 +- rust-toolchain.toml | 2 +- 41 files changed, 49 insertions(+), 433 deletions(-) delete mode 100644 crates/theme_importer/src/util.rs diff --git a/Dockerfile b/Dockerfile index 0bd1b8dd7f..0614ae589e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ # syntax = docker/dockerfile:1.2 -FROM rust:1.77-bookworm as builder +FROM rust:1.78-bookworm as builder WORKDIR app COPY . . diff --git a/crates/assistant2/src/ui/composer.rs b/crates/assistant2/src/ui/composer.rs index b6515a9548..b08f0f6ec1 100644 --- a/crates/assistant2/src/ui/composer.rs +++ b/crates/assistant2/src/ui/composer.rs @@ -144,7 +144,7 @@ impl RenderOnce for ModelSelector { let assistant_chat = self.assistant_chat.clone(); move |cx| { _ = assistant_chat.update(cx, |assistant_chat, cx| { - assistant_chat.model = model.clone(); + assistant_chat.model.clone_from(&model); cx.notify(); }); } diff --git a/crates/client/src/client.rs b/crates/client/src/client.rs index 7787089568..2144b1ed81 100644 --- a/crates/client/src/client.rs +++ b/crates/client/src/client.rs @@ -100,7 +100,7 @@ impl Settings for ClientSettings { fn load(sources: SettingsSources, _: &mut AppContext) -> Result { let mut result = sources.json_merge::()?; if let Some(server_url) = &*ZED_SERVER_URL { - result.server_url = server_url.clone() + result.server_url.clone_from(&server_url) } Ok(result) } diff --git a/crates/client/src/telemetry.rs b/crates/client/src/telemetry.rs index 96198c44b4..8b29609773 100644 --- a/crates/client/src/telemetry.rs +++ b/crates/client/src/telemetry.rs @@ -217,7 +217,7 @@ impl Telemetry { } let metrics_id: Option> = metrics_id.map(|id| id.into()); - state.metrics_id = metrics_id.clone(); + state.metrics_id.clone_from(&metrics_id); state.is_staff = Some(is_staff); drop(state); } diff --git a/crates/collab/src/api.rs b/crates/collab/src/api.rs index 51cbc58152..f5663db247 100644 --- a/crates/collab/src/api.rs +++ b/crates/collab/src/api.rs @@ -116,13 +116,6 @@ struct CreateUserParams { invite_count: i32, } -#[derive(Serialize, Debug)] -struct CreateUserResponse { - user: User, - signup_device_id: Option, - metrics_id: String, -} - async fn get_rpc_server_snapshot( Extension(rpc_server): Extension>>, ) -> Result { diff --git a/crates/collab_ui/src/notifications/incoming_call_notification.rs b/crates/collab_ui/src/notifications/incoming_call_notification.rs index 7afa85f694..4279841f53 100644 --- a/crates/collab_ui/src/notifications/incoming_call_notification.rs +++ b/crates/collab_ui/src/notifications/incoming_call_notification.rs @@ -55,11 +55,6 @@ pub fn init(app_state: &Arc, cx: &mut AppContext) { .detach(); } -#[derive(Clone, PartialEq)] -struct RespondToCall { - accept: bool, -} - struct IncomingCallNotificationState { call: IncomingCall, app_state: Weak, diff --git a/crates/editor/src/display_map/fold_map.rs b/crates/editor/src/display_map/fold_map.rs index 3bac418602..e773bc8604 100644 --- a/crates/editor/src/display_map/fold_map.rs +++ b/crates/editor/src/display_map/fold_map.rs @@ -6,7 +6,6 @@ use gpui::{ElementId, HighlightStyle, Hsla}; use language::{Chunk, Edit, Point, TextSummary}; use multi_buffer::{Anchor, AnchorRangeExt, MultiBufferSnapshot, ToOffset}; use std::{ - any::TypeId, cmp::{self, Ordering}, iter, ops::{Add, AddAssign, Deref, DerefMut, Range, Sub}, @@ -1066,28 +1065,6 @@ impl<'a> Iterator for FoldChunks<'a> { } } -#[derive(Copy, Clone, Eq, PartialEq)] -struct HighlightEndpoint { - offset: InlayOffset, - is_start: bool, - tag: Option, - style: HighlightStyle, -} - -impl PartialOrd for HighlightEndpoint { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) - } -} - -impl Ord for HighlightEndpoint { - fn cmp(&self, other: &Self) -> Ordering { - self.offset - .cmp(&other.offset) - .then_with(|| other.is_start.cmp(&self.is_start)) - } -} - #[derive(Copy, Clone, Debug, Default, Eq, Ord, PartialOrd, PartialEq)] pub struct FoldOffset(pub usize); diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index d1d8c697fa..e03ef6c08d 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -1167,7 +1167,7 @@ impl CompletionsMenu { for mat in &mut matches { let completion = &completions[mat.candidate_id]; - mat.string = completion.label.text.clone(); + mat.string.clone_from(&completion.label.text); for position in &mut mat.positions { *position += completion.label.filter_range.start; } @@ -10837,34 +10837,12 @@ impl ViewInputHandler for Editor { } trait SelectionExt { - fn offset_range(&self, buffer: &MultiBufferSnapshot) -> Range; - fn point_range(&self, buffer: &MultiBufferSnapshot) -> Range; fn display_range(&self, map: &DisplaySnapshot) -> Range; fn spanned_rows(&self, include_end_if_at_line_start: bool, map: &DisplaySnapshot) -> Range; } impl SelectionExt for Selection { - fn point_range(&self, buffer: &MultiBufferSnapshot) -> Range { - let start = self.start.to_point(buffer); - let end = self.end.to_point(buffer); - if self.reversed { - end..start - } else { - start..end - } - } - - fn offset_range(&self, buffer: &MultiBufferSnapshot) -> Range { - let start = self.start.to_offset(buffer); - let end = self.end.to_offset(buffer); - if self.reversed { - end..start - } else { - start..end - } - } - fn display_range(&self, map: &DisplaySnapshot) -> Range { let start = self .start diff --git a/crates/editor/src/selections_collection.rs b/crates/editor/src/selections_collection.rs index d4d40b8563..137cff4827 100644 --- a/crates/editor/src/selections_collection.rs +++ b/crates/editor/src/selections_collection.rs @@ -69,7 +69,7 @@ impl SelectionsCollection { self.next_selection_id = other.next_selection_id; self.line_mode = other.line_mode; self.disjoint = other.disjoint.clone(); - self.pending = other.pending.clone(); + self.pending.clone_from(&other.pending); } pub fn count(&self) -> usize { diff --git a/crates/git/src/blame.rs b/crates/git/src/blame.rs index 6b9848609d..516918c6ba 100644 --- a/crates/git/src/blame.rs +++ b/crates/git/src/blame.rs @@ -255,15 +255,21 @@ fn parse_git_blame(output: &str) -> Result> { .get(&new_entry.sha) .and_then(|slot| entries.get(*slot)) { - new_entry.author = existing_entry.author.clone(); - new_entry.author_mail = existing_entry.author_mail.clone(); + new_entry.author.clone_from(&existing_entry.author); + new_entry + .author_mail + .clone_from(&existing_entry.author_mail); new_entry.author_time = existing_entry.author_time; - new_entry.author_tz = existing_entry.author_tz.clone(); - new_entry.committer = existing_entry.committer.clone(); - new_entry.committer_mail = existing_entry.committer_mail.clone(); + new_entry.author_tz.clone_from(&existing_entry.author_tz); + new_entry.committer.clone_from(&existing_entry.committer); + new_entry + .committer_mail + .clone_from(&existing_entry.committer_mail); new_entry.committer_time = existing_entry.committer_time; - new_entry.committer_tz = existing_entry.committer_tz.clone(); - new_entry.summary = existing_entry.summary.clone(); + new_entry + .committer_tz + .clone_from(&existing_entry.committer_tz); + new_entry.summary.clone_from(&existing_entry.summary); } current_entry.replace(new_entry); diff --git a/crates/gpui/src/app/async_context.rs b/crates/gpui/src/app/async_context.rs index b251c638f5..a0e463d719 100644 --- a/crates/gpui/src/app/async_context.rs +++ b/crates/gpui/src/app/async_context.rs @@ -25,10 +25,7 @@ impl Context for AsyncAppContext { fn new_model( &mut self, build_model: impl FnOnce(&mut ModelContext<'_, T>) -> T, - ) -> Self::Result> - where - T: 'static, - { + ) -> Self::Result> { let app = self .app .upgrade() diff --git a/crates/gpui/src/app/test_context.rs b/crates/gpui/src/app/test_context.rs index 98512e6d81..0c6fb888e1 100644 --- a/crates/gpui/src/app/test_context.rs +++ b/crates/gpui/src/app/test_context.rs @@ -35,10 +35,7 @@ impl Context for TestAppContext { fn new_model( &mut self, build_model: impl FnOnce(&mut ModelContext<'_, T>) -> T, - ) -> Self::Result> - where - T: 'static, - { + ) -> Self::Result> { let mut app = self.app.borrow_mut(); app.new_model(build_model) } diff --git a/crates/gpui/src/elements/div.rs b/crates/gpui/src/elements/div.rs index 989bab7c67..e77d42bafe 100644 --- a/crates/gpui/src/elements/div.rs +++ b/crates/gpui/src/elements/div.rs @@ -708,10 +708,7 @@ pub trait InteractiveElement: Sized { fn on_drag_move( mut self, listener: impl Fn(&DragMoveEvent, &mut WindowContext) + 'static, - ) -> Self - where - T: 'static, - { + ) -> Self { self.interactivity().on_drag_move(listener); self } diff --git a/crates/gpui/src/platform.rs b/crates/gpui/src/platform.rs index b6415a6e50..6c234c3c34 100644 --- a/crates/gpui/src/platform.rs +++ b/crates/gpui/src/platform.rs @@ -41,7 +41,6 @@ use std::borrow::Cow; use std::hash::{Hash, Hasher}; use std::time::Duration; use std::{ - any::Any, fmt::{self, Debug}, ops::Range, path::{Path, PathBuf}, @@ -107,7 +106,6 @@ pub(crate) trait Platform: 'static { fn displays(&self) -> Vec>; fn primary_display(&self) -> Option>; - fn display(&self, id: DisplayId) -> Option>; fn active_window(&self) -> Option; fn open_window( &self, @@ -129,11 +127,8 @@ pub(crate) trait Platform: 'static { fn prompt_for_new_path(&self, directory: &Path) -> oneshot::Receiver>; fn reveal_path(&self, path: &Path); - fn on_become_active(&self, callback: Box); - fn on_resign_active(&self, callback: Box); fn on_quit(&self, callback: Box); fn on_reopen(&self, callback: Box); - fn on_event(&self, callback: Box bool>); fn set_menus(&self, menus: Vec, keymap: &Keymap); fn add_recent_document(&self, _path: &Path) {} @@ -196,7 +191,6 @@ pub(crate) trait PlatformWindow: HasWindowHandle + HasDisplayHandle { fn display(&self) -> Rc; fn mouse_position(&self) -> Point; fn modifiers(&self) -> Modifiers; - fn as_any_mut(&mut self) -> &mut dyn Any; fn set_input_handler(&mut self, input_handler: PlatformInputHandler); fn take_input_handler(&mut self) -> Option; fn prompt( @@ -221,12 +215,10 @@ pub(crate) trait PlatformWindow: HasWindowHandle + HasDisplayHandle { fn on_input(&self, callback: Box DispatchEventResult>); fn on_active_status_change(&self, callback: Box); fn on_resize(&self, callback: Box, f32)>); - fn on_fullscreen(&self, callback: Box); fn on_moved(&self, callback: Box); fn on_should_close(&self, callback: Box bool>); fn on_close(&self, callback: Box); fn on_appearance_changed(&self, callback: Box); - fn is_topmost_for_position(&self, position: Point) -> bool; fn draw(&self, scene: &Scene); fn completed_frame(&self) {} fn sprite_atlas(&self) -> Arc; @@ -274,13 +266,6 @@ pub(crate) trait PlatformTextSystem: Send + Sync { raster_bounds: Bounds, ) -> Result<(Size, Vec)>; fn layout_line(&self, text: &str, font_size: Pixels, runs: &[FontRun]) -> LineLayout; - fn wrap_line( - &self, - text: &str, - font_id: FontId, - font_size: Pixels, - width: Pixels, - ) -> Vec; } /// Basic metadata about the current application and operating system. @@ -566,7 +551,6 @@ pub struct WindowOptions { /// The variables that can be configured when creating a new window #[derive(Debug)] pub(crate) struct WindowParams { - /// pub bounds: Bounds, /// The titlebar configuration of the window diff --git a/crates/gpui/src/platform/cosmic_text/text_system.rs b/crates/gpui/src/platform/cosmic_text/text_system.rs index a6f131ff7f..c1c5f5aa80 100644 --- a/crates/gpui/src/platform/cosmic_text/text_system.rs +++ b/crates/gpui/src/platform/cosmic_text/text_system.rs @@ -176,17 +176,6 @@ impl PlatformTextSystem for CosmicTextSystem { fn layout_line(&self, text: &str, font_size: Pixels, runs: &[FontRun]) -> LineLayout { self.0.write().layout_line(text, font_size, runs) } - - // todo(linux) Confirm that this has been superseded by the LineWrapper - fn wrap_line( - &self, - _text: &str, - _font_id: FontId, - _font_size: Pixels, - _width: Pixels, - ) -> Vec { - unimplemented!() - } } impl CosmicTextSystemState { diff --git a/crates/gpui/src/platform/linux/platform.rs b/crates/gpui/src/platform/linux/platform.rs index 99d77c76a1..696421714b 100644 --- a/crates/gpui/src/platform/linux/platform.rs +++ b/crates/gpui/src/platform/linux/platform.rs @@ -199,10 +199,6 @@ impl Platform for P { self.displays() } - fn display(&self, id: DisplayId) -> Option> { - self.display(id) - } - // todo(linux) fn active_window(&self) -> Option { None @@ -306,18 +302,6 @@ impl Platform for P { open::that(dir); } - fn on_become_active(&self, callback: Box) { - self.with_common(|common| { - common.callbacks.become_active = Some(callback); - }); - } - - fn on_resign_active(&self, callback: Box) { - self.with_common(|common| { - common.callbacks.resign_active = Some(callback); - }); - } - fn on_quit(&self, callback: Box) { self.with_common(|common| { common.callbacks.quit = Some(callback); @@ -330,12 +314,6 @@ impl Platform for P { }); } - fn on_event(&self, callback: Box bool>) { - self.with_common(|common| { - common.callbacks.event = Some(callback); - }); - } - fn on_app_menu_action(&self, callback: Box) { self.with_common(|common| { common.callbacks.app_menu_action = Some(callback); diff --git a/crates/gpui/src/platform/linux/wayland/window.rs b/crates/gpui/src/platform/linux/wayland/window.rs index da312459a5..05e9e29bdc 100644 --- a/crates/gpui/src/platform/linux/wayland/window.rs +++ b/crates/gpui/src/platform/linux/wayland/window.rs @@ -580,10 +580,6 @@ impl PlatformWindow for WaylandWindow { crate::Modifiers::default() } - fn as_any_mut(&mut self) -> &mut dyn Any { - self - } - fn set_input_handler(&mut self, input_handler: PlatformInputHandler) { self.borrow_mut().input_handler = Some(input_handler); } @@ -668,10 +664,6 @@ impl PlatformWindow for WaylandWindow { self.0.callbacks.borrow_mut().resize = Some(callback); } - fn on_fullscreen(&self, callback: Box) { - self.0.callbacks.borrow_mut().fullscreen = Some(callback); - } - fn on_moved(&self, callback: Box) { self.0.callbacks.borrow_mut().moved = Some(callback); } @@ -688,11 +680,6 @@ impl PlatformWindow for WaylandWindow { // todo(linux) } - // todo(linux) - fn is_topmost_for_position(&self, position: Point) -> bool { - false - } - fn draw(&self, scene: &Scene) { let mut state = self.borrow_mut(); state.renderer.draw(scene); diff --git a/crates/gpui/src/platform/linux/x11/window.rs b/crates/gpui/src/platform/linux/x11/window.rs index 33b8f594d6..b28391a587 100644 --- a/crates/gpui/src/platform/linux/x11/window.rs +++ b/crates/gpui/src/platform/linux/x11/window.rs @@ -460,10 +460,6 @@ impl PlatformWindow for X11Window { Modifiers::default() } - fn as_any_mut(&mut self) -> &mut dyn std::any::Any { - self - } - fn set_input_handler(&mut self, input_handler: PlatformInputHandler) { self.0.state.borrow_mut().input_handler = Some(input_handler); } @@ -587,10 +583,6 @@ impl PlatformWindow for X11Window { self.0.callbacks.borrow_mut().resize = Some(callback); } - fn on_fullscreen(&self, callback: Box) { - self.0.callbacks.borrow_mut().fullscreen = Some(callback); - } - fn on_moved(&self, callback: Box) { self.0.callbacks.borrow_mut().moved = Some(callback); } @@ -607,11 +599,6 @@ impl PlatformWindow for X11Window { self.0.callbacks.borrow_mut().appearance_changed = Some(callback); } - // todo(linux) - fn is_topmost_for_position(&self, _position: Point) -> bool { - unimplemented!() - } - fn draw(&self, scene: &Scene) { let mut inner = self.0.state.borrow_mut(); inner.renderer.draw(scene); diff --git a/crates/gpui/src/platform/mac/platform.rs b/crates/gpui/src/platform/mac/platform.rs index 5772898693..d541d78e81 100644 --- a/crates/gpui/src/platform/mac/platform.rs +++ b/crates/gpui/src/platform/mac/platform.rs @@ -1,9 +1,9 @@ use super::{events::key_to_native, BoolExt}; use crate::{ - Action, AnyWindowHandle, BackgroundExecutor, ClipboardItem, CursorStyle, DisplayId, - ForegroundExecutor, Keymap, MacDispatcher, MacDisplay, MacTextSystem, MacWindow, Menu, - MenuItem, PathPromptOptions, Platform, PlatformDisplay, PlatformInput, PlatformTextSystem, - PlatformWindow, Result, SemanticVersion, Task, WindowAppearance, WindowParams, + Action, AnyWindowHandle, BackgroundExecutor, ClipboardItem, CursorStyle, ForegroundExecutor, + Keymap, MacDispatcher, MacDisplay, MacTextSystem, MacWindow, Menu, MenuItem, PathPromptOptions, + Platform, PlatformDisplay, PlatformInput, PlatformTextSystem, PlatformWindow, Result, + SemanticVersion, Task, WindowAppearance, WindowParams, }; use anyhow::{anyhow, bail}; use block::ConcreteBlock; @@ -487,10 +487,6 @@ impl Platform for MacPlatform { .collect() } - fn display(&self, id: DisplayId) -> Option> { - MacDisplay::find_by_id(id).map(|screen| Rc::new(screen) as Rc<_>) - } - fn active_window(&self) -> Option { MacWindow::active_window() } @@ -679,14 +675,6 @@ impl Platform for MacPlatform { } } - fn on_become_active(&self, callback: Box) { - self.0.lock().become_active = Some(callback); - } - - fn on_resign_active(&self, callback: Box) { - self.0.lock().resign_active = Some(callback); - } - fn on_quit(&self, callback: Box) { self.0.lock().quit = Some(callback); } @@ -695,10 +683,6 @@ impl Platform for MacPlatform { self.0.lock().reopen = Some(callback); } - fn on_event(&self, callback: Box bool>) { - self.0.lock().event = Some(callback); - } - fn on_app_menu_action(&self, callback: Box) { self.0.lock().menu_command = Some(callback); } diff --git a/crates/gpui/src/platform/mac/text_system.rs b/crates/gpui/src/platform/mac/text_system.rs index 6c4a10af00..8806d1bd18 100644 --- a/crates/gpui/src/platform/mac/text_system.rs +++ b/crates/gpui/src/platform/mac/text_system.rs @@ -7,8 +7,7 @@ use anyhow::anyhow; use cocoa::appkit::{CGFloat, CGPoint}; use collections::{BTreeSet, HashMap}; use core_foundation::{ - array::CFIndex, - attributed_string::{CFAttributedStringRef, CFMutableAttributedString}, + attributed_string::CFMutableAttributedString, base::{CFRange, TCFType}, number::CFNumber, string::CFString, @@ -42,7 +41,7 @@ use pathfinder_geometry::{ vector::{Vector2F, Vector2I}, }; use smallvec::SmallVec; -use std::{borrow::Cow, char, cmp, convert::TryFrom, ffi::c_void, sync::Arc}; +use std::{borrow::Cow, char, cmp, convert::TryFrom, sync::Arc}; use super::open_type; @@ -186,16 +185,6 @@ impl PlatformTextSystem for MacTextSystem { fn layout_line(&self, text: &str, font_size: Pixels, font_runs: &[FontRun]) -> LineLayout { self.0.write().layout_line(text, font_size, font_runs) } - - fn wrap_line( - &self, - text: &str, - font_id: FontId, - font_size: Pixels, - width: Pixels, - ) -> Vec { - self.0.read().wrap_line(text, font_id, font_size, width) - } } impl MacTextSystemState { @@ -527,43 +516,6 @@ impl MacTextSystemState { len: text.len(), } } - - fn wrap_line( - &self, - text: &str, - font_id: FontId, - font_size: Pixels, - width: Pixels, - ) -> Vec { - let mut string = CFMutableAttributedString::new(); - string.replace_str(&CFString::new(text), CFRange::init(0, 0)); - let cf_range = CFRange::init(0, text.encode_utf16().count() as isize); - let font = &self.fonts[font_id.0]; - unsafe { - string.set_attribute( - cf_range, - kCTFontAttributeName, - &font.native_font().clone_with_font_size(font_size.into()), - ); - - let typesetter = CTTypesetterCreateWithAttributedString(string.as_concrete_TypeRef()); - let mut ix_converter = StringIndexConverter::new(text); - let mut break_indices = Vec::new(); - while ix_converter.utf8_ix < text.len() { - let utf16_len = CTTypesetterSuggestLineBreak( - typesetter, - ix_converter.utf16_ix as isize, - width.into(), - ) as usize; - ix_converter.advance_to_utf16_ix(ix_converter.utf16_ix + utf16_len); - if ix_converter.utf8_ix >= text.len() { - break; - } - break_indices.push(ix_converter.utf8_ix); - } - break_indices - } - } } #[derive(Clone)] @@ -605,22 +557,6 @@ impl<'a> StringIndexConverter<'a> { } } -#[repr(C)] -pub(crate) struct __CFTypesetter(c_void); - -type CTTypesetterRef = *const __CFTypesetter; - -#[link(name = "CoreText", kind = "framework")] -extern "C" { - fn CTTypesetterCreateWithAttributedString(string: CFAttributedStringRef) -> CTTypesetterRef; - - fn CTTypesetterSuggestLineBreak( - typesetter: CTTypesetterRef, - start_index: CFIndex, - width: f64, - ) -> CFIndex; -} - impl From for FontMetrics { fn from(metrics: Metrics) -> Self { FontMetrics { @@ -741,23 +677,6 @@ mod lenient_font_attributes { mod tests { use crate::{font, px, FontRun, GlyphId, MacTextSystem, PlatformTextSystem}; - #[test] - fn test_wrap_line() { - let fonts = MacTextSystem::new(); - let font_id = fonts.font_id(&font("Helvetica")).unwrap(); - - let line = "one two three four five\n"; - let wrap_boundaries = fonts.wrap_line(line, font_id, px(16.), px(64.0)); - assert_eq!(wrap_boundaries, &["one two ".len(), "one two three ".len()]); - - let line = "aaa ααα ✋✋✋ 🎉🎉🎉\n"; - let wrap_boundaries = fonts.wrap_line(line, font_id, px(16.), px(64.0)); - assert_eq!( - wrap_boundaries, - &["aaa ααα ".len(), "aaa ααα ✋✋✋ ".len(),] - ); - } - #[test] fn test_layout_line_bom_char() { let fonts = MacTextSystem::new(); diff --git a/crates/gpui/src/platform/mac/window.rs b/crates/gpui/src/platform/mac/window.rs index 66bb6bd40f..75584196c0 100644 --- a/crates/gpui/src/platform/mac/window.rs +++ b/crates/gpui/src/platform/mac/window.rs @@ -34,7 +34,6 @@ use parking_lot::Mutex; use raw_window_handle as rwh; use smallvec::SmallVec; use std::{ - any::Any, cell::Cell, ffi::{c_void, CStr}, mem, @@ -504,16 +503,6 @@ impl MacWindowState { px((frame.size.height - content_layout_rect.size.height) as f32) } } - - fn to_screen_ns_point(&self, point: Point) -> NSPoint { - unsafe { - let point = NSPoint::new( - point.x.into(), - (self.content_size().height - point.y).into(), - ); - msg_send![self.native_window, convertPointToScreen: point] - } - } } unsafe impl Send for MacWindowState {} @@ -863,10 +852,6 @@ impl PlatformWindow for MacWindow { } } - fn as_any_mut(&mut self) -> &mut dyn Any { - self - } - fn set_input_handler(&mut self, input_handler: PlatformInputHandler) { self.0.as_ref().lock().input_handler = Some(input_handler); } @@ -1102,10 +1087,6 @@ impl PlatformWindow for MacWindow { self.0.as_ref().lock().resize_callback = Some(callback); } - fn on_fullscreen(&self, callback: Box) { - self.0.as_ref().lock().fullscreen_callback = Some(callback); - } - fn on_moved(&self, callback: Box) { self.0.as_ref().lock().moved_callback = Some(callback); } @@ -1122,31 +1103,6 @@ impl PlatformWindow for MacWindow { self.0.lock().appearance_changed_callback = Some(callback); } - fn is_topmost_for_position(&self, position: Point) -> bool { - let self_borrow = self.0.lock(); - let self_handle = self_borrow.handle; - - unsafe { - let app = NSApplication::sharedApplication(nil); - - // Convert back to screen coordinates - let screen_point = self_borrow.to_screen_ns_point(position); - - let window_number: NSInteger = msg_send![class!(NSWindow), windowNumberAtPoint:screen_point belowWindowWithWindowNumber:0]; - let top_most_window: id = msg_send![app, windowWithWindowNumber: window_number]; - - let is_panel: BOOL = msg_send![top_most_window, isKindOfClass: PANEL_CLASS]; - let is_window: BOOL = msg_send![top_most_window, isKindOfClass: WINDOW_CLASS]; - if is_panel == YES || is_window == YES { - let topmost_window = get_window_state(&*top_most_window).lock().handle; - topmost_window == self_handle - } else { - // Someone else's window is on top - false - } - } - } - fn draw(&self, scene: &crate::Scene) { let mut this = self.0.lock(); this.renderer.draw(scene); diff --git a/crates/gpui/src/platform/test/platform.rs b/crates/gpui/src/platform/test/platform.rs index 14618e2584..c243f4fac1 100644 --- a/crates/gpui/src/platform/test/platform.rs +++ b/crates/gpui/src/platform/test/platform.rs @@ -1,7 +1,7 @@ use crate::{ - AnyWindowHandle, BackgroundExecutor, ClipboardItem, CursorStyle, DisplayId, ForegroundExecutor, - Keymap, Platform, PlatformDisplay, PlatformTextSystem, Task, TestDisplay, TestWindow, - WindowAppearance, WindowParams, + AnyWindowHandle, BackgroundExecutor, ClipboardItem, CursorStyle, ForegroundExecutor, Keymap, + Platform, PlatformDisplay, PlatformTextSystem, Task, TestDisplay, TestWindow, WindowAppearance, + WindowParams, }; use anyhow::{anyhow, Result}; use collections::VecDeque; @@ -90,7 +90,7 @@ impl TestPlatform { pub(crate) fn set_active_window(&self, window: Option) { let executor = self.foreground_executor().clone(); let previous_window = self.active_window.borrow_mut().take(); - *self.active_window.borrow_mut() = window.clone(); + self.active_window.borrow_mut().clone_from(&window); executor .spawn(async move { @@ -168,10 +168,6 @@ impl Platform for TestPlatform { Some(self.active_display.clone()) } - fn display(&self, id: DisplayId) -> Option> { - self.displays().iter().find(|d| d.id() == id).cloned() - } - fn active_window(&self) -> Option { self.active_window .borrow() @@ -228,20 +224,12 @@ impl Platform for TestPlatform { unimplemented!() } - fn on_become_active(&self, _callback: Box) {} - - fn on_resign_active(&self, _callback: Box) {} - fn on_quit(&self, _callback: Box) {} fn on_reopen(&self, _callback: Box) { unimplemented!() } - fn on_event(&self, _callback: Box bool>) { - unimplemented!() - } - fn set_menus(&self, _menus: Vec, _keymap: &Keymap) {} fn add_recent_document(&self, _paths: &Path) {} diff --git a/crates/gpui/src/platform/test/text_system.rs b/crates/gpui/src/platform/test/text_system.rs index ca3a9e3a33..bec559a0f7 100644 --- a/crates/gpui/src/platform/test/text_system.rs +++ b/crates/gpui/src/platform/test/text_system.rs @@ -47,13 +47,4 @@ impl PlatformTextSystem for TestTextSystem { fn layout_line(&self, text: &str, font_size: Pixels, runs: &[FontRun]) -> LineLayout { unimplemented!() } - fn wrap_line( - &self, - text: &str, - font_id: FontId, - font_size: Pixels, - width: Pixels, - ) -> Vec { - unimplemented!() - } } diff --git a/crates/gpui/src/platform/test/window.rs b/crates/gpui/src/platform/test/window.rs index 959d72d9fa..bc9349e017 100644 --- a/crates/gpui/src/platform/test/window.rs +++ b/crates/gpui/src/platform/test/window.rs @@ -144,10 +144,6 @@ impl PlatformWindow for TestWindow { crate::Modifiers::default() } - fn as_any_mut(&mut self) -> &mut dyn std::any::Any { - self - } - fn set_input_handler(&mut self, input_handler: PlatformInputHandler) { self.0.lock().input_handler = Some(input_handler); } @@ -235,10 +231,6 @@ impl PlatformWindow for TestWindow { self.0.lock().resize_callback = Some(callback) } - fn on_fullscreen(&self, _callback: Box) { - unimplemented!() - } - fn on_moved(&self, callback: Box) { self.0.lock().moved_callback = Some(callback) } @@ -251,10 +243,6 @@ impl PlatformWindow for TestWindow { fn on_appearance_changed(&self, _callback: Box) {} - fn is_topmost_for_position(&self, _position: crate::Point) -> bool { - unimplemented!() - } - fn draw(&self, _scene: &crate::Scene) {} fn sprite_atlas(&self) -> sync::Arc { diff --git a/crates/gpui/src/platform/windows/direct_write.rs b/crates/gpui/src/platform/windows/direct_write.rs index eded791634..6078d999be 100644 --- a/crates/gpui/src/platform/windows/direct_write.rs +++ b/crates/gpui/src/platform/windows/direct_write.rs @@ -182,16 +182,6 @@ impl PlatformTextSystem for DirectWriteTextSystem { fn layout_line(&self, text: &str, font_size: Pixels, runs: &[FontRun]) -> LineLayout { self.0.write().layout_line(text, font_size, runs) } - - fn wrap_line( - &self, - _text: &str, - _font_id: FontId, - _font_size: Pixels, - _width: Pixels, - ) -> Vec { - unimplemented!() - } } impl DirectWriteState { diff --git a/crates/gpui/src/platform/windows/platform.rs b/crates/gpui/src/platform/windows/platform.rs index 72772e871b..5e363614b9 100644 --- a/crates/gpui/src/platform/windows/platform.rs +++ b/crates/gpui/src/platform/windows/platform.rs @@ -342,14 +342,6 @@ impl Platform for WindowsPlatform { WindowsDisplay::displays() } - fn display(&self, id: crate::DisplayId) -> Option> { - if let Some(display) = WindowsDisplay::new(id) { - Some(Rc::new(display) as Rc) - } else { - None - } - } - fn primary_display(&self) -> Option> { if let Some(display) = WindowsDisplay::primary_monitor() { Some(Rc::new(display) as Rc) @@ -511,14 +503,6 @@ impl Platform for WindowsPlatform { .detach(); } - fn on_become_active(&self, callback: Box) { - self.inner.callbacks.lock().become_active = Some(callback); - } - - fn on_resign_active(&self, callback: Box) { - self.inner.callbacks.lock().resign_active = Some(callback); - } - fn on_quit(&self, callback: Box) { self.inner.callbacks.lock().quit = Some(callback); } @@ -527,10 +511,6 @@ impl Platform for WindowsPlatform { self.inner.callbacks.lock().reopen = Some(callback); } - fn on_event(&self, callback: Box bool>) { - self.inner.callbacks.lock().event = Some(callback); - } - // todo(windows) fn set_menus(&self, menus: Vec, keymap: &Keymap) {} diff --git a/crates/gpui/src/platform/windows/window.rs b/crates/gpui/src/platform/windows/window.rs index cc2aa9591e..ec27c5b254 100644 --- a/crates/gpui/src/platform/windows/window.rs +++ b/crates/gpui/src/platform/windows/window.rs @@ -1,7 +1,6 @@ #![deny(unsafe_op_in_unsafe_fn)] use std::{ - any::Any, cell::{Cell, RefCell}, iter::once, num::NonZeroIsize, @@ -1408,10 +1407,6 @@ impl PlatformWindow for WindowsWindow { Modifiers::none() } - fn as_any_mut(&mut self) -> &mut dyn Any { - self - } - // todo(windows) fn set_input_handler(&mut self, input_handler: PlatformInputHandler) { self.inner.input_handler.set(Some(input_handler)); @@ -1566,11 +1561,6 @@ impl PlatformWindow for WindowsWindow { self.inner.callbacks.borrow_mut().resize = Some(callback); } - // todo(windows) - fn on_fullscreen(&self, callback: Box) { - self.inner.callbacks.borrow_mut().fullscreen = Some(callback); - } - // todo(windows) fn on_moved(&self, callback: Box) { self.inner.callbacks.borrow_mut().moved = Some(callback); @@ -1591,11 +1581,6 @@ impl PlatformWindow for WindowsWindow { self.inner.callbacks.borrow_mut().appearance_changed = Some(callback); } - // todo(windows) - fn is_topmost_for_position(&self, _position: Point) -> bool { - true - } - // todo(windows) fn draw(&self, scene: &Scene) { self.inner.renderer.borrow_mut().draw(scene) diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rs index 4d2c3e15c8..d7e9863cfd 100644 --- a/crates/gpui/src/window.rs +++ b/crates/gpui/src/window.rs @@ -1430,8 +1430,12 @@ impl<'a> WindowContext<'a> { let mut deferred_draws = mem::take(&mut self.window.next_frame.deferred_draws); for deferred_draw_ix in deferred_draw_indices { let deferred_draw = &mut deferred_draws[*deferred_draw_ix]; - self.window.element_id_stack = deferred_draw.element_id_stack.clone(); - self.window.text_style_stack = deferred_draw.text_style_stack.clone(); + self.window + .element_id_stack + .clone_from(&deferred_draw.element_id_stack); + self.window + .text_style_stack + .clone_from(&deferred_draw.text_style_stack); self.window .next_frame .dispatch_tree @@ -1464,7 +1468,9 @@ impl<'a> WindowContext<'a> { let mut deferred_draws = mem::take(&mut self.window.next_frame.deferred_draws); for deferred_draw_ix in deferred_draw_indices { let mut deferred_draw = &mut deferred_draws[*deferred_draw_ix]; - self.window.element_id_stack = deferred_draw.element_id_stack.clone(); + self.window + .element_id_stack + .clone_from(&deferred_draw.element_id_stack); self.window .next_frame .dispatch_tree diff --git a/crates/language/src/buffer.rs b/crates/language/src/buffer.rs index 8428338fc1..5bebc16e4e 100644 --- a/crates/language/src/buffer.rs +++ b/crates/language/src/buffer.rs @@ -2072,7 +2072,7 @@ impl Buffer { /// Override current completion triggers with the user-provided completion triggers. pub fn set_completion_triggers(&mut self, triggers: Vec, cx: &mut ModelContext) { - self.completion_triggers = triggers.clone(); + self.completion_triggers.clone_from(&triggers); self.completion_triggers_timestamp = self.text.lamport_clock.tick(); self.send_operation( Operation::UpdateCompletionTriggers { diff --git a/crates/language/src/language.rs b/crates/language/src/language.rs index 6132105078..dc92f0a2d3 100644 --- a/crates/language/src/language.rs +++ b/crates/language/src/language.rs @@ -1126,7 +1126,7 @@ impl Language { for setting in query.property_settings(ix) { match setting.key.as_ref() { "language" => { - config.language = setting.value.clone(); + config.language.clone_from(&setting.value); } "combined" => { config.combined = true; diff --git a/crates/language/src/outline.rs b/crates/language/src/outline.rs index 685fd297fc..bf807bfc75 100644 --- a/crates/language/src/outline.rs +++ b/crates/language/src/outline.rs @@ -82,7 +82,7 @@ impl Outline { let mut prev_item_ix = 0; for mut string_match in matches { let outline_match = &self.items[string_match.candidate_id]; - string_match.string = outline_match.text.clone(); + string_match.string.clone_from(&outline_match.text); if is_path_query { let prefix_len = self.path_candidate_prefixes[string_match.candidate_id]; diff --git a/crates/live_kit_server/build.rs b/crates/live_kit_server/build.rs index fa1bde69d6..b12b36ffe0 100644 --- a/crates/live_kit_server/build.rs +++ b/crates/live_kit_server/build.rs @@ -1,5 +1,6 @@ fn main() { prost_build::Config::new() + .type_attribute("SendDataResponse", "#[allow(clippy::empty_docs)]") .compile_protos(&["protocol/livekit_room.proto"], &["protocol"]) .unwrap(); } diff --git a/crates/search/src/buffer_search.rs b/crates/search/src/buffer_search.rs index 3e0b8fb748..7eb7296fa1 100644 --- a/crates/search/src/buffer_search.rs +++ b/crates/search/src/buffer_search.rs @@ -426,10 +426,6 @@ impl ToolbarItemView for BufferSearchBar { } ToolbarItemLocation::Hidden } - - fn row_count(&self, _: &WindowContext<'_>) -> usize { - 1 - } } impl BufferSearchBar { diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rs index f7f659f78a..dd814f9973 100644 --- a/crates/search/src/project_search.rs +++ b/crates/search/src/project_search.rs @@ -1629,15 +1629,6 @@ impl ToolbarItemView for ProjectSearchBar { ToolbarItemLocation::Hidden } } - - fn row_count(&self, cx: &WindowContext<'_>) -> usize { - if let Some(search) = self.active_project_search.as_ref() { - if search.read(cx).filters_enabled { - return 2; - } - } - 1 - } } fn register_workspace_action( diff --git a/crates/theme/src/settings.rs b/crates/theme/src/settings.rs index 5d7d486187..2492e45aa7 100644 --- a/crates/theme/src/settings.rs +++ b/crates/theme/src/settings.rs @@ -441,7 +441,7 @@ impl settings::Settings for ThemeSettings { } } - this.theme_overrides = value.theme_overrides.clone(); + this.theme_overrides.clone_from(&value.theme_overrides); this.apply_theme_overrides(); merge(&mut this.ui_font_size, value.ui_font_size.map(Into::into)); diff --git a/crates/theme_importer/src/main.rs b/crates/theme_importer/src/main.rs index 765dd38ea9..661ac079ae 100644 --- a/crates/theme_importer/src/main.rs +++ b/crates/theme_importer/src/main.rs @@ -1,6 +1,5 @@ mod assets; mod color; -mod util; mod vscode; use std::fs::File; diff --git a/crates/theme_importer/src/util.rs b/crates/theme_importer/src/util.rs deleted file mode 100644 index a78d57ecde..0000000000 --- a/crates/theme_importer/src/util.rs +++ /dev/null @@ -1,11 +0,0 @@ -use anyhow::Result; - -pub trait Traverse { - fn traverse(self, f: impl FnOnce(T) -> Result) -> Result>; -} - -impl Traverse for Option { - fn traverse(self, f: impl FnOnce(T) -> Result) -> Result> { - self.map_or(Ok(None), |value| f(value).map(Some)) - } -} diff --git a/crates/workspace/src/toolbar.rs b/crates/workspace/src/toolbar.rs index 0e2628aab4..fe5beba5e1 100644 --- a/crates/workspace/src/toolbar.rs +++ b/crates/workspace/src/toolbar.rs @@ -18,13 +18,6 @@ pub trait ToolbarItemView: Render + EventEmitter { ) -> ToolbarItemLocation; fn pane_focus_update(&mut self, _pane_focused: bool, _cx: &mut ViewContext) {} - - /// Number of times toolbar's height will be repeated to get the effective height. - /// Useful when multiple rows one under each other are needed. - /// The rows have the same width and act as a whole when reacting to resizes and similar events. - fn row_count(&self, _cx: &WindowContext) -> usize { - 1 - } } trait ToolbarItemViewHandle: Send { @@ -36,7 +29,6 @@ trait ToolbarItemViewHandle: Send { cx: &mut WindowContext, ) -> ToolbarItemLocation; fn focus_changed(&mut self, pane_focused: bool, cx: &mut WindowContext); - fn row_count(&self, cx: &WindowContext) -> usize; } #[derive(Copy, Clone, Debug, PartialEq)] @@ -239,8 +231,4 @@ impl ToolbarItemViewHandle for View { cx.notify(); }); } - - fn row_count(&self, cx: &WindowContext) -> usize { - self.read(cx).row_count(cx) - } } diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index dc08370447..aab9a860c9 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -3322,7 +3322,7 @@ impl Workspace { } if &update.id != &self.last_active_view_id { - self.last_active_view_id = update.id.clone(); + self.last_active_view_id.clone_from(&update.id); self.update_followers( is_project_item, proto::update_followers::Variant::UpdateActiveView(update), diff --git a/crates/zed/src/reliability.rs b/crates/zed/src/reliability.rs index b277235e6b..29c78d916d 100644 --- a/crates/zed/src/reliability.rs +++ b/crates/zed/src/reliability.rs @@ -524,7 +524,7 @@ async fn upload_previous_crashes( } if uploaded < filename { - uploaded = filename.clone(); + uploaded.clone_from(&filename); KEY_VALUE_STORE .write_kvp(LAST_CRASH_UPLOADED.to_string(), filename) .await?; diff --git a/rust-toolchain.toml b/rust-toolchain.toml index df6ae34590..f618116c84 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,5 +1,5 @@ [toolchain] -channel = "1.77" +channel = "1.78" profile = "minimal" components = [ "rustfmt", "clippy" ] targets = [ "x86_64-apple-darwin", "aarch64-apple-darwin", "x86_64-unknown-linux-gnu", "wasm32-wasi" ]