{"record":{"id":"c733a0d879f62f42","repo":"iced-rs/iced","slug":"editor-cannot-have-multiple-strong-references","errorCode":null,"errorMessage":"Editor cannot have multiple strong references","messagePattern":"Editor cannot have multiple strong references","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"graphics/src/text/editor.rs","lineNumber":842,"sourceCode":"                if window > visible_lines {\n                    window -= visible_lines;\n                    None\n                } else {\n                    Some(scroll.line + i)\n                }\n            })\n            .unwrap_or(buffer.lines.len().saturating_sub(1));\n\n        let current_line = highlighter.current_line();\n\n        if current_line > last_visible_line {\n            return;\n        }\n\n        let editor = self.0.take().expect(\"Editor should always be initialized\");\n\n        let mut internal =\n            Arc::try_unwrap(editor).expect(\"Editor cannot have multiple strong references\");\n\n        let mut font_system = text::font_system().write().expect(\"Write font system\");\n\n        let attributes = text::to_attributes(font);\n\n        for line in &mut buffer_mut_from_editor(&mut internal.editor).lines\n            [current_line..=last_visible_line]\n        {\n            let mut list = cosmic_text::AttrsList::new(&attributes);\n\n            for (range, highlight) in highlighter.highlight_line(line.text()) {\n                let format = format_highlight(&highlight);\n\n                if format.color.is_some() || format.font.is_some() {\n                    list.add_span(\n                        range,\n                        &cosmic_text::Attrs {\n                            color_opt: format.color.map(text::to_color),","sourceCodeStart":824,"sourceCodeEnd":860,"githubUrl":"https://github.com/iced-rs/iced/blob/3de451447bd28217bb535632867550908e29d5d0/graphics/src/text/editor.rs#L824-L860","documentation":"Editor::highlight needs exclusive mutable access: it Arc::try_unwraps the internal Arc<Internal> (editor.rs:842, same pattern as with_internal_mut at editor.rs:67). If any other strong reference exists, try_unwrap returns Err and expect(\"Editor cannot have multiple strong references\") panics. Editor is cheap to clone precisely because it wraps an Arc, and every surviving clone blocks highlighting and mutation.","triggerScenarios":"Cloning the Editor (or the widget/tree holding it) and keeping the twin alive while the original is mutated/highlighted; caching editors in a map while also using them in the tree; two widgets sharing one editor instance.","commonSituations":"Stashing a copy of the editor for background measurement or persistence; splitting view/state ownership by cloning; reusing one editor across multiple text_editor-like widgets.","solutions":["Keep exactly one strong owner: never clone() the Editor; move or borrow it instead","For read-only sharing use editor.downgrade() (a Weak reference), which does not block Arc::try_unwrap","Drop cached/cloned editors before driving update/highlight","Give each widget its own editor state instead of sharing one instance"],"exampleFix":"// before\nlet editor_copy = editor.clone(); // kept in a cache\neditor.highlight(font, &mut hl, fmt); // panics: clone still alive\n\n// after - share read access via Weak\ndebug_snapshot(editor); // reads bounds only\nlet weak = editor.downgrade(); // Weak does not block try_unwrap\ndrop(editor_copy);              // if a clone existed, release it first\neditor.highlight(font, &mut hl, fmt);","handlingStrategy":"validation","validationCode":"// keep exactly one strong reference alive when mutating/highlighting\n// drop any cached clones before the update/highlight cycle\ndrop(cached_editors.values()); // if you keep a map of clones, clear it first\neditor.update(bounds, font, size, line_height, wrapping, alignment, hint, &mut highlighter);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never clone() an Editor you intend to mutate or highlight; move or borrow it","Use editor.downgrade() (Weak) for read-only sharing; Weak does not block Arc::try_unwrap","Give each widget its own editor state instead of sharing one instance","Audit caches that outlive the widget tree for stashed editor clones"],"tags":["rust","iced","editor","arc","ownership","clone"],"backgroundTag":"arc-multiple-strong-references","analyzedSha":"3de451447bd28217bb535632867550908e29d5d0","analyzedAt":"2026-08-17T10:40:26.997Z","contentChangedAt":"2026-08-17T10:40:26.997Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}