From 5704ae0d83f0537f7cb5131b6e55e7f4b1fa0770 Mon Sep 17 00:00:00 2001 From: Shafkath Shuhan Date: Fri, 9 Jul 2021 11:22:22 -0400 Subject: [PATCH] move out reference variable --- helix-term/src/ui/editor.rs | 49 ++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 0cdbacfaf59e..51f8c6fb59f3 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -123,36 +123,35 @@ impl EditorView { }; // TODO: range doesn't actually restrict source, just highlight range - let highlights: Vec<_> = match doc.syntax() { - Some(syntax) => { - let scopes = theme.scopes(); - syntax - .highlight_iter(text.slice(..), Some(range), None, |language| { - loader - .language_config_for_scope(&format!("source.{}", language)) - .and_then(|language_config| { - let config = language_config.highlight_config(scopes)?; - let config_ref = { - let reference = config.as_ref(); + let highlights: Vec<_> = + match doc.syntax() { + Some(syntax) => { + let scopes = theme.scopes(); + syntax + .highlight_iter(text.slice(..), Some(range), None, |language| { + loader + .language_config_for_scope(&format!("source.{}", language)) + .and_then(|language_config| { + let config = language_config.highlight_config(scopes)?; + let config_ref = config.as_ref(); // Safe because the referenced `HighglightConfiguration` is behind // an `Arc` that will never be dropped in this function. - unsafe { + let config_ref = unsafe { std::mem::transmute::< _, &'static syntax::HighlightConfiguration, - >(reference) - } - }; - Some(config_ref) - }) - }) - .collect() // TODO: we collect here to avoid holding the lock, fix later - } - None => vec![Ok(HighlightEvent::Source { - start: range.start, - end: range.end, - })], - }; + >(config_ref) + }; + Some(config_ref) + }) + }) + .collect() // TODO: we collect here to avoid holding the lock, fix later + } + None => vec![Ok(HighlightEvent::Source { + start: range.start, + end: range.end, + })], + }; let mut spans = Vec::new(); let mut visual_x = 0u16; let mut line = 0u16;