Skip to content

Commit 8b36ecb

Browse files
authored
Rollup merge of #129477 - Xiretza:fix-fluent-diagnostics, r=compiler-errors
Fix fluent diagnostics This line number calculation was both wrong and unnecessary.
2 parents e9e13a6 + 5b3bde9 commit 8b36ecb

File tree

4 files changed

+32
-18
lines changed

4 files changed

+32
-18
lines changed

Diff for: compiler/rustc_fluent_macro/src/fluent.rs

-17
Original file line numberDiff line numberDiff line change
@@ -138,25 +138,8 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok
138138
// with a lowercase as rustc errors do.
139139
err.replace_range(0..1, &err.chars().next().unwrap().to_lowercase().to_string());
140140

141-
let line_starts: Vec<usize> = std::iter::once(0)
142-
.chain(
143-
this.source()
144-
.char_indices()
145-
.filter_map(|(i, c)| Some(i + 1).filter(|_| c == '\n')),
146-
)
147-
.collect();
148-
let line_start = line_starts
149-
.iter()
150-
.enumerate()
151-
.map(|(line, idx)| (line + 1, idx))
152-
.filter(|(_, idx)| **idx <= pos.start)
153-
.last()
154-
.unwrap()
155-
.0;
156-
157141
let message = annotate_snippets::Level::Error.title(&err).snippet(
158142
Snippet::source(this.source())
159-
.line_start(line_start)
160143
.origin(&relative_ftl_path)
161144
.fold(true)
162145
.annotation(annotate_snippets::Level::Error.span(pos.start..pos.end - 1)),

Diff for: tests/ui-fulldeps/fluent-messages/many-lines.ftl

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
no_crate_foo = foo
2+
3+
# This file tests error reporting for
4+
# fluent files with many lines.
5+
# The error message should point to the correct line number
6+
# and include no more context than necessary.
7+
8+
no_crate_bar =
9+
10+
no_crate_baz =
11+
baz

Diff for: tests/ui-fulldeps/fluent-messages/test.rs

+5
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,8 @@ mod bad_escape {
8080
//~| ERROR invalid escape `\"`
8181
//~| ERROR invalid escape `\'`
8282
}
83+
84+
mod many_lines {
85+
rustc_fluent_macro::fluent_messages! { "./many-lines.ftl" }
86+
//~^ ERROR could not parse Fluent resource
87+
}

Diff for: tests/ui-fulldeps/fluent-messages/test.stderr

+16-1
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,20 @@ LL | rustc_fluent_macro::fluent_messages! { "./invalid-escape.ftl" }
103103
|
104104
= note: Fluent does not interpret these escape sequences (<https://projectfluent.org/fluent/guide/special.html>)
105105

106-
error: aborting due to 13 previous errors
106+
error: could not parse Fluent resource
107+
--> $DIR/test.rs:85:44
108+
|
109+
LL | rustc_fluent_macro::fluent_messages! { "./many-lines.ftl" }
110+
| ^^^^^^^^^^^^^^^^^^
111+
|
112+
= help: see additional errors emitted
113+
114+
error: expected a message field for "no_crate_bar"
115+
--> ./many-lines.ftl:8:1
116+
|
117+
8 | no_crate_bar =
118+
| ^^^^^^^^^^^^^^
119+
|
120+
121+
error: aborting due to 14 previous errors
107122

0 commit comments

Comments
 (0)