- Notifications
You must be signed in to change notification settings - Fork47
Open
Description
I have code like the following
fntypo_to_group<'t>(msg:&'tTypo<'t>) ->Group<'t>{let title =match&msg.corrections{ typos::Status::Valid =>unimplemented!("never valid words to report"), typos::Status::Invalid =>{format!("`{}` is disallowed", msg.typo,)} typos::Status::Corrections(corrections) =>{format!("`{}` should be {}", msg.typo, itertools::join(corrections.iter().map(|s| format!("`{s}`")),", "))}};let group =Group::with_title(Level::ERROR.primary_title(Cow::Owned(title)));let group =match&msg.context{Some(Context::File(context)) =>{let path = context.path.as_os_str().to_string_lossy();let line =String::from_utf8_lossy(msg.buffer.as_ref());let snippet =Snippet::source(line).path(path).line_start(context.line_num);append_corrections(msg,0, snippet, group)}Some(Context::Path(context)) =>{let path = context.path.parent().unwrap_or(std::path::Path::new(".")).join("");let path = path.as_os_str().to_string_lossy();let line = context.path.as_os_str().to_string_lossy();let snippet =Snippet::source(line);append_corrections(msg, path.len(), snippet, group)}Some(_) |None => group,}; group}fnappend_corrections<'t>(msg:&'tTypo<'t>,offset:usize,snippet:Snippet<'t,Annotation<'t>>,group:Group<'t>,) ->Group<'t>{let span_start = msg.byte_offset + offset;let span_end = span_start + msg.typo.len();let span = span_start..span_end;match&msg.corrections{ typos::Status::Valid =>unimplemented!("never valid words to report"), typos::Status::Invalid =>{let snippet = snippet.annotation(AnnotationKind::Primary.span(span)); group.element(snippet)} typos::Status::Corrections(corrections) =>{let snippet = snippet.annotation(AnnotationKind::Primary.span(span)); group.element(snippet)}}}
The problem is that I want to make theCorrections variant inappend_corrections usePatch but can't because the passed insnippet has to have one specific type.
One option is for us to createSnippets withT = () and thenannotation can convert it toT= Annotation andpatch toT= Patch.