Skip to content

Commit bd4e3f3

Browse files
Rollup merge of #109798 - est31:ftl_test_note, r=davidtwco
fluent_messages macro: don't emit the OS error in a note This makes it possible to make the normalization of the error message precise, allowing us to not normalize all notes away. See #109700 (comment)
2 parents 45fcb6f + 97fb15d commit bd4e3f3

File tree

3 files changed

+15
-24
lines changed

3 files changed

+15
-24
lines changed

compiler/rustc_macros/src/diagnostics/fluent.rs

+9-14
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ use proc_macro2::TokenStream;
1515
use quote::quote;
1616
use std::{
1717
collections::{HashMap, HashSet},
18-
fs::File,
19-
io::Read,
18+
fs::read_to_string,
2019
path::{Path, PathBuf},
2120
};
2221
use syn::{parse_macro_input, Ident, LitStr};
@@ -95,22 +94,18 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok
9594

9695
// As this macro also outputs an `include_str!` for this file, the macro will always be
9796
// re-executed when the file changes.
98-
let mut resource_file = match File::open(absolute_ftl_path) {
99-
Ok(resource_file) => resource_file,
97+
let resource_contents = match read_to_string(absolute_ftl_path) {
98+
Ok(resource_contents) => resource_contents,
10099
Err(e) => {
101-
Diagnostic::spanned(resource_span, Level::Error, "could not open Fluent resource")
102-
.note(e.to_string())
103-
.emit();
100+
Diagnostic::spanned(
101+
resource_span,
102+
Level::Error,
103+
format!("could not open Fluent resource: {}", e.to_string()),
104+
)
105+
.emit();
104106
return failed(&crate_name);
105107
}
106108
};
107-
let mut resource_contents = String::new();
108-
if let Err(e) = resource_file.read_to_string(&mut resource_contents) {
109-
Diagnostic::spanned(resource_span, Level::Error, "could not read Fluent resource")
110-
.note(e.to_string())
111-
.emit();
112-
return failed(&crate_name);
113-
}
114109
let mut bad = false;
115110
for esc in ["\\n", "\\\"", "\\'"] {
116111
for _ in resource_contents.matches(esc) {

tests/ui-fulldeps/fluent-messages/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// normalize-stderr-test "note.*" -> "note: os-specific message"
1+
// normalize-stderr-test "could not open Fluent resource:.*" -> "could not open Fluent resource: os-specific message"
22

33
#![feature(rustc_private)]
44
#![crate_type = "lib"]

tests/ui-fulldeps/fluent-messages/test.stderr

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
error: could not open Fluent resource
1+
error: could not open Fluent resource: os-specific message
22
--> $DIR/test.rs:24:24
33
|
44
LL | fluent_messages! { "/definitely_does_not_exist.ftl" }
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6-
|
7-
= note: os-specific message
86

9-
error: could not open Fluent resource
7+
error: could not open Fluent resource: os-specific message
108
--> $DIR/test.rs:31:24
119
|
1210
LL | fluent_messages! { "../definitely_does_not_exist.ftl" }
1311
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14-
|
15-
= note: os-specific message
1612

1713
error: could not parse Fluent resource
1814
--> $DIR/test.rs:38:24
@@ -89,23 +85,23 @@ error: invalid escape `\n` in Fluent resource
8985
LL | fluent_messages! { "./invalid-escape.ftl" }
9086
| ^^^^^^^^^^^^^^^^^^^^^^
9187
|
92-
= note: os-specific message
88+
= note: Fluent does not interpret these escape sequences (<https://projectfluent.org/fluent/guide/special.html>)
9389

9490
error: invalid escape `\"` in Fluent resource
9591
--> $DIR/test.rs:99:24
9692
|
9793
LL | fluent_messages! { "./invalid-escape.ftl" }
9894
| ^^^^^^^^^^^^^^^^^^^^^^
9995
|
100-
= note: os-specific message
96+
= note: Fluent does not interpret these escape sequences (<https://projectfluent.org/fluent/guide/special.html>)
10197

10298
error: invalid escape `\'` in Fluent resource
10399
--> $DIR/test.rs:99:24
104100
|
105101
LL | fluent_messages! { "./invalid-escape.ftl" }
106102
| ^^^^^^^^^^^^^^^^^^^^^^
107103
|
108-
= note: os-specific message
104+
= note: Fluent does not interpret these escape sequences (<https://projectfluent.org/fluent/guide/special.html>)
109105

110106
error: aborting due to 13 previous errors
111107

0 commit comments

Comments
 (0)