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

Difference in error message when switching from proc-macro-error #1

Closed
zhassan-aws opened this issue Sep 5, 2024 · 2 comments
Closed

Comments

@zhassan-aws
Copy link

zhassan-aws commented Sep 5, 2024

Thank you for creating this fork of proc-macro-error. We've switched to proc-macro-error2 in model-checking/kani#3493, but we observed a difference in the emitted error.

With proc-macro-error, the error was:

error: Cannot derive `Arbitrary` for `Wrapper` union
 --> union.rs:5:10
  |
5 | #[derive(kani::Arbitrary)]
  |          ^^^^^^^^^^^^^^^
  |
note: `#[derive(Arbitrary)]` cannot be used for unions such as `Wrapper`
 --> union.rs:6:7
  |
6 | union Wrapper {
  |       ^^^^^^^
  = note: this error originates in the derive macro `kani::Arbitrary` (in Nightly builds, run with -Z macro-backtrace for more info)

With proc-macro-error2, the error is:

error: Cannot derive `Arbitrary` for `Wrapper` union
       
         = note: `#[derive(Arbitrary)]` cannot be used for unions such as `Wrapper`
       
 --> union.rs:5:10
  |
5 | #[derive(kani::Arbitrary)]
  |          ^^^^^^^^^^^^^^^
  |
  = note: this error originates in the derive macro `kani::Arbitrary` (in Nightly builds, run with -Z macro-backtrace for more info)

The two notable differences are:

  1. The annotated item (union Wrapper) is no longer included in the error
  2. The first note does not appear after the span.

Is the difference expected?

This is the code that emits the error:

https://github.com/model-checking/kani/blob/701f6fb8e26acf0c31f053cc1503a4139b277e29/library/kani_macros/src/derive.rs#L89

@GnomedDev
Copy link
Owner

GnomedDev commented Sep 6, 2024

The only thing I can think to have caused this is that it is no longer doing hacky nightly detection to use the unstable Diagnostic API. If you enable the nightly feature of this crate does it revert the error messages back?

I am personally against automatic nightly detection as it causes huge headaches for everyone in the ecosystem as people can unknowingly be using unstable features when just using the nightly toolchain for other reasons.

@zhassan-aws
Copy link
Author

If you enable the nightly feature of this crate does it revert the error messages back?

Using the nightly feature does the trick!

$ diff -u without_nightly.log with_nightly.log 
--- without_nightly.log 2024-09-06 16:41:20.185980525 -0700
+++ with_nightly.log    2024-09-06 16:39:56.254197678 -0700
@@ -1,13 +1,15 @@
 Kani Rust Verifier 0.55.0 (standalone)
 error: Cannot derive `Arbitrary` for `Wrapper` union
-       
-         = note: `#[derive(Arbitrary)]` cannot be used for unions such as `Wrapper`
-       
  --> union.rs:5:10
   |
 5 | #[derive(kani::Arbitrary)]
   |          ^^^^^^^^^^^^^^^
   |
+note: `#[derive(Arbitrary)]` cannot be used for unions such as `Wrapper`
+ --> union.rs:6:7
+  |
+6 | union Wrapper {
+  |       ^^^^^^^
   = note: this error originates in the derive macro `kani::Arbitrary` (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: aborting due to 1 previous error

Thanks! I'll close this issue.

@GnomedDev GnomedDev pinned this issue Sep 6, 2024
github-merge-queue bot pushed a commit to model-checking/kani that referenced this issue Sep 7, 2024
As suggested in
GnomedDev/proc-macro-error-2#1 (comment),
turning on the `nightly` feature for `proc-macro-error2` to restore the
previous error message for `derive(Arbitrary)`.

Resolves #3495 

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 and MIT licenses.
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

No branches or pull requests

2 participants