Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Replace panicking unwraps in iterator and Option chains (#61277)

Miguel Raz Guzmán Macedo4605a0f8dc09
diff --git a/crates/agent_ui/src/entry_view_state.rs b/crates/agent_ui/src/entry_view_state.rs
index bdc79beacc9..092450b0fb9 100644
--- a/crates/agent_ui/src/entry_view_state.rs
+++ b/crates/agent_ui/src/entry_view_state.rs
@@ -566,7 +566,7 @@ impl Entry {
self.content_map()?
.get(&diff.entity_id())
.cloned()
- .map(|entity| entity.downcast::<Editor>().unwrap())
+ .and_then(|entity| entity.downcast::<Editor>().ok())
}
pub fn terminal(
@@ -576,7 +576,7 @@ impl Entry {
self.content_map()?
.get(&terminal.entity_id())
.cloned()
- .map(|entity| entity.downcast::<TerminalView>().unwrap())
+ .and_then(|entity| entity.downcast::<TerminalView>().ok())
}
pub fn scroll_handle_for_assistant_message_chunk(
diff --git a/crates/language/src/buffer.rs b/crates/language/src/buffer.rs
index 00cf28568a5..e568a5db4f5 100644
--- a/crates/language/src/buffer.rs
+++ b/crates/language/src/buffer.rs
@@ -3665,7 +3665,12 @@ impl BufferSnapshot {
let indent_configs = matches
.grammars()
.iter()
- .map(|grammar| grammar.indents_config.as_ref().unwrap())
+ .map(|grammar| {
+ grammar
+ .indents_config
+ .as_ref()
+ .expect("grammar in indent match set has indents_config")
+ })
.collect::<Vec<_>>();
let mut indent_ranges = Vec::<Range<Point>>::new();
diff --git a/crates/vim/src/command.rs b/crates/vim/src/command.rs
index df6a911329b..316128d9cb1 100644
--- a/crates/vim/src/command.rs
+++ b/crates/vim/src/command.rs
@@ -771,7 +771,7 @@ pub fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
let keystrokes = action
.command
.chars()
- .map(|c| Keystroke::parse(&c.to_string()).unwrap())
+ .filter_map(|c| Keystroke::parse(&c.to_string()).ok())
.collect();
vim.switch_mode(Mode::Normal, true, window, cx);
if let Some(override_rows) = &action.override_rows {