Skip to content
This repository has been archived by the owner on Mar 20, 2023. It is now read-only.

async-caop-uri-macros: rewrote and updated them #32

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Luro02
Copy link
Contributor

@Luro02 Luro02 commented Apr 26, 2020

I updated the proc-macros to use the latest versions of syn and quote and improved the error messages by using syn::Error and Spans.

For example this error message is now returned

error: ascii control chars are forbidden for security reasons
 --> $DIR/escaped_ascii_control.rs:7:29
  |
7 |     assert_rel_ref_literal!("https://www.example.com/a/%00/c");
  |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

which previously was

error: proc-macro derive panicked
 --> src/main.rs:4:5
  |
4 |     uri!("https://www.example.com/a/%00/c");
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: message: Malformed percent encoding at index 29
  = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

In the future it would be possible to further improve the error messages to

error: ascii control chars are forbidden for security reasons
 --> $DIR/escaped_ascii_control.rs:7:29
  |
7 |     assert_rel_ref_literal!("https://www.example.com/a/%00/c");
  |                                                        ^^^
  |
  = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

but this requires proc_macro::Literal::subspan to be stable.


I had to add proc-macro2 as a dependency, because syn only returns proc-macro2 types and the conversion between proc-macro and proc-macro2 is not always possible.


For the new error messages I added trybuild, which allows to test the stderr returned by proc-macros. I set up some basic tests for some of them, but not all of them.


I also improved the verification of the uri encoding, by removing a lot of redundant code and simplifying the remaining code, which should have improved the parsing speed :)

@darconeous darconeous self-requested a review June 4, 2021 17:08
@darconeous
Copy link
Contributor

Sorry for the delay in reviewing this!

Whoah! This is a big pull request. I'll try to get it reviewed this weekend. The proc macros stuff definitely needed some love.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants