Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fluent_messages macro: don't emit the OS error in a note #109798

Merged
merged 2 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions compiler/rustc_macros/src/diagnostics/fluent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ use proc_macro2::TokenStream;
use quote::quote;
use std::{
collections::{HashMap, HashSet},
fs::File,
io::Read,
fs::read_to_string,
path::{Path, PathBuf},
};
use syn::{parse_macro_input, Ident, LitStr};
Expand Down Expand Up @@ -95,22 +94,18 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok

// As this macro also outputs an `include_str!` for this file, the macro will always be
// re-executed when the file changes.
let mut resource_file = match File::open(absolute_ftl_path) {
Ok(resource_file) => resource_file,
let resource_contents = match read_to_string(absolute_ftl_path) {
Ok(resource_contents) => resource_contents,
Err(e) => {
Diagnostic::spanned(resource_span, Level::Error, "could not open Fluent resource")
.note(e.to_string())
.emit();
Diagnostic::spanned(
resource_span,
Level::Error,
format!("could not open Fluent resource: {}", e.to_string()),
)
.emit();
return failed(&crate_name);
}
};
let mut resource_contents = String::new();
if let Err(e) = resource_file.read_to_string(&mut resource_contents) {
Diagnostic::spanned(resource_span, Level::Error, "could not read Fluent resource")
.note(e.to_string())
.emit();
return failed(&crate_name);
}
let mut bad = false;
for esc in ["\\n", "\\\"", "\\'"] {
for _ in resource_contents.matches(esc) {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui-fulldeps/fluent-messages/test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// normalize-stderr-test "note.*" -> "note: os-specific message"
// normalize-stderr-test "could not open Fluent resource:.*" -> "could not open Fluent resource: os-specific message"

#![feature(rustc_private)]
#![crate_type = "lib"]
Expand Down
14 changes: 5 additions & 9 deletions tests/ui-fulldeps/fluent-messages/test.stderr
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
error: could not open Fluent resource
error: could not open Fluent resource: os-specific message
--> $DIR/test.rs:24:24
|
LL | fluent_messages! { "/definitely_does_not_exist.ftl" }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: os-specific message

error: could not open Fluent resource
error: could not open Fluent resource: os-specific message
--> $DIR/test.rs:31:24
|
LL | fluent_messages! { "../definitely_does_not_exist.ftl" }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: os-specific message

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

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

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

error: aborting due to 13 previous errors