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

Swap to Proc Macro Error 2 RUSTSEC-2024-0370 #350

Merged
merged 15 commits into from
Oct 25, 2024
Merged

Conversation

pvichivanives
Copy link
Contributor

@pvichivanives pvichivanives commented Sep 6, 2024

Hi!
Given the RUSTSEC warning issued here: https://rustsec.org/advisories/RUSTSEC-2024-0370 just submitting a PR to move to the reccomended new version of procmacroerror2
image

Closes #351

@jayvdb
Copy link

jayvdb commented Sep 8, 2024

Please run the tests with TRYBUILD=overwrite set.

@jayvdb
Copy link

jayvdb commented Sep 11, 2024

ping @Keats

@pvichivanives
Copy link
Contributor Author

pvichivanives commented Sep 12, 2024

Apparently the error messages between 1.79 and 1.81 are different. I've pushed the error messages for 1.79 since it seems thats what the CI test was failing on fist. However, one will always fail. This is true on the master branch as well.

darling = { version = "0.20", features = ["suggestions"] }
once_cell = "1.18.0"

[features]
nightly = ["proc-macro-error2/nightly"]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can the name be more clear somehow?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nightly_features?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, I don't even know what this does in proc-macro-error2

Copy link
Contributor Author

@pvichivanives pvichivanives Sep 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the nightly feature in proc-macro-error2 its just a different implementation for emitting diagnostics and aborting. The main difference between the two appear to be that warnings are emitted in nightly while ignored in non-nightly builds. Tagging @HigherOrderLogic since they requested this.

I also think its fine if the feature isn't included since Validator might not want to use these extra warnings anyway. Might be a good idea to move this to a different PR for another discussion.

If you want to look at the code its here: https://github.com/GnomedDev/proc-macro-error-2/tree/master/src/imp
The delegate.rs is the nightly version and fallback.rs is the non nightly version

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, I don't even know what this does in proc-macro-error2

It's as @pvichivanives said, this feature enables emitting warning when using nightly compiler, otherwise ignored.

So to match the function, I think this feature can be renamed to nightly-warnning, or nightly-proc-macro, or even the longer nightly-proc-macro-error

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've written this in #351, but I'd like to point it out here too: proc-macro-error2 fundamentally does not do the same thing as proc-macro-error, which is to avoid the need to have the user switch on a separate crate feature to get better proc macro diagnostics on nightly. The entire point of proc-macro-error is that both sets of error reporting functionality (via compiler_error! or via the nightly proc macro diagnostics API) are available to proc macro authors already, but instead of the library author having to decide (or add a feature), whether the nightly APIs can be used is detected at build time via build.rs. Using proc-macro-error2 still provides a shim around #[cfg(nightly_macro_diagnostics)] so there's a single API for the macro code no matter the compiler version, but doesn't do the auto-detection.

If this is fine for you @Keats, then this might not be a concern for this PR, but you should make sure that this is actually what you want. In particular, I've linked a different crate in the issue above (proc-macro2-diagnostics) that's a similar kind of drop-in replacement but which does do the build-time compiler detection. To me, this would definitely be preferable because IMO the point of using proc-macro-error is to automatically give good error messages where possible. At minimum, if you decide to go forwards with this PR and proc-macro-error2, the feature should receive some documentation in the crate docs. Otherwise, no one's gonna know what it does or turn it on, because most even nitghtly users will probably not know what a proc-macro-error2 is or what it does and that they could be getting much better error messages (which again is why I think it would be better if they didn't have to know at all).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly I don't really care which version gets used. The least disturbance the better though. If someone took proc-macro-error and just bumped syn without any other changes it would be fine. But I agree that needing a feature for some nightly stuff is not great

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to swap over the pr/close this pr if you would want to make one @domenicquirl. Am slightly concerned though that proc-macro2-diagnostics has 1 commit in the last 12 months, being a version bump which hasn't been released yet (last release was around 1year ago). Also SergioBenitez/version_check#23 <- for this as a rust team dev pointed out they would prefer people didn't automatically detect nightly.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't be too worried about that, Sergio has been active in the issues over there as recent as a month ago. It's just a small crate that doesn't need lots of updating.

Aside from that, point taken on nightly detection in general. It's maybe worth pointing out that there's also a PR to proc-macro2-diagnostics that tries to put their nightly detection (the detection itself, not the usage of the nightly APIs) behind a feature flag.

Personally, I don't use validator in a nightly context, which means I don't get nice diagnostics either way, so I probably won't push for a specific alternative solution as long as the syn version gets bumped with the switch. Just wanted to make sure that the change in behaviour is known, and as I said above I think you should add a section to the top-level crate docs that explains that this feature exists and what it does. Otherwise I'm pretty sure most people will miss it or see it and have a hard time figuring out what it does.

@pvichivanives
Copy link
Contributor Author

pvichivanives commented Oct 3, 2024

Interesting, its definitely all passing locally for me except for the error message issue that I mentioned earlier. IS CI turning all feature flags to true?

@Keats
Copy link
Owner

Keats commented Oct 4, 2024

It does: https://github.com/Keats/validator/blob/master/.github/workflows/ci.yml#L25-L28

@pvichivanives
Copy link
Contributor Author

TY! Haven't used the github workflow before so didn't know ci was there. Updated it to only run all the feature flags. Still that issue though of the TRYBUILD=overwrite set where rn its set to 1.70. I can set it to 1.81 as well but that then we would fail. The wording was changed in 1.81. So I also bumped the tests MSRV to 1.81 but I can rever that commit if not desired.

cargo build --features unic --features derive --features card
cargo test --features unic --features derive --features card
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between those diffs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This takes out the 'derive_nightly_features' feature since that doesn't work with rust stable.

If you mean between the two like between two lines not really anything

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a nightly CI run that enables all the features? Otherwise that feature is never tested

@Keats
Copy link
Owner

Keats commented Oct 14, 2024

That looks ok to me. Ok for everyone else as well?

@pvichivanives
Copy link
Contributor Author

pvichivanives commented Oct 14, 2024

Wanted to note that we have an issue with Workflow though in that Nightly uses different highlighting to stable. This is expected since we are enabling the NIGHTLY warnings. Going to see if I can fix that later in another PR but for now I have try-build fail disabled with all-features
image

@Keats
Copy link
Owner

Keats commented Oct 16, 2024

Maybe just try to build in CI using nightly rather than run the test?

@pvichivanives
Copy link
Contributor Author

Happy to just build in CI too, I thought it might be more useful if we at least run all the tests we can though.

@pvichivanives pvichivanives requested a review from Keats October 22, 2024 17:46
@Keats Keats merged commit b06dbc6 into Keats:master Oct 25, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Get rid of proc-macro-error (RUSTSEC-2024-0370 and syn version)
5 participants