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

expected unsuffixed literal or identifier, found IN_ISDIR #122796

Closed
Thomasdezeeuw opened this issue Mar 20, 2024 · 11 comments
Closed

expected unsuffixed literal or identifier, found IN_ISDIR #122796

Thomasdezeeuw opened this issue Mar 20, 2024 · 11 comments
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) C-discussion Category: Discussion or questions that doesn't represent real issues. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Thomasdezeeuw
Copy link
Contributor

I have the following (open source) code: https://github.com/Thomasdezeeuw/heph/blob/1c7ee4af37627fcfb11749389973fa5e4a34a0bf/rt/src/fs/watch.rs#L354-L466. It's over a 100 lines and I'm not sure what is causing the issue.

This compiled fine since it was added to the repository, latest nightly compiler that is know to work is from rustc 1.78.0-nightly (c67326b06 2024-03-15).

However using the currently nightly compiler, 1.79.0-nightly (a7e4de13c 2024-03-19), fails to compile it giving the following errors:

error: expected unsuffixed literal or identifier, found `IN_ISDIR`
   --> rt/src/fs/watch.rs:454:23
    |
354 |     bit_checks!(self.event.mask);
    |     ---------------------------- in this macro invocation
...
454 |         #[doc(alias = $bit)]
    |                       ^^^^
    |
    = note: this error originates in the macro `bit_checks` (in Nightly builds, run with -Z macro-backtrace for more info)

error: expected unsuffixed literal or identifier, found `IN_ACCESS`
   --> rt/src/fs/watch.rs:454:23
    |
354 |     bit_checks!(self.event.mask);
    |     ---------------------------- in this macro invocation
...
454 |         #[doc(alias = $bit)]
    |                       ^^^^
    |
    = note: this error originates in the macro `bit_checks` (in Nightly builds, run with -Z macro-backtrace for more info)

error: expected unsuffixed literal or identifier, found `IN_MODIFY`
   --> rt/src/fs/watch.rs:454:23
    |
354 |     bit_checks!(self.event.mask);
    |     ---------------------------- in this macro invocation
...
454 |         #[doc(alias = $bit)]
    |                       ^^^^
    |
    = note: this error originates in the macro `bit_checks` (in Nightly builds, run with -Z macro-backtrace for more info)

error: expected unsuffixed literal or identifier, found `IN_ATTRIB`
   --> rt/src/fs/watch.rs:454:23
    |
354 |     bit_checks!(self.event.mask);
    |     ---------------------------- in this macro invocation
...
454 |         #[doc(alias = $bit)]
    |                       ^^^^
    |
    = note: this error originates in the macro `bit_checks` (in Nightly builds, run with -Z macro-backtrace for more info)

error: expected unsuffixed literal or identifier, found `IN_CLOSE_WRITE`
   --> rt/src/fs/watch.rs:454:23
    |
354 |     bit_checks!(self.event.mask);
    |     ---------------------------- in this macro invocation
...
454 |         #[doc(alias = $bit)]
    |                       ^^^^
    |
    = note: this error originates in the macro `bit_checks` (in Nightly builds, run with -Z macro-backtrace for more info)

error: expected unsuffixed literal or identifier, found `IN_CLOSE_NOWRITE`
   --> rt/src/fs/watch.rs:454:23
    |
354 |     bit_checks!(self.event.mask);
    |     ---------------------------- in this macro invocation
...
454 |         #[doc(alias = $bit)]
    |                       ^^^^
    |
    = note: this error originates in the macro `bit_checks` (in Nightly builds, run with -Z macro-backtrace for more info)

error: expected unsuffixed literal or identifier, found `IN_CLOSE`
   --> rt/src/fs/watch.rs:454:23
    |
354 |     bit_checks!(self.event.mask);
    |     ---------------------------- in this macro invocation
...
454 |         #[doc(alias = $bit)]
    |                       ^^^^
    |
    = note: this error originates in the macro `bit_checks` (in Nightly builds, run with -Z macro-backtrace for more info)

error: expected unsuffixed literal or identifier, found `IN_OPEN`
   --> rt/src/fs/watch.rs:454:23
    |
354 |     bit_checks!(self.event.mask);
    |     ---------------------------- in this macro invocation
...
454 |         #[doc(alias = $bit)]
    |                       ^^^^
    |
    = note: this error originates in the macro `bit_checks` (in Nightly builds, run with -Z macro-backtrace for more info)

error: expected unsuffixed literal or identifier, found `IN_DELETE_SELF`
   --> rt/src/fs/watch.rs:454:23
    |
354 |     bit_checks!(self.event.mask);
    |     ---------------------------- in this macro invocation
...
454 |         #[doc(alias = $bit)]
    |                       ^^^^
    |
    = note: this error originates in the macro `bit_checks` (in Nightly builds, run with -Z macro-backtrace for more info)

error: expected unsuffixed literal or identifier, found `IN_MOVE_SELF`
   --> rt/src/fs/watch.rs:454:23
    |
354 |     bit_checks!(self.event.mask);
    |     ---------------------------- in this macro invocation
...
454 |         #[doc(alias = $bit)]
    |                       ^^^^
    |
    = note: this error originates in the macro `bit_checks` (in Nightly builds, run with -Z macro-backtrace for more info)

error: expected unsuffixed literal or identifier, found `IN_UNMOUNT`
   --> rt/src/fs/watch.rs:454:23
    |
354 |     bit_checks!(self.event.mask);
    |     ---------------------------- in this macro invocation
...
454 |         #[doc(alias = $bit)]
    |                       ^^^^
    |
    = note: this error originates in the macro `bit_checks` (in Nightly builds, run with -Z macro-backtrace for more info)

error: expected unsuffixed literal or identifier, found `IN_MOVED_FROM`
   --> rt/src/fs/watch.rs:454:23
    |
354 |     bit_checks!(self.event.mask);
    |     ---------------------------- in this macro invocation
...
454 |         #[doc(alias = $bit)]
    |                       ^^^^
    |
    = note: this error originates in the macro `bit_checks` (in Nightly builds, run with -Z macro-backtrace for more info)

error: expected unsuffixed literal or identifier, found `IN_MOVED_TO`
   --> rt/src/fs/watch.rs:454:23
    |
354 |     bit_checks!(self.event.mask);
    |     ---------------------------- in this macro invocation
...
454 |         #[doc(alias = $bit)]
    |                       ^^^^
    |
    = note: this error originates in the macro `bit_checks` (in Nightly builds, run with -Z macro-backtrace for more info)

error: expected unsuffixed literal or identifier, found `IN_MOVE`
   --> rt/src/fs/watch.rs:454:23
    |
354 |     bit_checks!(self.event.mask);
    |     ---------------------------- in this macro invocation
...
454 |         #[doc(alias = $bit)]
    |                       ^^^^
    |
    = note: this error originates in the macro `bit_checks` (in Nightly builds, run with -Z macro-backtrace for more info)

error: expected unsuffixed literal or identifier, found `IN_CREATE`
   --> rt/src/fs/watch.rs:454:23
    |
354 |     bit_checks!(self.event.mask);
    |     ---------------------------- in this macro invocation
...
454 |         #[doc(alias = $bit)]
    |                       ^^^^
    |
    = note: this error originates in the macro `bit_checks` (in Nightly builds, run with -Z macro-backtrace for more info)

error: expected unsuffixed literal or identifier, found `IN_DELETE`
   --> rt/src/fs/watch.rs:454:23
    |
354 |     bit_checks!(self.event.mask);
    |     ---------------------------- in this macro invocation
...
454 |         #[doc(alias = $bit)]
    |                       ^^^^
    |
    = note: this error originates in the macro `bit_checks` (in Nightly builds, run with -Z macro-backtrace for more info)

error: could not compile `heph-rt` (lib) due to 16 previous errors
make: *** [Makefile.include:21: test] Error 101

Also available on the CI:

There are two problems. First, the regression from the previous nightly. Second, the error message is rather confusing, I have would have no idea what the actual problem is.

Meta

rustc --version --verbose:

rustc 1.79.0-nightly (a7e4de13c 2024-03-19)
binary: rustc
commit-hash: a7e4de13c1785819f4d61da41f6704ed69d5f203
commit-date: 2024-03-19
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.2

@Thomasdezeeuw Thomasdezeeuw added the C-bug Category: This is a bug. label Mar 20, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 20, 2024
@Thomasdezeeuw
Copy link
Contributor Author

The code works with nightly-2024-03-16:

rustc 1.78.0-nightly (766bdce74 2024-03-16)
binary: rustc
commit-hash: 766bdce744d531267d53ba2a3f9ffcda69fb9b17
commit-date: 2024-03-16
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.2

@fmease fmease added A-attributes Area: Attributes (`#[…]`, `#![…]`) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-discussion Category: Discussion or questions that doesn't represent real issues. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. C-bug Category: This is a bug. labels Mar 20, 2024
@jieyouxu
Copy link
Member

Exhibit A:

#![crate_type = "lib"]
#![allow(dead_code)]

pub const IN_ISDIR: usize = 0;

macro_rules! m {
    ($bit: ident) => {
        #[doc(alias = $bit)]
        pub const fn foo() {}
    };
}

struct Bar;

impl Bar {
    m!(IN_ISDIR);
}

OK on stable, ERROR on nightly 2024-03-19.


Exhibit B:

#![crate_type = "lib"]
#![allow(dead_code)]

pub const IN_ISDIR: usize = 0;

macro_rules! m {
    ($bit: ident) => {
        #[doc(alias = $bit)]
        pub const fn foo() {}
    };
}

struct Bar;

m!(IN_ISDIR);

ERROR on both.


Exhibit C:

#![crate_type = "lib"]
#![allow(dead_code)]

pub const IN_ISDIR: usize = 0;

macro_rules! m {
    ($bit: ident) => {
        #[doc(alias = $bit)]
        pub fn foo() {}            // <- notice not `const` like Exhibit A
    };
}

struct Bar;

impl Bar {
    m!(IN_ISDIR);
}

ERROR on both.

@fmease
Copy link
Member

fmease commented Mar 20, 2024

First and foremost, sorry for breaking your crate! However this was an intentional breaking change. We used to not validate attributes on certain kinds of associated functions. We did a crater run and found only a single regression. Therefore I decided to roll with it.

@fmease
Copy link
Member

fmease commented Mar 20, 2024

Intentionally regressed in #121545.

@jieyouxu
Copy link
Member

Makes a lot of sense, was about to say the stable behavior is the surprising one lol

@fmease
Copy link
Member

fmease commented Mar 20, 2024

@Thomasdezeeuw Your #[doc(alias = $bit)] attribute is malformed, the latest rustc is correct here. The doc-alias takes a string literal IIRC. To fix this, you can do #[doc(alias = stringify!($bit))].

See also: https://doc.rust-lang.org/rustdoc/advanced-features.html#add-aliases-for-an-item-in-documentation-search

@jieyouxu
Copy link
Member

Intentionally regressed in #121545.

If this is an intentional regression, we can probably close this issue?

@fmease fmease closed this as not planned Won't fix, can't repro, duplicate, stale Mar 20, 2024
@fmease
Copy link
Member

fmease commented Mar 20, 2024

The diagnostic isn't great tho lol, we should open an issue if there isn't one already. We are not expecting an identifier.

@Thomasdezeeuw
Copy link
Contributor Author

@jieyouxu @fmease thanks for the responses.

Any chance we can reopen (or create another issue) to improve the diagnostic message though? Because I won't have guessed from the error message that the problem was in the doc attributed.

@jieyouxu
Copy link
Member

Any chance we can reopen (or create another issue) to improve the diagnostic message though? Because I won't have guessed from the error message that the problem was in the doc attributed.

Feel free to create an issue for the diagnostic (which is actionable)

@fmease
Copy link
Member

fmease commented Mar 22, 2024

Any chance we can reopen (or create another issue) to improve the diagnostic message though? Because I won't have guessed from the error message that the problem was in the doc attributed.

I will look into that later.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue May 10, 2024
…m, r=nnethercote

Fix parse error message for meta items

Addresses rust-lang#122796 (comment), cc [`@]Thomasdezeeuw.`

For attrs inside of a macro like `#[doc(alias = $ident)]` or `#[cfg(feature = $ident)]` where `$ident` is a macro metavariable of fragment kind `ident`, we used to say the following when expanded (with `$ident` ⟼ `ident`):

```
error: expected unsuffixed literal or identifier, found `ident`
  --> weird.rs:6:19
   |
6  |      #[cfg(feature = $ident)]
   |                      ^^^^^^
...
11 | m!(id);
   | ------ in this macro invocation
   |
   = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
```

This was incorrect and caused confusion, justifiably so (see rust-lang#122796).

In this position, we only accept/expect *unsuffixed literals* which consist of numeric & string literals as well as the boolean literals / the keywords / the reserved identifiers `false` & `true` **but not** arbitrary identifiers.

Furthermore, we used to suggest garbage when encountering unexpected non-identifier tokens:

```
error: expected unsuffixed literal, found `-`
  --> weird.rs:16:17
   |
16 | #[cfg(feature = -1)]
   |                 ^
   |
help: surround the identifier with quotation marks to parse it as a string
   |
16 | #[cfg(feature =" "-1)]
   |                + +
```

Now we no longer do.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue May 10, 2024
…m, r=nnethercote

Fix parse error message for meta items

Addresses rust-lang#122796 (comment), cc [``@]Thomasdezeeuw.``

For attrs inside of a macro like `#[doc(alias = $ident)]` or `#[cfg(feature = $ident)]` where `$ident` is a macro metavariable of fragment kind `ident`, we used to say the following when expanded (with `$ident` ⟼ `ident`):

```
error: expected unsuffixed literal or identifier, found `ident`
  --> weird.rs:6:19
   |
6  |      #[cfg(feature = $ident)]
   |                      ^^^^^^
...
11 | m!(id);
   | ------ in this macro invocation
   |
   = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
```

This was incorrect and caused confusion, justifiably so (see rust-lang#122796).

In this position, we only accept/expect *unsuffixed literals* which consist of numeric & string literals as well as the boolean literals / the keywords / the reserved identifiers `false` & `true` **but not** arbitrary identifiers.

Furthermore, we used to suggest garbage when encountering unexpected non-identifier tokens:

```
error: expected unsuffixed literal, found `-`
  --> weird.rs:16:17
   |
16 | #[cfg(feature = -1)]
   |                 ^
   |
help: surround the identifier with quotation marks to parse it as a string
   |
16 | #[cfg(feature =" "-1)]
   |                + +
```

Now we no longer do.
rust-timer added a commit to rust-lang-ci/rust that referenced this issue May 10, 2024
Rollup merge of rust-lang#124778 - fmease:fix-diag-msg-parse-meta-item, r=nnethercote

Fix parse error message for meta items

Addresses rust-lang#122796 (comment), cc [``@]Thomasdezeeuw.``

For attrs inside of a macro like `#[doc(alias = $ident)]` or `#[cfg(feature = $ident)]` where `$ident` is a macro metavariable of fragment kind `ident`, we used to say the following when expanded (with `$ident` ⟼ `ident`):

```
error: expected unsuffixed literal or identifier, found `ident`
  --> weird.rs:6:19
   |
6  |      #[cfg(feature = $ident)]
   |                      ^^^^^^
...
11 | m!(id);
   | ------ in this macro invocation
   |
   = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
```

This was incorrect and caused confusion, justifiably so (see rust-lang#122796).

In this position, we only accept/expect *unsuffixed literals* which consist of numeric & string literals as well as the boolean literals / the keywords / the reserved identifiers `false` & `true` **but not** arbitrary identifiers.

Furthermore, we used to suggest garbage when encountering unexpected non-identifier tokens:

```
error: expected unsuffixed literal, found `-`
  --> weird.rs:16:17
   |
16 | #[cfg(feature = -1)]
   |                 ^
   |
help: surround the identifier with quotation marks to parse it as a string
   |
16 | #[cfg(feature =" "-1)]
   |                + +
```

Now we no longer do.
github-actions bot pushed a commit to rust-lang/miri that referenced this issue May 11, 2024
…hercote

Fix parse error message for meta items

Addresses rust-lang/rust#122796 (comment), cc [``@]Thomasdezeeuw.``

For attrs inside of a macro like `#[doc(alias = $ident)]` or `#[cfg(feature = $ident)]` where `$ident` is a macro metavariable of fragment kind `ident`, we used to say the following when expanded (with `$ident` ⟼ `ident`):

```
error: expected unsuffixed literal or identifier, found `ident`
  --> weird.rs:6:19
   |
6  |      #[cfg(feature = $ident)]
   |                      ^^^^^^
...
11 | m!(id);
   | ------ in this macro invocation
   |
   = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
```

This was incorrect and caused confusion, justifiably so (see #122796).

In this position, we only accept/expect *unsuffixed literals* which consist of numeric & string literals as well as the boolean literals / the keywords / the reserved identifiers `false` & `true` **but not** arbitrary identifiers.

Furthermore, we used to suggest garbage when encountering unexpected non-identifier tokens:

```
error: expected unsuffixed literal, found `-`
  --> weird.rs:16:17
   |
16 | #[cfg(feature = -1)]
   |                 ^
   |
help: surround the identifier with quotation marks to parse it as a string
   |
16 | #[cfg(feature =" "-1)]
   |                + +
```

Now we no longer do.
flip1995 pushed a commit to flip1995/rust-clippy that referenced this issue May 24, 2024
…hercote

Fix parse error message for meta items

Addresses rust-lang/rust#122796 (comment), cc [``@]Thomasdezeeuw.``

For attrs inside of a macro like `#[doc(alias = $ident)]` or `#[cfg(feature = $ident)]` where `$ident` is a macro metavariable of fragment kind `ident`, we used to say the following when expanded (with `$ident` ⟼ `ident`):

```
error: expected unsuffixed literal or identifier, found `ident`
  --> weird.rs:6:19
   |
6  |      #[cfg(feature = $ident)]
   |                      ^^^^^^
...
11 | m!(id);
   | ------ in this macro invocation
   |
   = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
```

This was incorrect and caused confusion, justifiably so (see #122796).

In this position, we only accept/expect *unsuffixed literals* which consist of numeric & string literals as well as the boolean literals / the keywords / the reserved identifiers `false` & `true` **but not** arbitrary identifiers.

Furthermore, we used to suggest garbage when encountering unexpected non-identifier tokens:

```
error: expected unsuffixed literal, found `-`
  --> weird.rs:16:17
   |
16 | #[cfg(feature = -1)]
   |                 ^
   |
help: surround the identifier with quotation marks to parse it as a string
   |
16 | #[cfg(feature =" "-1)]
   |                + +
```

Now we no longer do.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) C-discussion Category: Discussion or questions that doesn't represent real issues. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants