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 https://github.com/rust-lang/rust/pull/109700#discussion_r1152489053
This commit is contained in:
Guillaume Gomez 2023-03-31 22:32:50 +02:00 committed by GitHub
commit bd4e3f37da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 24 deletions

View file

@ -15,8 +15,7 @@ use proc_macro2::TokenStream;
use quote::quote; use quote::quote;
use std::{ use std::{
collections::{HashMap, HashSet}, collections::{HashMap, HashSet},
fs::File, fs::read_to_string,
io::Read,
path::{Path, PathBuf}, path::{Path, PathBuf},
}; };
use syn::{parse_macro_input, Ident, LitStr}; use syn::{parse_macro_input, Ident, LitStr};
@ -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 // As this macro also outputs an `include_str!` for this file, the macro will always be
// re-executed when the file changes. // re-executed when the file changes.
let mut resource_file = match File::open(absolute_ftl_path) { let resource_contents = match read_to_string(absolute_ftl_path) {
Ok(resource_file) => resource_file, Ok(resource_contents) => resource_contents,
Err(e) => { Err(e) => {
Diagnostic::spanned(resource_span, Level::Error, "could not open Fluent resource") Diagnostic::spanned(
.note(e.to_string()) resource_span,
.emit(); Level::Error,
format!("could not open Fluent resource: {}", e.to_string()),
)
.emit();
return failed(&crate_name); 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; let mut bad = false;
for esc in ["\\n", "\\\"", "\\'"] { for esc in ["\\n", "\\\"", "\\'"] {
for _ in resource_contents.matches(esc) { for _ in resource_contents.matches(esc) {

View file

@ -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)] #![feature(rustc_private)]
#![crate_type = "lib"] #![crate_type = "lib"]

View file

@ -1,18 +1,14 @@
error: could not open Fluent resource error: could not open Fluent resource: os-specific message
--> $DIR/test.rs:24:24 --> $DIR/test.rs:24:24
| |
LL | fluent_messages! { "/definitely_does_not_exist.ftl" } 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 --> $DIR/test.rs:31:24
| |
LL | fluent_messages! { "../definitely_does_not_exist.ftl" } LL | fluent_messages! { "../definitely_does_not_exist.ftl" }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: os-specific message
error: could not parse Fluent resource error: could not parse Fluent resource
--> $DIR/test.rs:38:24 --> $DIR/test.rs:38:24
@ -89,7 +85,7 @@ error: invalid escape `\n` in Fluent resource
LL | fluent_messages! { "./invalid-escape.ftl" } 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 error: invalid escape `\"` in Fluent resource
--> $DIR/test.rs:99:24 --> $DIR/test.rs:99:24
@ -97,7 +93,7 @@ error: invalid escape `\"` in Fluent resource
LL | fluent_messages! { "./invalid-escape.ftl" } 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 error: invalid escape `\'` in Fluent resource
--> $DIR/test.rs:99:24 --> $DIR/test.rs:99:24
@ -105,7 +101,7 @@ error: invalid escape `\'` in Fluent resource
LL | fluent_messages! { "./invalid-escape.ftl" } 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 error: aborting due to 13 previous errors