Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Fix stack overflow by removing `Deref` and `DerefMut` impls
Marshall Bowers3b38641f9883
diff --git a/Cargo.lock b/Cargo.lockindex d7b49e57984..a8aa299305f 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -758,6 +758,17 @@ dependencies = ["rustc-demangle",]+[[package]]+name = "backtrace-on-stack-overflow"+version = "0.3.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7fd2d70527f3737a1ad17355e260706c1badebabd1fa06a7a053407380df841b"+dependencies = [+ "backtrace",+ "libc",+ "nix 0.23.2",+]+[[package]]name = "bae"version = "0.1.7"@@ -4692,6 +4703,19 @@ dependencies = ["winapi 0.3.9",]+[[package]]+name = "nix"+version = "0.23.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "8f3790c00a0150112de0f4cd161e3d7fc4b2d8a5542ffc35f099a2562aecb35c"+dependencies = [+ "bitflags 1.3.2",+ "cc",+ "cfg-if 1.0.0",+ "libc",+ "memoffset 0.6.5",+]+[[package]]name = "nix"version = "0.24.3"@@ -7521,6 +7545,7 @@ name = "storybook2"version = "0.1.0"dependencies = ["anyhow",+ "backtrace-on-stack-overflow","gpui3","log","rust-embed",diff --git a/crates/gpui3/src/app.rs b/crates/gpui3/src/app.rsindex 1bbcc8c6087..afbe875d336 100644--- a/crates/gpui3/src/app.rs+++ b/crates/gpui3/src/app.rs@@ -97,20 +97,6 @@ pub struct AppContext<Thread = ()> {pub(crate) layout_id_buffer: Vec<LayoutId>, // We recycle this memory across layout requests.}-impl Deref for AppContext<MainThread> {- type Target = AppContext<()>;-- fn deref(&self) -> &Self::Target {- self- }-}--impl DerefMut for AppContext<MainThread> {- fn deref_mut(&mut self) -> &mut Self::Target {- self- }-}-impl<Thread> AppContext<Thread> {// TODO: Better names for these?#[inline]@@ -333,7 +319,10 @@ impl AppContext<MainThread> {let id = self.windows.insert(None);let handle = WindowHandle::new(id);let mut window = Window::new(handle.into(), options, self);- let root_view = build_root_view(&mut WindowContext::mutable(self, &mut window));+ let root_view = build_root_view(&mut WindowContext::mutable(+ self.downcast_mut(),+ &mut window,+ ));window.root_view.replace(root_view.into_any());self.windows.get_mut(id).unwrap().replace(window);handlediff --git a/crates/storybook2/Cargo.toml b/crates/storybook2/Cargo.tomlindex d1a7c419652..bd984c54c13 100644--- a/crates/storybook2/Cargo.toml+++ b/crates/storybook2/Cargo.toml@@ -10,6 +10,8 @@ path = "src/storybook2.rs"[dependencies]anyhow.workspace = true+# TODO: Remove after diagnosing stack overflow.+backtrace-on-stack-overflow = "0.3.0"gpui3 = { path = "../gpui3" }log.workspace = truerust-embed.workspace = truediff --git a/crates/storybook2/src/storybook2.rs b/crates/storybook2/src/storybook2.rsindex a9fbc050b7f..3b341dbd537 100644--- a/crates/storybook2/src/storybook2.rs+++ b/crates/storybook2/src/storybook2.rs@@ -14,6 +14,8 @@ mod workspace;// }fn main() {+ unsafe { backtrace_on_stack_overflow::enable() };+SimpleLogger::init(LevelFilter::Info, Default::default()).expect("could not initialize logger");gpui3::App::production().run(|cx| {