Skip to content

Commit

Permalink
fluent_macro: fix diagnostics for fluent parse failures
Browse files Browse the repository at this point in the history
This line number calculation was both wrong and unnecessary.
  • Loading branch information
Xiretza committed Sep 17, 2024
1 parent 0a25324 commit 5b3bde9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 22 deletions.
17 changes: 0 additions & 17 deletions compiler/rustc_fluent_macro/src/fluent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,25 +138,8 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok
// with a lowercase as rustc errors do.
err.replace_range(0..1, &err.chars().next().unwrap().to_lowercase().to_string());

let line_starts: Vec<usize> = std::iter::once(0)
.chain(
this.source()
.char_indices()
.filter_map(|(i, c)| Some(i + 1).filter(|_| c == '\n')),
)
.collect();
let line_start = line_starts
.iter()
.enumerate()
.map(|(line, idx)| (line + 1, idx))
.filter(|(_, idx)| **idx <= pos.start)
.last()
.unwrap()
.0;

let message = annotate_snippets::Level::Error.title(&err).snippet(
Snippet::source(this.source())
.line_start(line_start)
.origin(&relative_ftl_path)
.fold(true)
.annotation(annotate_snippets::Level::Error.span(pos.start..pos.end - 1)),
Expand Down
10 changes: 5 additions & 5 deletions tests/ui-fulldeps/fluent-messages/test.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ LL | rustc_fluent_macro::fluent_messages! { "./many-lines.ftl" }
= help: see additional errors emitted

error: expected a message field for "no_crate_bar"
--> ./many-lines.ftl:15:1
|
15 | no_crate_bar =
| ^^^^^^^^^^^^^^
|
--> ./many-lines.ftl:8:1
|
8 | no_crate_bar =
| ^^^^^^^^^^^^^^
|

error: aborting due to 14 previous errors

0 comments on commit 5b3bde9

Please sign in to comment.