Skip to content

Commit

Permalink
Add short comment explaining the macro error "recovery trick"
Browse files Browse the repository at this point in the history
  • Loading branch information
Veykril committed Oct 9, 2021
1 parent 57892f5 commit e695387
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tokio-macros/src/lib.rs
Expand Up @@ -187,6 +187,8 @@ use proc_macro::TokenStream;
pub fn main(args: TokenStream, item: TokenStream) -> TokenStream {
entry::main(args, item.clone(), true).unwrap_or_else(|err| {
let mut output: TokenStream = err.to_compile_error().into();
// Append the item in case of errors so that IDEs can still properly resolve the annotated
// item in the attribute expansion in case of failure
output.extend(item);
output
})
Expand Down Expand Up @@ -237,6 +239,8 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream {
pub fn main_rt(args: TokenStream, item: TokenStream) -> TokenStream {
entry::main(args, item.clone(), false).unwrap_or_else(|err| {
let mut output: TokenStream = err.to_compile_error().into();
// Append the item in case of errors so that IDEs can still properly resolve the annotated
// item in the attribute expansion in case of failure
output.extend(item);
output
})
Expand Down Expand Up @@ -287,6 +291,8 @@ pub fn main_rt(args: TokenStream, item: TokenStream) -> TokenStream {
pub fn test(args: TokenStream, item: TokenStream) -> TokenStream {
entry::test(args, item.clone(), true).unwrap_or_else(|err| {
let mut output: TokenStream = err.to_compile_error().into();
// Append the item in case of errors so that IDEs can still properly resolve the annotated
// item in the attribute expansion in case of failure
output.extend(item);
output
})
Expand All @@ -313,6 +319,8 @@ pub fn test(args: TokenStream, item: TokenStream) -> TokenStream {
pub fn test_rt(args: TokenStream, item: TokenStream) -> TokenStream {
entry::test(args, item.clone(), false).unwrap_or_else(|err| {
let mut output: TokenStream = err.to_compile_error().into();
// Append the item in case of errors so that IDEs can still properly resolve the annotated
// item in the attribute expansion in case of failure
output.extend(item);
output
})
Expand Down

0 comments on commit e695387

Please sign in to comment.