diff --git a/src/format_report_formatter.rs b/src/format_report_formatter.rs index fd536d4df41..9c744b8e2ef 100644 --- a/src/format_report_formatter.rs +++ b/src/format_report_formatter.rs @@ -78,7 +78,7 @@ impl<'a> Display for FormatReportFormatter<'a> { None }; - let origin = format!("{}:{}", file, error.line); + let origin = file.to_string(); let slice = Slice { source: &error.line_buffer.clone(), line_start: error.line, diff --git a/src/formatting.rs b/src/formatting.rs index cd57a025b67..dd13a28f704 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -645,3 +645,32 @@ where f(); } } + +#[cfg(test)] +mod test { + use std::path::PathBuf; + + use crate::FormatReportFormatterBuilder; + + use super::*; + + #[test] + fn test_internal_error_file_and_line_number_annotations() { + let mut config = Config::default(); + config.set().error_on_unformatted(true); + + let mut text = String::new(); + text.push_str("fn main() {\n"); + text.push_str(" println!(\"hello world!\"); \n"); // Note the space before the '\n' + text.push_str("}"); + + let report = FormatReport::new(); + let name = FileName::Real(PathBuf::from("internal_error_test.rs")); + + format_lines(&mut text, &name, &vec![], &config, &report); + let output = FormatReportFormatterBuilder::new(&report) + .build() + .to_string(); + assert!(output.contains("--> internal_error_test.rs:2:30")); + } +}