(&self, f: &mut std::fmt::Formatter)
| 13 | |
| 14 | impl std::fmt::Debug for Errors { |
| 15 | fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { |
| 16 | if self.errors.is_empty() { |
| 17 | return Ok(()); |
| 18 | } |
| 19 | let diagnostics = Vec::from_iter(self.errors.iter().map(|e| { |
| 20 | let message = match e { |
| 21 | Error::IoError { context, .. } => context.clone(), |
| 22 | Error::ParseError { msg, .. } => format!("parse error: {msg}"), |
| 23 | Error::TypeError { msg, .. } => format!("type error: {msg}"), |
| 24 | Error::UnreachableError { msg, .. } => format!("unreachable rule: {msg}"), |
| 25 | Error::OverlapError { msg, .. } => format!("overlap error: {msg}"), |
| 26 | Error::RecursionError { msg, .. } => format!("recursion error: {msg}"), |
| 27 | Error::ShadowedError { .. } => { |
| 28 | "more general higher-priority rule shadows other rules".to_string() |
| 29 | } |
| 30 | }; |
| 31 | |
| 32 | let labels = match e { |
| 33 | Error::IoError { .. } => vec![], |
| 34 | |
| 35 | Error::ParseError { span, .. } |
| 36 | | Error::TypeError { span, .. } |
| 37 | | Error::UnreachableError { span, .. } |
| 38 | | Error::RecursionError { span, .. } => { |
| 39 | vec![Label::primary(span.from.file, span)] |
| 40 | } |
| 41 | |
| 42 | Error::OverlapError { rules, .. } => { |
| 43 | let mut labels = vec![Label::primary(rules[0].from.file, &rules[0])]; |
| 44 | labels.extend( |
| 45 | rules[1..] |
| 46 | .iter() |
| 47 | .map(|span| Label::secondary(span.from.file, span)), |
| 48 | ); |
| 49 | labels |
| 50 | } |
| 51 | |
| 52 | Error::ShadowedError { shadowed, mask } => { |
| 53 | let mut labels = vec![Label::primary(mask.from.file, mask)]; |
| 54 | labels.extend( |
| 55 | shadowed |
| 56 | .iter() |
| 57 | .map(|span| Label::secondary(span.from.file, span)), |
| 58 | ); |
| 59 | labels |
| 60 | } |
| 61 | }; |
| 62 | |
| 63 | let mut sources = Vec::new(); |
| 64 | let mut source = e.source(); |
| 65 | while let Some(e) = source { |
| 66 | sources.push(format!("{e:?}")); |
| 67 | source = std::error::Error::source(e); |
| 68 | } |
| 69 | |
| 70 | Diagnostic::error() |
| 71 | .with_message(message) |
| 72 | .with_labels(labels) |
nothing calls this directly
no test coverage detected