Emit shim implementation on macro error
Dependencies
- [2]
OWXLFLRMMerge `cli_macros` shim into `fluent_embed` - [3]
CESJ4CTOMove macro-specific code into `macro_impl` module - [4]
73C6NOJ7Fix minimal `Localize` implementation on errors - [5]
7JPOCQEIAdd explicit error handling for macro parsing - [6]
LU6IFZFGRemove `std::io::Write` trait bound from `Localize` - [7]
QJC4IQITRefactor `Localize` functions to infallibly return `String` - [8]
NEBSVXIAApply Clippy fixes - [9]
6XEMHUGSUse full `Locale` instead of `LanguageIdentifier` subset - [10]
RUCC2HKZRename from `fluent_embed` to `l10n_embed` - [11]
EKXWNEPKRename `Localize::message_for_locale` to `Localize::localize_for` - [12]
RA3H7PWCRefactor `Localize` for performance - [13]
PGBXJWIHMove `l10n_embed` re-exports into `macro_prelude` module - [14]
LIO32J4BFix compiler error when `expand` feature is disabled - [15]
XGRU7WZEAdd `expand` feature for proc-macro debugging - [*]
O77KA6C4Create `fluent_embed` crate
Change contents
- edit in l10n_embed_derive/src/lib.rs at line 16
// No errors found, emit the generated `l10n_embed::Localize` implementation - replacement in l10n_embed_derive/src/lib.rs at line 33
// Emit the relevant error messagemacro_impl::error::emit(error, &attribute_stream, &derive_input_stream);// Using the `proc_macro_error2` crate to generate errors ignores// the token stream returned from this function, so use the `set_dummy` function// to make sure a macro error is as self-contained as possible:// - Derive input streams are not consumed, so structs/enums don't "disappear" when macro returns error// - Generate a shim trait implementation when possible so that editor completions still work as expectedproc_macro_error2::set_dummy(match syn::parse2::<syn::DeriveInput>(derive_input_stream.clone()) {// Generate a minimal `Localize` implementation so the error is self-containedOk(derive_input) => {let ident = derive_input.ident;let (impl_generics, type_generics, where_clause) =derive_input.generics.split_for_impl(); - replacement in l10n_embed_derive/src/lib.rs at line 46
// Generate a minimal `Localize` implementation so the error is self-containedmatch syn::parse2::<syn::DeriveInput>(derive_input_stream.clone()) {Ok(derive_input) => {let ident = derive_input.ident;quote! {#derive_input_streamquote! {#derive_input_stream - replacement in l10n_embed_derive/src/lib.rs at line 49[9.1795]→[10.2022:2087](∅→∅),[10.2087]→[12.4287:4328](∅→∅),[6.476]→[5.2937:2976](∅→∅),[11.745]→[5.2937:2976](∅→∅),[7.1403]→[5.2937:2976](∅→∅),[12.4328]→[5.2937:2976](∅→∅),[5.2937]→[5.2937:2976](∅→∅),[5.2976]→[12.4329:4479](∅→∅),[7.1446]→[5.3194:3278](∅→∅),[12.4479]→[5.3194:3278](∅→∅),[5.3194]→[5.3194:3278](∅→∅)
impl ::l10n_embed::Localize for #ident {fn localize(&self,context: &::l10n_embed::Context,buffer: &mut String,) {unimplemented!("Encountered error in derive macro")impl #impl_generics ::l10n_embed::Localize for #ident #type_generics #where_clause {fn localize(&self,context: &::l10n_embed::Context,buffer: &mut String,) {unimplemented!("Encountered error in derive macro")} - replacement in l10n_embed_derive/src/lib.rs at line 60[3.5945]→[9.1874:1892](∅→∅),[9.1892]→[5.3354:3505](∅→∅),[5.3354]→[5.3354:3505](∅→∅),[5.3505]→[3.5963:5977](∅→∅),[3.5963]→[3.5963:5977](∅→∅)
}// Unable to fail gracefully if the ident is unknown, so just return the original inputErr(_) => derive_input_stream,}// Unable to implement Localize if the ident is unknown, so just return the original inputErr(_) => derive_input_stream.clone(),},);// Emit the relevant error messagemacro_impl::error::emit(error, &attribute_stream, &derive_input_stream);// `proc_macro_error2` will output the relevant token stream, but the function still needs to return somethingquote!()