Skip to content

Document diagostic attribute duplicates#2226

Closed
mejrs wants to merge 1 commit intorust-lang:masterfrom
mejrs:multiples
Closed

Document diagostic attribute duplicates#2226
mejrs wants to merge 1 commit intorust-lang:masterfrom
mejrs:multiples

Conversation

@mejrs
Copy link
Copy Markdown
Contributor

@mejrs mejrs commented Apr 13, 2026

You can stack these attributes, which I think is a cool little known fact. For example:

#[diagnostic::on_unimplemented(
    message = "pyclass `{Self}` cannot be subclassed",
    label = "required for `#[pyclass(extends={Self})]`",
    note = "`{Self}` must have `#[pyclass(subclass)]` to be eligible for subclassing"
)]
#[cfg_attr(
    Py_LIMITED_API,
    diagnostic::on_unimplemented(
        note = "with the `abi3` feature enabled, PyO3 does not support subclassing native types",
    )
)]
pub trait PyClassBaseType: Sized {

See rust-lang/rust#155294 for the test this rule will link to.

@rustbot rustbot added the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label Apr 13, 2026
If any of the other options appears several times the first occurrence of the relevant option specifies the actually used value. Subsequent occurrences generates a warning.

r[attributes.diagnostic.on_unimplemented.duplicates]
The `diagnostic::on_unimplemented` attribute may be used any number of times. All keys from all uses of the attribute will be used and are subject to the repetition rules.
Copy link
Copy Markdown
Contributor Author

@mejrs mejrs Apr 13, 2026

Choose a reason for hiding this comment

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

View changes since the review

Existing prose looks like

The `cfg` attribute may be used any number of times on a form.

and

The `derive` attribute may be used any number of times on an item.

I'm not sure what I should use, or what a form is for that matter (it's not in the glossary).

@ehuss
Copy link
Copy Markdown
Contributor

ehuss commented Apr 14, 2026

Thanks for the PR! We have an open PR at #1893 that updates this rule (among a few other things).

@mejrs
Copy link
Copy Markdown
Contributor Author

mejrs commented Apr 14, 2026

Oh shoot, I didn't see that at all. Great minds think alike, I suppose. Would you like me to merge the linked test?

@mejrs mejrs closed this Apr 14, 2026
@rustbot rustbot removed the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label Apr 14, 2026
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.

3 participants