diff --git a/crates/repl_cli/src/repl_state.rs b/crates/repl_cli/src/repl_state.rs index f3bb1acf5b..a1dcf38fc3 100644 --- a/crates/repl_cli/src/repl_state.rs +++ b/crates/repl_cli/src/repl_state.rs @@ -214,9 +214,34 @@ impl ReplState { } }; - // TODO filter out UNUSED warnings for all past_def_ident entries - // TODO allow turning off printing of warnings - format_output(output, problems) + format_output(output, problems, |warning| { + // Filter out UNUSED warnings for entries in past_def_idents, + // since otherwise those are totally unhelpful and very annoying! + // + // Obviously doing string matching on the error message itself is a + // brittle and hacky way to do this. It would be nice in the future to + // thread the authoritative information through here, but that's + // too large a change to justify in the first (already very large) + // implementation of the "remembered defs" feature! + const UNUSED_DEF_SHORT_PREFIX: &str = "\u{1b}[36m── UNUSED DEFINITION ─"; + const UNUSED_DEF_FULL_PREFIX:&str = "\u{1b}[36m── UNUSED DEFINITION ───────────────────────────────────────────────────────────\u{1b}[0m\n\n\u{1b}[34m"; + + if warning.starts_with(UNUSED_DEF_SHORT_PREFIX) { + let ident_start = &warning[UNUSED_DEF_FULL_PREFIX.len()..]; + + if let Some(ident_len) = ident_start.find("\u{1b}[0m") { + let ident = &ident_start[..ident_len]; + + // If this is an unused definition warning for an entry + // in our past_def_idents, filter it out. + if self.past_def_idents.contains(ident) { + return false; + } + } + } + + true + }) } fn next_auto_ident(&mut self) -> u64 { @@ -398,11 +423,20 @@ impl Validator for ReplState { } } -fn format_output(opt_output: Option, problems: Problems) -> String { +fn format_output bool>( + opt_output: Option, + problems: Problems, + warning_filter: F, +) -> String { let mut buf = String::new(); // Join all the warnings and errors together with blank lines. - for message in problems.warnings.iter().chain(problems.errors.iter()) { + for message in problems + .warnings + .iter() + .filter(warning_filter) + .chain(problems.errors.iter()) + { if !buf.is_empty() { buf.push_str("\n\n"); }