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

Remove E0773 "A builtin-macro was defined more than once." #138613

Merged
merged 1 commit into from
Mar 20, 2025

Conversation

m-ou-se
Copy link
Member

@m-ou-se m-ou-se commented Mar 17, 2025

Error E0773 "A builtin-macro was defined more than once" is triggered when using the same #[rustc_builtin_macro(..)] twice. However, it can only be triggered in unstable code (using a rustc_ attribute), and there doesn't seem to be any harm in using the same implementation from compiler/rustc_builtin_macros/… for multiple macro definitions.

By changing the Box to an Arc in SyntaxExtensionKind, we can throw away the BuiltinMacroState::{NotYetSeen, AlreadySeen} logic, simplifying things.

@m-ou-se m-ou-se added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 17, 2025
@rustbot
Copy link
Collaborator

rustbot commented Mar 17, 2025

r? @cjgillot

rustbot has assigned @cjgillot.
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

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 17, 2025
@rustbot
Copy link
Collaborator

rustbot commented Mar 17, 2025

Some changes occurred in diagnostic error codes

cc @GuillaumeGomez

@m-ou-se
Copy link
Member Author

m-ou-se commented Mar 17, 2025

cc @jyn514 who originally added this error in #76143

@jdonszelmann
Copy link
Contributor

jdonszelmann commented Mar 17, 2025

I reviewed the changes and they look reasonable to me. I just can't quite judge how important this check was. The check feels to me like just a sanity check, and there's now a good usecase for actually doing the thing the error tries to prevent.

@m-ou-se
Copy link
Member Author

m-ou-se commented Mar 17, 2025

Originally, the macro was just removed from builtin_macros when #[rustc_builtin_macro] was used, resuting in a confusing "not found" error when used more than once.

To avoid that confusion, #76143 added logic to keep track of the already used builtin macros to give a better error. I think the better/simpler strategy is to just use Arc instead of Box such that you don't have to remove or track anything, lifting the 'only one definition' limitation.

@jdonszelmann
Copy link
Contributor

right, so by making things an Arc, we solve the issue for which the error was initially added. Then I don't think there's much reason not to do this :)

@jdonszelmann
Copy link
Contributor

alright then, first @bors r+ rollup here we go!

@bors
Copy link
Contributor

bors commented Mar 17, 2025

📌 Commit 97d870e has been approved by jdonszelmann

It is now in the queue for this repository.

@bors bors 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 Mar 17, 2025
@rust-log-analyzer

This comment has been minimized.

@m-ou-se m-ou-se force-pushed the no-more-e0773 branch 2 times, most recently from 43ea8cf to c9eda62 Compare March 17, 2025 17:29
@jyn514
Copy link
Member

jyn514 commented Mar 17, 2025

i don't quite follow why it's useful to define a macro more than once, but as long as it works i have no objection. people shouldn't be using rustc_builtin_macro outside of std anyway.

@jyn514
Copy link
Member

jyn514 commented Mar 17, 2025

wait, you also removed the test? please don't do that, please test that duplicate macros work.

@jdonszelmann
Copy link
Contributor

this is useful when you want multiple macros with different names implemented by the same definition in rustc_builtin_macros

@m-ou-se
Copy link
Member Author

m-ou-se commented Mar 17, 2025

It's also useful when making a quick test/example while working on rustc, to not get conflicts with core when testing something with rustc_builtin_macro.

@m-ou-se
Copy link
Member Author

m-ou-se commented Mar 17, 2025

i don't quite follow why it's useful to define a macro more than once

I don't see why it's useful to limit it to one use either. (Which caused some hard to debug issues in the past.)

@workingjubilee
Copy link
Member

this is useful when you want multiple macros with different names implemented by the same definition in rustc_builtin_macros

Is there a problem with having the other macros forward to that builtin one?

@m-ou-se
Copy link
Member Author

m-ou-se commented Mar 17, 2025

Is there a problem with having the other macros forward to that builtin one?

That's not as easy for attribute and derive macros.

@workingjubilee
Copy link
Member

Ooh, yeah. Doable but still, gotcha.

@jdonszelmann
Copy link
Contributor

@jyn514 's comment of adding a test sounds like a good one. After that I'm willing to r+ again :)

@fmease
Copy link
Member

fmease commented Mar 17, 2025

could you also squash :)

@bors r-

@rustbot rustbot assigned petrochenkov and unassigned jdonszelmann Mar 17, 2025
@petrochenkov petrochenkov added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 17, 2025
@petrochenkov
Copy link
Contributor

The Box -> Arc change doesn't affect just built-in macros, it affects all macros, so let's check the perf first.
@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 18, 2025
@petrochenkov petrochenkov removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 18, 2025
@bors
Copy link
Contributor

bors commented Mar 18, 2025

⌛ Trying commit c9eda62 with merge cfeb465...

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 18, 2025
Remove E0773 "A builtin-macro was defined more than once."

Error E0773 "A builtin-macro was defined more than once" is triggered when using the same `#[rustc_builtin_macro(..)]` twice. However, it can only be triggered in unstable code (using a `rustc_` attribute), and there doesn't seem to be any harm in using the same implementation from `compiler/rustc_builtin_macros/…` for multiple macro definitions.

By changing the Box to an Arc in `SyntaxExtensionKind`, we can throw away the `BuiltinMacroState::{NotYetSeen, AlreadySeen}` logic, simplifying things.
@bors
Copy link
Contributor

bors commented Mar 18, 2025

☀️ Try build successful - checks-actions
Build commit: cfeb465 (cfeb4659d0a4e3cac73a43d4b6e3b8b4c08da529)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (cfeb465): comparison URL.

Overall result: ❌ regressions - no action needed

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.2% [0.2%, 0.2%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary 2.5%, secondary -1.8%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
2.5% [2.5%, 2.5%] 1
Regressions ❌
(secondary)
1.5% [1.5%, 1.5%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.9% [-3.7%, -2.1%] 3
All ❌✅ (primary) 2.5% [2.5%, 2.5%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 776.359s -> 775.772s (-0.08%)
Artifact size: 365.12 MiB -> 365.09 MiB (-0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 18, 2025
@petrochenkov
Copy link
Contributor

The change itself makes sense.
r=me after restoring the comment (#138613 (comment)) and tests (#138613 (comment)), and squashing commits.
@rustbot author
@bors rollup=maybe

@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Mar 18, 2025
This removes E0773 "A builtin-macro was defined more than once."
@jdonszelmann
Copy link
Contributor

@bors r=jdonszelmann,petrochenkov then :)

@bors
Copy link
Contributor

bors commented Mar 19, 2025

📌 Commit 6c865c1 has been approved by jdonszelmann,petrochenkov

It is now in the queue for this repository.

@bors bors 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 19, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 19, 2025
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#135394 (`MaybeUninit` inherent slice methods part 2)
 - rust-lang#137051 (Implement default methods for `io::Empty` and `io::Sink`)
 - rust-lang#138001 (mir_build: consider privacy when checking for irrefutable patterns)
 - rust-lang#138540 (core/slice: Mark some `split_off` variants unstably const)
 - rust-lang#138589 (If a label is placed on the block of a loop instead of the header, suggest moving it to the header.)
 - rust-lang#138594 (Fix next solver handling of shallow trait impl check)
 - rust-lang#138613 (Remove E0773 "A builtin-macro was defined more than once.")

Failed merges:

 - rust-lang#138602 (Slim `rustc_parse_format` dependencies down)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 19, 2025
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#135394 (`MaybeUninit` inherent slice methods part 2)
 - rust-lang#137051 (Implement default methods for `io::Empty` and `io::Sink`)
 - rust-lang#138001 (mir_build: consider privacy when checking for irrefutable patterns)
 - rust-lang#138540 (core/slice: Mark some `split_off` variants unstably const)
 - rust-lang#138589 (If a label is placed on the block of a loop instead of the header, suggest moving it to the header.)
 - rust-lang#138594 (Fix next solver handling of shallow trait impl check)
 - rust-lang#138613 (Remove E0773 "A builtin-macro was defined more than once.")

Failed merges:

 - rust-lang#138602 (Slim `rustc_parse_format` dependencies down)

r? `@ghost`
`@rustbot` modify labels: rollup
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Mar 20, 2025
Rollup merge of rust-lang#138613 - m-ou-se:no-more-e0773, r=jdonszelmann,petrochenkov

Remove E0773 "A builtin-macro was defined more than once."

Error E0773 "A builtin-macro was defined more than once" is triggered when using the same `#[rustc_builtin_macro(..)]` twice. However, it can only be triggered in unstable code (using a `rustc_` attribute), and there doesn't seem to be any harm in using the same implementation from `compiler/rustc_builtin_macros/…` for multiple macro definitions.

By changing the Box to an Arc in `SyntaxExtensionKind`, we can throw away the `BuiltinMacroState::{NotYetSeen, AlreadySeen}` logic, simplifying things.
@bors bors merged commit 966021d into rust-lang:master Mar 20, 2025
6 checks passed
@rustbot rustbot added this to the 1.87.0 milestone Mar 20, 2025
@m-ou-se m-ou-se deleted the no-more-e0773 branch March 20, 2025 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) 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.

None yet