MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / parse_header

Function parse_header

src/diagnose.rs:96–117  ·  view source on GitHub ↗

Parses a diagnostic header line: `error[E0308]: mismatched types` `warning: unused variable` `error: useless conversion ...`

(line: &str)

Source from the content-addressed store, hash-verified

94/// `warning: unused variable`
95/// `error: useless conversion ...`
96fn parse_header(line: &str) -> Option<(Severity, Option<String>, String)> {
97 // ANSI escapes can appear when cargo is run with `--color=always`; strip
98 // a leading reset sequence if present. We don't bother with full ANSI
99 // stripping — the typical input is plain text.
100 let line = line.trim_start_matches("\u{1b}[0m");
101
102 // Find the first colon. Severity is everything before it (optionally
103 // followed by `[CODE]`). Message is everything after.
104 let (head, rest) = line.split_once(": ")?;
105 let (sev_token, code) = if let Some(idx) = head.find('[') {
106 if !head.ends_with(']') {
107 return None;
108 }
109 let sev = &head[..idx];
110 let code = &head[idx + 1..head.len() - 1];
111 (sev, Some(code.to_string()))
112 } else {
113 (head, None)
114 };
115 let severity = Severity::parse(sev_token.trim())?;
116 Some((severity, code, rest.trim().to_string()))
117}
118
119/// Parses a primary-span line:
120/// ` --> src/foo.rs:42:10`

Callers 1

parse_cargo_outputFunction · 0.85

Calls 1

parseFunction · 0.70

Tested by

no test coverage detected