From 748678b0cf769963d49230c574385567f1a45b8d Mon Sep 17 00:00:00 2001 From: Nia Espera Date: Sat, 18 Oct 2025 04:59:41 +0200 Subject: [PATCH] Constify everything --- crates/acp_thread/src/acp_thread.rs | 22 +-- crates/acp_thread/src/connection.rs | 2 +- crates/acp_thread/src/diff.rs | 2 +- crates/acp_thread/src/mention.rs | 2 +- crates/acp_thread/src/terminal.rs | 12 +- crates/acp_tools/src/acp_tools.rs | 2 +- crates/action_log/src/action_log.rs | 2 +- crates/agent/src/agent.rs | 2 +- crates/agent/src/edit_agent.rs | 4 +- .../src/edit_agent/create_file_parser.rs | 2 +- .../src/edit_agent/streaming_fuzzy_matcher.rs | 4 +- crates/agent/src/history_store.rs | 4 +- crates/agent/src/thread.rs | 20 +-- .../src/tools/context_server_registry.rs | 2 +- crates/agent/src/tools/copy_path_tool.rs | 2 +- .../agent/src/tools/create_directory_tool.rs | 2 +- crates/agent/src/tools/delete_path_tool.rs | 2 +- crates/agent/src/tools/diagnostics_tool.rs | 2 +- crates/agent/src/tools/edit_file_tool.rs | 2 +- crates/agent/src/tools/fetch_tool.rs | 2 +- crates/agent/src/tools/find_path_tool.rs | 2 +- crates/agent/src/tools/grep_tool.rs | 4 +- crates/agent/src/tools/list_directory_tool.rs | 2 +- crates/agent/src/tools/move_path_tool.rs | 2 +- crates/agent/src/tools/open_tool.rs | 2 +- crates/agent/src/tools/read_file_tool.rs | 2 +- crates/agent_servers/src/acp.rs | 4 +- crates/agent_servers/src/agent_servers.rs | 4 +- crates/agent_servers/src/custom.rs | 2 +- crates/agent_settings/src/agent_profile.rs | 4 +- crates/agent_settings/src/agent_settings.rs | 2 +- .../agent_ui/src/acp/completion_provider.rs | 2 +- crates/agent_ui/src/acp/entry_view_state.rs | 6 +- crates/agent_ui/src/acp/message_editor.rs | 2 +- crates/agent_ui/src/acp/model_selector.rs | 2 +- crates/agent_ui/src/acp/thread_history.rs | 4 +- crates/agent_ui/src/acp/thread_view.rs | 6 +- .../add_llm_provider_modal.rs | 4 +- .../configure_context_server_modal.rs | 4 +- crates/agent_ui/src/agent_panel.rs | 16 +- crates/agent_ui/src/agent_ui.rs | 2 +- crates/agent_ui/src/buffer_codegen.rs | 4 +- crates/agent_ui/src/context.rs | 14 +- crates/agent_ui/src/context_picker.rs | 20 +-- .../src/context_picker/completion_provider.rs | 2 +- .../context_picker/fetch_context_picker.rs | 2 +- .../src/context_picker/file_context_picker.rs | 2 +- .../context_picker/rules_context_picker.rs | 2 +- .../context_picker/symbol_context_picker.rs | 2 +- .../context_picker/thread_context_picker.rs | 2 +- crates/agent_ui/src/context_store.rs | 6 +- crates/agent_ui/src/inline_assistant.rs | 4 +- crates/agent_ui/src/inline_prompt_editor.rs | 12 +- crates/agent_ui/src/slash_command_picker.rs | 2 +- crates/agent_ui/src/terminal_codegen.rs | 4 +- crates/agent_ui/src/text_thread_editor.rs | 4 +- crates/agent_ui/src/ui/burn_mode_tooltip.rs | 4 +- .../src/ui/unavailable_editing_tooltip.rs | 2 +- crates/agent_ui/src/ui/usage_callout.rs | 2 +- .../src/agent_api_keys_onboarding.rs | 2 +- crates/ai_onboarding/src/ai_upsell_card.rs | 2 +- crates/anthropic/src/anthropic.rs | 4 +- .../src/assistant_context.rs | 34 ++--- .../src/assistant_slash_command.rs | 2 +- .../src/context_server_command.rs | 4 +- crates/audio/src/audio.rs | 2 +- crates/auto_update/src/auto_update.rs | 4 +- crates/bedrock/src/models.rs | 8 +- crates/buffer_diff/src/buffer_diff.rs | 22 +-- crates/call/src/call_impl/mod.rs | 4 +- crates/call/src/call_impl/participant.rs | 4 +- crates/call/src/call_impl/room.rs | 18 +-- crates/channel/src/channel_buffer.rs | 8 +- crates/channel/src/channel_store.rs | 6 +- .../src/channel_store/channel_index.rs | 4 +- crates/client/src/client.rs | 12 +- crates/client/src/user.rs | 10 +- crates/clock/src/clock.rs | 6 +- .../cloud_api_client/src/cloud_api_client.rs | 2 +- crates/cloud_api_types/src/timestamp.rs | 2 +- .../cloud_llm_client/src/cloud_llm_client.rs | 2 +- .../src/cloud_zeta2_prompt.rs | 2 +- crates/collab/src/db.rs | 8 +- crates/collab/src/db/ids.rs | 18 +-- crates/collab/src/db/queries/extensions.rs | 2 +- crates/collab/src/db/tables/channel.rs | 2 +- .../db/tables/channel_buffer_collaborator.rs | 2 +- .../src/db/tables/channel_chat_participant.rs | 2 +- crates/collab/src/db/tables/follower.rs | 4 +- .../src/db/tables/project_collaborator.rs | 2 +- crates/collab/src/lib.rs | 4 +- crates/collab/src/llm/db.rs | 2 +- crates/collab/src/rpc.rs | 6 +- crates/collab_ui/src/collab_panel.rs | 2 +- .../incoming_call_notification.rs | 2 +- .../project_shared_notification.rs | 2 +- crates/component/src/component.rs | 2 +- crates/component/src/component_layout.rs | 12 +- crates/context_server/src/protocol.rs | 4 +- crates/context_server/src/types.rs | 2 +- crates/copilot/src/copilot.rs | 6 +- crates/copilot/src/copilot_chat.rs | 20 +-- .../src/copilot_completion_provider.rs | 2 +- crates/dap/src/client.rs | 8 +- crates/dap/src/debugger_settings.rs | 2 +- crates/debugger_tools/src/dap_log.rs | 4 +- crates/debugger_ui/src/debugger_panel.rs | 2 +- crates/debugger_ui/src/new_process_modal.rs | 2 +- crates/debugger_ui/src/persistence.rs | 4 +- crates/debugger_ui/src/session.rs | 2 +- crates/debugger_ui/src/session/running.rs | 14 +- .../src/session/running/breakpoint_list.rs | 10 +- .../src/session/running/memory_view.rs | 12 +- .../src/session/running/stack_frame_list.rs | 2 +- .../src/session/running/variable_list.rs | 14 +- crates/deepseek/src/deepseek.rs | 6 +- crates/denoise/src/lib.rs | 4 +- crates/diagnostics/src/buffer_diagnostics.rs | 2 +- crates/edit_prediction/src/edit_prediction.rs | 6 +- .../src/edit_prediction_button.rs | 4 +- .../src/declaration.rs | 12 +- crates/edit_prediction_context/src/imports.rs | 4 +- .../src/syntax_index.rs | 2 +- crates/editor/src/blink_manager.rs | 6 +- crates/editor/src/code_context_menus.rs | 12 +- crates/editor/src/display_map.rs | 20 +-- crates/editor/src/display_map/block_map.rs | 20 +-- crates/editor/src/display_map/crease_map.rs | 4 +- crates/editor/src/display_map/fold_map.rs | 12 +- crates/editor/src/display_map/inlay_map.rs | 6 +- crates/editor/src/display_map/tab_map.rs | 14 +- crates/editor/src/display_map/wrap_map.rs | 14 +- crates/editor/src/editor.rs | 140 +++++++++--------- crates/editor/src/editor_settings.rs | 2 +- crates/editor/src/element.rs | 8 +- crates/editor/src/git/blame.rs | 2 +- crates/editor/src/hover_links.rs | 2 +- crates/editor/src/hover_popover.rs | 2 +- crates/editor/src/indent_guides.rs | 2 +- crates/editor/src/inlay_hint_cache.rs | 6 +- crates/editor/src/items.rs | 6 +- crates/editor/src/proposed_changes_editor.rs | 4 +- crates/editor/src/scroll.rs | 28 ++-- crates/editor/src/scroll/autoscroll.rs | 20 +-- crates/editor/src/scroll/scroll_amount.rs | 4 +- crates/editor/src/selections_collection.rs | 18 +-- crates/editor/src/signature_help.rs | 4 +- crates/extension/src/extension_events.rs | 2 +- crates/extension_api/src/http_client.rs | 8 +- .../extension_host/src/capability_granter.rs | 2 +- crates/extension_host/src/extension_host.rs | 6 +- crates/extension_host/src/wasm_host/wit.rs | 4 +- .../src/components/extension_card.rs | 2 +- crates/extensions_ui/src/extensions_ui.rs | 4 +- crates/file_finder/src/file_finder.rs | 8 +- crates/file_finder/src/open_path_prompt.rs | 4 +- crates/fs/src/fs.rs | 4 +- crates/fs/src/mac_watcher.rs | 2 +- crates/fuzzy/src/char_bag.rs | 4 +- crates/git/src/repository.rs | 6 +- crates/git/src/status.rs | 34 ++--- crates/git_ui/src/commit_tooltip.rs | 4 +- crates/git_ui/src/git_panel.rs | 36 ++--- crates/git_ui/src/git_ui.rs | 4 +- crates/git_ui/src/picker_prompt.rs | 2 +- crates/git_ui/src/remote_output.rs | 2 +- crates/google_ai/src/google_ai.rs | 14 +- crates/gpui/src/action.rs | 8 +- crates/gpui/src/app.rs | 16 +- crates/gpui/src/app/async_context.rs | 8 +- crates/gpui/src/app/context.rs | 2 +- crates/gpui/src/app/entity_map.rs | 8 +- crates/gpui/src/arena.rs | 4 +- crates/gpui/src/bounds_tree.rs | 4 +- crates/gpui/src/color.rs | 10 +- crates/gpui/src/element.rs | 4 +- crates/gpui/src/elements/anchored.rs | 10 +- crates/gpui/src/elements/animation.rs | 4 +- crates/gpui/src/elements/deferred.rs | 4 +- crates/gpui/src/elements/div.rs | 10 +- crates/gpui/src/elements/img.rs | 2 +- crates/gpui/src/elements/list.rs | 6 +- crates/gpui/src/elements/surface.rs | 2 +- crates/gpui/src/elements/svg.rs | 10 +- crates/gpui/src/elements/text.rs | 2 +- crates/gpui/src/elements/uniform_list.rs | 2 +- crates/gpui/src/executor.rs | 2 +- crates/gpui/src/geometry.rs | 44 +++--- crates/gpui/src/input.rs | 2 +- crates/gpui/src/inspector.rs | 6 +- crates/gpui/src/interactive.rs | 10 +- crates/gpui/src/key_dispatch.rs | 4 +- crates/gpui/src/keymap.rs | 2 +- crates/gpui/src/keymap/binding.rs | 6 +- crates/gpui/src/keymap/context.rs | 4 +- crates/gpui/src/path_builder.rs | 2 +- crates/gpui/src/platform.rs | 24 +-- crates/gpui/src/platform/app_menu.rs | 4 +- crates/gpui/src/platform/keystroke.rs | 14 +- crates/gpui/src/platform/mac.rs | 6 +- crates/gpui/src/platform/mac/metal_atlas.rs | 4 +- .../gpui/src/platform/mac/metal_renderer.rs | 10 +- crates/gpui/src/platform/mac/platform.rs | 4 +- .../gpui/src/platform/mac/screen_capture.rs | 6 +- crates/gpui/src/platform/mac/text_system.rs | 2 +- crates/gpui/src/platform/mac/window.rs | 2 +- crates/gpui/src/scene.rs | 10 +- crates/gpui/src/style.rs | 2 +- crates/gpui/src/tab_stop.rs | 4 +- crates/gpui/src/text_system.rs | 4 +- crates/gpui/src/text_system/line_wrapper.rs | 10 +- crates/gpui/src/view.rs | 4 +- crates/gpui/src/window.rs | 30 ++-- crates/gpui/src/window/prompts.rs | 2 +- crates/html_to_markdown/src/html_element.rs | 2 +- crates/html_to_markdown/src/markdown.rs | 2 +- .../html_to_markdown/src/markdown_writer.rs | 4 +- .../src/structure/wikipedia.rs | 2 +- crates/http_client/src/async_body.rs | 4 +- crates/http_client/src/http_client.rs | 2 +- crates/image_viewer/src/image_info.rs | 2 +- crates/keymap_editor/src/keymap_editor.rs | 24 +-- .../src/ui_components/keystroke_input.rs | 2 +- crates/language/src/buffer.rs | 42 +++--- crates/language/src/language.rs | 24 +-- crates/language/src/language_registry.rs | 4 +- crates/language/src/language_settings.rs | 2 +- crates/language/src/proto.rs | 16 +- crates/language/src/syntax_map.rs | 8 +- crates/language/src/toolchain.rs | 4 +- crates/language_model/src/language_model.rs | 2 +- crates/language_model/src/request.rs | 2 +- crates/language_model/src/role.rs | 4 +- crates/language_models/src/api_key.rs | 6 +- .../language_models/src/provider/anthropic.rs | 4 +- .../language_models/src/provider/deepseek.rs | 2 +- crates/language_models/src/provider/google.rs | 4 +- .../language_models/src/provider/lmstudio.rs | 2 +- .../language_models/src/provider/mistral.rs | 2 +- crates/language_models/src/provider/ollama.rs | 2 +- .../language_models/src/provider/open_ai.rs | 2 +- .../src/provider/open_ai_compatible.rs | 2 +- .../src/provider/open_router.rs | 2 +- crates/language_models/src/provider/vercel.rs | 2 +- crates/language_models/src/provider/x_ai.rs | 2 +- crates/language_onboarding/src/python.rs | 2 +- crates/language_tools/src/lsp_log_view.rs | 4 +- crates/language_tools/src/syntax_tree_view.rs | 2 +- crates/languages/src/css.rs | 2 +- crates/languages/src/json.rs | 2 +- crates/languages/src/python.rs | 10 +- crates/languages/src/tailwind.rs | 2 +- crates/languages/src/typescript.rs | 2 +- crates/languages/src/yaml.rs | 2 +- crates/lmstudio/src/lmstudio.rs | 6 +- crates/lsp/src/lsp.rs | 10 +- crates/markdown/src/markdown.rs | 10 +- .../markdown_preview/src/markdown_elements.rs | 10 +- .../markdown_preview/src/markdown_minifier.rs | 2 +- .../markdown_preview/src/markdown_parser.rs | 8 +- .../markdown_preview/src/markdown_renderer.rs | 2 +- crates/menu/src/menu.rs | 2 +- crates/mistral/src/mistral.rs | 8 +- crates/multi_buffer/src/anchor.rs | 12 +- crates/multi_buffer/src/multi_buffer.rs | 56 +++---- crates/multi_buffer/src/position.rs | 22 +-- crates/notifications/src/status_toast.rs | 6 +- crates/ollama/src/ollama.rs | 2 +- crates/onboarding/src/theme_preview.rs | 2 +- crates/open_ai/src/open_ai.rs | 12 +- crates/open_router/src/open_router.rs | 10 +- crates/outline_panel/src/outline_panel.rs | 12 +- crates/paths/src/paths.rs | 8 +- crates/picker/src/picker.rs | 8 +- crates/picker/src/popover_menu.rs | 2 +- crates/prettier/src/prettier.rs | 4 +- crates/project/src/buffer_store.rs | 6 +- crates/project/src/context_server_store.rs | 2 +- crates/project/src/debounced_delay.rs | 2 +- .../project/src/debugger/breakpoint_store.rs | 16 +- crates/project/src/debugger/dap_store.rs | 8 +- crates/project/src/debugger/memory.rs | 2 +- crates/project/src/debugger/session.rs | 38 ++--- crates/project/src/git_store.rs | 12 +- crates/project/src/git_store/git_traversal.rs | 4 +- crates/project/src/lsp_store.rs | 14 +- crates/project/src/lsp_store/log_store.rs | 4 +- .../project/src/lsp_store/lsp_ext_command.rs | 4 +- crates/project/src/manifest_tree.rs | 2 +- .../project/src/manifest_tree/server_tree.rs | 2 +- crates/project/src/prettier_store.rs | 2 +- crates/project/src/project.rs | 54 +++---- crates/project/src/project_settings.rs | 16 +- crates/project/src/search.rs | 28 ++-- crates/project/src/search_history.rs | 4 +- crates/project/src/task_inventory.rs | 6 +- crates/project/src/task_store.rs | 2 +- crates/project/src/terminals.rs | 2 +- crates/project/src/toolchain_store.rs | 2 +- crates/project/src/worktree_store.rs | 4 +- crates/project_panel/src/project_panel.rs | 14 +- crates/project_panel/src/utils.rs | 2 +- crates/prompt_store/src/prompt_store.rs | 2 +- crates/proto/src/proto.rs | 2 +- crates/proto/src/typed_envelope.rs | 6 +- crates/recent_projects/src/remote_servers.rs | 4 +- crates/release_channel/src/lib.rs | 12 +- crates/remote/src/json_log.rs | 4 +- crates/remote/src/proxy.rs | 4 +- crates/remote/src/remote_client.rs | 12 +- crates/remote_server/src/headless_project.rs | 2 +- .../repl/src/components/kernel_list_item.rs | 4 +- crates/repl/src/kernels/mod.rs | 4 +- crates/repl/src/notebook/cell.rs | 6 +- crates/repl/src/notebook/notebook_ui.rs | 2 +- crates/repl/src/outputs.rs | 2 +- crates/repl/src/repl_store.rs | 2 +- crates/rope/src/chunk.rs | 32 ++-- crates/rope/src/point.rs | 8 +- crates/rope/src/point_utf16.rs | 6 +- crates/rope/src/rope.rs | 14 +- crates/rpc/src/message_stream.rs | 2 +- crates/rpc/src/notification.rs | 2 +- crates/scheduler/src/executor.rs | 2 +- crates/scheduler/src/scheduler.rs | 4 +- crates/search/src/buffer_search.rs | 14 +- crates/search/src/project_search.rs | 12 +- crates/search/src/search.rs | 6 +- crates/search/src/search_status_button.rs | 2 +- .../semantic_version/src/semantic_version.rs | 6 +- crates/settings/src/base_keymap_setting.rs | 2 +- crates/settings/src/keymap_file.rs | 8 +- crates/settings/src/settings.rs | 8 +- crates/settings/src/settings_content.rs | 2 +- crates/settings/src/settings_content/agent.rs | 10 +- .../settings/src/settings_content/language.rs | 4 +- .../src/settings_content/language_model.rs | 4 +- .../settings/src/settings_content/project.rs | 2 +- crates/settings/src/settings_content/theme.rs | 4 +- .../src/settings_content/workspace.rs | 6 +- crates/settings/src/settings_store.rs | 2 +- crates/settings_ui/src/components.rs | 4 +- crates/settings_ui/src/settings_ui.rs | 10 +- crates/sqlez/src/connection.rs | 2 +- crates/sqlez/src/thread_safe_connection.rs | 4 +- crates/sqlez/src/util.rs | 2 +- crates/storybook/src/storybook.rs | 2 +- crates/streaming_diff/src/streaming_diff.rs | 4 +- crates/sum_tree/src/cursor.rs | 8 +- crates/sum_tree/src/sum_tree.rs | 10 +- crates/supermaven/src/supermaven.rs | 2 +- .../src/supermaven_completion_provider.rs | 2 +- crates/system_specs/src/system_specs.rs | 2 +- crates/task/src/shell_builder.rs | 4 +- crates/task/src/static_source.rs | 2 +- crates/task/src/task.rs | 8 +- crates/terminal/src/mappings/keys.rs | 6 +- crates/terminal/src/mappings/mouse.rs | 8 +- crates/terminal/src/pty_info.rs | 4 +- crates/terminal/src/terminal.rs | 28 ++-- crates/terminal_view/src/terminal_element.rs | 12 +- crates/terminal_view/src/terminal_panel.rs | 2 +- .../src/terminal_path_like_target.rs | 6 +- crates/terminal_view/src/terminal_view.rs | 10 +- crates/text/src/operation_queue.rs | 2 +- crates/text/src/patch.rs | 2 +- crates/text/src/selection.rs | 6 +- crates/text/src/text.rs | 46 +++--- crates/theme/src/scale.rs | 10 +- crates/theme/src/schema.rs | 2 +- crates/theme/src/settings.rs | 22 +-- crates/theme/src/styles/colors.rs | 2 +- crates/theme/src/styles/status.rs | 2 +- crates/theme/src/theme.rs | 18 +-- crates/theme_importer/src/vscode/converter.rs | 2 +- crates/theme_importer/src/vscode/syntax.rs | 2 +- .../title_bar/src/platforms/platform_linux.rs | 2 +- .../src/platforms/platform_windows.rs | 4 +- crates/ui/src/components/avatar.rs | 2 +- crates/ui/src/components/badge.rs | 2 +- crates/ui/src/components/banner.rs | 4 +- crates/ui/src/components/button/button.rs | 6 +- .../ui/src/components/button/button_icon.rs | 2 +- .../ui/src/components/button/button_like.rs | 2 +- .../ui/src/components/button/icon_button.rs | 10 +- .../ui/src/components/button/split_button.rs | 4 +- .../ui/src/components/button/toggle_button.rs | 22 +-- crates/ui/src/components/callout.rs | 10 +- crates/ui/src/components/chip.rs | 6 +- crates/ui/src/components/content_group.rs | 4 +- crates/ui/src/components/context_menu.rs | 20 +-- crates/ui/src/components/data_table.rs | 10 +- crates/ui/src/components/disclosure.rs | 6 +- crates/ui/src/components/divider.rs | 4 +- crates/ui/src/components/dropdown_menu.rs | 16 +- crates/ui/src/components/icon.rs | 10 +- .../ui/src/components/icon/decorated_icon.rs | 2 +- .../ui/src/components/icon/icon_decoration.rs | 14 +- crates/ui/src/components/image.rs | 2 +- crates/ui/src/components/indicator.rs | 8 +- crates/ui/src/components/keybinding.rs | 8 +- crates/ui/src/components/keybinding_hint.rs | 2 +- .../ui/src/components/label/spinner_label.rs | 4 +- crates/ui/src/components/list/list_header.rs | 2 +- crates/ui/src/components/list/list_item.rs | 20 +-- .../ui/src/components/list/list_sub_header.rs | 4 +- crates/ui/src/components/modal.rs | 14 +- crates/ui/src/components/navigable.rs | 2 +- crates/ui/src/components/popover_menu.rs | 8 +- .../src/components/progress/progress_bar.rs | 10 +- crates/ui/src/components/right_click_menu.rs | 4 +- crates/ui/src/components/scrollbar.rs | 30 ++-- crates/ui/src/components/tab.rs | 4 +- crates/ui/src/components/tab_bar.rs | 4 +- crates/ui/src/components/toggle.rs | 30 ++-- crates/ui/src/components/tree_view_item.rs | 10 +- crates/ui/src/styles/animation.rs | 2 +- crates/ui/src/styles/typography.rs | 8 +- crates/ui/src/traits/toggleable.rs | 6 +- crates/ui/src/utils/corner_solver.rs | 2 +- crates/ui/src/utils/format_distance.rs | 10 +- crates/ui_input/src/number_field.rs | 12 +- crates/ui_input/src/ui_input.rs | 6 +- crates/util/src/paths.rs | 10 +- crates/util/src/rel_path.rs | 18 +-- crates/util/src/util.rs | 2 +- crates/vercel/src/vercel.rs | 10 +- crates/vim/src/command.rs | 6 +- crates/vim/src/helix/boundary.rs | 4 +- crates/vim/src/motion.rs | 14 +- crates/vim/src/object.rs | 8 +- crates/vim/src/state.rs | 8 +- crates/vim/src/vim.rs | 2 +- crates/watch/src/watch.rs | 2 +- crates/workspace/src/dock.rs | 12 +- crates/workspace/src/history_manager.rs | 2 +- crates/workspace/src/item.rs | 2 +- crates/workspace/src/modal_layer.rs | 4 +- crates/workspace/src/notifications.rs | 18 +-- crates/workspace/src/pane.rs | 28 ++-- crates/workspace/src/pane_group.rs | 14 +- crates/workspace/src/persistence/model.rs | 4 +- crates/workspace/src/searchable.rs | 2 +- crates/workspace/src/theme_preview.rs | 2 +- crates/workspace/src/toast_layer.rs | 4 +- crates/workspace/src/toolbar.rs | 2 +- crates/workspace/src/workspace.rs | 36 ++--- crates/worktree/src/worktree.rs | 58 ++++---- crates/x_ai/src/x_ai.rs | 14 +- crates/zed/src/zed/component_preview.rs | 2 +- crates/zed_actions/src/lib.rs | 4 +- crates/zeta/src/license_detection.rs | 4 +- crates/zeta/src/rate_completion_modal.rs | 2 +- crates/zeta/src/zeta.rs | 8 +- crates/zeta2/src/prediction.rs | 2 +- crates/zeta2/src/zeta2.rs | 4 +- crates/zlog/src/filter.rs | 2 +- crates/zlog/src/zlog.rs | 2 +- 458 files changed, 1676 insertions(+), 1676 deletions(-) diff --git a/crates/acp_thread/src/acp_thread.rs b/crates/acp_thread/src/acp_thread.rs index f041c9120a52e4b9c23acf121110f00ee157641e..f60691dc580b8d90bc2ae1f231d5bac015f52f96 100644 --- a/crates/acp_thread/src/acp_thread.rs +++ b/crates/acp_thread/src/acp_thread.rs @@ -127,7 +127,7 @@ impl AgentThreadEntry { } } - pub fn user_message(&self) -> Option<&UserMessage> { + pub const fn user_message(&self) -> Option<&UserMessage> { if let AgentThreadEntry::UserMessage(message) = self { Some(message) } else { @@ -536,7 +536,7 @@ impl ContentBlock { } } - pub fn markdown(&self) -> Option<&Entity> { + pub const fn markdown(&self) -> Option<&Entity> { match self { ContentBlock::Empty => None, ContentBlock::Markdown { markdown } => Some(markdown), @@ -544,7 +544,7 @@ impl ContentBlock { } } - pub fn resource_link(&self) -> Option<&acp::ResourceLink> { + pub const fn resource_link(&self) -> Option<&acp::ResourceLink> { match self { ContentBlock::ResourceLink { resource_link } => Some(resource_link), _ => None, @@ -630,7 +630,7 @@ pub enum ToolCallUpdate { } impl ToolCallUpdate { - fn id(&self) -> &acp::ToolCallId { + const fn id(&self) -> &acp::ToolCallId { match self { Self::UpdateFields(update) => &update.id, Self::UpdateDiff(diff) => &diff.id, @@ -682,7 +682,7 @@ pub struct PlanStats<'a> { } impl Plan { - pub fn is_empty(&self) -> bool { + pub const fn is_empty(&self) -> bool { self.entries.is_empty() } @@ -1022,11 +1022,11 @@ impl AcpThread { &self.connection } - pub fn action_log(&self) -> &Entity { + pub const fn action_log(&self) -> &Entity { &self.action_log } - pub fn project(&self) -> &Entity { + pub const fn project(&self) -> &Entity { &self.project } @@ -1038,11 +1038,11 @@ impl AcpThread { &self.entries } - pub fn session_id(&self) -> &acp::SessionId { + pub const fn session_id(&self) -> &acp::SessionId { &self.session_id } - pub fn status(&self) -> ThreadStatus { + pub const fn status(&self) -> ThreadStatus { if self.send_task.is_some() { ThreadStatus::Generating } else { @@ -1050,7 +1050,7 @@ impl AcpThread { } } - pub fn token_usage(&self) -> Option<&TokenUsage> { + pub const fn token_usage(&self) -> Option<&TokenUsage> { self.token_usage.as_ref() } @@ -1533,7 +1533,7 @@ impl AcpThread { first_tool_call } - pub fn plan(&self) -> &Plan { + pub const fn plan(&self) -> &Plan { &self.plan } diff --git a/crates/acp_thread/src/connection.rs b/crates/acp_thread/src/connection.rs index fe66f954370f8118d054ee56f1e9f68f2de7e6f4..4be352bf40e40a287fa5d52a5ebd3f9c4d001e23 100644 --- a/crates/acp_thread/src/connection.rs +++ b/crates/acp_thread/src/connection.rs @@ -133,7 +133,7 @@ pub struct AuthRequired { } impl AuthRequired { - pub fn new() -> Self { + pub const fn new() -> Self { Self { description: None, provider_id: None, diff --git a/crates/acp_thread/src/diff.rs b/crates/acp_thread/src/diff.rs index 15de12af27fe233bad4ad8ebb2893ffa5fbdd598..03c0ebc1429fdd51c559b955c650c437bbf9002d 100644 --- a/crates/acp_thread/src/diff.rs +++ b/crates/acp_thread/src/diff.rs @@ -129,7 +129,7 @@ impl Diff { } } - pub fn multibuffer(&self) -> &Entity { + pub const fn multibuffer(&self) -> &Entity { match self { Self::Pending(PendingDiff { multibuffer, .. }) => multibuffer, Self::Finalized(FinalizedDiff { multibuffer, .. }) => multibuffer, diff --git a/crates/acp_thread/src/mention.rs b/crates/acp_thread/src/mention.rs index bbd13da5fa4124546d5457755f2bd2f5d737ccac..dcddee96f1a832588c2932f48780e08633ea457d 100644 --- a/crates/acp_thread/src/mention.rs +++ b/crates/acp_thread/src/mention.rs @@ -206,7 +206,7 @@ impl MentionUri { } } - pub fn as_link<'a>(&'a self) -> MentionLink<'a> { + pub const fn as_link<'a>(&'a self) -> MentionLink<'a> { MentionLink(self) } diff --git a/crates/acp_thread/src/terminal.rs b/crates/acp_thread/src/terminal.rs index 888c7698c3d2270769f3afbe712ecba7d08b055f..db3c5e4e5dfec4a3062ae8bd2c09e02b0cbf45b6 100644 --- a/crates/acp_thread/src/terminal.rs +++ b/crates/acp_thread/src/terminal.rs @@ -82,7 +82,7 @@ impl Terminal { } } - pub fn id(&self) -> &acp::TerminalId { + pub const fn id(&self) -> &acp::TerminalId { &self.id } @@ -143,23 +143,23 @@ impl Terminal { (content, original_content_len) } - pub fn command(&self) -> &Entity { + pub const fn command(&self) -> &Entity { &self.command } - pub fn working_dir(&self) -> &Option { + pub const fn working_dir(&self) -> &Option { &self.working_dir } - pub fn started_at(&self) -> Instant { + pub const fn started_at(&self) -> Instant { self.started_at } - pub fn output(&self) -> Option<&TerminalOutput> { + pub const fn output(&self) -> Option<&TerminalOutput> { self.output.as_ref() } - pub fn inner(&self) -> &Entity { + pub const fn inner(&self) -> &Entity { &self.terminal } diff --git a/crates/acp_tools/src/acp_tools.rs b/crates/acp_tools/src/acp_tools.rs index 7ba4f555a2a42303f82cfdc1f8e24860ed3e1d69..30f7746db24143f98809300e0c212235c00bb3b0 100644 --- a/crates/acp_tools/src/acp_tools.rs +++ b/crates/acp_tools/src/acp_tools.rs @@ -531,7 +531,7 @@ pub struct AcpToolsToolbarItemView { } impl AcpToolsToolbarItemView { - pub fn new() -> Self { + pub const fn new() -> Self { Self { acp_tools: None, just_copied: false, diff --git a/crates/action_log/src/action_log.rs b/crates/action_log/src/action_log.rs index b7722f211afda3a77bc96292a50acf869e7424d6..7b5cd75ea28c4eb80bde8f6096c67cfa64238778 100644 --- a/crates/action_log/src/action_log.rs +++ b/crates/action_log/src/action_log.rs @@ -27,7 +27,7 @@ impl ActionLog { } } - pub fn project(&self) -> &Entity { + pub const fn project(&self) -> &Entity { &self.project } diff --git a/crates/agent/src/agent.rs b/crates/agent/src/agent.rs index 32dec9f723a6776fd14def29be3be4eb21afa72d..9ec6dffde8792ccf05cf43c2c95b18f2eb933489 100644 --- a/crates/agent/src/agent.rs +++ b/crates/agent/src/agent.rs @@ -375,7 +375,7 @@ impl NativeAgent { acp_thread } - pub fn models(&self) -> &LanguageModels { + pub const fn models(&self) -> &LanguageModels { &self.models } diff --git a/crates/agent/src/edit_agent.rs b/crates/agent/src/edit_agent.rs index 829287f65478d56d793ed506c44a8331580cc4c5..c2ff1f13ac9c7a5be258d3f02e7bae644524c067 100644 --- a/crates/agent/src/edit_agent.rs +++ b/crates/agent/src/edit_agent.rs @@ -747,14 +747,14 @@ enum IndentDelta { } impl IndentDelta { - fn character(&self) -> char { + const fn character(&self) -> char { match self { IndentDelta::Spaces(_) => ' ', IndentDelta::Tabs(_) => '\t', } } - fn len(&self) -> isize { + const fn len(&self) -> isize { match self { IndentDelta::Spaces(n) => *n, IndentDelta::Tabs(n) => *n, diff --git a/crates/agent/src/edit_agent/create_file_parser.rs b/crates/agent/src/edit_agent/create_file_parser.rs index 2272434d796a92e53b741f8ed5f4303d94f88489..812ecc0d154edd1a0a64ce4ee0526f99e0730353 100644 --- a/crates/agent/src/edit_agent/create_file_parser.rs +++ b/crates/agent/src/edit_agent/create_file_parser.rs @@ -27,7 +27,7 @@ enum ParserState { } impl CreateFileParser { - pub fn new() -> Self { + pub const fn new() -> Self { CreateFileParser { state: ParserState::Pending, buffer: String::new(), diff --git a/crates/agent/src/edit_agent/streaming_fuzzy_matcher.rs b/crates/agent/src/edit_agent/streaming_fuzzy_matcher.rs index 386b8204400a157b37b2f356829fa27df3abca92..547f21c9a6aa9c6dcc4785798f0f480a281b8468 100644 --- a/crates/agent/src/edit_agent/streaming_fuzzy_matcher.rs +++ b/crates/agent/src/edit_agent/streaming_fuzzy_matcher.rs @@ -262,7 +262,7 @@ struct SearchState { } impl SearchState { - fn new(cost: u32, direction: SearchDirection) -> Self { + const fn new(cost: u32, direction: SearchDirection) -> Self { Self { cost, direction } } } @@ -274,7 +274,7 @@ struct SearchMatrix { } impl SearchMatrix { - fn new(cols: usize) -> Self { + const fn new(cols: usize) -> Self { SearchMatrix { cols, rows: 0, diff --git a/crates/agent/src/history_store.rs b/crates/agent/src/history_store.rs index c342110f3ee289b6e84241517b69fe9a86efcf16..cb2f6c31a372eabe142dd38ed78914849ef6e94a 100644 --- a/crates/agent/src/history_store.rs +++ b/crates/agent/src/history_store.rs @@ -54,7 +54,7 @@ pub enum HistoryEntry { } impl HistoryEntry { - pub fn updated_at(&self) -> DateTime { + pub const fn updated_at(&self) -> DateTime { match self { HistoryEntry::AcpThread(thread) => thread.updated_at, HistoryEntry::TextThread(context) => context.mtime.to_utc(), @@ -253,7 +253,7 @@ impl HistoryStore { cx.notify() } - pub fn is_empty(&self, _cx: &App) -> bool { + pub const fn is_empty(&self, _cx: &App) -> bool { self.entries.is_empty() } diff --git a/crates/agent/src/thread.rs b/crates/agent/src/thread.rs index ec9d50ff2f62c5602dd91e5da47593764ea01c85..0d9d0b4c2542653ad9fa6d0a96daa84a322cb6ac 100644 --- a/crates/agent/src/thread.rs +++ b/crates/agent/src/thread.rs @@ -102,7 +102,7 @@ pub enum Message { } impl Message { - pub fn as_agent_message(&self) -> Option<&AgentMessage> { + pub const fn as_agent_message(&self) -> Option<&AgentMessage> { match self { Message::Agent(agent_message) => Some(agent_message), _ => None, @@ -129,7 +129,7 @@ impl Message { } } - pub fn role(&self) -> Role { + pub const fn role(&self) -> Role { match self { Message::User(_) | Message::Resume => Role::User, Message::Agent(_) => Role::Assistant, @@ -672,7 +672,7 @@ impl Thread { } } - pub fn id(&self) -> &acp::SessionId { + pub const fn id(&self) -> &acp::SessionId { &self.id } @@ -975,19 +975,19 @@ impl Thread { }) } - pub fn project_context(&self) -> &Entity { + pub const fn project_context(&self) -> &Entity { &self.project_context } - pub fn project(&self) -> &Entity { + pub const fn project(&self) -> &Entity { &self.project } - pub fn action_log(&self) -> &Entity { + pub const fn action_log(&self) -> &Entity { &self.action_log } - pub fn is_empty(&self) -> bool { + pub const fn is_empty(&self) -> bool { self.messages.is_empty() && self.title.is_none() } @@ -1020,7 +1020,7 @@ impl Thread { cx.notify() } - pub fn completion_mode(&self) -> CompletionMode { + pub const fn completion_mode(&self) -> CompletionMode { self.completion_mode } @@ -1086,7 +1086,7 @@ impl Thread { self.tools.remove(name).is_some() } - pub fn profile(&self) -> &AgentProfileId { + pub const fn profile(&self) -> &AgentProfileId { &self.profile_id } @@ -1658,7 +1658,7 @@ impl Thread { self.title.clone().unwrap_or("New Thread".into()) } - pub fn is_generating_summary(&self) -> bool { + pub const fn is_generating_summary(&self) -> bool { self.pending_summary_generation.is_some() } diff --git a/crates/agent/src/tools/context_server_registry.rs b/crates/agent/src/tools/context_server_registry.rs index 382d2ba9be74b4518de853037c858fd054366d5d..1a06397c70e1b74a1aa85ec0e852a5ade5d9211c 100644 --- a/crates/agent/src/tools/context_server_registry.rs +++ b/crates/agent/src/tools/context_server_registry.rs @@ -130,7 +130,7 @@ struct ContextServerTool { } impl ContextServerTool { - fn new( + const fn new( store: Entity, server_id: ContextServerId, tool: context_server::types::Tool, diff --git a/crates/agent/src/tools/copy_path_tool.rs b/crates/agent/src/tools/copy_path_tool.rs index 236978c78f0c2fee7ecf611486349bab094b3cec..be2a636cb88e811d5d66fce6cb789b6158bcb069 100644 --- a/crates/agent/src/tools/copy_path_tool.rs +++ b/crates/agent/src/tools/copy_path_tool.rs @@ -41,7 +41,7 @@ pub struct CopyPathTool { } impl CopyPathTool { - pub fn new(project: Entity) -> Self { + pub const fn new(project: Entity) -> Self { Self { project } } } diff --git a/crates/agent/src/tools/create_directory_tool.rs b/crates/agent/src/tools/create_directory_tool.rs index b6240e99cf4dd6698bf9f46edd8d4681247d8f64..677b7b11f33b0e7ffb60b5ec2ee2513f296ec926 100644 --- a/crates/agent/src/tools/create_directory_tool.rs +++ b/crates/agent/src/tools/create_directory_tool.rs @@ -32,7 +32,7 @@ pub struct CreateDirectoryTool { } impl CreateDirectoryTool { - pub fn new(project: Entity) -> Self { + pub const fn new(project: Entity) -> Self { Self { project } } } diff --git a/crates/agent/src/tools/delete_path_tool.rs b/crates/agent/src/tools/delete_path_tool.rs index 01a77f5d811127b3df470ec73fbc91ff7c26fd52..8dae85a525c8956902513e261b4bb4365af5cd50 100644 --- a/crates/agent/src/tools/delete_path_tool.rs +++ b/crates/agent/src/tools/delete_path_tool.rs @@ -32,7 +32,7 @@ pub struct DeletePathTool { } impl DeletePathTool { - pub fn new(project: Entity, action_log: Entity) -> Self { + pub const fn new(project: Entity, action_log: Entity) -> Self { Self { project, action_log, diff --git a/crates/agent/src/tools/diagnostics_tool.rs b/crates/agent/src/tools/diagnostics_tool.rs index f07ec4cfe6903ec454eb39a7afc7748327e026ec..fdc6fb8841aebbb828ef490e4e544b7359fd9c39 100644 --- a/crates/agent/src/tools/diagnostics_tool.rs +++ b/crates/agent/src/tools/diagnostics_tool.rs @@ -54,7 +54,7 @@ pub struct DiagnosticsTool { } impl DiagnosticsTool { - pub fn new(project: Entity) -> Self { + pub const fn new(project: Entity) -> Self { Self { project } } } diff --git a/crates/agent/src/tools/edit_file_tool.rs b/crates/agent/src/tools/edit_file_tool.rs index 0adff2dee3571f09b40ee69896c05e50c56b51b9..d0e4620dd66c7f2235e82dd364ba1e83da55bbcf 100644 --- a/crates/agent/src/tools/edit_file_tool.rs +++ b/crates/agent/src/tools/edit_file_tool.rs @@ -129,7 +129,7 @@ pub struct EditFileTool { } impl EditFileTool { - pub fn new( + pub const fn new( project: Entity, thread: WeakEntity, language_registry: Arc, diff --git a/crates/agent/src/tools/fetch_tool.rs b/crates/agent/src/tools/fetch_tool.rs index 60654ac863acdc559aeaad90f1c73727f33d1b59..94b9269c1c1bdd879ac15a14227ea90dc8b4f527 100644 --- a/crates/agent/src/tools/fetch_tool.rs +++ b/crates/agent/src/tools/fetch_tool.rs @@ -34,7 +34,7 @@ pub struct FetchTool { } impl FetchTool { - pub fn new(http_client: Arc) -> Self { + pub const fn new(http_client: Arc) -> Self { Self { http_client } } diff --git a/crates/agent/src/tools/find_path_tool.rs b/crates/agent/src/tools/find_path_tool.rs index 59f203cec98a17fda9e46f6fc222f3157d125060..bfc4675d89f15cb03902607455eedfc820e7090d 100644 --- a/crates/agent/src/tools/find_path_tool.rs +++ b/crates/agent/src/tools/find_path_tool.rs @@ -76,7 +76,7 @@ pub struct FindPathTool { } impl FindPathTool { - pub fn new(project: Entity) -> Self { + pub const fn new(project: Entity) -> Self { Self { project } } } diff --git a/crates/agent/src/tools/grep_tool.rs b/crates/agent/src/tools/grep_tool.rs index 7e78a3d1c4ba5492faf1ac7c879ab315366d724e..bef5f27e48698080f77aabbd11b0cd4761582f9c 100644 --- a/crates/agent/src/tools/grep_tool.rs +++ b/crates/agent/src/tools/grep_tool.rs @@ -46,7 +46,7 @@ pub struct GrepToolInput { impl GrepToolInput { /// Which page of search results this is. - pub fn page(&self) -> u32 { + pub const fn page(&self) -> u32 { 1 + (self.offset / RESULTS_PER_PAGE) } } @@ -58,7 +58,7 @@ pub struct GrepTool { } impl GrepTool { - pub fn new(project: Entity) -> Self { + pub const fn new(project: Entity) -> Self { Self { project } } } diff --git a/crates/agent/src/tools/list_directory_tool.rs b/crates/agent/src/tools/list_directory_tool.rs index cd8b46ddebc2d9ffb953f8aabef10c30a33dde37..4e924db769e656c37308ee90fee46e3a8e7f516c 100644 --- a/crates/agent/src/tools/list_directory_tool.rs +++ b/crates/agent/src/tools/list_directory_tool.rs @@ -42,7 +42,7 @@ pub struct ListDirectoryTool { } impl ListDirectoryTool { - pub fn new(project: Entity) -> Self { + pub const fn new(project: Entity) -> Self { Self { project } } } diff --git a/crates/agent/src/tools/move_path_tool.rs b/crates/agent/src/tools/move_path_tool.rs index ae58145126f6356beaa1457d719812bb56d6e7db..27faaa6e52c7f0a9fc4979c499e87680c50d38a6 100644 --- a/crates/agent/src/tools/move_path_tool.rs +++ b/crates/agent/src/tools/move_path_tool.rs @@ -43,7 +43,7 @@ pub struct MovePathTool { } impl MovePathTool { - pub fn new(project: Entity) -> Self { + pub const fn new(project: Entity) -> Self { Self { project } } } diff --git a/crates/agent/src/tools/open_tool.rs b/crates/agent/src/tools/open_tool.rs index b98ae9af3bd98cd44bc9348e72519ceea53c6292..d20f1be83a9a36a6ec08cadb052612bc1519f2ee 100644 --- a/crates/agent/src/tools/open_tool.rs +++ b/crates/agent/src/tools/open_tool.rs @@ -28,7 +28,7 @@ pub struct OpenTool { } impl OpenTool { - pub fn new(project: Entity) -> Self { + pub const fn new(project: Entity) -> Self { Self { project } } } diff --git a/crates/agent/src/tools/read_file_tool.rs b/crates/agent/src/tools/read_file_tool.rs index f3ce8e35f2856a3dd53770eef48ec1091fe9b116..229b360ee618310ed77de59fb82dca7cfb3e1b33 100644 --- a/crates/agent/src/tools/read_file_tool.rs +++ b/crates/agent/src/tools/read_file_tool.rs @@ -47,7 +47,7 @@ pub struct ReadFileTool { } impl ReadFileTool { - pub fn new(project: Entity, action_log: Entity) -> Self { + pub const fn new(project: Entity, action_log: Entity) -> Self { Self { project, action_log, diff --git a/crates/agent_servers/src/acp.rs b/crates/agent_servers/src/acp.rs index dac6db1b12c38a967c3abd05cf34a96a44f77b08..6cfe63cf9f21084fffaed2a59962641461586e13 100644 --- a/crates/agent_servers/src/acp.rs +++ b/crates/agent_servers/src/acp.rs @@ -197,7 +197,7 @@ impl AcpConnection { }) } - pub fn prompt_capabilities(&self) -> &acp::PromptCapabilities { + pub const fn prompt_capabilities(&self) -> &acp::PromptCapabilities { &self.agent_capabilities.prompt_capabilities } @@ -548,7 +548,7 @@ struct AcpModelSelector { } impl AcpModelSelector { - fn new( + const fn new( session_id: acp::SessionId, connection: Rc, state: Rc>, diff --git a/crates/agent_servers/src/agent_servers.rs b/crates/agent_servers/src/agent_servers.rs index b44c2123fb5052e2487464d813936cd1edf9821a..ac2261dc7de78664a983a2c215df0a036134efc2 100644 --- a/crates/agent_servers/src/agent_servers.rs +++ b/crates/agent_servers/src/agent_servers.rs @@ -34,7 +34,7 @@ pub struct AgentServerDelegate { } impl AgentServerDelegate { - pub fn new( + pub const fn new( store: Entity, project: Entity, status_tx: Option>, @@ -48,7 +48,7 @@ impl AgentServerDelegate { } } - pub fn project(&self) -> &Entity { + pub const fn project(&self) -> &Entity { &self.project } } diff --git a/crates/agent_servers/src/custom.rs b/crates/agent_servers/src/custom.rs index 406a18965111a44bc4e78469b20aaf199cbda037..7835df11e303b04523be88546c314650b1095ca9 100644 --- a/crates/agent_servers/src/custom.rs +++ b/crates/agent_servers/src/custom.rs @@ -15,7 +15,7 @@ pub struct CustomAgentServer { } impl CustomAgentServer { - pub fn new(name: SharedString) -> Self { + pub const fn new(name: SharedString) -> Self { Self { name } } } diff --git a/crates/agent_settings/src/agent_profile.rs b/crates/agent_settings/src/agent_profile.rs index 999ddc8083a1a4b4c271ea9bde4c1e45307e9542..3af9fa1a0036eda70f20eb215048e9ec3837335e 100644 --- a/crates/agent_settings/src/agent_profile.rs +++ b/crates/agent_settings/src/agent_profile.rs @@ -33,11 +33,11 @@ pub struct AgentProfile { pub type AvailableProfiles = IndexMap; impl AgentProfile { - pub fn new(id: AgentProfileId) -> Self { + pub const fn new(id: AgentProfileId) -> Self { Self { id } } - pub fn id(&self) -> &AgentProfileId { + pub const fn id(&self) -> &AgentProfileId { &self.id } diff --git a/crates/agent_settings/src/agent_settings.rs b/crates/agent_settings/src/agent_settings.rs index 988340318c9f6a68d7b36010eecf0957df145236..901781d4f7086cb09e4181d3b254aa254ac072c0 100644 --- a/crates/agent_settings/src/agent_settings.rs +++ b/crates/agent_settings/src/agent_settings.rs @@ -96,7 +96,7 @@ impl AgentSettings { }); } - pub fn set_message_editor_max_lines(&self) -> usize { + pub const fn set_message_editor_max_lines(&self) -> usize { self.message_editor_min_lines * 2 } } diff --git a/crates/agent_ui/src/acp/completion_provider.rs b/crates/agent_ui/src/acp/completion_provider.rs index c5ab47fe18970791c047ef157f6664188c95e346..869509aa7defb9f313467edf883856eb403884a8 100644 --- a/crates/agent_ui/src/acp/completion_provider.rs +++ b/crates/agent_ui/src/acp/completion_provider.rs @@ -76,7 +76,7 @@ pub struct ContextPickerCompletionProvider { } impl ContextPickerCompletionProvider { - pub fn new( + pub const fn new( message_editor: WeakEntity, workspace: WeakEntity, history_store: Entity, diff --git a/crates/agent_ui/src/acp/entry_view_state.rs b/crates/agent_ui/src/acp/entry_view_state.rs index 8123c4a422b9d95a2da45e75ceb4079675d845fd..cc42b0d9e125fc349bc731099add5c731ff46add 100644 --- a/crates/agent_ui/src/acp/entry_view_state.rs +++ b/crates/agent_ui/src/acp/entry_view_state.rs @@ -32,7 +32,7 @@ pub struct EntryViewState { } impl EntryViewState { - pub fn new( + pub const fn new( workspace: WeakEntity, project: Entity, history_store: Entity, @@ -272,7 +272,7 @@ impl Entry { } } - pub fn message_editor(&self) -> Option<&Entity> { + pub const fn message_editor(&self) -> Option<&Entity> { match self { Self::UserMessage(editor) => Some(editor), Self::AssistantMessage(_) | Self::Content(_) => None, @@ -306,7 +306,7 @@ impl Entry { } } - fn content_map(&self) -> Option<&HashMap> { + const fn content_map(&self) -> Option<&HashMap> { match self { Self::Content(map) => Some(map), _ => None, diff --git a/crates/agent_ui/src/acp/message_editor.rs b/crates/agent_ui/src/acp/message_editor.rs index 57157e59c6b48541ff82bdc417bc119ed01bb997..44cad86dacf2d965e4b4268a5e36c48b86c712ed 100644 --- a/crates/agent_ui/src/acp/message_editor.rs +++ b/crates/agent_ui/src/acp/message_editor.rs @@ -1561,7 +1561,7 @@ impl MentionSet { pub struct MessageEditorAddon {} impl MessageEditorAddon { - pub fn new() -> Self { + pub const fn new() -> Self { Self {} } } diff --git a/crates/agent_ui/src/acp/model_selector.rs b/crates/agent_ui/src/acp/model_selector.rs index 45fec558720fc5e88548f6dd7bc24fe624a908f5..31966304544792bc4270975079176c13e2a25f8c 100644 --- a/crates/agent_ui/src/acp/model_selector.rs +++ b/crates/agent_ui/src/acp/model_selector.rs @@ -95,7 +95,7 @@ impl AcpModelPickerDelegate { } } - pub fn active_model(&self) -> Option<&AgentModelInfo> { + pub const fn active_model(&self) -> Option<&AgentModelInfo> { self.selected_model.as_ref() } } diff --git a/crates/agent_ui/src/acp/thread_history.rs b/crates/agent_ui/src/acp/thread_history.rs index ee280eb9a123e46ba5cf3b75cdeaf67c4b98b71c..8c73a865018faa16d0fdbfe271324bfd43c8d79f 100644 --- a/crates/agent_ui/src/acp/thread_history.rs +++ b/crates/agent_ui/src/acp/thread_history.rs @@ -42,7 +42,7 @@ enum ListItemType { } impl ListItemType { - fn history_entry(&self) -> Option<&HistoryEntry> { + const fn history_entry(&self) -> Option<&HistoryEntry> { match self { ListItemType::Entry { entry, .. } => Some(entry), ListItemType::SearchResult { entry, .. } => Some(entry), @@ -540,7 +540,7 @@ impl AcpHistoryEntryElement { } } - pub fn hovered(mut self, hovered: bool) -> Self { + pub const fn hovered(mut self, hovered: bool) -> Self { self.hovered = hovered; self } diff --git a/crates/agent_ui/src/acp/thread_view.rs b/crates/agent_ui/src/acp/thread_view.rs index cb2e8be2701c2152ef889f7bdc9925f8014f9519..c800b53178a8a8c1afa16210a8cec30074ba9b9d 100644 --- a/crates/agent_ui/src/acp/thread_view.rs +++ b/crates/agent_ui/src/acp/thread_view.rs @@ -820,11 +820,11 @@ impl AcpThreadView { } } - pub fn workspace(&self) -> &WeakEntity { + pub const fn workspace(&self) -> &WeakEntity { &self.workspace } - pub fn thread(&self) -> Option<&Entity> { + pub const fn thread(&self) -> Option<&Entity> { match &self.thread_state { ThreadState::Ready { thread, .. } => Some(thread), ThreadState::Unauthenticated { .. } @@ -833,7 +833,7 @@ impl AcpThreadView { } } - pub fn mode_selector(&self) -> Option<&Entity> { + pub const fn mode_selector(&self) -> Option<&Entity> { match &self.thread_state { ThreadState::Ready { mode_selector, .. } => mode_selector.as_ref(), ThreadState::Unauthenticated { .. } diff --git a/crates/agent_ui/src/agent_configuration/add_llm_provider_modal.rs b/crates/agent_ui/src/agent_configuration/add_llm_provider_modal.rs index 5e1712e626da98c60834da28906afa3eb30b92e6..f59fd49b789da4b1cb350e370c72fc9c9eb53fdc 100644 --- a/crates/agent_ui/src/agent_configuration/add_llm_provider_modal.rs +++ b/crates/agent_ui/src/agent_configuration/add_llm_provider_modal.rs @@ -19,13 +19,13 @@ pub enum LlmCompatibleProvider { } impl LlmCompatibleProvider { - fn name(&self) -> &'static str { + const fn name(&self) -> &'static str { match self { LlmCompatibleProvider::OpenAi => "OpenAI", } } - fn api_url(&self) -> &'static str { + const fn api_url(&self) -> &'static str { match self { LlmCompatibleProvider::OpenAi => "https://api.openai.com/v1", } diff --git a/crates/agent_ui/src/agent_configuration/configure_context_server_modal.rs b/crates/agent_ui/src/agent_configuration/configure_context_server_modal.rs index ce8e167dab3ed2e4d84c4afd747cb266740f1d42..c64c49bcdef02511e72c0e422e0a23e845165119 100644 --- a/crates/agent_ui/src/agent_configuration/configure_context_server_modal.rs +++ b/crates/agent_ui/src/agent_configuration/configure_context_server_modal.rs @@ -60,11 +60,11 @@ enum ConfigurationSource { } impl ConfigurationSource { - fn has_configuration_options(&self) -> bool { + const fn has_configuration_options(&self) -> bool { !matches!(self, ConfigurationSource::Extension { editor: None, .. }) } - fn is_new(&self) -> bool { + const fn is_new(&self) -> bool { matches!(self, ConfigurationSource::New { .. }) } diff --git a/crates/agent_ui/src/agent_panel.rs b/crates/agent_ui/src/agent_panel.rs index 2def41c74dd715637f269e572342d04b944505b5..a1309ad605d70408a2dc817778b473c1071e102b 100644 --- a/crates/agent_ui/src/agent_panel.rs +++ b/crates/agent_ui/src/agent_panel.rs @@ -240,7 +240,7 @@ impl AgentType { } } - fn icon(&self) -> Option { + const fn icon(&self) -> Option { match self { Self::NativeAgent | Self::TextThread => None, Self::Gemini => Some(IconName::AiGemini), @@ -264,7 +264,7 @@ impl From for AgentType { } impl ActiveView { - pub fn which_font_size_used(&self) -> WhichFontSize { + pub const fn which_font_size_used(&self) -> WhichFontSize { match self { ActiveView::ExternalAgentThread { .. } | ActiveView::History => { WhichFontSize::AgentFont @@ -676,23 +676,23 @@ impl AgentPanel { } } - pub(crate) fn prompt_store(&self) -> &Option> { + pub(crate) const fn prompt_store(&self) -> &Option> { &self.prompt_store } - pub(crate) fn inline_assist_context_store(&self) -> &Entity { + pub(crate) const fn inline_assist_context_store(&self) -> &Entity { &self.inline_assist_context_store } - pub(crate) fn thread_store(&self) -> &Entity { + pub(crate) const fn thread_store(&self) -> &Entity { &self.history_store } - pub(crate) fn context_server_registry(&self) -> &Entity { + pub(crate) const fn context_server_registry(&self) -> &Entity { &self.context_server_registry } - fn active_thread_view(&self) -> Option<&Entity> { + const fn active_thread_view(&self) -> Option<&Entity> { match &self.active_view { ActiveView::ExternalAgentThread { thread_view, .. } => Some(thread_view), ActiveView::TextThread { .. } | ActiveView::History | ActiveView::Configuration => None, @@ -2484,7 +2484,7 @@ struct PromptLibraryInlineAssist { } impl PromptLibraryInlineAssist { - pub fn new(workspace: WeakEntity) -> Self { + pub const fn new(workspace: WeakEntity) -> Self { Self { workspace } } } diff --git a/crates/agent_ui/src/agent_ui.rs b/crates/agent_ui/src/agent_ui.rs index 7c31500c937a6513c932c66560cf8754cbafbf1c..4cdc1e6236e39002313263082d216e1ccc530040 100644 --- a/crates/agent_ui/src/agent_ui.rs +++ b/crates/agent_ui/src/agent_ui.rs @@ -218,7 +218,7 @@ pub struct ManageProfiles { } impl ManageProfiles { - pub fn customize_tools(profile_id: AgentProfileId) -> Self { + pub const fn customize_tools(profile_id: AgentProfileId) -> Self { Self { customize_tools: Some(profile_id), } diff --git a/crates/agent_ui/src/buffer_codegen.rs b/crates/agent_ui/src/buffer_codegen.rs index 215e2a74d7be9cbcb18442dcefa1581d08eec7b2..22f16a3f3c24346f983f9255173e5fe7ced26ddc 100644 --- a/crates/agent_ui/src/buffer_codegen.rs +++ b/crates/agent_ui/src/buffer_codegen.rs @@ -941,7 +941,7 @@ impl StripInvalidSpans where T: Stream>, { - fn new(stream: T) -> Self { + const fn new(stream: T) -> Self { Self { stream, stream_done: false, @@ -1067,7 +1067,7 @@ pub struct Diff { } impl Diff { - fn is_empty(&self) -> bool { + const fn is_empty(&self) -> bool { self.deleted_row_ranges.is_empty() && self.inserted_row_ranges.is_empty() } } diff --git a/crates/agent_ui/src/context.rs b/crates/agent_ui/src/context.rs index 3d0600605153fd8343205f3889953c100bde7a7a..0f13e5506df85cae8df7a72e716f945f2cc4aaf2 100644 --- a/crates/agent_ui/src/context.rs +++ b/crates/agent_ui/src/context.rs @@ -34,7 +34,7 @@ pub enum ContextKind { } impl ContextKind { - pub fn icon(&self) -> IconName { + pub const fn icon(&self) -> IconName { match self { ContextKind::File => IconName::File, ContextKind::Directory => IconName::Folder, @@ -68,7 +68,7 @@ pub enum AgentContextHandle { } impl AgentContextHandle { - pub fn id(&self) -> ContextId { + pub const fn id(&self) -> ContextId { match self { Self::File(context) => context.context_id, Self::Directory(context) => context.context_id, @@ -82,7 +82,7 @@ impl AgentContextHandle { } } - pub fn element_id(&self, name: SharedString) -> ElementId { + pub const fn element_id(&self, name: SharedString) -> ElementId { ElementId::NamedInteger(name, self.id().0) } } @@ -130,11 +130,11 @@ impl AgentContext { pub struct ContextId(u64); impl ContextId { - pub fn zero() -> Self { + pub const fn zero() -> Self { ContextId(0) } - fn for_lookup() -> Self { + const fn for_lookup() -> Self { ContextId(u64::MAX) } @@ -519,7 +519,7 @@ impl FetchedUrlContext { })) } - pub fn load(self) -> Task> { + pub const fn load(self) -> Task> { Task::ready(Some(AgentContext::FetchedUrl(self))) } } @@ -649,7 +649,7 @@ impl RulesContextHandle { self.prompt_id.hash(state) } - pub fn lookup_key(prompt_id: UserPromptId) -> AgentContextKey { + pub const fn lookup_key(prompt_id: UserPromptId) -> AgentContextKey { AgentContextKey(AgentContextHandle::Rules(RulesContextHandle { prompt_id, context_id: ContextId::for_lookup(), diff --git a/crates/agent_ui/src/context_picker.rs b/crates/agent_ui/src/context_picker.rs index caffb31521e397ca7cd6b1fa0c8f4ae73d5ab9ff..68e02dd149e49fb488440e088f25823788eef52d 100644 --- a/crates/agent_ui/src/context_picker.rs +++ b/crates/agent_ui/src/context_picker.rs @@ -47,21 +47,21 @@ pub(crate) enum ContextPickerEntry { } impl ContextPickerEntry { - pub fn keyword(&self) -> &'static str { + pub const fn keyword(&self) -> &'static str { match self { Self::Mode(mode) => mode.keyword(), Self::Action(action) => action.keyword(), } } - pub fn label(&self) -> &'static str { + pub const fn label(&self) -> &'static str { match self { Self::Mode(mode) => mode.label(), Self::Action(action) => action.label(), } } - pub fn icon(&self) -> IconName { + pub const fn icon(&self) -> IconName { match self { Self::Mode(mode) => mode.icon(), Self::Action(action) => action.icon(), @@ -84,19 +84,19 @@ pub(crate) enum ContextPickerAction { } impl ContextPickerAction { - pub fn keyword(&self) -> &'static str { + pub const fn keyword(&self) -> &'static str { match self { Self::AddSelections => "selection", } } - pub fn label(&self) -> &'static str { + pub const fn label(&self) -> &'static str { match self { Self::AddSelections => "Selection", } } - pub fn icon(&self) -> IconName { + pub const fn icon(&self) -> IconName { match self { Self::AddSelections => IconName::Reader, } @@ -119,7 +119,7 @@ impl TryFrom<&str> for ContextPickerMode { } impl ContextPickerMode { - pub fn keyword(&self) -> &'static str { + pub const fn keyword(&self) -> &'static str { match self { Self::File => "file", Self::Symbol => "symbol", @@ -129,7 +129,7 @@ impl ContextPickerMode { } } - pub fn label(&self) -> &'static str { + pub const fn label(&self) -> &'static str { match self { Self::File => "Files & Directories", Self::Symbol => "Symbols", @@ -139,7 +139,7 @@ impl ContextPickerMode { } } - pub fn icon(&self) -> IconName { + pub const fn icon(&self) -> IconName { match self { Self::File => IconName::File, Self::Symbol => IconName::Code, @@ -281,7 +281,7 @@ impl ContextPicker { } /// Whether threads are allowed as context. - pub fn allow_threads(&self) -> bool { + pub const fn allow_threads(&self) -> bool { self.thread_store.is_some() } diff --git a/crates/agent_ui/src/context_picker/completion_provider.rs b/crates/agent_ui/src/context_picker/completion_provider.rs index 56444141f12903db4868f9e154cccdb872b48514..8e69f40b9838ad8ea649f9449f5518fef7770cde 100644 --- a/crates/agent_ui/src/context_picker/completion_provider.rs +++ b/crates/agent_ui/src/context_picker/completion_provider.rs @@ -243,7 +243,7 @@ pub struct ContextPickerCompletionProvider { } impl ContextPickerCompletionProvider { - pub fn new( + pub const fn new( workspace: WeakEntity, context_store: WeakEntity, thread_store: Option>, diff --git a/crates/agent_ui/src/context_picker/fetch_context_picker.rs b/crates/agent_ui/src/context_picker/fetch_context_picker.rs index 31fc45aca3ccbf561793769939169d214aaa2d99..6b713b09559b37949fa959c2209a6afa23af7e2d 100644 --- a/crates/agent_ui/src/context_picker/fetch_context_picker.rs +++ b/crates/agent_ui/src/context_picker/fetch_context_picker.rs @@ -59,7 +59,7 @@ pub struct FetchContextPickerDelegate { } impl FetchContextPickerDelegate { - pub fn new( + pub const fn new( context_picker: WeakEntity, workspace: WeakEntity, context_store: WeakEntity, diff --git a/crates/agent_ui/src/context_picker/file_context_picker.rs b/crates/agent_ui/src/context_picker/file_context_picker.rs index 8d1e5cb46dfba7bc89770356334fb08a7bf7a0c5..3161f5d537de4826a9a8e371d99a639e75c65048 100644 --- a/crates/agent_ui/src/context_picker/file_context_picker.rs +++ b/crates/agent_ui/src/context_picker/file_context_picker.rs @@ -57,7 +57,7 @@ pub struct FileContextPickerDelegate { } impl FileContextPickerDelegate { - pub fn new( + pub const fn new( context_picker: WeakEntity, workspace: WeakEntity, context_store: WeakEntity, diff --git a/crates/agent_ui/src/context_picker/rules_context_picker.rs b/crates/agent_ui/src/context_picker/rules_context_picker.rs index 68f4917a4fd5689aab1a418dd78d2c8a322cd717..cd00dad8ac91368db0ba122261652e03fbcb3561 100644 --- a/crates/agent_ui/src/context_picker/rules_context_picker.rs +++ b/crates/agent_ui/src/context_picker/rules_context_picker.rs @@ -59,7 +59,7 @@ pub struct RulesContextPickerDelegate { } impl RulesContextPickerDelegate { - pub fn new( + pub const fn new( prompt_store: WeakEntity, context_picker: WeakEntity, context_store: WeakEntity, diff --git a/crates/agent_ui/src/context_picker/symbol_context_picker.rs b/crates/agent_ui/src/context_picker/symbol_context_picker.rs index fbce71d94efd84b1acc6e0b5d4ea11cb2b9243d5..c7fd74c9938dac6f6ad27b4cf0bc7672ab07a5fb 100644 --- a/crates/agent_ui/src/context_picker/symbol_context_picker.rs +++ b/crates/agent_ui/src/context_picker/symbol_context_picker.rs @@ -59,7 +59,7 @@ pub struct SymbolContextPickerDelegate { } impl SymbolContextPickerDelegate { - pub fn new( + pub const fn new( context_picker: WeakEntity, workspace: WeakEntity, context_store: WeakEntity, diff --git a/crates/agent_ui/src/context_picker/thread_context_picker.rs b/crates/agent_ui/src/context_picker/thread_context_picker.rs index d6a3a270742fe28c483d2d7d39894eb9e3c021ea..53c470d346f3e80a8f892ae2ce9d10f2321a1e1c 100644 --- a/crates/agent_ui/src/context_picker/thread_context_picker.rs +++ b/crates/agent_ui/src/context_picker/thread_context_picker.rs @@ -59,7 +59,7 @@ pub struct ThreadContextPickerDelegate { } impl ThreadContextPickerDelegate { - pub fn new( + pub const fn new( thread_store: WeakEntity, context_picker: WeakEntity, context_store: WeakEntity, diff --git a/crates/agent_ui/src/context_store.rs b/crates/agent_ui/src/context_store.rs index e2ee1cd0c94fd6132719ffcc0bd352865b5f9cf9..8b268d6ae8b2f3ef4714b20a05c36c485e696ae3 100644 --- a/crates/agent_ui/src/context_store.rs +++ b/crates/agent_ui/src/context_store.rs @@ -526,7 +526,7 @@ impl ContextStore { .collect() } - pub fn thread_ids(&self) -> &HashSet { + pub const fn thread_ids(&self) -> &HashSet { &self.context_thread_ids } } @@ -549,7 +549,7 @@ pub enum SuggestedContext { } impl SuggestedContext { - pub fn name(&self) -> &SharedString { + pub const fn name(&self) -> &SharedString { match self { Self::File { name, .. } => name, // Self::Thread { name, .. } => name, @@ -565,7 +565,7 @@ impl SuggestedContext { } } - pub fn kind(&self) -> ContextKind { + pub const fn kind(&self) -> ContextKind { match self { Self::File { .. } => ContextKind::File, // Self::Thread { .. } => ContextKind::Thread, diff --git a/crates/agent_ui/src/inline_assistant.rs b/crates/agent_ui/src/inline_assistant.rs index 0f7f1f1d78056553f758796c7e6b2f14781fce0f..2346d4f3225fe9df65ce42006daf7d63f447ab19 100644 --- a/crates/agent_ui/src/inline_assistant.rs +++ b/crates/agent_ui/src/inline_assistant.rs @@ -1618,7 +1618,7 @@ struct InlineAssistGroup { } impl InlineAssistGroup { - fn new() -> Self { + const fn new() -> Self { Self { assist_ids: Vec::new(), linked: true, @@ -1642,7 +1642,7 @@ fn build_assist_editor_renderer(editor: &Entity>) -> struct InlineAssistGroupId(usize); impl InlineAssistGroupId { - fn post_inc(&mut self) -> InlineAssistGroupId { + const fn post_inc(&mut self) -> InlineAssistGroupId { let id = *self; self.0 += 1; id diff --git a/crates/agent_ui/src/inline_prompt_editor.rs b/crates/agent_ui/src/inline_prompt_editor.rs index 70d6009e466e3e2f6ba3cd65076f77f7d12b22e0..4afa235d734fd657514ebea9a1d986df764c4fd1 100644 --- a/crates/agent_ui/src/inline_prompt_editor.rs +++ b/crates/agent_ui/src/inline_prompt_editor.rs @@ -759,7 +759,7 @@ pub enum PromptEditorEvent { pub struct InlineAssistId(pub usize); impl InlineAssistId { - pub fn post_inc(&mut self) -> InlineAssistId { + pub const fn post_inc(&mut self) -> InlineAssistId { let id = *self; self.0 += 1; id @@ -932,7 +932,7 @@ impl PromptEditor { pub struct TerminalInlineAssistId(pub usize); impl TerminalInlineAssistId { - pub fn post_inc(&mut self) -> TerminalInlineAssistId { + pub const fn post_inc(&mut self) -> TerminalInlineAssistId { let id = *self; self.0 += 1; id @@ -1135,27 +1135,27 @@ pub enum GenerationMode { } impl GenerationMode { - fn start_label(self) -> &'static str { + const fn start_label(self) -> &'static str { match self { GenerationMode::Generate => "Generate", GenerationMode::Transform => "Transform", } } - fn tooltip_interrupt(self) -> &'static str { + const fn tooltip_interrupt(self) -> &'static str { match self { GenerationMode::Generate => "Interrupt Generation", GenerationMode::Transform => "Interrupt Transform", } } - fn tooltip_restart(self) -> &'static str { + const fn tooltip_restart(self) -> &'static str { match self { GenerationMode::Generate => "Restart Generation", GenerationMode::Transform => "Restart Transform", } } - fn tooltip_accept(self) -> &'static str { + const fn tooltip_accept(self) -> &'static str { match self { GenerationMode::Generate => "Accept Generation", GenerationMode::Transform => "Accept Transform", diff --git a/crates/agent_ui/src/slash_command_picker.rs b/crates/agent_ui/src/slash_command_picker.rs index a6bb61510cbeb557e22018c73082bba17d177d7e..b921d943a65472093815fad9007f8d6f2e6ddbb7 100644 --- a/crates/agent_ui/src/slash_command_picker.rs +++ b/crates/agent_ui/src/slash_command_picker.rs @@ -56,7 +56,7 @@ where T: PopoverTrigger + ButtonCommon, TT: Fn(&mut Window, &mut App) -> AnyView + 'static, { - pub(crate) fn new( + pub(crate) const fn new( working_set: Arc, active_context_editor: WeakEntity, trigger: T, diff --git a/crates/agent_ui/src/terminal_codegen.rs b/crates/agent_ui/src/terminal_codegen.rs index 5a4a9d560a16e858dcaedf706f2067a24bc12c5f..4b4060e17fd7ef2c6a705f526580edd8cf133b8b 100644 --- a/crates/agent_ui/src/terminal_codegen.rs +++ b/crates/agent_ui/src/terminal_codegen.rs @@ -21,7 +21,7 @@ pub struct TerminalCodegen { impl EventEmitter for TerminalCodegen {} impl TerminalCodegen { - pub fn new(terminal: Entity, telemetry: Option>) -> Self { + pub const fn new(terminal: Entity, telemetry: Option>) -> Self { Self { terminal, telemetry, @@ -171,7 +171,7 @@ struct TerminalTransaction { } impl TerminalTransaction { - pub fn start(terminal: Entity) -> Self { + pub const fn start(terminal: Entity) -> Self { Self { terminal } } diff --git a/crates/agent_ui/src/text_thread_editor.rs b/crates/agent_ui/src/text_thread_editor.rs index 2d28d95450726554787f6a9cb211e852ceaccddf..8b43e8ef69286b1b5cd81037737d0cf199f2167d 100644 --- a/crates/agent_ui/src/text_thread_editor.rs +++ b/crates/agent_ui/src/text_thread_editor.rs @@ -338,11 +338,11 @@ impl TextThreadEditor { }); } - pub fn context(&self) -> &Entity { + pub const fn context(&self) -> &Entity { &self.context } - pub fn editor(&self) -> &Entity { + pub const fn editor(&self) -> &Entity { &self.editor } diff --git a/crates/agent_ui/src/ui/burn_mode_tooltip.rs b/crates/agent_ui/src/ui/burn_mode_tooltip.rs index f95dc1250e36bba388452ce11e6ec783e44248e1..d89a3f68921e2d21e948a20d0dba9ccbff49fad8 100644 --- a/crates/agent_ui/src/ui/burn_mode_tooltip.rs +++ b/crates/agent_ui/src/ui/burn_mode_tooltip.rs @@ -7,11 +7,11 @@ pub struct BurnModeTooltip { } impl BurnModeTooltip { - pub fn new() -> Self { + pub const fn new() -> Self { Self { selected: false } } - pub fn selected(mut self, selected: bool) -> Self { + pub const fn selected(mut self, selected: bool) -> Self { self.selected = selected; self } diff --git a/crates/agent_ui/src/ui/unavailable_editing_tooltip.rs b/crates/agent_ui/src/ui/unavailable_editing_tooltip.rs index 2993fb89a989619ecfe3d79b06d82a2a6f71fc31..0f89d7b86855d5bf12f348e9752ae2190cbb780e 100644 --- a/crates/agent_ui/src/ui/unavailable_editing_tooltip.rs +++ b/crates/agent_ui/src/ui/unavailable_editing_tooltip.rs @@ -6,7 +6,7 @@ pub struct UnavailableEditingTooltip { } impl UnavailableEditingTooltip { - pub fn new(agent_name: SharedString) -> Self { + pub const fn new(agent_name: SharedString) -> Self { Self { agent_name } } } diff --git a/crates/agent_ui/src/ui/usage_callout.rs b/crates/agent_ui/src/ui/usage_callout.rs index e31af9f49aca781e735a96384dbaddbd3b446ef7..7fbae65adf98a7b9e0ba765d16600b2d7d14e186 100644 --- a/crates/agent_ui/src/ui/usage_callout.rs +++ b/crates/agent_ui/src/ui/usage_callout.rs @@ -11,7 +11,7 @@ pub struct UsageCallout { } impl UsageCallout { - pub fn new(plan: Plan, usage: ModelRequestUsage) -> Self { + pub const fn new(plan: Plan, usage: ModelRequestUsage) -> Self { Self { plan, usage } } } diff --git a/crates/ai_onboarding/src/agent_api_keys_onboarding.rs b/crates/ai_onboarding/src/agent_api_keys_onboarding.rs index fadc4222ae44f3dbad862fd9479b89321dbd3016..9146ea314487a8fdf12e8822994f1b4e700d047c 100644 --- a/crates/ai_onboarding/src/agent_api_keys_onboarding.rs +++ b/crates/ai_onboarding/src/agent_api_keys_onboarding.rs @@ -105,7 +105,7 @@ impl Render for ApiKeysWithProviders { pub struct ApiKeysWithoutProviders; impl ApiKeysWithoutProviders { - pub fn new() -> Self { + pub const fn new() -> Self { Self } } diff --git a/crates/ai_onboarding/src/ai_upsell_card.rs b/crates/ai_onboarding/src/ai_upsell_card.rs index 91191688b556d6b040ad8de760fba5ed0fd3659e..8c55866084ab06350e7e481f345bcfea9b7b4848 100644 --- a/crates/ai_onboarding/src/ai_upsell_card.rs +++ b/crates/ai_onboarding/src/ai_upsell_card.rs @@ -41,7 +41,7 @@ impl AiUpsellCard { } } - pub fn tab_index(mut self, tab_index: Option) -> Self { + pub const fn tab_index(mut self, tab_index: Option) -> Self { self.tab_index = tab_index; self } diff --git a/crates/anthropic/src/anthropic.rs b/crates/anthropic/src/anthropic.rs index cd2077cdeb1370a9753df83f9b239ef776bab149..7f89457ad88032bcffba078c1aee1c18c338413a 100644 --- a/crates/anthropic/src/anthropic.rs +++ b/crates/anthropic/src/anthropic.rs @@ -126,7 +126,7 @@ pub enum Model { } impl Model { - pub fn default_fast() -> Self { + pub const fn default_fast() -> Self { Self::Claude3_5Haiku } @@ -297,7 +297,7 @@ impl Model { } } - pub fn max_token_count(&self) -> u64 { + pub const fn max_token_count(&self) -> u64 { match self { Self::ClaudeOpus4 | Self::ClaudeOpus4_1 diff --git a/crates/assistant_context/src/assistant_context.rs b/crates/assistant_context/src/assistant_context.rs index 6c06cc2c8ec7f845b1e6d49631a1bea6755a62d0..6e51f6c832781eb49cd3de8c77ce9a216f8c4e90 100644 --- a/crates/assistant_context/src/assistant_context.rs +++ b/crates/assistant_context/src/assistant_context.rs @@ -62,7 +62,7 @@ impl ContextId { Self(Uuid::new_v4().to_string()) } - pub fn from_proto(id: String) -> Self { + pub const fn from_proto(id: String) -> Self { Self(id) } @@ -75,7 +75,7 @@ impl ContextId { pub struct MessageId(pub clock::Lamport); impl MessageId { - pub fn as_u64(self) -> u64 { + pub const fn as_u64(self) -> u64 { self.0.as_u64() } } @@ -505,14 +505,14 @@ impl ContextSummary { .map_or_else(|| message.into(), |content| content.text.clone().into()) } - pub fn content(&self) -> Option<&ContextSummaryContent> { + pub const fn content(&self) -> Option<&ContextSummaryContent> { match self { ContextSummary::Content(content) => Some(content), ContextSummary::Pending | ContextSummary::Error => None, } } - fn content_as_mut(&mut self) -> Option<&mut ContextSummaryContent> { + const fn content_as_mut(&mut self) -> Option<&mut ContextSummaryContent> { match self { ContextSummary::Content(content) => Some(content), ContextSummary::Pending | ContextSummary::Error => None, @@ -530,11 +530,11 @@ impl ContextSummary { } } - pub fn is_pending(&self) -> bool { + pub const fn is_pending(&self) -> bool { matches!(self, ContextSummary::Pending) } - fn timestamp(&self) -> Option { + const fn timestamp(&self) -> Option { match self { ContextSummary::Content(content) => Some(content.timestamp), ContextSummary::Pending | ContextSummary::Error => None, @@ -636,7 +636,7 @@ pub enum Content { } impl Content { - fn range(&self) -> Range { + const fn range(&self) -> Range { match self { Self::Image { anchor, .. } => *anchor..*anchor, } @@ -731,11 +731,11 @@ impl AssistantContext { ) } - pub fn completion_mode(&self) -> agent_settings::CompletionMode { + pub const fn completion_mode(&self) -> agent_settings::CompletionMode { self.completion_mode } - pub fn set_completion_mode(&mut self, completion_mode: agent_settings::CompletionMode) { + pub const fn set_completion_mode(&mut self, completion_mode: agent_settings::CompletionMode) { self.completion_mode = completion_mode; } @@ -902,11 +902,11 @@ impl AssistantContext { this } - pub fn id(&self) -> &ContextId { + pub const fn id(&self) -> &ContextId { &self.id } - pub fn replica_id(&self) -> ReplicaId { + pub const fn replica_id(&self) -> ReplicaId { self.timestamp.replica_id } @@ -917,7 +917,7 @@ impl AssistantContext { } } - pub fn slash_commands(&self) -> &Arc { + pub const fn slash_commands(&self) -> &Arc { &self.slash_commands } @@ -1165,7 +1165,7 @@ impl AssistantContext { cx.emit(ContextEvent::Operation(op)); } - pub fn buffer(&self) -> &Entity { + pub const fn buffer(&self) -> &Entity { &self.buffer } @@ -1181,11 +1181,11 @@ impl AssistantContext { self.prompt_builder.clone() } - pub fn path(&self) -> Option<&Arc> { + pub const fn path(&self) -> Option<&Arc> { self.path.as_ref() } - pub fn summary(&self) -> &ContextSummary { + pub const fn summary(&self) -> &ContextSummary { &self.summary } @@ -1258,7 +1258,7 @@ impl AssistantContext { } } - pub fn token_count(&self) -> Option { + pub const fn token_count(&self) -> Option { self.token_count } @@ -3046,7 +3046,7 @@ pub enum PendingToolUseStatus { } impl PendingToolUseStatus { - pub fn is_idle(&self) -> bool { + pub const fn is_idle(&self) -> bool { matches!(self, PendingToolUseStatus::Idle) } } diff --git a/crates/assistant_slash_command/src/assistant_slash_command.rs b/crates/assistant_slash_command/src/assistant_slash_command.rs index 2e6bb7325e14ac109d77854e1d848c541a685458..93c634f503fdf69eb2cd9be59a98772bd5f154c6 100644 --- a/crates/assistant_slash_command/src/assistant_slash_command.rs +++ b/crates/assistant_slash_command/src/assistant_slash_command.rs @@ -47,7 +47,7 @@ impl From for AfterCompletion { } impl AfterCompletion { - pub fn run(&self) -> bool { + pub const fn run(&self) -> bool { match self { AfterCompletion::Run => true, AfterCompletion::Compose | AfterCompletion::Continue => false, diff --git a/crates/assistant_slash_commands/src/context_server_command.rs b/crates/assistant_slash_commands/src/context_server_command.rs index ee0cbf54c23a595f6503162c91dd1df3be019dd5..138ec90f437b25648c48cf6f27968b7797162fcd 100644 --- a/crates/assistant_slash_commands/src/context_server_command.rs +++ b/crates/assistant_slash_commands/src/context_server_command.rs @@ -23,7 +23,7 @@ pub struct ContextServerSlashCommand { } impl ContextServerSlashCommand { - pub fn new(store: Entity, id: ContextServerId, prompt: Prompt) -> Self { + pub const fn new(store: Entity, id: ContextServerId, prompt: Prompt) -> Self { Self { server_id: id, prompt, @@ -242,7 +242,7 @@ fn prompt_arguments(prompt: &Prompt, arguments: &[String]) -> Result bool { +pub const fn acceptable_prompt(prompt: &Prompt) -> bool { match &prompt.arguments { None => true, Some(args) if args.len() <= 1 => true, diff --git a/crates/audio/src/audio.rs b/crates/audio/src/audio.rs index 9ad5a36a374d87b2cdcc6434377da3652af97786..961d8da2d1fe42ed3d614c1eaae3a0bf2c2ff3fb 100644 --- a/crates/audio/src/audio.rs +++ b/crates/audio/src/audio.rs @@ -65,7 +65,7 @@ pub enum Sound { } impl Sound { - fn file(&self) -> &'static str { + const fn file(&self) -> &'static str { match self { Self::Joined => "joined_call", Self::GuestJoined => "guest_joined_call", diff --git a/crates/auto_update/src/auto_update.rs b/crates/auto_update/src/auto_update.rs index 9f93dd27900e4b90de8c6d61d41b3b6c287eaaf0..b94d41e8183aad8d012017e51729c6f7cd30d371 100644 --- a/crates/auto_update/src/auto_update.rs +++ b/crates/auto_update/src/auto_update.rs @@ -67,7 +67,7 @@ pub enum AutoUpdateStatus { } impl AutoUpdateStatus { - pub fn is_updated(&self) -> bool { + pub const fn is_updated(&self) -> bool { matches!(self, Self::Updated { .. }) } } @@ -371,7 +371,7 @@ impl AutoUpdater { })); } - pub fn current_version(&self) -> SemanticVersion { + pub const fn current_version(&self) -> SemanticVersion { self.current_version } diff --git a/crates/bedrock/src/models.rs b/crates/bedrock/src/models.rs index ab0426bb7d0c28fd9b14028bd0b2c885a5310da0..8b8a9180efa216cdac110d1b32b3af854d47774d 100644 --- a/crates/bedrock/src/models.rs +++ b/crates/bedrock/src/models.rs @@ -357,7 +357,7 @@ impl Model { } } - pub fn max_token_count(&self) -> u64 { + pub const fn max_token_count(&self) -> u64 { match self { Self::Claude3_5SonnetV2 | Self::Claude3Opus @@ -421,7 +421,7 @@ impl Model { } } - pub fn supports_tool_use(&self) -> bool { + pub const fn supports_tool_use(&self) -> bool { match self { // Anthropic Claude 3 models (all support tool use) Self::Claude3Opus @@ -458,7 +458,7 @@ impl Model { } } - pub fn supports_caching(&self) -> bool { + pub const fn supports_caching(&self) -> bool { match self { // Only Claude models on Bedrock support caching // Nova models support only text caching @@ -514,7 +514,7 @@ impl Model { } } - pub fn mode(&self) -> BedrockModelMode { + pub const fn mode(&self) -> BedrockModelMode { match self { Model::Claude3_7SonnetThinking => BedrockModelMode::Thinking { budget_tokens: Some(4096), diff --git a/crates/buffer_diff/src/buffer_diff.rs b/crates/buffer_diff/src/buffer_diff.rs index 13479f6428b02d52f45415a989b694cc04ab5c25..98723f75a62a5581de8cb2422dcdac58b2960eee 100644 --- a/crates/buffer_diff/src/buffer_diff.rs +++ b/crates/buffer_diff/src/buffer_diff.rs @@ -284,7 +284,7 @@ impl BufferDiffSnapshot { self.inner.hunks_intersecting_range_rev(range, buffer) } - pub fn base_text(&self) -> &language::BufferSnapshot { + pub const fn base_text(&self) -> &language::BufferSnapshot { &self.inner.base_text } @@ -1098,11 +1098,11 @@ impl BufferDiff { changed_range } - pub fn base_text(&self) -> &language::BufferSnapshot { + pub const fn base_text(&self) -> &language::BufferSnapshot { &self.inner.base_text } - pub fn base_text_exists(&self) -> bool { + pub const fn base_text_exists(&self) -> bool { self.inner.base_text_exists } @@ -1248,7 +1248,7 @@ impl DiffHunk { } impl DiffHunkStatus { - pub fn has_secondary_hunk(&self) -> bool { + pub const fn has_secondary_hunk(&self) -> bool { matches!( self.secondary, DiffHunkSecondaryStatus::HasSecondaryHunk @@ -1257,7 +1257,7 @@ impl DiffHunkStatus { ) } - pub fn is_pending(&self) -> bool { + pub const fn is_pending(&self) -> bool { matches!( self.secondary, DiffHunkSecondaryStatus::SecondaryHunkAdditionPending @@ -1277,42 +1277,42 @@ impl DiffHunkStatus { self.kind == DiffHunkStatusKind::Modified } - pub fn added(secondary: DiffHunkSecondaryStatus) -> Self { + pub const fn added(secondary: DiffHunkSecondaryStatus) -> Self { Self { kind: DiffHunkStatusKind::Added, secondary, } } - pub fn modified(secondary: DiffHunkSecondaryStatus) -> Self { + pub const fn modified(secondary: DiffHunkSecondaryStatus) -> Self { Self { kind: DiffHunkStatusKind::Modified, secondary, } } - pub fn deleted(secondary: DiffHunkSecondaryStatus) -> Self { + pub const fn deleted(secondary: DiffHunkSecondaryStatus) -> Self { Self { kind: DiffHunkStatusKind::Deleted, secondary, } } - pub fn deleted_none() -> Self { + pub const fn deleted_none() -> Self { Self { kind: DiffHunkStatusKind::Deleted, secondary: DiffHunkSecondaryStatus::NoSecondaryHunk, } } - pub fn added_none() -> Self { + pub const fn added_none() -> Self { Self { kind: DiffHunkStatusKind::Added, secondary: DiffHunkSecondaryStatus::NoSecondaryHunk, } } - pub fn modified_none() -> Self { + pub const fn modified_none() -> Self { Self { kind: DiffHunkStatusKind::Modified, secondary: DiffHunkSecondaryStatus::NoSecondaryHunk, diff --git a/crates/call/src/call_impl/mod.rs b/crates/call/src/call_impl/mod.rs index 156a80faba61d2a4946bafa5943c167284d14a97..b09436df50cf1ebfbe0ff9ef0087678ee50bd1bb 100644 --- a/crates/call/src/call_impl/mod.rs +++ b/crates/call/src/call_impl/mod.rs @@ -404,7 +404,7 @@ impl ActiveCall { room.update(cx, |room, cx| room.unshare_project(project, cx)) } - pub fn location(&self) -> Option<&WeakEntity> { + pub const fn location(&self) -> Option<&WeakEntity> { self.location.as_ref() } @@ -466,7 +466,7 @@ impl ActiveCall { self.client.clone() } - pub fn pending_invites(&self) -> &HashSet { + pub const fn pending_invites(&self) -> &HashSet { &self.pending_invites } diff --git a/crates/call/src/call_impl/participant.rs b/crates/call/src/call_impl/participant.rs index 6fb6a2eb79b537aa9d7296a323f7d45221a4b05d..9def8a925c9e25f58cfe17e6f01c43119c54ae80 100644 --- a/crates/call/src/call_impl/participant.rs +++ b/crates/call/src/call_impl/participant.rs @@ -41,7 +41,7 @@ pub struct LocalParticipant { } impl LocalParticipant { - pub fn can_write(&self) -> bool { + pub const fn can_write(&self) -> bool { matches!( self.role, proto::ChannelRole::Admin | proto::ChannelRole::Member @@ -67,7 +67,7 @@ impl RemoteParticipant { !self.video_tracks.is_empty() } - pub fn can_write(&self) -> bool { + pub const fn can_write(&self) -> bool { matches!( self.role, proto::ChannelRole::Admin | proto::ChannelRole::Member diff --git a/crates/call/src/call_impl/room.rs b/crates/call/src/call_impl/room.rs index e659d1cf05b228423796d4c48906d568d71770d9..553f68b7110aa5052c9e5ff3afd5105411d7bf06 100644 --- a/crates/call/src/call_impl/room.rs +++ b/crates/call/src/call_impl/room.rs @@ -92,7 +92,7 @@ pub struct Room { impl EventEmitter for Room {} impl Room { - pub fn channel_id(&self) -> Option { + pub const fn channel_id(&self) -> Option { self.channel_id } @@ -520,15 +520,15 @@ impl Room { }) } - pub fn id(&self) -> u64 { + pub const fn id(&self) -> u64 { self.id } - pub fn status(&self) -> RoomStatus { + pub const fn status(&self) -> RoomStatus { self.status } - pub fn local_participant(&self) -> &LocalParticipant { + pub const fn local_participant(&self) -> &LocalParticipant { &self.local_participant } @@ -536,7 +536,7 @@ impl Room { self.user_store.read(cx).current_user() } - pub fn remote_participants(&self) -> &BTreeMap { + pub const fn remote_participants(&self) -> &BTreeMap { &self.remote_participants } @@ -1304,7 +1304,7 @@ impl Room { self.live_kit.as_ref().map(|live_kit| live_kit.deafened) } - pub fn can_use_microphone(&self) -> bool { + pub const fn can_use_microphone(&self) -> bool { use proto::ChannelRole::*; match self.local_participant.role { @@ -1313,7 +1313,7 @@ impl Room { } } - pub fn can_share_projects(&self) -> bool { + pub const fn can_share_projects(&self) -> bool { use proto::ChannelRole::*; match self.local_participant.role { Admin | Member => true, @@ -1708,11 +1708,11 @@ pub enum RoomStatus { } impl RoomStatus { - pub fn is_offline(&self) -> bool { + pub const fn is_offline(&self) -> bool { matches!(self, RoomStatus::Offline) } - pub fn is_online(&self) -> bool { + pub const fn is_online(&self) -> bool { matches!(self, RoomStatus::Online) } } diff --git a/crates/channel/src/channel_buffer.rs b/crates/channel/src/channel_buffer.rs index 828248b330b6ef6cfe0e13eab426de2900d364b2..e582a3dfe56f2e09f923963153c527cc6480b295 100644 --- a/crates/channel/src/channel_buffer.rs +++ b/crates/channel/src/channel_buffer.rs @@ -119,7 +119,7 @@ impl ChannelBuffer { self.buffer.read(cx).remote_id() } - pub fn user_store(&self) -> &Entity { + pub const fn user_store(&self) -> &Entity { &self.user_store } @@ -234,7 +234,7 @@ impl ChannelBuffer { })); } - pub fn epoch(&self) -> u64 { + pub const fn epoch(&self) -> u64 { self.buffer_epoch } @@ -242,7 +242,7 @@ impl ChannelBuffer { self.buffer.clone() } - pub fn collaborators(&self) -> &HashMap { + pub const fn collaborators(&self) -> &HashMap { &self.collaborators } @@ -268,7 +268,7 @@ impl ChannelBuffer { cx.notify() } - pub fn is_connected(&self) -> bool { + pub const fn is_connected(&self) -> bool { self.connected } diff --git a/crates/channel/src/channel_store.rs b/crates/channel/src/channel_store.rs index e983d03e0d6758f681de9e4a3e6fd13dc7075b01..7cb96b39af578c2008bb0a2f90a955f7f9b22e76 100644 --- a/crates/channel/src/channel_store.rs +++ b/crates/channel/src/channel_store.rs @@ -85,7 +85,7 @@ impl Channel { .unwrap_or_default() } - pub fn is_root_channel(&self) -> bool { + pub const fn is_root_channel(&self) -> bool { self.parent_path.is_empty() } @@ -797,7 +797,7 @@ impl ChannelStore { } } - pub fn has_pending_channel_invite_response(&self, _: &Arc) -> bool { + pub const fn has_pending_channel_invite_response(&self, _: &Arc) -> bool { false } @@ -1114,7 +1114,7 @@ impl ChannelStore { } impl ChannelState { - fn set_role(&mut self, role: ChannelRole) { + const fn set_role(&mut self, role: ChannelRole) { self.role = Some(role); } diff --git a/crates/channel/src/channel_store/channel_index.rs b/crates/channel/src/channel_store/channel_index.rs index 749160f956de936ce5731c77269474d148801001..68ee227aad4cd1ec76472ce3d0e60d6083310b53 100644 --- a/crates/channel/src/channel_store/channel_index.rs +++ b/crates/channel/src/channel_store/channel_index.rs @@ -11,7 +11,7 @@ pub struct ChannelIndex { } impl ChannelIndex { - pub fn by_id(&self) -> &BTreeMap> { + pub const fn by_id(&self) -> &BTreeMap> { &self.channels_by_id } @@ -32,7 +32,7 @@ impl ChannelIndex { .retain(|channel_id| !channels.contains(channel_id)); } - pub fn bulk_insert(&mut self) -> ChannelPathsInsertGuard<'_> { + pub const fn bulk_insert(&mut self) -> ChannelPathsInsertGuard<'_> { ChannelPathsInsertGuard { channels_ordered: &mut self.channels_ordered, channels_by_id: &mut self.channels_by_id, diff --git a/crates/client/src/client.rs b/crates/client/src/client.rs index 5aff87155f3a0328aa017060604b5fc79604731e..62c5266fc8be8e86873d717e1a1aaf7996d3fc7c 100644 --- a/crates/client/src/client.rs +++ b/crates/client/src/client.rs @@ -283,11 +283,11 @@ pub enum Status { } impl Status { - pub fn is_connected(&self) -> bool { + pub const fn is_connected(&self) -> bool { matches!(self, Self::Connected { .. }) } - pub fn was_connected(&self) -> bool { + pub const fn was_connected(&self) -> bool { matches!( self, Self::ConnectionLost @@ -298,18 +298,18 @@ impl Status { } /// Returns whether the client is currently connected or was connected at some point. - pub fn is_or_was_connected(&self) -> bool { + pub const fn is_or_was_connected(&self) -> bool { self.is_connected() || self.was_connected() } - pub fn is_signing_in(&self) -> bool { + pub const fn is_signing_in(&self) -> bool { matches!( self, Self::Authenticating | Self::Reauthenticating | Self::Connecting | Self::Reconnecting ) } - pub fn is_signed_out(&self) -> bool { + pub const fn is_signed_out(&self) -> bool { matches!(self, Self::SignedOut | Self::UpgradeRequired) } } @@ -1692,7 +1692,7 @@ impl Client { .ok(); } - pub fn telemetry(&self) -> &Arc { + pub const fn telemetry(&self) -> &Arc { &self.telemetry } } diff --git a/crates/client/src/user.rs b/crates/client/src/user.rs index de0668b406c512eabfc70f4702466f013eb8c515..fc23dba51993e1f00af2e80606f39fb56e4ba80a 100644 --- a/crates/client/src/user.rs +++ b/crates/client/src/user.rs @@ -42,7 +42,7 @@ impl std::fmt::Display for ChannelId { pub struct ProjectId(pub u64); impl ProjectId { - pub fn to_proto(self) -> u64 { + pub const fn to_proto(self) -> u64 { self.0 } } @@ -320,7 +320,7 @@ impl UserStore { Ok(()) } - pub fn invite_info(&self) -> Option<&InviteInfo> { + pub const fn invite_info(&self) -> Option<&InviteInfo> { self.invite_info.as_ref() } @@ -766,7 +766,7 @@ impl UserStore { cx.notify(); } - pub fn edit_prediction_usage(&self) -> Option { + pub const fn edit_prediction_usage(&self) -> Option { self.edit_prediction_usage } @@ -879,7 +879,7 @@ impl UserStore { } } - pub fn participant_indices(&self) -> &HashMap { + pub const fn participant_indices(&self) -> &HashMap { &self.participant_indices } @@ -953,7 +953,7 @@ impl Collaborator { } impl RequestUsage { - pub fn over_limit(&self) -> bool { + pub const fn over_limit(&self) -> bool { match self.limit { UsageLimit::Limited(limit) => self.amount >= limit, UsageLimit::Unlimited => false, diff --git a/crates/clock/src/clock.rs b/crates/clock/src/clock.rs index 64645c9b46f68416c6792b17258baf8e49ca9585..bee465d5b1176792dd54869c241702772f4cb03f 100644 --- a/crates/clock/src/clock.rs +++ b/crates/clock/src/clock.rs @@ -182,18 +182,18 @@ impl Lamport { value: Seq::MAX, }; - pub fn new(replica_id: ReplicaId) -> Self { + pub const fn new(replica_id: ReplicaId) -> Self { Self { value: 1, replica_id, } } - pub fn as_u64(self) -> u64 { + pub const fn as_u64(self) -> u64 { ((self.value as u64) << 32) | (self.replica_id as u64) } - pub fn tick(&mut self) -> Self { + pub const fn tick(&mut self) -> Self { let timestamp = *self; self.value += 1; timestamp diff --git a/crates/cloud_api_client/src/cloud_api_client.rs b/crates/cloud_api_client/src/cloud_api_client.rs index 53b2b16a6a7c9447face6daa199bc4b2125445b9..cd4c1e768f7dd65931bfd7223c31a8dbd990138f 100644 --- a/crates/cloud_api_client/src/cloud_api_client.rs +++ b/crates/cloud_api_client/src/cloud_api_client.rs @@ -26,7 +26,7 @@ pub struct CloudApiClient { } impl CloudApiClient { - pub fn new(http_client: Arc) -> Self { + pub const fn new(http_client: Arc) -> Self { Self { credentials: RwLock::new(None), http_client, diff --git a/crates/cloud_api_types/src/timestamp.rs b/crates/cloud_api_types/src/timestamp.rs index 1f055d58ef42a856ee9cbf5c2effd2edeaa7c850..3dd3db16aa050877722eb8140f52b93a162ff90d 100644 --- a/crates/cloud_api_types/src/timestamp.rs +++ b/crates/cloud_api_types/src/timestamp.rs @@ -6,7 +6,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer}; pub struct Timestamp(pub DateTime); impl Timestamp { - pub fn new(datetime: DateTime) -> Self { + pub const fn new(datetime: DateTime) -> Self { Self(datetime) } } diff --git a/crates/cloud_llm_client/src/cloud_llm_client.rs b/crates/cloud_llm_client/src/cloud_llm_client.rs index bb77c3a5b7f8009093cbf7bc427160ed535e6c62..9013772596dac45b4f960b2b4aec723a91b17c34 100644 --- a/crates/cloud_llm_client/src/cloud_llm_client.rs +++ b/crates/cloud_llm_client/src/cloud_llm_client.rs @@ -86,7 +86,7 @@ pub enum Plan { } impl Plan { - pub fn is_v2(&self) -> bool { + pub const fn is_v2(&self) -> bool { matches!(self, Self::V2(_)) } } diff --git a/crates/cloud_zeta2_prompt/src/cloud_zeta2_prompt.rs b/crates/cloud_zeta2_prompt/src/cloud_zeta2_prompt.rs index 284b245acf2305350e6a6a5e7c38dfaa9b16c5d4..2a4ba8de0cd6295480f563c249bcbc01719b8836 100644 --- a/crates/cloud_zeta2_prompt/src/cloud_zeta2_prompt.rs +++ b/crates/cloud_zeta2_prompt/src/cloud_zeta2_prompt.rs @@ -625,7 +625,7 @@ fn declaration_score_density(declaration: &ReferencedDeclaration, style: Declara declaration_score(declaration, style) / declaration_size(declaration, style) as f32 } -fn declaration_score(declaration: &ReferencedDeclaration, style: DeclarationStyle) -> f32 { +const fn declaration_score(declaration: &ReferencedDeclaration, style: DeclarationStyle) -> f32 { match style { DeclarationStyle::Signature => declaration.signature_score, DeclarationStyle::Declaration => declaration.declaration_score, diff --git a/crates/collab/src/db.rs b/crates/collab/src/db.rs index 1152cb97d79ef2c7df437479d79b28a5ca6d2ef7..23d8ff1d222ef4607de2c898fa1449dd7b91f9be 100644 --- a/crates/collab/src/db.rs +++ b/crates/collab/src/db.rs @@ -84,7 +84,7 @@ impl Database { }) } - pub fn options(&self) -> &ConnectOptions { + pub const fn options(&self) -> &ConnectOptions { &self.options } @@ -319,7 +319,7 @@ pub enum Contact { } impl Contact { - pub fn user_id(&self) -> UserId { + pub const fn user_id(&self) -> UserId { match self { Contact::Accepted { user_id, .. } => *user_id, Contact::Outgoing { user_id } => *user_id, @@ -675,7 +675,7 @@ pub struct ExtensionVersionConstraints { } impl LocalSettingsKind { - pub fn from_proto(proto_kind: proto::LocalSettingsKind) -> Self { + pub const fn from_proto(proto_kind: proto::LocalSettingsKind) -> Self { match proto_kind { proto::LocalSettingsKind::Settings => Self::Settings, proto::LocalSettingsKind::Tasks => Self::Tasks, @@ -684,7 +684,7 @@ impl LocalSettingsKind { } } - pub fn to_proto(self) -> proto::LocalSettingsKind { + pub const fn to_proto(self) -> proto::LocalSettingsKind { match self { Self::Settings => proto::LocalSettingsKind::Settings, Self::Tasks => proto::LocalSettingsKind::Tasks, diff --git a/crates/collab/src/db/ids.rs b/crates/collab/src/db/ids.rs index 8f116cfd633749b21ff197a723f9e779a750b561..893753b8f3722f096eeff93b09badeefa83f8415 100644 --- a/crates/collab/src/db/ids.rs +++ b/crates/collab/src/db/ids.rs @@ -38,7 +38,7 @@ macro_rules! id_type { #[allow(unused)] #[allow(missing_docs)] - pub fn to_proto(self) -> u64 { + pub const fn to_proto(self) -> u64 { self.0 as u64 } } @@ -120,7 +120,7 @@ pub enum ChannelRole { impl ChannelRole { /// Returns true if this role is more powerful than the other role. - pub fn should_override(&self, other: Self) -> bool { + pub const fn should_override(&self, other: Self) -> bool { use ChannelRole::*; match self { Admin => matches!(other, Member | Banned | Talker | Guest), @@ -132,7 +132,7 @@ impl ChannelRole { } /// Returns the maximal role between the two - pub fn max(&self, other: Self) -> Self { + pub const fn max(&self, other: Self) -> Self { if self.should_override(other) { *self } else { @@ -150,7 +150,7 @@ impl ChannelRole { } /// True if the role allows access to all descendant channels - pub fn can_see_all_descendants(&self) -> bool { + pub const fn can_see_all_descendants(&self) -> bool { use ChannelRole::*; match self { Admin | Member => true, @@ -159,7 +159,7 @@ impl ChannelRole { } /// True if the role only allows access to public descendant channels - pub fn can_only_see_public_descendants(&self) -> bool { + pub const fn can_only_see_public_descendants(&self) -> bool { use ChannelRole::*; match self { Guest | Talker => true, @@ -168,7 +168,7 @@ impl ChannelRole { } /// True if the role can share screen/microphone/projects into rooms. - pub fn can_use_microphone(&self) -> bool { + pub const fn can_use_microphone(&self) -> bool { use ChannelRole::*; match self { Admin | Member | Talker => true, @@ -177,7 +177,7 @@ impl ChannelRole { } /// True if the role can edit shared projects. - pub fn can_edit_projects(&self) -> bool { + pub const fn can_edit_projects(&self) -> bool { use ChannelRole::*; match self { Admin | Member => true, @@ -186,7 +186,7 @@ impl ChannelRole { } /// True if the role can read shared projects. - pub fn can_read_projects(&self) -> bool { + pub const fn can_read_projects(&self) -> bool { use ChannelRole::*; match self { Admin | Member | Guest | Talker => true, @@ -194,7 +194,7 @@ impl ChannelRole { } } - pub fn requires_cla(&self) -> bool { + pub const fn requires_cla(&self) -> bool { use ChannelRole::*; match self { Admin | Member => true, diff --git a/crates/collab/src/db/queries/extensions.rs b/crates/collab/src/db/queries/extensions.rs index 914e78c6e3c327bf7f37a465771add478b3c68f5..f9b58955528a20fe13c4a7f6634c03c636945dcc 100644 --- a/crates/collab/src/db/queries/extensions.rs +++ b/crates/collab/src/db/queries/extensions.rs @@ -469,7 +469,7 @@ fn metadata_from_extension_and_version( } } -pub fn convert_time_to_chrono(time: time::PrimitiveDateTime) -> chrono::DateTime { +pub const fn convert_time_to_chrono(time: time::PrimitiveDateTime) -> chrono::DateTime { chrono::DateTime::from_naive_utc_and_offset( #[allow(deprecated)] chrono::NaiveDateTime::from_timestamp_opt(time.assume_utc().unix_timestamp(), 0).unwrap(), diff --git a/crates/collab/src/db/tables/channel.rs b/crates/collab/src/db/tables/channel.rs index cd3b867e139b4050bb982c47c50f4e136dcfa6e2..d772e064f443bf491e44b1c87528a0a02dc58764 100644 --- a/crates/collab/src/db/tables/channel.rs +++ b/crates/collab/src/db/tables/channel.rs @@ -20,7 +20,7 @@ impl Model { self.ancestors().last() } - pub fn is_root(&self) -> bool { + pub const fn is_root(&self) -> bool { self.parent_path.is_empty() } diff --git a/crates/collab/src/db/tables/channel_buffer_collaborator.rs b/crates/collab/src/db/tables/channel_buffer_collaborator.rs index ac2637b36e3129d1c4582c869db398088b9055d9..f14c935dafcf83db31c0c0a7baca17dd40c2a9c3 100644 --- a/crates/collab/src/db/tables/channel_buffer_collaborator.rs +++ b/crates/collab/src/db/tables/channel_buffer_collaborator.rs @@ -16,7 +16,7 @@ pub struct Model { } impl Model { - pub fn connection(&self) -> ConnectionId { + pub const fn connection(&self) -> ConnectionId { ConnectionId { owner_id: self.connection_server_id.0 as u32, id: self.connection_id as u32, diff --git a/crates/collab/src/db/tables/channel_chat_participant.rs b/crates/collab/src/db/tables/channel_chat_participant.rs index f3ef36c289f86e5f20411cf9b3f442698f6a4024..17c5209b59be607e50d974fa74d27057fe0cbffe 100644 --- a/crates/collab/src/db/tables/channel_chat_participant.rs +++ b/crates/collab/src/db/tables/channel_chat_participant.rs @@ -14,7 +14,7 @@ pub struct Model { } impl Model { - pub fn connection(&self) -> ConnectionId { + pub const fn connection(&self) -> ConnectionId { ConnectionId { owner_id: self.connection_server_id.0 as u32, id: self.connection_id as u32, diff --git a/crates/collab/src/db/tables/follower.rs b/crates/collab/src/db/tables/follower.rs index ffd45434e9006d09939a369a3010cc85393f7dde..fa5a7f055b40b2feb3655cc9665d97e295411334 100644 --- a/crates/collab/src/db/tables/follower.rs +++ b/crates/collab/src/db/tables/follower.rs @@ -16,14 +16,14 @@ pub struct Model { } impl Model { - pub fn leader_connection(&self) -> ConnectionId { + pub const fn leader_connection(&self) -> ConnectionId { ConnectionId { owner_id: self.leader_connection_server_id.0 as u32, id: self.leader_connection_id as u32, } } - pub fn follower_connection(&self) -> ConnectionId { + pub const fn follower_connection(&self) -> ConnectionId { ConnectionId { owner_id: self.follower_connection_server_id.0 as u32, id: self.follower_connection_id as u32, diff --git a/crates/collab/src/db/tables/project_collaborator.rs b/crates/collab/src/db/tables/project_collaborator.rs index 1564abdf4680d3b268572213392eb0a975b0446c..ddb65340f08aabc31eb58fbcf0a25a89c0cdf5ec 100644 --- a/crates/collab/src/db/tables/project_collaborator.rs +++ b/crates/collab/src/db/tables/project_collaborator.rs @@ -18,7 +18,7 @@ pub struct Model { } impl Model { - pub fn connection(&self) -> ConnectionId { + pub const fn connection(&self) -> ConnectionId { ConnectionId { owner_id: self.connection_server_id.0 as u32, id: self.connection_id as u32, diff --git a/crates/collab/src/lib.rs b/crates/collab/src/lib.rs index 14573e94b0b535b1644510e28dfc906b1a2c420e..828b6483862715ad651ae269696eadb72d384ea7 100644 --- a/crates/collab/src/lib.rs +++ b/crates/collab/src/lib.rs @@ -225,11 +225,11 @@ pub enum ServiceMode { } impl ServiceMode { - pub fn is_collab(&self) -> bool { + pub const fn is_collab(&self) -> bool { matches!(self, Self::Collab | Self::All) } - pub fn is_api(&self) -> bool { + pub const fn is_api(&self) -> bool { matches!(self, Self::Api | Self::All) } } diff --git a/crates/collab/src/llm/db.rs b/crates/collab/src/llm/db.rs index b15d5a42b5f183831b34552beba3f616d3a7c3f0..8589b611ab6935a8d96e35b7d48ba521f0cd37b6 100644 --- a/crates/collab/src/llm/db.rs +++ b/crates/collab/src/llm/db.rs @@ -32,7 +32,7 @@ impl LlmDatabase { }) } - pub fn options(&self) -> &ConnectOptions { + pub const fn options(&self) -> &ConnectOptions { &self.options } diff --git a/crates/collab/src/rpc.rs b/crates/collab/src/rpc.rs index fa2ca6a890af93979eed759265286d99a5a98bb2..e14c0c61272217e5ba72c071c5b4bcc6d24419ae 100644 --- a/crates/collab/src/rpc.rs +++ b/crates/collab/src/rpc.rs @@ -224,14 +224,14 @@ impl Session { } } - fn is_staff(&self) -> bool { + const fn is_staff(&self) -> bool { match &self.principal { Principal::User(user) => user.admin, Principal::Impersonated { .. } => true, } } - fn user_id(&self) -> UserId { + const fn user_id(&self) -> UserId { match &self.principal { Principal::User(user) => user.id, Principal::Impersonated { user, .. } => user.id, @@ -2809,7 +2809,7 @@ async fn remove_contact( Ok(()) } -fn should_auto_subscribe_to_channels(version: ZedVersion) -> bool { +const fn should_auto_subscribe_to_channels(version: ZedVersion) -> bool { version.0.minor() < 139 } diff --git a/crates/collab_ui/src/collab_panel.rs b/crates/collab_ui/src/collab_panel.rs index e9c9c4b0fae49fc97c30bdc7697460f82043750e..e3b4ee378e27d55460d7a1d100caeb3a11b0bfe9 100644 --- a/crates/collab_ui/src/collab_panel.rs +++ b/crates/collab_ui/src/collab_panel.rs @@ -1871,7 +1871,7 @@ impl CollabPanel { }); } - fn start_move_channel( + const fn start_move_channel( &mut self, channel_id: ChannelId, _window: &mut Window, diff --git a/crates/collab_ui/src/notifications/incoming_call_notification.rs b/crates/collab_ui/src/notifications/incoming_call_notification.rs index 0bf71ce61439f17135b7ef2ebc651a36d985e342..c4a854507f31e9219450ffc72297390718b379ae 100644 --- a/crates/collab_ui/src/notifications/incoming_call_notification.rs +++ b/crates/collab_ui/src/notifications/incoming_call_notification.rs @@ -63,7 +63,7 @@ pub struct IncomingCallNotification { state: Arc, } impl IncomingCallNotificationState { - pub fn new(call: IncomingCall, app_state: Weak) -> Self { + pub const fn new(call: IncomingCall, app_state: Weak) -> Self { Self { call, app_state } } diff --git a/crates/collab_ui/src/notifications/project_shared_notification.rs b/crates/collab_ui/src/notifications/project_shared_notification.rs index b21a2dfcb7a73c2e8a483097f9589cc6626fd2ca..a8d6971699f0378025b4f1619f3fc3c7f5c296bf 100644 --- a/crates/collab_ui/src/notifications/project_shared_notification.rs +++ b/crates/collab_ui/src/notifications/project_shared_notification.rs @@ -87,7 +87,7 @@ pub struct ProjectSharedNotification { } impl ProjectSharedNotification { - fn new( + const fn new( owner: Arc, project_id: u64, worktree_root_names: Vec, diff --git a/crates/component/src/component.rs b/crates/component/src/component.rs index 8c7b7ea4d7347ff087c84880c31df5d355870f65..b2d030653e5cd42754fb1fa2421b0989175c23bc 100644 --- a/crates/component/src/component.rs +++ b/crates/component/src/component.rs @@ -283,7 +283,7 @@ pub enum ComponentStatus { } impl ComponentStatus { - pub fn description(&self) -> &str { + pub const fn description(&self) -> &str { match self { ComponentStatus::WorkInProgress => { "These components are still being designed or refined. They shouldn't be used in the app yet." diff --git a/crates/component/src/component_layout.rs b/crates/component/src/component_layout.rs index a840d520a62b57516f20c190f2a5148505ccfed4..1d2f27f09d90d61825a55e5bfa8f6b44995cb576 100644 --- a/crates/component/src/component_layout.rs +++ b/crates/component/src/component_layout.rs @@ -83,7 +83,7 @@ impl ComponentExample { self } - pub fn width(mut self, width: Pixels) -> Self { + pub const fn width(mut self, width: Pixels) -> Self { self.width = Some(width); self } @@ -150,7 +150,7 @@ impl RenderOnce for ComponentExampleGroup { } impl ComponentExampleGroup { - pub fn new(examples: Vec) -> Self { + pub const fn new(examples: Vec) -> Self { Self { title: None, examples, @@ -168,15 +168,15 @@ impl ComponentExampleGroup { vertical: false, } } - pub fn width(mut self, width: Pixels) -> Self { + pub const fn width(mut self, width: Pixels) -> Self { self.width = Some(width); self } - pub fn grow(mut self) -> Self { + pub const fn grow(mut self) -> Self { self.grow = true; self } - pub fn vertical(mut self) -> Self { + pub const fn vertical(mut self) -> Self { self.vertical = true; self } @@ -193,7 +193,7 @@ pub fn empty_example(variant_name: impl Into) -> ComponentExample ComponentExample::new(variant_name, div().w_full().text_center().items_center().text_xs().opacity(0.4).child("This space is intentionally left blank. It indicates a case that should render nothing.").into_any_element()) } -pub fn example_group(examples: Vec) -> ComponentExampleGroup { +pub const fn example_group(examples: Vec) -> ComponentExampleGroup { ComponentExampleGroup::new(examples) } diff --git a/crates/context_server/src/protocol.rs b/crates/context_server/src/protocol.rs index 5355f20f620b5bed76bf945e863fdb5cbcc2ff43..41a20fba5968adc1f65a5feb6d456efcf4912384 100644 --- a/crates/context_server/src/protocol.rs +++ b/crates/context_server/src/protocol.rs @@ -20,7 +20,7 @@ pub struct ModelContextProtocol { } impl ModelContextProtocol { - pub(crate) fn new(inner: Client) -> Self { + pub(crate) const fn new(inner: Client) -> Self { Self { inner } } @@ -86,7 +86,7 @@ pub enum ServerCapability { impl InitializedContextServerProtocol { /// Check if the server supports a specific capability - pub fn capable(&self, capability: ServerCapability) -> bool { + pub const fn capable(&self, capability: ServerCapability) -> bool { match capability { ServerCapability::Experimental => self.initialize.capabilities.experimental.is_some(), ServerCapability::Logging => self.initialize.capabilities.logging.is_some(), diff --git a/crates/context_server/src/types.rs b/crates/context_server/src/types.rs index 03aca4f3caf7995091bbc8e049494b324674a9d3..a7a6fa71d71a629a055cddd5b8ac8a5e90821538 100644 --- a/crates/context_server/src/types.rs +++ b/crates/context_server/src/types.rs @@ -660,7 +660,7 @@ pub enum CompletionTotal { } impl CompletionTotal { - pub fn from_options(has_more: Option, total: Option) -> Self { + pub const fn from_options(has_more: Option, total: Option) -> Self { match (has_more, total) { (_, Some(count)) => CompletionTotal::Exact(count), (Some(true), _) => CompletionTotal::HasMore, diff --git a/crates/copilot/src/copilot.rs b/crates/copilot/src/copilot.rs index d8fa8967a862053ccf2a820878f450c38ea18fad..c02f09a8dbab7ff9ac22f32b061b2c1ee73f85b0 100644 --- a/crates/copilot/src/copilot.rs +++ b/crates/copilot/src/copilot.rs @@ -183,11 +183,11 @@ pub enum Status { } impl Status { - pub fn is_authorized(&self) -> bool { + pub const fn is_authorized(&self) -> bool { matches!(self, Status::Authorized) } - pub fn is_configured(&self) -> bool { + pub const fn is_configured(&self) -> bool { matches!( self, Status::Starting { .. } @@ -712,7 +712,7 @@ impl Copilot { start_task } - pub fn language_server(&self) -> Option<&Arc> { + pub const fn language_server(&self) -> Option<&Arc> { if let CopilotServer::Running(server) = &self.server { Some(&server.lsp) } else { diff --git a/crates/copilot/src/copilot_chat.rs b/crates/copilot/src/copilot_chat.rs index a6758ce53c0aa18d04dcd376c2e0afb93add6ab5..8a21ca744d3e883a3db8f866c95ff189c9c14dd2 100644 --- a/crates/copilot/src/copilot_chat.rs +++ b/crates/copilot/src/copilot_chat.rs @@ -189,35 +189,35 @@ pub struct ImageUrl { } impl Model { - pub fn uses_streaming(&self) -> bool { + pub const fn uses_streaming(&self) -> bool { self.capabilities.supports.streaming } - pub fn id(&self) -> &str { + pub const fn id(&self) -> &str { self.id.as_str() } - pub fn display_name(&self) -> &str { + pub const fn display_name(&self) -> &str { self.name.as_str() } - pub fn max_token_count(&self) -> u64 { + pub const fn max_token_count(&self) -> u64 { self.capabilities.limits.max_prompt_tokens } - pub fn supports_tools(&self) -> bool { + pub const fn supports_tools(&self) -> bool { self.capabilities.supports.tool_calls } - pub fn vendor(&self) -> ModelVendor { + pub const fn vendor(&self) -> ModelVendor { self.vendor } - pub fn supports_vision(&self) -> bool { + pub const fn supports_vision(&self) -> bool { self.capabilities.supports.vision } - pub fn supports_parallel_tool_calls(&self) -> bool { + pub const fn supports_parallel_tool_calls(&self) -> bool { self.capabilities.supports.parallel_tool_calls } @@ -289,7 +289,7 @@ pub enum ChatMessageContent { } impl ChatMessageContent { - pub fn empty() -> Self { + pub const fn empty() -> Self { ChatMessageContent::Multipart(vec![]) } } @@ -541,7 +541,7 @@ impl CopilotChat { anyhow::Ok(()) } - pub fn is_authenticated(&self) -> bool { + pub const fn is_authenticated(&self) -> bool { self.oauth_token.is_some() } diff --git a/crates/copilot/src/copilot_completion_provider.rs b/crates/copilot/src/copilot_completion_provider.rs index 6027c081ccef31bfdeb83cb944dcba861bc95da8..6adfff90dffccd00a3f1d71405f81894bee7b8b8 100644 --- a/crates/copilot/src/copilot_completion_provider.rs +++ b/crates/copilot/src/copilot_completion_provider.rs @@ -20,7 +20,7 @@ pub struct CopilotCompletionProvider { } impl CopilotCompletionProvider { - pub fn new(copilot: Entity) -> Self { + pub const fn new(copilot: Entity) -> Self { Self { cycled: false, buffer_id: None, diff --git a/crates/dap/src/client.rs b/crates/dap/src/client.rs index 15801e989169677f6e42bdd7b9c5642d82ea644a..171a154857178d8ef503eaabd65383bedb3b3144 100644 --- a/crates/dap/src/client.rs +++ b/crates/dap/src/client.rs @@ -19,11 +19,11 @@ use std::{ pub struct SessionId(pub u32); impl SessionId { - pub fn from_proto(client_id: u64) -> Self { + pub const fn from_proto(client_id: u64) -> Self { Self(client_id as u32) } - pub fn to_proto(self) -> u64 { + pub const fn to_proto(self) -> u64 { self.0 as u64 } } @@ -155,11 +155,11 @@ impl DebugAdapterClient { self.transport_delegate.send_message(message).await } - pub fn id(&self) -> SessionId { + pub const fn id(&self) -> SessionId { self.id } - pub fn binary(&self) -> &DebugAdapterBinary { + pub const fn binary(&self) -> &DebugAdapterBinary { &self.binary } diff --git a/crates/dap/src/debugger_settings.rs b/crates/dap/src/debugger_settings.rs index dc38c9a0616ff8d37bdfd33f269a4fec9a6395b2..6e4a06ffecd83bc877f168324c4869ddb18c522a 100644 --- a/crates/dap/src/debugger_settings.rs +++ b/crates/dap/src/debugger_settings.rs @@ -49,7 +49,7 @@ impl Settings for DebuggerSettings { } } -fn dap_granularity_from_settings( +const fn dap_granularity_from_settings( granularity: settings::SteppingGranularity, ) -> dap_types::SteppingGranularity { match granularity { diff --git a/crates/debugger_tools/src/dap_log.rs b/crates/debugger_tools/src/dap_log.rs index 4c994ad7eb749dcb5828daa83bad34a579f9f14c..1b59826864255076a501737ffdd00e53877c996d 100644 --- a/crates/debugger_tools/src/dap_log.rs +++ b/crates/debugger_tools/src/dap_log.rs @@ -120,7 +120,7 @@ enum MessageKind { } impl MessageKind { - fn label(&self) -> &'static str { + const fn label(&self) -> &'static str { match self { Self::Send => SEND, Self::Receive => RECEIVE, @@ -495,7 +495,7 @@ pub struct DapLogToolbarItemView { } impl DapLogToolbarItemView { - pub fn new() -> Self { + pub const fn new() -> Self { Self { log_view: None } } } diff --git a/crates/debugger_ui/src/debugger_panel.rs b/crates/debugger_ui/src/debugger_panel.rs index 093cef3630e3ae3627a2999b9deb81be3b0aeb8d..284b226e92aa8e19cafa33d30d8c9ad7dc994068 100644 --- a/crates/debugger_ui/src/debugger_panel.rs +++ b/crates/debugger_ui/src/debugger_panel.rs @@ -135,7 +135,7 @@ impl DebugPanel { .map(|session| session.read(cx).running_state().clone()) } - pub fn project(&self) -> &Entity { + pub const fn project(&self) -> &Entity { &self.project } diff --git a/crates/debugger_ui/src/new_process_modal.rs b/crates/debugger_ui/src/new_process_modal.rs index 56c4a690325a0f5d8387fa76c1121206ff8f05fb..3311b5bcbdb51fb5a50ee2e498145a470673329c 100644 --- a/crates/debugger_ui/src/new_process_modal.rs +++ b/crates/debugger_ui/src/new_process_modal.rs @@ -964,7 +964,7 @@ impl AttachMode { attach_picker, }) } - pub(super) fn debug_request(&self) -> task::AttachRequest { + pub(super) const fn debug_request(&self) -> task::AttachRequest { task::AttachRequest { process_id: None } } } diff --git a/crates/debugger_ui/src/persistence.rs b/crates/debugger_ui/src/persistence.rs index ab68fea1154182fe266bb150d762f8be0995d733..e8f54c2a0b0ee95135f4d4ce1e5f5985ff9240fe 100644 --- a/crates/debugger_ui/src/persistence.rs +++ b/crates/debugger_ui/src/persistence.rs @@ -55,7 +55,7 @@ impl DebuggerPaneItem { } } - pub(crate) fn to_shared_string(self) -> SharedString { + pub(crate) const fn to_shared_string(self) -> SharedString { match self { DebuggerPaneItem::Console => SharedString::new_static("Console"), DebuggerPaneItem::Variables => SharedString::new_static("Variables"), @@ -67,7 +67,7 @@ impl DebuggerPaneItem { DebuggerPaneItem::MemoryView => SharedString::new_static("Memory View"), } } - pub(crate) fn tab_tooltip(self) -> SharedString { + pub(crate) const fn tab_tooltip(self) -> SharedString { let tooltip = match self { DebuggerPaneItem::Console => { "Displays program output and allows manual input of debugger commands." diff --git a/crates/debugger_ui/src/session.rs b/crates/debugger_ui/src/session.rs index 40c9bd810f9c5c9691f51f3d38957a98c9f037a2..b145ad1165845142e4cf72cc8e58fe3e68d4df88 100644 --- a/crates/debugger_ui/src/session.rs +++ b/crates/debugger_ui/src/session.rs @@ -116,7 +116,7 @@ impl DebugSession { }) } - pub fn running_state(&self) -> &Entity { + pub const fn running_state(&self) -> &Entity { &self.running_state } } diff --git a/crates/debugger_ui/src/session/running.rs b/crates/debugger_ui/src/session/running.rs index 8f25ee7fa4cf1210ff72b577765481e1ab109cc0..d17d0f906a59983552fe9d1829432a90b3ad72d9 100644 --- a/crates/debugger_ui/src/session/running.rs +++ b/crates/debugger_ui/src/session/running.rs @@ -82,11 +82,11 @@ pub struct RunningState { } impl RunningState { - pub(crate) fn thread_id(&self) -> Option { + pub(crate) const fn thread_id(&self) -> Option { self.thread_id } - pub(crate) fn active_pane(&self) -> &Entity { + pub(crate) const fn active_pane(&self) -> &Entity { &self.active_pane } } @@ -217,7 +217,7 @@ impl SubView { this } - pub(crate) fn view_kind(&self) -> DebuggerPaneItem { + pub(crate) const fn view_kind(&self) -> DebuggerPaneItem { self.kind } pub(crate) fn with_indicator(&mut self, indicator: Box bool>) { @@ -1447,11 +1447,11 @@ impl RunningState { self.variable_list.read(cx).has_open_context_menu() } - pub fn session(&self) -> &Entity { + pub const fn session(&self) -> &Entity { &self.session } - pub fn session_id(&self) -> SessionId { + pub const fn session_id(&self) -> SessionId { self.session_id } @@ -1459,7 +1459,7 @@ impl RunningState { self.stack_frame_list.read(cx).opened_stack_frame_id() } - pub(crate) fn stack_frame_list(&self) -> &Entity { + pub(crate) const fn stack_frame_list(&self) -> &Entity { &self.stack_frame_list } @@ -1532,7 +1532,7 @@ impl RunningState { } } - pub fn selected_thread_id(&self) -> Option { + pub const fn selected_thread_id(&self) -> Option { self.thread_id } diff --git a/crates/debugger_ui/src/session/running/breakpoint_list.rs b/crates/debugger_ui/src/session/running/breakpoint_list.rs index cec906e293485f3ab7b3685f65834d2b143ef8e2..277059ef69ba2e00b37f272508ed0424c6077828 100644 --- a/crates/debugger_ui/src/session/running/breakpoint_list.rs +++ b/crates/debugger_ui/src/session/running/breakpoint_list.rs @@ -1214,7 +1214,7 @@ impl BreakpointEntry { } } - fn has_log(&self) -> bool { + const fn has_log(&self) -> bool { match &self.kind { BreakpointEntryKind::LineBreakpoint(line_breakpoint) => { line_breakpoint.breakpoint.message.is_some() @@ -1223,7 +1223,7 @@ impl BreakpointEntry { } } - fn has_condition(&self) -> bool { + const fn has_condition(&self) -> bool { match &self.kind { BreakpointEntryKind::LineBreakpoint(line_breakpoint) => { line_breakpoint.breakpoint.condition.is_some() @@ -1233,7 +1233,7 @@ impl BreakpointEntry { } } - fn has_hit_condition(&self) -> bool { + const fn has_hit_condition(&self) -> bool { match &self.kind { BreakpointEntryKind::LineBreakpoint(line_breakpoint) => { line_breakpoint.breakpoint.hit_condition.is_some() @@ -1278,11 +1278,11 @@ impl From<&Capabilities> for SupportedBreakpointProperties { } impl SupportedBreakpointProperties { - fn for_exception_breakpoints(self) -> Self { + const fn for_exception_breakpoints(self) -> Self { // TODO: we don't yet support conditions for exception breakpoints at the data layer, hence all props are disabled here. Self::empty() } - fn for_data_breakpoints(self) -> Self { + const fn for_data_breakpoints(self) -> Self { // TODO: we don't yet support conditions for data breakpoints at the data layer, hence all props are disabled here. Self::empty() } diff --git a/crates/debugger_ui/src/session/running/memory_view.rs b/crates/debugger_ui/src/session/running/memory_view.rs index bc6e90ed09a9c6ac519cca8345a0ffbb6459f249..631cb0a5d1a10ccfbe16d3dd2285cb5fba1cdff8 100644 --- a/crates/debugger_ui/src/session/running/memory_view.rs +++ b/crates/debugger_ui/src/session/running/memory_view.rs @@ -56,7 +56,7 @@ impl Drag { range.contains(&address) } - fn memory_range(&self) -> RangeInclusive { + const fn memory_range(&self) -> RangeInclusive { if self.start_address < self.end_address { self.start_address..=self.end_address } else { @@ -77,10 +77,10 @@ impl SelectedMemoryRange { SelectedMemoryRange::DragComplete(drag) => drag.contains(address), } } - fn is_dragging(&self) -> bool { + const fn is_dragging(&self) -> bool { matches!(self, SelectedMemoryRange::DragUnderway(_)) } - fn drag(&self) -> &Drag { + const fn drag(&self) -> &Drag { match self { SelectedMemoryRange::DragUnderway(drag) => drag, SelectedMemoryRange::DragComplete(drag) => drag, @@ -116,16 +116,16 @@ impl ViewState { selection: None, } } - fn row_count(&self) -> u64 { + const fn row_count(&self) -> u64 { // This was picked fully arbitrarily. There's no incentive for us to care about page sizes other than the fact that it seems to be a good // middle ground for data size. const PAGE_SIZE: u64 = 4096; PAGE_SIZE / self.line_width.width as u64 } - fn schedule_scroll_down(&mut self) { + const fn schedule_scroll_down(&mut self) { self.base_row = self.base_row.saturating_add(1) } - fn schedule_scroll_up(&mut self) { + const fn schedule_scroll_up(&mut self) { self.base_row = self.base_row.saturating_sub(1); } diff --git a/crates/debugger_ui/src/session/running/stack_frame_list.rs b/crates/debugger_ui/src/session/running/stack_frame_list.rs index 309b58e7de40f527e4ab96f8aacd668810aede64..1e29bb194c411317bc8b0770161fa6e8e6a7cbc9 100644 --- a/crates/debugger_ui/src/session/running/stack_frame_list.rs +++ b/crates/debugger_ui/src/session/running/stack_frame_list.rs @@ -199,7 +199,7 @@ impl StackFrameList { self.list_filter } - pub fn opened_stack_frame_id(&self) -> Option { + pub const fn opened_stack_frame_id(&self) -> Option { self.opened_stack_frame_id } diff --git a/crates/debugger_ui/src/session/running/variable_list.rs b/crates/debugger_ui/src/session/running/variable_list.rs index aa8cb143ac71328920bb1a41933b456491647a03..41084b64fe7b18463124a24968b574de56749fe6 100644 --- a/crates/debugger_ui/src/session/running/variable_list.rs +++ b/crates/debugger_ui/src/session/running/variable_list.rs @@ -100,21 +100,21 @@ enum DapEntry { } impl DapEntry { - fn as_watcher(&self) -> Option<&Watcher> { + const fn as_watcher(&self) -> Option<&Watcher> { match self { DapEntry::Watcher(watcher) => Some(watcher), _ => None, } } - fn as_variable(&self) -> Option<&dap::Variable> { + const fn as_variable(&self) -> Option<&dap::Variable> { match self { DapEntry::Variable(dap) => Some(dap), _ => None, } } - fn as_scope(&self) -> Option<&dap::Scope> { + const fn as_scope(&self) -> Option<&dap::Scope> { match self { DapEntry::Scope(dap) => Some(dap), _ => None, @@ -138,15 +138,15 @@ struct ListEntry { } impl ListEntry { - fn as_watcher(&self) -> Option<&Watcher> { + const fn as_watcher(&self) -> Option<&Watcher> { self.entry.as_watcher() } - fn as_variable(&self) -> Option<&dap::Variable> { + const fn as_variable(&self) -> Option<&dap::Variable> { self.entry.as_variable() } - fn as_scope(&self) -> Option<&dap::Scope> { + const fn as_scope(&self) -> Option<&dap::Scope> { self.entry.as_scope() } @@ -257,7 +257,7 @@ impl VariableList { } } - pub(super) fn has_open_context_menu(&self) -> bool { + pub(super) const fn has_open_context_menu(&self) -> bool { self.open_context_menu.is_some() } diff --git a/crates/deepseek/src/deepseek.rs b/crates/deepseek/src/deepseek.rs index 64a1cbe5d96354260c2bf84a43ed70be7336aa7a..44fd69516b16bf69b3be1a882f73d5af21dffff4 100644 --- a/crates/deepseek/src/deepseek.rs +++ b/crates/deepseek/src/deepseek.rs @@ -64,7 +64,7 @@ pub enum Model { } impl Model { - pub fn default_fast() -> Self { + pub const fn default_fast() -> Self { Model::Chat } @@ -94,14 +94,14 @@ impl Model { } } - pub fn max_token_count(&self) -> u64 { + pub const fn max_token_count(&self) -> u64 { match self { Self::Chat | Self::Reasoner => 128_000, Self::Custom { max_tokens, .. } => *max_tokens, } } - pub fn max_output_tokens(&self) -> Option { + pub const fn max_output_tokens(&self) -> Option { match self { Self::Chat => Some(8_192), Self::Reasoner => Some(64_000), diff --git a/crates/denoise/src/lib.rs b/crates/denoise/src/lib.rs index f6cbf0fadf1f216cc6168c2b249f807b557869af..545e7f7b68794040f045b5b25889716c7d1ef6eb 100644 --- a/crates/denoise/src/lib.rs +++ b/crates/denoise/src/lib.rs @@ -35,7 +35,7 @@ impl fmt::Debug for Denoiser { struct Queue(VecDeque<[Sample; BLOCK_SHIFT]>); impl Queue { - fn new() -> Self { + const fn new() -> Self { Self(VecDeque::new()) } fn push(&mut self, block: [Sample; BLOCK_SHIFT]) { @@ -97,7 +97,7 @@ impl Denoiser { }) } - pub fn set_enabled(&mut self, enabled: bool) { + pub const fn set_enabled(&mut self, enabled: bool) { self.state = match (enabled, self.state) { (false, IterState::StartingMidAudio { .. }) | (false, IterState::Enabled) => { IterState::Disabled diff --git a/crates/diagnostics/src/buffer_diagnostics.rs b/crates/diagnostics/src/buffer_diagnostics.rs index e25d3a7702e02c93e38f5808434aff57e743defe..830e4a358b66fa4305d800f9ba4cceded219463d 100644 --- a/crates/diagnostics/src/buffer_diagnostics.rs +++ b/crates/diagnostics/src/buffer_diagnostics.rs @@ -621,7 +621,7 @@ impl BufferDiagnosticsEditor { self.update_all_diagnostics(window, cx); } - fn max_diagnostics_severity(include_warnings: bool) -> DiagnosticSeverity { + const fn max_diagnostics_severity(include_warnings: bool) -> DiagnosticSeverity { match include_warnings { true => DiagnosticSeverity::Warning, false => DiagnosticSeverity::Error, diff --git a/crates/edit_prediction/src/edit_prediction.rs b/crates/edit_prediction/src/edit_prediction.rs index 22cb1047d1dda93b639990e549f9b76b3ff385f5..1e08baa52163cba4049060ea05611c51ebc472ff 100644 --- a/crates/edit_prediction/src/edit_prediction.rs +++ b/crates/edit_prediction/src/edit_prediction.rs @@ -40,15 +40,15 @@ pub enum DataCollectionState { } impl DataCollectionState { - pub fn is_supported(&self) -> bool { + pub const fn is_supported(&self) -> bool { !matches!(self, DataCollectionState::Unsupported) } - pub fn is_enabled(&self) -> bool { + pub const fn is_enabled(&self) -> bool { matches!(self, DataCollectionState::Enabled { .. }) } - pub fn is_project_open_source(&self) -> bool { + pub const fn is_project_open_source(&self) -> bool { match self { Self::Enabled { is_project_open_source, diff --git a/crates/edit_prediction_button/src/edit_prediction_button.rs b/crates/edit_prediction_button/src/edit_prediction_button.rs index 95ffa2f0e66713170d4fb5d63493daf07a7a555d..24bf8deb78acadc74e3d0a0f6adb548ce28d099d 100644 --- a/crates/edit_prediction_button/src/edit_prediction_button.rs +++ b/crates/edit_prediction_button/src/edit_prediction_button.rs @@ -945,7 +945,7 @@ impl StatusItemView for EditPredictionButton { } impl SupermavenButtonStatus { - fn to_icon(&self) -> IconName { + const fn to_icon(&self) -> IconName { match self { SupermavenButtonStatus::Ready => IconName::Supermaven, SupermavenButtonStatus::Errored(_) => IconName::SupermavenError, @@ -963,7 +963,7 @@ impl SupermavenButtonStatus { } } - fn has_menu(&self) -> bool { + const fn has_menu(&self) -> bool { match self { SupermavenButtonStatus::Ready | SupermavenButtonStatus::NeedsActivation(_) => true, SupermavenButtonStatus::Errored(_) | SupermavenButtonStatus::Initializing => false, diff --git a/crates/edit_prediction_context/src/declaration.rs b/crates/edit_prediction_context/src/declaration.rs index cc32640425ecc563b1f24a6c695be1c13199cd73..1905bb350d5541d64eca0df14aa9cc100b4de771 100644 --- a/crates/edit_prediction_context/src/declaration.rs +++ b/crates/edit_prediction_context/src/declaration.rs @@ -39,35 +39,35 @@ pub enum Declaration { const ITEM_TEXT_TRUNCATION_LENGTH: usize = 1024; impl Declaration { - pub fn identifier(&self) -> &Identifier { + pub const fn identifier(&self) -> &Identifier { match self { Declaration::File { declaration, .. } => &declaration.identifier, Declaration::Buffer { declaration, .. } => &declaration.identifier, } } - pub fn parent(&self) -> Option { + pub const fn parent(&self) -> Option { match self { Declaration::File { declaration, .. } => declaration.parent, Declaration::Buffer { declaration, .. } => declaration.parent, } } - pub fn as_buffer(&self) -> Option<&BufferDeclaration> { + pub const fn as_buffer(&self) -> Option<&BufferDeclaration> { match self { Declaration::File { .. } => None, Declaration::Buffer { declaration, .. } => Some(declaration), } } - pub fn as_file(&self) -> Option<&FileDeclaration> { + pub const fn as_file(&self) -> Option<&FileDeclaration> { match self { Declaration::Buffer { .. } => None, Declaration::File { declaration, .. } => Some(declaration), } } - pub fn project_entry_id(&self) -> ProjectEntryId { + pub const fn project_entry_id(&self) -> ProjectEntryId { match self { Declaration::File { project_entry_id, .. @@ -78,7 +78,7 @@ impl Declaration { } } - pub fn cached_path(&self) -> &CachedDeclarationPath { + pub const fn cached_path(&self) -> &CachedDeclarationPath { match self { Declaration::File { cached_path, .. } => cached_path, Declaration::Buffer { cached_path, .. } => cached_path, diff --git a/crates/edit_prediction_context/src/imports.rs b/crates/edit_prediction_context/src/imports.rs index 70f175159340ddb9a6f26f23db0c1b3c843e7b96..edca774aca29915979108626eb85075d8230c63a 100644 --- a/crates/edit_prediction_context/src/imports.rs +++ b/crates/edit_prediction_context/src/imports.rs @@ -493,7 +493,7 @@ enum ContentKind { } impl ContentKind { - fn capture_name(&self) -> &'static str { + const fn capture_name(&self) -> &'static str { match self { ContentKind::Name => "name", ContentKind::Wildcard => "wildcard", @@ -521,7 +521,7 @@ impl ImportTree { } #[allow(dead_code)] - fn debug<'a>(&'a self, snapshot: &'a BufferSnapshot) -> ImportTreeDebug<'a> { + const fn debug<'a>(&'a self, snapshot: &'a BufferSnapshot) -> ImportTreeDebug<'a> { ImportTreeDebug { tree: self, snapshot, diff --git a/crates/edit_prediction_context/src/syntax_index.rs b/crates/edit_prediction_context/src/syntax_index.rs index e2728ebfc029c7c1b74a35f2e6f5a79003a9a77e..5c43b335a4f3b09b100a45a03f3227b4c3d3818f 100644 --- a/crates/edit_prediction_context/src/syntax_index.rs +++ b/crates/edit_prediction_context/src/syntax_index.rs @@ -324,7 +324,7 @@ impl SyntaxIndex { } } - pub fn state(&self) -> &Arc> { + pub const fn state(&self) -> &Arc> { &self.state } diff --git a/crates/editor/src/blink_manager.rs b/crates/editor/src/blink_manager.rs index 9c2b911f1b068d5d8cc14c3875af08033f34bc66..a26822855176343b7820205a3d6be1a9fb9568c8 100644 --- a/crates/editor/src/blink_manager.rs +++ b/crates/editor/src/blink_manager.rs @@ -30,7 +30,7 @@ impl BlinkManager { } } - fn next_blink_epoch(&mut self) -> usize { + const fn next_blink_epoch(&mut self) -> usize { self.blink_epoch += 1; self.blink_epoch } @@ -95,12 +95,12 @@ impl BlinkManager { self.blink_cursors(self.blink_epoch, cx); } - pub fn disable(&mut self, _cx: &mut Context) { + pub const fn disable(&mut self, _cx: &mut Context) { self.visible = false; self.enabled = false; } - pub fn visible(&self) -> bool { + pub const fn visible(&self) -> bool { self.visible } } diff --git a/crates/editor/src/code_context_menus.rs b/crates/editor/src/code_context_menus.rs index 359c985ee9208a1a83e3458635df883c2cf991a8..9a215b9df0752f02a729073cb6dfd8dabe0cb927 100644 --- a/crates/editor/src/code_context_menus.rs +++ b/crates/editor/src/code_context_menus.rs @@ -141,7 +141,7 @@ impl CodeContextMenu { } } - pub fn origin(&self) -> ContextMenuOrigin { + pub const fn origin(&self) -> ContextMenuOrigin { match self { CodeContextMenu::Completions(menu) => menu.origin(), CodeContextMenu::CodeActions(menu) => menu.origin(), @@ -725,7 +725,7 @@ impl CompletionsMenu { !self.entries.borrow().is_empty() } - fn origin(&self) -> ContextMenuOrigin { + const fn origin(&self) -> ContextMenuOrigin { ContextMenuOrigin::Cursor } @@ -1356,20 +1356,20 @@ pub enum CodeActionsItem { } impl CodeActionsItem { - fn as_task(&self) -> Option<&ResolvedTask> { + const fn as_task(&self) -> Option<&ResolvedTask> { let Self::Task(_, task) = self else { return None; }; Some(task) } - fn as_code_action(&self) -> Option<&CodeAction> { + const fn as_code_action(&self) -> Option<&CodeAction> { let Self::CodeAction { action, .. } = self else { return None; }; Some(action) } - fn as_debug_scenario(&self) -> Option<&DebugScenario> { + const fn as_debug_scenario(&self) -> Option<&DebugScenario> { let Self::DebugScenario(scenario) = self else { return None; }; @@ -1458,7 +1458,7 @@ impl CodeActionsMenu { !self.actions.is_empty() } - fn origin(&self) -> ContextMenuOrigin { + const fn origin(&self) -> ContextMenuOrigin { match &self.deployed_from { Some(CodeActionSource::Indicator(row)) | Some(CodeActionSource::RunMenu(row)) => { ContextMenuOrigin::GutterIndicator(*row) diff --git a/crates/editor/src/display_map.rs b/crates/editor/src/display_map.rs index b3d642f60ea591fcf8b1987c723b4ba025dc110a..a6df6eb33a9a4aaff7872dc0d582bf8b5c61b2d6 100644 --- a/crates/editor/src/display_map.rs +++ b/crates/editor/src/display_map.rs @@ -384,7 +384,7 @@ impl DisplayMap { self.block_map.folded_buffers.contains(&buffer_id) } - pub(crate) fn folded_buffers(&self) -> &HashSet { + pub(crate) const fn folded_buffers(&self) -> &HashSet { &self.block_map.folded_buffers } @@ -767,18 +767,18 @@ pub struct DisplaySnapshot { pub(crate) fold_placeholder: FoldPlaceholder, } impl DisplaySnapshot { - pub fn wrap_snapshot(&self) -> &WrapSnapshot { + pub const fn wrap_snapshot(&self) -> &WrapSnapshot { &self.block_snapshot.wrap_snapshot } - pub fn tab_snapshot(&self) -> &TabSnapshot { + pub const fn tab_snapshot(&self) -> &TabSnapshot { &self.block_snapshot.wrap_snapshot.tab_snapshot } - pub fn fold_snapshot(&self) -> &FoldSnapshot { + pub const fn fold_snapshot(&self) -> &FoldSnapshot { &self.block_snapshot.wrap_snapshot.tab_snapshot.fold_snapshot } - pub fn inlay_snapshot(&self) -> &InlaySnapshot { + pub const fn inlay_snapshot(&self) -> &InlaySnapshot { &self .block_snapshot .wrap_snapshot @@ -787,7 +787,7 @@ impl DisplaySnapshot { .inlay_snapshot } - pub fn buffer_snapshot(&self) -> &MultiBufferSnapshot { + pub const fn buffer_snapshot(&self) -> &MultiBufferSnapshot { &self .block_snapshot .wrap_snapshot @@ -1394,11 +1394,11 @@ impl DisplaySnapshot { self.inlay_highlights.get(&type_id) } - pub fn buffer_header_height(&self) -> u32 { + pub const fn buffer_header_height(&self) -> u32 { self.block_snapshot.buffer_header_height } - pub fn excerpt_header_height(&self) -> u32 { + pub const fn excerpt_header_height(&self) -> u32 { self.block_snapshot.excerpt_header_height } @@ -1489,11 +1489,11 @@ impl Sub for DisplayRow { } impl DisplayPoint { - pub fn new(row: DisplayRow, column: u32) -> Self { + pub const fn new(row: DisplayRow, column: u32) -> Self { Self(BlockPoint(Point::new(row.0, column))) } - pub fn zero() -> Self { + pub const fn zero() -> Self { Self::new(DisplayRow(0), 0) } diff --git a/crates/editor/src/display_map/block_map.rs b/crates/editor/src/display_map/block_map.rs index c954e1ba1b487c1c33187e895b7897f8ed67f94e..e8a5bcab00646a83c134d5fa77d585b396bac791 100644 --- a/crates/editor/src/display_map/block_map.rs +++ b/crates/editor/src/display_map/block_map.rs @@ -89,7 +89,7 @@ pub enum BlockPlacement { } impl BlockPlacement { - pub fn start(&self) -> &T { + pub const fn start(&self) -> &T { match self { BlockPlacement::Above(position) => position, BlockPlacement::Below(position) => position, @@ -98,7 +98,7 @@ impl BlockPlacement { } } - fn end(&self) -> &T { + const fn end(&self) -> &T { match self { BlockPlacement::Above(position) => position, BlockPlacement::Below(position) => position, @@ -107,7 +107,7 @@ impl BlockPlacement { } } - pub fn as_ref(&self) -> BlockPlacement<&T> { + pub const fn as_ref(&self) -> BlockPlacement<&T> { match self { BlockPlacement::Above(position) => BlockPlacement::Above(position), BlockPlacement::Below(position) => BlockPlacement::Below(position), @@ -128,7 +128,7 @@ impl BlockPlacement { } } - fn tie_break(&self) -> u8 { + const fn tie_break(&self) -> u8 { match self { BlockPlacement::Replace(_) => 0, BlockPlacement::Above(_) => 1, @@ -379,7 +379,7 @@ impl Block { } } - fn is_header(&self) -> bool { + const fn is_header(&self) -> bool { match self { Block::Custom(_) => false, Block::FoldedBuffer { .. } => true, @@ -388,7 +388,7 @@ impl Block { } } - pub fn is_buffer_header(&self) -> bool { + pub const fn is_buffer_header(&self) -> bool { match self { Block::Custom(_) => false, Block::FoldedBuffer { .. } => true, @@ -949,7 +949,7 @@ fn push_isomorphic(tree: &mut SumTree, rows: u32, wrap_snapshot: &Wra } impl BlockPoint { - pub fn new(row: u32, column: u32) -> Self { + pub const fn new(row: u32, column: u32) -> Self { Self(Point::new(row, column)) } } @@ -1913,15 +1913,15 @@ impl CustomBlock { self.render.lock()(cx) } - pub fn start(&self) -> Anchor { + pub const fn start(&self) -> Anchor { *self.placement.start() } - pub fn end(&self) -> Anchor { + pub const fn end(&self) -> Anchor { *self.placement.end() } - pub fn style(&self) -> BlockStyle { + pub const fn style(&self) -> BlockStyle { self.style } } diff --git a/crates/editor/src/display_map/crease_map.rs b/crates/editor/src/display_map/crease_map.rs index a68c27886733d34a60ef0ce2ef4006b92b679db9..8b1dd39dee7b4e670efb4f3e398614e3c68cfad9 100644 --- a/crates/editor/src/display_map/crease_map.rs +++ b/crates/editor/src/display_map/crease_map.rs @@ -235,14 +235,14 @@ impl Crease { } } - pub fn range(&self) -> &Range { + pub const fn range(&self) -> &Range { match self { Crease::Inline { range, .. } => range, Crease::Block { range, .. } => range, } } - pub fn metadata(&self) -> Option<&CreaseMetadata> { + pub const fn metadata(&self) -> Option<&CreaseMetadata> { match self { Self::Inline { metadata, .. } => metadata.as_ref(), Self::Block { .. } => None, diff --git a/crates/editor/src/display_map/fold_map.rs b/crates/editor/src/display_map/fold_map.rs index e5d82f8f70a9b5e29622b1302c1eaaf2070b0387..b69cc053bfaf859adaa8157ed40297d6347d0236 100644 --- a/crates/editor/src/display_map/fold_map.rs +++ b/crates/editor/src/display_map/fold_map.rs @@ -76,19 +76,19 @@ impl PartialEq for FoldPlaceholder { pub struct FoldPoint(pub Point); impl FoldPoint { - pub fn new(row: u32, column: u32) -> Self { + pub const fn new(row: u32, column: u32) -> Self { Self(Point::new(row, column)) } - pub fn row(self) -> u32 { + pub const fn row(self) -> u32 { self.0.row } - pub fn column(self) -> u32 { + pub const fn column(self) -> u32 { self.0.column } - pub fn row_mut(&mut self) -> &mut u32 { + pub const fn row_mut(&mut self) -> &mut u32 { &mut self.0.row } @@ -632,7 +632,7 @@ pub struct FoldSnapshot { } impl FoldSnapshot { - pub fn buffer(&self) -> &MultiBufferSnapshot { + pub const fn buffer(&self) -> &MultiBufferSnapshot { &self.inlay_snapshot.buffer } @@ -1048,7 +1048,7 @@ struct TransformPlaceholder { } impl Transform { - fn is_fold(&self) -> bool { + const fn is_fold(&self) -> bool { self.placeholder.is_some() } } diff --git a/crates/editor/src/display_map/inlay_map.rs b/crates/editor/src/display_map/inlay_map.rs index c4532a93f1d50e91dbd4791b4621b74ee0813cbe..918307017acbc11862f80d0aaabf80e4b391ecf2 100644 --- a/crates/editor/src/display_map/inlay_map.rs +++ b/crates/editor/src/display_map/inlay_map.rs @@ -284,7 +284,7 @@ impl InlayChunks<'_> { self.max_output_offset = new_range.end; } - pub fn offset(&self) -> InlayOffset { + pub const fn offset(&self) -> InlayOffset { self.output_offset } } @@ -543,11 +543,11 @@ impl Iterator for InlayBufferRows<'_> { } impl InlayPoint { - pub fn new(row: u32, column: u32) -> Self { + pub const fn new(row: u32, column: u32) -> Self { Self(Point::new(row, column)) } - pub fn row(self) -> u32 { + pub const fn row(self) -> u32 { self.0.row } } diff --git a/crates/editor/src/display_map/tab_map.rs b/crates/editor/src/display_map/tab_map.rs index b37d81c66614030ab574244f3de0277d3fd8bee9..6a422b3896d5c5ec0a7684dfe5f7a35f3d4d4ff3 100644 --- a/crates/editor/src/display_map/tab_map.rs +++ b/crates/editor/src/display_map/tab_map.rs @@ -168,7 +168,7 @@ pub struct TabSnapshot { } impl TabSnapshot { - pub fn buffer_snapshot(&self) -> &MultiBufferSnapshot { + pub const fn buffer_snapshot(&self) -> &MultiBufferSnapshot { &self.fold_snapshot.inlay_snapshot.buffer } @@ -428,19 +428,19 @@ impl TabSnapshot { pub struct TabPoint(pub Point); impl TabPoint { - pub fn new(row: u32, column: u32) -> Self { + pub const fn new(row: u32, column: u32) -> Self { Self(Point::new(row, column)) } - pub fn zero() -> Self { + pub const fn zero() -> Self { Self::new(0, 0) } - pub fn row(self) -> u32 { + pub const fn row(self) -> u32 { self.0.row } - pub fn column(self) -> u32 { + pub const fn column(self) -> u32 { self.0.column } } @@ -1544,11 +1544,11 @@ where None } - fn byte_offset(&self) -> u32 { + const fn byte_offset(&self) -> u32 { self.byte_offset } - fn char_offset(&self) -> u32 { + const fn char_offset(&self) -> u32 { self.char_offset } } diff --git a/crates/editor/src/display_map/wrap_map.rs b/crates/editor/src/display_map/wrap_map.rs index 39c247cb4e105155e77c8fd5c84e5f185d726af1..2ddb77bb5d045adebd384c47fc6cd676d2189926 100644 --- a/crates/editor/src/display_map/wrap_map.rs +++ b/crates/editor/src/display_map/wrap_map.rs @@ -327,7 +327,7 @@ impl WrapSnapshot { } } - pub fn buffer_snapshot(&self) -> &MultiBufferSnapshot { + pub const fn buffer_snapshot(&self) -> &MultiBufferSnapshot { self.tab_snapshot.buffer_snapshot() } @@ -1067,7 +1067,7 @@ impl Transform { } } - fn is_isomorphic(&self) -> bool { + const fn is_isomorphic(&self) -> bool { self.display_text.is_none() } } @@ -1116,23 +1116,23 @@ impl SumTreeExt for SumTree { } impl WrapPoint { - pub fn new(row: u32, column: u32) -> Self { + pub const fn new(row: u32, column: u32) -> Self { Self(Point::new(row, column)) } - pub fn row(self) -> u32 { + pub const fn row(self) -> u32 { self.0.row } - pub fn row_mut(&mut self) -> &mut u32 { + pub const fn row_mut(&mut self) -> &mut u32 { &mut self.0.row } - pub fn column(self) -> u32 { + pub const fn column(self) -> u32 { self.0.column } - pub fn column_mut(&mut self) -> &mut u32 { + pub const fn column_mut(&mut self) -> &mut u32 { &mut self.0.column } } diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index cc02740900770e4bee42ad49361f65b7dda98568..9ea15a6cdd61483ca1a93a198156a901dc4ee8c5 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -252,7 +252,7 @@ enum ReportEditorEvent { } impl ReportEditorEvent { - pub fn event_type(&self) -> &'static str { + pub const fn event_type(&self) -> &'static str { match self { Self::Saved { .. } => "Editor Saved", Self::EditorOpened => "Editor Opened", @@ -268,7 +268,7 @@ struct InlineValueCache { } impl InlineValueCache { - fn new(enabled: bool) -> Self { + const fn new(enabled: bool) -> Self { Self { enabled, inlays: Vec::new(), @@ -287,7 +287,7 @@ pub enum InlayId { } impl InlayId { - fn id(&self) -> u32 { + const fn id(&self) -> u32 { match self { Self::EditPrediction(id) => *id, Self::DebuggerValue(id) => *id, @@ -318,7 +318,7 @@ pub enum Navigated { } impl Navigated { - pub fn from_bool(yes: bool) -> Navigated { + pub const fn from_bool(yes: bool) -> Navigated { if yes { Navigated::Yes } else { Navigated::No } } } @@ -507,7 +507,7 @@ pub enum EditorMode { } impl EditorMode { - pub fn full() -> Self { + pub const fn full() -> Self { Self::Full { scale_ui_elements_with_buffer_font_size: true, show_active_line_background: true, @@ -516,17 +516,17 @@ impl EditorMode { } #[inline] - pub fn is_full(&self) -> bool { + pub const fn is_full(&self) -> bool { matches!(self, Self::Full { .. }) } #[inline] - pub fn is_single_line(&self) -> bool { + pub const fn is_single_line(&self) -> bool { matches!(self, Self::SingleLine { .. }) } #[inline] - fn is_minimap(&self) -> bool { + const fn is_minimap(&self) -> bool { matches!(self, Self::Minimap { .. }) } } @@ -692,14 +692,14 @@ pub enum EditPredictionPreview { } impl EditPredictionPreview { - pub fn released_too_fast(&self) -> bool { + pub const fn released_too_fast(&self) -> bool { match self { EditPredictionPreview::Inactive { released_too_fast } => *released_too_fast, EditPredictionPreview::Active { .. } => false, } } - pub fn set_previous_scroll_position(&mut self, scroll_position: Option) { + pub const fn set_previous_scroll_position(&mut self, scroll_position: Option) { if let EditPredictionPreview::Active { previous_scroll_position, .. @@ -726,7 +726,7 @@ pub enum ContextMenuPlacement { struct EditorActionId(usize); impl EditorActionId { - pub fn post_inc(&mut self) -> Self { + pub const fn post_inc(&mut self) -> Self { let answer = self.0; *self = Self(answer + 1); @@ -778,7 +778,7 @@ impl MinimapVisibility { } } - fn hidden(&self) -> Self { + const fn hidden(&self) -> Self { match *self { Self::Enabled { setting_configuration, @@ -791,11 +791,11 @@ impl MinimapVisibility { } } - fn disabled(&self) -> bool { + const fn disabled(&self) -> bool { matches!(*self, Self::Disabled) } - fn settings_visibility(&self) -> bool { + const fn settings_visibility(&self) -> bool { match *self { Self::Enabled { setting_configuration, @@ -805,7 +805,7 @@ impl MinimapVisibility { } } - fn visible(&self) -> bool { + const fn visible(&self) -> bool { match *self { Self::Enabled { setting_configuration, @@ -815,7 +815,7 @@ impl MinimapVisibility { } } - fn toggle_visibility(&self) -> Self { + const fn toggle_visibility(&self) -> Self { match *self { Self::Enabled { toggle_override, @@ -901,7 +901,7 @@ pub struct ChangeList { } impl ChangeList { - pub fn new() -> Self { + pub const fn new() -> Self { Self { changes: Vec::new(), position: None, @@ -1205,7 +1205,7 @@ enum NextScrollCursorCenterTopBottom { } impl NextScrollCursorCenterTopBottom { - fn next(&self) -> Self { + const fn next(&self) -> Self { match self { Self::Center => Self::Top, Self::Top => Self::Bottom, @@ -1356,14 +1356,14 @@ impl SelectionEffects { } } - pub fn completions(self, completions: bool) -> Self { + pub const fn completions(self, completions: bool) -> Self { Self { completions, ..self } } - pub fn nav_history(self, nav_history: bool) -> Self { + pub const fn nav_history(self, nav_history: bool) -> Self { Self { nav_history: Some(nav_history), ..self @@ -1632,7 +1632,7 @@ enum InlayHintRefreshReason { } impl InlayHintRefreshReason { - fn description(&self) -> &'static str { + const fn description(&self) -> &'static str { match self { Self::ModifiersChanged(_) => "modifiers changed", Self::Toggle(_) => "toggle", @@ -2550,7 +2550,7 @@ impl Editor { key_context } - pub fn last_bounds(&self) -> Option<&Bounds> { + pub const fn last_bounds(&self) -> Option<&Bounds> { self.last_bounds.as_ref() } @@ -2714,15 +2714,15 @@ impl Editor { }); } - pub fn leader_id(&self) -> Option { + pub const fn leader_id(&self) -> Option { self.leader_id } - pub fn buffer(&self) -> &Entity { + pub const fn buffer(&self) -> &Entity { &self.buffer } - pub fn project(&self) -> Option<&Entity> { + pub const fn project(&self) -> Option<&Entity> { self.project.as_ref() } @@ -2789,7 +2789,7 @@ impl Editor { .excerpt_containing(self.selections.newest_anchor().head(), cx) } - pub fn mode(&self) -> &EditorMode { + pub const fn mode(&self) -> &EditorMode { &self.mode } @@ -2805,7 +2805,7 @@ impl Editor { self.collaboration_hub = Some(hub); } - pub fn set_in_project_search(&mut self, in_project_search: bool) { + pub const fn set_in_project_search(&mut self, in_project_search: bool) { self.in_project_search = in_project_search; } @@ -2901,14 +2901,14 @@ impl Editor { cx.notify(); } - pub fn set_current_line_highlight( + pub const fn set_current_line_highlight( &mut self, current_line_highlight: Option, ) { self.current_line_highlight = current_line_highlight; } - pub fn set_collapse_matches(&mut self, collapse_matches: bool) { + pub const fn set_collapse_matches(&mut self, collapse_matches: bool) { self.collapse_matches = collapse_matches; } @@ -2926,7 +2926,7 @@ impl Editor { } } - pub fn set_input_enabled(&mut self, input_enabled: bool) { + pub const fn set_input_enabled(&mut self, input_enabled: bool) { self.input_enabled = input_enabled; } @@ -2946,7 +2946,7 @@ impl Editor { } } - pub fn set_menu_edit_predictions_policy(&mut self, value: MenuEditPredictionsPolicy) { + pub const fn set_menu_edit_predictions_policy(&mut self, value: MenuEditPredictionsPolicy) { self.menu_edit_predictions_policy = value; } @@ -2962,19 +2962,19 @@ impl Editor { self.read_only || self.buffer.read(cx).read_only() } - pub fn set_read_only(&mut self, read_only: bool) { + pub const fn set_read_only(&mut self, read_only: bool) { self.read_only = read_only; } - pub fn set_use_autoclose(&mut self, autoclose: bool) { + pub const fn set_use_autoclose(&mut self, autoclose: bool) { self.use_autoclose = autoclose; } - pub fn set_use_auto_surround(&mut self, auto_surround: bool) { + pub const fn set_use_auto_surround(&mut self, auto_surround: bool) { self.use_auto_surround = auto_surround; } - pub fn set_auto_replace_emoji_shortcode(&mut self, auto_replace: bool) { + pub const fn set_auto_replace_emoji_shortcode(&mut self, auto_replace: bool) { self.auto_replace_emoji_shortcode = auto_replace; } @@ -3029,11 +3029,11 @@ impl Editor { }) } - pub fn set_use_modal_editing(&mut self, to: bool) { + pub const fn set_use_modal_editing(&mut self, to: bool) { self.use_modal_editing = to; } - pub fn use_modal_editing(&self) -> bool { + pub const fn use_modal_editing(&self) -> bool { self.use_modal_editing } @@ -5193,11 +5193,11 @@ impl Editor { ); } - pub fn inlay_hints_enabled(&self) -> bool { + pub const fn inlay_hints_enabled(&self) -> bool { self.inlay_hint_cache.enabled } - pub fn inline_values_enabled(&self) -> bool { + pub const fn inline_values_enabled(&self) -> bool { self.inline_value_cache.enabled } @@ -6627,7 +6627,7 @@ impl Editor { .into_any_element() } - pub fn context_menu(&self) -> &RefCell> { + pub const fn context_menu(&self) -> &RefCell> { &self.context_menu } @@ -7222,21 +7222,21 @@ impl Editor { Some(()) } - fn show_edit_predictions_in_menu(&self) -> bool { + const fn show_edit_predictions_in_menu(&self) -> bool { match self.edit_prediction_settings { EditPredictionSettings::Disabled => false, EditPredictionSettings::Enabled { show_in_menu, .. } => show_in_menu, } } - pub fn edit_predictions_enabled(&self) -> bool { + pub const fn edit_predictions_enabled(&self) -> bool { match self.edit_prediction_settings { EditPredictionSettings::Disabled => false, EditPredictionSettings::Enabled { .. } => true, } } - fn edit_prediction_requires_modifier(&self) -> bool { + const fn edit_prediction_requires_modifier(&self) -> bool { match self.edit_prediction_settings { EditPredictionSettings::Disabled => false, EditPredictionSettings::Enabled { @@ -7308,7 +7308,7 @@ impl Editor { self.snippet_stack.is_empty() && self.edit_predictions_enabled() } - pub fn edit_prediction_preview_is_active(&self) -> bool { + pub const fn edit_prediction_preview_is_active(&self) -> bool { matches!( self.edit_prediction_preview, EditPredictionPreview::Active { .. } @@ -7721,7 +7721,7 @@ impl Editor { }) } - pub fn has_active_edit_prediction(&self) -> bool { + pub const fn has_active_edit_prediction(&self) -> bool { self.active_edit_prediction.is_some() } @@ -8670,7 +8670,7 @@ impl Editor { .map(|menu| menu.origin()) } - pub fn set_context_menu_options(&mut self, options: ContextMenuOptions) { + pub const fn set_context_menu_options(&mut self, options: ContextMenuOptions) { self.context_menu_options = Some(options); } @@ -9257,7 +9257,7 @@ impl Editor { None } - fn edit_prediction_cursor_popover_height(&self) -> Pixels { + const fn edit_prediction_cursor_popover_height(&self) -> Pixels { px(30.) } @@ -11707,7 +11707,7 @@ impl Editor { }); } - pub fn clear_selection_drag_state(&mut self) { + pub const fn clear_selection_drag_state(&mut self) { self.selection_drag_state = SelectionDragState::None; } @@ -14111,7 +14111,7 @@ impl Editor { self.nav_history = nav_history; } - pub fn nav_history(&self) -> Option<&ItemNavHistory> { + pub const fn nav_history(&self) -> Option<&ItemNavHistory> { self.nav_history.as_ref() } @@ -17352,7 +17352,7 @@ impl Editor { Some(rename) } - pub fn pending_rename(&self) -> Option<&RenameState> { + pub const fn pending_rename(&self) -> Option<&RenameState> { self.pending_rename.as_ref() } @@ -17642,7 +17642,7 @@ impl Editor { } } - pub fn active_diagnostic_group(&self) -> Option<&ActiveDiagnosticGroup> { + pub const fn active_diagnostic_group(&self) -> Option<&ActiveDiagnosticGroup> { match &self.active_diagnostics { ActiveDiagnostic::Group(group) => Some(group), _ => None, @@ -17722,19 +17722,19 @@ impl Editor { self.inline_diagnostics.clear(); } - pub fn disable_word_completions(&mut self) { + pub const fn disable_word_completions(&mut self) { self.word_completions_enabled = false; } - pub fn diagnostics_enabled(&self) -> bool { + pub const fn diagnostics_enabled(&self) -> bool { self.diagnostics_enabled && self.mode.is_full() } - pub fn inline_diagnostics_enabled(&self) -> bool { + pub const fn inline_diagnostics_enabled(&self) -> bool { self.inline_diagnostics_enabled && self.diagnostics_enabled() } - pub fn show_inline_diagnostics(&self) -> bool { + pub const fn show_inline_diagnostics(&self) -> bool { self.show_inline_diagnostics } @@ -19199,7 +19199,7 @@ impl Editor { self.focused_block = Some(focused_block); } - pub(crate) fn take_focused_block(&mut self) -> Option { + pub(crate) const fn take_focused_block(&mut self) -> Option { self.focused_block.take() } @@ -19403,7 +19403,7 @@ impl Editor { self.style = Some(style); } - pub fn style(&self) -> Option<&EditorStyle> { + pub const fn style(&self) -> Option<&EditorStyle> { self.style.as_ref() } @@ -19422,7 +19422,7 @@ impl Editor { } } - pub fn set_soft_wrap(&mut self) { + pub const fn set_soft_wrap(&mut self) { self.soft_wrap_mode_override = Some(language_settings::SoftWrap::EditorWidth) } @@ -19470,7 +19470,7 @@ impl Editor { cx.notify(); } - fn should_show_indent_guides(&self) -> Option { + const fn should_show_indent_guides(&self) -> Option { self.show_indent_guides } @@ -19846,7 +19846,7 @@ impl Editor { None } - pub fn git_blame_inline_enabled(&self) -> bool { + pub const fn git_blame_inline_enabled(&self) -> bool { self.git_blame_inline_enabled } @@ -19930,11 +19930,11 @@ impl Editor { } } - pub fn blame(&self) -> Option<&Entity> { + pub const fn blame(&self) -> Option<&Entity> { self.blame.as_ref() } - pub fn show_git_blame_gutter(&self) -> bool { + pub const fn show_git_blame_gutter(&self) -> bool { self.show_git_blame_gutter } @@ -21186,11 +21186,11 @@ impl Editor { cx.notify(); } - pub fn set_searchable(&mut self, searchable: bool) { + pub const fn set_searchable(&mut self, searchable: bool) { self.searchable = searchable; } - pub fn searchable(&self) -> bool { + pub const fn searchable(&self) -> bool { self.searchable } @@ -21639,7 +21639,7 @@ impl Editor { mouse_context_menu::deploy_context_menu(self, None, position, window, cx); } - pub fn inlay_hint_cache(&self) -> &InlayHintCache { + pub const fn inlay_hint_cache(&self) -> &InlayHintCache { &self.inlay_hint_cache } @@ -21895,7 +21895,7 @@ impl Editor { }) } - pub fn file_header_size(&self) -> u32 { + pub const fn file_header_size(&self) -> u32 { FILE_HEADER_HEIGHT } @@ -22456,7 +22456,7 @@ struct WordBreakingTokenizer<'a> { } impl<'a> WordBreakingTokenizer<'a> { - fn new(input: &'a str) -> Self { + const fn new(input: &'a str) -> Self { Self { input } } } @@ -23600,7 +23600,7 @@ impl EditorSnapshot { .language_at(position) } - pub fn is_focused(&self) -> bool { + pub const fn is_focused(&self) -> bool { self.is_focused } @@ -24358,7 +24358,7 @@ fn edit_prediction_fallback_text(edits: &[(Range, String)], cx: &App) -> } } -pub fn diagnostic_style(severity: lsp::DiagnosticSeverity, colors: &StatusColors) -> Hsla { +pub const fn diagnostic_style(severity: lsp::DiagnosticSeverity, colors: &StatusColors) -> Hsla { match severity { lsp::DiagnosticSeverity::ERROR => colors.error, lsp::DiagnosticSeverity::WARNING => colors.warning, @@ -24533,7 +24533,7 @@ impl RowRangeExt for Range { /// If select range has more than one line, we /// just point the cursor to range.start. -fn collapse_multiline_range(range: Range) -> Range { +const fn collapse_multiline_range(range: Range) -> Range { if range.start.row == range.end.row { range } else { diff --git a/crates/editor/src/editor_settings.rs b/crates/editor/src/editor_settings.rs index 9ecbbff97612d391e56271f19331160ef08ba534..af456295f4c62c9337f8263e4d7b9e0e001893d3 100644 --- a/crates/editor/src/editor_settings.rs +++ b/crates/editor/src/editor_settings.rs @@ -105,7 +105,7 @@ impl Minimap { self.display_in == DisplayIn::ActiveEditor } - pub fn with_show_override(self) -> Self { + pub const fn with_show_override(self) -> Self { Self { show: ShowMinimap::Always, ..self diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 2dcb9996c37d54ad352795b39a0b28ece2827759..9f9f1d46a1e28dbad0ea060fbe1f96a9caee45ab 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -9678,7 +9678,7 @@ impl Element for EditorElement { } } -pub(super) fn gutter_bounds( +pub(super) const fn gutter_bounds( editor_bounds: Bounds, gutter_dimensions: GutterDimensions, ) -> Bounds { @@ -10047,7 +10047,7 @@ impl ScrollbarLayout { } } - fn with_thumb_state(self, thumb_state: Option) -> Self { + const fn with_thumb_state(self, thumb_state: Option) -> Self { if let Some(thumb_state) = thumb_state { Self { thumb_state, @@ -10367,7 +10367,7 @@ pub struct CursorName { } impl CursorLayout { - pub fn new( + pub const fn new( origin: gpui::Point, block_width: Pixels, line_height: Pixels, @@ -10475,7 +10475,7 @@ impl CursorLayout { } } - pub fn shape(&self) -> CursorShape { + pub const fn shape(&self) -> CursorShape { self.shape } } diff --git a/crates/editor/src/git/blame.rs b/crates/editor/src/git/blame.rs index 836b61d56674f070abc13dbf6c67981c78818ff6..634c7f8b02b3dd62667d8dc3ada2cb00220562f1 100644 --- a/crates/editor/src/git/blame.rs +++ b/crates/editor/src/git/blame.rs @@ -326,7 +326,7 @@ impl GitBlame { max_author_length } - pub fn blur(&mut self, _: &mut Context) { + pub const fn blur(&mut self, _: &mut Context) { self.focused = false; } diff --git a/crates/editor/src/hover_links.rs b/crates/editor/src/hover_links.rs index 4a1a6a934678adb9512ee6883684d2ecb1b2d90a..62e3d3ffc00d0446f08dc46c2fc2c41c41e41741 100644 --- a/crates/editor/src/hover_links.rs +++ b/crates/editor/src/hover_links.rs @@ -85,7 +85,7 @@ pub enum TriggerPoint { } impl TriggerPoint { - fn anchor(&self) -> &Anchor { + const fn anchor(&self) -> &Anchor { match self { TriggerPoint::Text(anchor) => anchor, TriggerPoint::InlayHint(inlay_range, _, _) => &inlay_range.inlay_position, diff --git a/crates/editor/src/hover_popover.rs b/crates/editor/src/hover_popover.rs index 2b0ebf52805493d008c8b69ec4ff86991d6c743d..03002c2a46c680537ec18aadc698b46070d97e23 100644 --- a/crates/editor/src/hover_popover.rs +++ b/crates/editor/src/hover_popover.rs @@ -756,7 +756,7 @@ pub struct HoverState { } impl HoverState { - pub fn visible(&self) -> bool { + pub const fn visible(&self) -> bool { !self.info_popovers.is_empty() || self.diagnostic_popover.is_some() } diff --git a/crates/editor/src/indent_guides.rs b/crates/editor/src/indent_guides.rs index 7c392d27531472a413ce4d32d09cce4eb722e462..2d87d89f0c591192e644f3ef586238da54a7a21c 100644 --- a/crates/editor/src/indent_guides.rs +++ b/crates/editor/src/indent_guides.rs @@ -23,7 +23,7 @@ pub struct ActiveIndentGuidesState { } impl ActiveIndentGuidesState { - pub fn should_refresh(&self) -> bool { + pub const fn should_refresh(&self) -> bool { self.pending_refresh.is_none() && self.dirty } } diff --git a/crates/editor/src/inlay_hint_cache.rs b/crates/editor/src/inlay_hint_cache.rs index 34d737452e905449c259fb41fe03a96e34159b05..5e085f918fa8f2720cfdc26cb6fdd3dd336d09a1 100644 --- a/crates/editor/src/inlay_hint_cache.rs +++ b/crates/editor/src/inlay_hint_cache.rs @@ -109,7 +109,7 @@ struct ExcerptQuery { } impl InvalidationStrategy { - fn should_invalidate(&self) -> bool { + const fn should_invalidate(&self) -> bool { matches!( self, InvalidationStrategy::RefreshRequested | InvalidationStrategy::BufferEdited @@ -660,7 +660,7 @@ impl InlayHintCache { } } -fn debounce_value(debounce_ms: u64) -> Option { +const fn debounce_value(debounce_ms: u64) -> Option { if debounce_ms > 0 { Some(Duration::from_millis(debounce_ms)) } else { @@ -751,7 +751,7 @@ struct QueryRanges { } impl QueryRanges { - fn is_empty(&self) -> bool { + const fn is_empty(&self) -> bool { self.before_visible.is_empty() && self.visible.is_empty() && self.after_visible.is_empty() } diff --git a/crates/editor/src/items.rs b/crates/editor/src/items.rs index 708efbbe979dd153dbafde265e56bc2ddd725f76..b48ac212638d6eddcf31b33b960b8bd5cf0ebfb4 100644 --- a/crates/editor/src/items.rs +++ b/crates/editor/src/items.rs @@ -1809,7 +1809,7 @@ pub fn active_match_index( } } -pub fn entry_label_color(selected: bool) -> Color { +pub const fn entry_label_color(selected: bool) -> Color { if selected { Color::Default } else { @@ -1817,7 +1817,7 @@ pub fn entry_label_color(selected: bool) -> Color { } } -pub fn entry_diagnostic_aware_icon_name_and_color( +pub const fn entry_diagnostic_aware_icon_name_and_color( diagnostic_severity: Option, ) -> Option<(IconName, Color)> { match diagnostic_severity { @@ -1827,7 +1827,7 @@ pub fn entry_diagnostic_aware_icon_name_and_color( } } -pub fn entry_diagnostic_aware_icon_decoration_and_color( +pub const fn entry_diagnostic_aware_icon_decoration_and_color( diagnostic_severity: Option, ) -> Option<(IconDecorationKind, Color)> { match diagnostic_severity { diff --git a/crates/editor/src/proposed_changes_editor.rs b/crates/editor/src/proposed_changes_editor.rs index 2d4710a8d44a023f0c3206ad0c327a34c36fdac4..270b3bcf6ce0c7089e2494c62d21f4931d93d34a 100644 --- a/crates/editor/src/proposed_changes_editor.rs +++ b/crates/editor/src/proposed_changes_editor.rs @@ -354,13 +354,13 @@ impl Item for ProposedChangesEditor { } impl ProposedChangesEditorToolbar { - pub fn new() -> Self { + pub const fn new() -> Self { Self { current_editor: None, } } - fn get_toolbar_item_location(&self) -> ToolbarItemLocation { + const fn get_toolbar_item_location(&self) -> ToolbarItemLocation { if self.current_editor.is_some() { ToolbarItemLocation::PrimaryRight } else { diff --git a/crates/editor/src/scroll.rs b/crates/editor/src/scroll.rs index 001be45ab814e1627dc34abbba342272d3e15750..0c5d3c27f756cddcdc498613e6ffd9ae9c34e8f4 100644 --- a/crates/editor/src/scroll.rs +++ b/crates/editor/src/scroll.rs @@ -139,7 +139,7 @@ pub struct ActiveScrollbarState { } impl ActiveScrollbarState { - pub fn new(axis: Axis, thumb_state: ScrollbarThumbState) -> Self { + pub const fn new(axis: Axis, thumb_state: ScrollbarThumbState) -> Self { ActiveScrollbarState { axis, thumb_state } } @@ -189,16 +189,16 @@ impl ScrollManager { } } - pub fn clone_state(&mut self, other: &Self) { + pub const fn clone_state(&mut self, other: &Self) { self.anchor = other.anchor; self.ongoing = other.ongoing; } - pub fn anchor(&self) -> ScrollAnchor { + pub const fn anchor(&self) -> ScrollAnchor { self.anchor } - pub fn ongoing_scroll(&self) -> OngoingScroll { + pub const fn ongoing_scroll(&self) -> OngoingScroll { self.ongoing } @@ -345,15 +345,15 @@ impl ScrollManager { } } - pub fn scrollbars_visible(&self) -> bool { + pub const fn scrollbars_visible(&self) -> bool { self.show_scrollbars } - pub fn take_autoscroll_request(&mut self) -> Option<(Autoscroll, bool)> { + pub const fn take_autoscroll_request(&mut self) -> Option<(Autoscroll, bool)> { self.autoscroll_request.take() } - pub fn active_scrollbar_state(&self) -> Option<&ActiveScrollbarState> { + pub const fn active_scrollbar_state(&self) -> Option<&ActiveScrollbarState> { self.active_scrollbar.as_ref() } @@ -440,7 +440,7 @@ impl ScrollManager { } } - pub fn minimap_thumb_state(&self) -> Option { + pub const fn minimap_thumb_state(&self) -> Option { self.minimap_thumb_state } @@ -453,17 +453,17 @@ impl ScrollManager { } } - pub fn set_forbid_vertical_scroll(&mut self, forbid: bool) { + pub const fn set_forbid_vertical_scroll(&mut self, forbid: bool) { self.forbid_vertical_scroll = forbid; } - pub fn forbid_vertical_scroll(&self) -> bool { + pub const fn forbid_vertical_scroll(&self) -> bool { self.forbid_vertical_scroll } } impl Editor { - pub fn vertical_scroll_margin(&self) -> usize { + pub const fn vertical_scroll_margin(&self) -> usize { self.scroll_manager.vertical_scroll_margin as usize } @@ -472,7 +472,7 @@ impl Editor { cx.notify(); } - pub fn visible_line_count(&self) -> Option { + pub const fn visible_line_count(&self) -> Option { self.scroll_manager.visible_line_count } @@ -481,7 +481,7 @@ impl Editor { .map(|line_count| line_count as u32 - 1) } - pub fn visible_column_count(&self) -> Option { + pub const fn visible_column_count(&self) -> Option { self.scroll_manager.visible_column_count } @@ -506,7 +506,7 @@ impl Editor { } } - pub(crate) fn set_visible_column_count(&mut self, columns: f64) { + pub(crate) const fn set_visible_column_count(&mut self, columns: f64) { self.scroll_manager.visible_column_count = Some(columns); } diff --git a/crates/editor/src/scroll/autoscroll.rs b/crates/editor/src/scroll/autoscroll.rs index 28fd9442193bbec663d3f72eaa805214375dd8ca..a07611941760331b8b0533cae2c85124cc5e0559 100644 --- a/crates/editor/src/scroll/autoscroll.rs +++ b/crates/editor/src/scroll/autoscroll.rs @@ -16,49 +16,49 @@ pub enum Autoscroll { impl Autoscroll { /// scrolls the minimal amount to (try) and fit all cursors onscreen - pub fn fit() -> Self { + pub const fn fit() -> Self { Self::Strategy(AutoscrollStrategy::Fit, None) } /// scrolls the minimal amount to fit the newest cursor - pub fn newest() -> Self { + pub const fn newest() -> Self { Self::Strategy(AutoscrollStrategy::Newest, None) } /// scrolls so the newest cursor is vertically centered - pub fn center() -> Self { + pub const fn center() -> Self { Self::Strategy(AutoscrollStrategy::Center, None) } /// scrolls so the newest cursor is near the top /// (offset by vertical_scroll_margin) - pub fn focused() -> Self { + pub const fn focused() -> Self { Self::Strategy(AutoscrollStrategy::Focused, None) } /// Scrolls so that the newest cursor is roughly an n-th line from the top. - pub fn top_relative(n: usize) -> Self { + pub const fn top_relative(n: usize) -> Self { Self::Strategy(AutoscrollStrategy::TopRelative(n), None) } /// Scrolls so that the newest cursor is at the top. - pub fn top() -> Self { + pub const fn top() -> Self { Self::Strategy(AutoscrollStrategy::Top, None) } /// Scrolls so that the newest cursor is roughly an n-th line from the bottom. - pub fn bottom_relative(n: usize) -> Self { + pub const fn bottom_relative(n: usize) -> Self { Self::Strategy(AutoscrollStrategy::BottomRelative(n), None) } /// Scrolls so that the newest cursor is at the bottom. - pub fn bottom() -> Self { + pub const fn bottom() -> Self { Self::Strategy(AutoscrollStrategy::Bottom, None) } /// Applies a given auto-scroll strategy to a given anchor instead of a cursor. /// E.G: Autoscroll::center().for_anchor(...) results in the anchor being at the center of the screen. - pub fn for_anchor(self, anchor: Anchor) -> Self { + pub const fn for_anchor(self, anchor: Anchor) -> Self { match self { Autoscroll::Next => self, Autoscroll::Strategy(autoscroll_strategy, _) => { @@ -91,7 +91,7 @@ pub enum AutoscrollStrategy { } impl AutoscrollStrategy { - fn next(&self) -> Self { + const fn next(&self) -> Self { match self { AutoscrollStrategy::Center => AutoscrollStrategy::Top, AutoscrollStrategy::Top => AutoscrollStrategy::Bottom, diff --git a/crates/editor/src/scroll/scroll_amount.rs b/crates/editor/src/scroll/scroll_amount.rs index 3280290d6e5ccc1ca3eecc3755c2039bd024cc24..f04a56af00f4ed8d1a0c3b3b36cda3879b4a4914 100644 --- a/crates/editor/src/scroll/scroll_amount.rs +++ b/crates/editor/src/scroll/scroll_amount.rs @@ -10,7 +10,7 @@ pub enum ScrollDirection { } impl ScrollDirection { - pub fn is_upwards(&self) -> bool { + pub const fn is_upwards(&self) -> bool { matches!(self, ScrollDirection::Upwards) } } @@ -70,7 +70,7 @@ impl ScrollAmount { matches!(self, ScrollAmount::Page(count) if count.abs() == 1.0) } - pub fn direction(&self) -> ScrollDirection { + pub const fn direction(&self) -> ScrollDirection { match self { Self::Line(amount) if amount.is_sign_positive() => ScrollDirection::Downwards, Self::Page(amount) if amount.is_sign_positive() => ScrollDirection::Downwards, diff --git a/crates/editor/src/selections_collection.rs b/crates/editor/src/selections_collection.rs index ab0e78595310da43b803cd53b9177dec53a37d81..a58ad15b11c79657718bc019cb2f191dd26c9e11 100644 --- a/crates/editor/src/selections_collection.rs +++ b/crates/editor/src/selections_collection.rs @@ -451,31 +451,31 @@ impl SelectionsCollection { (mutable_collection.selections_changed, result) } - pub fn next_selection_id(&self) -> usize { + pub const fn next_selection_id(&self) -> usize { self.next_selection_id } - pub fn line_mode(&self) -> bool { + pub const fn line_mode(&self) -> bool { self.line_mode } - pub fn set_line_mode(&mut self, line_mode: bool) { + pub const fn set_line_mode(&mut self, line_mode: bool) { self.line_mode = line_mode; } - pub fn select_mode(&self) -> &SelectMode { + pub const fn select_mode(&self) -> &SelectMode { &self.select_mode } - pub fn set_select_mode(&mut self, select_mode: SelectMode) { + pub const fn set_select_mode(&mut self, select_mode: SelectMode) { self.select_mode = select_mode; } - pub fn is_extending(&self) -> bool { + pub const fn is_extending(&self) -> bool { self.is_extending } - pub fn set_is_extending(&mut self, is_extending: bool) { + pub const fn set_is_extending(&mut self, is_extending: bool) { self.is_extending = is_extending; } } @@ -524,7 +524,7 @@ impl<'a> MutableSelectionsCollection<'a> { self.selections_changed |= changed; } - pub fn clear_pending(&mut self) { + pub const fn clear_pending(&mut self) { if self.collection.pending.is_some() { self.collection.pending = None; self.selections_changed = true; @@ -556,7 +556,7 @@ impl<'a> MutableSelectionsCollection<'a> { self.selections_changed = true; } - pub(crate) fn set_pending(&mut self, selection: Selection, mode: SelectMode) { + pub(crate) const fn set_pending(&mut self, selection: Selection, mode: SelectMode) { self.collection.pending = Some(PendingSelection { selection, mode }); self.selections_changed = true; } diff --git a/crates/editor/src/signature_help.rs b/crates/editor/src/signature_help.rs index 6abd3e48880a59f3ce74511013bcd048ad5a2a51..1196c37551f5c67a424cdf2c13a456aa592702ea 100644 --- a/crates/editor/src/signature_help.rs +++ b/crates/editor/src/signature_help.rs @@ -276,7 +276,7 @@ impl SignatureHelpState { self.popover.as_ref() } - pub fn popover_mut(&mut self) -> Option<&mut SignatureHelpPopover> { + pub const fn popover_mut(&mut self) -> Option<&mut SignatureHelpPopover> { self.popover.as_mut() } @@ -296,7 +296,7 @@ impl SignatureHelpState { self.hidden_by == Some(SignatureHelpHiddenBy::Selection) } - pub fn is_shown(&self) -> bool { + pub const fn is_shown(&self) -> bool { self.popover.is_some() } diff --git a/crates/extension/src/extension_events.rs b/crates/extension/src/extension_events.rs index 6dc99470dfb5abad524e5a7cbc326b2dd5e0bd26..3ce5e39fd0d1e79afda80114c53757e733a2c12c 100644 --- a/crates/extension/src/extension_events.rs +++ b/crates/extension/src/extension_events.rs @@ -23,7 +23,7 @@ impl ExtensionEvents { .map(|g| g.0.clone()) } - fn new(_cx: &mut Context) -> Self { + const fn new(_cx: &mut Context) -> Self { Self } diff --git a/crates/extension_api/src/http_client.rs b/crates/extension_api/src/http_client.rs index 9e30da8db4856635460c7636f0698fef34266797..e8c69ab2c4f6c608460d751cda15c534b517f9b7 100644 --- a/crates/extension_api/src/http_client.rs +++ b/crates/extension_api/src/http_client.rs @@ -6,7 +6,7 @@ pub use crate::wit::zed::extension::http_client::{ impl HttpRequest { /// Returns a builder for an [`HttpRequest`]. - pub fn builder() -> HttpRequestBuilder { + pub const fn builder() -> HttpRequestBuilder { HttpRequestBuilder::new() } @@ -39,7 +39,7 @@ impl Default for HttpRequestBuilder { impl HttpRequestBuilder { /// Returns a new [`HttpRequestBuilder`]. - pub fn new() -> Self { + pub const fn new() -> Self { HttpRequestBuilder { method: None, url: None, @@ -50,7 +50,7 @@ impl HttpRequestBuilder { } /// Sets the HTTP method for the request. - pub fn method(mut self, method: HttpMethod) -> Self { + pub const fn method(mut self, method: HttpMethod) -> Self { self.method = Some(method); self } @@ -80,7 +80,7 @@ impl HttpRequestBuilder { } /// Sets the redirect policy for the request. - pub fn redirect_policy(mut self, policy: RedirectPolicy) -> Self { + pub const fn redirect_policy(mut self, policy: RedirectPolicy) -> Self { self.redirect_policy = policy; self } diff --git a/crates/extension_host/src/capability_granter.rs b/crates/extension_host/src/capability_granter.rs index 5491967e080fc4d12a52f0360dab1896b77e19d3..bfd6961ceb7a646ebdf41667f5f35b8f3f4f1990 100644 --- a/crates/extension_host/src/capability_granter.rs +++ b/crates/extension_host/src/capability_granter.rs @@ -10,7 +10,7 @@ pub struct CapabilityGranter { } impl CapabilityGranter { - pub fn new( + pub const fn new( granted_capabilities: Vec, manifest: Arc, ) -> Self { diff --git a/crates/extension_host/src/extension_host.rs b/crates/extension_host/src/extension_host.rs index 3397f770c241ab0b29deab661e014811fed7f852..ddd3e74dce1cd6cd7acfd4c81a8464b457ff84ca 100644 --- a/crates/extension_host/src/extension_host.rs +++ b/crates/extension_host/src/extension_host.rs @@ -80,7 +80,7 @@ const CURRENT_SCHEMA_VERSION: SchemaVersion = SchemaVersion(1); const SUPPRESSED_EXTENSIONS: &[&str] = &["snippets", "ruff", "ty", "basedpyright"]; /// Returns the [`SchemaVersion`] range that is compatible with this version of Zed. -pub fn schema_version_range() -> RangeInclusive { +pub const fn schema_version_range() -> RangeInclusive { SchemaVersion::ZERO..=CURRENT_SCHEMA_VERSION } @@ -428,11 +428,11 @@ impl ExtensionStore { self.installed_dir.clone() } - pub fn outstanding_operations(&self) -> &BTreeMap, ExtensionOperation> { + pub const fn outstanding_operations(&self) -> &BTreeMap, ExtensionOperation> { &self.outstanding_operations } - pub fn installed_extensions(&self) -> &BTreeMap, ExtensionIndexEntry> { + pub const fn installed_extensions(&self) -> &BTreeMap, ExtensionIndexEntry> { &self.extension_index.extensions } diff --git a/crates/extension_host/src/wasm_host/wit.rs b/crates/extension_host/src/wasm_host/wit.rs index 1f1fa49bd535ad19f4981eeed9fcdca1ba9421a9..2af3c5444aea0bcd3cca5e5e9da70bed202a734a 100644 --- a/crates/extension_host/src/wasm_host/wit.rs +++ b/crates/extension_host/src/wasm_host/wit.rs @@ -49,7 +49,7 @@ pub fn new_linker( linker } -fn wasi_view(state: &mut WasmState) -> &mut WasmState { +const fn wasi_view(state: &mut WasmState) -> &mut WasmState { state } @@ -63,7 +63,7 @@ pub fn is_supported_wasm_api_version( /// Returns the Wasm API version range that is supported by the Wasm host. #[inline(always)] -pub fn wasm_api_version_range(release_channel: ReleaseChannel) -> RangeInclusive { +pub const fn wasm_api_version_range(release_channel: ReleaseChannel) -> RangeInclusive { // Note: The release channel can be used to stage a new version of the extension API. let _ = release_channel; diff --git a/crates/extensions_ui/src/components/extension_card.rs b/crates/extensions_ui/src/components/extension_card.rs index abdd32fee99cd056e9fece60a2ff7646f55cd264..02238d9af347c833efa7e6c62cd212883f9cd7ad 100644 --- a/crates/extensions_ui/src/components/extension_card.rs +++ b/crates/extensions_ui/src/components/extension_card.rs @@ -16,7 +16,7 @@ impl ExtensionCard { } } - pub fn overridden_by_dev_extension(mut self, overridden: bool) -> Self { + pub const fn overridden_by_dev_extension(mut self, overridden: bool) -> Self { self.overridden_by_dev_extension = overridden; self } diff --git a/crates/extensions_ui/src/extensions_ui.rs b/crates/extensions_ui/src/extensions_ui.rs index dc40bad4e0476f5e714aa24fa3ef4d618d2bdcc9..40733d0465f7c9cb2e7c9594fcb077e277687c4c 100644 --- a/crates/extensions_ui/src/extensions_ui.rs +++ b/crates/extensions_ui/src/extensions_ui.rs @@ -181,7 +181,7 @@ pub fn init(cx: &mut App) { .detach(); } -fn extension_provides_label(provides: ExtensionProvides) -> &'static str { +const fn extension_provides_label(provides: ExtensionProvides) -> &'static str { match provides { ExtensionProvides::Themes => "Themes", ExtensionProvides::IconThemes => "Icon Themes", @@ -213,7 +213,7 @@ enum ExtensionFilter { } impl ExtensionFilter { - pub fn include_dev_extensions(&self) -> bool { + pub const fn include_dev_extensions(&self) -> bool { match self { Self::All | Self::Installed => true, Self::NotInstalled => false, diff --git a/crates/file_finder/src/file_finder.rs b/crates/file_finder/src/file_finder.rs index 9e813bcb782c2e2f8e86e1e6a019d890c203b1b5..0ea642864e10fd5073d12c455ffe35a8153dbaeb 100644 --- a/crates/file_finder/src/file_finder.rs +++ b/crates/file_finder/src/file_finder.rs @@ -466,7 +466,7 @@ enum Match { } impl Match { - fn relative_path(&self) -> Option<&Arc> { + const fn relative_path(&self) -> Option<&Arc> { match self { Match::History { path, .. } => Some(&path.project.path), Match::Search(panel_match) => Some(&panel_match.0.path), @@ -488,7 +488,7 @@ impl Match { } } - fn panel_match(&self) -> Option<&ProjectPanelOrdMatch> { + const fn panel_match(&self) -> Option<&ProjectPanelOrdMatch> { match self { Match::History { panel_match, .. } => panel_match.as_ref(), Match::Search(panel_match) => Some(panel_match), @@ -498,7 +498,7 @@ impl Match { } impl Matches { - fn len(&self) -> usize { + const fn len(&self) -> usize { self.matches.len() } @@ -771,7 +771,7 @@ struct FoundPath { } impl FoundPath { - fn new(project: ProjectPath, absolute: PathBuf) -> Self { + const fn new(project: ProjectPath, absolute: PathBuf) -> Self { Self { project, absolute } } } diff --git a/crates/file_finder/src/open_path_prompt.rs b/crates/file_finder/src/open_path_prompt.rs index 694ef1eaceb720c3b63d4ca9d243ab73e9442970..83d39493892a14ecd72ba4ff19c862f2cf13dc83 100644 --- a/crates/file_finder/src/open_path_prompt.rs +++ b/crates/file_finder/src/open_path_prompt.rs @@ -77,7 +77,7 @@ impl OpenPathDelegate { self } - pub fn show_hidden(mut self) -> Self { + pub const fn show_hidden(mut self) -> Self { self.hidden_entries = true; self } @@ -144,7 +144,7 @@ impl OpenPathDelegate { } } - fn current_dir(&self) -> &'static str { + const fn current_dir(&self) -> &'static str { match self.path_style { PathStyle::Posix => "./", PathStyle::Windows => ".\\", diff --git a/crates/fs/src/fs.rs b/crates/fs/src/fs.rs index 9907d0dcbde489b4f4de57133baf299ad0be14a1..38d84be8d86f012e21019588fa4451c929e97b9b 100644 --- a/crates/fs/src/fs.rs +++ b/crates/fs/src/fs.rs @@ -229,7 +229,7 @@ impl MTime { /// Returns the value wrapped by this `MTime`, for presentation to the user. The name including /// "_for_user" is to discourage misuse - this method should not be used when making decisions /// about file dirtiness. - pub fn timestamp_for_user(self) -> SystemTime { + pub const fn timestamp_for_user(self) -> SystemTime { self.0 } @@ -328,7 +328,7 @@ impl FileHandle for std::fs::File { pub struct RealWatcher {} impl RealFs { - pub fn new(git_binary_path: Option, executor: BackgroundExecutor) -> Self { + pub const fn new(git_binary_path: Option, executor: BackgroundExecutor) -> Self { Self { bundled_git_binary_path: git_binary_path, executor, diff --git a/crates/fs/src/mac_watcher.rs b/crates/fs/src/mac_watcher.rs index b781a231ba2bc33a895480ea278a7ccfe3364fe7..1b241bff5df4d19f5027922efe933cc2779404f6 100644 --- a/crates/fs/src/mac_watcher.rs +++ b/crates/fs/src/mac_watcher.rs @@ -17,7 +17,7 @@ pub struct MacWatcher { } impl MacWatcher { - pub fn new( + pub const fn new( events_tx: smol::channel::Sender>, handles: Weak>>, latency: Duration, diff --git a/crates/fuzzy/src/char_bag.rs b/crates/fuzzy/src/char_bag.rs index 13b00816ed0141117fb6d5ac9265e4b82c7aa57d..66d7f3d9d67a104118c475bf92c1ba89360bd034 100644 --- a/crates/fuzzy/src/char_bag.rs +++ b/crates/fuzzy/src/char_bag.rs @@ -4,11 +4,11 @@ use std::iter::FromIterator; pub struct CharBag(u64); impl CharBag { - pub fn is_superset(self, other: CharBag) -> bool { + pub const fn is_superset(self, other: CharBag) -> bool { self.0 & other.0 == other.0 } - fn insert(&mut self, c: char) { + const fn insert(&mut self, c: char) { let c = c.to_ascii_lowercase(); if c.is_ascii_lowercase() { let mut count = self.0; diff --git a/crates/git/src/repository.rs b/crates/git/src/repository.rs index 2e132d4eaca55c9307bf3368c412f77ed6726df2..3f5f3c77f77571ced3ce77a43b573ff6a6579a40 100644 --- a/crates/git/src/repository.rs +++ b/crates/git/src/repository.rs @@ -115,11 +115,11 @@ impl From for UpstreamTracking { } impl UpstreamTracking { - pub fn is_gone(&self) -> bool { + pub const fn is_gone(&self) -> bool { matches!(self, UpstreamTracking::Gone) } - pub fn status(&self) -> Option { + pub const fn status(&self) -> Option { match self { UpstreamTracking::Gone => None, UpstreamTracking::Tracked(status) => Some(*status), @@ -134,7 +134,7 @@ pub struct RemoteCommandOutput { } impl RemoteCommandOutput { - pub fn is_empty(&self) -> bool { + pub const fn is_empty(&self) -> bool { self.stdout.is_empty() && self.stderr.is_empty() } } diff --git a/crates/git/src/status.rs b/crates/git/src/status.rs index c3f28aa2040446822f81990804a63fcb5a53300c..08408a3f66be7d6b718a08a319b5cec8484a6951 100644 --- a/crates/git/src/status.rs +++ b/crates/git/src/status.rs @@ -62,23 +62,23 @@ pub enum StageStatus { } impl StageStatus { - pub fn is_fully_staged(&self) -> bool { + pub const fn is_fully_staged(&self) -> bool { matches!(self, StageStatus::Staged) } - pub fn is_fully_unstaged(&self) -> bool { + pub const fn is_fully_unstaged(&self) -> bool { matches!(self, StageStatus::Unstaged) } - pub fn has_staged(&self) -> bool { + pub const fn has_staged(&self) -> bool { matches!(self, StageStatus::Staged | StageStatus::PartiallyStaged) } - pub fn has_unstaged(&self) -> bool { + pub const fn has_unstaged(&self) -> bool { matches!(self, StageStatus::Unstaged | StageStatus::PartiallyStaged) } - pub fn as_bool(self) -> Option { + pub const fn as_bool(self) -> Option { match self { StageStatus::Staged => Some(true), StageStatus::Unstaged => Some(false), @@ -139,7 +139,7 @@ impl FileStatus { Ok(status) } - pub fn staging(self) -> StageStatus { + pub const fn staging(self) -> StageStatus { match self { FileStatus::Untracked | FileStatus::Ignored | FileStatus::Unmerged { .. } => { StageStatus::Unstaged @@ -152,15 +152,15 @@ impl FileStatus { } } - pub fn is_conflicted(self) -> bool { + pub const fn is_conflicted(self) -> bool { matches!(self, FileStatus::Unmerged { .. }) } - pub fn is_ignored(self) -> bool { + pub const fn is_ignored(self) -> bool { matches!(self, FileStatus::Ignored) } - pub fn has_changes(&self) -> bool { + pub const fn has_changes(&self) -> bool { self.is_modified() || self.is_created() || self.is_deleted() @@ -168,7 +168,7 @@ impl FileStatus { || self.is_conflicted() } - pub fn is_modified(self) -> bool { + pub const fn is_modified(self) -> bool { match self { FileStatus::Tracked(tracked) => matches!( (tracked.index_status, tracked.worktree_status), @@ -178,7 +178,7 @@ impl FileStatus { } } - pub fn is_created(self) -> bool { + pub const fn is_created(self) -> bool { match self { FileStatus::Tracked(tracked) => matches!( (tracked.index_status, tracked.worktree_status), @@ -189,15 +189,15 @@ impl FileStatus { } } - pub fn is_deleted(self) -> bool { + pub const fn is_deleted(self) -> bool { matches!(self, FileStatus::Tracked(tracked) if matches!((tracked.index_status, tracked.worktree_status), (StatusCode::Deleted, _) | (_, StatusCode::Deleted))) } - pub fn is_untracked(self) -> bool { + pub const fn is_untracked(self) -> bool { matches!(self, FileStatus::Untracked) } - pub fn summary(self) -> GitSummary { + pub const fn summary(self) -> GitSummary { match self { FileStatus::Ignored => GitSummary::UNCHANGED, FileStatus::Untracked => GitSummary::UNTRACKED, @@ -230,7 +230,7 @@ impl StatusCode { } } - fn to_summary(self) -> TrackedSummary { + const fn to_summary(self) -> TrackedSummary { match self { StatusCode::Modified | StatusCode::TypeChanged => TrackedSummary { modified: 1, @@ -250,14 +250,14 @@ impl StatusCode { } } - pub fn index(self) -> FileStatus { + pub const fn index(self) -> FileStatus { FileStatus::Tracked(TrackedStatus { index_status: self, worktree_status: StatusCode::Unmodified, }) } - pub fn worktree(self) -> FileStatus { + pub const fn worktree(self) -> FileStatus { FileStatus::Tracked(TrackedStatus { index_status: StatusCode::Unmodified, worktree_status: self, diff --git a/crates/git_ui/src/commit_tooltip.rs b/crates/git_ui/src/commit_tooltip.rs index 84ecc0b3a9c0c708ec81a0af1234506ec0208cd0..1d19de0c91a1ddffbc6301aece588cd519343845 100644 --- a/crates/git_ui/src/commit_tooltip.rs +++ b/crates/git_ui/src/commit_tooltip.rs @@ -33,7 +33,7 @@ pub struct CommitAvatar<'a> { } impl<'a> CommitAvatar<'a> { - pub fn new(sha: &'a SharedString, remote: Option<&'a GitRemote>) -> Self { + pub const fn new(sha: &'a SharedString, remote: Option<&'a GitRemote>) -> Self { Self { sha, remote } } @@ -83,7 +83,7 @@ impl Hash for CommitAvatarAsset { } impl CommitAvatarAsset { - fn new(remote: GitRemote, sha: SharedString) -> Self { + const fn new(remote: GitRemote, sha: SharedString) -> Self { Self { remote, sha } } } diff --git a/crates/git_ui/src/git_panel.rs b/crates/git_ui/src/git_panel.rs index ce6ddf43f6dbf1e4df32c45f7c96f7c08447df06..6c41b79cb2c6c4cab6170521bc7a729810f18938 100644 --- a/crates/git_ui/src/git_panel.rs +++ b/crates/git_ui/src/git_panel.rs @@ -225,7 +225,7 @@ impl GitHeaderEntry { Section::New => status.is_created(), } } - pub fn title(&self) -> &'static str { + pub const fn title(&self) -> &'static str { match self.header { Section::Conflict => "Conflicts", Section::Tracked => "Tracked", @@ -241,7 +241,7 @@ enum GitListEntry { } impl GitListEntry { - fn status_entry(&self) -> Option<&GitStatusEntry> { + const fn status_entry(&self) -> Option<&GitStatusEntry> { match self { GitListEntry::Status(entry) => Some(entry), _ => None, @@ -1333,7 +1333,7 @@ impl GitPanel { .detach(); } - pub fn total_staged_count(&self) -> usize { + pub const fn total_staged_count(&self) -> usize { self.tracked_staged_count + self.new_staged_count + self.conflicted_staged_count } @@ -2807,7 +2807,7 @@ impl GitPanel { cx.notify(); } - fn header_state(&self, header_type: Section) -> ToggleState { + const fn header_state(&self, header_type: Section) -> ToggleState { let (staged_count, count) = match header_type { Section::New => (self.new_staged_count, self.new_count), Section::Tracked => (self.tracked_staged_count, self.tracked_count), @@ -2873,23 +2873,23 @@ impl GitPanel { entry.staging } - pub(crate) fn has_staged_changes(&self) -> bool { + pub(crate) const fn has_staged_changes(&self) -> bool { self.tracked_staged_count > 0 || self.new_staged_count > 0 || self.conflicted_staged_count > 0 } - pub(crate) fn has_unstaged_changes(&self) -> bool { + pub(crate) const fn has_unstaged_changes(&self) -> bool { self.tracked_count > self.tracked_staged_count || self.new_count > self.new_staged_count || self.conflicted_count > self.conflicted_staged_count } - fn has_tracked_changes(&self) -> bool { + const fn has_tracked_changes(&self) -> bool { self.tracked_count > 0 } - pub fn has_unstaged_conflicts(&self) -> bool { + pub const fn has_unstaged_conflicts(&self) -> bool { self.conflicted_count > 0 && self.conflicted_count != self.conflicted_staged_count } @@ -3004,21 +3004,21 @@ impl GitPanel { workspace.add_item_to_center(Box::new(editor), window, cx); } - pub fn can_commit(&self) -> bool { + pub const fn can_commit(&self) -> bool { (self.has_staged_changes() || self.has_tracked_changes()) && !self.has_unstaged_conflicts() } - pub fn can_stage_all(&self) -> bool { + pub const fn can_stage_all(&self) -> bool { self.has_unstaged_changes() } - pub fn can_unstage_all(&self) -> bool { + pub const fn can_unstage_all(&self) -> bool { self.has_staged_changes() } // eventually we'll need to take depth into account here // if we add a tree view - fn item_width_estimate(path: usize, file_name: usize) -> usize { + const fn item_width_estimate(path: usize, file_name: usize) -> usize { path + file_name } @@ -3235,7 +3235,7 @@ impl GitPanel { } } - pub fn commit_button_title(&self) -> &'static str { + pub const fn commit_button_title(&self) -> &'static str { if self.amend_pending { if self.has_staged_changes() { "Amend" @@ -3822,7 +3822,7 @@ impl GitPanel { Label::new(label.into()).color(color).single_line() } - fn list_item_height(&self) -> Rems { + const fn list_item_height(&self) -> Rems { rems(1.75) } @@ -4160,7 +4160,7 @@ impl GitPanel { !self.project.read(cx).is_read_only(cx) } - pub fn amend_pending(&self) -> bool { + pub const fn amend_pending(&self) -> bool { self.amend_pending } @@ -4186,7 +4186,7 @@ impl GitPanel { cx.notify(); } - pub fn signoff_enabled(&self) -> bool { + pub const fn signoff_enabled(&self) -> bool { self.signoff_enabled } @@ -4535,7 +4535,7 @@ pub struct PanelRepoFooter { } impl PanelRepoFooter { - pub fn new( + pub const fn new( active_repository: SharedString, branch: Option, head_commit: Option, @@ -4549,7 +4549,7 @@ impl PanelRepoFooter { } } - pub fn new_preview(active_repository: SharedString, branch: Option) -> Self { + pub const fn new_preview(active_repository: SharedString, branch: Option) -> Self { Self { active_repository, branch, diff --git a/crates/git_ui/src/git_ui.rs b/crates/git_ui/src/git_ui.rs index da2e2ca032aa005ad619eabf094ae6981975b050..a622372d1b7287539c85c6b83adb008d59d9857c 100644 --- a/crates/git_ui/src/git_ui.rs +++ b/crates/git_ui/src/git_ui.rs @@ -687,7 +687,7 @@ pub struct GitStatusIcon { } impl GitStatusIcon { - pub fn new(status: FileStatus) -> Self { + pub const fn new(status: FileStatus) -> Self { Self { status } } } @@ -729,7 +729,7 @@ impl Component for GitStatusIcon { } fn preview(_window: &mut Window, _cx: &mut App) -> Option { - fn tracked_file_status(code: StatusCode) -> FileStatus { + const fn tracked_file_status(code: StatusCode) -> FileStatus { FileStatus::Tracked(git::status::TrackedStatus { index_status: code, worktree_status: code, diff --git a/crates/git_ui/src/picker_prompt.rs b/crates/git_ui/src/picker_prompt.rs index 6161c62af571f3a90c3110d63cc26ea3a7e032ae..4c560e8aa26daff6f52db43a429e64d537f37652 100644 --- a/crates/git_ui/src/picker_prompt.rs +++ b/crates/git_ui/src/picker_prompt.rs @@ -98,7 +98,7 @@ pub struct PickerPromptDelegate { } impl PickerPromptDelegate { - pub fn new( + pub const fn new( prompt: Arc, options: Vec, tx: oneshot::Sender, diff --git a/crates/git_ui/src/remote_output.rs b/crates/git_ui/src/remote_output.rs index 8437bf0d0d37c2b2767624110fed056bbae25d05..fbd059475c063f20be81344cedc3803f7ee84b86 100644 --- a/crates/git_ui/src/remote_output.rs +++ b/crates/git_ui/src/remote_output.rs @@ -12,7 +12,7 @@ pub enum RemoteAction { } impl RemoteAction { - pub fn name(&self) -> &'static str { + pub const fn name(&self) -> &'static str { match self { RemoteAction::Fetch(_) => "fetch", RemoteAction::Pull(_) => "pull", diff --git a/crates/google_ai/src/google_ai.rs b/crates/google_ai/src/google_ai.rs index 9b7e5ec8d1c42fc846d131cfd063de5bba8287ae..accb150dddee1108be825a2c066cfcfb966823cc 100644 --- a/crates/google_ai/src/google_ai.rs +++ b/crates/google_ai/src/google_ai.rs @@ -442,7 +442,7 @@ pub struct ModelName { } impl ModelName { - pub fn is_empty(&self) -> bool { + pub const fn is_empty(&self) -> bool { self.model_id.is_empty() } } @@ -529,7 +529,7 @@ pub enum Model { } impl Model { - pub fn default_fast() -> Self { + pub const fn default_fast() -> Self { Self::Gemini20FlashLite } @@ -576,7 +576,7 @@ impl Model { } } - pub fn max_token_count(&self) -> u64 { + pub const fn max_token_count(&self) -> u64 { match self { Self::Gemini15Pro => 2_097_152, Self::Gemini15Flash8b => 1_048_576, @@ -590,7 +590,7 @@ impl Model { } } - pub fn max_output_tokens(&self) -> Option { + pub const fn max_output_tokens(&self) -> Option { match self { Model::Gemini15Pro => Some(8_192), Model::Gemini15Flash8b => Some(8_192), @@ -604,15 +604,15 @@ impl Model { } } - pub fn supports_tools(&self) -> bool { + pub const fn supports_tools(&self) -> bool { true } - pub fn supports_images(&self) -> bool { + pub const fn supports_images(&self) -> bool { true } - pub fn mode(&self) -> GoogleModelMode { + pub const fn mode(&self) -> GoogleModelMode { match self { Self::Gemini15Pro | Self::Gemini15Flash8b diff --git a/crates/gpui/src/action.rs b/crates/gpui/src/action.rs index 38e94aa356dcb7ea1f0f988d1407471bfc0d3a84..0caafa6e5a67de850f4f586307abd424648a53b1 100644 --- a/crates/gpui/src/action.rs +++ b/crates/gpui/src/action.rs @@ -376,7 +376,7 @@ impl ActionRegistry { }) } - pub fn all_action_names(&self) -> &[&'static str] { + pub const fn all_action_names(&self) -> &[&'static str] { self.all_names.as_slice() } @@ -397,15 +397,15 @@ impl ActionRegistry { .collect::>() } - pub fn deprecated_aliases(&self) -> &HashMap<&'static str, &'static str> { + pub const fn deprecated_aliases(&self) -> &HashMap<&'static str, &'static str> { &self.deprecated_aliases } - pub fn deprecation_messages(&self) -> &HashMap<&'static str, &'static str> { + pub const fn deprecation_messages(&self) -> &HashMap<&'static str, &'static str> { &self.deprecation_messages } - pub fn documentation(&self) -> &HashMap<&'static str, &'static str> { + pub const fn documentation(&self) -> &HashMap<&'static str, &'static str> { &self.documentation } } diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index 07ff04e32abc19dbe681ab6214d06469fe7917ff..52e9e27b5c235077b4f6a16b0b0ec11da5e82197 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -283,7 +283,7 @@ impl SystemWindowTabController { } /// Get all tab groups. - pub fn tab_groups(&self) -> &FxHashMap> { + pub const fn tab_groups(&self) -> &FxHashMap> { &self.tab_groups } @@ -766,7 +766,7 @@ impl App { result } - pub(crate) fn start_update(&mut self) { + pub(crate) const fn start_update(&mut self) { self.pending_updates += 1; } @@ -1402,7 +1402,7 @@ impl App { } /// Obtains a reference to the executor, which can be used to spawn futures. - pub fn background_executor(&self) -> &BackgroundExecutor { + pub const fn background_executor(&self) -> &BackgroundExecutor { &self.background_executor } @@ -1446,7 +1446,7 @@ impl App { } /// Accessor for the text system. - pub fn text_system(&self) -> &Arc { + pub const fn text_system(&self) -> &Arc { &self.text_system } @@ -1712,7 +1712,7 @@ impl App { /// event handlers with a lower z-index (mouse) or higher in the tree (keyboard). This is /// the opposite of [`Self::propagate`]. It's also possible to cancel a call to [`Self::propagate`] by /// calling this method before effects are flushed. - pub fn stop_propagation(&mut self) { + pub const fn stop_propagation(&mut self) { self.propagate_event = false; } @@ -1720,7 +1720,7 @@ impl App { /// dispatching to action handlers higher in the element tree. This is the opposite of /// [`Self::stop_propagation`]. It's also possible to cancel a call to [`Self::stop_propagation`] by calling /// this method before effects are flushed. - pub fn propagate(&mut self) { + pub const fn propagate(&mut self) { self.propagate_event = true; } @@ -1939,7 +1939,7 @@ impl App { } /// Is there currently something being dragged? - pub fn has_active_drag(&self) -> bool { + pub const fn has_active_drag(&self) -> bool { self.active_drag.is_some() } @@ -2058,7 +2058,7 @@ impl App { /// Returns the name for this [`App`]. #[cfg(any(test, feature = "test-support", debug_assertions))] - pub fn get_name(&self) -> Option<&'static str> { + pub const fn get_name(&self) -> Option<&'static str> { self.name } diff --git a/crates/gpui/src/app/async_context.rs b/crates/gpui/src/app/async_context.rs index cfe7a5a75c258d09194c7d77a117208161713c6f..d7a87c835a95137c5d4148626693d20ef082689e 100644 --- a/crates/gpui/src/app/async_context.rs +++ b/crates/gpui/src/app/async_context.rs @@ -129,12 +129,12 @@ impl AsyncApp { } /// Get an executor which can be used to spawn futures in the background. - pub fn background_executor(&self) -> &BackgroundExecutor { + pub const fn background_executor(&self) -> &BackgroundExecutor { &self.background_executor } /// Get an executor which can be used to spawn futures in the foreground. - pub fn foreground_executor(&self) -> &ForegroundExecutor { + pub const fn foreground_executor(&self) -> &ForegroundExecutor { &self.foreground_executor } @@ -271,12 +271,12 @@ pub struct AsyncWindowContext { } impl AsyncWindowContext { - pub(crate) fn new_context(app: AsyncApp, window: AnyWindowHandle) -> Self { + pub(crate) const fn new_context(app: AsyncApp, window: AnyWindowHandle) -> Self { Self { app, window } } /// Get the handle of the window this context is associated with. - pub fn window_handle(&self) -> AnyWindowHandle { + pub const fn window_handle(&self) -> AnyWindowHandle { self.window } diff --git a/crates/gpui/src/app/context.rs b/crates/gpui/src/app/context.rs index 41d6cac82b7c179040d61ddfd22b003c143a5fb9..b469058b498a7bb2956ff80fc57a888dd0a327a6 100644 --- a/crates/gpui/src/app/context.rs +++ b/crates/gpui/src/app/context.rs @@ -37,7 +37,7 @@ impl<'a, T> ops::DerefMut for Context<'a, T> { } impl<'a, T: 'static> Context<'a, T> { - pub(crate) fn new_context(app: &'a mut App, entity_state: WeakEntity) -> Self { + pub(crate) const fn new_context(app: &'a mut App, entity_state: WeakEntity) -> Self { Self { app, entity_state } } diff --git a/crates/gpui/src/app/entity_map.rs b/crates/gpui/src/app/entity_map.rs index bea98cb06a5f80fc8141a52bc47f48e8734b40c9..3aa50093318dab5752bfbed3b22cba70bc19130f 100644 --- a/crates/gpui/src/app/entity_map.rs +++ b/crates/gpui/src/app/entity_map.rs @@ -244,12 +244,12 @@ impl AnyEntity { } /// Returns the id associated with this entity. - pub fn entity_id(&self) -> EntityId { + pub const fn entity_id(&self) -> EntityId { self.entity_id } /// Returns the [TypeId] associated with this entity. - pub fn entity_type(&self) -> TypeId { + pub const fn entity_type(&self) -> TypeId { self.entity_type } @@ -395,7 +395,7 @@ impl Entity { } /// Get the entity ID associated with this entity - pub fn entity_id(&self) -> EntityId { + pub const fn entity_id(&self) -> EntityId { self.any_entity.entity_id } @@ -520,7 +520,7 @@ pub struct AnyWeakEntity { impl AnyWeakEntity { /// Get the entity ID associated with this weak reference. - pub fn entity_id(&self) -> EntityId { + pub const fn entity_id(&self) -> EntityId { self.entity_id } diff --git a/crates/gpui/src/arena.rs b/crates/gpui/src/arena.rs index 9898c8056ab0240abd32ee34992dbe96f8ebab57..68aec045cf6de60a8eb089f1e43cf8ff24dc810d 100644 --- a/crates/gpui/src/arena.rs +++ b/crates/gpui/src/arena.rs @@ -64,7 +64,7 @@ impl Chunk { } } - fn reset(&mut self) { + const fn reset(&mut self) { self.offset = self.start; } } @@ -95,7 +95,7 @@ impl Arena { } } - pub fn capacity(&self) -> usize { + pub const fn capacity(&self) -> usize { self.chunks.len() * self.chunk_size.get() } diff --git a/crates/gpui/src/bounds_tree.rs b/crates/gpui/src/bounds_tree.rs index a96bfe55b9ff431a96da7bf42692288264eb184c..4a534060603f02fa091798ed4a17e82f9cff4cf5 100644 --- a/crates/gpui/src/bounds_tree.rs +++ b/crates/gpui/src/bounds_tree.rs @@ -216,14 +216,14 @@ impl Node where U: Clone + Debug + Default + PartialEq, { - fn bounds(&self) -> &Bounds { + const fn bounds(&self) -> &Bounds { match self { Node::Leaf { bounds, .. } => bounds, Node::Internal { bounds, .. } => bounds, } } - fn max_ordering(&self) -> u32 { + const fn max_ordering(&self) -> u32 { match self { Node::Leaf { order: ordering, .. diff --git a/crates/gpui/src/color.rs b/crates/gpui/src/color.rs index 3af5731bb57dad81a522d93a77c0aec871ae47cb..d04c91deb9ef4c3ccc8e2a2f159ccedece2be04c 100644 --- a/crates/gpui/src/color.rs +++ b/crates/gpui/src/color.rs @@ -333,7 +333,7 @@ impl Display for Hsla { } /// Construct an [`Hsla`] object from plain values -pub fn hsla(h: f32, s: f32, l: f32, a: f32) -> Hsla { +pub const fn hsla(h: f32, s: f32, l: f32, a: f32) -> Hsla { Hsla { h: h.clamp(0., 1.), s: s.clamp(0., 1.), @@ -373,7 +373,7 @@ pub const fn transparent_white() -> Hsla { } /// Opaque grey in [`Hsla`], values will be clamped to the range [0, 1] -pub fn opaque_grey(lightness: f32, opacity: f32) -> Hsla { +pub const fn opaque_grey(lightness: f32, opacity: f32) -> Hsla { Hsla { h: 0., s: 0., @@ -505,7 +505,7 @@ impl Hsla { } /// Returns a new HSLA color with the same hue, and lightness, but with no saturation. - pub fn grayscale(&self) -> Self { + pub const fn grayscale(&self) -> Self { Hsla { h: self.h, s: 0., @@ -576,7 +576,7 @@ impl Hsla { /// ``` /// /// This will return a blue color with 25% opacity. - pub fn alpha(&self, a: f32) -> Self { + pub const fn alpha(&self, a: f32) -> Self { Hsla { h: self.h, s: self.s, @@ -811,7 +811,7 @@ impl Background { /// Use specified color space for color interpolation. /// /// - pub fn color_space(mut self, color_space: ColorSpace) -> Self { + pub const fn color_space(mut self, color_space: ColorSpace) -> Self { self.color_space = color_space; self } diff --git a/crates/gpui/src/element.rs b/crates/gpui/src/element.rs index a3fc6269f33d8726b55f8e8be4aadb52109a7606..e5c1f83721d60317937a9a2888fa9f35237ee134 100644 --- a/crates/gpui/src/element.rs +++ b/crates/gpui/src/element.rs @@ -188,7 +188,7 @@ pub struct Component { impl Component { /// Create a new component from the given RenderOnce type. #[track_caller] - pub fn new(component: C) -> Self { + pub const fn new(component: C) -> Self { Component { component: Some(component), #[cfg(debug_assertions)] @@ -341,7 +341,7 @@ enum ElementDrawPhase { /// A wrapper around an implementer of [`Element`] that allows it to be drawn in a window. impl Drawable { - pub(crate) fn new(element: E) -> Self { + pub(crate) const fn new(element: E) -> Self { Drawable { element, phase: ElementDrawPhase::Start, diff --git a/crates/gpui/src/elements/anchored.rs b/crates/gpui/src/elements/anchored.rs index f92593ef8db992ca40ca46a12efbf14aa259c83c..51f1a9f414326e73321383fd7912e132873ed54a 100644 --- a/crates/gpui/src/elements/anchored.rs +++ b/crates/gpui/src/elements/anchored.rs @@ -37,21 +37,21 @@ pub fn anchored() -> Anchored { impl Anchored { /// Sets which corner of the anchored element should be anchored to the current position. - pub fn anchor(mut self, anchor: Corner) -> Self { + pub const fn anchor(mut self, anchor: Corner) -> Self { self.anchor_corner = anchor; self } /// Sets the position in window coordinates /// (otherwise the location the anchored element is rendered is used) - pub fn position(mut self, anchor: Point) -> Self { + pub const fn position(mut self, anchor: Point) -> Self { self.anchor_position = Some(anchor); self } /// Offset the final position by this amount. /// Useful when you want to anchor to an element but offset from it, such as in PopoverMenu. - pub fn offset(mut self, offset: Point) -> Self { + pub const fn offset(mut self, offset: Point) -> Self { self.offset = Some(offset); self } @@ -59,13 +59,13 @@ impl Anchored { /// Sets the position mode for this anchored element. Local will have this /// interpret its [`Anchored::position`] as relative to the parent element. /// While Window will have it interpret the position as relative to the window. - pub fn position_mode(mut self, mode: AnchoredPositionMode) -> Self { + pub const fn position_mode(mut self, mode: AnchoredPositionMode) -> Self { self.position_mode = mode; self } /// Snap to window edge instead of switching anchor corner when an overflow would occur. - pub fn snap_to_window(mut self) -> Self { + pub const fn snap_to_window(mut self) -> Self { self.fit_mode = AnchoredFitMode::SnapToWindow; self } diff --git a/crates/gpui/src/elements/animation.rs b/crates/gpui/src/elements/animation.rs index e72fb00456d14dec74ffc56e040511c189af1d18..5ad9afbb72e07d68566dc00dca1f84367d095f3e 100644 --- a/crates/gpui/src/elements/animation.rs +++ b/crates/gpui/src/elements/animation.rs @@ -34,7 +34,7 @@ impl Animation { } /// Set the animation to loop when it finishes. - pub fn repeat(mut self) -> Self { + pub const fn repeat(mut self) -> Self { self.oneshot = false; self } @@ -210,7 +210,7 @@ mod easing { use std::f32::consts::PI; /// The linear easing function, or delta itself - pub fn linear(delta: f32) -> f32 { + pub const fn linear(delta: f32) -> f32 { delta } diff --git a/crates/gpui/src/elements/deferred.rs b/crates/gpui/src/elements/deferred.rs index 9498734198dbe58798867ebe7f20138e5667777b..662ff5274f6fa9549fcee408fce234b32f68409d 100644 --- a/crates/gpui/src/elements/deferred.rs +++ b/crates/gpui/src/elements/deferred.rs @@ -22,7 +22,7 @@ impl Deferred { /// Sets the `priority` value of the `deferred` element, which /// determines the drawing order relative to other deferred elements, /// with higher values being drawn on top. - pub fn with_priority(mut self, priority: usize) -> Self { + pub const fn with_priority(mut self, priority: usize) -> Self { self.priority = priority; self } @@ -89,7 +89,7 @@ impl IntoElement for Deferred { impl Deferred { /// Sets a priority for the element. A higher priority conceptually means painting the element /// on top of deferred draws with a lower priority (i.e. closer to the viewer). - pub fn priority(mut self, priority: usize) -> Self { + pub const fn priority(mut self, priority: usize) -> Self { self.priority = priority; self } diff --git a/crates/gpui/src/elements/div.rs b/crates/gpui/src/elements/div.rs index 4d4e176919784f7d7fba68f68cc00b8e7ff92922..103bdf06f0115391238b72fac072f4e890fc29e2 100644 --- a/crates/gpui/src/elements/div.rs +++ b/crates/gpui/src/elements/div.rs @@ -102,7 +102,7 @@ impl Interactivity { } /// Gets the source location of construction. Returns `None` when not in debug mode. - pub fn source_location(&self) -> Option<&'static std::panic::Location<'static>> { + pub const fn source_location(&self) -> Option<&'static std::panic::Location<'static>> { #[cfg(any(feature = "inspector", debug_assertions))] { self.source_location @@ -572,13 +572,13 @@ impl Interactivity { /// `block_mouse_except_scroll` should be preferred. /// /// The imperative API equivalent to [`InteractiveElement::occlude`] - pub fn occlude_mouse(&mut self) { + pub const fn occlude_mouse(&mut self) { self.hitbox_behavior = HitboxBehavior::BlockMouse; } /// Set the bounds of this element as a window control area for the platform window. /// The imperative API equivalent to [`InteractiveElement::window_control_area`] - pub fn window_control_area(&mut self, area: WindowControlArea) { + pub const fn window_control_area(&mut self, area: WindowControlArea) { self.window_control = Some(area); } @@ -586,7 +586,7 @@ impl Interactivity { /// [`Hitbox::is_hovered`] for details. /// /// The imperative API equivalent to [`InteractiveElement::block_mouse_except_scroll`] - pub fn block_mouse_except_scroll(&mut self) { + pub const fn block_mouse_except_scroll(&mut self) { self.hitbox_behavior = HitboxBehavior::BlockMouseExceptScroll; } } @@ -2585,7 +2585,7 @@ pub struct ElementClickedState { } impl ElementClickedState { - fn is_clicked(&self) -> bool { + const fn is_clicked(&self) -> bool { self.group || self.element } } diff --git a/crates/gpui/src/elements/img.rs b/crates/gpui/src/elements/img.rs index 075c7cf32beb400d800ca4f8970f51dae6da7afe..3f73564cdede6e35e264feee24893e8d934f27c1 100644 --- a/crates/gpui/src/elements/img.rs +++ b/crates/gpui/src/elements/img.rs @@ -206,7 +206,7 @@ pub fn img(source: impl Into) -> Img { impl Img { /// A list of all format extensions currently supported by this img element - pub fn extensions() -> &'static [&'static str] { + pub const fn extensions() -> &'static [&'static str] { // This is the list in [image::ImageFormat::from_extension] + `svg` &[ "avif", "jpg", "jpeg", "png", "gif", "webp", "tif", "tiff", "tga", "dds", "bmp", "ico", diff --git a/crates/gpui/src/elements/list.rs b/crates/gpui/src/elements/list.rs index 0d2b9971d8074a3051b31f44faf91f9c734f3064..0ce6ac1ee8e233ae4c052a8664565db7bf749988 100644 --- a/crates/gpui/src/elements/list.rs +++ b/crates/gpui/src/elements/list.rs @@ -43,7 +43,7 @@ pub struct List { impl List { /// Set the sizing behavior for the list. - pub fn with_sizing_behavior(mut self, behavior: ListSizingBehavior) -> Self { + pub const fn with_sizing_behavior(mut self, behavior: ListSizingBehavior) -> Self { self.sizing_behavior = behavior; self } @@ -116,7 +116,7 @@ pub enum ListMeasuringBehavior { } impl ListMeasuringBehavior { - fn reset(&mut self) { + const fn reset(&mut self) { match self { ListMeasuringBehavior::Measure(has_measured) => *has_measured = false, ListMeasuringBehavior::Visible => {} @@ -164,7 +164,7 @@ enum ListItem { } impl ListItem { - fn size(&self) -> Option> { + const fn size(&self) -> Option> { if let ListItem::Measured { size, .. } = self { Some(*size) } else { diff --git a/crates/gpui/src/elements/surface.rs b/crates/gpui/src/elements/surface.rs index b4fced1001b3f9881b66f2f93e81588c750aa64c..bc0de575536afd72ae28450e214f87a35925230c 100644 --- a/crates/gpui/src/elements/surface.rs +++ b/crates/gpui/src/elements/surface.rs @@ -39,7 +39,7 @@ pub fn surface(source: impl Into) -> Surface { impl Surface { /// Set the object fit for the image. - pub fn object_fit(mut self, object_fit: ObjectFit) -> Self { + pub const fn object_fit(mut self, object_fit: ObjectFit) -> Self { self.object_fit = object_fit; self } diff --git a/crates/gpui/src/elements/svg.rs b/crates/gpui/src/elements/svg.rs index a55245dcdfbf42898e519b6d06f03e3f6c33158c..c8c8e4d1ecb6f81da7741024a190e7fb863d48e4 100644 --- a/crates/gpui/src/elements/svg.rs +++ b/crates/gpui/src/elements/svg.rs @@ -32,7 +32,7 @@ impl Svg { /// Transform the SVG element with the given transformation. /// Note that this won't effect the hitbox or layout of the element, only the rendering. - pub fn with_transformation(mut self, transformation: Transformation) -> Self { + pub const fn with_transformation(mut self, transformation: Transformation) -> Self { self.transformation = Some(transformation); self } @@ -165,7 +165,7 @@ impl Default for Transformation { impl Transformation { /// Create a new Transformation with the specified scale along each axis. - pub fn scale(scale: Size) -> Self { + pub const fn scale(scale: Size) -> Self { Self { scale, translate: point(px(0.0), px(0.0)), @@ -174,7 +174,7 @@ impl Transformation { } /// Create a new Transformation with the specified translation. - pub fn translate(translate: Point) -> Self { + pub const fn translate(translate: Point) -> Self { Self { scale: size(1.0, 1.0), translate, @@ -193,13 +193,13 @@ impl Transformation { } /// Update the scaling factor of this transformation. - pub fn with_scaling(mut self, scale: Size) -> Self { + pub const fn with_scaling(mut self, scale: Size) -> Self { self.scale = scale; self } /// Update the translation value of this transformation. - pub fn with_translation(mut self, translate: Point) -> Self { + pub const fn with_translation(mut self, translate: Point) -> Self { self.translate = translate; self } diff --git a/crates/gpui/src/elements/text.rs b/crates/gpui/src/elements/text.rs index 5d34ccfa5d78e09d47b36a2e061fdaa0fbbca45f..ad0bfa5d1fcccba00509bed6d3df2ef9fd051c2d 100644 --- a/crates/gpui/src/elements/text.rs +++ b/crates/gpui/src/elements/text.rs @@ -164,7 +164,7 @@ impl StyledText { } /// Get the layout for this element. This can be used to map indices to pixels and vice versa. - pub fn layout(&self) -> &TextLayout { + pub const fn layout(&self) -> &TextLayout { &self.layout } diff --git a/crates/gpui/src/elements/uniform_list.rs b/crates/gpui/src/elements/uniform_list.rs index 949d4339e616cd9f49b3783f46da0f80424c474f..4a449b484badf96121366347ee5d2d1a5502e45d 100644 --- a/crates/gpui/src/elements/uniform_list.rs +++ b/crates/gpui/src/elements/uniform_list.rs @@ -627,7 +627,7 @@ impl UniformList { } /// Sets the sizing behavior, similar to the `List` element. - pub fn with_sizing_behavior(mut self, behavior: ListSizingBehavior) -> Self { + pub const fn with_sizing_behavior(mut self, behavior: ListSizingBehavior) -> Self { self.sizing_behavior = behavior; self } diff --git a/crates/gpui/src/executor.rs b/crates/gpui/src/executor.rs index ab5cafcbac55b40b2e136f28a08f2245ae27e4f1..a74f194210da0a01c2a78d702768e17adce1875f 100644 --- a/crates/gpui/src/executor.rs +++ b/crates/gpui/src/executor.rs @@ -68,7 +68,7 @@ enum TaskState { impl Task { /// Creates a new task that will resolve with the value - pub fn ready(val: T) -> Self { + pub const fn ready(val: T) -> Self { Task(TaskState::Ready(Some(val))) } diff --git a/crates/gpui/src/geometry.rs b/crates/gpui/src/geometry.rs index fa6f90b9ac9949ed7b5444e13045aaef6f9c0224..d07a5e0cf5643756a17592d4ca1dfecff079fd08 100644 --- a/crates/gpui/src/geometry.rs +++ b/crates/gpui/src/geometry.rs @@ -31,7 +31,7 @@ pub enum Axis { impl Axis { /// Swap this axis to the opposite axis. - pub fn invert(self) -> Self { + pub const fn invert(self) -> Self { match self { Axis::Vertical => Axis::Horizontal, Axis::Horizontal => Axis::Vertical, @@ -405,7 +405,7 @@ pub struct Size { impl Size { /// Create a new Size, a synonym for [`size`] - pub fn new(width: T, height: T) -> Self { + pub const fn new(width: T, height: T) -> Self { size(width, height) } } @@ -723,7 +723,7 @@ impl Size { /// # Returns /// /// A `Size` with width and height set to `Length::Auto`. - pub fn auto() -> Self { + pub const fn auto() -> Self { Self { width: Length::Auto, height: Length::Auto, @@ -759,7 +759,7 @@ pub struct Bounds { } /// Create a bounds with the given origin and size -pub fn bounds( +pub const fn bounds( origin: Point, size: Size, ) -> Bounds { @@ -810,7 +810,7 @@ where /// # Returns /// /// Returns a `Bounds` that has the given origin and size. - pub fn new(origin: Point, size: Size) -> Self { + pub const fn new(origin: Point, size: Size) -> Self { Bounds { origin, size } } } @@ -1865,7 +1865,7 @@ impl Edges { /// assert_eq!(auto_edges.bottom, Length::Auto); /// assert_eq!(auto_edges.left, Length::Auto); /// ``` - pub fn auto() -> Self { + pub const fn auto() -> Self { Self { top: Length::Auto, right: Length::Auto, @@ -2137,7 +2137,7 @@ impl Corner { /// assert_eq!(Corner::TopLeft.opposite_corner(), Corner::BottomRight); /// ``` #[must_use] - pub fn opposite_corner(self) -> Self { + pub const fn opposite_corner(self) -> Self { match self { Corner::TopLeft => Corner::BottomRight, Corner::TopRight => Corner::BottomLeft, @@ -2156,7 +2156,7 @@ impl Corner { /// assert_eq!(result, Corner::TopRight); /// ``` #[must_use] - pub fn other_side_corner_along(self, axis: Axis) -> Self { + pub const fn other_side_corner_along(self, axis: Axis) -> Self { match axis { Axis::Vertical => match self { Corner::TopLeft => Corner::BottomLeft, @@ -2492,7 +2492,7 @@ impl From for Corners { pub struct Radians(pub f32); /// Create a `Radian` from a raw value -pub fn radians(value: f32) -> Radians { +pub const fn radians(value: f32) -> Radians { Radians(value) } @@ -2675,7 +2675,7 @@ impl Pixels { /// # Returns /// /// Returns a new `Pixels` instance with the floored value. - pub fn floor(&self) -> Self { + pub const fn floor(&self) -> Self { Self(self.0.floor()) } @@ -2684,7 +2684,7 @@ impl Pixels { /// # Returns /// /// Returns a new `Pixels` instance with the rounded value. - pub fn round(&self) -> Self { + pub const fn round(&self) -> Self { Self(self.0.round()) } @@ -2693,7 +2693,7 @@ impl Pixels { /// # Returns /// /// Returns a new `Pixels` instance with the ceiling value. - pub fn ceil(&self) -> Self { + pub const fn ceil(&self) -> Self { Self(self.0.ceil()) } @@ -2728,7 +2728,7 @@ impl Pixels { /// # Returns /// /// A new `Pixels` instance with the absolute value of the original `Pixels`. - pub fn abs(&self) -> Self { + pub const fn abs(&self) -> Self { Self(self.0.abs()) } @@ -2739,7 +2739,7 @@ impl Pixels { /// Returns: /// * `1.0` if the value is positive /// * `-1.0` if the value is negative - pub fn signum(&self) -> f32 { + pub const fn signum(&self) -> f32 { self.0.signum() } @@ -2748,7 +2748,7 @@ impl Pixels { /// # Returns /// /// A f64 value of the `Pixels`. - pub fn to_f64(self) -> f64 { + pub const fn to_f64(self) -> f64 { self.0 as f64 } } @@ -2883,7 +2883,7 @@ impl DevicePixels { /// let total_bytes = pixels.to_bytes(bytes_per_pixel); /// assert_eq!(total_bytes, 40); // 10 pixels * 4 bytes/pixel = 40 bytes /// ``` - pub fn to_bytes(self, bytes_per_pixel: u8) -> u32 { + pub const fn to_bytes(self, bytes_per_pixel: u8) -> u32 { self.0 as u32 * bytes_per_pixel as u32 } } @@ -2959,7 +2959,7 @@ impl ScaledPixels { /// # Returns /// /// Returns a new `ScaledPixels` instance with the floored value. - pub fn floor(&self) -> Self { + pub const fn floor(&self) -> Self { Self(self.0.floor()) } @@ -2968,7 +2968,7 @@ impl ScaledPixels { /// # Returns /// /// Returns a new `ScaledPixels` instance with the rounded value. - pub fn round(&self) -> Self { + pub const fn round(&self) -> Self { Self(self.0.round()) } @@ -2977,7 +2977,7 @@ impl ScaledPixels { /// # Returns /// /// Returns a new `ScaledPixels` instance with the ceiled value. - pub fn ceil(&self) -> Self { + pub const fn ceil(&self) -> Self { Self(self.0.ceil()) } } @@ -3569,7 +3569,7 @@ pub const fn relative(fraction: f32) -> DefiniteLength { } /// Returns the Golden Ratio, i.e. `~(1.0 + sqrt(5.0)) / 2.0`. -pub fn phi() -> DefiniteLength { +pub const fn phi() -> DefiniteLength { relative(1.618_034) } @@ -3582,7 +3582,7 @@ pub fn phi() -> DefiniteLength { /// # Returns /// /// A `Rems` representing the specified number of rems. -pub fn rems(rems: f32) -> Rems { +pub const fn rems(rems: f32) -> Rems { Rems(rems) } @@ -3610,7 +3610,7 @@ pub const fn px(pixels: f32) -> Pixels { /// # Returns /// /// A `Length` variant set to `Auto`. -pub fn auto() -> Length { +pub const fn auto() -> Length { Length::Auto } diff --git a/crates/gpui/src/input.rs b/crates/gpui/src/input.rs index dc36ef9e16feedf31c01cd38327fd12729f894b3..1931cd2c7fb5aa0c84ff8ea7c75abdd4ff02a00a 100644 --- a/crates/gpui/src/input.rs +++ b/crates/gpui/src/input.rs @@ -83,7 +83,7 @@ impl ElementInputHandler { /// Used in [`Element::paint`][element_paint] with the element's bounds, a `Window`, and a `App` context. /// /// [element_paint]: crate::Element::paint - pub fn new(element_bounds: Bounds, view: Entity) -> Self { + pub const fn new(element_bounds: Bounds, view: Entity) -> Self { ElementInputHandler { view, element_bounds, diff --git a/crates/gpui/src/inspector.rs b/crates/gpui/src/inspector.rs index 9f86576a599845bb9e09760e8001333b9dea745d..fc9e421fb79e7b26888bb2a2144573d2fa3a1a36 100644 --- a/crates/gpui/src/inspector.rs +++ b/crates/gpui/src/inspector.rs @@ -77,7 +77,7 @@ mod conditional { } impl Inspector { - pub(crate) fn new() -> Self { + pub(crate) const fn new() -> Self { Self { active_element: None, pick_depth: Some(0.0), @@ -143,12 +143,12 @@ mod conditional { } /// Starts element picking mode, allowing the user to select elements by clicking. - pub fn start_picking(&mut self) { + pub const fn start_picking(&mut self) { self.pick_depth = Some(0.0); } /// Returns whether the inspector is currently in picking mode. - pub fn is_picking(&self) -> bool { + pub const fn is_picking(&self) -> bool { self.pick_depth.is_some() } diff --git a/crates/gpui/src/interactive.rs b/crates/gpui/src/interactive.rs index dafe623dfada7ba7b21140fc36c7c824e8b5f3f6..6d6dc9328587ac08166127c5b4d16bfc46932461 100644 --- a/crates/gpui/src/interactive.rs +++ b/crates/gpui/src/interactive.rs @@ -205,7 +205,7 @@ impl ClickEvent { /// /// `Keyboard`: None /// `Mouse`: The position of the mouse when the button was released. - pub fn mouse_position(&self) -> Option> { + pub const fn mouse_position(&self) -> Option> { match self { ClickEvent::Keyboard(_) => None, ClickEvent::Mouse(event) => Some(event.up.position), @@ -242,7 +242,7 @@ impl ClickEvent { /// /// `Keyboard`: false, keyboard clicks only work if an element is already focused /// `Mouse`: Whether this was the first focusing click - pub fn first_focus(&self) -> bool { + pub const fn first_focus(&self) -> bool { match self { ClickEvent::Keyboard(_) => false, ClickEvent::Mouse(event) => event.down.first_mouse, @@ -253,7 +253,7 @@ impl ClickEvent { /// /// `Keyboard`: Always 1 /// `Mouse`: Count of clicks from MouseUpEvent - pub fn click_count(&self) -> usize { + pub const fn click_count(&self) -> usize { match self { ClickEvent::Keyboard(_) => 1, ClickEvent::Mouse(event) => event.up.click_count, @@ -261,7 +261,7 @@ impl ClickEvent { } /// Returns whether the click event is generated by a keyboard event - pub fn is_keyboard(&self) -> bool { + pub const fn is_keyboard(&self) -> bool { match self { ClickEvent::Mouse(_) => false, ClickEvent::Keyboard(_) => true, @@ -407,7 +407,7 @@ impl Default for ScrollDelta { impl ScrollDelta { /// Returns true if this is a precise scroll delta in pixels. - pub fn precise(&self) -> bool { + pub const fn precise(&self) -> bool { match self { ScrollDelta::Pixels(_) => true, ScrollDelta::Lines(_) => false, diff --git a/crates/gpui/src/key_dispatch.rs b/crates/gpui/src/key_dispatch.rs index 03ee31fdad5bdfc48e10dbf74a2557ea7ee0036e..38f2a870f0fe2ed6168b74dd90000d3e9d931143 100644 --- a/crates/gpui/src/key_dispatch.rs +++ b/crates/gpui/src/key_dispatch.rs @@ -107,7 +107,7 @@ impl ReusedSubtree { DispatchNodeId((node_id.0 - self.old_range.start) + self.new_range.start) } - pub fn contains_focus(&self) -> bool { + pub const fn contains_focus(&self) -> bool { self.contains_focus } } @@ -158,7 +158,7 @@ impl DispatchTree { self.view_node_ids.clear(); } - pub fn len(&self) -> usize { + pub const fn len(&self) -> usize { self.nodes.len() } diff --git a/crates/gpui/src/keymap.rs b/crates/gpui/src/keymap.rs index e26123339bd65fecd6ff9e5356098e29cee30890..c7b3a7ce69e84fb970d14f864e1df02ce7b4b530 100644 --- a/crates/gpui/src/keymap.rs +++ b/crates/gpui/src/keymap.rs @@ -36,7 +36,7 @@ impl Keymap { } /// Get the current version of the keymap. - pub fn version(&self) -> KeymapVersion { + pub const fn version(&self) -> KeymapVersion { self.version } diff --git a/crates/gpui/src/keymap/binding.rs b/crates/gpui/src/keymap/binding.rs index fc4b32941b85f4cdea31aaba7198d3e7043ee481..2f714509805112f2453b6b1730c142bf82a49727 100644 --- a/crates/gpui/src/keymap/binding.rs +++ b/crates/gpui/src/keymap/binding.rs @@ -75,13 +75,13 @@ impl KeyBinding { } /// Set the metadata for this binding. - pub fn with_meta(mut self, meta: KeyBindingMetaIndex) -> Self { + pub const fn with_meta(mut self, meta: KeyBindingMetaIndex) -> Self { self.meta = Some(meta); self } /// Set the metadata for this binding. - pub fn set_meta(&mut self, meta: KeyBindingMetaIndex) { + pub const fn set_meta(&mut self, meta: KeyBindingMetaIndex) { self.meta = Some(meta); } @@ -116,7 +116,7 @@ impl KeyBinding { } /// Get the metadata for this binding - pub fn meta(&self) -> Option { + pub const fn meta(&self) -> Option { self.meta } diff --git a/crates/gpui/src/keymap/context.rs b/crates/gpui/src/keymap/context.rs index 960bd1752fe8c1527b9c593658e429af4cd61029..4471310f1edada8b29ac87b48f442c26d91a18be 100644 --- a/crates/gpui/src/keymap/context.rs +++ b/crates/gpui/src/keymap/context.rs @@ -95,7 +95,7 @@ impl KeyContext { } /// Check if this context is empty. - pub fn is_empty(&self) -> bool { + pub const fn is_empty(&self) -> bool { self.0.is_empty() } @@ -448,7 +448,7 @@ fn is_identifier_char(c: char) -> bool { c.is_alphanumeric() || c == '_' || c == '-' } -fn is_vim_operator_char(c: char) -> bool { +const fn is_vim_operator_char(c: char) -> bool { c == '>' || c == '<' || c == '~' || c == '"' || c == '?' } diff --git a/crates/gpui/src/path_builder.rs b/crates/gpui/src/path_builder.rs index 40a6e71e0a1738adf1ed261183d2340682826992..a3899d85dd85e2a32cb5501a146b731e475d4a72 100644 --- a/crates/gpui/src/path_builder.rs +++ b/crates/gpui/src/path_builder.rs @@ -202,7 +202,7 @@ impl PathBuilder { /// Applies a transform to the path. #[inline] - pub fn transform(&mut self, transform: Transform) { + pub const fn transform(&mut self, transform: Transform) { self.transform = Some(transform); } diff --git a/crates/gpui/src/platform.rs b/crates/gpui/src/platform.rs index 6847a34a843395a18531bcf3114d1dfe24f7bf29..421229b1c7c53b5c1b7e34d8f5caff0daec60c9f 100644 --- a/crates/gpui/src/platform.rs +++ b/crates/gpui/src/platform.rs @@ -432,7 +432,7 @@ pub struct Tiling { impl Tiling { /// Initializes a [`Tiling`] type with all sides tiled - pub fn tiled() -> Self { + pub const fn tiled() -> Self { Self { top: true, left: true, @@ -442,7 +442,7 @@ impl Tiling { } /// Whether any edge is tiled - pub fn is_tiled(&self) -> bool { + pub const fn is_tiled(&self) -> bool { self.top || self.left || self.right || self.bottom } } @@ -592,7 +592,7 @@ pub(crate) struct NoopTextSystem; impl NoopTextSystem { #[allow(dead_code)] - pub fn new() -> Self { + pub const fn new() -> Self { Self } } @@ -723,7 +723,7 @@ impl AtlasKey { ), allow(dead_code) )] - pub(crate) fn texture_kind(&self) -> AtlasTextureKind { + pub(crate) const fn texture_kind(&self) -> AtlasTextureKind { match self { AtlasKey::Glyph(params) => { if params.is_emoji { @@ -1201,7 +1201,7 @@ impl Default for WindowBounds { impl WindowBounds { /// Retrieve the inner bounds - pub fn get_bounds(&self) -> Bounds { + pub const fn get_bounds(&self) -> Bounds { match self { WindowBounds::Windowed(bounds) => *bounds, WindowBounds::Maximized(bounds) => *bounds, @@ -1376,12 +1376,12 @@ impl PromptButton { } #[allow(dead_code)] - pub(crate) fn is_cancel(&self) -> bool { + pub(crate) const fn is_cancel(&self) -> bool { matches!(self, PromptButton::Cancel(_)) } /// Returns the label of the button - pub fn label(&self) -> &SharedString { + pub const fn label(&self) -> &SharedString { match self { PromptButton::Ok(label) => label, PromptButton::Cancel(label) => label, @@ -1705,7 +1705,7 @@ impl Image { } /// Get this image's ID - pub fn id(&self) -> u64 { + pub const fn id(&self) -> u64 { self.id } @@ -1788,12 +1788,12 @@ impl Image { } /// Get the format of the clipboard image - pub fn format(&self) -> ImageFormat { + pub const fn format(&self) -> ImageFormat { self.format } /// Get the raw bytes of the clipboard image - pub fn bytes(&self) -> &[u8] { + pub const fn bytes(&self) -> &[u8] { self.bytes.as_slice() } } @@ -1807,7 +1807,7 @@ pub struct ClipboardString { impl ClipboardString { /// Create a new clipboard string with the given text - pub fn new(text: String) -> Self { + pub const fn new(text: String) -> Self { Self { text, metadata: None, @@ -1822,7 +1822,7 @@ impl ClipboardString { } /// Get the text of the clipboard string - pub fn text(&self) -> &String { + pub const fn text(&self) -> &String { &self.text } diff --git a/crates/gpui/src/platform/app_menu.rs b/crates/gpui/src/platform/app_menu.rs index 4069fee7268c18bd5dbdfb3f3fb8a73d2f7f6e92..1dbadd3e173b02c4d993129cc89b6a200c3aac2f 100644 --- a/crates/gpui/src/platform/app_menu.rs +++ b/crates/gpui/src/platform/app_menu.rs @@ -75,12 +75,12 @@ pub enum MenuItem { impl MenuItem { /// Creates a new menu item that is a separator - pub fn separator() -> Self { + pub const fn separator() -> Self { Self::Separator } /// Creates a new menu item that is a submenu - pub fn submenu(menu: Menu) -> Self { + pub const fn submenu(menu: Menu) -> Self { Self::Submenu(menu) } diff --git a/crates/gpui/src/platform/keystroke.rs b/crates/gpui/src/platform/keystroke.rs index 4a2bfc785e3eb7e13a845bb67b4524255affb3bb..acb2b265e3cd6d7f3e414e84276ccfd60df86566 100644 --- a/crates/gpui/src/platform/keystroke.rs +++ b/crates/gpui/src/platform/keystroke.rs @@ -283,7 +283,7 @@ impl KeybindingKeystroke { } /// Create a new keybinding keystroke from the given keystroke, without any platform-specific mapping. - pub fn from_keystroke(keystroke: Keystroke) -> Self { + pub const fn from_keystroke(keystroke: Keystroke) -> Self { #[cfg(target_os = "windows")] { let key = keystroke.key.clone(); @@ -301,7 +301,7 @@ impl KeybindingKeystroke { } /// Returns the GPUI representation of the keystroke. - pub fn inner(&self) -> &Keystroke { + pub const fn inner(&self) -> &Keystroke { &self.inner } @@ -311,7 +311,7 @@ impl KeybindingKeystroke { /// - On macOS and Linux, this modifiers is the same as `inner.modifiers`, which is the GPUI representation of the keystroke. /// - On Windows, this modifiers is the display modifiers, for example, a `ctrl-@` keystroke will have `inner.modifiers` as /// `Modifiers::control()` and `display_modifiers` as `Modifiers::control_shift()`. - pub fn modifiers(&self) -> &Modifiers { + pub const fn modifiers(&self) -> &Modifiers { #[cfg(target_os = "windows")] { &self.display_modifiers @@ -339,7 +339,7 @@ impl KeybindingKeystroke { } /// Sets the modifiers. On Windows this modifies both `inner.modifiers` and `display_modifiers`. - pub fn set_modifiers(&mut self, modifiers: Modifiers) { + pub const fn set_modifiers(&mut self, modifiers: Modifiers) { self.inner.modifiers = modifiers; #[cfg(target_os = "windows")] { @@ -471,7 +471,7 @@ pub struct Modifiers { impl Modifiers { /// Returns whether any modifier key is pressed. - pub fn modified(&self) -> bool { + pub const fn modified(&self) -> bool { self.control || self.alt || self.shift || self.platform || self.function } @@ -479,7 +479,7 @@ impl Modifiers { /// /// On macOS, this is the command key. /// On Linux and Windows, this is the control key. - pub fn secondary(&self) -> bool { + pub const fn secondary(&self) -> bool { #[cfg(target_os = "macos")] { self.platform @@ -492,7 +492,7 @@ impl Modifiers { } /// Returns how many modifier keys are pressed. - pub fn number_of_modifiers(&self) -> u8 { + pub const fn number_of_modifiers(&self) -> u8 { self.control as u8 + self.alt as u8 + self.shift as u8 diff --git a/crates/gpui/src/platform/mac.rs b/crates/gpui/src/platform/mac.rs index 76d636b457517da64cf66988325652ddea56c5d3..05afaa7d931bf987cd4db0a38a1daa0f4ea8188d 100644 --- a/crates/gpui/src/platform/mac.rs +++ b/crates/gpui/src/platform/mac.rs @@ -93,18 +93,18 @@ struct NSRange { } impl NSRange { - fn invalid() -> Self { + const fn invalid() -> Self { Self { location: NSNotFound as NSUInteger, length: 0, } } - fn is_valid(&self) -> bool { + const fn is_valid(&self) -> bool { self.location != NSNotFound as NSUInteger } - fn to_range(self) -> Option> { + const fn to_range(self) -> Option> { if self.is_valid() { let start = self.location as usize; let end = start + self.length as usize; diff --git a/crates/gpui/src/platform/mac/metal_atlas.rs b/crates/gpui/src/platform/mac/metal_atlas.rs index 8282530c5efdc13ca95a1f04c0f6ef1a23c8366c..9c13c7ceffd59b1cd51df3870afa38ba524f3791 100644 --- a/crates/gpui/src/platform/mac/metal_atlas.rs +++ b/crates/gpui/src/platform/mac/metal_atlas.rs @@ -233,11 +233,11 @@ impl MetalAtlasTexture { } } - fn decrement_ref_count(&mut self) { + const fn decrement_ref_count(&mut self) { self.live_atlas_keys -= 1; } - fn is_unreferenced(&mut self) -> bool { + const fn is_unreferenced(&mut self) -> bool { self.live_atlas_keys == 0 } } diff --git a/crates/gpui/src/platform/mac/metal_renderer.rs b/crates/gpui/src/platform/mac/metal_renderer.rs index 9e5d6ec5ff02c74b4f0acfada8eee3d002bfd06b..9edcfe0729cd4274a1360476cfebce76d37859fc 100644 --- a/crates/gpui/src/platform/mac/metal_renderer.rs +++ b/crates/gpui/src/platform/mac/metal_renderer.rs @@ -162,7 +162,7 @@ impl MetalRenderer { .new_library_with_data(SHADERS_METALLIB) .expect("error building metal library"); - fn to_float2_bits(point: PointF) -> u64 { + const fn to_float2_bits(point: PointF) -> u64 { let mut output = point.y.to_bits() as u64; output <<= 32; output |= point.x.to_bits() as u64; @@ -285,7 +285,7 @@ impl MetalRenderer { self.layer.as_ptr() } - pub fn sprite_atlas(&self) -> &Arc { + pub const fn sprite_atlas(&self) -> &Arc { &self.sprite_atlas } @@ -342,11 +342,11 @@ impl MetalRenderer { } } - pub fn update_transparency(&self, _transparent: bool) { + pub const fn update_transparency(&self, _transparent: bool) { // todo(mac)? } - pub fn destroy(&self) { + pub const fn destroy(&self) { // nothing to do } @@ -1291,7 +1291,7 @@ fn build_path_rasterization_pipeline_state( } // Align to multiples of 256 make Metal happy. -fn align_offset(offset: &mut usize) { +const fn align_offset(offset: &mut usize) { *offset = (*offset).div_ceil(256) * 256; } diff --git a/crates/gpui/src/platform/mac/platform.rs b/crates/gpui/src/platform/mac/platform.rs index ee393fbced4924d0cd0556a8a4e6de21a012501a..c98e3f7b81abb93ae55054397d5636be31b4ad1d 100644 --- a/crates/gpui/src/platform/mac/platform.rs +++ b/crates/gpui/src/platform/mac/platform.rs @@ -1650,11 +1650,11 @@ impl UTType { Self(unsafe { NSPasteboardTypeTIFF }) // This is a rare case where there's a built-in NSPasteboardType } - fn inner(&self) -> *const Object { + const fn inner(&self) -> *const Object { self.0 } - fn inner_mut(&self) -> *mut Object { + const fn inner_mut(&self) -> *mut Object { self.0 as *mut _ } } diff --git a/crates/gpui/src/platform/mac/screen_capture.rs b/crates/gpui/src/platform/mac/screen_capture.rs index 4d4ffa6896520e465dfeb7b1ccc06e1149f9e25d..de1b9b8ec5b1416f29a61a3380c1235ecb5b9b68 100644 --- a/crates/gpui/src/platform/mac/screen_capture.rs +++ b/crates/gpui/src/platform/mac/screen_capture.rs @@ -304,11 +304,11 @@ unsafe fn build_classes() { } } -extern "C" fn output_video_effect_did_start_for_stream(_this: &Object, _: Sel, _stream: id) {} +const extern "C" fn output_video_effect_did_start_for_stream(_this: &Object, _: Sel, _stream: id) {} -extern "C" fn output_video_effect_did_stop_for_stream(_this: &Object, _: Sel, _stream: id) {} +const extern "C" fn output_video_effect_did_stop_for_stream(_this: &Object, _: Sel, _stream: id) {} -extern "C" fn stream_did_stop_with_error(_this: &Object, _: Sel, _stream: id, _error: id) {} +const extern "C" fn stream_did_stop_with_error(_this: &Object, _: Sel, _stream: id, _error: id) {} extern "C" fn stream_did_output_sample_buffer_of_type( this: &Object, diff --git a/crates/gpui/src/platform/mac/text_system.rs b/crates/gpui/src/platform/mac/text_system.rs index 3d89ba79f316ca526af03eb274290d7d30aa190c..db04c3814d49609a2a9028ecea89163db15068a6 100644 --- a/crates/gpui/src/platform/mac/text_system.rs +++ b/crates/gpui/src/platform/mac/text_system.rs @@ -558,7 +558,7 @@ struct StringIndexConverter<'a> { } impl<'a> StringIndexConverter<'a> { - fn new(text: &'a str) -> Self { + const fn new(text: &'a str) -> Self { Self { text, utf8_ix: 0, diff --git a/crates/gpui/src/platform/mac/window.rs b/crates/gpui/src/platform/mac/window.rs index 95efffa3e77cdbeebf53acd47dd1aa9b33cb24ab..94fdb103bda2793eef367c4b0228472dda590474 100644 --- a/crates/gpui/src/platform/mac/window.rs +++ b/crates/gpui/src/platform/mac/window.rs @@ -1602,7 +1602,7 @@ unsafe fn drop_window_state(object: &Object) { } } -extern "C" fn yes(_: &Object, _: Sel) -> BOOL { +const extern "C" fn yes(_: &Object, _: Sel) -> BOOL { YES } diff --git a/crates/gpui/src/scene.rs b/crates/gpui/src/scene.rs index 758d06e5972e36b15fe0b8ce9d7d3193f8d3844d..26900ed3762b604229a7290cb782d4b2668ac47f 100644 --- a/crates/gpui/src/scene.rs +++ b/crates/gpui/src/scene.rs @@ -48,7 +48,7 @@ impl Scene { self.surfaces.clear(); } - pub fn len(&self) -> usize { + pub const fn len(&self) -> usize { self.paint_operations.len() } @@ -207,7 +207,7 @@ pub(crate) enum Primitive { } impl Primitive { - pub fn bounds(&self) -> &Bounds { + pub const fn bounds(&self) -> &Bounds { match self { Primitive::Shadow(shadow) => &shadow.bounds, Primitive::Quad(quad) => &quad.bounds, @@ -219,7 +219,7 @@ impl Primitive { } } - pub fn content_mask(&self) -> &ContentMask { + pub const fn content_mask(&self) -> &ContentMask { match self { Primitive::Shadow(shadow) => &shadow.content_mask, Primitive::Quad(quad) => &quad.content_mask, @@ -528,7 +528,7 @@ impl Eq for TransformationMatrix {} impl TransformationMatrix { /// The unit matrix, has no effect. - pub fn unit() -> Self { + pub const fn unit() -> Self { Self { rotation_scale: [[1.0, 0.0], [0.0, 1.0]], translation: [0.0, 0.0], @@ -724,7 +724,7 @@ impl Path { } /// Move the start, current point to the given point. - pub fn move_to(&mut self, to: Point) { + pub const fn move_to(&mut self, to: Point) { self.contour_count += 1; self.start = to; self.current = to; diff --git a/crates/gpui/src/style.rs b/crates/gpui/src/style.rs index 42f8f25e47620fe673720055037b7f91f44165a2..0d981a64860e7c3648b4845c4a7f95f61b8692e9 100644 --- a/crates/gpui/src/style.rs +++ b/crates/gpui/src/style.rs @@ -819,7 +819,7 @@ impl Fill { /// Unwrap this fill into a solid color, if it is one. /// /// If the fill is not a solid color, this method returns `None`. - pub fn color(&self) -> Option { + pub const fn color(&self) -> Option { match self { Fill::Color(color) => Some(*color), } diff --git a/crates/gpui/src/tab_stop.rs b/crates/gpui/src/tab_stop.rs index 8a95a3975af736d544e01cbf6e212994b8e7e8c6..69ea23a5d54afbe8784943ea0f8dc60e5661d44a 100644 --- a/crates/gpui/src/tab_stop.rs +++ b/crates/gpui/src/tab_stop.rs @@ -23,7 +23,7 @@ pub enum TabStopOperation { } impl TabStopOperation { - fn focus_handle(&self) -> Option<&FocusHandle> { + const fn focus_handle(&self) -> Option<&FocusHandle> { match self { TabStopOperation::Insert(focus_handle) => Some(focus_handle), _ => None, @@ -192,7 +192,7 @@ impl TabStopMap { } } - pub fn paint_index(&self) -> usize { + pub const fn paint_index(&self) -> usize { self.insertion_history.len() } diff --git a/crates/gpui/src/text_system.rs b/crates/gpui/src/text_system.rs index cd665aae1b475dda8501ca459492fbf68e71c17f..b5ffd0f49c86ef4f2a6533cab59f282af81e7799 100644 --- a/crates/gpui/src/text_system.rs +++ b/crates/gpui/src/text_system.rs @@ -818,13 +818,13 @@ pub fn font(family: impl Into) -> Font { impl Font { /// Set this Font to be bold - pub fn bold(mut self) -> Self { + pub const fn bold(mut self) -> Self { self.weight = FontWeight::BOLD; self } /// Set this Font to be italic - pub fn italic(mut self) -> Self { + pub const fn italic(mut self) -> Self { self.style = FontStyle::Italic; self } diff --git a/crates/gpui/src/text_system/line_wrapper.rs b/crates/gpui/src/text_system/line_wrapper.rs index 55599cc0535dfdd94bfd895ce6001f3a83a27cf6..0b1ab0285c995da65bd63ee74ae0de5bf5d3b658 100644 --- a/crates/gpui/src/text_system/line_wrapper.rs +++ b/crates/gpui/src/text_system/line_wrapper.rs @@ -165,7 +165,7 @@ impl LineWrapper { /// Any character in this list should be treated as a word character, /// meaning it can be part of a word that should not be wrapped. - pub(crate) fn is_word_char(c: char) -> bool { + pub(crate) const fn is_word_char(c: char) -> bool { // ASCII alphanumeric characters, for English, numbers: `Hello123`, etc. c.is_ascii_alphanumeric() || // Latin script in Unicode for French, German, Spanish, etc. @@ -255,12 +255,12 @@ pub enum LineFragment<'a> { impl<'a> LineFragment<'a> { /// Creates a new text fragment from the given text. - pub fn text(text: &'a str) -> Self { + pub const fn text(text: &'a str) -> Self { LineFragment::Text { text } } /// Creates a new non-text element with the given width and UTF-8 encoded length. - pub fn element(width: Pixels, len_utf8: usize) -> Self { + pub const fn element(width: Pixels, len_utf8: usize) -> Self { LineFragment::Element { width, len_utf8 } } @@ -288,7 +288,7 @@ enum WrapBoundaryCandidate { } impl WrapBoundaryCandidate { - pub fn len_utf8(&self) -> usize { + pub const fn len_utf8(&self) -> usize { match self { WrapBoundaryCandidate::Char { character } => character.len_utf8(), WrapBoundaryCandidate::Element { len_utf8: len, .. } => *len, @@ -306,7 +306,7 @@ pub struct Boundary { } impl Boundary { - fn new(ix: usize, next_indent: u32) -> Self { + const fn new(ix: usize, next_indent: u32) -> Self { Self { ix, next_indent } } } diff --git a/crates/gpui/src/view.rs b/crates/gpui/src/view.rs index 217971792ee978307a19f7e40374cb337e38a625..5ba9ab0c561fcc023777a874ac78839a22bd13a9 100644 --- a/crates/gpui/src/view.rs +++ b/crates/gpui/src/view.rs @@ -127,12 +127,12 @@ impl AnyView { } /// Gets the [TypeId] of the underlying view. - pub fn entity_type(&self) -> TypeId { + pub const fn entity_type(&self) -> TypeId { self.entity.entity_type } /// Gets the entity id of this handle. - pub fn entity_id(&self) -> EntityId { + pub const fn entity_id(&self) -> EntityId { self.entity.entity_id() } } diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rs index 5534a4a8ddf98c2bf5d26637b7af3a499dd63ae1..6d0639761739123ec7842dadbf6b0123ae4de139 100644 --- a/crates/gpui/src/window.rs +++ b/crates/gpui/src/window.rs @@ -515,7 +515,7 @@ impl HitboxId { window.mouse_hit_test.ids.contains(&self) } - fn next(mut self) -> HitboxId { + const fn next(mut self) -> HitboxId { HitboxId(self.0.wrapping_add(1)) } } @@ -1359,7 +1359,7 @@ impl Window { } /// Obtain a handle to the window that belongs to this context. - pub fn window_handle(&self) -> AnyWindowHandle { + pub const fn window_handle(&self) -> AnyWindowHandle { self.handle } @@ -1372,7 +1372,7 @@ impl Window { } /// Close this window. - pub fn remove_window(&mut self) { + pub const fn remove_window(&mut self) { self.removed = true; } @@ -1432,7 +1432,7 @@ impl Window { } /// Accessor for the text system. - pub fn text_system(&self) -> &Arc { + pub const fn text_system(&self) -> &Arc { &self.text_system } @@ -1708,12 +1708,12 @@ impl Window { } /// Returns the appearance of the current window. - pub fn appearance(&self) -> WindowAppearance { + pub const fn appearance(&self) -> WindowAppearance { self.appearance } /// Returns the size of the drawable area within the window. - pub fn viewport_size(&self) -> Size { + pub const fn viewport_size(&self) -> Size { self.viewport_size } @@ -1761,7 +1761,7 @@ impl Window { } /// Returns the client_inset value by [`Self::set_client_inset`]. - pub fn client_inset(&self) -> Option { + pub const fn client_inset(&self) -> Option { self.client_inset } @@ -1812,7 +1812,7 @@ impl Window { /// The scale factor of the display associated with the window. For example, it could /// return 2.0 for a "retina" display, indicating that each logical pixel should actually /// be rendered as two pixels on screen. - pub fn scale_factor(&self) -> f32 { + pub const fn scale_factor(&self) -> f32 { self.scale_factor } @@ -1871,12 +1871,12 @@ impl Window { /// Call to prevent the default action of an event. Currently only used to prevent /// parent elements from becoming focused on mouse down. - pub fn prevent_default(&mut self) { + pub const fn prevent_default(&mut self) { self.default_prevented = true; } /// Obtain whether default has been prevented for the event currently being dispatched. - pub fn default_prevented(&self) -> bool { + pub const fn default_prevented(&self) -> bool { self.default_prevented } @@ -1890,17 +1890,17 @@ impl Window { } /// The position of the mouse relative to the window. - pub fn mouse_position(&self) -> Point { + pub const fn mouse_position(&self) -> Point { self.mouse_position } /// The current state of the keyboard's modifiers - pub fn modifiers(&self) -> Modifiers { + pub const fn modifiers(&self) -> Modifiers { self.modifiers } /// The current state of the keyboard's capslock - pub fn capslock(&self) -> Capslock { + pub const fn capslock(&self) -> Capslock { self.capslock } @@ -3927,7 +3927,7 @@ impl Window { } /// Determine whether a potential multi-stroke key binding is in progress on this window. - pub fn has_pending_keystrokes(&self) -> bool { + pub const fn has_pending_keystrokes(&self) -> bool { self.pending_input.is_some() } @@ -4795,7 +4795,7 @@ pub struct AnyWindowHandle { impl AnyWindowHandle { /// Get the ID of this window. - pub fn window_id(&self) -> WindowId { + pub const fn window_id(&self) -> WindowId { self.id } diff --git a/crates/gpui/src/window/prompts.rs b/crates/gpui/src/window/prompts.rs index 778ee1dab0eb8312161dcbca0ddf8964afe0c6bb..bbbb0c53b19a1843810a4cf3591063bd61cc1cf8 100644 --- a/crates/gpui/src/window/prompts.rs +++ b/crates/gpui/src/window/prompts.rs @@ -26,7 +26,7 @@ pub struct PromptHandle { } impl PromptHandle { - pub(crate) fn new(sender: oneshot::Sender) -> Self { + pub(crate) const fn new(sender: oneshot::Sender) -> Self { Self { sender } } diff --git a/crates/html_to_markdown/src/html_element.rs b/crates/html_to_markdown/src/html_element.rs index 26918e3c74b6e2b8ab0ba9e88af18019c58ad26e..efe240ed44896497a405a39a4040e1b60b4fcc89 100644 --- a/crates/html_to_markdown/src/html_element.rs +++ b/crates/html_to_markdown/src/html_element.rs @@ -28,7 +28,7 @@ pub struct HtmlElement { } impl HtmlElement { - pub fn new(tag: String, attrs: RefCell>) -> Self { + pub const fn new(tag: String, attrs: RefCell>) -> Self { Self { tag, attrs } } diff --git a/crates/html_to_markdown/src/markdown.rs b/crates/html_to_markdown/src/markdown.rs index bb3b3563bcdff8692c80b1b79e7c94d4184bf1cb..2ee5ae22d4f7f3c027883e2959b485227fa80389 100644 --- a/crates/html_to_markdown/src/markdown.rs +++ b/crates/html_to_markdown/src/markdown.rs @@ -122,7 +122,7 @@ pub struct TableHandler { } impl TableHandler { - pub fn new() -> Self { + pub const fn new() -> Self { Self { current_table_columns: 0, is_first_th: true, diff --git a/crates/html_to_markdown/src/markdown_writer.rs b/crates/html_to_markdown/src/markdown_writer.rs index c32205ae7b349239d0a41a5a63c0793d958b4eea..3125803fd0f432c111ca5dbfba19427c3c2b24d4 100644 --- a/crates/html_to_markdown/src/markdown_writer.rs +++ b/crates/html_to_markdown/src/markdown_writer.rs @@ -38,14 +38,14 @@ impl Default for MarkdownWriter { } impl MarkdownWriter { - pub fn new() -> Self { + pub const fn new() -> Self { Self { current_element_stack: VecDeque::new(), markdown: String::new(), } } - pub fn current_element_stack(&self) -> &VecDeque { + pub const fn current_element_stack(&self) -> &VecDeque { &self.current_element_stack } diff --git a/crates/html_to_markdown/src/structure/wikipedia.rs b/crates/html_to_markdown/src/structure/wikipedia.rs index c8d399a6610dcbc7beea939dfae2eacb8b0512ad..ea7ca170069ca5ecf855ae67281783bfc954cf02 100644 --- a/crates/html_to_markdown/src/structure/wikipedia.rs +++ b/crates/html_to_markdown/src/structure/wikipedia.rs @@ -67,7 +67,7 @@ pub struct WikipediaCodeHandler { } impl WikipediaCodeHandler { - pub fn new() -> Self { + pub const fn new() -> Self { Self { language: None } } } diff --git a/crates/http_client/src/async_body.rs b/crates/http_client/src/async_body.rs index 6b99a54a7d941c290f2680bc2a599bc63251e24b..18e22ba345aaed9df088311fd0bed4af93acf544 100644 --- a/crates/http_client/src/async_body.rs +++ b/crates/http_client/src/async_body.rs @@ -28,7 +28,7 @@ impl AsyncBody { /// /// An empty body represents the *absence* of a body, which is semantically /// different than the presence of a body of zero length. - pub fn empty() -> Self { + pub const fn empty() -> Self { Self(Inner::Empty) } /// Create a streaming body that reads from the given reader. @@ -39,7 +39,7 @@ impl AsyncBody { Self(Inner::AsyncReader(Box::pin(read))) } - pub fn from_bytes(bytes: Bytes) -> Self { + pub const fn from_bytes(bytes: Bytes) -> Self { Self(Inner::Bytes(Cursor::new(bytes))) } } diff --git a/crates/http_client/src/http_client.rs b/crates/http_client/src/http_client.rs index 056cee4e346e34b5689a0dfe3278c880b7297986..4d3a6fbe74b0d6fba6dc23d4db24a80449ccfd62 100644 --- a/crates/http_client/src/http_client.rs +++ b/crates/http_client/src/http_client.rs @@ -346,7 +346,7 @@ pub fn read_no_proxy_from_env() -> Option { pub struct BlockedHttpClient; impl BlockedHttpClient { - pub fn new() -> Self { + pub const fn new() -> Self { BlockedHttpClient } } diff --git a/crates/image_viewer/src/image_info.rs b/crates/image_viewer/src/image_info.rs index 6e8956abc67868457f071e04f3c2a1957ff6c19c..680c7bd334200fe43e377ef627a7c94139702a40 100644 --- a/crates/image_viewer/src/image_info.rs +++ b/crates/image_viewer/src/image_info.rs @@ -14,7 +14,7 @@ pub struct ImageInfo { } impl ImageInfo { - pub fn new(_workspace: &Workspace) -> Self { + pub const fn new(_workspace: &Workspace) -> Self { Self { metadata: None, _observe_active_image: None, diff --git a/crates/keymap_editor/src/keymap_editor.rs b/crates/keymap_editor/src/keymap_editor.rs index fce98ef596e2fb77cdf8091755de39ea55dce615..e58335e2906c19a8652ba8f5a26d40e64ba486f8 100644 --- a/crates/keymap_editor/src/keymap_editor.rs +++ b/crates/keymap_editor/src/keymap_editor.rs @@ -115,7 +115,7 @@ pub struct KeymapEventChannel {} impl Global for KeymapEventChannel {} impl KeymapEventChannel { - fn new() -> Self { + const fn new() -> Self { Self {} } @@ -140,14 +140,14 @@ enum SearchMode { } impl SearchMode { - fn invert(&self) -> Self { + const fn invert(&self) -> Self { match self { SearchMode::Normal => SearchMode::KeyStroke { exact_match: false }, SearchMode::KeyStroke { .. } => SearchMode::Normal, } } - fn exact_match(&self) -> bool { + const fn exact_match(&self) -> bool { match self { SearchMode::Normal => false, SearchMode::KeyStroke { exact_match } => *exact_match, @@ -163,7 +163,7 @@ enum FilterState { } impl FilterState { - fn invert(&self) -> Self { + const fn invert(&self) -> Self { match self { FilterState::All => FilterState::Conflicts, FilterState::Conflicts => FilterState::All, @@ -191,7 +191,7 @@ struct ConflictOrigin { } impl ConflictOrigin { - fn new(source: KeybindSource, index: usize) -> Self { + const fn new(source: KeybindSource, index: usize) -> Self { Self { override_source: source, index, @@ -199,7 +199,7 @@ impl ConflictOrigin { } } - fn with_overridden_source(self, source: KeybindSource) -> Self { + const fn with_overridden_source(self, source: KeybindSource) -> Self { Self { overridden_source: Some(source), ..self @@ -347,7 +347,7 @@ impl ConflictState { .is_some_and(|conflict| conflict.is_user_keybind_conflict()) } - fn any_user_binding_conflicts(&self) -> bool { + const fn any_user_binding_conflicts(&self) -> bool { self.has_user_conflicts } } @@ -959,7 +959,7 @@ impl KeymapEditor { cx.notify(); } - fn context_menu_deployed(&self) -> bool { + const fn context_menu_deployed(&self) -> bool { self.context_menu.is_some() } @@ -1417,7 +1417,7 @@ impl ProcessedBinding { ) } - fn is_unbound(&self) -> bool { + const fn is_unbound(&self) -> bool { matches!(self, Self::Unmapped(_)) } @@ -1431,7 +1431,7 @@ impl ProcessedBinding { .map(|binding| binding.keystrokes.as_slice()) } - fn keybind_information(&self) -> Option<&KeybindInformation> { + const fn keybind_information(&self) -> Option<&KeybindInformation> { match self { Self::Mapped(keybind_information, _) => Some(keybind_information), Self::Unmapped(_) => None, @@ -1456,7 +1456,7 @@ impl ProcessedBinding { .map(|binding| &binding.keystroke_text) } - fn action(&self) -> &ActionInformation { + const fn action(&self) -> &ActionInformation { match self { Self::Mapped(_, action) | Self::Unmapped(action) => action, } @@ -1488,7 +1488,7 @@ enum KeybindContextString { impl KeybindContextString { const GLOBAL: SharedString = SharedString::new_static(""); - pub fn local(&self) -> Option<&SharedString> { + pub const fn local(&self) -> Option<&SharedString> { match self { KeybindContextString::Global => None, KeybindContextString::Local(name, _) => Some(name), diff --git a/crates/keymap_editor/src/ui_components/keystroke_input.rs b/crates/keymap_editor/src/ui_components/keystroke_input.rs index e264df3b62bc3c5c78acc38ed906e81837dfbf94..ec73181e6bf2ee6decc87b5807301414147154f9 100644 --- a/crates/keymap_editor/src/ui_components/keystroke_input.rs +++ b/crates/keymap_editor/src/ui_components/keystroke_input.rs @@ -102,7 +102,7 @@ impl KeystrokeInput { self.keystrokes_changed(cx); } - pub fn set_search(&mut self, search: bool) { + pub const fn set_search(&mut self, search: bool) { self.search = search; } diff --git a/crates/language/src/buffer.rs b/crates/language/src/buffer.rs index 1605eea051b660f7285481223b0b3b9f97aef732..1fffd4937267bac93cb358f39925e59ddbf6b782 100644 --- a/crates/language/src/buffer.rs +++ b/crates/language/src/buffer.rs @@ -389,7 +389,7 @@ pub enum DiskState { impl DiskState { /// Returns the file's last known modification time on disk. - pub fn mtime(self) -> Option { + pub const fn mtime(self) -> Option { match self { DiskState::New => None, DiskState::Present { mtime } => Some(mtime), @@ -397,7 +397,7 @@ impl DiskState { } } - pub fn exists(&self) -> bool { + pub const fn exists(&self) -> bool { match self { DiskState::New => false, DiskState::Present { .. } => true, @@ -954,7 +954,7 @@ impl Buffer { } /// Returns the [`Capability`] of this buffer. - pub fn capability(&self) -> Capability { + pub const fn capability(&self) -> Capability { self.capability } @@ -1252,12 +1252,12 @@ impl Buffer { } /// The version of the buffer that was last saved or reloaded from disk. - pub fn saved_version(&self) -> &clock::Global { + pub const fn saved_version(&self) -> &clock::Global { &self.saved_version } /// The mtime of the buffer's file when the buffer was last saved or reloaded from disk. - pub fn saved_mtime(&self) -> Option { + pub const fn saved_mtime(&self) -> Option { self.saved_mtime } @@ -1423,7 +1423,7 @@ impl Buffer { } /// Returns the primary [`Language`] assigned to this [`Buffer`]. - pub fn language(&self) -> Option<&Arc> { + pub const fn language(&self) -> Option<&Arc> { self.language.as_ref() } @@ -1479,7 +1479,7 @@ impl Buffer { /// An integer version number that accounts for all updates besides /// the buffer's text itself (which is versioned via a version vector). - pub fn non_text_state_update_count(&self) -> usize { + pub const fn non_text_state_update_count(&self) -> usize { self.non_text_state_update_count } @@ -2859,7 +2859,7 @@ impl Buffer { /// Returns a list of strings which trigger a completion menu for this language. /// Usually this is driven by LSP server which returns a list of trigger characters for completions. - pub fn completion_triggers(&self) -> &BTreeSet { + pub const fn completion_triggers(&self) -> &BTreeSet { &self.completion_triggers } @@ -3380,7 +3380,7 @@ impl BufferSnapshot { } /// Returns the main [`Language`]. - pub fn language(&self) -> Option<&Arc> { + pub const fn language(&self) -> Option<&Arc> { self.language.as_ref() } @@ -4564,7 +4564,7 @@ impl BufferSnapshot { /// Raw access to the diagnostic sets. Typically `diagnostic_groups` or `diagnostic_group` /// should be used instead. - pub fn diagnostic_sets(&self) -> &SmallVec<[(LanguageServerId, DiagnosticSet); 2]> { + pub const fn diagnostic_sets(&self) -> &SmallVec<[(LanguageServerId, DiagnosticSet); 2]> { &self.diagnostics } @@ -4616,12 +4616,12 @@ impl BufferSnapshot { /// An integer version number that accounts for all updates besides /// the buffer's text itself (which is versioned via a version vector). - pub fn non_text_state_update_count(&self) -> usize { + pub const fn non_text_state_update_count(&self) -> usize { self.non_text_state_update_count } /// An integer version that changes when the buffer's syntax changes. - pub fn syntax_update_count(&self) -> usize { + pub const fn syntax_update_count(&self) -> usize { self.syntax.update_count() } @@ -4866,7 +4866,7 @@ impl<'a> BufferChunks<'a> { } /// The current byte offset in the buffer. - pub fn offset(&self) -> usize { + pub const fn offset(&self) -> usize { self.range.start } @@ -4874,7 +4874,7 @@ impl<'a> BufferChunks<'a> { self.range.clone() } - fn update_diagnostic_depths(&mut self, endpoint: DiagnosticEndpoint) { + const fn update_diagnostic_depths(&mut self, endpoint: DiagnosticEndpoint) { let depth = match endpoint.severity { DiagnosticSeverity::ERROR => &mut self.error_depth, DiagnosticSeverity::WARNING => &mut self.warning_depth, @@ -4897,7 +4897,7 @@ impl<'a> BufferChunks<'a> { } } - fn current_diagnostic_severity(&self) -> Option { + const fn current_diagnostic_severity(&self) -> Option { if self.error_depth > 0 { Some(DiagnosticSeverity::ERROR) } else if self.warning_depth > 0 { @@ -4911,7 +4911,7 @@ impl<'a> BufferChunks<'a> { } } - fn current_code_is_unnecessary(&self) -> bool { + const fn current_code_is_unnecessary(&self) -> bool { self.unnecessary_depth > 0 } } @@ -5061,7 +5061,7 @@ impl Default for Diagnostic { impl IndentSize { /// Returns an [`IndentSize`] representing the given spaces. - pub fn spaces(len: u32) -> Self { + pub const fn spaces(len: u32) -> Self { Self { len, kind: IndentKind::Space, @@ -5069,7 +5069,7 @@ impl IndentSize { } /// Returns an [`IndentSize`] representing a tab. - pub fn tab() -> Self { + pub const fn tab() -> Self { Self { len: 1, kind: IndentKind::Tab, @@ -5082,7 +5082,7 @@ impl IndentSize { } /// The character representation of this [`IndentSize`]. - pub fn char(&self) -> char { + pub const fn char(&self) -> char { match self.kind { IndentKind::Space => ' ', IndentKind::Tab => '\t', @@ -5110,7 +5110,7 @@ impl IndentSize { self } - pub fn len_with_expanded_tabs(&self, tab_size: NonZeroU32) -> usize { + pub const fn len_with_expanded_tabs(&self, tab_size: NonZeroU32) -> usize { match self.kind { IndentKind::Space => self.len as usize, IndentKind::Tab => self.len as usize * tab_size.get() as usize, @@ -5222,7 +5222,7 @@ pub struct CharClassifier { } impl CharClassifier { - pub fn new(scope: Option) -> Self { + pub const fn new(scope: Option) -> Self { Self { scope, scope_context: None, diff --git a/crates/language/src/language.rs b/crates/language/src/language.rs index fb523aeb9e84e49f4d4c9afb0583eacc1e844030..625f60df55ca0861448b9a23c7abcb5864d95007 100644 --- a/crates/language/src/language.rs +++ b/crates/language/src/language.rs @@ -951,7 +951,7 @@ impl Default for Override { } impl Override { - fn as_option<'a>(this: Option<&'a Self>, original: Option<&'a T>) -> Option<&'a T> { + const fn as_option<'a>(this: Option<&'a Self>, original: Option<&'a T>) -> Option<&'a T> { match this { Some(Self::Set(value)) => Some(value), Some(Self::Remove { remove: true }) => None, @@ -1010,7 +1010,7 @@ pub struct WrapCharactersConfig { pub end_suffix: String, } -fn auto_indent_using_last_non_empty_line_default() -> bool { +const fn auto_indent_using_last_non_empty_line_default() -> bool { true } @@ -1251,7 +1251,7 @@ impl TextObject { } } - pub fn around(&self) -> Option { + pub const fn around(&self) -> Option { match self { TextObject::InsideFunction => Some(TextObject::AroundFunction), TextObject::InsideClass => Some(TextObject::AroundClass), @@ -1352,7 +1352,7 @@ impl Language { Self::new_with_id(LanguageId::new(), config, ts_language) } - pub fn id(&self) -> LanguageId { + pub const fn id(&self) -> LanguageId { self.id } @@ -1929,7 +1929,7 @@ impl Language { pub fn name(&self) -> LanguageName { self.config.name.clone() } - pub fn manifest(&self) -> Option<&ManifestName> { + pub const fn manifest(&self) -> Option<&ManifestName> { self.manifest_name.as_ref() } @@ -1997,7 +1997,7 @@ impl Language { } } - pub fn grammar(&self) -> Option<&Arc> { + pub const fn grammar(&self) -> Option<&Arc> { self.grammar.as_ref() } @@ -2016,7 +2016,7 @@ impl Language { self.config.prettier_parser_name.as_deref() } - pub fn config(&self) -> &LanguageConfig { + pub const fn config(&self) -> &LanguageConfig { &self.config } } @@ -2188,7 +2188,7 @@ impl Debug for Language { } impl Grammar { - pub fn id(&self) -> GrammarId { + pub const fn id(&self) -> GrammarId { self.id } @@ -2224,11 +2224,11 @@ impl Grammar { Some(self.highlight_map.lock().get(capture_id)) } - pub fn debug_variables_config(&self) -> Option<&DebugVariablesConfig> { + pub const fn debug_variables_config(&self) -> Option<&DebugVariablesConfig> { self.debug_variables_config.as_ref() } - pub fn imports_config(&self) -> Option<&ImportsConfig> { + pub const fn imports_config(&self) -> Option<&ImportsConfig> { self.imports_config.as_ref() } } @@ -2357,7 +2357,7 @@ impl CodeLabel { } } - pub fn text(&self) -> &str { + pub const fn text(&self) -> &str { self.text.as_str() } @@ -2568,7 +2568,7 @@ pub fn point_to_lsp(point: PointUtf16) -> lsp::Position { lsp::Position::new(point.row, point.column) } -pub fn point_from_lsp(point: lsp::Position) -> Unclipped { +pub const fn point_from_lsp(point: lsp::Position) -> Unclipped { Unclipped(PointUtf16::new(point.line, point.character)) } diff --git a/crates/language/src/language_registry.rs b/crates/language/src/language_registry.rs index 022eb89e6d2b378b8c4305c81887060d776bb411..d429c80751b85451d628c6ae3dfd518f8baf1716 100644 --- a/crates/language/src/language_registry.rs +++ b/crates/language/src/language_registry.rs @@ -177,11 +177,11 @@ impl AvailableLanguage { self.name.clone() } - pub fn matcher(&self) -> &LanguageMatcher { + pub const fn matcher(&self) -> &LanguageMatcher { &self.matcher } - pub fn hidden(&self) -> bool { + pub const fn hidden(&self) -> bool { self.hidden } } diff --git a/crates/language/src/language_settings.rs b/crates/language/src/language_settings.rs index b6c65ede0596fe96ba1a750bcbcbcb971a3be617..b1c6c84ca3afc35880f84b478042a9843766f071 100644 --- a/crates/language/src/language_settings.rs +++ b/crates/language/src/language_settings.rs @@ -459,7 +459,7 @@ impl AllLanguageSettings { } /// Returns the edit predictions preview mode for the given language and path. - pub fn edit_predictions_mode(&self) -> EditPredictionsMode { + pub const fn edit_predictions_mode(&self) -> EditPredictionsMode { self.edit_predictions.mode } } diff --git a/crates/language/src/proto.rs b/crates/language/src/proto.rs index bc85b10859632fc3e2cf61c663b7159a023f4f3a..de4bcdb7fabd5c1f4142563c72c4c7e58df53318 100644 --- a/crates/language/src/proto.rs +++ b/crates/language/src/proto.rs @@ -14,7 +14,7 @@ pub use proto::{BufferState, File, Operation}; use super::{point_from_lsp, point_to_lsp}; /// Deserializes a `[text::LineEnding]` from the RPC representation. -pub fn deserialize_line_ending(message: proto::LineEnding) -> text::LineEnding { +pub const fn deserialize_line_ending(message: proto::LineEnding) -> text::LineEnding { match message { proto::LineEnding::Unix => text::LineEnding::Unix, proto::LineEnding::Windows => text::LineEnding::Windows, @@ -22,7 +22,7 @@ pub fn deserialize_line_ending(message: proto::LineEnding) -> text::LineEnding { } /// Serializes a [`text::LineEnding`] to be sent over RPC. -pub fn serialize_line_ending(message: text::LineEnding) -> proto::LineEnding { +pub const fn serialize_line_ending(message: text::LineEnding) -> proto::LineEnding { match message { text::LineEnding::Unix => proto::LineEnding::Unix, text::LineEnding::Windows => proto::LineEnding::Windows, @@ -184,7 +184,7 @@ pub fn serialize_selection(selection: &Selection) -> proto::Selection { } /// Serializes a [`CursorShape`] to be sent over RPC. -pub fn serialize_cursor_shape(cursor_shape: &CursorShape) -> proto::CursorShape { +pub const fn serialize_cursor_shape(cursor_shape: &CursorShape) -> proto::CursorShape { match cursor_shape { CursorShape::Bar => proto::CursorShape::CursorBar, CursorShape::Block => proto::CursorShape::CursorBlock, @@ -194,7 +194,7 @@ pub fn serialize_cursor_shape(cursor_shape: &CursorShape) -> proto::CursorShape } /// Deserializes a [`CursorShape`] from the RPC representation. -pub fn deserialize_cursor_shape(cursor_shape: proto::CursorShape) -> CursorShape { +pub const fn deserialize_cursor_shape(cursor_shape: proto::CursorShape) -> CursorShape { match cursor_shape { proto::CursorShape::CursorBar => CursorShape::Bar, proto::CursorShape::CursorBlock => CursorShape::Block, @@ -557,7 +557,7 @@ pub fn deserialize_transaction(transaction: proto::Transaction) -> Result proto::LamportTimestamp { +pub const fn serialize_timestamp(timestamp: clock::Lamport) -> proto::LamportTimestamp { proto::LamportTimestamp { replica_id: timestamp.replica_id as u32, value: timestamp.value, @@ -565,7 +565,7 @@ pub fn serialize_timestamp(timestamp: clock::Lamport) -> proto::LamportTimestamp } /// Deserializes a [`clock::Lamport`] timestamp from the RPC representation. -pub fn deserialize_timestamp(timestamp: proto::LamportTimestamp) -> clock::Lamport { +pub const fn deserialize_timestamp(timestamp: proto::LamportTimestamp) -> clock::Lamport { clock::Lamport { replica_id: timestamp.replica_id as ReplicaId, value: timestamp.value, @@ -573,7 +573,7 @@ pub fn deserialize_timestamp(timestamp: proto::LamportTimestamp) -> clock::Lampo } /// Serializes a range of [`FullOffset`]s to be sent over RPC. -pub fn serialize_range(range: &Range) -> proto::Range { +pub const fn serialize_range(range: &Range) -> proto::Range { proto::Range { start: range.start.0 as u64, end: range.end.0 as u64, @@ -581,7 +581,7 @@ pub fn serialize_range(range: &Range) -> proto::Range { } /// Deserializes a range of [`FullOffset`]s from the RPC representation. -pub fn deserialize_range(range: proto::Range) -> Range { +pub const fn deserialize_range(range: proto::Range) -> Range { FullOffset(range.start as usize)..FullOffset(range.end as usize) } diff --git a/crates/language/src/syntax_map.rs b/crates/language/src/syntax_map.rs index 528b25d47193ebdbbf0dbe12cd18c66e31ad37d0..b7f4857a4b1c918c41e790d939c9d48829d3cd81 100644 --- a/crates/language/src/syntax_map.rs +++ b/crates/language/src/syntax_map.rs @@ -111,7 +111,7 @@ impl SyntaxLayerContent { } } - fn tree(&self) -> Option<&Tree> { + const fn tree(&self) -> Option<&Tree> { match self { SyntaxLayerContent::Parsed { tree, .. } => Some(tree), SyntaxLayerContent::Pending { .. } => None, @@ -279,7 +279,7 @@ impl SyntaxSnapshot { self.layers.is_empty() } - pub fn update_count(&self) -> usize { + pub const fn update_count(&self) -> usize { self.update_count } @@ -953,7 +953,7 @@ impl SyntaxSnapshot { self.layers.summary().contains_unknown_injections } - pub fn language_registry_version(&self) -> usize { + pub const fn language_registry_version(&self) -> usize { self.language_registry_version } } @@ -1086,7 +1086,7 @@ pub struct TreeSitterOptions { max_start_depth: Option, } impl TreeSitterOptions { - pub fn max_start_depth(max_start_depth: u32) -> Self { + pub const fn max_start_depth(max_start_depth: u32) -> Self { Self { max_start_depth: Some(max_start_depth), } diff --git a/crates/language/src/toolchain.rs b/crates/language/src/toolchain.rs index d3466307f368e7008eedbc8881aa78ab854bc08b..001c7e06e263f4c08f7bfb89f8cca97d06c0a17c 100644 --- a/crates/language/src/toolchain.rs +++ b/crates/language/src/toolchain.rs @@ -43,7 +43,7 @@ pub enum ToolchainScope { } impl ToolchainScope { - pub fn label(&self) -> &'static str { + pub const fn label(&self) -> &'static str { match self { ToolchainScope::Subproject(_, _) => "Subproject", ToolchainScope::Project => "Project", @@ -51,7 +51,7 @@ impl ToolchainScope { } } - pub fn description(&self) -> &'static str { + pub const fn description(&self) -> &'static str { match self { ToolchainScope::Subproject(_, _) => { "Available only in the subproject you're currently in." diff --git a/crates/language_model/src/language_model.rs b/crates/language_model/src/language_model.rs index 24f9b84afcfa7b9a40b4a1b7684e9a9b036a5a85..1a72f50ca592d180ae3dcfd016101b22f15e7259 100644 --- a/crates/language_model/src/language_model.rs +++ b/crates/language_model/src/language_model.rs @@ -440,7 +440,7 @@ pub struct TokenUsage { } impl TokenUsage { - pub fn total_tokens(&self) -> u64 { + pub const fn total_tokens(&self) -> u64 { self.input_tokens + self.output_tokens + self.cache_read_input_tokens diff --git a/crates/language_model/src/request.rs b/crates/language_model/src/request.rs index 2902e9ae5aaa45ea4607317bee12a3f91abbbe55..aa5a0afd04d4361d8a3f2b92c709514ac9709f7f 100644 --- a/crates/language_model/src/request.rs +++ b/crates/language_model/src/request.rs @@ -145,7 +145,7 @@ impl LanguageModelImage { }) } - pub fn estimate_tokens(&self) -> usize { + pub const fn estimate_tokens(&self) -> usize { let width = self.size.width.0.unsigned_abs() as usize; let height = self.size.height.0.unsigned_abs() as usize; diff --git a/crates/language_model/src/role.rs b/crates/language_model/src/role.rs index 4b47ef36dd564e5950ce7d42a7e4f9263f3998b7..6f3665a43c130710d111980626da7cd46196f81a 100644 --- a/crates/language_model/src/role.rs +++ b/crates/language_model/src/role.rs @@ -19,7 +19,7 @@ impl Role { } } - pub fn to_proto(self) -> proto::LanguageModelRole { + pub const fn to_proto(self) -> proto::LanguageModelRole { match self { Role::User => proto::LanguageModelRole::LanguageModelUser, Role::Assistant => proto::LanguageModelRole::LanguageModelAssistant, @@ -27,7 +27,7 @@ impl Role { } } - pub fn cycle(self) -> Role { + pub const fn cycle(self) -> Role { match self { Role::User => Role::Assistant, Role::Assistant => Role::System, diff --git a/crates/language_models/src/api_key.rs b/crates/language_models/src/api_key.rs index 122234b6ced6d0bf1b7a0d684683c841824ccd2d..cb68fc7697b2c48b4fb1d9dd791555c8d0d21636 100644 --- a/crates/language_models/src/api_key.rs +++ b/crates/language_models/src/api_key.rs @@ -35,7 +35,7 @@ pub struct ApiKey { } impl ApiKeyState { - pub fn new(url: SharedString) -> Self { + pub const fn new(url: SharedString) -> Self { Self { url, load_status: LoadStatus::NotPresent, @@ -43,11 +43,11 @@ impl ApiKeyState { } } - pub fn has_key(&self) -> bool { + pub const fn has_key(&self) -> bool { matches!(self.load_status, LoadStatus::Loaded { .. }) } - pub fn is_from_env_var(&self) -> bool { + pub const fn is_from_env_var(&self) -> bool { match &self.load_status { LoadStatus::Loaded(ApiKey { source: ApiKeySource::EnvVar { .. }, diff --git a/crates/language_models/src/provider/anthropic.rs b/crates/language_models/src/provider/anthropic.rs index 2897b836b12d7bcaabfe3841a9f0c77ba6ab497e..4f9dc48e8f3e5f9daa2ea4a060c8913238ae7034 100644 --- a/crates/language_models/src/provider/anthropic.rs +++ b/crates/language_models/src/provider/anthropic.rs @@ -53,7 +53,7 @@ pub struct State { } impl State { - fn is_authenticated(&self) -> bool { + const fn is_authenticated(&self) -> bool { self.api_key_state.has_key() } @@ -798,7 +798,7 @@ struct RawToolUse { } /// Updates usage data by preferring counts from `new`. -fn update_usage(usage: &mut Usage, new: &Usage) { +const fn update_usage(usage: &mut Usage, new: &Usage) { if let Some(input_tokens) = new.input_tokens { usage.input_tokens = Some(input_tokens); } diff --git a/crates/language_models/src/provider/deepseek.rs b/crates/language_models/src/provider/deepseek.rs index ec420bfd83b427701ffa6eb13a9eb6035604f0b1..00807dabf33f5ef065cb9f9b886d03b5ef95a849 100644 --- a/crates/language_models/src/provider/deepseek.rs +++ b/crates/language_models/src/provider/deepseek.rs @@ -54,7 +54,7 @@ pub struct State { } impl State { - fn is_authenticated(&self) -> bool { + const fn is_authenticated(&self) -> bool { self.api_key_state.has_key() } diff --git a/crates/language_models/src/provider/google.rs b/crates/language_models/src/provider/google.rs index f6ac364611c0e121115a4bd692893ed8bfa89ab3..2ab9963e2570822d9c12b2e8794279b715f710ed 100644 --- a/crates/language_models/src/provider/google.rs +++ b/crates/language_models/src/provider/google.rs @@ -75,7 +75,7 @@ static API_KEY_ENV_VAR: LazyLock = LazyLock::new(|| { }); impl State { - fn is_authenticated(&self) -> bool { + const fn is_authenticated(&self) -> bool { self.api_key_state.has_key() } @@ -715,7 +715,7 @@ pub fn count_google_tokens( .boxed() } -fn update_usage(usage: &mut UsageMetadata, new: &UsageMetadata) { +const fn update_usage(usage: &mut UsageMetadata, new: &UsageMetadata) { if let Some(prompt_token_count) = new.prompt_token_count { usage.prompt_token_count = Some(prompt_token_count); } diff --git a/crates/language_models/src/provider/lmstudio.rs b/crates/language_models/src/provider/lmstudio.rs index c0b3509c0e2c9636ca48cdb0de0cc6ed32a2b792..18abdbecff9554add5e8a5773557096302a556af 100644 --- a/crates/language_models/src/provider/lmstudio.rs +++ b/crates/language_models/src/provider/lmstudio.rs @@ -52,7 +52,7 @@ pub struct State { } impl State { - fn is_authenticated(&self) -> bool { + const fn is_authenticated(&self) -> bool { !self.available_models.is_empty() } diff --git a/crates/language_models/src/provider/mistral.rs b/crates/language_models/src/provider/mistral.rs index ad7bf600d56354ee12e72c9ebc2bfe09f0094da7..37550529656076fd7fad7737693cdf0dab557c13 100644 --- a/crates/language_models/src/provider/mistral.rs +++ b/crates/language_models/src/provider/mistral.rs @@ -52,7 +52,7 @@ pub struct State { } impl State { - fn is_authenticated(&self) -> bool { + const fn is_authenticated(&self) -> bool { self.api_key_state.has_key() } diff --git a/crates/language_models/src/provider/ollama.rs b/crates/language_models/src/provider/ollama.rs index a25ecbe01aa659817b41cac54d76871b4742ea66..9f02e0ee308361163209b396dfd4048cdeee9091 100644 --- a/crates/language_models/src/provider/ollama.rs +++ b/crates/language_models/src/provider/ollama.rs @@ -59,7 +59,7 @@ pub struct State { } impl State { - fn is_authenticated(&self) -> bool { + const fn is_authenticated(&self) -> bool { !self.fetched_models.is_empty() } diff --git a/crates/language_models/src/provider/open_ai.rs b/crates/language_models/src/provider/open_ai.rs index 3eaaa8b58598328e6e843b1f86b8f4e5cbd04c1e..9622d4466f147263341d3110817c4c90bb170126 100644 --- a/crates/language_models/src/provider/open_ai.rs +++ b/crates/language_models/src/provider/open_ai.rs @@ -49,7 +49,7 @@ pub struct State { } impl State { - fn is_authenticated(&self) -> bool { + const fn is_authenticated(&self) -> bool { self.api_key_state.has_key() } diff --git a/crates/language_models/src/provider/open_ai_compatible.rs b/crates/language_models/src/provider/open_ai_compatible.rs index cca49c982ce6e93614c4574a84ffaa4bd1d8f0c6..f36e29f71fd13e46d533d3a3c80f6d2364f8b026 100644 --- a/crates/language_models/src/provider/open_ai_compatible.rs +++ b/crates/language_models/src/provider/open_ai_compatible.rs @@ -44,7 +44,7 @@ pub struct State { } impl State { - fn is_authenticated(&self) -> bool { + const fn is_authenticated(&self) -> bool { self.api_key_state.has_key() } diff --git a/crates/language_models/src/provider/open_router.rs b/crates/language_models/src/provider/open_router.rs index 5bfc97c41f60351288ccf08c3a86b4b0947ee997..35dfe2c8edf9daf16438a814d2e047f7c028d9b2 100644 --- a/crates/language_models/src/provider/open_router.rs +++ b/crates/language_models/src/provider/open_router.rs @@ -49,7 +49,7 @@ pub struct State { } impl State { - fn is_authenticated(&self) -> bool { + const fn is_authenticated(&self) -> bool { self.api_key_state.has_key() } diff --git a/crates/language_models/src/provider/vercel.rs b/crates/language_models/src/provider/vercel.rs index ad12e5a628779eddf333bdd4f91bddbea016c402..59a62564da7db89b808b07cf633ebd75e994bbce 100644 --- a/crates/language_models/src/provider/vercel.rs +++ b/crates/language_models/src/provider/vercel.rs @@ -44,7 +44,7 @@ pub struct State { } impl State { - fn is_authenticated(&self) -> bool { + const fn is_authenticated(&self) -> bool { self.api_key_state.has_key() } diff --git a/crates/language_models/src/provider/x_ai.rs b/crates/language_models/src/provider/x_ai.rs index 243a2e3e0217f10d580a278d25e7168f4f62fe21..e3dabc0de2664aabf84f494144b5aa6fd5e6a3b3 100644 --- a/crates/language_models/src/provider/x_ai.rs +++ b/crates/language_models/src/provider/x_ai.rs @@ -44,7 +44,7 @@ pub struct State { } impl State { - fn is_authenticated(&self) -> bool { + const fn is_authenticated(&self) -> bool { self.api_key_state.has_key() } diff --git a/crates/language_onboarding/src/python.rs b/crates/language_onboarding/src/python.rs index e715cb7c806f417980a93a62210c72ca8529fcb5..b89bc079f84997d6533c59408e9119cfb4c72a6f 100644 --- a/crates/language_onboarding/src/python.rs +++ b/crates/language_onboarding/src/python.rs @@ -31,7 +31,7 @@ impl BasedPyrightBanner { } } - fn onboarding_banner_enabled(&self) -> bool { + const fn onboarding_banner_enabled(&self) -> bool { !self.dismissed && self.have_basedpyright } } diff --git a/crates/language_tools/src/lsp_log_view.rs b/crates/language_tools/src/lsp_log_view.rs index e834dd6aec003930d68ed745f67aff50b2c8f66b..77cd0634d8bc498e3c37109a17cf06b5a164c9cb 100644 --- a/crates/language_tools/src/lsp_log_view.rs +++ b/crates/language_tools/src/lsp_log_view.rs @@ -668,7 +668,7 @@ impl LspLogView { } } -fn log_type(log_kind: LogKind) -> Option { +const fn log_type(log_kind: LogKind) -> Option { match log_kind { LogKind::Rpc => Some(LogType::Rpc), LogKind::Trace => Some(LogType::Trace), @@ -1275,7 +1275,7 @@ const SERVER_TRACE: &str = "Server Trace"; const SERVER_INFO: &str = "Server Info"; impl LspLogToolbarItemView { - pub fn new() -> Self { + pub const fn new() -> Self { Self { log_view: None, _log_view_subscription: None, diff --git a/crates/language_tools/src/syntax_tree_view.rs b/crates/language_tools/src/syntax_tree_view.rs index 464d518c2e9c697d292d7bffda7ee7bae68dd254..4feede62da62c9a75c09cee5be038d73946f2e49 100644 --- a/crates/language_tools/src/syntax_tree_view.rs +++ b/crates/language_tools/src/syntax_tree_view.rs @@ -594,7 +594,7 @@ impl Default for SyntaxTreeToolbarItemView { } impl SyntaxTreeToolbarItemView { - pub fn new() -> Self { + pub const fn new() -> Self { Self { tree_view: None, subscription: None, diff --git a/crates/languages/src/css.rs b/crates/languages/src/css.rs index 035a2c693dbbdceed38adc8ccc0510274205670f..1de195c6a046a51cfd164822e4bd5f7fd497be30 100644 --- a/crates/languages/src/css.rs +++ b/crates/languages/src/css.rs @@ -28,7 +28,7 @@ pub struct CssLspAdapter { impl CssLspAdapter { const PACKAGE_NAME: &str = "vscode-langservers-extracted"; - pub fn new(node: NodeRuntime) -> Self { + pub const fn new(node: NodeRuntime) -> Self { CssLspAdapter { node } } } diff --git a/crates/languages/src/json.rs b/crates/languages/src/json.rs index 45fa2dd75cce051439980b40996dda9865246a99..cb2338360d19ab3235413de4b662b30a22152ef7 100644 --- a/crates/languages/src/json.rs +++ b/crates/languages/src/json.rs @@ -135,7 +135,7 @@ pub struct JsonLspAdapter { impl JsonLspAdapter { const PACKAGE_NAME: &str = "vscode-langservers-extracted"; - pub fn new(node: NodeRuntime) -> Self { + pub const fn new(node: NodeRuntime) -> Self { Self { node } } } diff --git a/crates/languages/src/python.rs b/crates/languages/src/python.rs index d0bdff37676c0a7fc6e4ba4930ad461497dd790d..1727e262a586c315dce5c792d4a8f5066a0c4a13 100644 --- a/crates/languages/src/python.rs +++ b/crates/languages/src/python.rs @@ -341,7 +341,7 @@ impl PyrightLspAdapter { const SERVER_PATH: &str = "node_modules/pyright/langserver.index.js"; const NODE_MODULE_RELATIVE_SERVER_PATH: &str = "pyright/langserver.index.js"; - pub fn new(node: NodeRuntime) -> Self { + pub const fn new(node: NodeRuntime) -> Self { PyrightLspAdapter { node } } @@ -905,7 +905,7 @@ fn python_module_name_from_relative_path(relative_path: &str) -> String { .to_string() } -fn is_python_env_global(k: &PythonEnvironmentKind) -> bool { +const fn is_python_env_global(k: &PythonEnvironmentKind) -> bool { matches!( k, PythonEnvironmentKind::Homebrew @@ -920,7 +920,7 @@ fn is_python_env_global(k: &PythonEnvironmentKind) -> bool { ) } -fn python_env_kind_display(k: &PythonEnvironmentKind) -> &'static str { +const fn python_env_kind_display(k: &PythonEnvironmentKind) -> &'static str { match k { PythonEnvironmentKind::Conda => "Conda", PythonEnvironmentKind::Pixi => "pixi", @@ -1320,7 +1320,7 @@ pub(crate) struct PyLspAdapter { } impl PyLspAdapter { const SERVER_NAME: LanguageServerName = LanguageServerName::new_static("pylsp"); - pub(crate) fn new() -> Self { + pub(crate) const fn new() -> Self { Self { python_venv_base: OnceCell::new(), } @@ -1631,7 +1631,7 @@ impl BasedPyrightLspAdapter { const SERVER_PATH: &str = "node_modules/basedpyright/langserver.index.js"; const NODE_MODULE_RELATIVE_SERVER_PATH: &str = "basedpyright/langserver.index.js"; - pub(crate) fn new(node: NodeRuntime) -> Self { + pub(crate) const fn new(node: NodeRuntime) -> Self { BasedPyrightLspAdapter { node } } diff --git a/crates/languages/src/tailwind.rs b/crates/languages/src/tailwind.rs index e1b50a5ccaabb7770d13abc79fbac1da5fa4cbbe..4d626f9f6f9bbd30129a44400ac13fd8017adf4c 100644 --- a/crates/languages/src/tailwind.rs +++ b/crates/languages/src/tailwind.rs @@ -35,7 +35,7 @@ impl TailwindLspAdapter { LanguageServerName::new_static("tailwindcss-language-server"); const PACKAGE_NAME: &str = "@tailwindcss/language-server"; - pub fn new(node: NodeRuntime) -> Self { + pub const fn new(node: NodeRuntime) -> Self { TailwindLspAdapter { node } } } diff --git a/crates/languages/src/typescript.rs b/crates/languages/src/typescript.rs index a9a1104c8c6cfa2b6eaa7083d18316cee4978fc8..2d7208ac6c9f0d7baf50d7f26c15fb258096fa7b 100644 --- a/crates/languages/src/typescript.rs +++ b/crates/languages/src/typescript.rs @@ -890,7 +890,7 @@ impl EsLintLspAdapter { "eslint.config.mts", ]; - pub fn new(node: NodeRuntime) -> Self { + pub const fn new(node: NodeRuntime) -> Self { EsLintLspAdapter { node } } diff --git a/crates/languages/src/yaml.rs b/crates/languages/src/yaml.rs index 45faa142369e6c08817deebfbf8774f228bf70d5..323724057e1abd89ef40ddc36f2f36eb6f7aae52 100644 --- a/crates/languages/src/yaml.rs +++ b/crates/languages/src/yaml.rs @@ -31,7 +31,7 @@ pub struct YamlLspAdapter { impl YamlLspAdapter { const SERVER_NAME: LanguageServerName = LanguageServerName::new_static("yaml-language-server"); const PACKAGE_NAME: &str = "yaml-language-server"; - pub fn new(node: NodeRuntime) -> Self { + pub const fn new(node: NodeRuntime) -> Self { YamlLspAdapter { node } } } diff --git a/crates/lmstudio/src/lmstudio.rs b/crates/lmstudio/src/lmstudio.rs index ef2f7b6208f62e079609049b8eff83a80034741e..14a9ac0189fa3bcb02e0a27cf8f520738cc523b7 100644 --- a/crates/lmstudio/src/lmstudio.rs +++ b/crates/lmstudio/src/lmstudio.rs @@ -76,11 +76,11 @@ impl Model { self.display_name.as_ref().unwrap_or(&self.name) } - pub fn max_token_count(&self) -> u64 { + pub const fn max_token_count(&self) -> u64 { self.max_tokens } - pub fn supports_tool_calls(&self) -> bool { + pub const fn supports_tool_calls(&self) -> bool { self.supports_tool_calls } } @@ -138,7 +138,7 @@ pub enum MessageContent { } impl MessageContent { - pub fn empty() -> Self { + pub const fn empty() -> Self { MessageContent::Multipart(vec![]) } diff --git a/crates/lsp/src/lsp.rs b/crates/lsp/src/lsp.rs index 84e5a95ed80e75bf7d338b589f5b1c1c6495a616..1cbf6e68f4dc8642760e289dbe5e9bb21247d703 100644 --- a/crates/lsp/src/lsp.rs +++ b/crates/lsp/src/lsp.rs @@ -121,11 +121,11 @@ pub enum LanguageServerSelector { pub struct LanguageServerId(pub usize); impl LanguageServerId { - pub fn from_proto(id: u64) -> Self { + pub const fn from_proto(id: u64) -> Self { Self(id as usize) } - pub fn to_proto(self) -> u64 { + pub const fn to_proto(self) -> u64 { self.0 as u64 } } @@ -279,7 +279,7 @@ struct LspRequest { } impl LspRequest { - pub fn new(id: i32, request: F) -> Self { + pub const fn new(id: i32, request: F) -> Self { Self { id, request } } } @@ -1176,12 +1176,12 @@ impl LanguageServer { } /// Get the id of the running language server. - pub fn server_id(&self) -> LanguageServerId { + pub const fn server_id(&self) -> LanguageServerId { self.server_id } /// Language server's binary information. - pub fn binary(&self) -> &LanguageServerBinary { + pub const fn binary(&self) -> &LanguageServerBinary { &self.binary } diff --git a/crates/markdown/src/markdown.rs b/crates/markdown/src/markdown.rs index c34ed69288e39c26d105877d76ee76c01c864c72..fc5f032bc033bcf19d4f515a93aa7588f516e083 100644 --- a/crates/markdown/src/markdown.rs +++ b/crates/markdown/src/markdown.rs @@ -204,7 +204,7 @@ impl Markdown { this } - pub fn is_parsing(&self) -> bool { + pub const fn is_parsing(&self) -> bool { self.pending_parse.is_some() } @@ -411,7 +411,7 @@ struct Selection { } impl Selection { - fn set_head(&mut self, head: usize) { + const fn set_head(&mut self, head: usize) { if head < self.tail() { if !self.reversed { self.end = self.start; @@ -427,7 +427,7 @@ impl Selection { } } - fn tail(&self) -> usize { + const fn tail(&self) -> usize { if self.reversed { self.end } else { self.start } } } @@ -441,11 +441,11 @@ pub struct ParsedMarkdown { } impl ParsedMarkdown { - pub fn source(&self) -> &SharedString { + pub const fn source(&self) -> &SharedString { &self.source } - pub fn events(&self) -> &Arc<[(Range, MarkdownEvent)]> { + pub const fn events(&self) -> &Arc<[(Range, MarkdownEvent)]> { &self.events } } diff --git a/crates/markdown_preview/src/markdown_elements.rs b/crates/markdown_preview/src/markdown_elements.rs index d0bde48889143b8ab9f66d9dc2839ebabf7d3541..09180bd38b062452997578e1e2f342f408438878 100644 --- a/crates/markdown_preview/src/markdown_elements.rs +++ b/crates/markdown_preview/src/markdown_elements.rs @@ -36,7 +36,7 @@ impl ParsedMarkdownElement { }) } - pub fn is_list_item(&self) -> bool { + pub const fn is_list_item(&self) -> bool { matches!(self, Self::ListItem(_)) } } @@ -132,13 +132,13 @@ impl Default for ParsedMarkdownTableRow { } impl ParsedMarkdownTableRow { - pub fn new() -> Self { + pub const fn new() -> Self { Self { children: Vec::new(), } } - pub fn with_children(children: Vec) -> Self { + pub const fn with_children(children: Vec) -> Self { Self { children } } } @@ -326,11 +326,11 @@ impl Image { self.alt_text = Some(alt_text); } - pub fn set_width(&mut self, width: DefiniteLength) { + pub const fn set_width(&mut self, width: DefiniteLength) { self.width = Some(width); } - pub fn set_height(&mut self, height: DefiniteLength) { + pub const fn set_height(&mut self, height: DefiniteLength) { self.height = Some(height); } } diff --git a/crates/markdown_preview/src/markdown_minifier.rs b/crates/markdown_preview/src/markdown_minifier.rs index a7d5ad0be0d9e65617bb45c66eb9748123d43067..23ef755ec98d2b47c9d5bd3900f2f07dd3982cbe 100644 --- a/crates/markdown_preview/src/markdown_minifier.rs +++ b/crates/markdown_preview/src/markdown_minifier.rs @@ -24,7 +24,7 @@ where { /// Creates a new `Minifier` instance. #[inline] - pub fn new(w: &'a mut W, options: MinifierOptions) -> Self { + pub const fn new(w: &'a mut W, options: MinifierOptions) -> Self { Self { w, options, diff --git a/crates/markdown_preview/src/markdown_parser.rs b/crates/markdown_preview/src/markdown_parser.rs index ad175922daaa20508852f36dd4f62ad90199b7ca..d2db12cf4954eb1e105d4b280b81549a3cc7a2be 100644 --- a/crates/markdown_preview/src/markdown_parser.rs +++ b/crates/markdown_preview/src/markdown_parser.rs @@ -76,7 +76,7 @@ impl Default for MarkdownListItem { } impl<'a> MarkdownParser<'a> { - fn new( + const fn new( tokens: Vec<(Event<'a>, Range)>, file_location_directory: Option, language_registry: Option>, @@ -90,7 +90,7 @@ impl<'a> MarkdownParser<'a> { } } - fn eof(&self) -> bool { + const fn eof(&self) -> bool { if self.tokens.is_empty() { return true; } @@ -119,7 +119,7 @@ impl<'a> MarkdownParser<'a> { self.current().map(|(event, _)| event) } - fn is_text_like(event: &Event) -> bool { + const fn is_text_like(event: &Event) -> bool { match event { Event::Text(_) // Represent an inline code block @@ -515,7 +515,7 @@ impl<'a> MarkdownParser<'a> { } } - fn convert_alignment(alignment: &Alignment) -> ParsedMarkdownTableAlignment { + const fn convert_alignment(alignment: &Alignment) -> ParsedMarkdownTableAlignment { match alignment { Alignment::None => ParsedMarkdownTableAlignment::None, Alignment::Left => ParsedMarkdownTableAlignment::Left, diff --git a/crates/markdown_preview/src/markdown_renderer.rs b/crates/markdown_preview/src/markdown_renderer.rs index 6f794b1358a1869779b01f6af3069bf8be735e7e..1beedfdb195663700121b94149b4aafbc3369a5c 100644 --- a/crates/markdown_preview/src/markdown_renderer.rs +++ b/crates/markdown_preview/src/markdown_renderer.rs @@ -36,7 +36,7 @@ impl CheckboxClickedEvent { self.source_range.clone() } - pub fn checked(&self) -> bool { + pub const fn checked(&self) -> bool { self.checked } } diff --git a/crates/menu/src/menu.rs b/crates/menu/src/menu.rs index 9a1937d100210cb975ab0630be9fd15078561e0b..bcf66d4d0065dd4e813143f85e50d47d261311a3 100644 --- a/crates/menu/src/menu.rs +++ b/crates/menu/src/menu.rs @@ -7,7 +7,7 @@ use gpui::actions; // These may provide relevant context: // https://github.com/rust-lang/rust/issues/47384 // https://github.com/mmastrac/rust-ctor/issues/280 -pub fn init() {} +pub const fn init() {} actions!( menu, diff --git a/crates/mistral/src/mistral.rs b/crates/mistral/src/mistral.rs index eca4743d0442b9ca169ac966f78af0112565fcbc..d8afd630826b50d1672cdcd1c3ba777293d32a1c 100644 --- a/crates/mistral/src/mistral.rs +++ b/crates/mistral/src/mistral.rs @@ -92,7 +92,7 @@ pub enum Model { } impl Model { - pub fn default_fast() -> Self { + pub const fn default_fast() -> Self { Model::MistralSmallLatest } @@ -152,7 +152,7 @@ impl Model { } } - pub fn max_token_count(&self) -> u64 { + pub const fn max_token_count(&self) -> u64 { match self { Self::CodestralLatest => 256000, Self::MistralLargeLatest => 131000, @@ -170,7 +170,7 @@ impl Model { } } - pub fn max_output_tokens(&self) -> Option { + pub const fn max_output_tokens(&self) -> Option { match self { Self::Custom { max_output_tokens, .. @@ -313,7 +313,7 @@ pub enum MessageContent { } impl MessageContent { - pub fn empty() -> Self { + pub const fn empty() -> Self { Self::Plain { content: String::new(), } diff --git a/crates/multi_buffer/src/anchor.rs b/crates/multi_buffer/src/anchor.rs index a2498cb02fb836c6a70af9407d2a4e520c9d3d3b..43c53aef02d6068af43d0239ae0ea7cf87b24afa 100644 --- a/crates/multi_buffer/src/anchor.rs +++ b/crates/multi_buffer/src/anchor.rs @@ -16,14 +16,14 @@ pub struct Anchor { } impl Anchor { - pub fn with_diff_base_anchor(self, diff_base_anchor: text::Anchor) -> Self { + pub const fn with_diff_base_anchor(self, diff_base_anchor: text::Anchor) -> Self { Self { diff_base_anchor: Some(diff_base_anchor), ..self } } - pub fn in_buffer( + pub const fn in_buffer( excerpt_id: ExcerptId, buffer_id: BufferId, text_anchor: text::Anchor, @@ -36,7 +36,7 @@ impl Anchor { } } - pub fn range_in_buffer( + pub const fn range_in_buffer( excerpt_id: ExcerptId, buffer_id: BufferId, range: Range, @@ -45,7 +45,7 @@ impl Anchor { ..Self::in_buffer(excerpt_id, buffer_id, range.end) } - pub fn min() -> Self { + pub const fn min() -> Self { Self { buffer_id: None, excerpt_id: ExcerptId::min(), @@ -54,7 +54,7 @@ impl Anchor { } } - pub fn max() -> Self { + pub const fn max() -> Self { Self { buffer_id: None, excerpt_id: ExcerptId::max(), @@ -108,7 +108,7 @@ impl Anchor { Ordering::Equal } - pub fn bias(&self) -> Bias { + pub const fn bias(&self) -> Bias { self.text_anchor.bias } diff --git a/crates/multi_buffer/src/multi_buffer.rs b/crates/multi_buffer/src/multi_buffer.rs index 18a619212dba49bf1c384679ec90120af80e0e2a..780d05f9bb55b0207f9a22a028c4346f70ffaff3 100644 --- a/crates/multi_buffer/src/multi_buffer.rs +++ b/crates/multi_buffer/src/multi_buffer.rs @@ -156,7 +156,7 @@ impl MultiBufferDiffHunk { && self.buffer_range == (text::Anchor::MIN..text::Anchor::MAX) } - pub fn multi_buffer_range(&self) -> Range { + pub const fn multi_buffer_range(&self) -> Range { let start = Anchor::in_buffer(self.excerpt_id, self.buffer_id, self.buffer_range.start); let end = Anchor::in_buffer(self.excerpt_id, self.buffer_id, self.buffer_range.end); start..end @@ -171,7 +171,7 @@ pub struct PathKey { } impl PathKey { - pub fn with_sort_prefix(sort_prefix: u64, path: Arc) -> Self { + pub const fn with_sort_prefix(sort_prefix: u64, path: Arc) -> Self { Self { sort_prefix: Some(sort_prefix), path, @@ -587,7 +587,7 @@ pub enum ExpandExcerptDirection { } impl ExpandExcerptDirection { - pub fn should_expand_up(&self) -> bool { + pub const fn should_expand_up(&self) -> bool { match self { ExpandExcerptDirection::Up => true, ExpandExcerptDirection::Down => false, @@ -595,7 +595,7 @@ impl ExpandExcerptDirection { } } - pub fn should_expand_down(&self) -> bool { + pub const fn should_expand_down(&self) -> bool { match self { ExpandExcerptDirection::Up => false, ExpandExcerptDirection::Down => true, @@ -615,7 +615,7 @@ pub struct IndentGuide { } impl IndentGuide { - pub fn indent_level(&self) -> u32 { + pub const fn indent_level(&self) -> u32 { self.depth * self.tab_size } } @@ -745,7 +745,7 @@ impl MultiBuffer { } } - pub fn is_singleton(&self) -> bool { + pub const fn is_singleton(&self) -> bool { self.singleton } @@ -4224,7 +4224,7 @@ impl MultiBufferSnapshot { .map(|ch| classifier.kind(ch)) } - pub fn is_singleton(&self) -> bool { + pub const fn is_singleton(&self) -> bool { self.singleton } @@ -5408,11 +5408,11 @@ impl MultiBufferSnapshot { }) } - pub fn edit_count(&self) -> usize { + pub const fn edit_count(&self) -> usize { self.edit_count } - pub fn non_text_state_update_count(&self) -> usize { + pub const fn non_text_state_update_count(&self) -> usize { self.non_text_state_update_count } @@ -5891,7 +5891,7 @@ impl MultiBufferSnapshot { result.into_iter() } - pub fn trailing_excerpt_update_count(&self) -> usize { + pub const fn trailing_excerpt_update_count(&self) -> usize { self.trailing_excerpt_update_count } @@ -5953,15 +5953,15 @@ impl MultiBufferSnapshot { Some(buffer_snapshot.language_indent_size_at(offset, cx)) } - pub fn is_dirty(&self) -> bool { + pub const fn is_dirty(&self) -> bool { self.is_dirty } - pub fn has_deleted_file(&self) -> bool { + pub const fn has_deleted_file(&self) -> bool { self.has_deleted_file } - pub fn has_conflict(&self) -> bool { + pub const fn has_conflict(&self) -> bool { self.has_conflict } @@ -6333,7 +6333,7 @@ impl MultiBufferSnapshot { }) } - pub fn show_headers(&self) -> bool { + pub const fn show_headers(&self) -> bool { self.show_headers } @@ -7027,15 +7027,15 @@ impl Excerpt { } impl<'a> MultiBufferExcerpt<'a> { - pub fn id(&self) -> ExcerptId { + pub const fn id(&self) -> ExcerptId { self.excerpt.id } - pub fn buffer_id(&self) -> BufferId { + pub const fn buffer_id(&self) -> BufferId { self.excerpt.buffer_id } - pub fn start_anchor(&self) -> Anchor { + pub const fn start_anchor(&self) -> Anchor { Anchor::in_buffer( self.excerpt.id, self.excerpt.buffer_id, @@ -7043,7 +7043,7 @@ impl<'a> MultiBufferExcerpt<'a> { ) } - pub fn end_anchor(&self) -> Anchor { + pub const fn end_anchor(&self) -> Anchor { Anchor::in_buffer( self.excerpt.id, self.excerpt.buffer_id, @@ -7051,7 +7051,7 @@ impl<'a> MultiBufferExcerpt<'a> { ) } - pub fn buffer(&self) -> &'a BufferSnapshot { + pub const fn buffer(&self) -> &'a BufferSnapshot { &self.excerpt.buffer } @@ -7065,7 +7065,7 @@ impl<'a> MultiBufferExcerpt<'a> { .to_offset(&self.excerpt.buffer.text) } - pub fn start_offset(&self) -> usize { + pub const fn start_offset(&self) -> usize { self.offset } @@ -7144,25 +7144,25 @@ impl<'a> MultiBufferExcerpt<'a> { && range.end <= self.excerpt.buffer_end_offset() } - pub fn max_buffer_row(&self) -> u32 { + pub const fn max_buffer_row(&self) -> u32 { self.excerpt.max_buffer_row } } impl ExcerptId { - pub fn min() -> Self { + pub const fn min() -> Self { Self(0) } - pub fn max() -> Self { + pub const fn max() -> Self { Self(u32::MAX) } - pub fn to_proto(self) -> u64 { + pub const fn to_proto(self) -> u64 { self.0 as _ } - pub fn from_proto(proto: u64) -> Self { + pub const fn from_proto(proto: u64) -> Self { Self(proto as _) } @@ -7226,7 +7226,7 @@ impl sum_tree::KeyedItem for ExcerptIdMapping { } impl DiffTransform { - fn hunk_info(&self) -> Option { + const fn hunk_info(&self) -> Option { match self { DiffTransform::DeletedHunk { hunk_info, .. } => Some(*hunk_info), DiffTransform::BufferContent { @@ -7254,7 +7254,7 @@ impl sum_tree::Item for DiffTransform { } impl DiffTransformSummary { - fn excerpt_len(&self) -> ExcerptOffset { + const fn excerpt_len(&self) -> ExcerptOffset { ExcerptOffset::new(self.input.len) } } @@ -7593,7 +7593,7 @@ impl Iterator for MultiBufferRows<'_> { } impl<'a> MultiBufferChunks<'a> { - pub fn offset(&self) -> usize { + pub const fn offset(&self) -> usize { self.range.start } diff --git a/crates/multi_buffer/src/position.rs b/crates/multi_buffer/src/position.rs index 8a3ce78d0d9f7a6880dbc3202c002507c800b7b0..90ef230b7373e5f6d1c34e34637f6dad6769036a 100644 --- a/crates/multi_buffer/src/position.rs +++ b/crates/multi_buffer/src/position.rs @@ -24,63 +24,63 @@ pub struct TypedRow { } impl TypedOffset { - pub fn new(offset: usize) -> Self { + pub const fn new(offset: usize) -> Self { Self { value: offset, _marker: PhantomData, } } - pub fn saturating_sub(self, n: TypedOffset) -> Self { + pub const fn saturating_sub(self, n: TypedOffset) -> Self { Self { value: self.value.saturating_sub(n.value), _marker: PhantomData, } } - pub fn zero() -> Self { + pub const fn zero() -> Self { Self::new(0) } - pub fn is_zero(&self) -> bool { + pub const fn is_zero(&self) -> bool { self.value == 0 } } impl TypedPoint { - pub fn new(row: u32, column: u32) -> Self { + pub const fn new(row: u32, column: u32) -> Self { Self { value: Point::new(row, column), _marker: PhantomData, } } - pub fn wrap(point: Point) -> Self { + pub const fn wrap(point: Point) -> Self { Self { value: point, _marker: PhantomData, } } - pub fn row(&self) -> u32 { + pub const fn row(&self) -> u32 { self.value.row } - pub fn column(&self) -> u32 { + pub const fn column(&self) -> u32 { self.value.column } - pub fn zero() -> Self { + pub const fn zero() -> Self { Self::wrap(Point::zero()) } - pub fn is_zero(&self) -> bool { + pub const fn is_zero(&self) -> bool { self.value.is_zero() } } impl TypedRow { - pub fn new(row: u32) -> Self { + pub const fn new(row: u32) -> Self { Self { value: row, _marker: PhantomData, diff --git a/crates/notifications/src/status_toast.rs b/crates/notifications/src/status_toast.rs index 7affa93f5a496bd0e436c74e5ff32f8aa871d026..e92cfa26c630689bc240fa4ff8da01a2c4e90f61 100644 --- a/crates/notifications/src/status_toast.rs +++ b/crates/notifications/src/status_toast.rs @@ -19,7 +19,7 @@ impl ToastIcon { } } - pub fn color(mut self, color: Color) -> Self { + pub const fn color(mut self, color: Color) -> Self { self.color = color; self } @@ -67,7 +67,7 @@ impl StatusToast { }) } - pub fn icon(mut self, icon: ToastIcon) -> Self { + pub const fn icon(mut self, icon: ToastIcon) -> Self { self.icon = Some(icon); self } @@ -90,7 +90,7 @@ impl StatusToast { self } - pub fn dismiss_button(mut self, show: bool) -> Self { + pub const fn dismiss_button(mut self, show: bool) -> Self { self.show_dismiss = show; self } diff --git a/crates/ollama/src/ollama.rs b/crates/ollama/src/ollama.rs index 0ed3b6da17d952cc874485337ec380ef3ca990a8..e43433de418516fe6b48dd93f93d7e8ddb48b196 100644 --- a/crates/ollama/src/ollama.rs +++ b/crates/ollama/src/ollama.rs @@ -72,7 +72,7 @@ impl Model { self.display_name.as_ref().unwrap_or(&self.name) } - pub fn max_token_count(&self) -> u64 { + pub const fn max_token_count(&self) -> u64 { self.max_tokens } } diff --git a/crates/onboarding/src/theme_preview.rs b/crates/onboarding/src/theme_preview.rs index 8bd65d8a2707acdc53333071486f41741398a82a..ae0ce9e301e6a84346aa1a85c71011941e6e990d 100644 --- a/crates/onboarding/src/theme_preview.rs +++ b/crates/onboarding/src/theme_preview.rs @@ -43,7 +43,7 @@ impl ThemePreviewTile { pub const ROOT_PADDING: Pixels = px(2.0); pub const CHILD_BORDER: Pixels = px(1.0); - pub fn new(theme: Arc, seed: f32) -> Self { + pub const fn new(theme: Arc, seed: f32) -> Self { Self { theme, seed, diff --git a/crates/open_ai/src/open_ai.rs b/crates/open_ai/src/open_ai.rs index 1cada03a60c54668d2675c2e076345a9507fcb43..cf66a985b80b912048a4aa0a30f2170429cc6a80 100644 --- a/crates/open_ai/src/open_ai.rs +++ b/crates/open_ai/src/open_ai.rs @@ -95,7 +95,7 @@ pub enum Model { } impl Model { - pub fn default_fast() -> Self { + pub const fn default_fast() -> Self { // TODO: Replace with FiveMini since all other models are deprecated Self::FourPointOneMini } @@ -165,7 +165,7 @@ impl Model { } } - pub fn max_token_count(&self) -> u64 { + pub const fn max_token_count(&self) -> u64 { match self { Self::ThreePointFiveTurbo => 16_385, Self::Four => 8_192, @@ -186,7 +186,7 @@ impl Model { } } - pub fn max_output_tokens(&self) -> Option { + pub const fn max_output_tokens(&self) -> Option { match self { Self::Custom { max_output_tokens, .. @@ -221,7 +221,7 @@ impl Model { /// Returns whether the given model supports the `parallel_tool_calls` parameter. /// /// If the model does not support the parameter, do not pass it up, or the API will return an error. - pub fn supports_parallel_tool_calls(&self) -> bool { + pub const fn supports_parallel_tool_calls(&self) -> bool { match self { Self::ThreePointFiveTurbo | Self::Four @@ -241,7 +241,7 @@ impl Model { /// Returns whether the given model supports the `prompt_cache_key` parameter. /// /// If the model does not support the parameter, do not pass it up. - pub fn supports_prompt_cache_key(&self) -> bool { + pub const fn supports_prompt_cache_key(&self) -> bool { true } } @@ -321,7 +321,7 @@ pub enum MessageContent { } impl MessageContent { - pub fn empty() -> Self { + pub const fn empty() -> Self { MessageContent::Multipart(vec![]) } diff --git a/crates/open_router/src/open_router.rs b/crates/open_router/src/open_router.rs index 0081c877756dab46433481ac58f2180877e7667f..6d6f9ccffede1df4b08dc5eddfae84cf69e32d3e 100644 --- a/crates/open_router/src/open_router.rs +++ b/crates/open_router/src/open_router.rs @@ -126,11 +126,11 @@ impl Model { self.display_name.as_ref().unwrap_or(&self.name) } - pub fn max_token_count(&self) -> u64 { + pub const fn max_token_count(&self) -> u64 { self.max_tokens } - pub fn max_output_tokens(&self) -> Option { + pub const fn max_output_tokens(&self) -> Option { None } @@ -138,7 +138,7 @@ impl Model { self.supports_tools.unwrap_or(false) } - pub fn supports_parallel_tool_calls(&self) -> bool { + pub const fn supports_parallel_tool_calls(&self) -> bool { false } } @@ -236,7 +236,7 @@ pub enum MessageContent { } impl MessageContent { - pub fn empty() -> Self { + pub const fn empty() -> Self { Self::Plain(String::new()) } @@ -726,7 +726,7 @@ impl std::fmt::Display for ApiErrorCode { } impl ApiErrorCode { - pub fn from_status(status: u16) -> Self { + pub const fn from_status(status: u16) -> Self { match status { 400 => ApiErrorCode::InvalidRequestError, 401 => ApiErrorCode::AuthenticationError, diff --git a/crates/outline_panel/src/outline_panel.rs b/crates/outline_panel/src/outline_panel.rs index 4a4990b40a5f3f7ad2f182e007593e62a8bcd015..912d00a584baae875061d79c177c13e70dd5ab8e 100644 --- a/crates/outline_panel/src/outline_panel.rs +++ b/crates/outline_panel/src/outline_panel.rs @@ -290,7 +290,7 @@ impl SelectedEntry { } } - fn is_invalidated(&self) -> bool { + const fn is_invalidated(&self) -> bool { matches!(self, Self::Invalidated(_)) } } @@ -302,7 +302,7 @@ struct FsChildren { } impl FsChildren { - fn may_be_fold_part(&self) -> bool { + const fn may_be_fold_part(&self) -> bool { self.dirs == 0 || (self.dirs == 1 && self.files == 0) } } @@ -344,7 +344,7 @@ impl Excerpt { } } - fn should_fetch_outlines(&self) -> bool { + const fn should_fetch_outlines(&self) -> bool { match &self.outlines { ExcerptOutlines::Outlines(_) => false, ExcerptOutlines::Invalidated(_) => true, @@ -577,7 +577,7 @@ enum OutlineEntry { } impl OutlineEntry { - fn ids(&self) -> (BufferId, ExcerptId) { + const fn ids(&self) -> (BufferId, ExcerptId) { match self { OutlineEntry::Excerpt(excerpt) => (excerpt.buffer_id, excerpt.id), OutlineEntry::Outline(outline) => (outline.buffer_id, outline.excerpt_id), @@ -1416,7 +1416,7 @@ impl OutlinePanel { cx.notify(); } - fn is_unfoldable(&self, entry: &PanelEntry) -> bool { + const fn is_unfoldable(&self, entry: &PanelEntry) -> bool { matches!(entry, PanelEntry::FoldedDirs(..)) } @@ -4444,7 +4444,7 @@ impl OutlinePanel { cx.notify(); } - fn selected_entry(&self) -> Option<&PanelEntry> { + const fn selected_entry(&self) -> Option<&PanelEntry> { match &self.selected_entry { SelectedEntry::Invalidated(entry) => entry.as_ref(), SelectedEntry::Valid(entry, _) => Some(entry), diff --git a/crates/paths/src/paths.rs b/crates/paths/src/paths.rs index bbb6ddb976312b7baca5a11ace863b4a3be8d2bc..5fdb90bd94bf6c0515f614c7d5c6c0cf604c32cb 100644 --- a/crates/paths/src/paths.rs +++ b/crates/paths/src/paths.rs @@ -403,12 +403,12 @@ pub fn remote_servers_dir() -> &'static PathBuf { } /// Returns the relative path to a `.zed` folder within a project. -pub fn local_settings_folder_name() -> &'static str { +pub const fn local_settings_folder_name() -> &'static str { ".zed" } /// Returns the relative path to a `.vscode` folder within a project. -pub fn local_vscode_folder_name() -> &'static str { +pub const fn local_vscode_folder_name() -> &'static str { ".vscode" } @@ -433,11 +433,11 @@ pub fn local_vscode_tasks_file_relative_path() -> &'static RelPath { *CACHED } -pub fn debug_task_file_name() -> &'static str { +pub const fn debug_task_file_name() -> &'static str { "debug.json" } -pub fn task_file_name() -> &'static str { +pub const fn task_file_name() -> &'static str { "tasks.json" } diff --git a/crates/picker/src/picker.rs b/crates/picker/src/picker.rs index 247fcbdd875ffc2e52d90d9b1309f874c508e588..f99d511d84bfa8a06757cc811f0a20c4ba7de048 100644 --- a/crates/picker/src/picker.rs +++ b/crates/picker/src/picker.rs @@ -332,22 +332,22 @@ impl Picker { self } - pub fn widest_item(mut self, ix: Option) -> Self { + pub const fn widest_item(mut self, ix: Option) -> Self { self.widest_item = ix; self } - pub fn max_height(mut self, max_height: Option) -> Self { + pub const fn max_height(mut self, max_height: Option) -> Self { self.max_height = max_height; self } - pub fn show_scrollbar(mut self, show_scrollbar: bool) -> Self { + pub const fn show_scrollbar(mut self, show_scrollbar: bool) -> Self { self.show_scrollbar = show_scrollbar; self } - pub fn modal(mut self, modal: bool) -> Self { + pub const fn modal(mut self, modal: bool) -> Self { self.is_modal = modal; self } diff --git a/crates/picker/src/popover_menu.rs b/crates/picker/src/popover_menu.rs index 42eedb2492149aa56de527e38fcf4f2b0e4da608..9ff9ed759fc10f35fa4a00d4631f8ed3d37445be 100644 --- a/crates/picker/src/popover_menu.rs +++ b/crates/picker/src/popover_menu.rs @@ -57,7 +57,7 @@ where self } - pub fn offset(mut self, offset: Point) -> Self { + pub const fn offset(mut self, offset: Point) -> Self { self.offset = Some(offset); self } diff --git a/crates/prettier/src/prettier.rs b/crates/prettier/src/prettier.rs index b9c40e814c4caf760123cf460e2eed7298f9e951..493063507ffa270ef575327906cc5b82a3ea0d56 100644 --- a/crates/prettier/src/prettier.rs +++ b/crates/prettier/src/prettier.rs @@ -506,7 +506,7 @@ impl Prettier { } } - pub fn server(&self) -> Option<&Arc> { + pub const fn server(&self) -> Option<&Arc> { match self { Self::Real(local) => Some(&local.server), #[cfg(any(test, feature = "test-support"))] @@ -514,7 +514,7 @@ impl Prettier { } } - pub fn is_default(&self) -> bool { + pub const fn is_default(&self) -> bool { match self { Self::Real(local) => local.default, #[cfg(any(test, feature = "test-support"))] diff --git a/crates/project/src/buffer_store.rs b/crates/project/src/buffer_store.rs index 8a4d4f7918c12abd94cf7bf8fc97c939db7ce033..c3abc6bd079be706800b775b8f965cdd80a1945e 100644 --- a/crates/project/src/buffer_store.rs +++ b/crates/project/src/buffer_store.rs @@ -782,21 +782,21 @@ impl BufferStore { } } - fn as_local_mut(&mut self) -> Option<&mut LocalBufferStore> { + const fn as_local_mut(&mut self) -> Option<&mut LocalBufferStore> { match &mut self.state { BufferStoreState::Local(state) => Some(state), _ => None, } } - fn as_remote_mut(&mut self) -> Option<&mut RemoteBufferStore> { + const fn as_remote_mut(&mut self) -> Option<&mut RemoteBufferStore> { match &mut self.state { BufferStoreState::Remote(state) => Some(state), _ => None, } } - fn as_remote(&self) -> Option<&RemoteBufferStore> { + const fn as_remote(&self) -> Option<&RemoteBufferStore> { match &self.state { BufferStoreState::Remote(state) => Some(state), _ => None, diff --git a/crates/project/src/context_server_store.rs b/crates/project/src/context_server_store.rs index e358ddfbf51a362d95b8b75a9b4831ca4089875d..57ba29f7528720a7bdaccbe1d309bb1cc74ad269 100644 --- a/crates/project/src/context_server_store.rs +++ b/crates/project/src/context_server_store.rs @@ -102,7 +102,7 @@ pub enum ContextServerConfiguration { } impl ContextServerConfiguration { - pub fn command(&self) -> &ContextServerCommand { + pub const fn command(&self) -> &ContextServerCommand { match self { ContextServerConfiguration::Custom { command } => command, ContextServerConfiguration::Extension { command, .. } => command, diff --git a/crates/project/src/debounced_delay.rs b/crates/project/src/debounced_delay.rs index 0ea045be5f581ffa7422fe3fdcf85dd305eff3e7..1bd890251d274e2de20f687d6dceb941f953b414 100644 --- a/crates/project/src/debounced_delay.rs +++ b/crates/project/src/debounced_delay.rs @@ -15,7 +15,7 @@ impl Default for DebouncedDelay { } impl DebouncedDelay { - pub fn new() -> Self { + pub const fn new() -> Self { Self { task: None, cancel_channel: None, diff --git a/crates/project/src/debugger/breakpoint_store.rs b/crates/project/src/debugger/breakpoint_store.rs index 42663ab9852a5dc2e9850d20dd20940c6723d03c..03258b776e0ca7eed7bb2991e5087cdd256bfb51 100644 --- a/crates/project/src/debugger/breakpoint_store.rs +++ b/crates/project/src/debugger/breakpoint_store.rs @@ -47,7 +47,7 @@ mod breakpoints_in_file { session_state: Default::default(), } } - pub(super) fn position(&self) -> &text::Anchor { + pub(super) const fn position(&self) -> &text::Anchor { &self.bp.position } } @@ -638,7 +638,7 @@ impl BreakpointStore { }) } - pub fn active_position(&self) -> Option<&ActiveStackFrame> { + pub const fn active_position(&self) -> Option<&ActiveStackFrame> { self.active_stack_frame.as_ref() } @@ -894,17 +894,17 @@ pub enum BreakpointState { impl BreakpointState { #[inline] - pub fn is_enabled(&self) -> bool { + pub const fn is_enabled(&self) -> bool { matches!(self, BreakpointState::Enabled) } #[inline] - pub fn is_disabled(&self) -> bool { + pub const fn is_disabled(&self) -> bool { matches!(self, BreakpointState::Disabled) } #[inline] - pub fn to_int(self) -> i32 { + pub const fn to_int(self) -> i32 { match self { BreakpointState::Enabled => 0, BreakpointState::Disabled => 1, @@ -922,7 +922,7 @@ pub struct Breakpoint { } impl Breakpoint { - pub fn new_standard() -> Self { + pub const fn new_standard() -> Self { Self { state: BreakpointState::Enabled, hit_condition: None, @@ -995,12 +995,12 @@ impl Breakpoint { } #[inline] - pub fn is_enabled(&self) -> bool { + pub const fn is_enabled(&self) -> bool { self.state.is_enabled() } #[inline] - pub fn is_disabled(&self) -> bool { + pub const fn is_disabled(&self) -> bool { self.state.is_disabled() } } diff --git a/crates/project/src/debugger/dap_store.rs b/crates/project/src/debugger/dap_store.rs index 7d80c563e9678ec097dab030bdca047a967e2cf0..615b833ae8fd38607e19ab3320d2ed21246d4780 100644 --- a/crates/project/src/debugger/dap_store.rs +++ b/crates/project/src/debugger/dap_store.rs @@ -437,7 +437,7 @@ impl DapStore { } } - fn as_local(&self) -> Option<&LocalDapStore> { + const fn as_local(&self) -> Option<&LocalDapStore> { match &self.mode { DapStoreMode::Local(local_dap_store) => Some(local_dap_store), _ => None, @@ -560,11 +560,11 @@ impl DapStore { .map(|client| client.read(cx).capabilities.clone()) } - pub fn breakpoint_store(&self) -> &Entity { + pub const fn breakpoint_store(&self) -> &Entity { &self.breakpoint_store } - pub fn worktree_store(&self) -> &Entity { + pub const fn worktree_store(&self) -> &Entity { &self.worktree_store } @@ -929,7 +929,7 @@ impl DapStore { self.adapter_options.get(name).cloned() } - pub fn all_adapter_options(&self) -> &BTreeMap> { + pub const fn all_adapter_options(&self) -> &BTreeMap> { &self.adapter_options } } diff --git a/crates/project/src/debugger/memory.rs b/crates/project/src/debugger/memory.rs index 42ad64e6880ba653c6c95cb13f0e6bcc23c9bdae..aaa4eb42e5bf0e30c1f97bf000d64e0494cff527 100644 --- a/crates/project/src/debugger/memory.rs +++ b/crates/project/src/debugger/memory.rs @@ -209,7 +209,7 @@ impl MemoryPageBuilder { (self.base_address, contents) } /// Drives the fetching of memory, in an iterator-esque style. - pub(super) fn next_request(&self) -> Option { + pub(super) const fn next_request(&self) -> Option { if self.left_to_read == 0 { None } else { diff --git a/crates/project/src/debugger/session.rs b/crates/project/src/debugger/session.rs index b5fbfd80d6152faf9d04715138859dc565e8cba8..46d45410c9b28768b8928d406bf782f0e1030501 100644 --- a/crates/project/src/debugger/session.rs +++ b/crates/project/src/debugger/session.rs @@ -107,7 +107,7 @@ pub enum ThreadStatus { } impl ThreadStatus { - pub fn label(&self) -> &'static str { + pub const fn label(&self) -> &'static str { match self { ThreadStatus::Running => "Running", ThreadStatus::Stopped => "Stopped", @@ -232,7 +232,7 @@ impl RunningMode { }) } - pub(crate) fn worktree(&self) -> &WeakEntity { + pub(crate) const fn worktree(&self) -> &WeakEntity { &self.worktree } @@ -595,14 +595,14 @@ impl SessionState { } /// Did this debug session stop at least once? - pub(crate) fn has_ever_stopped(&self) -> bool { + pub(crate) const fn has_ever_stopped(&self) -> bool { match self { SessionState::Booting(_) => false, SessionState::Running(running_mode) => running_mode.has_ever_stopped, } } - fn stopped(&mut self) { + const fn stopped(&mut self) { if let SessionState::Running(running) = self { running.has_ever_stopped = true; } @@ -894,7 +894,7 @@ impl Session { }) } - pub fn task_context(&self) -> &TaskContext { + pub const fn task_context(&self) -> &TaskContext { &self.task_context } @@ -999,7 +999,7 @@ impl Session { }) } - pub fn session_id(&self) -> SessionId { + pub const fn session_id(&self) -> SessionId { self.id } @@ -1021,7 +1021,7 @@ impl Session { .map(|session| session.read(cx).id) } - pub fn parent_session(&self) -> Option<&Entity> { + pub const fn parent_session(&self) -> Option<&Entity> { self.parent_session.as_ref() } @@ -1056,11 +1056,11 @@ impl Session { }) } - pub fn capabilities(&self) -> &Capabilities { + pub const fn capabilities(&self) -> &Capabilities { &self.capabilities } - pub fn binary(&self) -> Option<&DebugAdapterBinary> { + pub const fn binary(&self) -> Option<&DebugAdapterBinary> { match &self.mode { SessionState::Booting(_) => None, SessionState::Running(running_mode) => Some(&running_mode.binary), @@ -1075,7 +1075,7 @@ impl Session { self.label.clone() } - pub fn is_terminated(&self) -> bool { + pub const fn is_terminated(&self) -> bool { self.is_session_terminated } @@ -1106,25 +1106,25 @@ impl Session { tx } - pub fn is_started(&self) -> bool { + pub const fn is_started(&self) -> bool { match &self.mode { SessionState::Booting(_) => false, SessionState::Running(running) => running.is_started, } } - pub fn is_building(&self) -> bool { + pub const fn is_building(&self) -> bool { matches!(self.mode, SessionState::Booting(_)) } - pub fn as_running_mut(&mut self) -> Option<&mut RunningMode> { + pub const fn as_running_mut(&mut self) -> Option<&mut RunningMode> { match &mut self.mode { SessionState::Running(local_mode) => Some(local_mode), SessionState::Booting(_) => None, } } - pub fn as_running(&self) -> Option<&RunningMode> { + pub const fn as_running(&self) -> Option<&RunningMode> { match &self.mode { SessionState::Running(local_mode) => Some(local_mode), SessionState::Booting(_) => None, @@ -1917,7 +1917,7 @@ impl Session { ); } - pub fn ignore_breakpoints(&self) -> bool { + pub const fn ignore_breakpoints(&self) -> bool { self.ignore_breakpoints } @@ -2023,7 +2023,7 @@ impl Session { self.send_data_breakpoints(cx); } - pub fn breakpoints_enabled(&self) -> bool { + pub const fn breakpoints_enabled(&self) -> bool { self.ignore_breakpoints } @@ -2236,7 +2236,7 @@ impl Session { } } - pub fn has_ever_stopped(&self) -> bool { + pub const fn has_ever_stopped(&self) -> bool { self.mode.has_ever_stopped() } pub fn step_over( @@ -2503,7 +2503,7 @@ impl Session { .collect() } - pub fn watchers(&self) -> &HashMap { + pub const fn watchers(&self) -> &HashMap { &self.watchers } @@ -2750,7 +2750,7 @@ impl Session { self.thread_states.thread_state(thread_id) } - pub fn quirks(&self) -> SessionQuirks { + pub const fn quirks(&self) -> SessionQuirks { self.quirks } diff --git a/crates/project/src/git_store.rs b/crates/project/src/git_store.rs index 461b15ef5f84a22f2a666674e12d27f0ef341d99..dd31767e0ad0e9230973467201786e7fb6fd82c3 100644 --- a/crates/project/src/git_store.rs +++ b/crates/project/src/git_store.rs @@ -438,7 +438,7 @@ impl GitStore { client.add_entity_request_handler(Self::handle_git_clone); } - pub fn is_local(&self) -> bool { + pub const fn is_local(&self) -> bool { matches!(self.state, GitStoreState::Local { .. }) } pub fn set_active_repo_for_path(&mut self, project_path: &ProjectPath, cx: &mut Context) { @@ -1364,7 +1364,7 @@ impl GitStore { } } - pub fn repositories(&self) -> &HashMap> { + pub const fn repositories(&self) -> &HashMap> { &self.repositories } @@ -2765,11 +2765,11 @@ fn make_remote_delegate( } impl RepositoryId { - pub fn to_proto(self) -> u64 { + pub const fn to_proto(self) -> u64 { self.0 } - pub fn from_proto(id: u64) -> Self { + pub const fn from_proto(id: u64) -> Self { RepositoryId(id) } } @@ -5272,7 +5272,7 @@ fn status_to_proto(status: FileStatus) -> proto::GitFileStatus { } } -fn unmerged_status_to_proto(code: UnmergedStatusCode) -> i32 { +const fn unmerged_status_to_proto(code: UnmergedStatusCode) -> i32 { match code { UnmergedStatusCode::Added => proto::GitStatus::Added as _, UnmergedStatusCode::Deleted => proto::GitStatus::Deleted as _, @@ -5280,7 +5280,7 @@ fn unmerged_status_to_proto(code: UnmergedStatusCode) -> i32 { } } -fn tracked_status_to_proto(code: StatusCode) -> i32 { +const fn tracked_status_to_proto(code: StatusCode) -> i32 { match code { StatusCode::Added => proto::GitStatus::Added as _, StatusCode::Deleted => proto::GitStatus::Deleted as _, diff --git a/crates/project/src/git_store/git_traversal.rs b/crates/project/src/git_store/git_traversal.rs index ca4a22b14d3682790282744b4834980d669b8d93..cb77e15191dd33d040ed47b08faa8debb7b4cdb7 100644 --- a/crates/project/src/git_store/git_traversal.rs +++ b/crates/project/src/git_store/git_traversal.rs @@ -128,7 +128,7 @@ impl<'a> GitTraversal<'a> { found } - pub fn start_offset(&self) -> usize { + pub const fn start_offset(&self) -> usize { self.traversal.start_offset() } @@ -229,7 +229,7 @@ pub struct GitEntry { } impl GitEntry { - pub fn to_ref(&self) -> GitEntryRef<'_> { + pub const fn to_ref(&self) -> GitEntryRef<'_> { GitEntryRef { entry: &self.entry, git_summary: self.git_summary, diff --git a/crates/project/src/lsp_store.rs b/crates/project/src/lsp_store.rs index c33f922a62d6ce702748a92063c8c2a1a2095a56..f34b1957b68e7b4824e800ec65207a6a619070c8 100644 --- a/crates/project/src/lsp_store.rs +++ b/crates/project/src/lsp_store.rs @@ -144,7 +144,7 @@ pub enum LspFormatTarget { pub type OpenLspBufferHandle = Entity>; impl FormatTrigger { - fn from_proto(value: i32) -> FormatTrigger { + const fn from_proto(value: i32) -> FormatTrigger { match value { 0 => FormatTrigger::Save, 1 => FormatTrigger::Manual, @@ -3477,7 +3477,7 @@ pub(crate) enum LspStoreMode { } impl LspStoreMode { - fn is_local(&self) -> bool { + const fn is_local(&self) -> bool { matches!(self, LspStoreMode::Local(_)) } } @@ -3649,21 +3649,21 @@ impl LspStore { ); } - pub fn as_remote(&self) -> Option<&RemoteLspStore> { + pub const fn as_remote(&self) -> Option<&RemoteLspStore> { match &self.mode { LspStoreMode::Remote(remote_lsp_store) => Some(remote_lsp_store), _ => None, } } - pub fn as_local(&self) -> Option<&LocalLspStore> { + pub const fn as_local(&self) -> Option<&LocalLspStore> { match &self.mode { LspStoreMode::Local(local_lsp_store) => Some(local_lsp_store), _ => None, } } - pub fn as_local_mut(&mut self) -> Option<&mut LocalLspStore> { + pub const fn as_local_mut(&mut self) -> Option<&mut LocalLspStore> { match &mut self.mode { LspStoreMode::Local(local_lsp_store) => Some(local_lsp_store), _ => None, @@ -4262,7 +4262,7 @@ impl LspStore { self.buffer_store.clone() } - pub fn set_active_entry(&mut self, active_entry: Option) { + pub const fn set_active_entry(&mut self, active_entry: Option) { self.active_entry = active_entry; } @@ -12444,7 +12444,7 @@ impl DiagnosticSummary { this } - pub fn is_empty(&self) -> bool { + pub const fn is_empty(&self) -> bool { self.error_count == 0 && self.warning_count == 0 } diff --git a/crates/project/src/lsp_store/log_store.rs b/crates/project/src/lsp_store/log_store.rs index 00098712bf0092a6795de2ed48c7ccf15925c555..a84261b689254c0df48b491fdd4458be0e7fb6b8 100644 --- a/crates/project/src/lsp_store/log_store.rs +++ b/crates/project/src/lsp_store/log_store.rs @@ -172,7 +172,7 @@ impl std::fmt::Debug for LanguageServerKind { } impl LanguageServerKind { - pub fn project(&self) -> Option<&WeakEntity> { + pub const fn project(&self) -> Option<&WeakEntity> { match self { Self::Local { project } => Some(project), Self::Remote { project } => Some(project), @@ -204,7 +204,7 @@ pub enum LogKind { } impl LogKind { - pub fn from_server_log_type(log_type: &LanguageServerLogType) -> Self { + pub const fn from_server_log_type(log_type: &LanguageServerLogType) -> Self { match log_type { LanguageServerLogType::Log(_) => Self::Logs, LanguageServerLogType::Trace { .. } => Self::Trace, diff --git a/crates/project/src/lsp_store/lsp_ext_command.rs b/crates/project/src/lsp_store/lsp_ext_command.rs index c79e3df178290fa614e08a8abd85a527a696b003..af25c03bb2ad14976ec9260be64f27ca2d10858c 100644 --- a/crates/project/src/lsp_store/lsp_ext_command.rs +++ b/crates/project/src/lsp_store/lsp_ext_command.rs @@ -49,7 +49,7 @@ pub struct ExpandedMacro { } impl ExpandedMacro { - pub fn is_empty(&self) -> bool { + pub const fn is_empty(&self) -> bool { self.name.is_empty() && self.expansion.is_empty() } } @@ -180,7 +180,7 @@ pub struct DocsUrls { } impl DocsUrls { - pub fn is_empty(&self) -> bool { + pub const fn is_empty(&self) -> bool { self.web.is_none() && self.local.is_none() } } diff --git a/crates/project/src/manifest_tree.rs b/crates/project/src/manifest_tree.rs index ffa4872ca78e2295e18c515a03e81e4d7b63c07b..fb33b4330b8b1b3591d2ac54ad764b40c9af76d5 100644 --- a/crates/project/src/manifest_tree.rs +++ b/crates/project/src/manifest_tree.rs @@ -206,7 +206,7 @@ pub(crate) struct ManifestQueryDelegate { } impl ManifestQueryDelegate { - pub fn new(worktree: Snapshot) -> Self { + pub const fn new(worktree: Snapshot) -> Self { Self { worktree } } } diff --git a/crates/project/src/manifest_tree/server_tree.rs b/crates/project/src/manifest_tree/server_tree.rs index b6828fdb281d51600096bbcad411f94a91c69e54..afe69bae270218a32df50737e2663e94c46f11b4 100644 --- a/crates/project/src/manifest_tree/server_tree.rs +++ b/crates/project/src/manifest_tree/server_tree.rs @@ -455,7 +455,7 @@ impl ServerTreeRebase { ) } - pub(crate) fn server_tree(&mut self) -> &mut LanguageServerTree { + pub(crate) const fn server_tree(&mut self) -> &mut LanguageServerTree { &mut self.new_tree } } diff --git a/crates/project/src/prettier_store.rs b/crates/project/src/prettier_store.rs index 40deac76404ddb4378fe08cae931d0f0e3583487..a2947ebf6613c790fd7738344f2269551a55455c 100644 --- a/crates/project/src/prettier_store.rs +++ b/crates/project/src/prettier_store.rs @@ -812,7 +812,7 @@ impl Default for DefaultPrettier { } impl DefaultPrettier { - pub fn instance(&self) -> Option<&PrettierInstance> { + pub const fn instance(&self) -> Option<&PrettierInstance> { if let PrettierInstallation::Installed(instance) = &self.prettier { Some(instance) } else { diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 56a2811f07a4c3f37c610df48bb7c6db1904f9f2..a6a77e0cb2e19d2ae7698db34363ac0e7dffa485 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -490,7 +490,7 @@ pub enum CompletionSource { } impl CompletionSource { - pub fn server_id(&self) -> Option { + pub const fn server_id(&self) -> Option { if let CompletionSource::Lsp { server_id, .. } = self { Some(*server_id) } else { @@ -597,7 +597,7 @@ pub struct CompletionDisplayOptions { } impl CompletionDisplayOptions { - pub fn merge(&mut self, other: &CompletionDisplayOptions) { + pub const fn merge(&mut self, other: &CompletionDisplayOptions) { self.dynamic_width = self.dynamic_width && other.dynamic_width; } } @@ -1704,7 +1704,7 @@ impl Project { Ok(project) } - fn new_search_history() -> SearchHistory { + const fn new_search_history() -> SearchHistory { SearchHistory::new( Some(MAX_PROJECT_SEARCH_HISTORY_SIZE), search_history::QueryInsertionBehavior::AlwaysInsert, @@ -1856,7 +1856,7 @@ impl Project { self.buffer_store.read(cx).get(remote_id) } - pub fn languages(&self) -> &Arc { + pub const fn languages(&self) -> &Arc { &self.languages } @@ -1872,7 +1872,7 @@ impl Project { self.user_store.clone() } - pub fn node_runtime(&self) -> Option<&NodeRuntime> { + pub const fn node_runtime(&self) -> Option<&NodeRuntime> { self.node.as_ref() } @@ -1880,7 +1880,7 @@ impl Project { self.buffer_store.read(cx).buffers().collect() } - pub fn environment(&self) -> &Entity { + pub const fn environment(&self) -> &Entity { &self.environment } @@ -1939,7 +1939,7 @@ impl Project { &self.fs } - pub fn remote_id(&self) -> Option { + pub const fn remote_id(&self) -> Option { match self.client_state { ProjectClientState::Local => None, ProjectClientState::Shared { remote_id, .. } @@ -1947,7 +1947,7 @@ impl Project { } } - pub fn supports_terminal(&self, _cx: &App) -> bool { + pub const fn supports_terminal(&self, _cx: &App) -> bool { if self.is_local() { return true; } @@ -1970,7 +1970,7 @@ impl Project { .map(|remote| remote.read(cx).connection_options()) } - pub fn replica_id(&self) -> ReplicaId { + pub const fn replica_id(&self) -> ReplicaId { match self.client_state { ProjectClientState::Remote { replica_id, .. } => replica_id, _ => { @@ -1983,15 +1983,15 @@ impl Project { } } - pub fn task_store(&self) -> &Entity { + pub const fn task_store(&self) -> &Entity { &self.task_store } - pub fn snippets(&self) -> &Entity { + pub const fn snippets(&self) -> &Entity { &self.snippets } - pub fn search_history(&self, kind: SearchInputKind) -> &SearchHistory { + pub const fn search_history(&self, kind: SearchInputKind) -> &SearchHistory { match kind { SearchInputKind::Query => &self.search_history, SearchInputKind::Include => &self.search_included_history, @@ -1999,7 +1999,7 @@ impl Project { } } - pub fn search_history_mut(&mut self, kind: SearchInputKind) -> &mut SearchHistory { + pub const fn search_history_mut(&mut self, kind: SearchInputKind) -> &mut SearchHistory { match kind { SearchInputKind::Query => &mut self.search_history, SearchInputKind::Include => &mut self.search_included_history, @@ -2007,7 +2007,7 @@ impl Project { } } - pub fn collaborators(&self) -> &HashMap { + pub const fn collaborators(&self) -> &HashMap { &self.collaborators } @@ -2511,7 +2511,7 @@ impl Project { .unwrap_or(false) } - pub fn capability(&self) -> Capability { + pub const fn capability(&self) -> Capability { match &self.client_state { ProjectClientState::Remote { capability, .. } => *capability, ProjectClientState::Shared { .. } | ProjectClientState::Local => Capability::ReadWrite, @@ -2522,7 +2522,7 @@ impl Project { self.is_disconnected(cx) || self.capability() == Capability::ReadOnly } - pub fn is_local(&self) -> bool { + pub const fn is_local(&self) -> bool { match &self.client_state { ProjectClientState::Local | ProjectClientState::Shared { .. } => { self.remote_client.is_none() @@ -2531,7 +2531,7 @@ impl Project { } } - pub fn is_via_remote_server(&self) -> bool { + pub const fn is_via_remote_server(&self) -> bool { match &self.client_state { ProjectClientState::Local | ProjectClientState::Shared { .. } => { self.remote_client.is_some() @@ -2540,7 +2540,7 @@ impl Project { } } - pub fn is_via_collab(&self) -> bool { + pub const fn is_via_collab(&self) -> bool { match &self.client_state { ProjectClientState::Local | ProjectClientState::Shared { .. } => false, ProjectClientState::Remote { .. } => true, @@ -4177,7 +4177,7 @@ impl Project { self.worktree_store.read(cx).find_worktree(abs_path, cx) } - pub fn is_shared(&self) -> bool { + pub const fn is_shared(&self) -> bool { match &self.client_state { ProjectClientState::Shared { .. } => true, ProjectClientState::Local => false, @@ -4429,7 +4429,7 @@ impl Project { .diagnostic_summaries(include_ignored, cx) } - pub fn active_entry(&self) -> Option { + pub const fn active_entry(&self) -> Option { self.active_entry } @@ -5213,15 +5213,15 @@ impl Project { .git_init(path, fallback_branch_name, cx) } - pub fn buffer_store(&self) -> &Entity { + pub const fn buffer_store(&self) -> &Entity { &self.buffer_store } - pub fn git_store(&self) -> &Entity { + pub const fn git_store(&self) -> &Entity { &self.git_store } - pub fn agent_server_store(&self) -> &Entity { + pub const fn agent_server_store(&self) -> &Entity { &self.agent_server_store } @@ -5496,18 +5496,18 @@ impl ResolvedPath { } } - pub fn project_path(&self) -> Option<&ProjectPath> { + pub const fn project_path(&self) -> Option<&ProjectPath> { match self { Self::ProjectPath { project_path, .. } => Some(project_path), _ => None, } } - pub fn is_file(&self) -> bool { + pub const fn is_file(&self) -> bool { !self.is_dir() } - pub fn is_dir(&self) -> bool { + pub const fn is_dir(&self) -> bool { match self { Self::ProjectPath { is_dir, .. } => *is_dir, Self::AbsPath { is_dir, .. } => *is_dir, @@ -5594,7 +5594,7 @@ impl Completion { } } -fn proto_to_prompt(level: proto::language_server_prompt_request::Level) -> gpui::PromptLevel { +const fn proto_to_prompt(level: proto::language_server_prompt_request::Level) -> gpui::PromptLevel { match level { proto::language_server_prompt_request::Level::Info(_) => gpui::PromptLevel::Info, proto::language_server_prompt_request::Level::Warning(_) => gpui::PromptLevel::Warning, diff --git a/crates/project/src/project_settings.rs b/crates/project/src/project_settings.rs index 788cd0212a094154e6c4e3b3eb0d379ecadaf11c..81f2b379b8ef776dc364336d5d32ff3ef7c321d1 100644 --- a/crates/project/src/project_settings.rs +++ b/crates/project/src/project_settings.rs @@ -170,14 +170,14 @@ impl ContextServerSettings { } } - pub fn enabled(&self) -> bool { + pub const fn enabled(&self) -> bool { match self { ContextServerSettings::Custom { enabled, .. } => *enabled, ContextServerSettings::Extension { enabled, .. } => *enabled, } } - pub fn set_enabled(&mut self, enabled: bool) { + pub const fn set_enabled(&mut self, enabled: bool) { match self { ContextServerSettings::Custom { enabled: e, .. } => *e = enabled, ContextServerSettings::Extension { enabled: e, .. } => *e = enabled, @@ -196,7 +196,7 @@ pub enum DiagnosticSeverity { } impl DiagnosticSeverity { - pub fn into_lsp(self) -> Option { + pub const fn into_lsp(self) -> Option { match self { DiagnosticSeverity::Off => None, DiagnosticSeverity::Error => Some(lsp::DiagnosticSeverity::ERROR), @@ -247,11 +247,11 @@ impl From for GoToDiagnosticSeverity { } impl GoToDiagnosticSeverity { - pub fn min() -> Self { + pub const fn min() -> Self { Self::Hint } - pub fn max() -> Self { + pub const fn max() -> Self { Self::Error } } @@ -356,7 +356,7 @@ pub struct BlameSettings { } impl GitSettings { - pub fn inline_blame_delay(&self) -> Option { + pub const fn inline_blame_delay(&self) -> Option { if self.inline_blame.delay_ms.as_millis() > 0 { Some(self.inline_blame.delay_ms) } else { @@ -1134,7 +1134,7 @@ impl SettingsObserver { } } -pub fn local_settings_kind_from_proto(kind: proto::LocalSettingsKind) -> LocalSettingsKind { +pub const fn local_settings_kind_from_proto(kind: proto::LocalSettingsKind) -> LocalSettingsKind { match kind { proto::LocalSettingsKind::Settings => LocalSettingsKind::Settings, proto::LocalSettingsKind::Tasks => LocalSettingsKind::Tasks, @@ -1143,7 +1143,7 @@ pub fn local_settings_kind_from_proto(kind: proto::LocalSettingsKind) -> LocalSe } } -pub fn local_settings_kind_to_proto(kind: LocalSettingsKind) -> proto::LocalSettingsKind { +pub const fn local_settings_kind_to_proto(kind: LocalSettingsKind) -> proto::LocalSettingsKind { match kind { LocalSettingsKind::Settings => proto::LocalSettingsKind::Settings, LocalSettingsKind::Tasks => proto::LocalSettingsKind::Tasks, diff --git a/crates/project/src/search.rs b/crates/project/src/search.rs index 9460540729aab4ab75022594fddeeb01df7919e5..56eda0121401a571e45ff9b516bb6b3ca2fdd3ae 100644 --- a/crates/project/src/search.rs +++ b/crates/project/src/search.rs @@ -44,13 +44,13 @@ impl SearchInputs { pub fn as_str(&self) -> &str { self.query.as_ref() } - pub fn files_to_include(&self) -> &PathMatcher { + pub const fn files_to_include(&self) -> &PathMatcher { &self.files_to_include } - pub fn files_to_exclude(&self) -> &PathMatcher { + pub const fn files_to_exclude(&self) -> &PathMatcher { &self.files_to_exclude } - pub fn buffers(&self) -> &Option>> { + pub const fn buffers(&self) -> &Option>> { &self.buffers } } @@ -505,21 +505,21 @@ impl SearchQuery { self.as_inner().as_str() } - pub fn whole_word(&self) -> bool { + pub const fn whole_word(&self) -> bool { match self { Self::Text { whole_word, .. } => *whole_word, Self::Regex { whole_word, .. } => *whole_word, } } - pub fn case_sensitive(&self) -> bool { + pub const fn case_sensitive(&self) -> bool { match self { Self::Text { case_sensitive, .. } => *case_sensitive, Self::Regex { case_sensitive, .. } => *case_sensitive, } } - pub fn include_ignored(&self) -> bool { + pub const fn include_ignored(&self) -> bool { match self { Self::Text { include_ignored, .. @@ -530,23 +530,23 @@ impl SearchQuery { } } - pub fn is_regex(&self) -> bool { + pub const fn is_regex(&self) -> bool { matches!(self, Self::Regex { .. }) } - pub fn files_to_include(&self) -> &PathMatcher { + pub const fn files_to_include(&self) -> &PathMatcher { self.as_inner().files_to_include() } - pub fn files_to_exclude(&self) -> &PathMatcher { + pub const fn files_to_exclude(&self) -> &PathMatcher { self.as_inner().files_to_exclude() } - pub fn buffers(&self) -> Option<&Vec>> { + pub const fn buffers(&self) -> Option<&Vec>> { self.as_inner().buffers.as_ref() } - pub fn is_opened_only(&self) -> bool { + pub const fn is_opened_only(&self) -> bool { self.as_inner().buffers.is_some() } @@ -555,7 +555,7 @@ impl SearchQuery { && self.files_to_include().sources().is_empty()) } - pub fn match_full_paths(&self) -> bool { + pub const fn match_full_paths(&self) -> bool { self.as_inner().match_full_paths } @@ -575,7 +575,7 @@ impl SearchQuery { } } } - pub fn as_inner(&self) -> &SearchInputs { + pub const fn as_inner(&self) -> &SearchInputs { match self { Self::Regex { inner, .. } | Self::Text { inner, .. } => inner, } @@ -585,7 +585,7 @@ impl SearchQuery { /// all matches. /// Returns `None` for text searches, as only regex searches support this /// option. - pub fn one_match_per_line(&self) -> Option { + pub const fn one_match_per_line(&self) -> Option { match self { Self::Regex { one_match_per_line, .. diff --git a/crates/project/src/search_history.rs b/crates/project/src/search_history.rs index 4b2a7a065b12c222dbc3a984d95ce9b83a52ecba..c5ca201a2ef6eb73646d244c5c64b1493a5ac958 100644 --- a/crates/project/src/search_history.rs +++ b/crates/project/src/search_history.rs @@ -23,7 +23,7 @@ pub struct SearchHistoryCursor { impl SearchHistoryCursor { /// Resets the selection to `None`. - pub fn reset(&mut self) { + pub const fn reset(&mut self) { self.selection = None; } } @@ -36,7 +36,7 @@ pub struct SearchHistory { } impl SearchHistory { - pub fn new(max_history_len: Option, insertion_behavior: QueryInsertionBehavior) -> Self { + pub const fn new(max_history_len: Option, insertion_behavior: QueryInsertionBehavior) -> Self { SearchHistory { max_history_len, insertion_behavior, diff --git a/crates/project/src/task_inventory.rs b/crates/project/src/task_inventory.rs index 4f4939491f19ebe6d32b82f780c4a9988a66c1d4..e11cd4e268494eb7bdd453b947188e2606a78b14 100644 --- a/crates/project/src/task_inventory.rs +++ b/crates/project/src/task_inventory.rs @@ -825,7 +825,7 @@ fn task_lru_comparator( }) } -fn task_source_kind_preference(kind: &TaskSourceKind) -> u32 { +const fn task_source_kind_preference(kind: &TaskSourceKind) -> u32 { match kind { TaskSourceKind::Lsp { .. } => 0, TaskSourceKind::Language { .. } => 1, @@ -967,7 +967,7 @@ pub struct BasicContextProvider { } impl BasicContextProvider { - pub fn new(worktree_store: Entity) -> Self { + pub const fn new(worktree_store: Entity) -> Self { Self { worktree_store } } } @@ -1075,7 +1075,7 @@ pub struct ContextProviderWithTasks { } impl ContextProviderWithTasks { - pub fn new(definitions: TaskTemplates) -> Self { + pub const fn new(definitions: TaskTemplates) -> Self { Self { templates: definitions, } diff --git a/crates/project/src/task_store.rs b/crates/project/src/task_store.rs index 0de5e239798c6a95078d79c2a25775c914a13611..de87c78debf72daff1eccc8900a8ba61e3db5ad2 100644 --- a/crates/project/src/task_store.rs +++ b/crates/project/src/task_store.rs @@ -230,7 +230,7 @@ impl TaskStore { } } - pub fn task_inventory(&self) -> Option<&Entity> { + pub const fn task_inventory(&self) -> Option<&Entity> { match self { TaskStore::Functional(state) => Some(&state.task_inventory), TaskStore::Noop => None, diff --git a/crates/project/src/terminals.rs b/crates/project/src/terminals.rs index c9594a4b55d44608fc80c2e64d8e39ebbeacee13..139d589ba21e1a3b0af3867e98ef28a2ed32f956 100644 --- a/crates/project/src/terminals.rs +++ b/crates/project/src/terminals.rs @@ -518,7 +518,7 @@ impl Project { }) } - pub fn local_terminal_handles(&self) -> &Vec> { + pub const fn local_terminal_handles(&self) -> &Vec> { &self.terminals.local_handles } } diff --git a/crates/project/src/toolchain_store.rs b/crates/project/src/toolchain_store.rs index 64a167206864a4bffe488fbd70da01c6c3a993b0..dc60aa121526196b5c2f535bf9315c656fa57b26 100644 --- a/crates/project/src/toolchain_store.rs +++ b/crates/project/src/toolchain_store.rs @@ -383,7 +383,7 @@ impl ToolchainStore { ToolchainStoreInner::Remote(remote) => Arc::new(RemoteStore(remote.downgrade())), } } - pub fn as_local_store(&self) -> Option<&Entity> { + pub const fn as_local_store(&self) -> Option<&Entity> { match &self.mode { ToolchainStoreInner::Local(local) => Some(local), ToolchainStoreInner::Remote(_) => None, diff --git a/crates/project/src/worktree_store.rs b/crates/project/src/worktree_store.rs index 670b405ed33757117ec62bfbbb4c947f79e5026a..d25e1b08f0d565f43bf75766cb8f8d7154e92b28 100644 --- a/crates/project/src/worktree_store.rs +++ b/crates/project/src/worktree_store.rs @@ -183,7 +183,7 @@ impl WorktreeStore { Some(worktree.read(cx).absolutize(&project_path.path)) } - pub fn path_style(&self) -> PathStyle { + pub const fn path_style(&self) -> PathStyle { match &self.state { WorktreeStoreState::Local { .. } => PathStyle::local(), WorktreeStoreState::Remote { path_style, .. } => *path_style, @@ -686,7 +686,7 @@ impl WorktreeStore { self.send_project_updates(cx); } - pub fn set_worktrees_reordered(&mut self, worktrees_reordered: bool) { + pub const fn set_worktrees_reordered(&mut self, worktrees_reordered: bool) { self.worktrees_reordered = worktrees_reordered; } diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs index 0160d4d151d5bd102e72e195127fd6a16b63ce15..3983af78f39d8e52e51d377f2a4df751f9e587f5 100644 --- a/crates/project_panel/src/project_panel.rs +++ b/crates/project_panel/src/project_panel.rs @@ -180,7 +180,7 @@ struct EditState { } impl EditState { - fn is_new_entry(&self) -> bool { + const fn is_new_entry(&self) -> bool { self.leaf_entry_id.is_none() } } @@ -332,7 +332,7 @@ struct FoldedAncestors { } impl FoldedAncestors { - fn max_ancestor_depth(&self) -> usize { + const fn max_ancestor_depth(&self) -> usize { self.ancestors.len() } @@ -344,7 +344,7 @@ impl FoldedAncestors { self.ancestors.get(self.current_ancestor_depth).copied() } - fn active_index(&self) -> usize { + const fn active_index(&self) -> usize { self.max_ancestor_depth() .saturating_sub(1) .saturating_sub(self.current_ancestor_depth) @@ -3612,7 +3612,7 @@ impl ProjectPanel { } } - fn is_copy_modifier_set(modifiers: &Modifiers) -> bool { + const fn is_copy_modifier_set(modifiers: &Modifiers) -> bool { cfg!(target_os = "macos") && modifiers.alt || cfg!(not(target_os = "macos")) && modifiers.control } @@ -5303,7 +5303,7 @@ impl StickyCandidate for StickyProjectPanelCandidate { } } -fn item_width_estimate(depth: usize, item_text_chars: usize, is_symlink: bool) -> usize { +const fn item_width_estimate(depth: usize, item_text_chars: usize, is_symlink: bool) -> usize { const ICON_SIZE_FACTOR: usize = 2; let mut item_width = depth * ICON_SIZE_FACTOR + item_text_chars; if is_symlink { @@ -6036,11 +6036,11 @@ impl Focusable for ProjectPanel { } impl ClipboardEntry { - fn is_cut(&self) -> bool { + const fn is_cut(&self) -> bool { matches!(self, Self::Cut { .. }) } - fn items(&self) -> &BTreeSet { + const fn items(&self) -> &BTreeSet { match self { ClipboardEntry::Copied(entries) | ClipboardEntry::Cut(entries) => entries, } diff --git a/crates/project_panel/src/utils.rs b/crates/project_panel/src/utils.rs index 486def9b84403727c30d82ebad61d4156d5de96a..faf8b234ad47a23cbcf0d2cf3d6b09a5dcf7a7e0 100644 --- a/crates/project_panel/src/utils.rs +++ b/crates/project_panel/src/utils.rs @@ -4,7 +4,7 @@ pub(crate) struct ReversibleIterable { } impl ReversibleIterable { - pub(crate) fn new(it: T, reverse: bool) -> Self { + pub(crate) const fn new(it: T, reverse: bool) -> Self { Self { it, reverse } } } diff --git a/crates/prompt_store/src/prompt_store.rs b/crates/prompt_store/src/prompt_store.rs index fb087ce34d6d67fe4ea11a33f554307ed558c18a..219ed8f998cbd799c0a912d3e9612dc20fa0038c 100644 --- a/crates/prompt_store/src/prompt_store.rs +++ b/crates/prompt_store/src/prompt_store.rs @@ -63,7 +63,7 @@ impl PromptId { UserPromptId::new().into() } - pub fn is_built_in(&self) -> bool { + pub const fn is_built_in(&self) -> bool { !matches!(self, PromptId::User { .. }) } } diff --git a/crates/proto/src/proto.rs b/crates/proto/src/proto.rs index 3710d77262f872d6a422827c9cf1829d21d8f221..1a553a479aa84adafb7430ce0d328598a2c17ba0 100644 --- a/crates/proto/src/proto.rs +++ b/crates/proto/src/proto.rs @@ -832,7 +832,7 @@ pub fn split_repository_update( } impl LspQuery { - pub fn query_name_and_write_permissions(&self) -> (&str, bool) { + pub const fn query_name_and_write_permissions(&self) -> (&str, bool) { match self.request { Some(lsp_query::Request::GetHover(_)) => ("GetHover", false), Some(lsp_query::Request::GetCodeActions(_)) => ("GetCodeActions", true), diff --git a/crates/proto/src/typed_envelope.rs b/crates/proto/src/typed_envelope.rs index a7a8a1c7a2314ad41eaa232cf2256a4bcb398d8d..8afa9ee41bdf09b3f6afa0986cb32d326d0a0986 100644 --- a/crates/proto/src/typed_envelope.rs +++ b/crates/proto/src/typed_envelope.rs @@ -127,13 +127,13 @@ impl AnyTypedEnvelope for TypedEnvelope { } impl PeerId { - pub fn from_u64(peer_id: u64) -> Self { + pub const fn from_u64(peer_id: u64) -> Self { let owner_id = (peer_id >> 32) as u32; let id = peer_id as u32; Self { owner_id, id } } - pub fn as_u64(self) -> u64 { + pub const fn as_u64(self) -> u64 { ((self.owner_id as u64) << 32) | (self.id as u64) } } @@ -200,7 +200,7 @@ impl TypedEnvelope { } impl TypedEnvelope { - pub fn receipt(&self) -> Receipt { + pub const fn receipt(&self) -> Receipt { Receipt { sender_id: self.sender_id, message_id: self.message_id, diff --git a/crates/recent_projects/src/remote_servers.rs b/crates/recent_projects/src/remote_servers.rs index 2596a3d41604ac3710b9d5302718c18b2f948b4f..b7cd9554464c4daa882a7580a05d7f3881c71777 100644 --- a/crates/recent_projects/src/remote_servers.rs +++ b/crates/recent_projects/src/remote_servers.rs @@ -418,7 +418,7 @@ enum RemoteEntry { } impl RemoteEntry { - fn is_from_zed(&self) -> bool { + const fn is_from_zed(&self) -> bool { matches!(self, Self::Project { .. }) } @@ -538,7 +538,7 @@ enum ViewServerOptionsState { } impl ViewServerOptionsState { - fn entries(&self) -> &[NavigableEntry] { + const fn entries(&self) -> &[NavigableEntry] { match self { Self::Ssh { entries, .. } => entries, Self::Wsl { entries, .. } => entries, diff --git a/crates/release_channel/src/lib.rs b/crates/release_channel/src/lib.rs index ba8d2e767503b00ed7f39921780a262b3e6c3624..bbbf02a524a8af8db89b893389a2f8d8df7418c5 100644 --- a/crates/release_channel/src/lib.rs +++ b/crates/release_channel/src/lib.rs @@ -44,7 +44,7 @@ impl Global for GlobalAppCommitSha {} impl AppCommitSha { /// Creates a new [`AppCommitSha`]. - pub fn new(sha: String) -> Self { + pub const fn new(sha: String) -> Self { AppCommitSha(sha) } @@ -139,12 +139,12 @@ impl ReleaseChannel { } /// Returns whether we want to poll for updates for this [`ReleaseChannel`] - pub fn poll_for_updates(&self) -> bool { + pub const fn poll_for_updates(&self) -> bool { !matches!(self, ReleaseChannel::Dev) } /// Returns the display name for this [`ReleaseChannel`]. - pub fn display_name(&self) -> &'static str { + pub const fn display_name(&self) -> &'static str { match self { ReleaseChannel::Dev => "Zed Dev", ReleaseChannel::Nightly => "Zed Nightly", @@ -154,7 +154,7 @@ impl ReleaseChannel { } /// Returns the programmatic name for this [`ReleaseChannel`]. - pub fn dev_name(&self) -> &'static str { + pub const fn dev_name(&self) -> &'static str { match self { ReleaseChannel::Dev => "dev", ReleaseChannel::Nightly => "nightly", @@ -166,7 +166,7 @@ impl ReleaseChannel { /// Returns the application ID that's used by Wayland as application ID /// and WM_CLASS on X11. /// This also has to match the bundle identifier for Zed on macOS. - pub fn app_id(&self) -> &'static str { + pub const fn app_id(&self) -> &'static str { match self { ReleaseChannel::Dev => "dev.zed.Zed-Dev", ReleaseChannel::Nightly => "dev.zed.Zed-Nightly", @@ -176,7 +176,7 @@ impl ReleaseChannel { } /// Returns the query parameter for this [`ReleaseChannel`]. - pub fn release_query_param(&self) -> Option<&'static str> { + pub const fn release_query_param(&self) -> Option<&'static str> { match self { Self::Dev => None, Self::Nightly => Some("nightly=1"), diff --git a/crates/remote/src/json_log.rs b/crates/remote/src/json_log.rs index 96cebbb3551481ca956405019c39c0b10c8b09b7..21d9655e61a1a3b13b68f81479af76aa28ef66fe 100644 --- a/crates/remote/src/json_log.rs +++ b/crates/remote/src/json_log.rs @@ -37,7 +37,7 @@ impl<'a> LogRecord<'a> { } } -fn serialize_level(level: Level) -> usize { +const fn serialize_level(level: Level) -> usize { match level { Level::Error => 1, Level::Warn => 2, @@ -47,7 +47,7 @@ fn serialize_level(level: Level) -> usize { } } -fn deserialize_level(level: usize) -> Option { +const fn deserialize_level(level: usize) -> Option { match level { 1 => Some(Level::Error), 2 => Some(Level::Warn), diff --git a/crates/remote/src/proxy.rs b/crates/remote/src/proxy.rs index d715d5ecf6286720f1c9bc040aee38a5fcf7addc..74a333d8de99a1808826a2a27195d39d1bd1f8f4 100644 --- a/crates/remote/src/proxy.rs +++ b/crates/remote/src/proxy.rs @@ -7,7 +7,7 @@ pub enum ProxyLaunchError { } impl ProxyLaunchError { - pub fn to_exit_code(&self) -> i32 { + pub const fn to_exit_code(&self) -> i32 { match self { // We're using 90 as the exit code, because 0-78 are often taken // by shells and other conventions and >128 also has certain meanings @@ -16,7 +16,7 @@ impl ProxyLaunchError { } } - pub fn from_exit_code(exit_code: i32) -> Option { + pub const fn from_exit_code(exit_code: i32) -> Option { match exit_code { 90 => Some(Self::ServerNotRunning), _ => None, diff --git a/crates/remote/src/remote_client.rs b/crates/remote/src/remote_client.rs index e9eafa25b0467f29d1dd12816aa17d65b94bf1d4..1223c92db154396744dfc53711e3e1b3d35292a6 100644 --- a/crates/remote/src/remote_client.rs +++ b/crates/remote/src/remote_client.rs @@ -147,7 +147,7 @@ impl State { } } - fn can_reconnect(&self) -> bool { + const fn can_reconnect(&self) -> bool { match self { Self::Connected { .. } | Self::HeartbeatMissed { .. } @@ -159,19 +159,19 @@ impl State { } } - fn is_reconnect_failed(&self) -> bool { + const fn is_reconnect_failed(&self) -> bool { matches!(self, Self::ReconnectFailed { .. }) } - fn is_reconnect_exhausted(&self) -> bool { + const fn is_reconnect_exhausted(&self) -> bool { matches!(self, Self::ReconnectExhausted { .. }) } - fn is_server_not_running(&self) -> bool { + const fn is_server_not_running(&self) -> bool { matches!(self, Self::ServerNotRunning) } - fn is_reconnecting(&self) -> bool { + const fn is_reconnecting(&self) -> bool { matches!(self, Self::Reconnecting { .. }) } @@ -880,7 +880,7 @@ impl RemoteClient { self.connection_state() == ConnectionState::Disconnected } - pub fn path_style(&self) -> PathStyle { + pub const fn path_style(&self) -> PathStyle { self.path_style } diff --git a/crates/remote_server/src/headless_project.rs b/crates/remote_server/src/headless_project.rs index 1c42f1995daa03fbcb90323f1a136659baa995f9..8f8d2aa7319cc7137c2b17943867cf2c037079e7 100644 --- a/crates/remote_server/src/headless_project.rs +++ b/crates/remote_server/src/headless_project.rs @@ -789,7 +789,7 @@ impl HeadlessProject { } } -fn prompt_to_proto( +const fn prompt_to_proto( prompt: &project::LanguageServerPromptRequest, ) -> proto::language_server_prompt_request::Level { match prompt.level { diff --git a/crates/repl/src/components/kernel_list_item.rs b/crates/repl/src/components/kernel_list_item.rs index 467407fbd2d3c6413efedb5b7576e5c982c8a0d6..ea0e6110c15602ae0f71bd722d0124fb2dd4ac28 100644 --- a/crates/repl/src/components/kernel_list_item.rs +++ b/crates/repl/src/components/kernel_list_item.rs @@ -12,7 +12,7 @@ pub struct KernelListItem { } impl KernelListItem { - pub fn new(kernel_specification: KernelSpecification) -> Self { + pub const fn new(kernel_specification: KernelSpecification) -> Self { Self { kernel_specification, status_color: Color::Disabled, @@ -21,7 +21,7 @@ impl KernelListItem { } } - pub fn status_color(mut self, color: Color) -> Self { + pub const fn status_color(mut self, color: Color) -> Self { self.status_color = color; self } diff --git a/crates/repl/src/kernels/mod.rs b/crates/repl/src/kernels/mod.rs index a99c80230a4ec468ac6505346b4c0d017e7576d7..ffdef8cecc6c23b9e8369410e8fb9406856238f4 100644 --- a/crates/repl/src/kernels/mod.rs +++ b/crates/repl/src/kernels/mod.rs @@ -178,7 +178,7 @@ pub enum KernelStatus { } impl KernelStatus { - pub fn is_connected(&self) -> bool { + pub const fn is_connected(&self) -> bool { matches!(self, KernelStatus::Idle | KernelStatus::Busy) } } @@ -240,7 +240,7 @@ impl Kernel { } } - pub fn is_shutting_down(&self) -> bool { + pub const fn is_shutting_down(&self) -> bool { match self { Kernel::Restarting | Kernel::ShuttingDown => true, Kernel::RunningKernel(_) diff --git a/crates/repl/src/notebook/cell.rs b/crates/repl/src/notebook/cell.rs index 87b8e1d55ae85e09c0398848a989b7764e0d3b04..4d5966fff3dac9e6283f3e537d2c08dc414e6f97 100644 --- a/crates/repl/src/notebook/cell.rs +++ b/crates/repl/src/notebook/cell.rs @@ -36,7 +36,7 @@ pub enum CellControlType { } impl CellControlType { - fn icon_name(&self) -> IconName { + const fn icon_name(&self) -> IconName { match self { CellControlType::RunCell => IconName::PlayFilled, CellControlType::RerunCell => IconName::ArrowCircle, @@ -444,7 +444,7 @@ impl CodeCell { pub fn is_dirty(&self, cx: &App) -> bool { self.editor.read(cx).buffer().read(cx).is_dirty(cx) } - pub fn has_outputs(&self) -> bool { + pub const fn has_outputs(&self) -> bool { !self.outputs.is_empty() } @@ -452,7 +452,7 @@ impl CodeCell { self.outputs.clear(); } - fn output_control(&self) -> Option { + const fn output_control(&self) -> Option { if self.has_outputs() { Some(CellControlType::ClearCell) } else { diff --git a/crates/repl/src/notebook/notebook_ui.rs b/crates/repl/src/notebook/notebook_ui.rs index 6f92fe511528097d363063bf837ad3b7efa83318..bc3317d0118b65fb08791f39f0bf29c4e2b6d118 100644 --- a/crates/repl/src/notebook/notebook_ui.rs +++ b/crates/repl/src/notebook/notebook_ui.rs @@ -189,7 +189,7 @@ impl NotebookEditor { self.cell_map.len() } - fn selected_index(&self) -> usize { + const fn selected_index(&self) -> usize { self.selected_cell_index } diff --git a/crates/repl/src/outputs.rs b/crates/repl/src/outputs.rs index 2cd6494d66be1b615e10e537c139e4b2e22af863..f7de6a85cd8c663bdba30fbab99fbdb37c356833 100644 --- a/crates/repl/src/outputs.rs +++ b/crates/repl/src/outputs.rs @@ -58,7 +58,7 @@ use user_error::ErrorView; use workspace::Workspace; /// When deciding what to render from a collection of mediatypes, we need to rank them in order of importance -fn rank_mime_type(mimetype: &MimeType) -> usize { +const fn rank_mime_type(mimetype: &MimeType) -> usize { match mimetype { MimeType::DataTable(_) => 6, MimeType::Png(_) => 4, diff --git a/crates/repl/src/repl_store.rs b/crates/repl/src/repl_store.rs index a5dc7b6c7b642b3c8afb46924fcb6e54620cb19b..6f64c4f4028b62603556e491d5c72c14bcedb571 100644 --- a/crates/repl/src/repl_store.rs +++ b/crates/repl/src/repl_store.rs @@ -67,7 +67,7 @@ impl ReplStore { &self.fs } - pub fn is_enabled(&self) -> bool { + pub const fn is_enabled(&self) -> bool { self.enabled } diff --git a/crates/rope/src/chunk.rs b/crates/rope/src/chunk.rs index 91e61a517144f5b2408902173a8c34ccb865e9d5..8b003f607b292579a80664acfcce8b0e31179bca 100644 --- a/crates/rope/src/chunk.rs +++ b/crates/rope/src/chunk.rs @@ -79,7 +79,7 @@ impl Chunk { } #[inline(always)] - pub fn chars(&self) -> u128 { + pub const fn chars(&self) -> u128 { self.chars } } @@ -107,17 +107,17 @@ impl Into for ChunkSlice<'_> { impl<'a> ChunkSlice<'a> { #[inline(always)] - pub fn is_empty(&self) -> bool { + pub const fn is_empty(&self) -> bool { self.text.is_empty() } #[inline(always)] - pub fn is_char_boundary(self, offset: usize) -> bool { + pub const fn is_char_boundary(self, offset: usize) -> bool { self.text.is_char_boundary(offset) } #[inline(always)] - pub fn split_at(self, mid: usize) -> (ChunkSlice<'a>, ChunkSlice<'a>) { + pub const fn split_at(self, mid: usize) -> (ChunkSlice<'a>, ChunkSlice<'a>) { if mid == MAX_BASE { let left = self; let right = ChunkSlice { @@ -206,19 +206,19 @@ impl<'a> ChunkSlice<'a> { /// Get length in bytes #[inline(always)] - pub fn len(&self) -> usize { + pub const fn len(&self) -> usize { self.text.len() } /// Get length in UTF-16 code units #[inline(always)] - pub fn len_utf16(&self) -> OffsetUtf16 { + pub const fn len_utf16(&self) -> OffsetUtf16 { OffsetUtf16(self.chars_utf16.count_ones() as usize) } /// Get point representing number of lines and length of last line #[inline(always)] - pub fn lines(&self) -> Point { + pub const fn lines(&self) -> Point { let row = self.newlines.count_ones(); let column = self.newlines.leading_zeros() - (u128::BITS - self.text.len() as u32); Point::new(row, column) @@ -226,7 +226,7 @@ impl<'a> ChunkSlice<'a> { /// Get number of chars in first line #[inline(always)] - pub fn first_line_chars(&self) -> u32 { + pub const fn first_line_chars(&self) -> u32 { if self.newlines == 0 { self.chars.count_ones() } else { @@ -237,7 +237,7 @@ impl<'a> ChunkSlice<'a> { /// Get number of chars in last line #[inline(always)] - pub fn last_line_chars(&self) -> u32 { + pub const fn last_line_chars(&self) -> u32 { if self.newlines == 0 { self.chars.count_ones() } else { @@ -248,7 +248,7 @@ impl<'a> ChunkSlice<'a> { /// Get number of UTF-16 code units in last line #[inline(always)] - pub fn last_line_len_utf16(&self) -> u32 { + pub const fn last_line_len_utf16(&self) -> u32 { if self.newlines == 0 { self.chars_utf16.count_ones() } else { @@ -294,7 +294,7 @@ impl<'a> ChunkSlice<'a> { } #[inline(always)] - pub fn offset_to_point(&self, offset: usize) -> Point { + pub const fn offset_to_point(&self, offset: usize) -> Point { let mask = if offset == MAX_BASE { u128::MAX } else { @@ -331,7 +331,7 @@ impl<'a> ChunkSlice<'a> { } #[inline(always)] - pub fn offset_to_offset_utf16(&self, offset: usize) -> OffsetUtf16 { + pub const fn offset_to_offset_utf16(&self, offset: usize) -> OffsetUtf16 { let mask = if offset == MAX_BASE { u128::MAX } else { @@ -359,7 +359,7 @@ impl<'a> ChunkSlice<'a> { } #[inline(always)] - pub fn offset_to_point_utf16(&self, offset: usize) -> PointUtf16 { + pub const fn offset_to_point_utf16(&self, offset: usize) -> PointUtf16 { let mask = if offset == MAX_BASE { u128::MAX } else { @@ -536,7 +536,7 @@ impl<'a> ChunkSlice<'a> { } #[inline(always)] - pub fn tabs(&self) -> Tabs { + pub const fn tabs(&self) -> Tabs { Tabs { tabs: self.tabs, chars: self.chars, @@ -581,7 +581,7 @@ impl Iterator for Tabs { /// Finds the n-th bit that is set to 1. #[inline(always)] -fn nth_set_bit(v: u128, n: usize) -> usize { +const fn nth_set_bit(v: u128, n: usize) -> usize { let low = v as u64; let high = (v >> 64) as u64; @@ -594,7 +594,7 @@ fn nth_set_bit(v: u128, n: usize) -> usize { } #[inline(always)] -fn nth_set_bit_u64(v: u64, mut n: u64) -> u64 { +const fn nth_set_bit_u64(v: u64, mut n: u64) -> u64 { let v = v.reverse_bits(); let mut s: u64 = 64; diff --git a/crates/rope/src/point.rs b/crates/rope/src/point.rs index a5a0a442c3209a299fc299526418d792b7f7fd12..cc27d4202bd6c45770a734456462610a135b0466 100644 --- a/crates/rope/src/point.rs +++ b/crates/rope/src/point.rs @@ -16,11 +16,11 @@ impl Point { column: u32::MAX, }; - pub fn new(row: u32, column: u32) -> Self { + pub const fn new(row: u32, column: u32) -> Self { Point { row, column } } - pub fn row_range(range: Range) -> Range { + pub const fn row_range(range: Range) -> Range { Point { row: range.start, column: 0, @@ -30,7 +30,7 @@ impl Point { } } - pub fn zero() -> Self { + pub const fn zero() -> Self { Point::new(0, 0) } @@ -43,7 +43,7 @@ impl Point { point } - pub fn is_zero(&self) -> bool { + pub const fn is_zero(&self) -> bool { self.row == 0 && self.column == 0 } diff --git a/crates/rope/src/point_utf16.rs b/crates/rope/src/point_utf16.rs index 096c2defa405c4d7b071b3f046a66e46be64bc50..36325ebbebd22d82e93af7c816dbd84ea730c3b7 100644 --- a/crates/rope/src/point_utf16.rs +++ b/crates/rope/src/point_utf16.rs @@ -15,15 +15,15 @@ impl PointUtf16 { column: u32::MAX, }; - pub fn new(row: u32, column: u32) -> Self { + pub const fn new(row: u32, column: u32) -> Self { PointUtf16 { row, column } } - pub fn zero() -> Self { + pub const fn zero() -> Self { PointUtf16::new(0, 0) } - pub fn is_zero(&self) -> bool { + pub const fn is_zero(&self) -> bool { self.row == 0 && self.column == 0 } diff --git a/crates/rope/src/rope.rs b/crates/rope/src/rope.rs index b0b34c95120acddb26081b9265346c80a5afc99c..5113e6aa5f07f419895715ad6dc8797a2c5b6647 100644 --- a/crates/rope/src/rope.rs +++ b/crates/rope/src/rope.rs @@ -648,7 +648,7 @@ impl<'a> Cursor<'a> { self.slice(self.rope.chunks.extent(())) } - pub fn offset(&self) -> usize { + pub const fn offset(&self) -> usize { self.offset } } @@ -694,7 +694,7 @@ impl<'a> Chunks<'a> { } } - fn offset_is_valid(&self) -> bool { + const fn offset_is_valid(&self) -> bool { if self.reversed { if self.offset <= self.range.start || self.offset > self.range.end { return false; @@ -706,7 +706,7 @@ impl<'a> Chunks<'a> { true } - pub fn offset(&self) -> usize { + pub const fn offset(&self) -> usize { self.offset } @@ -914,7 +914,7 @@ impl<'a> Chunks<'a> { }) } - pub fn lines(self) -> Lines<'a> { + pub const fn lines(self) -> Lines<'a> { let reversed = self.reversed; Lines { chunks: self, @@ -1147,7 +1147,7 @@ impl<'a> Lines<'a> { self.done = false; } - pub fn offset(&self) -> usize { + pub const fn offset(&self) -> usize { self.chunks.offset() } } @@ -1204,14 +1204,14 @@ pub struct TextSummary { } impl TextSummary { - pub fn lines_utf16(&self) -> PointUtf16 { + pub const fn lines_utf16(&self) -> PointUtf16 { PointUtf16 { row: self.lines.row, column: self.last_line_len_utf16, } } - pub fn newline() -> Self { + pub const fn newline() -> Self { Self { len: 1, chars: 1, diff --git a/crates/rpc/src/message_stream.rs b/crates/rpc/src/message_stream.rs index 023e916df3113e73adafdc0d38948121ad2e9cec..28d458dcc74ac5acbd693333a67b8cf991fd3a7a 100644 --- a/crates/rpc/src/message_stream.rs +++ b/crates/rpc/src/message_stream.rs @@ -27,7 +27,7 @@ pub enum Message { } impl MessageStream { - pub fn new(stream: S) -> Self { + pub const fn new(stream: S) -> Self { Self { stream, encoding_buffer: Vec::new(), diff --git a/crates/rpc/src/notification.rs b/crates/rpc/src/notification.rs index 50364c738798d21e8f66e37086bcaf309bdedfb0..7878af0c1e0355e56ceab8d6569f482515341fa8 100644 --- a/crates/rpc/src/notification.rs +++ b/crates/rpc/src/notification.rs @@ -65,7 +65,7 @@ impl Notification { serde_json::from_value(value).ok() } - pub fn all_variant_names() -> &'static [&'static str] { + pub const fn all_variant_names() -> &'static [&'static str] { Self::VARIANTS } } diff --git a/crates/scheduler/src/executor.rs b/crates/scheduler/src/executor.rs index a5a0126860f4e685f5f442a201920015bda2fd37..b379fc8f4f7895e591000b40aa2bdb6ff0db5716 100644 --- a/crates/scheduler/src/executor.rs +++ b/crates/scheduler/src/executor.rs @@ -126,7 +126,7 @@ enum TaskState { impl Task { /// Creates a new task that will resolve with the value - pub fn ready(val: T) -> Self { + pub const fn ready(val: T) -> Self { Task(TaskState::Ready(Some(val))) } diff --git a/crates/scheduler/src/scheduler.rs b/crates/scheduler/src/scheduler.rs index 8d485e009cc68d0a2da784ee2f91e9fbf4f2b3b9..abb513369cadd41b62c3aece369c8384a5a15fa6 100644 --- a/crates/scheduler/src/scheduler.rs +++ b/crates/scheduler/src/scheduler.rs @@ -38,7 +38,7 @@ pub trait Scheduler: Send + Sync { pub struct SessionId(u16); impl SessionId { - pub fn new(id: u16) -> Self { + pub const fn new(id: u16) -> Self { SessionId(id) } } @@ -46,7 +46,7 @@ impl SessionId { pub struct Timer(oneshot::Receiver<()>); impl Timer { - pub fn new(rx: oneshot::Receiver<()>) -> Self { + pub const fn new(rx: oneshot::Receiver<()>) -> Self { Timer(rx) } } diff --git a/crates/search/src/buffer_search.rs b/crates/search/src/buffer_search.rs index 923e30e0b6878ad32fd65d210101a5a62fd38687..bbffc158b648de04ec6bd2ce3e5151b6abaaff65 100644 --- a/crates/search/src/buffer_search.rs +++ b/crates/search/src/buffer_search.rs @@ -74,7 +74,7 @@ actions!( ); impl Deploy { - pub fn find() -> Self { + pub const fn find() -> Self { Self { focus: true, replace_enabled: false, @@ -82,7 +82,7 @@ impl Deploy { } } - pub fn replace() -> Self { + pub const fn replace() -> Self { Self { focus: true, replace_enabled: true, @@ -127,7 +127,7 @@ pub struct BufferSearchBar { } impl BufferSearchBar { - pub fn query_editor_focused(&self) -> bool { + pub const fn query_editor_focused(&self) -> bool { self.query_editor_focused } } @@ -683,7 +683,7 @@ impl BufferSearchBar { } } - pub fn is_dismissed(&self) -> bool { + pub const fn is_dismissed(&self) -> bool { self.dismissed } @@ -915,7 +915,7 @@ impl BufferSearchBar { cx.notify(); } - pub fn has_search_option(&mut self, search_option: SearchOptions) -> bool { + pub const fn has_search_option(&mut self, search_option: SearchOptions) -> bool { self.search_options.contains(search_option) } @@ -1169,7 +1169,7 @@ impl BufferSearchBar { } } - pub fn has_active_match(&self) -> bool { + pub const fn has_active_match(&self) -> bool { self.active_match_index.is_some() } @@ -1303,7 +1303,7 @@ impl BufferSearchBar { done_rx } - fn reverse_direction_if_backwards(&self, direction: Direction) -> Direction { + const fn reverse_direction_if_backwards(&self, direction: Direction) -> Direction { if self.search_options.contains(SearchOptions::BACKWARDS) { direction.opposite() } else { diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rs index c292d05df75ad329c608d456aaf07a9d1d3af044..ab554eeea5e7a2c8d4a0b00f0d322791a412c0d6 100644 --- a/crates/search/src/project_search.rs +++ b/crates/search/src/project_search.rs @@ -269,14 +269,14 @@ impl ProjectSearch { search_excluded_history_cursor: self.search_excluded_history_cursor.clone(), }) } - fn cursor(&self, kind: SearchInputKind) -> &SearchHistoryCursor { + const fn cursor(&self, kind: SearchInputKind) -> &SearchHistoryCursor { match kind { SearchInputKind::Query => &self.search_history_cursor, SearchInputKind::Include => &self.search_included_history_cursor, SearchInputKind::Exclude => &self.search_excluded_history_cursor, } } - fn cursor_mut(&mut self, kind: SearchInputKind) -> &mut SearchHistoryCursor { + const fn cursor_mut(&mut self, kind: SearchInputKind) -> &mut SearchHistoryCursor { match kind { SearchInputKind::Query => &mut self.search_history_cursor, SearchInputKind::Include => &mut self.search_included_history_cursor, @@ -654,7 +654,7 @@ impl ProjectSearchView { }); } - fn current_settings(&self) -> ProjectSearchSettings { + const fn current_settings(&self) -> ProjectSearchSettings { ProjectSearchSettings { search_options: self.search_options, filters_enabled: self.filters_enabled, @@ -672,7 +672,7 @@ impl ProjectSearchView { self.adjust_query_regex_language(cx); } - fn toggle_opened_only(&mut self, _window: &mut Window, _cx: &mut Context) { + const fn toggle_opened_only(&mut self, _window: &mut Window, _cx: &mut Context) { self.included_opened_only = !self.included_opened_only; } @@ -1440,7 +1440,7 @@ impl ProjectSearchView { } } - pub fn has_matches(&self) -> bool { + pub const fn has_matches(&self) -> bool { self.active_match_index.is_some() } @@ -1605,7 +1605,7 @@ impl Default for ProjectSearchBar { } impl ProjectSearchBar { - pub fn new() -> Self { + pub const fn new() -> Self { Self { active_project_search: None, subscription: None, diff --git a/crates/search/src/search.rs b/crates/search/src/search.rs index 147ffcbbfb1956a4e258b7242729d366f4c2d1be..a581a505b3d0c0f83faef16fd7d7418b4aebfdc6 100644 --- a/crates/search/src/search.rs +++ b/crates/search/src/search.rs @@ -91,11 +91,11 @@ pub(crate) enum SearchSource<'a, 'b> { } impl SearchOption { - pub fn as_options(&self) -> SearchOptions { + pub const fn as_options(&self) -> SearchOptions { SearchOptions::from_bits(1 << *self as u8).unwrap() } - pub fn label(&self) -> &'static str { + pub const fn label(&self) -> &'static str { match self { SearchOption::WholeWord => "Match Whole Words", SearchOption::CaseSensitive => "Match Case Sensitivity", @@ -165,7 +165,7 @@ impl SearchOption { } impl SearchOptions { - pub fn none() -> SearchOptions { + pub const fn none() -> SearchOptions { SearchOptions::NONE } diff --git a/crates/search/src/search_status_button.rs b/crates/search/src/search_status_button.rs index 544a15155c0be789fe239f039e9d0b94b99dabdd..8a23ba17dba5ed237b314777e94c1e4cc3368a5e 100644 --- a/crates/search/src/search_status_button.rs +++ b/crates/search/src/search_status_button.rs @@ -8,7 +8,7 @@ pub const SEARCH_ICON: IconName = IconName::MagnifyingGlass; pub struct SearchButton; impl SearchButton { - pub fn new() -> Self { + pub const fn new() -> Self { Self {} } } diff --git a/crates/semantic_version/src/semantic_version.rs b/crates/semantic_version/src/semantic_version.rs index 11688ec4c61aba3b2bf66be121b3e1bd18724540..93f79ce742510f1fdf041f104d738ad1f0b17580 100644 --- a/crates/semantic_version/src/semantic_version.rs +++ b/crates/semantic_version/src/semantic_version.rs @@ -30,19 +30,19 @@ impl SemanticVersion { /// Returns the major version number. #[inline(always)] - pub fn major(&self) -> usize { + pub const fn major(&self) -> usize { self.major } /// Returns the minor version number. #[inline(always)] - pub fn minor(&self) -> usize { + pub const fn minor(&self) -> usize { self.minor } /// Returns the patch version number. #[inline(always)] - pub fn patch(&self) -> usize { + pub const fn patch(&self) -> usize { self.patch } } diff --git a/crates/settings/src/base_keymap_setting.rs b/crates/settings/src/base_keymap_setting.rs index 4915bdd85319e4abaf3ea575d387a39cc14f302d..bfba815e08e8f9d1fd61e25a8a61786d2deb95d4 100644 --- a/crates/settings/src/base_keymap_setting.rs +++ b/crates/settings/src/base_keymap_setting.rs @@ -87,7 +87,7 @@ impl BaseKeymap { ("Cursor", Self::Cursor), ]; - pub fn asset_path(&self) -> Option<&'static str> { + pub const fn asset_path(&self) -> Option<&'static str> { #[cfg(target_os = "macos")] match self { BaseKeymap::JetBrains => Some("keymaps/macos/jetbrains.json"), diff --git a/crates/settings/src/keymap_file.rs b/crates/settings/src/keymap_file.rs index b69b498a6c5596d8bbc78799e8edbe0befc9c35e..db331de277137850a96258e7e37d18abb709f3bd 100644 --- a/crates/settings/src/keymap_file.rs +++ b/crates/settings/src/keymap_file.rs @@ -944,7 +944,7 @@ impl KeybindUpdateOperation<'_> { } impl<'a> KeybindUpdateOperation<'a> { - pub fn add(source: KeybindUpdateTarget<'a>) -> Self { + pub const fn add(source: KeybindUpdateTarget<'a>) -> Self { Self::Add { source, from: None } } } @@ -1014,7 +1014,7 @@ impl KeybindSource { const VIM: KeyBindingMetaIndex = KeyBindingMetaIndex(KeybindSource::Vim as u32); const USER: KeyBindingMetaIndex = KeyBindingMetaIndex(KeybindSource::User as u32); - pub fn name(&self) -> &'static str { + pub const fn name(&self) -> &'static str { match self { KeybindSource::User => "User", KeybindSource::Default => "Default", @@ -1024,7 +1024,7 @@ impl KeybindSource { } } - pub fn meta(&self) -> KeyBindingMetaIndex { + pub const fn meta(&self) -> KeyBindingMetaIndex { match self { KeybindSource::User => Self::USER, KeybindSource::Default => Self::DEFAULT, @@ -1034,7 +1034,7 @@ impl KeybindSource { } } - pub fn from_meta(index: KeyBindingMetaIndex) -> Self { + pub const fn from_meta(index: KeyBindingMetaIndex) -> Self { match index { Self::USER => KeybindSource::User, Self::BASE => KeybindSource::Base, diff --git a/crates/settings/src/settings.rs b/crates/settings/src/settings.rs index 6fe078301abab974ba202660319966e7df42027a..acf863d2f0badd7908fc735c05fe3e561351d3fe 100644 --- a/crates/settings/src/settings.rs +++ b/crates/settings/src/settings.rs @@ -47,19 +47,19 @@ impl From for usize { } impl WorktreeId { - pub fn from_usize(handle_id: usize) -> Self { + pub const fn from_usize(handle_id: usize) -> Self { Self(handle_id) } - pub fn from_proto(id: u64) -> Self { + pub const fn from_proto(id: u64) -> Self { Self(id as usize) } - pub fn to_proto(self) -> u64 { + pub const fn to_proto(self) -> u64 { self.0 as u64 } - pub fn to_usize(self) -> usize { + pub const fn to_usize(self) -> usize { self.0 } } diff --git a/crates/settings/src/settings_content.rs b/crates/settings/src/settings_content.rs index 92493557eeeb5f28c6a4d25fca3f9e38f8eef6bb..9431ca2bf5a9255fce9385532c5a804934458184 100644 --- a/crates/settings/src/settings_content.rs +++ b/crates/settings/src/settings_content.rs @@ -164,7 +164,7 @@ pub struct SettingsContent { } impl SettingsContent { - pub fn languages_mut(&mut self) -> &mut HashMap { + pub const fn languages_mut(&mut self) -> &mut HashMap { &mut self.project.all_languages.languages.0 } } diff --git a/crates/settings/src/settings_content/agent.rs b/crates/settings/src/settings_content/agent.rs index 80326c84688697ab4dcbc83d9013cf3acab26d2b..1d9d7b5c84928adf46a630c692606187b2299aab 100644 --- a/crates/settings/src/settings_content/agent.rs +++ b/crates/settings/src/settings_content/agent.rs @@ -112,7 +112,7 @@ pub struct AgentSettingsContent { } impl AgentSettingsContent { - pub fn set_dock(&mut self, dock: DockPosition) { + pub const fn set_dock(&mut self, dock: DockPosition) { self.dock = Some(dock); } @@ -147,19 +147,19 @@ impl AgentSettingsContent { }); } - pub fn set_always_allow_tool_actions(&mut self, allow: bool) { + pub const fn set_always_allow_tool_actions(&mut self, allow: bool) { self.always_allow_tool_actions = Some(allow); } - pub fn set_play_sound_when_agent_done(&mut self, allow: bool) { + pub const fn set_play_sound_when_agent_done(&mut self, allow: bool) { self.play_sound_when_agent_done = Some(allow); } - pub fn set_single_file_review(&mut self, allow: bool) { + pub const fn set_single_file_review(&mut self, allow: bool) { self.single_file_review = Some(allow); } - pub fn set_use_modifier_to_send(&mut self, always_use: bool) { + pub const fn set_use_modifier_to_send(&mut self, always_use: bool) { self.use_modifier_to_send = Some(always_use); } diff --git a/crates/settings/src/settings_content/language.rs b/crates/settings/src/settings_content/language.rs index a5dbd682d2ca4943e6230789acad96c5d7e2a742..4b9266d11ff0ce182846344517edbecafd6892b5 100644 --- a/crates/settings/src/settings_content/language.rs +++ b/crates/settings/src/settings_content/language.rs @@ -82,7 +82,7 @@ pub enum EditPredictionProvider { } impl EditPredictionProvider { - pub fn is_zed(&self) -> bool { + pub const fn is_zed(&self) -> bool { match self { EditPredictionProvider::Zed => true, EditPredictionProvider::None @@ -504,7 +504,7 @@ impl InlayHintKind { } /// Returns the name of this [`InlayHintKind`]. - pub fn name(&self) -> &'static str { + pub const fn name(&self) -> &'static str { match self { InlayHintKind::Type => "type", InlayHintKind::Parameter => "parameter", diff --git a/crates/settings/src/settings_content/language_model.rs b/crates/settings/src/settings_content/language_model.rs index 7139aac5eaca5c521007b21dbbb665bb4855347a..e634575751ad6d17c4d6cba7d320d4c25677f62b 100644 --- a/crates/settings/src/settings_content/language_model.rs +++ b/crates/settings/src/settings_content/language_model.rs @@ -123,7 +123,7 @@ pub enum KeepAlive { impl KeepAlive { /// Keep model alive until a new model is loaded or until Ollama shuts down - pub fn indefinite() -> Self { + pub const fn indefinite() -> Self { Self::Seconds(-1) } } @@ -398,7 +398,7 @@ impl Default for DataCollection { } } -fn default_true() -> bool { +const fn default_true() -> bool { true } diff --git a/crates/settings/src/settings_content/project.rs b/crates/settings/src/settings_content/project.rs index d421a7bb2aefb92f0c7cd1de1c89fe1fee95e3ec..bcda184564a093d19f3fb77645ecfeb5469f086a 100644 --- a/crates/settings/src/settings_content/project.rs +++ b/crates/settings/src/settings_content/project.rs @@ -195,7 +195,7 @@ pub enum ContextServerSettingsContent { }, } impl ContextServerSettingsContent { - pub fn set_enabled(&mut self, enabled: bool) { + pub const fn set_enabled(&mut self, enabled: bool) { match self { ContextServerSettingsContent::Custom { enabled: custom_enabled, diff --git a/crates/settings/src/settings_content/theme.rs b/crates/settings/src/settings_content/theme.rs index 45640ae3ae37321498bb3dafd6d07b2ba1f2d92e..a34819597b2a508f465ac9e7c642d0459fdd85ae 100644 --- a/crates/settings/src/settings_content/theme.rs +++ b/crates/settings/src/settings_content/theme.rs @@ -238,7 +238,7 @@ pub enum UiDensity { impl UiDensity { /// The spacing ratio of a given density. /// TODO: Standardize usage throughout the app or remove - pub fn spacing_ratio(self) -> f32 { + pub const fn spacing_ratio(self) -> f32 { match self { UiDensity::Compact => 0.75, UiDensity::Default => 1.0, @@ -879,7 +879,7 @@ pub struct HighlightStyleContent { } impl HighlightStyleContent { - pub fn is_empty(&self) -> bool { + pub const fn is_empty(&self) -> bool { self.color.is_none() && self.background_color.is_none() && self.font_style.is_none() diff --git a/crates/settings/src/settings_content/workspace.rs b/crates/settings/src/settings_content/workspace.rs index 7ebb468f79bf195fb9d97b8d52dd6e728d8c8f99..153690355828af543e7e5d229042e943b522328c 100644 --- a/crates/settings/src/settings_content/workspace.rs +++ b/crates/settings/src/settings_content/workspace.rs @@ -311,7 +311,7 @@ pub enum CloseWindowWhenNoItems { } impl CloseWindowWhenNoItems { - pub fn should_close(&self) -> bool { + pub const fn should_close(&self) -> bool { match self { CloseWindowWhenNoItems::PlatformDefault => cfg!(target_os = "macos"), CloseWindowWhenNoItems::CloseWindow => true, @@ -394,7 +394,7 @@ pub enum AutosaveSetting { } impl AutosaveSetting { - pub fn should_save_on_close(&self) -> bool { + pub const fn should_save_on_close(&self) -> bool { matches!( &self, AutosaveSetting::OnFocusChange @@ -481,7 +481,7 @@ pub enum OnLastWindowClosed { } impl OnLastWindowClosed { - pub fn is_quit_app(&self) -> bool { + pub const fn is_quit_app(&self) -> bool { match self { OnLastWindowClosed::PlatformDefault => false, OnLastWindowClosed::QuitApp => true, diff --git a/crates/settings/src/settings_store.rs b/crates/settings/src/settings_store.rs index 709b4982706250f91c7aaefc365ddf7613cdf5f4..f82a72f428616f415d649d17655f9fac354a7437 100644 --- a/crates/settings/src/settings_store.rs +++ b/crates/settings/src/settings_store.rs @@ -318,7 +318,7 @@ impl SettingsStore { /// /// For user-facing functionality use the typed setting interface. /// (e.g. ProjectSettings::get_global(cx)) - pub fn raw_user_settings(&self) -> Option<&UserSettingsContent> { + pub const fn raw_user_settings(&self) -> Option<&UserSettingsContent> { self.user_settings.as_ref() } diff --git a/crates/settings_ui/src/components.rs b/crates/settings_ui/src/components.rs index a29aae3bb1f2ef086e6d3289b03fbe29000d0f45..a6d09beea1a519f770941dbda6e9d6f7c11e61ca 100644 --- a/crates/settings_ui/src/components.rs +++ b/crates/settings_ui/src/components.rs @@ -28,7 +28,7 @@ impl SettingsEditor { self } - pub fn with_placeholder(mut self, placeholder: &'static str) -> Self { + pub const fn with_placeholder(mut self, placeholder: &'static str) -> Self { self.placeholder = Some(placeholder); self } @@ -38,7 +38,7 @@ impl SettingsEditor { self } - pub(crate) fn tab_index(mut self, arg: isize) -> Self { + pub(crate) const fn tab_index(mut self, arg: isize) -> Self { self.tab_index = Some(arg); self } diff --git a/crates/settings_ui/src/settings_ui.rs b/crates/settings_ui/src/settings_ui.rs index 7856164a12a34643b9a223023a8ab27922c68906..3ba4d4cadf8272825079da06272a2debac24ad7d 100644 --- a/crates/settings_ui/src/settings_ui.rs +++ b/crates/settings_ui/src/settings_ui.rs @@ -893,7 +893,7 @@ impl std::ops::BitOr for FileMask { } impl FileMask { - fn contains(&self, other: FileMask) -> bool { + const fn contains(&self, other: FileMask) -> bool { self.0 & other.0 != 0 } } @@ -951,11 +951,11 @@ enum SettingsUiFile { } impl SettingsUiFile { - fn is_server(&self) -> bool { + const fn is_server(&self) -> bool { matches!(self, SettingsUiFile::Server(_)) } - fn worktree_id(&self) -> Option { + const fn worktree_id(&self) -> Option { match self { SettingsUiFile::User => None, SettingsUiFile::Project((worktree_id, _)) => Some(*worktree_id), @@ -980,7 +980,7 @@ impl SettingsUiFile { } } - fn mask(&self) -> FileMask { + const fn mask(&self) -> FileMask { match self { SettingsUiFile::User => USER, SettingsUiFile::Project(_) => LOCAL, @@ -2478,7 +2478,7 @@ impl SettingsWindow { self.navbar_entries[index].page_index } - fn is_navbar_entry_selected(&self, ix: usize) -> bool { + const fn is_navbar_entry_selected(&self, ix: usize) -> bool { ix == self.navbar_entry } diff --git a/crates/sqlez/src/connection.rs b/crates/sqlez/src/connection.rs index 53f0d4e2614f340cc0563d5cd9374bdc3626d9bb..3904e975655cf6625a3c83343fd8bbbb45f79bec 100644 --- a/crates/sqlez/src/connection.rs +++ b/crates/sqlez/src/connection.rs @@ -60,7 +60,7 @@ impl Connection { Self::open(&in_memory_path, false).expect("Could not create fallback in memory db") } - pub fn persistent(&self) -> bool { + pub const fn persistent(&self) -> bool { self.persistent } diff --git a/crates/sqlez/src/thread_safe_connection.rs b/crates/sqlez/src/thread_safe_connection.rs index 966f14a9c2f244780da7190aebac88e95c7ac068..f4050e2a3391640c7d89a7dd554897497d4a5bfb 100644 --- a/crates/sqlez/src/thread_safe_connection.rs +++ b/crates/sqlez/src/thread_safe_connection.rs @@ -49,14 +49,14 @@ impl ThreadSafeConnectionBuilder { /// Sets the query to run every time a connection is opened. This must /// be infallible (EG only use pragma statements) and not cause writes. /// to the db or it will panic. - pub fn with_connection_initialize_query(mut self, initialize_query: &'static str) -> Self { + pub const fn with_connection_initialize_query(mut self, initialize_query: &'static str) -> Self { self.connection.connection_initialize_query = Some(initialize_query); self } /// Queues an initialization query for the database file. This must be infallible /// but may cause changes to the database file such as with `PRAGMA journal_mode` - pub fn with_db_initialization_query(mut self, initialize_query: &'static str) -> Self { + pub const fn with_db_initialization_query(mut self, initialize_query: &'static str) -> Self { self.db_initialize_query = Some(initialize_query); self } diff --git a/crates/sqlez/src/util.rs b/crates/sqlez/src/util.rs index 8be6d3f4e08e88ac0af3338731c47c9c677e5239..add2bfed0e92c9bc4133fe990dff4a44e6c47b86 100644 --- a/crates/sqlez/src/util.rs +++ b/crates/sqlez/src/util.rs @@ -14,7 +14,7 @@ pub struct UnboundedSyncSender { } impl UnboundedSyncSender { - pub fn new(sender: Sender) -> Self { + pub const fn new(sender: Sender) -> Self { Self { cloneable_sender: Mutex::new(sender), local_senders: ThreadLocal::new(), diff --git a/crates/storybook/src/storybook.rs b/crates/storybook/src/storybook.rs index 592ee7bc7ac5cc92125fc7b4aa5846b4338884d7..63b81d0460081550d21b8ea72c1a668e83be2669 100644 --- a/crates/storybook/src/storybook.rs +++ b/crates/storybook/src/storybook.rs @@ -117,7 +117,7 @@ pub struct StoryWrapper { } impl StoryWrapper { - pub(crate) fn new(story: AnyView) -> Self { + pub(crate) const fn new(story: AnyView) -> Self { Self { story } } } diff --git a/crates/streaming_diff/src/streaming_diff.rs b/crates/streaming_diff/src/streaming_diff.rs index 5677981b0dc9878963e01d09e7281749d6603c8f..2b0945bce0d2680cb3ae022e63f3fc4de547b54c 100644 --- a/crates/streaming_diff/src/streaming_diff.rs +++ b/crates/streaming_diff/src/streaming_diff.rs @@ -15,7 +15,7 @@ struct Matrix { } impl Matrix { - fn new() -> Self { + const fn new() -> Self { Self { cells: Vec::new(), rows: 0, @@ -492,7 +492,7 @@ impl LineDiff { } } -fn is_line_start(point: Point) -> bool { +const fn is_line_start(point: Point) -> bool { point.column == 0 } diff --git a/crates/sum_tree/src/cursor.rs b/crates/sum_tree/src/cursor.rs index 6df1d3da41556dc7eb93f7460b960ccddbe52de6..a5563f239d5b09593d091f028dd9905140394ba3 100644 --- a/crates/sum_tree/src/cursor.rs +++ b/crates/sum_tree/src/cursor.rs @@ -11,7 +11,7 @@ struct StackEntry<'a, T: Item, D> { impl<'a, T: Item, D> StackEntry<'a, T, D> { #[inline] - fn index(&self) -> usize { + const fn index(&self) -> usize { self.index as usize } } @@ -78,7 +78,7 @@ where self.position = D::zero(self.cx); } - pub fn start(&self) -> &D { + pub const fn start(&self) -> &D { &self.position } @@ -655,7 +655,7 @@ where } } - pub fn start(&self) -> &D { + pub const fn start(&self) -> &D { self.cursor.start() } @@ -799,7 +799,7 @@ where struct End(PhantomData); impl End { - fn new() -> Self { + const fn new() -> Self { Self(PhantomData) } } diff --git a/crates/sum_tree/src/sum_tree.rs b/crates/sum_tree/src/sum_tree.rs index bfd2423c9230ea4246509e164d7a03f4890cbf4a..7ee09468a595be7aacce40b75bccd54f5ce74cec 100644 --- a/crates/sum_tree/src/sum_tree.rs +++ b/crates/sum_tree/src/sum_tree.rs @@ -176,7 +176,7 @@ pub enum Bias { } impl Bias { - pub fn invert(self) -> Self { + pub const fn invert(self) -> Self { match self { Self::Left => Self::Right, Self::Right => Self::Left, @@ -855,18 +855,18 @@ where } impl Node { - fn is_leaf(&self) -> bool { + const fn is_leaf(&self) -> bool { matches!(self, Node::Leaf { .. }) } - fn height(&self) -> u8 { + const fn height(&self) -> u8 { match self { Node::Internal { height, .. } => *height, Node::Leaf { .. } => 0, } } - fn summary(&self) -> &T::Summary { + const fn summary(&self) -> &T::Summary { match self { Node::Internal { summary, .. } => summary, Node::Leaf { summary, .. } => summary, @@ -896,7 +896,7 @@ impl Node { } } - fn is_underflowing(&self) -> bool { + const fn is_underflowing(&self) -> bool { match self { Node::Internal { child_trees, .. } => child_trees.len() < TREE_BASE, Node::Leaf { items, .. } => items.len() < TREE_BASE, diff --git a/crates/supermaven/src/supermaven.rs b/crates/supermaven/src/supermaven.rs index 7a9963dbc424185c52be6879a0a9e722db7106b2..9f52c26737e016750b0d02522d1d73ba77997fbd 100644 --- a/crates/supermaven/src/supermaven.rs +++ b/crates/supermaven/src/supermaven.rs @@ -113,7 +113,7 @@ impl Supermaven { *self = Self::Starting; } - pub fn is_enabled(&self) -> bool { + pub const fn is_enabled(&self) -> bool { matches!(self, Self::Spawned { .. }) } diff --git a/crates/supermaven/src/supermaven_completion_provider.rs b/crates/supermaven/src/supermaven_completion_provider.rs index 32177aaa427e8616a2767410a7a6ec84c05abbee..59c02b381627e0fb83e18c45d51667a478b4d492 100644 --- a/crates/supermaven/src/supermaven_completion_provider.rs +++ b/crates/supermaven/src/supermaven_completion_provider.rs @@ -25,7 +25,7 @@ pub struct SupermavenCompletionProvider { } impl SupermavenCompletionProvider { - pub fn new(supermaven: Entity) -> Self { + pub const fn new(supermaven: Entity) -> Self { Self { supermaven, buffer_id: None, diff --git a/crates/system_specs/src/system_specs.rs b/crates/system_specs/src/system_specs.rs index 5c2b0a7fed82c53bbaab5f0ee9a8cc74462870d8..4a4b7f0ebfd46ca3152c4655708fbbdd5b62953a 100644 --- a/crates/system_specs/src/system_specs.rs +++ b/crates/system_specs/src/system_specs.rs @@ -143,7 +143,7 @@ impl Display for SystemSpecs { } } -fn try_determine_available_gpus() -> Option { +const fn try_determine_available_gpus() -> Option { #[cfg(any(target_os = "linux", target_os = "freebsd"))] { #[allow( diff --git a/crates/task/src/shell_builder.rs b/crates/task/src/shell_builder.rs index a6504f4eb765a8a144343691b82cdca9a6802cbd..abbaeb07b7a5fd4eba352c60e30c7204a69ad78d 100644 --- a/crates/task/src/shell_builder.rs +++ b/crates/task/src/shell_builder.rs @@ -34,7 +34,7 @@ impl ShellBuilder { redirect_stdin: false, } } - pub fn non_interactive(mut self) -> Self { + pub const fn non_interactive(mut self) -> Self { self.interactive = false; self } @@ -68,7 +68,7 @@ impl ShellBuilder { } } - pub fn redirect_stdin_to_dev_null(mut self) -> Self { + pub const fn redirect_stdin_to_dev_null(mut self) -> Self { self.redirect_stdin = true; self } diff --git a/crates/task/src/static_source.rs b/crates/task/src/static_source.rs index 9e4051ef9721f4f4ce3b6bbebd38535e4ed8e27b..a3a372085ad9e34015fbd17e915401f7696d60a1 100644 --- a/crates/task/src/static_source.rs +++ b/crates/task/src/static_source.rs @@ -113,7 +113,7 @@ impl TrackedFile { impl StaticSource { /// Initializes the static source, reacting on tasks config changes. - pub fn new(tasks: TrackedFile) -> Self { + pub const fn new(tasks: TrackedFile) -> Self { Self { tasks } } /// Returns current list of tasks diff --git a/crates/task/src/task.rs b/crates/task/src/task.rs index bfb84ced944cda758c7c453f561ca4ec13220c07..29b5f9e0f778386dbb29a0e434d34521088e6be9 100644 --- a/crates/task/src/task.rs +++ b/crates/task/src/task.rs @@ -130,17 +130,17 @@ pub struct ResolvedTask { impl ResolvedTask { /// A task template before the resolution. - pub fn original_task(&self) -> &TaskTemplate { + pub const fn original_task(&self) -> &TaskTemplate { &self.original_task } /// Variables that were substituted during the task template resolution. - pub fn substituted_variables(&self) -> &HashSet { + pub const fn substituted_variables(&self) -> &HashSet { &self.substituted_variables } /// A human-readable label to display in the UI. - pub fn display_label(&self) -> &str { + pub const fn display_label(&self) -> &str { self.resolved.label.as_str() } } @@ -404,7 +404,7 @@ struct EnvVariableReplacer { } impl EnvVariableReplacer { - fn new(variables: HashMap) -> Self { + const fn new(variables: HashMap) -> Self { Self { variables } } diff --git a/crates/terminal/src/mappings/keys.rs b/crates/terminal/src/mappings/keys.rs index b003bf82ad368cd9938788b26a037895677f2caa..cf3e10b4dd78f47ef18247214719e3ed586c4c48 100644 --- a/crates/terminal/src/mappings/keys.rs +++ b/crates/terminal/src/mappings/keys.rs @@ -15,7 +15,7 @@ enum AlacModifiers { } impl AlacModifiers { - fn new(ks: &Keystroke) -> Self { + const fn new(ks: &Keystroke) -> Self { match ( ks.modifiers.alt, ks.modifiers.control, @@ -31,7 +31,7 @@ impl AlacModifiers { } } - fn any(&self) -> bool { + const fn any(&self) -> bool { match &self { AlacModifiers::None => false, AlacModifiers::Alt => true, @@ -246,7 +246,7 @@ pub fn to_esc_str( /// 8 | Shift + Alt + Control /// ---------+--------------------------- /// from: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-PC-Style-Function-Keys -fn modifier_code(keystroke: &Keystroke) -> u32 { +const fn modifier_code(keystroke: &Keystroke) -> u32 { let mut modifier_code = 0; if keystroke.modifiers.shift { modifier_code |= 1; diff --git a/crates/terminal/src/mappings/mouse.rs b/crates/terminal/src/mappings/mouse.rs index 8c3eed8b54972806bdb71c5d4671cfe2a4705ce4..152b97af1f78d94a8b5816ce143184376e426c75 100644 --- a/crates/terminal/src/mappings/mouse.rs +++ b/crates/terminal/src/mappings/mouse.rs @@ -16,7 +16,7 @@ enum MouseFormat { } impl MouseFormat { - fn from_mode(mode: TermMode) -> Self { + const fn from_mode(mode: TermMode) -> Self { if mode.contains(TermMode::SGR_MOUSE) { MouseFormat::Sgr } else if mode.contains(TermMode::UTF8_MOUSE) { @@ -42,7 +42,7 @@ enum AlacMouseButton { } impl AlacMouseButton { - fn from_move_button(e: Option) -> Self { + const fn from_move_button(e: Option) -> Self { match e { Some(gpui::MouseButton::Left) => AlacMouseButton::LeftMove, Some(gpui::MouseButton::Middle) => AlacMouseButton::MiddleMove, @@ -52,7 +52,7 @@ impl AlacMouseButton { } } - fn from_button(e: MouseButton) -> Self { + const fn from_button(e: MouseButton) -> Self { match e { gpui::MouseButton::Left => AlacMouseButton::LeftButton, gpui::MouseButton::Right => AlacMouseButton::MiddleButton, @@ -74,7 +74,7 @@ impl AlacMouseButton { } } - fn is_other(&self) -> bool { + const fn is_other(&self) -> bool { matches!(self, AlacMouseButton::Other) } } diff --git a/crates/terminal/src/pty_info.rs b/crates/terminal/src/pty_info.rs index f8e8a122f845253175ba6f176c12408056163fdb..8c696de56f854457ffca901d75b3bd908a3b29f2 100644 --- a/crates/terminal/src/pty_info.rs +++ b/crates/terminal/src/pty_info.rs @@ -32,7 +32,7 @@ impl ProcessIdGetter { Some(Pid::from_u32(pid as u32)) } - pub fn fallback_pid(&self) -> u32 { + pub const fn fallback_pid(&self) -> u32 { self.fallback_pid } } @@ -104,7 +104,7 @@ impl PtyProcessInfo { } } - pub fn pid_getter(&self) -> &ProcessIdGetter { + pub const fn pid_getter(&self) -> &ProcessIdGetter { &self.pid_getter } diff --git a/crates/terminal/src/terminal.rs b/crates/terminal/src/terminal.rs index 960812da00060a987fbaafe6f248a0d582d60e4f..10f6b42e401e0e22457dd1f3cfeeef9fc5742c2b 100644 --- a/crates/terminal/src/terminal.rs +++ b/crates/terminal/src/terminal.rs @@ -194,7 +194,7 @@ pub struct TerminalBounds { } impl TerminalBounds { - pub fn new(line_height: Pixels, cell_width: Pixels, bounds: Bounds) -> Self { + pub const fn new(line_height: Pixels, cell_width: Pixels, bounds: Bounds) -> Self { TerminalBounds { cell_width, line_height, @@ -210,19 +210,19 @@ impl TerminalBounds { (self.bounds.size.width / self.cell_width).floor() as usize } - pub fn height(&self) -> Pixels { + pub const fn height(&self) -> Pixels { self.bounds.size.height } - pub fn width(&self) -> Pixels { + pub const fn width(&self) -> Pixels { self.bounds.size.width } - pub fn cell_width(&self) -> Pixels { + pub const fn cell_width(&self) -> Pixels { self.cell_width } - pub fn line_height(&self) -> Pixels { + pub const fn line_height(&self) -> Pixels { self.line_height } } @@ -875,7 +875,7 @@ impl TaskStatus { } } - fn register_task_exit(&mut self, error_code: i32) { + const fn register_task_exit(&mut self, error_code: i32) { *self = TaskStatus::Completed { success: error_code == 0, }; @@ -1221,13 +1221,13 @@ impl Terminal { cx.notify() } - fn next_link_id(&mut self) -> usize { + const fn next_link_id(&mut self) -> usize { let res = self.next_link_id; self.next_link_id = self.next_link_id.wrapping_add(1); res } - pub fn last_content(&self) -> &TerminalContent { + pub const fn last_content(&self) -> &TerminalContent { &self.last_content } @@ -1372,11 +1372,11 @@ impl Terminal { .push_back(InternalEvent::Scroll(AlacScroll::Bottom)); } - pub fn scrolled_to_top(&self) -> bool { + pub const fn scrolled_to_top(&self) -> bool { self.last_content.scrolled_to_top } - pub fn scrolled_to_bottom(&self) -> bool { + pub const fn scrolled_to_bottom(&self) -> bool { self.last_content.scrolled_to_bottom } @@ -1679,7 +1679,7 @@ impl Terminal { } } - pub fn mouse_mode(&self, shift: bool) -> bool { + pub const fn mouse_mode(&self, shift: bool) -> bool { self.last_content.mode.intersects(TermMode::MOUSE_MODE) && !shift } @@ -2057,14 +2057,14 @@ impl Terminal { } } - pub fn pid_getter(&self) -> Option<&ProcessIdGetter> { + pub const fn pid_getter(&self) -> Option<&ProcessIdGetter> { match &self.terminal_type { TerminalType::Pty { info, .. } => Some(info.pid_getter()), TerminalType::DisplayOnly => None, } } - pub fn task(&self) -> Option<&TaskState> { + pub const fn task(&self) -> Option<&TaskState> { self.task.as_ref() } @@ -2149,7 +2149,7 @@ impl Terminal { } } - pub fn vi_mode_enabled(&self) -> bool { + pub const fn vi_mode_enabled(&self) -> bool { self.vi_mode_enabled } diff --git a/crates/terminal_view/src/terminal_element.rs b/crates/terminal_view/src/terminal_element.rs index e06e8e9c63633746f336d308614ed9963740c4f8..5bf538fd63d7947cebe7b7901edebd2f7b61e2b4 100644 --- a/crates/terminal_view/src/terminal_element.rs +++ b/crates/terminal_view/src/terminal_element.rs @@ -61,18 +61,18 @@ struct DisplayCursor { } impl DisplayCursor { - fn from(cursor_point: AlacPoint, display_offset: usize) -> Self { + const fn from(cursor_point: AlacPoint, display_offset: usize) -> Self { Self { line: cursor_point.line.0 + display_offset as i32, col: cursor_point.column.0, } } - pub fn line(&self) -> i32 { + pub const fn line(&self) -> i32 { self.line } - pub fn col(&self) -> usize { + pub const fn col(&self) -> usize { self.col } } @@ -163,7 +163,7 @@ pub struct LayoutRect { } impl LayoutRect { - fn new(point: AlacPoint, num_of_cells: usize, color: Hsla) -> LayoutRect { + const fn new(point: AlacPoint, num_of_cells: usize, color: Hsla) -> LayoutRect { LayoutRect { point, num_of_cells, @@ -200,7 +200,7 @@ struct BackgroundRegion { } impl BackgroundRegion { - fn new(line: i32, col: i32, color: Hsla) -> Self { + const fn new(line: i32, col: i32, color: Hsla) -> Self { BackgroundRegion { start_line: line, start_col: col, @@ -527,7 +527,7 @@ impl TerminalElement { /// Regular icons (git, folders, etc.) are excluded as they need to remain readable. /// /// Fixes https://github.com/zed-industries/zed/issues/34234 - fn is_decorative_character(ch: char) -> bool { + const fn is_decorative_character(ch: char) -> bool { matches!( ch as u32, // Unicode Box Drawing and Block Elements diff --git a/crates/terminal_view/src/terminal_panel.rs b/crates/terminal_view/src/terminal_panel.rs index bd718d1432cfeb178355663bc657fd53fc37d57b..c37901d8f14180b1e8268f5de7ee6c0d42f4fd9b 100644 --- a/crates/terminal_view/src/terminal_panel.rs +++ b/crates/terminal_view/src/terminal_panel.rs @@ -1015,7 +1015,7 @@ impl TerminalPanel { self.active_pane.read(cx).items_len() == 0 && self.pending_terminals_to_add == 0 } - pub fn assistant_enabled(&self) -> bool { + pub const fn assistant_enabled(&self) -> bool { self.assistant_enabled } diff --git a/crates/terminal_view/src/terminal_path_like_target.rs b/crates/terminal_view/src/terminal_path_like_target.rs index 8a9b824286508f26c824b18c6ba9a0dbc16e90bd..195cffc8cca65720c7fec960ccf647f8de492044 100644 --- a/crates/terminal_view/src/terminal_path_like_target.rs +++ b/crates/terminal_view/src/terminal_path_like_target.rs @@ -37,21 +37,21 @@ enum OpenTarget { } impl OpenTarget { - fn is_file(&self) -> bool { + const fn is_file(&self) -> bool { match self { OpenTarget::Worktree(_, entry, ..) => entry.is_file(), OpenTarget::File(_, metadata) => !metadata.is_dir, } } - fn is_dir(&self) -> bool { + const fn is_dir(&self) -> bool { match self { OpenTarget::Worktree(_, entry, ..) => entry.is_dir(), OpenTarget::File(_, metadata) => metadata.is_dir, } } - fn path(&self) -> &PathWithPosition { + const fn path(&self) -> &PathWithPosition { match self { OpenTarget::Worktree(path, ..) => path, OpenTarget::File(path, _) => path, diff --git a/crates/terminal_view/src/terminal_view.rs b/crates/terminal_view/src/terminal_view.rs index e89e435b0c5dd2ba064a9904dfacec6870d8d512..e839ff2edb27130c18bdb7361a6a4b08708039af 100644 --- a/crates/terminal_view/src/terminal_view.rs +++ b/crates/terminal_view/src/terminal_view.rs @@ -174,7 +174,7 @@ impl ContentMode { } } - pub fn is_scrollable(&self) -> bool { + pub const fn is_scrollable(&self) -> bool { matches!(self, ContentMode::Scrollable) } } @@ -356,11 +356,11 @@ impl TerminalView { self.terminal.read(cx).last_content().terminal_bounds } - pub fn entity(&self) -> &Entity { + pub const fn entity(&self) -> &Entity { &self.terminal } - pub fn has_bell(&self) -> bool { + pub const fn has_bell(&self) -> bool { self.has_bell } @@ -660,7 +660,7 @@ impl TerminalView { .detach(); } - pub fn terminal(&self) -> &Entity { + pub const fn terminal(&self) -> &Entity { &self.terminal } @@ -681,7 +681,7 @@ impl TerminalView { cx.notify(); } - fn next_blink_epoch(&mut self) -> usize { + const fn next_blink_epoch(&mut self) -> usize { self.blink_epoch += 1; self.blink_epoch } diff --git a/crates/text/src/operation_queue.rs b/crates/text/src/operation_queue.rs index 6604817edfe2dcc243ba837a770b361bd505a7ef..38190e4bd259ec1a394dc97b8e045bf4a9f9e096 100644 --- a/crates/text/src/operation_queue.rs +++ b/crates/text/src/operation_queue.rs @@ -21,7 +21,7 @@ pub struct OperationSummary { } impl OperationKey { - pub fn new(timestamp: clock::Lamport) -> Self { + pub const fn new(timestamp: clock::Lamport) -> Self { Self(timestamp) } } diff --git a/crates/text/src/patch.rs b/crates/text/src/patch.rs index b8bb904052be44d7b67ba51215896f6f308c39c9..6e491e816eb91c4597c97d4e0c6971f8844b664e 100644 --- a/crates/text/src/patch.rs +++ b/crates/text/src/patch.rs @@ -180,7 +180,7 @@ where self.0.clear(); } - pub fn is_empty(&self) -> bool { + pub const fn is_empty(&self) -> bool { self.0.is_empty() } diff --git a/crates/text/src/selection.rs b/crates/text/src/selection.rs index e690792d0c903031f8fc7e8bf81215bf0db0e336..83ec3a7b5b7cda1ce1bdba03cfcd6ce2b0731e22 100644 --- a/crates/text/src/selection.rs +++ b/crates/text/src/selection.rs @@ -117,7 +117,7 @@ impl Selection { self.goal = new_goal; } - pub fn swap_head_tail(&mut self) { + pub const fn swap_head_tail(&mut self) { if self.reversed { self.reversed = false; } else { @@ -127,7 +127,7 @@ impl Selection { } impl Selection { - pub fn range(&self) -> Range { + pub const fn range(&self) -> Range { self.start..self.end } } @@ -144,7 +144,7 @@ impl Selection { } } - pub fn equals(&self, offset_range: &Range) -> bool { + pub const fn equals(&self, offset_range: &Range) -> bool { self.start == offset_range.start && self.end == offset_range.end } } diff --git a/crates/text/src/text.rs b/crates/text/src/text.rs index 2eacef5ae037e0d45c53404f30d8c81bdedf4dc1..1adad56fa1d2de5866706bce3715d30d1aaf3b58 100644 --- a/crates/text/src/text.rs +++ b/crates/text/src/text.rs @@ -84,7 +84,7 @@ impl BufferId { /// Increments this buffer id, returning the old value. /// So that's a post-increment operator in disguise. - pub fn next(&mut self) -> Self { + pub const fn next(&mut self) -> Self { let old = *self; self.0 = self.0.saturating_add(1); old @@ -137,7 +137,7 @@ impl Transaction { } impl HistoryEntry { - pub fn transaction_id(&self) -> TransactionId { + pub const fn transaction_id(&self) -> TransactionId { self.transaction.id } } @@ -175,7 +175,7 @@ impl PartialOrd for InsertionSlice { } impl InsertionSlice { - fn from_fragment(edit_id: clock::Lamport, fragment: &Fragment) -> Self { + const fn from_fragment(edit_id: clock::Lamport, fragment: &Fragment) -> Self { Self { edit_id, insertion_id: fragment.timestamp, @@ -639,7 +639,7 @@ impl LineIndent { } /// Constructs a new `LineIndent` which only contains spaces. - pub fn spaces(spaces: u32) -> Self { + pub const fn spaces(spaces: u32) -> Self { Self { tabs: 0, spaces, @@ -648,7 +648,7 @@ impl LineIndent { } /// Constructs a new `LineIndent` which only contains tabs. - pub fn tabs(tabs: u32) -> Self { + pub const fn tabs(tabs: u32) -> Self { Self { tabs, spaces: 0, @@ -657,22 +657,22 @@ impl LineIndent { } /// Indicates whether the line is empty. - pub fn is_line_empty(&self) -> bool { + pub const fn is_line_empty(&self) -> bool { self.tabs == 0 && self.spaces == 0 && self.line_blank } /// Indicates whether the line is blank (contains only whitespace). - pub fn is_line_blank(&self) -> bool { + pub const fn is_line_blank(&self) -> bool { self.line_blank } /// Returns the number of indentation characters (tabs or spaces). - pub fn raw_len(&self) -> u32 { + pub const fn raw_len(&self) -> u32 { self.tabs + self.spaces } /// Returns the number of indentation characters (tabs or spaces), taking tab size into account. - pub fn len(&self, tab_size: u32) -> u32 { + pub const fn len(&self, tab_size: u32) -> u32 { self.tabs * tab_size + self.spaces } } @@ -795,7 +795,7 @@ impl Buffer { } } - pub fn replica_id(&self) -> ReplicaId { + pub const fn replica_id(&self) -> ReplicaId { self.lamport_clock.replica_id } @@ -807,7 +807,7 @@ impl Buffer { self.deferred_ops.len() } - pub fn transaction_group_interval(&self) -> Duration { + pub const fn transaction_group_interval(&self) -> Duration { self.history.group_interval } @@ -1000,7 +1000,7 @@ impl Buffer { edit_op } - pub fn set_line_ending(&mut self, line_ending: LineEnding) { + pub const fn set_line_ending(&mut self, line_ending: LineEnding) { self.snapshot.line_ending = line_ending; } @@ -1419,11 +1419,11 @@ impl Buffer { self.history.group_until(transaction_id); } - pub fn base_text(&self) -> &Rope { + pub const fn base_text(&self) -> &Rope { &self.history.base_text } - pub fn operations(&self) -> &TreeMap { + pub const fn operations(&self) -> &TreeMap { &self.history.operations } @@ -1901,7 +1901,7 @@ impl Deref for Buffer { } impl BufferSnapshot { - pub fn as_rope(&self) -> &Rope { + pub const fn as_rope(&self) -> &Rope { &self.visible_text } @@ -1948,11 +1948,11 @@ impl BufferSnapshot { rope } - pub fn remote_id(&self) -> BufferId { + pub const fn remote_id(&self) -> BufferId { self.remote_id } - pub fn replica_id(&self) -> ReplicaId { + pub const fn replica_id(&self) -> ReplicaId { self.replica_id } @@ -2026,7 +2026,7 @@ impl BufferSnapshot { self.visible_text.to_string() } - pub fn line_ending(&self) -> LineEnding { + pub const fn line_ending(&self) -> LineEnding { self.line_ending } @@ -2086,7 +2086,7 @@ impl BufferSnapshot { self.visible_text.point_to_point_utf16(point) } - pub fn version(&self) -> &clock::Global { + pub const fn version(&self) -> &clock::Global { &self.version } @@ -3046,21 +3046,21 @@ impl Operation { operation_queue::Operation::lamport_timestamp(self).replica_id } - pub fn timestamp(&self) -> clock::Lamport { + pub const fn timestamp(&self) -> clock::Lamport { match self { Operation::Edit(edit) => edit.timestamp, Operation::Undo(undo) => undo.timestamp, } } - pub fn as_edit(&self) -> Option<&EditOperation> { + pub const fn as_edit(&self) -> Option<&EditOperation> { match self { Operation::Edit(edit) => Some(edit), _ => None, } } - pub fn is_edit(&self) -> bool { + pub const fn is_edit(&self) -> bool { matches!(self, Operation::Edit { .. }) } } @@ -3256,7 +3256,7 @@ impl Default for LineEnding { } impl LineEnding { - pub fn as_str(&self) -> &'static str { + pub const fn as_str(&self) -> &'static str { match self { LineEnding::Unix => "\n", LineEnding::Windows => "\r\n", diff --git a/crates/theme/src/scale.rs b/crates/theme/src/scale.rs index 70c6114cc6aa240d0de1b442a08583b66cebaf3b..450c14e640512dc3d67f5fb0133a41a38c084fa4 100644 --- a/crates/theme/src/scale.rs +++ b/crates/theme/src/scale.rs @@ -262,23 +262,23 @@ impl ColorScaleSet { } } - pub fn name(&self) -> &SharedString { + pub const fn name(&self) -> &SharedString { &self.name } - pub fn light(&self) -> &ColorScale { + pub const fn light(&self) -> &ColorScale { &self.light } - pub fn light_alpha(&self) -> &ColorScale { + pub const fn light_alpha(&self) -> &ColorScale { &self.light_alpha } - pub fn dark(&self) -> &ColorScale { + pub const fn dark(&self) -> &ColorScale { &self.dark } - pub fn dark_alpha(&self) -> &ColorScale { + pub const fn dark_alpha(&self) -> &ColorScale { &self.dark_alpha } diff --git a/crates/theme/src/schema.rs b/crates/theme/src/schema.rs index 2d7e1ff9d823eae0d48b375592c6d1f91318f472..0e487ddd848cc1f3be3729a6d4c40c2859fe18ed 100644 --- a/crates/theme/src/schema.rs +++ b/crates/theme/src/schema.rs @@ -20,7 +20,7 @@ fn ensure_non_opaque(color: Hsla) -> Hsla { } } -fn ensure_opaque(color: Hsla) -> Hsla { +const fn ensure_opaque(color: Hsla) -> Hsla { Hsla { a: 1.0, ..color } } diff --git a/crates/theme/src/settings.rs b/crates/theme/src/settings.rs index 3ac0f410efbdb4418236959e06d1b6772f7e3684..47601e899328ca5786f67df905ef780bc275edc4 100644 --- a/crates/theme/src/settings.rs +++ b/crates/theme/src/settings.rs @@ -53,7 +53,7 @@ pub enum UiDensity { impl UiDensity { /// The spacing ratio of a given density. /// TODO: Standardize usage throughout the app or remove - pub fn spacing_ratio(self) -> f32 { + pub const fn spacing_ratio(self) -> f32 { match self { UiDensity::Compact => 0.75, UiDensity::Default => 1.0, @@ -142,7 +142,7 @@ pub(crate) const DEFAULT_LIGHT_THEME: &'static str = "One Light"; pub(crate) const DEFAULT_DARK_THEME: &'static str = "One Dark"; /// Returns the name of the default theme for the given [`Appearance`]. -pub fn default_theme(appearance: Appearance) -> &'static str { +pub const fn default_theme(appearance: Appearance) -> &'static str { match appearance { Appearance::Light => DEFAULT_LIGHT_THEME, Appearance::Dark => DEFAULT_DARK_THEME, @@ -244,7 +244,7 @@ impl ThemeSelection { } /// Returns the [ThemeMode] for the [ThemeSelection]. - pub fn mode(&self) -> Option { + pub const fn mode(&self) -> Option { match self { ThemeSelection::Static(_) => None, ThemeSelection::Dynamic { mode, .. } => Some(*mode), @@ -296,7 +296,7 @@ impl IconThemeSelection { } /// Returns the [`ThemeMode`] for the [`IconThemeSelection`]. - pub fn mode(&self) -> Option { + pub const fn mode(&self) -> Option { match self { IconThemeSelection::Static(_) => None, IconThemeSelection::Dynamic { mode, .. } => Some(*mode), @@ -437,7 +437,7 @@ impl From for BufferLineHeight { impl BufferLineHeight { /// Returns the value of the line height. - pub fn value(&self) -> f32 { + pub const fn value(&self) -> f32 { match self { BufferLineHeight::Comfortable => 1.618, BufferLineHeight::Standard => 1.3, @@ -487,7 +487,7 @@ impl ThemeSettings { /// /// The real buffer font size is stored in-memory, to support temporary font size changes. /// Use [`Self::buffer_font_size`] to get the real font size. - pub fn buffer_font_size_settings(&self) -> Pixels { + pub const fn buffer_font_size_settings(&self) -> Pixels { self.buffer_font_size } @@ -495,7 +495,7 @@ impl ThemeSettings { /// /// The real UI font size is stored in-memory, to support temporary font size changes. /// Use [`Self::ui_font_size`] to get the real font size. - pub fn ui_font_size_settings(&self) -> Pixels { + pub const fn ui_font_size_settings(&self) -> Pixels { self.ui_font_size } @@ -503,7 +503,7 @@ impl ThemeSettings { /// /// The real agent font size is stored in-memory, to support temporary font size changes. /// Use [`Self::agent_ui_font_size`] to get the real font size. - pub fn agent_ui_font_size_settings(&self) -> Option { + pub const fn agent_ui_font_size_settings(&self) -> Option { self.agent_ui_font_size } @@ -511,13 +511,13 @@ impl ThemeSettings { /// /// The real agent buffer font size is stored in-memory, to support temporary font size changes. /// Use [`Self::agent_buffer_font_size`] to get the real font size. - pub fn agent_buffer_font_size_settings(&self) -> Option { + pub const fn agent_buffer_font_size_settings(&self) -> Option { self.agent_buffer_font_size } // TODO: Rename: `line_height` -> `buffer_line_height` /// Returns the buffer's line height. - pub fn line_height(&self) -> f32 { + pub const fn line_height(&self) -> f32 { f32::max(self.buffer_line_height.value(), MIN_LINE_HEIGHT) } @@ -670,7 +670,7 @@ pub fn clamp_font_size(size: Pixels) -> Pixels { size.clamp(MIN_FONT_SIZE, MAX_FONT_SIZE) } -fn clamp_font_weight(weight: f32) -> FontWeight { +const fn clamp_font_weight(weight: f32) -> FontWeight { FontWeight(weight.clamp(100., 950.)) } diff --git a/crates/theme/src/styles/colors.rs b/crates/theme/src/styles/colors.rs index 198ad97adb5d964a1d8f62c5bde99d1d5be5adf7..a548e8481d8bc55014f9ded500aee43a42e65955 100644 --- a/crates/theme/src/styles/colors.rs +++ b/crates/theme/src/styles/colors.rs @@ -404,7 +404,7 @@ pub enum ThemeColorField { } impl ThemeColors { - pub fn color(&self, field: ThemeColorField) -> Hsla { + pub const fn color(&self, field: ThemeColorField) -> Hsla { match field { ThemeColorField::Border => self.border, ThemeColorField::BorderVariant => self.border_variant, diff --git a/crates/theme/src/styles/status.rs b/crates/theme/src/styles/status.rs index ab333ecb3ee2d0be32aa76e99e073fb37873bcf9..580fb1a73ac998c34c5a8870ede2068326d06c78 100644 --- a/crates/theme/src/styles/status.rs +++ b/crates/theme/src/styles/status.rs @@ -181,7 +181,7 @@ impl StatusColors { } } - pub fn diagnostic(&self) -> DiagnosticColors { + pub const fn diagnostic(&self) -> DiagnosticColors { DiagnosticColors { error: self.error, warning: self.warning, diff --git a/crates/theme/src/theme.rs b/crates/theme/src/theme.rs index fab173484d999711590e6600a92e6ac870bee54e..c85f59ab1cd0da447e53048e45fb88706ea4ba3d 100644 --- a/crates/theme/src/theme.rs +++ b/crates/theme/src/theme.rs @@ -67,7 +67,7 @@ pub enum Appearance { impl Appearance { /// Returns whether the appearance is light. - pub fn is_light(&self) -> bool { + pub const fn is_light(&self) -> bool { match self { Self::Light => true, Self::Dark => false, @@ -337,37 +337,37 @@ pub struct Theme { impl Theme { /// Returns the [`SystemColors`] for the theme. #[inline(always)] - pub fn system(&self) -> &SystemColors { + pub const fn system(&self) -> &SystemColors { &self.styles.system } /// Returns the [`AccentColors`] for the theme. #[inline(always)] - pub fn accents(&self) -> &AccentColors { + pub const fn accents(&self) -> &AccentColors { &self.styles.accents } /// Returns the [`PlayerColors`] for the theme. #[inline(always)] - pub fn players(&self) -> &PlayerColors { + pub const fn players(&self) -> &PlayerColors { &self.styles.player } /// Returns the [`ThemeColors`] for the theme. #[inline(always)] - pub fn colors(&self) -> &ThemeColors { + pub const fn colors(&self) -> &ThemeColors { &self.styles.colors } /// Returns the [`SyntaxTheme`] for the theme. #[inline(always)] - pub fn syntax(&self) -> &Arc { + pub const fn syntax(&self) -> &Arc { &self.styles.syntax } /// Returns the [`StatusColors`] for the theme. #[inline(always)] - pub fn status(&self) -> &StatusColors { + pub const fn status(&self) -> &StatusColors { &self.styles.status } @@ -379,13 +379,13 @@ impl Theme { /// Returns the [`Appearance`] for the theme. #[inline(always)] - pub fn appearance(&self) -> Appearance { + pub const fn appearance(&self) -> Appearance { self.appearance } /// Returns the [`WindowBackgroundAppearance`] for the theme. #[inline(always)] - pub fn window_background_appearance(&self) -> WindowBackgroundAppearance { + pub const fn window_background_appearance(&self) -> WindowBackgroundAppearance { self.styles.window_background_appearance } diff --git a/crates/theme_importer/src/vscode/converter.rs b/crates/theme_importer/src/vscode/converter.rs index e4a9769978e7f2b987c1404474d0f029bec7977b..06f1f8b23340454425f89b7310e9eb5fcd2d1d85 100644 --- a/crates/theme_importer/src/vscode/converter.rs +++ b/crates/theme_importer/src/vscode/converter.rs @@ -33,7 +33,7 @@ pub struct VsCodeThemeConverter { } impl VsCodeThemeConverter { - pub fn new( + pub const fn new( theme: VsCodeTheme, theme_metadata: ThemeMetadata, syntax_overrides: IndexMap>, diff --git a/crates/theme_importer/src/vscode/syntax.rs b/crates/theme_importer/src/vscode/syntax.rs index 7b134089b70d30b1a7b49e42cadc86f2235cdc03..5cdfcb274cc82aa5c4bf468a5ad3abcb1dc968f6 100644 --- a/crates/theme_importer/src/vscode/syntax.rs +++ b/crates/theme_importer/src/vscode/syntax.rs @@ -173,7 +173,7 @@ impl ZedSyntaxToken { Some(matches) } - pub fn fallbacks(&self) -> &[Self] { + pub const fn fallbacks(&self) -> &[Self] { match self { ZedSyntaxToken::CommentDoc => &[ZedSyntaxToken::Comment], ZedSyntaxToken::Number => &[ZedSyntaxToken::Constant], diff --git a/crates/title_bar/src/platforms/platform_linux.rs b/crates/title_bar/src/platforms/platform_linux.rs index 0e7af80f80e8dcbea03a3b3375f1e4dfd7ca2f37..d9a8ebef1c5142354f3eb0de61a4110a717141b8 100644 --- a/crates/title_bar/src/platforms/platform_linux.rs +++ b/crates/title_bar/src/platforms/platform_linux.rs @@ -57,7 +57,7 @@ impl WindowControlType { /// /// Will take a [PlatformStyle] in the future to return a different /// icon name based on the platform. - pub fn icon(&self) -> IconName { + pub const fn icon(&self) -> IconName { match self { WindowControlType::Minimize => IconName::GenericMinimize, WindowControlType::Restore => IconName::GenericRestore, diff --git a/crates/title_bar/src/platforms/platform_windows.rs b/crates/title_bar/src/platforms/platform_windows.rs index 1df75ee8a9b3d2716e79f9a632b79e8c6df739c0..af5c64a5c5bb00ea9710b7121d83582fece869a0 100644 --- a/crates/title_bar/src/platforms/platform_windows.rs +++ b/crates/title_bar/src/platforms/platform_windows.rs @@ -8,12 +8,12 @@ pub struct WindowsWindowControls { } impl WindowsWindowControls { - pub fn new(button_height: Pixels) -> Self { + pub const fn new(button_height: Pixels) -> Self { Self { button_height } } #[cfg(not(target_os = "windows"))] - fn get_font() -> &'static str { + const fn get_font() -> &'static str { "Segoe Fluent Icons" } diff --git a/crates/ui/src/components/avatar.rs b/crates/ui/src/components/avatar.rs index 19f7c4660bc64e756950df6f5ab0e19192f4096b..0983732ccc6942ac8aed1f5d48e8c4c98efc19d1 100644 --- a/crates/ui/src/components/avatar.rs +++ b/crates/ui/src/components/avatar.rs @@ -184,7 +184,7 @@ pub struct AvatarAvailabilityIndicator { impl AvatarAvailabilityIndicator { /// Creates a new indicator - pub fn new(availability: CollaboratorAvailability) -> Self { + pub const fn new(availability: CollaboratorAvailability) -> Self { Self { availability, avatar_size: None, diff --git a/crates/ui/src/components/badge.rs b/crates/ui/src/components/badge.rs index 9db6fd616f56769b03d1856cfda3fdeef66e446f..26d58b3f78b7509428ab92edab0582f6fad1cc87 100644 --- a/crates/ui/src/components/badge.rs +++ b/crates/ui/src/components/badge.rs @@ -24,7 +24,7 @@ impl Badge { } } - pub fn icon(mut self, icon: IconName) -> Self { + pub const fn icon(mut self, icon: IconName) -> Self { self.icon = icon; self } diff --git a/crates/ui/src/components/banner.rs b/crates/ui/src/components/banner.rs index a09170f5b2693d26b2c9f3ef539e1a70d391615a..00b44b41e3d605b65c04a9b0767f4b2f936ec2e9 100644 --- a/crates/ui/src/components/banner.rs +++ b/crates/ui/src/components/banner.rs @@ -29,7 +29,7 @@ pub struct Banner { impl Banner { /// Creates a new `Banner` component with default styling. - pub fn new() -> Self { + pub const fn new() -> Self { Self { severity: Severity::Info, children: Vec::new(), @@ -38,7 +38,7 @@ impl Banner { } /// Sets the severity of the banner. - pub fn severity(mut self, severity: Severity) -> Self { + pub const fn severity(mut self, severity: Severity) -> Self { self.severity = severity; self } diff --git a/crates/ui/src/components/button/button.rs b/crates/ui/src/components/button/button.rs index b09b58b3e993eacca1b5ab6cf219bbf60d081b69..6508777a8db183773a731028ed3692c218c1a5ac 100644 --- a/crates/ui/src/components/button/button.rs +++ b/crates/ui/src/components/button/button.rs @@ -195,13 +195,13 @@ impl Button { /// /// This method allows you to specify where the keybinding should be displayed /// in relation to the button's label. - pub fn key_binding_position(mut self, position: KeybindingPosition) -> Self { + pub const fn key_binding_position(mut self, position: KeybindingPosition) -> Self { self.key_binding_position = position; self } /// Sets the alpha property of the color of label. - pub fn alpha(mut self, alpha: f32) -> Self { + pub const fn alpha(mut self, alpha: f32) -> Self { self.alpha = Some(alpha); self } @@ -210,7 +210,7 @@ impl Button { /// /// Buttons with static labels should _never_ be truncated, ensure /// this is only used when the label is dynamic and may overflow. - pub fn truncate(mut self, truncate: bool) -> Self { + pub const fn truncate(mut self, truncate: bool) -> Self { self.truncate = truncate; self } diff --git a/crates/ui/src/components/button/button_icon.rs b/crates/ui/src/components/button/button_icon.rs index 510c418714575112070e64e945da3e185f37ee3e..178846d684a4331958133f0126e0c2113933c100 100644 --- a/crates/ui/src/components/button/button_icon.rs +++ b/crates/ui/src/components/button/button_icon.rs @@ -64,7 +64,7 @@ impl ButtonIcon { self } - pub fn indicator_border_color(mut self, color: Option) -> Self { + pub const fn indicator_border_color(mut self, color: Option) -> Self { self.indicator_border_color = color; self } diff --git a/crates/ui/src/components/button/button_like.rs b/crates/ui/src/components/button/button_like.rs index 0c8893e2cccb64243f373126429a823b919bca42..b22dd6b49002813cd36d3bdeea2f0ef1201cc178 100644 --- a/crates/ui/src/components/button/button_like.rs +++ b/crates/ui/src/components/button/button_like.rs @@ -512,7 +512,7 @@ impl ButtonLike { self } - pub fn height(mut self, height: DefiniteLength) -> Self { + pub const fn height(mut self, height: DefiniteLength) -> Self { self.height = Some(height); self } diff --git a/crates/ui/src/components/button/icon_button.rs b/crates/ui/src/components/button/icon_button.rs index 961176ed6cee7e55c7a51cd52719c0eef8a8f181..76f1f1c0e72ef43e792b871d7d0de43c556add49 100644 --- a/crates/ui/src/components/button/icon_button.rs +++ b/crates/ui/src/components/button/icon_button.rs @@ -45,22 +45,22 @@ impl IconButton { this } - pub fn shape(mut self, shape: IconButtonShape) -> Self { + pub const fn shape(mut self, shape: IconButtonShape) -> Self { self.shape = shape; self } - pub fn icon_size(mut self, icon_size: IconSize) -> Self { + pub const fn icon_size(mut self, icon_size: IconSize) -> Self { self.icon_size = icon_size; self } - pub fn icon_color(mut self, icon_color: Color) -> Self { + pub const fn icon_color(mut self, icon_color: Color) -> Self { self.icon_color = icon_color; self } - pub fn alpha(mut self, alpha: f32) -> Self { + pub const fn alpha(mut self, alpha: f32) -> Self { self.alpha = Some(alpha); self } @@ -89,7 +89,7 @@ impl IconButton { self } - pub fn indicator_border_color(mut self, color: Option) -> Self { + pub const fn indicator_border_color(mut self, color: Option) -> Self { self.indicator_border_color = color; self diff --git a/crates/ui/src/components/button/split_button.rs b/crates/ui/src/components/button/split_button.rs index 14b9fd153cd5ad662467c75ff81700587667cee3..fbee2769079a6082de6b016973304edf07d5c9b4 100644 --- a/crates/ui/src/components/button/split_button.rs +++ b/crates/ui/src/components/button/split_button.rs @@ -29,7 +29,7 @@ pub struct SplitButton { } impl SplitButton { - pub fn new(left: ButtonLike, right: AnyElement) -> Self { + pub const fn new(left: ButtonLike, right: AnyElement) -> Self { Self { left, right, @@ -37,7 +37,7 @@ impl SplitButton { } } - pub fn style(mut self, style: SplitButtonStyle) -> Self { + pub const fn style(mut self, style: SplitButtonStyle) -> Self { self.style = style; self } diff --git a/crates/ui/src/components/button/toggle_button.rs b/crates/ui/src/components/button/toggle_button.rs index 2a3db701d15d12361ebe623d8d56fa35ae0016a7..79823bff3d5c446be3738342a8550270521e1e05 100644 --- a/crates/ui/src/components/button/toggle_button.rs +++ b/crates/ui/src/components/button/toggle_button.rs @@ -33,7 +33,7 @@ impl ToggleButtonPosition { ..Self::HORIZONTAL_MIDDLE }; - pub(crate) fn to_rounding(self) -> ButtonLikeRounding { + pub(crate) const fn to_rounding(self) -> ButtonLikeRounding { ButtonLikeRounding { top_left: self.topmost && self.leftmost, top_right: self.topmost && self.rightmost, @@ -66,20 +66,20 @@ impl ToggleButton { self } - pub fn position_in_group(mut self, position: ToggleButtonPosition) -> Self { + pub const fn position_in_group(mut self, position: ToggleButtonPosition) -> Self { self.position_in_group = Some(position); self } - pub fn first(self) -> Self { + pub const fn first(self) -> Self { self.position_in_group(ToggleButtonPosition::HORIZONTAL_FIRST) } - pub fn middle(self) -> Self { + pub const fn middle(self) -> Self { self.position_in_group(ToggleButtonPosition::HORIZONTAL_MIDDLE) } - pub fn last(self) -> Self { + pub const fn last(self) -> Self { self.position_in_group(ToggleButtonPosition::HORIZONTAL_LAST) } } @@ -363,7 +363,7 @@ impl ToggleButtonSimple { } } - pub fn selected(mut self, selected: bool) -> Self { + pub const fn selected(mut self, selected: bool) -> Self { self.selected = selected; self } @@ -411,7 +411,7 @@ impl ToggleButtonWithIcon { } } - pub fn selected(mut self, selected: bool) -> Self { + pub const fn selected(mut self, selected: bool) -> Self { self.selected = selected; self } @@ -496,17 +496,17 @@ impl ToggleButtonGroup { } impl ToggleButtonGroup { - pub fn style(mut self, style: ToggleButtonGroupStyle) -> Self { + pub const fn style(mut self, style: ToggleButtonGroupStyle) -> Self { self.style = style; self } - pub fn size(mut self, size: ToggleButtonGroupSize) -> Self { + pub const fn size(mut self, size: ToggleButtonGroupSize) -> Self { self.size = size; self } - pub fn selected_index(mut self, index: usize) -> Self { + pub const fn selected_index(mut self, index: usize) -> Self { self.selected_index = index; self } @@ -514,7 +514,7 @@ impl ToggleButtonGroup Self { + pub const fn tab_index(mut self, tab_index: &mut isize) -> Self { self.tab_index = Some(*tab_index); *tab_index += (COLS * ROWS) as isize; self diff --git a/crates/ui/src/components/callout.rs b/crates/ui/src/components/callout.rs index b5d1d7f25531cc956388da9d4a977bdfd14204b9..4441642cba503cfe470d38393e0c94da6f9266ca 100644 --- a/crates/ui/src/components/callout.rs +++ b/crates/ui/src/components/callout.rs @@ -38,7 +38,7 @@ pub struct Callout { impl Callout { /// Creates a new `Callout` component with default styling. - pub fn new() -> Self { + pub const fn new() -> Self { Self { severity: Severity::Info, icon: None, @@ -52,13 +52,13 @@ impl Callout { } /// Sets the severity of the callout. - pub fn severity(mut self, severity: Severity) -> Self { + pub const fn severity(mut self, severity: Severity) -> Self { self.severity = severity; self } /// Sets the icon to display in the callout. - pub fn icon(mut self, icon: IconName) -> Self { + pub const fn icon(mut self, icon: IconName) -> Self { self.icon = Some(icon); self } @@ -90,13 +90,13 @@ impl Callout { } /// Sets a custom line height for the callout content. - pub fn line_height(mut self, line_height: Pixels) -> Self { + pub const fn line_height(mut self, line_height: Pixels) -> Self { self.line_height = Some(line_height); self } /// Sets the border position in the callout. - pub fn border_position(mut self, border_position: BorderPosition) -> Self { + pub const fn border_position(mut self, border_position: BorderPosition) -> Self { self.border_position = border_position; self } diff --git a/crates/ui/src/components/chip.rs b/crates/ui/src/components/chip.rs index 8d0000db949fdf77353aa9a381076567f0b320f4..37bc6c1c60c0cc544a1aa9fcb55db7c01373f2da 100644 --- a/crates/ui/src/components/chip.rs +++ b/crates/ui/src/components/chip.rs @@ -30,19 +30,19 @@ impl Chip { } /// Sets the color of the label. - pub fn label_color(mut self, color: Color) -> Self { + pub const fn label_color(mut self, color: Color) -> Self { self.label_color = color; self } /// Sets the size of the label. - pub fn label_size(mut self, size: LabelSize) -> Self { + pub const fn label_size(mut self, size: LabelSize) -> Self { self.label_size = size; self } /// Sets a custom background color for the callout content. - pub fn bg_color(mut self, color: Hsla) -> Self { + pub const fn bg_color(mut self, color: Hsla) -> Self { self.bg_color = Some(color); self } diff --git a/crates/ui/src/components/content_group.rs b/crates/ui/src/components/content_group.rs index f89d38d15329ba2ca3b91ad7aafefcd5258c520a..76bb7262e53f2695b2d3cd0e75e202a9ed43e41f 100644 --- a/crates/ui/src/components/content_group.rs +++ b/crates/ui/src/components/content_group.rs @@ -43,13 +43,13 @@ impl ContentGroup { } /// Removes the border from the [`ContentGroup`]. - pub fn borderless(mut self) -> Self { + pub const fn borderless(mut self) -> Self { self.border = false; self } /// Removes the background fill from the [`ContentGroup`]. - pub fn unfilled(mut self) -> Self { + pub const fn unfilled(mut self) -> Self { self.fill = false; self } diff --git a/crates/ui/src/components/context_menu.rs b/crates/ui/src/components/context_menu.rs index 7b61789b3c87d54ff231e1d635266d6502fb944f..a1ce2c706875d2fac11638581d4bd67648e379dd 100644 --- a/crates/ui/src/components/context_menu.rs +++ b/crates/ui/src/components/context_menu.rs @@ -80,32 +80,32 @@ impl ContextMenuEntry { } } - pub fn toggleable(mut self, toggle_position: IconPosition, toggled: bool) -> Self { + pub const fn toggleable(mut self, toggle_position: IconPosition, toggled: bool) -> Self { self.toggle = Some((toggle_position, toggled)); self } - pub fn icon(mut self, icon: IconName) -> Self { + pub const fn icon(mut self, icon: IconName) -> Self { self.icon = Some(icon); self } - pub fn icon_position(mut self, position: IconPosition) -> Self { + pub const fn icon_position(mut self, position: IconPosition) -> Self { self.icon_position = position; self } - pub fn icon_size(mut self, icon_size: IconSize) -> Self { + pub const fn icon_size(mut self, icon_size: IconSize) -> Self { self.icon_size = icon_size; self } - pub fn icon_color(mut self, icon_color: Color) -> Self { + pub const fn icon_color(mut self, icon_color: Color) -> Self { self.icon_color = Some(icon_color); self } - pub fn toggle(mut self, toggle_position: IconPosition, toggled: bool) -> Self { + pub const fn toggle(mut self, toggle_position: IconPosition, toggled: bool) -> Self { self.toggle = Some((toggle_position, toggled)); self } @@ -120,7 +120,7 @@ impl ContextMenuEntry { self } - pub fn disabled(mut self, disabled: bool) -> Self { + pub const fn disabled(mut self, disabled: bool) -> Self { self.disabled = disabled; self } @@ -584,7 +584,7 @@ impl ContextMenu { self } - pub fn keep_open_on_confirm(mut self, keep_open: bool) -> Self { + pub const fn keep_open_on_confirm(mut self, keep_open: bool) -> Self { self.keep_open_on_confirm = keep_open; self } @@ -602,7 +602,7 @@ impl ContextMenu { handler(None, window, cx); } - pub fn fixed_width(mut self, width: DefiniteLength) -> Self { + pub const fn fixed_width(mut self, width: DefiniteLength) -> Self { self.fixed_width = Some(width); self } @@ -658,7 +658,7 @@ impl ContextMenu { cx.notify(); } - pub fn clear_selected(&mut self) { + pub const fn clear_selected(&mut self) { self.selected_index = None; } diff --git a/crates/ui/src/components/data_table.rs b/crates/ui/src/components/data_table.rs index 4a1f4939cca2eb85bb7a549d06af1e9ea8cf04d0..5ffc9a5d47e282b06d7df8f05ca0efebfa880fb2 100644 --- a/crates/ui/src/components/data_table.rs +++ b/crates/ui/src/components/data_table.rs @@ -33,21 +33,21 @@ enum TableContents { } impl TableContents { - fn rows_mut(&mut self) -> Option<&mut Vec<[AnyElement; COLS]>> { + const fn rows_mut(&mut self) -> Option<&mut Vec<[AnyElement; COLS]>> { match self { TableContents::Vec(rows) => Some(rows), TableContents::UniformList(_) => None, } } - fn len(&self) -> usize { + const fn len(&self) -> usize { match self { TableContents::Vec(rows) => rows.len(), TableContents::UniformList(data) => data.row_count, } } - fn is_empty(&self) -> bool { + const fn is_empty(&self) -> bool { self.len() == 0 } } @@ -186,7 +186,7 @@ impl TableResizeBehavior { *self != TableResizeBehavior::None } - pub fn min_size(&self) -> Option { + pub const fn min_size(&self) -> Option { match self { TableResizeBehavior::None => None, TableResizeBehavior::Resizable => Some(0.05), @@ -523,7 +523,7 @@ impl Table { } /// Enables row striping. - pub fn striped(mut self) -> Self { + pub const fn striped(mut self) -> Self { self.striped = true; self } diff --git a/crates/ui/src/components/disclosure.rs b/crates/ui/src/components/disclosure.rs index 84282db2e332dc5d39cde2b3aae8d8d181a1024c..fd571cbba3892caeae7da0f5a8d614b24d2397f8 100644 --- a/crates/ui/src/components/disclosure.rs +++ b/crates/ui/src/components/disclosure.rs @@ -40,17 +40,17 @@ impl Disclosure { self } - pub fn opened_icon(mut self, icon: IconName) -> Self { + pub const fn opened_icon(mut self, icon: IconName) -> Self { self.opened_icon = icon; self } - pub fn closed_icon(mut self, icon: IconName) -> Self { + pub const fn closed_icon(mut self, icon: IconName) -> Self { self.closed_icon = icon; self } - pub fn disabled(mut self, disabled: bool) -> Self { + pub const fn disabled(mut self, disabled: bool) -> Self { self.disabled = disabled; self } diff --git a/crates/ui/src/components/divider.rs b/crates/ui/src/components/divider.rs index 98eb45fd1dc1845284d63952eac684790d73bec4..fdb24d32262924d35fcd4880effc0d706528df0c 100644 --- a/crates/ui/src/components/divider.rs +++ b/crates/ui/src/components/divider.rs @@ -105,12 +105,12 @@ impl Divider { } } - pub fn inset(mut self) -> Self { + pub const fn inset(mut self) -> Self { self.inset = true; self } - pub fn color(mut self, color: DividerColor) -> Self { + pub const fn color(mut self, color: DividerColor) -> Self { self.color = color; self } diff --git a/crates/ui/src/components/dropdown_menu.rs b/crates/ui/src/components/dropdown_menu.rs index 5b5de7a257ad22f099b8c2c4cc81aa83d2841976..0c26723757478302746c132a14c1ddcb046a6367 100644 --- a/crates/ui/src/components/dropdown_menu.rs +++ b/crates/ui/src/components/dropdown_menu.rs @@ -83,12 +83,12 @@ impl DropdownMenu { } } - pub fn style(mut self, style: DropdownStyle) -> Self { + pub const fn style(mut self, style: DropdownStyle) -> Self { self.style = style; self } - pub fn trigger_size(mut self, size: ButtonSize) -> Self { + pub const fn trigger_size(mut self, size: ButtonSize) -> Self { self.trigger_size = size; self } @@ -101,12 +101,12 @@ impl DropdownMenu { self } - pub fn trigger_icon(mut self, icon: IconName) -> Self { + pub const fn trigger_icon(mut self, icon: IconName) -> Self { self.trigger_icon = Some(icon); self } - pub fn full_width(mut self, full_width: bool) -> Self { + pub const fn full_width(mut self, full_width: bool) -> Self { self.full_width = full_width; self } @@ -117,23 +117,23 @@ impl DropdownMenu { } /// Defines which corner of the handle to attach the menu's anchor to. - pub fn attach(mut self, attach: Corner) -> Self { + pub const fn attach(mut self, attach: Corner) -> Self { self.attach = Some(attach); self } /// Offsets the position of the menu by that many pixels. - pub fn offset(mut self, offset: Point) -> Self { + pub const fn offset(mut self, offset: Point) -> Self { self.offset = Some(offset); self } - pub fn tab_index(mut self, arg: isize) -> Self { + pub const fn tab_index(mut self, arg: isize) -> Self { self.tab_index = Some(arg); self } - pub fn no_chevron(mut self) -> Self { + pub const fn no_chevron(mut self) -> Self { self.chevron = false; self } diff --git a/crates/ui/src/components/icon.rs b/crates/ui/src/components/icon.rs index d7fadbd962a97c83d31438f43e800f9a4ff8c777..a0bf5ec6d1dc65d40e2d18dbf9b471d9712e6607 100644 --- a/crates/ui/src/components/icon.rs +++ b/crates/ui/src/components/icon.rs @@ -164,7 +164,7 @@ impl Icon { } } - pub fn color(mut self, color: Color) -> Self { + pub const fn color(mut self, color: Color) -> Self { self.color = color; self } @@ -177,7 +177,7 @@ impl Icon { /// Sets a custom size for the icon, in [`Rems`]. /// /// Not to be exposed outside of the `ui` crate. - pub(crate) fn custom_size(mut self, size: Rems) -> Self { + pub(crate) const fn custom_size(mut self, size: Rems) -> Self { self.size = size; self } @@ -217,7 +217,7 @@ pub struct IconWithIndicator { } impl IconWithIndicator { - pub fn new(icon: Icon, indicator: Option) -> Self { + pub const fn new(icon: Icon, indicator: Option) -> Self { Self { icon, indicator, @@ -230,14 +230,14 @@ impl IconWithIndicator { self } - pub fn indicator_color(mut self, color: Color) -> Self { + pub const fn indicator_color(mut self, color: Color) -> Self { if let Some(indicator) = self.indicator.as_mut() { indicator.color = color; } self } - pub fn indicator_border_color(mut self, color: Option) -> Self { + pub const fn indicator_border_color(mut self, color: Option) -> Self { self.indicator_border_color = color; self } diff --git a/crates/ui/src/components/icon/decorated_icon.rs b/crates/ui/src/components/icon/decorated_icon.rs index 82ca844c384b5ae6125988762a061a5d4b21187c..1a23fb747872d89fc4a9e68dc640fbb9477a3e32 100644 --- a/crates/ui/src/components/icon/decorated_icon.rs +++ b/crates/ui/src/components/icon/decorated_icon.rs @@ -9,7 +9,7 @@ pub struct DecoratedIcon { } impl DecoratedIcon { - pub fn new(icon: Icon, decoration: Option) -> Self { + pub const fn new(icon: Icon, decoration: Option) -> Self { Self { icon, decoration } } } diff --git a/crates/ui/src/components/icon/icon_decoration.rs b/crates/ui/src/components/icon/icon_decoration.rs index 9f84a8bcf4eb10672161ed2733d7ed5baa95f899..edd415d2393c26f9a9a914db62ec4a684a40e7b9 100644 --- a/crates/ui/src/components/icon/icon_decoration.rs +++ b/crates/ui/src/components/icon/icon_decoration.rs @@ -36,7 +36,7 @@ pub enum IconDecorationKind { } impl IconDecorationKind { - fn fg(&self) -> KnockoutIconName { + const fn fg(&self) -> KnockoutIconName { match self { Self::X => KnockoutIconName::XFg, Self::Dot => KnockoutIconName::DotFg, @@ -44,7 +44,7 @@ impl IconDecorationKind { } } - fn bg(&self) -> KnockoutIconName { + const fn bg(&self) -> KnockoutIconName { match self { Self::X => KnockoutIconName::XBg, Self::Dot => KnockoutIconName::DotBg, @@ -84,13 +84,13 @@ impl IconDecoration { } /// Sets the kind of decoration. - pub fn kind(mut self, kind: IconDecorationKind) -> Self { + pub const fn kind(mut self, kind: IconDecorationKind) -> Self { self.kind = kind; self } /// Sets the color of the decoration. - pub fn color(mut self, color: Hsla) -> Self { + pub const fn color(mut self, color: Hsla) -> Self { self.color = color; self } @@ -99,19 +99,19 @@ impl IconDecoration { /// /// Match this to the background of the element the icon will be rendered /// on. - pub fn knockout_color(mut self, color: Hsla) -> Self { + pub const fn knockout_color(mut self, color: Hsla) -> Self { self.knockout_color = color; self } /// Sets the color of the decoration that is used on hover. - pub fn knockout_hover_color(mut self, color: Hsla) -> Self { + pub const fn knockout_hover_color(mut self, color: Hsla) -> Self { self.knockout_hover_color = color; self } /// Sets the position of the decoration. - pub fn position(mut self, position: Point) -> Self { + pub const fn position(mut self, position: Point) -> Self { self.position = position; self } diff --git a/crates/ui/src/components/image.rs b/crates/ui/src/components/image.rs index 8a14cffd3b2de2e184fd87a9212775c470e3118d..4cf4ae260caa85e459531251b3ed03fb72324db4 100644 --- a/crates/ui/src/components/image.rs +++ b/crates/ui/src/components/image.rs @@ -64,7 +64,7 @@ impl Vector { } /// Sets the vector color. - pub fn color(mut self, color: Color) -> Self { + pub const fn color(mut self, color: Color) -> Self { self.color = color; self } diff --git a/crates/ui/src/components/indicator.rs b/crates/ui/src/components/indicator.rs index 59d69a068b3955c6218950b69ab2e8db88e48a04..dc9c3770a0bc3007fc70bcde6d42e80db2249560 100644 --- a/crates/ui/src/components/indicator.rs +++ b/crates/ui/src/components/indicator.rs @@ -17,7 +17,7 @@ pub struct Indicator { } impl Indicator { - pub fn dot() -> Self { + pub const fn dot() -> Self { Self { kind: IndicatorKind::Dot, border_color: None, @@ -25,7 +25,7 @@ impl Indicator { } } - pub fn bar() -> Self { + pub const fn bar() -> Self { Self { kind: IndicatorKind::Bar, border_color: None, @@ -43,12 +43,12 @@ impl Indicator { } } - pub fn color(mut self, color: Color) -> Self { + pub const fn color(mut self, color: Color) -> Self { self.color = color; self } - pub fn border_color(mut self, color: Color) -> Self { + pub const fn border_color(mut self, color: Color) -> Self { self.border_color = Some(color); self } diff --git a/crates/ui/src/components/keybinding.rs b/crates/ui/src/components/keybinding.rs index f8ac85528ec3317bb003d3f8763f8c57a7d4bba2..0496acee5067c57e0d9e13ddabf4a492cd62c50f 100644 --- a/crates/ui/src/components/keybinding.rs +++ b/crates/ui/src/components/keybinding.rs @@ -74,7 +74,7 @@ impl KeyBinding { } /// Sets the [`PlatformStyle`] for this [`KeyBinding`]. - pub fn platform_style(mut self, platform_style: PlatformStyle) -> Self { + pub const fn platform_style(mut self, platform_style: PlatformStyle) -> Self { self.platform_style = platform_style; self } @@ -87,12 +87,12 @@ impl KeyBinding { /// Sets whether this keybinding is currently disabled. /// Disabled keybinds will be rendered in a dimmed state. - pub fn disabled(mut self, disabled: bool) -> Self { + pub const fn disabled(mut self, disabled: bool) -> Self { self.disabled = disabled; self } - pub fn vim_mode(mut self, enabled: bool) -> Self { + pub const fn vim_mode(mut self, enabled: bool) -> Self { self.vim_mode = enabled; self } @@ -370,7 +370,7 @@ impl RenderOnce for KeyIcon { } impl KeyIcon { - pub fn new(icon: IconName, color: Option) -> Self { + pub const fn new(icon: IconName, color: Option) -> Self { Self { icon, color, diff --git a/crates/ui/src/components/keybinding_hint.rs b/crates/ui/src/components/keybinding_hint.rs index 58f2793ea0ee29b55eace9e7fe9e53c606ca0a43..b410db51d691bdc7d0340946a915ecfa9e7fbe0b 100644 --- a/crates/ui/src/components/keybinding_hint.rs +++ b/crates/ui/src/components/keybinding_hint.rs @@ -53,7 +53,7 @@ impl KeybindingHint { /// ); /// # } /// ``` - pub fn new(keybinding: KeyBinding, background_color: Hsla) -> Self { + pub const fn new(keybinding: KeyBinding, background_color: Hsla) -> Self { Self { prefix: None, suffix: None, diff --git a/crates/ui/src/components/label/spinner_label.rs b/crates/ui/src/components/label/spinner_label.rs index b7b65fbcc98c175e4407d72c3e07df236364f552..0d9dee74c86c719c6a6c8634a932d3eab9c3b736 100644 --- a/crates/ui/src/components/label/spinner_label.rs +++ b/crates/ui/src/components/label/spinner_label.rs @@ -44,14 +44,14 @@ impl SpinnerVariant { } } - fn duration(&self) -> Duration { + const fn duration(&self) -> Duration { match self { SpinnerVariant::Dots => Duration::from_millis(1000), SpinnerVariant::DotsVariant => Duration::from_millis(1000), } } - fn animation_id(&self) -> &'static str { + const fn animation_id(&self) -> &'static str { match self { SpinnerVariant::Dots => "spinner_label_dots", SpinnerVariant::DotsVariant => "spinner_label_dots_variant", diff --git a/crates/ui/src/components/list/list_header.rs b/crates/ui/src/components/list/list_header.rs index d59af07fa5271c070fca8433156b94301cc134aa..e8d6f9da9f4df956f1a1733861c8422d0cf5e684 100644 --- a/crates/ui/src/components/list/list_header.rs +++ b/crates/ui/src/components/list/list_header.rs @@ -65,7 +65,7 @@ impl ListHeader { self } - pub fn inset(mut self, inset: bool) -> Self { + pub const fn inset(mut self, inset: bool) -> Self { self.inset = inset; self } diff --git a/crates/ui/src/components/list/list_item.rs b/crates/ui/src/components/list/list_item.rs index a58291438a1d10bb1b61149f412151375b6b0a1f..dd2dadf263a2c42b5f3313f72927d112ca2666a4 100644 --- a/crates/ui/src/components/list/list_item.rs +++ b/crates/ui/src/components/list/list_item.rs @@ -81,17 +81,17 @@ impl ListItem { self } - pub fn spacing(mut self, spacing: ListItemSpacing) -> Self { + pub const fn spacing(mut self, spacing: ListItemSpacing) -> Self { self.spacing = spacing; self } - pub fn selectable(mut self, has_hover: bool) -> Self { + pub const fn selectable(mut self, has_hover: bool) -> Self { self.selectable = has_hover; self } - pub fn always_show_disclosure_icon(mut self, show: bool) -> Self { + pub const fn always_show_disclosure_icon(mut self, show: bool) -> Self { self.always_show_disclosure_icon = show; self } @@ -122,17 +122,17 @@ impl ListItem { self } - pub fn inset(mut self, inset: bool) -> Self { + pub const fn inset(mut self, inset: bool) -> Self { self.inset = inset; self } - pub fn indent_level(mut self, indent_level: usize) -> Self { + pub const fn indent_level(mut self, indent_level: usize) -> Self { self.indent_level = indent_level; self } - pub fn indent_step_size(mut self, indent_step_size: Pixels) -> Self { + pub const fn indent_step_size(mut self, indent_step_size: Pixels) -> Self { self.indent_step_size = indent_step_size; self } @@ -165,22 +165,22 @@ impl ListItem { self } - pub fn outlined(mut self) -> Self { + pub const fn outlined(mut self) -> Self { self.outlined = true; self } - pub fn rounded(mut self) -> Self { + pub const fn rounded(mut self) -> Self { self.rounded = true; self } - pub fn overflow_x(mut self) -> Self { + pub const fn overflow_x(mut self) -> Self { self.overflow_x = true; self } - pub fn focused(mut self, focused: bool) -> Self { + pub const fn focused(mut self, focused: bool) -> Self { self.focused = Some(focused); self } diff --git a/crates/ui/src/components/list/list_sub_header.rs b/crates/ui/src/components/list/list_sub_header.rs index e6f5abfe0ab5ee4f7e10a85c3d2b15402df8fc53..a32147b3f609a2790e94c340998824704fc9fc1f 100644 --- a/crates/ui/src/components/list/list_sub_header.rs +++ b/crates/ui/src/components/list/list_sub_header.rs @@ -21,7 +21,7 @@ impl ListSubHeader { } } - pub fn left_icon(mut self, left_icon: Option) -> Self { + pub const fn left_icon(mut self, left_icon: Option) -> Self { self.start_slot = left_icon; self } @@ -31,7 +31,7 @@ impl ListSubHeader { self } - pub fn inset(mut self, inset: bool) -> Self { + pub const fn inset(mut self, inset: bool) -> Self { self.inset = inset; self } diff --git a/crates/ui/src/components/modal.rs b/crates/ui/src/components/modal.rs index a70f5e1ea5a53a043086f3e102878f3614990d6e..5a0df47d6459beecf7f371ad0b68aabe10990f5c 100644 --- a/crates/ui/src/components/modal.rs +++ b/crates/ui/src/components/modal.rs @@ -46,12 +46,12 @@ impl Modal { self } - pub fn show_dismiss(mut self, show: bool) -> Self { + pub const fn show_dismiss(mut self, show: bool) -> Self { self.header.show_dismiss_button = show; self } - pub fn show_back(mut self, show: bool) -> Self { + pub const fn show_back(mut self, show: bool) -> Self { self.header.show_back_button = show; self } @@ -137,12 +137,12 @@ impl ModalHeader { self } - pub fn show_dismiss_button(mut self, show: bool) -> Self { + pub const fn show_dismiss_button(mut self, show: bool) -> Self { self.show_dismiss_button = show; self } - pub fn show_back_button(mut self, show: bool) -> Self { + pub const fn show_back_button(mut self, show: bool) -> Self { self.show_back_button = show; self } @@ -254,7 +254,7 @@ impl Default for ModalFooter { } impl ModalFooter { - pub fn new() -> Self { + pub const fn new() -> Self { Self { start_slot: None, end_slot: None, @@ -324,7 +324,7 @@ impl Section { } } - pub fn contained(mut self, contained: bool) -> Self { + pub const fn contained(mut self, contained: bool) -> Self { self.contained = contained; self } @@ -338,7 +338,7 @@ impl Section { self.meta = Some(meta.into()); self } - pub fn padded(mut self, padded: bool) -> Self { + pub const fn padded(mut self, padded: bool) -> Self { self.padded = padded; self } diff --git a/crates/ui/src/components/navigable.rs b/crates/ui/src/components/navigable.rs index a592bcc36f4cc490c4676a83660ace050025ee39..c2ea723cd8c150b3e66fcfd094416f2a2c1ad984 100644 --- a/crates/ui/src/components/navigable.rs +++ b/crates/ui/src/components/navigable.rs @@ -35,7 +35,7 @@ impl NavigableEntry { } impl Navigable { /// Creates new empty [Navigable] wrapper. - pub fn new(child: AnyElement) -> Self { + pub const fn new(child: AnyElement) -> Self { Self { child, selectable_children: vec![], diff --git a/crates/ui/src/components/popover_menu.rs b/crates/ui/src/components/popover_menu.rs index 439b53f0388114aa37adcf5277e87744e6f4f9e4..74aa901d8adb6bf4018b17ee12fd0f6a06fc514a 100644 --- a/crates/ui/src/components/popover_menu.rs +++ b/crates/ui/src/components/popover_menu.rs @@ -161,7 +161,7 @@ impl PopoverMenu { } } - pub fn full_width(mut self, full_width: bool) -> Self { + pub const fn full_width(mut self, full_width: bool) -> Self { self.full_width = full_width; self } @@ -219,19 +219,19 @@ impl PopoverMenu { /// Defines which corner of the menu to anchor to the attachment point. /// By default, it uses the cursor position. Also see the `attach` method. - pub fn anchor(mut self, anchor: Corner) -> Self { + pub const fn anchor(mut self, anchor: Corner) -> Self { self.anchor = anchor; self } /// Defines which corner of the handle to attach the menu's anchor to. - pub fn attach(mut self, attach: Corner) -> Self { + pub const fn attach(mut self, attach: Corner) -> Self { self.attach = Some(attach); self } /// Offsets the position of the content by that many pixels. - pub fn offset(mut self, offset: Point) -> Self { + pub const fn offset(mut self, offset: Point) -> Self { self.offset = Some(offset); self } diff --git a/crates/ui/src/components/progress/progress_bar.rs b/crates/ui/src/components/progress/progress_bar.rs index 5cc5abd36d041bc03676410983020b94ac8d8809..8b1b078ddced9f32a43c606cfaf0dc43a90024b5 100644 --- a/crates/ui/src/components/progress/progress_bar.rs +++ b/crates/ui/src/components/progress/progress_bar.rs @@ -30,31 +30,31 @@ impl ProgressBar { } /// Sets the current value of the progress bar. - pub fn value(mut self, value: f32) -> Self { + pub const fn value(mut self, value: f32) -> Self { self.value = value; self } /// Sets the maximum value of the progress bar. - pub fn max_value(mut self, max_value: f32) -> Self { + pub const fn max_value(mut self, max_value: f32) -> Self { self.max_value = max_value; self } /// Sets the background color of the progress bar. - pub fn bg_color(mut self, color: Hsla) -> Self { + pub const fn bg_color(mut self, color: Hsla) -> Self { self.bg_color = color; self } /// Sets the foreground color of the progress bar. - pub fn fg_color(mut self, color: Hsla) -> Self { + pub const fn fg_color(mut self, color: Hsla) -> Self { self.fg_color = color; self } /// Sets the over limit color of the progress bar. - pub fn over_color(mut self, color: Hsla) -> Self { + pub const fn over_color(mut self, color: Hsla) -> Self { self.over_color = color; self } diff --git a/crates/ui/src/components/right_click_menu.rs b/crates/ui/src/components/right_click_menu.rs index 761189671b935bf1f3d9e3f7d4d547528cf20196..e11dcf65e9a679b8dd2e9bb9a72b6bc610ad3063 100644 --- a/crates/ui/src/components/right_click_menu.rs +++ b/crates/ui/src/components/right_click_menu.rs @@ -34,13 +34,13 @@ impl RightClickMenu { /// anchor defines which corner of the menu to anchor to the attachment point /// (by default the cursor position, but see attach) - pub fn anchor(mut self, anchor: Corner) -> Self { + pub const fn anchor(mut self, anchor: Corner) -> Self { self.anchor = Some(anchor); self } /// attach defines which corner of the handle to attach the menu's anchor to - pub fn attach(mut self, attach: Corner) -> Self { + pub const fn attach(mut self, attach: Corner) -> Self { self.attach = Some(attach); self } diff --git a/crates/ui/src/components/scrollbar.rs b/crates/ui/src/components/scrollbar.rs index bfcaa93eb41f22c36d106273f6da98da38981f62..b9de0d8070c45c255c1519cbe3121848b5e07f32 100644 --- a/crates/ui/src/components/scrollbar.rs +++ b/crates/ui/src/components/scrollbar.rs @@ -83,7 +83,7 @@ pub mod scrollbars { pub struct ScrollbarAutoHide(pub bool); impl ScrollbarAutoHide { - pub fn should_hide(&self) -> bool { + pub const fn should_hide(&self) -> bool { self.0 } } @@ -342,11 +342,11 @@ impl ReservedSpace { *self != ReservedSpace::None } - fn needs_scroll_track(&self) -> bool { + const fn needs_scroll_track(&self) -> bool { matches!(self, ReservedSpace::Track(_)) } - fn track_color(&self) -> Option { + const fn track_color(&self) -> Option { match self { ReservedSpace::Track(color) => Some(*color), _ => None, @@ -363,7 +363,7 @@ enum ScrollbarWidth { } impl ScrollbarWidth { - fn to_pixels(&self) -> Pixels { + const fn to_pixels(&self) -> Pixels { match self { ScrollbarWidth::Normal => px(8.), ScrollbarWidth::Small => px(6.), @@ -425,13 +425,13 @@ impl Scrollbars { } /// Notify the current context whenever this scrollbar gets a scroll event - pub fn notify_content(mut self) -> Self { + pub const fn notify_content(mut self) -> Self { self.tracked_entity = Some(None); self } /// Set a parent model which should be notified whenever this scrollbar gets a scroll event. - pub fn tracked_entity(mut self, entity_id: EntityId) -> Self { + pub const fn tracked_entity(mut self, entity_id: EntityId) -> Self { self.tracked_entity = Some(Some(entity_id)); self } @@ -469,12 +469,12 @@ impl Scrollbars { self } - pub fn width_sm(mut self) -> Self { + pub const fn width_sm(mut self) -> Self { self.scrollbar_width = ScrollbarWidth::Small; self } - pub fn width_xs(mut self) -> Self { + pub const fn width_xs(mut self) -> Self { self.scrollbar_width = ScrollbarWidth::XSmall; self } @@ -513,7 +513,7 @@ impl VisibilityState { } } - fn is_visible(&self) -> bool { + const fn is_visible(&self) -> bool { matches!(self, Self::Visible | Self::Animating { .. }) } @@ -522,7 +522,7 @@ impl VisibilityState { *self == VisibilityState::Disabled } - fn animation_progress(&self) -> Option<(f32, Duration, bool)> { + const fn animation_progress(&self) -> Option<(f32, Duration, bool)> { match self { Self::Animating { showing, delta } => Some(( *delta, @@ -690,7 +690,7 @@ impl ScrollbarState { } #[inline] - fn visible_axes(&self) -> Option { + const fn visible_axes(&self) -> Option { match (&self.visibility.x, &self.visibility.y) { (ReservedSpace::None, ReservedSpace::None) => None, (ReservedSpace::None, _) => Some(ScrollAxes::Vertical), @@ -721,7 +721,7 @@ impl ScrollbarState { .flatten() } - fn scroll_handle(&self) -> &T { + const fn scroll_handle(&self) -> &T { &self.scroll_handle } @@ -731,7 +731,7 @@ impl ScrollbarState { cx.notify(); } - fn is_dragging(&self) -> bool { + const fn is_dragging(&self) -> bool { self.thumb_state.is_dragging() } @@ -850,7 +850,7 @@ impl ScrollbarState { }) } - fn visible(&self) -> bool { + const fn visible(&self) -> bool { self.show_state.is_visible() } @@ -889,7 +889,7 @@ enum ThumbState { } impl ThumbState { - fn is_dragging(&self) -> bool { + const fn is_dragging(&self) -> bool { matches!(*self, ThumbState::Dragging(..)) } } diff --git a/crates/ui/src/components/tab.rs b/crates/ui/src/components/tab.rs index e6823f46b750488d2903265ef0bda4d4862d8a8f..bb0d5bb4648d77231cfe02342aedc299f08f321a 100644 --- a/crates/ui/src/components/tab.rs +++ b/crates/ui/src/components/tab.rs @@ -56,12 +56,12 @@ impl Tab { } } - pub fn position(mut self, position: TabPosition) -> Self { + pub const fn position(mut self, position: TabPosition) -> Self { self.position = position; self } - pub fn close_side(mut self, close_side: TabCloseSide) -> Self { + pub const fn close_side(mut self, close_side: TabCloseSide) -> Self { self.close_side = close_side; self } diff --git a/crates/ui/src/components/tab_bar.rs b/crates/ui/src/components/tab_bar.rs index 3c467c06ce2654c5886c30e42dfb7276fdb7d289..07772da6128c287e4b30fa2ff410c9db35e9d206 100644 --- a/crates/ui/src/components/tab_bar.rs +++ b/crates/ui/src/components/tab_bar.rs @@ -29,7 +29,7 @@ impl TabBar { self } - pub fn start_children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]> { + pub const fn start_children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]> { &mut self.start_children } @@ -57,7 +57,7 @@ impl TabBar { self } - pub fn end_children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]> { + pub const fn end_children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]> { &mut self.end_children } diff --git a/crates/ui/src/components/toggle.rs b/crates/ui/src/components/toggle.rs index 8d582c11e77f4469bb959ec656c9d6800603a72e..bbd1580e89205bf8c3f32d6eb62579deced81a96 100644 --- a/crates/ui/src/components/toggle.rs +++ b/crates/ui/src/components/toggle.rs @@ -69,13 +69,13 @@ impl Checkbox { } /// Sets the disabled state of the [`Checkbox`]. - pub fn disabled(mut self, disabled: bool) -> Self { + pub const fn disabled(mut self, disabled: bool) -> Self { self.disabled = disabled; self } /// Sets the disabled state of the [`Checkbox`]. - pub fn placeholder(mut self, placeholder: bool) -> Self { + pub const fn placeholder(mut self, placeholder: bool) -> Self { self.placeholder = placeholder; self } @@ -100,19 +100,19 @@ impl Checkbox { } /// Sets the `fill` setting of the checkbox, indicating whether it should be filled. - pub fn fill(mut self) -> Self { + pub const fn fill(mut self) -> Self { self.filled = true; self } /// Sets the style of the checkbox using the specified [`ToggleStyle`]. - pub fn style(mut self, style: ToggleStyle) -> Self { + pub const fn style(mut self, style: ToggleStyle) -> Self { self.style = style; self } /// Match the style of the checkbox to the current elevation using [`ToggleStyle::ElevationBased`]. - pub fn elevation(mut self, elevation: ElevationIndex) -> Self { + pub const fn elevation(mut self, elevation: ElevationIndex) -> Self { self.style = ToggleStyle::ElevationBased(elevation); self } @@ -156,7 +156,7 @@ impl Checkbox { } /// container size - pub fn container_size() -> Pixels { + pub const fn container_size() -> Pixels { px(20.0) } } @@ -286,24 +286,24 @@ impl CheckboxWithLabel { } /// Sets the style of the checkbox using the specified [`ToggleStyle`]. - pub fn style(mut self, style: ToggleStyle) -> Self { + pub const fn style(mut self, style: ToggleStyle) -> Self { self.style = style; self } /// Match the style of the checkbox to the current elevation using [`ToggleStyle::ElevationBased`]. - pub fn elevation(mut self, elevation: ElevationIndex) -> Self { + pub const fn elevation(mut self, elevation: ElevationIndex) -> Self { self.style = ToggleStyle::ElevationBased(elevation); self } /// Sets the `fill` setting of the checkbox, indicating whether it should be filled. - pub fn fill(mut self) -> Self { + pub const fn fill(mut self) -> Self { self.filled = true; self } - pub fn checkbox_position(mut self, position: IconPosition) -> Self { + pub const fn checkbox_position(mut self, position: IconPosition) -> Self { self.checkbox_position = position; self } @@ -443,13 +443,13 @@ impl Switch { } /// Sets the color of the switch using the specified [`SwitchColor`]. - pub fn color(mut self, color: SwitchColor) -> Self { + pub const fn color(mut self, color: SwitchColor) -> Self { self.color = color; self } /// Sets the disabled state of the [`Switch`]. - pub fn disabled(mut self, disabled: bool) -> Self { + pub const fn disabled(mut self, disabled: bool) -> Self { self.disabled = disabled; self } @@ -632,14 +632,14 @@ impl SwitchField { self } - pub fn disabled(mut self, disabled: bool) -> Self { + pub const fn disabled(mut self, disabled: bool) -> Self { self.disabled = disabled; self } /// Sets the color of the switch using the specified [`SwitchColor`]. /// This changes the color scheme of the switch when it's in the "on" state. - pub fn color(mut self, color: SwitchColor) -> Self { + pub const fn color(mut self, color: SwitchColor) -> Self { self.color = color; self } @@ -649,7 +649,7 @@ impl SwitchField { self } - pub fn tab_index(mut self, tab_index: isize) -> Self { + pub const fn tab_index(mut self, tab_index: isize) -> Self { self.tab_index = Some(tab_index); self } diff --git a/crates/ui/src/components/tree_view_item.rs b/crates/ui/src/components/tree_view_item.rs index 8647b13a65dee64fd825c814303815241547cd75..fe99121ee7054e0c32c6d94f8cd622136b6c0d96 100644 --- a/crates/ui/src/components/tree_view_item.rs +++ b/crates/ui/src/components/tree_view_item.rs @@ -77,17 +77,17 @@ impl TreeViewItem { self } - pub fn tab_index(mut self, tab_index: isize) -> Self { + pub const fn tab_index(mut self, tab_index: isize) -> Self { self.tab_index = Some(tab_index); self } - pub fn expanded(mut self, toggle: bool) -> Self { + pub const fn expanded(mut self, toggle: bool) -> Self { self.expanded = toggle; self } - pub fn default_expanded(mut self, default_expanded: bool) -> Self { + pub const fn default_expanded(mut self, default_expanded: bool) -> Self { self.default_expanded = default_expanded; self } @@ -100,12 +100,12 @@ impl TreeViewItem { self } - pub fn root_item(mut self, root_item: bool) -> Self { + pub const fn root_item(mut self, root_item: bool) -> Self { self.root_item = root_item; self } - pub fn focused(mut self, focused: bool) -> Self { + pub const fn focused(mut self, focused: bool) -> Self { self.focused = focused; self } diff --git a/crates/ui/src/styles/animation.rs b/crates/ui/src/styles/animation.rs index acea834548675b3a896a03da731a7eb4fae777e4..497516ddec2558ff4165a28c42a191d2e8eed565 100644 --- a/crates/ui/src/styles/animation.rs +++ b/crates/ui/src/styles/animation.rs @@ -12,7 +12,7 @@ pub enum AnimationDuration { } impl AnimationDuration { - pub fn duration(&self) -> Duration { + pub const fn duration(&self) -> Duration { Duration::from_millis(*self as u64) } } diff --git a/crates/ui/src/styles/typography.rs b/crates/ui/src/styles/typography.rs index 0d7d5af9e74f11f7d77c9d03362f6be41dc9b2ec..0fea3de319cb1f55692a9392ce77d4ddbaca800a 100644 --- a/crates/ui/src/styles/typography.rs +++ b/crates/ui/src/styles/typography.rs @@ -166,7 +166,7 @@ pub enum HeadlineSize { impl HeadlineSize { /// Returns the headline size in rems. - pub fn rems(self) -> Rems { + pub const fn rems(self) -> Rems { match self { Self::XSmall => rems(0.88), Self::Small => rems(1.0), @@ -177,7 +177,7 @@ impl HeadlineSize { } /// Returns the line height for the headline size. - pub fn line_height(self) -> Rems { + pub const fn line_height(self) -> Rems { match self { Self::XSmall => rems(1.6), Self::Small => rems(1.6), @@ -221,13 +221,13 @@ impl Headline { } /// Set the size of the headline. - pub fn size(mut self, size: HeadlineSize) -> Self { + pub const fn size(mut self, size: HeadlineSize) -> Self { self.size = size; self } /// Set the color of the headline. - pub fn color(mut self, color: Color) -> Self { + pub const fn color(mut self, color: Color) -> Self { self.color = color; self } diff --git a/crates/ui/src/traits/toggleable.rs b/crates/ui/src/traits/toggleable.rs index f731f9965e9c18f6e60cfadf986c68f2f9a3f122..4de997ec34227f1495126896f087ef702f7de7e9 100644 --- a/crates/ui/src/traits/toggleable.rs +++ b/crates/ui/src/traits/toggleable.rs @@ -23,7 +23,7 @@ impl ToggleState { /// Returns the inverse of the current selection status. /// /// Indeterminate states become selected if inverted. - pub fn inverse(&self) -> Self { + pub const fn inverse(&self) -> Self { match self { Self::Unselected | Self::Indeterminate => Self::Selected, Self::Selected => Self::Unselected, @@ -31,7 +31,7 @@ impl ToggleState { } /// Creates a `ToggleState` from the given `any_checked` and `all_checked` flags. - pub fn from_any_and_all(any_checked: bool, all_checked: bool) -> Self { + pub const fn from_any_and_all(any_checked: bool, all_checked: bool) -> Self { match (any_checked, all_checked) { (true, true) => Self::Selected, (false, false) => Self::Unselected, @@ -40,7 +40,7 @@ impl ToggleState { } /// Returns whether this toggle state is selected - pub fn selected(&self) -> bool { + pub const fn selected(&self) -> bool { match self { ToggleState::Indeterminate | ToggleState::Unselected => false, ToggleState::Selected => true, diff --git a/crates/ui/src/utils/corner_solver.rs b/crates/ui/src/utils/corner_solver.rs index c49bccc44509d644650260819848aa92667964d5..809823b0f08675e00aea20885fbe5c1ab1068034 100644 --- a/crates/ui/src/utils/corner_solver.rs +++ b/crates/ui/src/utils/corner_solver.rs @@ -30,7 +30,7 @@ pub struct CornerSolver { } impl CornerSolver { - pub fn new(root_radius: Pixels, root_border: Pixels, root_padding: Pixels) -> Self { + pub const fn new(root_radius: Pixels, root_border: Pixels, root_padding: Pixels) -> Self { Self { root_radius, root_border, diff --git a/crates/ui/src/utils/format_distance.rs b/crates/ui/src/utils/format_distance.rs index 6ec497edee2a971e59faa1f6e99d589b9b27d864..9cf1370e1f81b41c0b52f2c82db7b7cf9624e7a3 100644 --- a/crates/ui/src/utils/format_distance.rs +++ b/crates/ui/src/utils/format_distance.rs @@ -30,7 +30,7 @@ pub struct FormatDistance { } impl FormatDistance { - pub fn new(date: DateTimeType, base_date: DateTimeType) -> Self { + pub const fn new(date: DateTimeType, base_date: DateTimeType) -> Self { Self { date, base_date, @@ -44,17 +44,17 @@ impl FormatDistance { Self::new(date, DateTimeType::Local(Local::now())) } - pub fn include_seconds(mut self, include_seconds: bool) -> Self { + pub const fn include_seconds(mut self, include_seconds: bool) -> Self { self.include_seconds = include_seconds; self } - pub fn add_suffix(mut self, add_suffix: bool) -> Self { + pub const fn add_suffix(mut self, add_suffix: bool) -> Self { self.add_suffix = add_suffix; self } - pub fn hide_prefix(mut self, hide_prefix: bool) -> Self { + pub const fn hide_prefix(mut self, hide_prefix: bool) -> Self { self.hide_prefix = hide_prefix; self } @@ -82,7 +82,7 @@ impl std::fmt::Display for FormatDistance { /// /// * `date` - A [NaiveDateTime`] object representing the date of interest /// * `base_date` - A [NaiveDateTime`] object representing the base date against which the comparison is made -fn distance_in_seconds(date: NaiveDateTime, base_date: NaiveDateTime) -> i64 { +const fn distance_in_seconds(date: NaiveDateTime, base_date: NaiveDateTime) -> i64 { let duration = date.signed_duration_since(base_date); -duration.num_seconds() } diff --git a/crates/ui_input/src/number_field.rs b/crates/ui_input/src/number_field.rs index b72566947771be6411ce879a48092f508909b18f..af166ad0f738a07db879a4798bc386ee1365b0c9 100644 --- a/crates/ui_input/src/number_field.rs +++ b/crates/ui_input/src/number_field.rs @@ -297,27 +297,27 @@ impl NumberField { self } - pub fn small_step(mut self, step: T) -> Self { + pub const fn small_step(mut self, step: T) -> Self { self.small_step = step; self } - pub fn normal_step(mut self, step: T) -> Self { + pub const fn normal_step(mut self, step: T) -> Self { self.step = step; self } - pub fn large_step(mut self, step: T) -> Self { + pub const fn large_step(mut self, step: T) -> Self { self.large_step = step; self } - pub fn min(mut self, min: T) -> Self { + pub const fn min(mut self, min: T) -> Self { self.min_value = min; self } - pub fn max(mut self, max: T) -> Self { + pub const fn max(mut self, max: T) -> Self { self.max_value = max; self } @@ -330,7 +330,7 @@ impl NumberField { self } - pub fn tab_index(mut self, tab_index: isize) -> Self { + pub const fn tab_index(mut self, tab_index: isize) -> Self { self.tab_index = Some(tab_index); self } diff --git a/crates/ui_input/src/ui_input.rs b/crates/ui_input/src/ui_input.rs index 56f0626f0a502c2bbf5471491441f69e7820e86e..10c87001546cf128dff6aae10d19d147f3188725 100644 --- a/crates/ui_input/src/ui_input.rs +++ b/crates/ui_input/src/ui_input.rs @@ -77,7 +77,7 @@ impl SingleLineInput { } } - pub fn start_icon(mut self, icon: IconName) -> Self { + pub const fn start_icon(mut self, icon: IconName) -> Self { self.start_icon = Some(icon); self } @@ -87,7 +87,7 @@ impl SingleLineInput { self } - pub fn label_size(mut self, size: LabelSize) -> Self { + pub const fn label_size(mut self, size: LabelSize) -> Self { self.label_size = size; self } @@ -107,7 +107,7 @@ impl SingleLineInput { self.editor().read(cx).text(cx).trim().is_empty() } - pub fn editor(&self) -> &Entity { + pub const fn editor(&self) -> &Entity { &self.editor } diff --git a/crates/util/src/paths.rs b/crates/util/src/paths.rs index 59efaff200ce98fd2150932b24492e42a07fa265..94f38facc1cdf0176bf67a64cd26bb30fc4a1893 100644 --- a/crates/util/src/paths.rs +++ b/crates/util/src/paths.rs @@ -258,7 +258,7 @@ impl SanitizedPath { self.0.starts_with(&prefix.0) } - pub fn as_path(&self) -> &Path { + pub const fn as_path(&self) -> &Path { &self.0 } @@ -341,7 +341,7 @@ impl PathStyle { } #[inline] - pub fn separator(&self) -> &'static str { + pub const fn separator(&self) -> &'static str { match self { PathStyle::Posix => "/", PathStyle::Windows => "\\", @@ -391,7 +391,7 @@ pub struct RemotePathBuf { } impl RemotePathBuf { - pub fn new(string: String, style: PathStyle) -> Self { + pub const fn new(string: String, style: PathStyle) -> Self { Self { style, string } } @@ -399,7 +399,7 @@ impl RemotePathBuf { Self::new(path.to_string(), style) } - pub fn path_style(&self) -> PathStyle { + pub const fn path_style(&self) -> PathStyle { self.style } @@ -539,7 +539,7 @@ pub struct PathWithPosition { impl PathWithPosition { /// Returns a PathWithPosition from a path. - pub fn from_path(path: PathBuf) -> Self { + pub const fn from_path(path: PathBuf) -> Self { Self { path, row: None, diff --git a/crates/util/src/rel_path.rs b/crates/util/src/rel_path.rs index b360297f209c54c6a33b174a738ed1876fbc16a0..e295088559641373ad033df17b89e8f25da0ca6a 100644 --- a/crates/util/src/rel_path.rs +++ b/crates/util/src/rel_path.rs @@ -32,7 +32,7 @@ pub struct RelPathBuf(String); impl RelPath { /// Creates an empty [`RelPath`]. - pub fn empty() -> &'static Self { + pub const fn empty() -> &'static Self { Self::new_unchecked("") } @@ -111,20 +111,20 @@ impl RelPath { } } - fn new_unchecked(s: &str) -> &Self { + const fn new_unchecked(s: &str) -> &Self { // Safety: `RelPath` is a transparent wrapper around `str`. unsafe { &*(s as *const str as *const Self) } } - pub fn is_empty(&self) -> bool { + pub const fn is_empty(&self) -> bool { self.0.is_empty() } - pub fn components(&self) -> RelPathComponents<'_> { + pub const fn components(&self) -> RelPathComponents<'_> { RelPathComponents(&self.0) } - pub fn ancestors(&self) -> RelPathAncestors<'_> { + pub const fn ancestors(&self) -> RelPathAncestors<'_> { RelPathAncestors(Some(&self.0)) } @@ -235,7 +235,7 @@ impl RelPath { /// Get the internal unix-style representation of the path. /// /// This should not be shown to the user. - pub fn as_unix_str(&self) -> &str { + pub const fn as_unix_str(&self) -> &str { &self.0 } @@ -289,7 +289,7 @@ impl fmt::Debug for RelPathBuf { } impl RelPathBuf { - pub fn new() -> Self { + pub const fn new() -> Self { Self(String::new()) } @@ -312,7 +312,7 @@ impl RelPathBuf { self.0.push_str(&path.0); } - pub fn as_rel_path(&self) -> &RelPath { + pub const fn as_rel_path(&self) -> &RelPath { RelPath::new_unchecked(self.0.as_str()) } @@ -381,7 +381,7 @@ pub struct RelPathAncestors<'a>(Option<&'a str>); const SEPARATOR: char = '/'; impl<'a> RelPathComponents<'a> { - pub fn rest(&self) -> &'a RelPath { + pub const fn rest(&self) -> &'a RelPath { RelPath::new_unchecked(self.0) } } diff --git a/crates/util/src/util.rs b/crates/util/src/util.rs index 3f1205f96531a897ac67492c84bc2f7e949ab02a..6713131144d2f728a2647d7bd515d8af3b01f268 100644 --- a/crates/util/src/util.rs +++ b/crates/util/src/util.rs @@ -749,7 +749,7 @@ impl Drop for Deferred { /// Run the given function when the returned value is dropped (unless it's cancelled). #[must_use] -pub fn defer(f: F) -> Deferred { +pub const fn defer(f: F) -> Deferred { Deferred(Some(f)) } diff --git a/crates/vercel/src/vercel.rs b/crates/vercel/src/vercel.rs index 8686fda53fbb1d19090f14ff944ec0641ac16c07..b86575c8edea8c59311237847d697a0da54ad845 100644 --- a/crates/vercel/src/vercel.rs +++ b/crates/vercel/src/vercel.rs @@ -22,7 +22,7 @@ pub enum Model { } impl Model { - pub fn default_fast() -> Self { + pub const fn default_fast() -> Self { Self::VZeroOnePointFiveMedium } @@ -49,14 +49,14 @@ impl Model { } } - pub fn max_token_count(&self) -> u64 { + pub const fn max_token_count(&self) -> u64 { match self { Self::VZeroOnePointFiveMedium => 128_000, Self::Custom { max_tokens, .. } => *max_tokens, } } - pub fn max_output_tokens(&self) -> Option { + pub const fn max_output_tokens(&self) -> Option { match self { Self::VZeroOnePointFiveMedium => Some(32_000), Self::Custom { @@ -65,14 +65,14 @@ impl Model { } } - pub fn supports_parallel_tool_calls(&self) -> bool { + pub const fn supports_parallel_tool_calls(&self) -> bool { match self { Self::VZeroOnePointFiveMedium => true, Model::Custom { .. } => false, } } - pub fn supports_prompt_cache_key(&self) -> bool { + pub const fn supports_prompt_cache_key(&self) -> bool { false } } diff --git a/crates/vim/src/command.rs b/crates/vim/src/command.rs index 9dc4ec999a47e6a0e8ab802761cab474ef81499b..8b099e6498887f815ae6884e1327e2dd2ee69bcf 100644 --- a/crates/vim/src/command.rs +++ b/crates/vim/src/command.rs @@ -164,7 +164,7 @@ impl VimOption { } } - fn to_string(&self) -> &'static str { + const fn to_string(&self) -> &'static str { match self { VimOption::Wrap(true) => "wrap", VimOption::Wrap(false) => "nowrap", @@ -792,7 +792,7 @@ impl VimCommand { self } - fn count(mut self) -> Self { + const fn count(mut self) -> Self { self.has_count = true; self } @@ -1140,7 +1140,7 @@ impl CommandRange { } } - pub fn as_count(&self) -> Option { + pub const fn as_count(&self) -> Option { if let CommandRange { start: Position::Line { row, offset: 0 }, end: None, diff --git a/crates/vim/src/helix/boundary.rs b/crates/vim/src/helix/boundary.rs index a6de926bc5a10415dad6584f3d07476b2bf0e5d7..627466f1e0ee18057f6ebc188b9b448c7c5d51af 100644 --- a/crates/vim/src/helix/boundary.rs +++ b/crates/vim/src/helix/boundary.rs @@ -715,11 +715,11 @@ fn try_find_preceding_boundary_data( None } -fn is_buffer_start(left: char) -> bool { +const fn is_buffer_start(left: char) -> bool { left == '\0' } -fn is_buffer_end(right: char) -> bool { +const fn is_buffer_end(right: char) -> bool { right == '\0' } diff --git a/crates/vim/src/motion.rs b/crates/vim/src/motion.rs index e44039914f801848ce362b081f6e1bcd18b3c1fa..33c410da5ec99a9ae07f06d5e30959c71500c8ee 100644 --- a/crates/vim/src/motion.rs +++ b/crates/vim/src/motion.rs @@ -28,14 +28,14 @@ pub(crate) enum MotionKind { } impl MotionKind { - pub(crate) fn for_mode(mode: Mode) -> Self { + pub(crate) const fn for_mode(mode: Mode) -> Self { match mode { Mode::VisualLine => MotionKind::Linewise, _ => MotionKind::Exclusive, } } - pub(crate) fn linewise(&self) -> bool { + pub(crate) const fn linewise(&self) -> bool { matches!(self, MotionKind::Linewise) } } @@ -809,11 +809,11 @@ impl Motion { } } - fn skip_exclusive_special_case(&self) -> bool { + const fn skip_exclusive_special_case(&self) -> bool { matches!(self, Motion::WrappingLeft | Motion::WrappingRight) } - pub(crate) fn push_to_jump_list(&self) -> bool { + pub(crate) const fn push_to_jump_list(&self) -> bool { use Motion::*; match self { CurrentLine @@ -880,7 +880,7 @@ impl Motion { } } - pub fn infallible(&self) -> bool { + pub const fn infallible(&self) -> bool { use Motion::*; match self { StartOfDocument | EndOfDocument | CurrentLine => true, @@ -2628,7 +2628,7 @@ fn find_backward( } /// Returns true if one char is equal to the other or its uppercase variant (if smartcase is true). -pub fn is_character_match(target: char, other: char, smartcase: bool) -> bool { +pub const fn is_character_match(target: char, other: char, smartcase: bool) -> bool { if smartcase { if target.is_uppercase() { target == other @@ -3015,7 +3015,7 @@ fn section_motion( display_point } -fn matches_indent_type( +const fn matches_indent_type( target_indent: &text::LineIndent, current_indent: &text::LineIndent, indent_type: IndentType, diff --git a/crates/vim/src/object.rs b/crates/vim/src/object.rs index 5d0ac722872f3c39067a668c4ed5d56847c61898..82666400a0c164c378f96fcd6f6fab16c9f6f126 100644 --- a/crates/vim/src/object.rs +++ b/crates/vim/src/object.rs @@ -259,7 +259,7 @@ fn get_line_range(map: &DisplaySnapshot, point: Point) -> Range { start..end } -fn get_visible_line_range(line_range: &Range) -> Range { +const fn get_visible_line_range(line_range: &Range) -> Range { let end_column = line_range.end.column.saturating_sub(1); line_range.start..Point::new(line_range.end.row, end_column) } @@ -448,7 +448,7 @@ impl Vim { } impl Object { - pub fn is_multiline(self) -> bool { + pub const fn is_multiline(self) -> bool { match self { Object::Word { .. } | Object::Subword { .. } @@ -476,7 +476,7 @@ impl Object { } } - pub fn always_expands_both_ways(self) -> bool { + pub const fn always_expands_both_ways(self) -> bool { match self { Object::Word { .. } | Object::Subword { .. } @@ -1367,7 +1367,7 @@ fn sentence( Some(range) } -fn is_possible_sentence_start(character: char) -> bool { +const fn is_possible_sentence_start(character: char) -> bool { !character.is_whitespace() && character != '.' } diff --git a/crates/vim/src/state.rs b/crates/vim/src/state.rs index 959edff63dd50fa549edcbae1bea213224b923af..891cd8df435c4607cbe017ea11fcc431c3642c21 100644 --- a/crates/vim/src/state.rs +++ b/crates/vim/src/state.rs @@ -66,7 +66,7 @@ impl Display for Mode { } impl Mode { - pub fn is_visual(&self) -> bool { + pub const fn is_visual(&self) -> bool { match self { Self::Visual | Self::VisualLine | Self::VisualBlock | Self::HelixSelect => true, Self::Normal | Self::Insert | Self::Replace | Self::HelixNormal => false, @@ -994,7 +994,7 @@ pub struct SearchState { } impl Operator { - pub fn id(&self) -> &'static str { + pub const fn id(&self) -> &'static str { match self { Operator::Object { around: false } => "i", Operator::Object { around: true } => "a", @@ -1063,7 +1063,7 @@ impl Operator { } } - pub fn is_waiting(&self, mode: Mode) -> bool { + pub const fn is_waiting(&self, mode: Mode) -> bool { match self { Operator::AddSurrounds { target } => target.is_some() || mode.is_visual(), Operator::FindForward { .. } @@ -1106,7 +1106,7 @@ impl Operator { } } - pub fn starts_dot_recording(&self) -> bool { + pub const fn starts_dot_recording(&self) -> bool { match self { Operator::Change | Operator::Delete diff --git a/crates/vim/src/vim.rs b/crates/vim/src/vim.rs index 7481d176109907baccf6e742d0b3f3614014dcac..ead7a941abf66418a32ded5cd5bc1f031d927f87 100644 --- a/crates/vim/src/vim.rs +++ b/crates/vim/src/vim.rs @@ -1296,7 +1296,7 @@ impl Vim { !(self.mode == Mode::Insert && self.last_mode == Mode::VisualBlock) } - pub fn clip_at_line_ends(&self) -> bool { + pub const fn clip_at_line_ends(&self) -> bool { match self.mode { Mode::Insert | Mode::Visual diff --git a/crates/watch/src/watch.rs b/crates/watch/src/watch.rs index 71dab748200e6ba1e3ecf0a5baaf4290bef68b59..5f6e4f59a96b42cafc7d22e62ac61c55c53bcc39 100644 --- a/crates/watch/src/watch.rs +++ b/crates/watch/src/watch.rs @@ -31,7 +31,7 @@ pub fn channel(value: T) -> (Sender, Receiver) { struct WakerId(usize); impl WakerId { - fn post_inc(&mut self) -> Self { + const fn post_inc(&mut self) -> Self { let id = *self; self.0 = id.0.wrapping_add(1); *self diff --git a/crates/workspace/src/dock.rs b/crates/workspace/src/dock.rs index d67d3c81a9fbf67518a49c6c75a842a50ca78684..710d1591ad44fd99990cb25db4915ff3027f0903 100644 --- a/crates/workspace/src/dock.rs +++ b/crates/workspace/src/dock.rs @@ -236,7 +236,7 @@ impl Into for DockPosition { } impl DockPosition { - fn label(&self) -> &'static str { + const fn label(&self) -> &'static str { match self { Self::Left => "Left", Self::Bottom => "Bottom", @@ -244,7 +244,7 @@ impl DockPosition { } } - pub fn axis(&self) -> Axis { + pub const fn axis(&self) -> Axis { match self { Self::Left | Self::Right => Axis::Horizontal, Self::Bottom => Axis::Vertical, @@ -342,11 +342,11 @@ impl Dock { dock } - pub fn position(&self) -> DockPosition { + pub const fn position(&self) -> DockPosition { self.position } - pub fn is_open(&self) -> bool { + pub const fn is_open(&self) -> bool { self.is_open } @@ -395,7 +395,7 @@ impl Dock { .and_then(|index| self.panel_entries.get(index)) } - pub fn active_panel_index(&self) -> Option { + pub const fn active_panel_index(&self) -> Option { self.active_panel_index } @@ -627,7 +627,7 @@ impl Dock { } } - pub fn panels_len(&self) -> usize { + pub const fn panels_len(&self) -> usize { self.panel_entries.len() } diff --git a/crates/workspace/src/history_manager.rs b/crates/workspace/src/history_manager.rs index 1b80e7c0125aac0ccf4a0f41c1b5be3c4a651e72..f772acc3654d6f2707c1cece3d9480ce2cc8229e 100644 --- a/crates/workspace/src/history_manager.rs +++ b/crates/workspace/src/history_manager.rs @@ -32,7 +32,7 @@ struct GlobalHistoryManager(Entity); impl Global for GlobalHistoryManager {} impl HistoryManager { - fn new() -> Self { + const fn new() -> Self { Self { history: Vec::new(), } diff --git a/crates/workspace/src/item.rs b/crates/workspace/src/item.rs index 1a6a09c38d0aea0c2df59947455628ec4a7ccd43..e94ee77289d8c1d8f89142c659f6f96a5f8e3500 100644 --- a/crates/workspace/src/item.rs +++ b/crates/workspace/src/item.rs @@ -117,7 +117,7 @@ pub struct TabContentParams { impl TabContentParams { /// Returns the text color to be used for the tab content. - pub fn text_color(&self) -> Color { + pub const fn text_color(&self) -> Color { if self.deemphasized { if self.selected { Color::Muted diff --git a/crates/workspace/src/modal_layer.rs b/crates/workspace/src/modal_layer.rs index bcd7db3a82aec46405927e118af86cf4a0d4912b..e669e30d3f4bbbf839323c9c80a156e3d8305d3f 100644 --- a/crates/workspace/src/modal_layer.rs +++ b/crates/workspace/src/modal_layer.rs @@ -67,7 +67,7 @@ impl Default for ModalLayer { } impl ModalLayer { - pub fn new() -> Self { + pub const fn new() -> Self { Self { active_modal: None, dismiss_on_focus_lost: false, @@ -159,7 +159,7 @@ impl ModalLayer { active_modal.modal.view().downcast::().ok() } - pub fn has_active_modal(&self) -> bool { + pub const fn has_active_modal(&self) -> bool { self.active_modal.is_some() } } diff --git a/crates/workspace/src/notifications.rs b/crates/workspace/src/notifications.rs index 768b10abe4f3973ca6424b7b59b4e3bfb44cbb15..e62096e51191e4b9c8323761b427c00b4bd80a7a 100644 --- a/crates/workspace/src/notifications.rs +++ b/crates/workspace/src/notifications.rs @@ -52,7 +52,7 @@ impl NotificationId { } /// Builds a `NotificationId` out of the given string. - pub fn named(id: SharedString) -> Self { + pub const fn named(id: SharedString) -> Self { Self::Named(id) } } @@ -500,12 +500,12 @@ impl NotificationFrame { /// Determines whether the given notification ID should be suppressible /// Suppressed motifications will not be shown anymore - pub fn show_suppress_button(mut self, show: bool) -> Self { + pub const fn show_suppress_button(mut self, show: bool) -> Self { self.show_suppress_button = show; self } - pub fn show_close_button(mut self, show: bool) -> Self { + pub const fn show_close_button(mut self, show: bool) -> Self { self.show_close_button = show; self } @@ -676,12 +676,12 @@ pub mod simple_message_notification { self } - pub fn primary_icon(mut self, icon: IconName) -> Self { + pub const fn primary_icon(mut self, icon: IconName) -> Self { self.primary_icon = Some(icon); self } - pub fn primary_icon_color(mut self, color: Color) -> Self { + pub const fn primary_icon_color(mut self, color: Color) -> Self { self.primary_icon_color = Some(color); self } @@ -710,12 +710,12 @@ pub mod simple_message_notification { self } - pub fn secondary_icon(mut self, icon: IconName) -> Self { + pub const fn secondary_icon(mut self, icon: IconName) -> Self { self.secondary_icon = Some(icon); self } - pub fn secondary_icon_color(mut self, color: Color) -> Self { + pub const fn secondary_icon_color(mut self, color: Color) -> Self { self.secondary_icon_color = Some(color); self } @@ -756,14 +756,14 @@ pub mod simple_message_notification { cx.emit(DismissEvent); } - pub fn show_close_button(mut self, show: bool) -> Self { + pub const fn show_close_button(mut self, show: bool) -> Self { self.show_close_button = show; self } /// Determines whether the given notification ID should be supressable /// Suppressed motifications will not be shown anymor - pub fn show_suppress_button(mut self, show: bool) -> Self { + pub const fn show_suppress_button(mut self, show: bool) -> Self { self.show_suppress_button = show; self } diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index 0784f30739be9ef6bf6c65f38e2f7e52c73390e8..f676364a81f32da5cb43d5223ec16acc464b35c1 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -251,7 +251,7 @@ actions!( ); impl DeploySearch { - pub fn find() -> Self { + pub const fn find() -> Self { Self { replace_enabled: false, included_files: None, @@ -715,7 +715,7 @@ impl Pane { cx.notify(); } - pub fn active_item_index(&self) -> usize { + pub const fn active_item_index(&self) -> usize { self.active_item_index } @@ -794,11 +794,11 @@ impl Pane { } } - pub fn nav_history(&self) -> &NavHistory { + pub const fn nav_history(&self) -> &NavHistory { &self.nav_history } - pub fn nav_history_mut(&mut self) -> &mut NavHistory { + pub const fn nav_history_mut(&mut self) -> &mut NavHistory { &mut self.nav_history } @@ -846,7 +846,7 @@ impl Pane { self.toolbar.update(cx, |_, cx| cx.notify()); } - pub fn preview_item_id(&self) -> Option { + pub const fn preview_item_id(&self) -> Option { self.preview_item_id } @@ -879,11 +879,11 @@ impl Pane { } /// Should only be used when deserializing a pane. - pub fn set_pinned_count(&mut self, count: usize) { + pub const fn set_pinned_count(&mut self, count: usize) { self.pinned_tab_count = count; } - pub fn pinned_count(&self) -> usize { + pub const fn pinned_count(&self) -> usize { self.pinned_tab_count } @@ -2319,7 +2319,7 @@ impl Pane { } } - pub fn toolbar(&self) -> &Entity { + pub const fn toolbar(&self) -> &Entity { &self.toolbar } @@ -2388,7 +2388,7 @@ impl Pane { }) } - pub fn icon_color(selected: bool) -> Color { + pub const fn icon_color(selected: bool) -> Color { if selected { Color::Default } else { @@ -2488,7 +2488,7 @@ impl Pane { }); } - fn is_tab_pinned(&self, ix: usize) -> bool { + const fn is_tab_pinned(&self, ix: usize) -> bool { self.pinned_tab_count > ix } @@ -3180,7 +3180,7 @@ impl Pane { cx.notify(); } - pub fn is_zoomed(&self) -> bool { + pub const fn is_zoomed(&self) -> bool { self.zoomed } @@ -3515,7 +3515,7 @@ impl Pane { .log_err(); } - pub fn display_nav_history_buttons(&mut self, display: Option) { + pub const fn display_nav_history_buttons(&mut self, display: Option) { self.display_nav_history_buttons = display; } @@ -3568,11 +3568,11 @@ impl Pane { .collect() } - pub fn drag_split_direction(&self) -> Option { + pub const fn drag_split_direction(&self) -> Option { self.drag_split_direction } - pub fn set_zoom_out_on_close(&mut self, zoom_out_on_close: bool) { + pub const fn set_zoom_out_on_close(&mut self, zoom_out_on_close: bool) { self.zoom_out_on_close = zoom_out_on_close; } } diff --git a/crates/workspace/src/pane_group.rs b/crates/workspace/src/pane_group.rs index 36898b127bdd749a9c1867a97bd72dfd6f4e15ea..79752781f39820228d2378aae15b3d16a6e1275f 100644 --- a/crates/workspace/src/pane_group.rs +++ b/crates/workspace/src/pane_group.rs @@ -36,11 +36,11 @@ pub struct PaneRenderResult { } impl PaneGroup { - pub fn with_root(root: Member) -> Self { + pub const fn with_root(root: Member) -> Self { Self { root } } - pub fn new(pane: Entity) -> Self { + pub const fn new(pane: Entity) -> Self { Self { root: Member::Pane(pane), } @@ -271,7 +271,7 @@ pub struct ActivePaneDecorator<'a> { } impl<'a> ActivePaneDecorator<'a> { - pub fn new(active_pane: &'a Entity, workspace: &'a WeakEntity) -> Self { + pub const fn new(active_pane: &'a Entity, workspace: &'a WeakEntity) -> Self { Self { active_pane, workspace, @@ -902,7 +902,7 @@ impl std::fmt::Display for SplitDirection { } impl SplitDirection { - pub fn all() -> [Self; 4] { + pub const fn all() -> [Self; 4] { [Self::Up, Self::Down, Self::Left, Self::Right] } @@ -950,14 +950,14 @@ impl SplitDirection { } } - pub fn axis(&self) -> Axis { + pub const fn axis(&self) -> Axis { match self { Self::Up | Self::Down => Axis::Vertical, Self::Left | Self::Right => Axis::Horizontal, } } - pub fn increasing(&self) -> bool { + pub const fn increasing(&self) -> bool { match self { Self::Left | Self::Up => false, Self::Down | Self::Right => true, @@ -1040,7 +1040,7 @@ mod element { } impl PaneAxisElement { - pub fn with_active_pane(mut self, active_pane_ix: Option) -> Self { + pub const fn with_active_pane(mut self, active_pane_ix: Option) -> Self { self.active_pane_ix = active_pane_ix; self } diff --git a/crates/workspace/src/persistence/model.rs b/crates/workspace/src/persistence/model.rs index 08a2f2e38dd142848f8a9c07652e147b58bee233..34a0c15046e8d4e1026bd8df317cb80183028ec2 100644 --- a/crates/workspace/src/persistence/model.rs +++ b/crates/workspace/src/persistence/model.rs @@ -71,7 +71,7 @@ pub struct DockStructure { } impl RemoteConnectionKind { - pub(crate) fn serialize(&self) -> &'static str { + pub(crate) const fn serialize(&self) -> &'static str { match self { RemoteConnectionKind::Ssh => "ssh", RemoteConnectionKind::Wsl => "wsl", @@ -254,7 +254,7 @@ pub struct SerializedPane { } impl SerializedPane { - pub fn new(children: Vec, active: bool, pinned_count: usize) -> Self { + pub const fn new(children: Vec, active: bool, pinned_count: usize) -> Self { SerializedPane { children, active, diff --git a/crates/workspace/src/searchable.rs b/crates/workspace/src/searchable.rs index 310fae908dbd6864c1636ebd393e4920d0f9ad02..97520091e1ac00f5ee67b1a2a1062991e8c008e5 100644 --- a/crates/workspace/src/searchable.rs +++ b/crates/workspace/src/searchable.rs @@ -26,7 +26,7 @@ pub enum Direction { } impl Direction { - pub fn opposite(&self) -> Self { + pub const fn opposite(&self) -> Self { match self { Direction::Prev => Direction::Next, Direction::Next => Direction::Prev, diff --git a/crates/workspace/src/theme_preview.rs b/crates/workspace/src/theme_preview.rs index 09a5415ca063d0aab2b2fab97abff3533e113b0b..683d94bbc40d9bec5a85a764e90f8a9c3d46501a 100644 --- a/crates/workspace/src/theme_preview.rs +++ b/crates/workspace/src/theme_preview.rs @@ -36,7 +36,7 @@ enum ThemePreviewPage { } impl ThemePreviewPage { - pub fn name(&self) -> &'static str { + pub const fn name(&self) -> &'static str { match self { Self::Overview => "Overview", Self::Typography => "Typography", diff --git a/crates/workspace/src/toast_layer.rs b/crates/workspace/src/toast_layer.rs index 515794554831dc62bdf8babf717ce1f372f37763..b2e80c208e04a8b27b66ab89277c04dac6c630d9 100644 --- a/crates/workspace/src/toast_layer.rs +++ b/crates/workspace/src/toast_layer.rs @@ -101,7 +101,7 @@ impl Default for ToastLayer { } impl ToastLayer { - pub fn new() -> Self { + pub const fn new() -> Self { Self { active_toast: None, duration_remaining: None, @@ -158,7 +158,7 @@ impl ToastLayer { active_toast.toast.view().downcast::().ok() } - pub fn has_active_toast(&self) -> bool { + pub const fn has_active_toast(&self) -> bool { self.active_toast.is_some() } diff --git a/crates/workspace/src/toolbar.rs b/crates/workspace/src/toolbar.rs index 9d6626af80fbab9b7bf8439a3c5f628263892bc6..545f3088c598bb93b4827c38fa66b6fd877651dc 100644 --- a/crates/workspace/src/toolbar.rs +++ b/crates/workspace/src/toolbar.rs @@ -233,7 +233,7 @@ impl Toolbar { .find_map(|(item, _)| item.to_any().downcast().ok()) } - pub fn hidden(&self) -> bool { + pub const fn hidden(&self) -> bool { self.hidden } } diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index bbb9ee767196c062707efcc2618670cf09da4e87..b8a7700c875d8532cede6bba692b1e920363ab7c 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -285,7 +285,7 @@ pub struct MoveItemToPane { pub clone: bool, } -fn default_1() -> usize { +const fn default_1() -> usize { 1 } @@ -302,7 +302,7 @@ pub struct MoveItemToPaneInDirection { pub clone: bool, } -fn default_right() -> SplitDirection { +const fn default_right() -> SplitDirection { SplitDirection::Right } @@ -472,7 +472,7 @@ impl Toast { self } - pub fn autohide(mut self) -> Self { + pub const fn autohide(mut self) -> Self { self.autohide = true; self } @@ -997,7 +997,7 @@ struct DelayedDebouncedEditAction { } impl DelayedDebouncedEditAction { - fn new() -> DelayedDebouncedEditAction { + const fn new() -> DelayedDebouncedEditAction { DelayedDebouncedEditAction { task: None, cancel_channel: None, @@ -1698,11 +1698,11 @@ impl Workspace { self.weak_self.clone() } - pub fn left_dock(&self) -> &Entity { + pub const fn left_dock(&self) -> &Entity { &self.left_dock } - pub fn bottom_dock(&self) -> &Entity { + pub const fn bottom_dock(&self) -> &Entity { &self.bottom_dock } @@ -1721,15 +1721,15 @@ impl Workspace { self.serialize_workspace(window, cx); } - pub fn right_dock(&self) -> &Entity { + pub const fn right_dock(&self) -> &Entity { &self.right_dock } - pub fn all_docks(&self) -> [&Entity; 3] { + pub const fn all_docks(&self) -> [&Entity; 3] { [&self.left_dock, &self.bottom_dock, &self.right_dock] } - pub fn dock_at_position(&self, position: DockPosition) -> &Entity { + pub const fn dock_at_position(&self, position: DockPosition) -> &Entity { match position { DockPosition::Left => &self.left_dock, DockPosition::Bottom => &self.bottom_dock, @@ -1737,7 +1737,7 @@ impl Workspace { } } - pub fn is_edited(&self) -> bool { + pub const fn is_edited(&self) -> bool { self.window_edited } @@ -1772,7 +1772,7 @@ impl Workspace { } } - pub fn status_bar(&self) -> &Entity { + pub const fn status_bar(&self) -> &Entity { &self.status_bar } @@ -1780,7 +1780,7 @@ impl Workspace { StatusBarSettings::get_global(cx).show } - pub fn app_state(&self) -> &Arc { + pub const fn app_state(&self) -> &Arc { &self.app_state } @@ -1788,7 +1788,7 @@ impl Workspace { &self.app_state.user_store } - pub fn project(&self) -> &Entity { + pub const fn project(&self) -> &Entity { &self.project } @@ -4199,7 +4199,7 @@ impl Workspace { &self.panes } - pub fn active_pane(&self) -> &Entity { + pub const fn active_pane(&self) -> &Entity { &self.active_pane } @@ -5164,7 +5164,7 @@ impl Workspace { } } - pub fn database_id(&self) -> Option { + pub const fn database_id(&self) -> Option { self.database_id } @@ -5954,7 +5954,7 @@ impl Workspace { window.root().flatten() } - pub fn zoomed_item(&self) -> Option<&AnyWeakView> { + pub const fn zoomed_item(&self) -> Option<&AnyWeakView> { self.zoomed.as_ref() } @@ -6884,7 +6884,7 @@ impl WorkspaceStore { })? } - pub fn workspaces(&self) -> &HashSet> { + pub const fn workspaces(&self) -> &HashSet> { &self.workspaces } } @@ -6900,7 +6900,7 @@ impl ViewId { }) } - pub(crate) fn to_proto(self) -> Option { + pub(crate) const fn to_proto(self) -> Option { if let CollaboratorId::PeerId(peer_id) = self.creator { Some(proto::ViewId { creator: Some(peer_id), diff --git a/crates/worktree/src/worktree.rs b/crates/worktree/src/worktree.rs index 3fa271a37ac014e046b4e5a98ae780d45a66743c..0b8a300f56972ad5353ca7b3cde2bf0e1640325c 100644 --- a/crates/worktree/src/worktree.rs +++ b/crates/worktree/src/worktree.rs @@ -570,7 +570,7 @@ impl Worktree { }) } - pub fn as_local(&self) -> Option<&LocalWorktree> { + pub const fn as_local(&self) -> Option<&LocalWorktree> { if let Worktree::Local(worktree) = self { Some(worktree) } else { @@ -578,7 +578,7 @@ impl Worktree { } } - pub fn as_remote(&self) -> Option<&RemoteWorktree> { + pub const fn as_remote(&self) -> Option<&RemoteWorktree> { if let Worktree::Remote(worktree) = self { Some(worktree) } else { @@ -586,7 +586,7 @@ impl Worktree { } } - pub fn as_local_mut(&mut self) -> Option<&mut LocalWorktree> { + pub const fn as_local_mut(&mut self) -> Option<&mut LocalWorktree> { if let Worktree::Local(worktree) = self { Some(worktree) } else { @@ -594,7 +594,7 @@ impl Worktree { } } - pub fn as_remote_mut(&mut self) -> Option<&mut RemoteWorktree> { + pub const fn as_remote_mut(&mut self) -> Option<&mut RemoteWorktree> { if let Worktree::Remote(worktree) = self { Some(worktree) } else { @@ -602,11 +602,11 @@ impl Worktree { } } - pub fn is_local(&self) -> bool { + pub const fn is_local(&self) -> bool { matches!(self, Worktree::Local(_)) } - pub fn is_remote(&self) -> bool { + pub const fn is_remote(&self) -> bool { !self.is_local() } @@ -647,14 +647,14 @@ impl Worktree { } } - pub fn is_visible(&self) -> bool { + pub const fn is_visible(&self) -> bool { match self { Worktree::Local(worktree) => worktree.visible, Worktree::Remote(worktree) => worktree.visible, } } - pub fn replica_id(&self) -> ReplicaId { + pub const fn replica_id(&self) -> ReplicaId { match self { Worktree::Local(_) => 0, Worktree::Remote(worktree) => worktree.replica_id, @@ -1018,7 +1018,7 @@ impl LocalWorktree { !self.share_private_files && self.settings.is_path_private(path) } - pub fn fs_is_case_sensitive(&self) -> bool { + pub const fn fs_is_case_sensitive(&self) -> bool { self.fs_case_sensitive } @@ -1792,7 +1792,7 @@ impl LocalWorktree { } impl RemoteWorktree { - pub fn project_id(&self) -> u64 { + pub const fn project_id(&self) -> u64 { self.project_id } @@ -2053,7 +2053,7 @@ impl Snapshot { } } - pub fn id(&self) -> WorktreeId { + pub const fn id(&self) -> WorktreeId { self.id } @@ -2367,7 +2367,7 @@ impl Snapshot { self.root_name.as_unix_str() } - pub fn scan_id(&self) -> usize { + pub const fn scan_id(&self) -> usize { self.scan_id } @@ -2388,7 +2388,7 @@ impl Snapshot { self.entry_for_path(&entry.path) } - pub fn path_style(&self) -> PathStyle { + pub const fn path_style(&self) -> PathStyle { self.path_style } } @@ -3175,7 +3175,7 @@ impl File { self.worktree.read(cx).id() } - pub fn project_entry_id(&self) -> Option { + pub const fn project_entry_id(&self) -> Option { match self.disk_state { DiskState::Deleted => None, _ => self.entry_id, @@ -3386,32 +3386,32 @@ impl Entry { } } - pub fn is_created(&self) -> bool { + pub const fn is_created(&self) -> bool { self.mtime.is_some() } - pub fn is_dir(&self) -> bool { + pub const fn is_dir(&self) -> bool { self.kind.is_dir() } - pub fn is_file(&self) -> bool { + pub const fn is_file(&self) -> bool { self.kind.is_file() } } impl EntryKind { - pub fn is_dir(&self) -> bool { + pub const fn is_dir(&self) -> bool { matches!( self, EntryKind::Dir | EntryKind::PendingDir | EntryKind::UnloadedDir ) } - pub fn is_unloaded(&self) -> bool { + pub const fn is_unloaded(&self) -> bool { matches!(self, EntryKind::UnloadedDir) } - pub fn is_file(&self) -> bool { + pub const fn is_file(&self) -> bool { matches!(self, EntryKind::File) } } @@ -5201,7 +5201,7 @@ struct TraversalProgress<'a> { } impl TraversalProgress<'_> { - fn count(&self, include_files: bool, include_dirs: bool, include_ignored: bool) -> usize { + const fn count(&self, include_files: bool, include_dirs: bool, include_ignored: bool) -> usize { match (include_files, include_dirs, include_ignored) { (true, true, true) => self.count, (true, true, false) => self.non_ignored_count, @@ -5315,11 +5315,11 @@ impl<'a> Traversal<'a> { self.cursor.item() } - pub fn snapshot(&self) -> &'a Snapshot { + pub const fn snapshot(&self) -> &'a Snapshot { self.snapshot } - pub fn start_offset(&self) -> usize { + pub const fn start_offset(&self) -> usize { self.cursor .start() .count(self.include_files, self.include_dirs, self.include_ignored) @@ -5390,11 +5390,11 @@ enum TraversalTarget<'a> { } impl<'a> TraversalTarget<'a> { - fn path(path: &'a RelPath) -> Self { + const fn path(path: &'a RelPath) -> Self { Self::Path(PathTarget::Path(path)) } - fn successor(path: &'a RelPath) -> Self { + const fn successor(path: &'a RelPath) -> Self { Self::Path(PathTarget::Successor(path)) } @@ -5522,19 +5522,19 @@ impl ProjectEntryId { Self(counter.fetch_add(1, SeqCst)) } - pub fn from_proto(id: u64) -> Self { + pub const fn from_proto(id: u64) -> Self { Self(id as usize) } - pub fn to_proto(self) -> u64 { + pub const fn to_proto(self) -> u64 { self.0 as u64 } - pub fn from_usize(id: usize) -> Self { + pub const fn from_usize(id: usize) -> Self { ProjectEntryId(id) } - pub fn to_usize(self) -> usize { + pub const fn to_usize(self) -> usize { self.0 } } diff --git a/crates/x_ai/src/x_ai.rs b/crates/x_ai/src/x_ai.rs index aac231b511684db9e2bfc36c822a963e5f231161..5acf0d794acfe00ac0f49f63703c90a08ff9a61d 100644 --- a/crates/x_ai/src/x_ai.rs +++ b/crates/x_ai/src/x_ai.rs @@ -47,7 +47,7 @@ pub enum Model { } impl Model { - pub fn default_fast() -> Self { + pub const fn default_fast() -> Self { Self::Grok3Fast } @@ -98,7 +98,7 @@ impl Model { } } - pub fn max_token_count(&self) -> u64 { + pub const fn max_token_count(&self) -> u64 { match self { Self::Grok3 | Self::Grok3Mini | Self::Grok3Fast | Self::Grok3MiniFast => 131_072, Self::Grok4 | Self::GrokCodeFast1 => 256_000, @@ -108,7 +108,7 @@ impl Model { } } - pub fn max_output_tokens(&self) -> Option { + pub const fn max_output_tokens(&self) -> Option { match self { Self::Grok3 | Self::Grok3Mini | Self::Grok3Fast | Self::Grok3MiniFast => Some(8_192), Self::Grok4 @@ -122,7 +122,7 @@ impl Model { } } - pub fn supports_parallel_tool_calls(&self) -> bool { + pub const fn supports_parallel_tool_calls(&self) -> bool { match self { Self::Grok2Vision | Self::Grok3 @@ -140,11 +140,11 @@ impl Model { } } - pub fn supports_prompt_cache_key(&self) -> bool { + pub const fn supports_prompt_cache_key(&self) -> bool { false } - pub fn supports_tool(&self) -> bool { + pub const fn supports_tool(&self) -> bool { match self { Self::Grok2Vision | Self::Grok3 @@ -163,7 +163,7 @@ impl Model { } } - pub fn supports_images(&self) -> bool { + pub const fn supports_images(&self) -> bool { match self { Self::Grok2Vision => true, Self::Custom { diff --git a/crates/zed/src/zed/component_preview.rs b/crates/zed/src/zed/component_preview.rs index 7a287cf3d83f24e7f4d42221bda420053a975860..e03dd3aac4ce367e295ff959dd04b670f7967637 100644 --- a/crates/zed/src/zed/component_preview.rs +++ b/crates/zed/src/zed/component_preview.rs @@ -880,7 +880,7 @@ pub struct ComponentPreviewPage { } impl ComponentPreviewPage { - pub fn new( + pub const fn new( component: ComponentMetadata, reset_key: usize, // languages: Arc diff --git a/crates/zed_actions/src/lib.rs b/crates/zed_actions/src/lib.rs index d62de329c9af63ab8c15e1703b2517ac12594195..de7203e4bcff275e82c4e8dff56c7722f9f8cc54 100644 --- a/crates/zed_actions/src/lib.rs +++ b/crates/zed_actions/src/lib.rs @@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize}; // These may provide relevant context: // https://github.com/rust-lang/rust/issues/47384 // https://github.com/mmastrac/rust-ctor/issues/280 -pub fn init() {} +pub const fn init() {} /// Opens a URL in the system's default web browser. #[derive(Clone, PartialEq, Deserialize, JsonSchema, Action)] @@ -412,7 +412,7 @@ pub enum Spawn { } impl Spawn { - pub fn modal() -> Self { + pub const fn modal() -> Self { Self::ViaModal { reveal_target: None, } diff --git a/crates/zeta/src/license_detection.rs b/crates/zeta/src/license_detection.rs index 44dae09d0a18e5732b9c52ce73cdf71abecc81b0..1397cd29d61aa6a5ed92eb20c73b06978a327d31 100644 --- a/crates/zeta/src/license_detection.rs +++ b/crates/zeta/src/license_detection.rs @@ -59,7 +59,7 @@ impl Display for OpenSourceLicense { impl OpenSourceLicense { /// These are SPDX identifiers for the licenses, except for BSD, where the variants are not /// distinguished. - pub fn spdx_identifier(&self) -> &'static str { + pub const fn spdx_identifier(&self) -> &'static str { match self { OpenSourceLicense::Apache2_0 => "apache-2.0", OpenSourceLicense::BSDZero => "0bsd", @@ -71,7 +71,7 @@ impl OpenSourceLicense { } } - pub fn patterns(&self) -> &'static [&'static str] { + pub const fn patterns(&self) -> &'static [&'static str] { match self { OpenSourceLicense::Apache2_0 => &[ include_str!("../license_patterns/apache-2.0-pattern"), diff --git a/crates/zeta/src/rate_completion_modal.rs b/crates/zeta/src/rate_completion_modal.rs index 8028865b057f0c6c3b49efc3a5c3c640208e65aa..a50f58b3446f05a0771a81cea7307b05bc8b5d19 100644 --- a/crates/zeta/src/rate_completion_modal.rs +++ b/crates/zeta/src/rate_completion_modal.rs @@ -45,7 +45,7 @@ enum RateCompletionView { } impl RateCompletionView { - pub fn name(&self) -> &'static str { + pub const fn name(&self) -> &'static str { match self { Self::SuggestedEdits => "Suggested Edits", Self::RawInput => "Recorded Events & Input", diff --git a/crates/zeta/src/zeta.rs b/crates/zeta/src/zeta.rs index 1d48571d7b06f35d82934122919e75bbbd087ffa..df29c9362fb4afdd455dbcb69c11fbd9d2e7ced0 100644 --- a/crates/zeta/src/zeta.rs +++ b/crates/zeta/src/zeta.rs @@ -1203,14 +1203,14 @@ pub enum DataCollectionChoice { } impl DataCollectionChoice { - pub fn is_enabled(self) -> bool { + pub const fn is_enabled(self) -> bool { match self { Self::Enabled => true, Self::NotAnswered | Self::Disabled => false, } } - pub fn is_answered(self) -> bool { + pub const fn is_answered(self) -> bool { match self { Self::Enabled | Self::Disabled => true, Self::NotAnswered => false, @@ -1218,7 +1218,7 @@ impl DataCollectionChoice { } #[must_use] - pub fn toggle(&self) -> DataCollectionChoice { + pub const fn toggle(&self) -> DataCollectionChoice { match self { Self::Enabled => Self::Disabled, Self::Disabled => Self::Enabled, @@ -1574,7 +1574,7 @@ impl edit_prediction::EditPredictionProvider for ZetaEditPredictionProvider { /// intentionally low to err on the side of underestimating limits. const BYTES_PER_TOKEN_GUESS: usize = 3; -fn guess_token_count(bytes: usize) -> usize { +const fn guess_token_count(bytes: usize) -> usize { bytes / BYTES_PER_TOKEN_GUESS } diff --git a/crates/zeta2/src/prediction.rs b/crates/zeta2/src/prediction.rs index a0dcd83b88142a5746c0b3c7d82bc7a64965edab..9d19b853d46e5f434f8742ed3ef6e9e9aedaa44b 100644 --- a/crates/zeta2/src/prediction.rs +++ b/crates/zeta2/src/prediction.rs @@ -190,7 +190,7 @@ pub fn interpolate_edits( if edits.is_empty() { None } else { Some(edits) } } -pub fn line_range_to_point_range(range: Range) -> Range { +pub const fn line_range_to_point_range(range: Range) -> Range { language::Point::new(range.start.0, 0)..language::Point::new(range.end.0, 0) } diff --git a/crates/zeta2/src/zeta2.rs b/crates/zeta2/src/zeta2.rs index 6e92443b8b4c91ce6bb168d3c87ce4ddce49bc35..ee48a08b7db9e7e17be5acb53ab4f6f438d7dbff 100644 --- a/crates/zeta2/src/zeta2.rs +++ b/crates/zeta2/src/zeta2.rs @@ -235,11 +235,11 @@ impl Zeta { debug_watch_rx } - pub fn options(&self) -> &ZetaOptions { + pub const fn options(&self) -> &ZetaOptions { &self.options } - pub fn set_options(&mut self, options: ZetaOptions) { + pub const fn set_options(&mut self, options: ZetaOptions) { self.options = options; } diff --git a/crates/zlog/src/filter.rs b/crates/zlog/src/filter.rs index 9a2de13cb3d33a1a6f4d17f7eddd4754cae40ea3..b608ad1234a6b2b56027a7def2153f0e728d6ee4 100644 --- a/crates/zlog/src/filter.rs +++ b/crates/zlog/src/filter.rs @@ -320,7 +320,7 @@ impl ScopeMap { this } - pub fn is_empty(&self) -> bool { + pub const fn is_empty(&self) -> bool { self.entries.is_empty() && self.modules.is_empty() } diff --git a/crates/zlog/src/zlog.rs b/crates/zlog/src/zlog.rs index 8254866b6f97f6479f55bd570d1bc63ab26b10d4..955f3e693a26481307a3b377b109683a514b7a9c 100644 --- a/crates/zlog/src/zlog.rs +++ b/crates/zlog/src/zlog.rs @@ -327,7 +327,7 @@ impl Timer { } } - pub fn warn_if_gt(mut self, warn_limit: std::time::Duration) -> Self { + pub const fn warn_if_gt(mut self, warn_limit: std::time::Duration) -> Self { self.warn_if_longer_than = Some(warn_limit); self }