Skip to content

Improve declare_features! macro error#157931

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
mejrs:feature_macro
Jun 17, 2026
Merged

Improve declare_features! macro error#157931
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
mejrs:feature_macro

Conversation

@mejrs

@mejrs mejrs commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

I got mildly annoyed when I went to add a new feature, and the fix for this is relatively simple.

Current error:

error[E0425]: cannot find value `better_rust` in module `sym`                                                                                                                                                                                                                           
   --> compiler\rustc_feature\src\unstable.rs:240:16
    |
157 |                 name: sym::$feature,
    |                            -------- due to this macro variable
...
240 |     (internal, better_rust, "2.0.0", None),
    |                ^^^^^^^^^^^ not found in `sym`

For more information about this error, try `rustc --explain E0425`

Previous error:

error[E0425]: cannot find value `better_rust` in module `sym`                                                                                                                                                                                                                           
   --> compiler\rustc_feature\src\unstable.rs:240:16
    |
157 |                 name: sym::$feature,
    |                            -------- due to this macro variable
...
240 |     (internal, better_rust, "2.0.0", None),
    |                ^^^^^^^^^^^ not found in `sym`

error[E0531]: cannot find unit struct, unit variant or constant `better_rust` in module `sym`
   --> compiler\rustc_feature\src\unstable.rs:240:16
    |
157 |                 name: sym::$feature,
    |                            -------- due to this macro variable
...
240 |     (internal, better_rust, "2.0.0", None),
    |                ^^^^^^^^^^^ not found in `sym`

Some errors have detailed explanations: E0425, E0531.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 15, 2026
@rustbot

rustbot commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

r? @jieyouxu

rustbot has assigned @jieyouxu.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 20 candidates

@jieyouxu jieyouxu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

While the change itself looks reasonable, do we know if this is one of the resolve errors that we should be suppressing (for the second instance)?

View changes since this review

@mejrs

mejrs commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

That is unwarranted in my eyes.

The existing deduplication that already happens here is not done by the resolver, it's done in rustc_errors. Which just compares the errors by hashing them.

I don't want to make such changes in the resolver, nor does a smarter deduplication mechanism in rustc_error seem worth it. Especially when there are already several easy tricks to avoid error duplication by rewriting the macro slightly (like what i did here, or by binding the metavariable to a local and using that)

@jieyouxu jieyouxu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, this seems reasonable.
@bors r+ rollup

View changes since this review

@rust-bors

rust-bors Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 3ae0f01 has been approved by jieyouxu

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 17, 2026
@rust-bors

rust-bors Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

⌛ Testing commit 3ae0f01 with merge f9279b5...

Workflow: https://github.com/rust-lang/rust/actions/runs/27679398121

rust-bors Bot pushed a commit that referenced this pull request Jun 17, 2026
Improve `declare_features!` macro error

I got mildly annoyed when I went to add a new feature, and the fix for this is relatively simple.

Current error:
```
error[E0425]: cannot find value `better_rust` in module `sym`                                                                                                                                                                                                                           
   --> compiler\rustc_feature\src\unstable.rs:240:16
    |
157 |                 name: sym::$feature,
    |                            -------- due to this macro variable
...
240 |     (internal, better_rust, "2.0.0", None),
    |                ^^^^^^^^^^^ not found in `sym`

For more information about this error, try `rustc --explain E0425`
```

Previous error:
```
error[E0425]: cannot find value `better_rust` in module `sym`                                                                                                                                                                                                                           
   --> compiler\rustc_feature\src\unstable.rs:240:16
    |
157 |                 name: sym::$feature,
    |                            -------- due to this macro variable
...
240 |     (internal, better_rust, "2.0.0", None),
    |                ^^^^^^^^^^^ not found in `sym`

error[E0531]: cannot find unit struct, unit variant or constant `better_rust` in module `sym`
   --> compiler\rustc_feature\src\unstable.rs:240:16
    |
157 |                 name: sym::$feature,
    |                            -------- due to this macro variable
...
240 |     (internal, better_rust, "2.0.0", None),
    |                ^^^^^^^^^^^ not found in `sym`

Some errors have detailed explanations: E0425, E0531.
```
@JonathanBrouwer

Copy link
Copy Markdown
Contributor

@bors yield
Yielding to enclosing rollup

@rust-bors

rust-bors Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Auto build was cancelled. Cancelled workflows:

The next pull request likely to be tested is #158015.

rust-bors Bot pushed a commit that referenced this pull request Jun 17, 2026
…uwer

Rollup of 3 pull requests

Successful merges:

 - #157931 (Improve `declare_features!` macro error)
 - #157992 (tidy: revisions inherit global directives)
 - #158010 (renovate: Pin GitHub Action digests to SemVer)
@rust-bors rust-bors Bot merged commit 854fdba into rust-lang:main Jun 17, 2026
13 of 14 checks passed
@rustbot rustbot added this to the 1.98.0 milestone Jun 17, 2026
rust-timer added a commit that referenced this pull request Jun 17, 2026
Rollup merge of #157931 - mejrs:feature_macro, r=jieyouxu

Improve `declare_features!` macro error

I got mildly annoyed when I went to add a new feature, and the fix for this is relatively simple.

Current error:
```
error[E0425]: cannot find value `better_rust` in module `sym`
   --> compiler\rustc_feature\src\unstable.rs:240:16
    |
157 |                 name: sym::$feature,
    |                            -------- due to this macro variable
...
240 |     (internal, better_rust, "2.0.0", None),
    |                ^^^^^^^^^^^ not found in `sym`

For more information about this error, try `rustc --explain E0425`
```

Previous error:
```
error[E0425]: cannot find value `better_rust` in module `sym`
   --> compiler\rustc_feature\src\unstable.rs:240:16
    |
157 |                 name: sym::$feature,
    |                            -------- due to this macro variable
...
240 |     (internal, better_rust, "2.0.0", None),
    |                ^^^^^^^^^^^ not found in `sym`

error[E0531]: cannot find unit struct, unit variant or constant `better_rust` in module `sym`
   --> compiler\rustc_feature\src\unstable.rs:240:16
    |
157 |                 name: sym::$feature,
    |                            -------- due to this macro variable
...
240 |     (internal, better_rust, "2.0.0", None),
    |                ^^^^^^^^^^^ not found in `sym`

Some errors have detailed explanations: E0425, E0531.
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants