Skip to content

Tweak invalid builtin attribute output - #145238

Merged
bors merged 7 commits into
rust-lang:masterfrom
estebank:attr-overhaul
Aug 12, 2025
Merged

Tweak invalid builtin attribute output#145238
bors merged 7 commits into
rust-lang:masterfrom
estebank:attr-overhaul

Conversation

@estebank

Copy link
Copy Markdown
Contributor
  • Add link to reference/docs when possible
  • More accurate suggestions by supporting multiple alternative suggestions
error: malformed `crate_type` attribute input
--> $DIR/crate-type-macro-call.rs:1:1
|
LL | #![crate_type = foo!()]
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: for more information, visit <https://doc.rust-lang.org/reference/linkage.html>
help: the following are the possible correct uses
|
LL - #![crate_type = foo!()]
LL + #![crate_type = "bin"]
|
LL - #![crate_type = foo!()]
LL + #![crate_type = "cdylib"]
|
LL - #![crate_type = foo!()]
LL + #![crate_type = "dylib"]
|
LL - #![crate_type = foo!()]
LL + #![crate_type = "lib"]
|
= and 4 other candidates

@rustbot

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

@rustbotrustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) 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 Aug 11, 2025
@rustbot

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann

This PR modifies tests/ui/issues/. If this PR is adding new tests to tests/ui/issues/,
please refrain from doing so, and instead add it to more descriptive subdirectories.

@rust-log-analyzer

This comment has been minimized.

@jdonszelmannjdonszelmann left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looks like a good change, just gotta fix the CI :)

}
if let Some(descr) = template.list {
suggestions.push(format!("#{inner}[{name}({descr})]"));
for descr in descr {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

note: this code will disappear soon, still a good change for now

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

most malformed attr errors are now emitted here: https://github.com/rust-lang/rust/pull/145238/files#diff-1e3857964b49daddd7568a3cc24d19c769660f5cb79accecbe72495c1da7eb02L693. Does this PR also improve those diagnostics? I'm not entirely sure it does.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

It does because of the change to AttributeTemplate::suggestions in https://github.com/rust-lang/rust/pull/145238/files#diff-09c366d3ad3ec9a42125253b610ca83cad6b156aa2a723f6c7e83eddef7b1e8fR135-R152 (compiler/rustc_feature/src/builtin_attrs.rs:142)

…medValueStr`
Modify `AttributeTemplate` to support list of alternatives for list and name value attribute styles.
Suggestions now provide more correct suggested code:
```
error[E0805]: malformed `used` attribute input
--> $DIR/used_with_multi_args.rs:3:1
|
LL | #[used(compiler, linker)]
| ^^^^^^------------------^
| |
| expected a single argument here
|
help: try changing it to one of the following valid forms of the attribute
|
LL - #[used(compiler, linker)]
LL + #[used(compiler)]
|
LL - #[used(compiler, linker)]
LL + #[used(linker)]
|
LL - #[used(compiler, linker)]
LL + #[used]
|
```
instead of the prior "masking" of the lack of this feature by suggesting pipe-separated lists:
```
error[E0805]: malformed `used` attribute input
--> $DIR/used_with_multi_args.rs:3:1
|
LL | #[used(compiler, linker)]
| ^^^^^^------------------^
| |
| expected a single argument here
|
help: try changing it to one of the following valid forms of the attribute
|
LL - #[used(compiler, linker)]
LL + #[used(compiler|linker)]
|
LL - #[used(compiler, linker)]
LL + #[used]
|
```
@jdonszelmann

Copy link
Copy Markdown
Contributor

r=me on green CI

@rust-log-analyzer

This comment has been minimized.

@rustbotrustbot added the T-clippy Relevant to the Clippy team. label Aug 11, 2025
@rustbot

Copy link
Copy Markdown
Collaborator

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@estebank

Copy link
Copy Markdown
ContributorAuthor

@bors r=jdonszelmann

@bors

bors commented Aug 11, 2025

Copy link
Copy Markdown
Collaborator

📌 Commit 928dd11 has been approved by jdonszelmann

It is now in the queue for this repository.

@borsbors 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 Aug 11, 2025
fmease added a commit to fmease/rust that referenced this pull request Aug 11, 2025
…mann
Tweak invalid builtin attribute output
- Add link to reference/docs when possible
- More accurate suggestions by supporting multiple alternative suggestions
```
error: malformed `crate_type` attribute input
--> $DIR/crate-type-macro-call.rs:1:1
|
LL | #![crate_type = foo!()]
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: for more information, visit <https://doc.rust-lang.org/reference/linkage.html>
help: the following are the possible correct uses
|
LL - #![crate_type = foo!()]
LL + #![crate_type = "bin"]
|
LL - #![crate_type = foo!()]
LL + #![crate_type = "cdylib"]
|
LL - #![crate_type = foo!()]
LL + #![crate_type = "dylib"]
|
LL - #![crate_type = foo!()]
LL + #![crate_type = "lib"]
|
= and 4 other candidates
```
@fmeasefmease mentioned this pull request Aug 11, 2025
fmease added a commit to fmease/rust that referenced this pull request Aug 12, 2025
…mann
Tweak invalid builtin attribute output
- Add link to reference/docs when possible
- More accurate suggestions by supporting multiple alternative suggestions
```
error: malformed `crate_type` attribute input
--> $DIR/crate-type-macro-call.rs:1:1
|
LL | #![crate_type = foo!()]
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: for more information, visit <https://doc.rust-lang.org/reference/linkage.html>
help: the following are the possible correct uses
|
LL - #![crate_type = foo!()]
LL + #![crate_type = "bin"]
|
LL - #![crate_type = foo!()]
LL + #![crate_type = "cdylib"]
|
LL - #![crate_type = foo!()]
LL + #![crate_type = "dylib"]
|
LL - #![crate_type = foo!()]
LL + #![crate_type = "lib"]
|
= and 4 other candidates
```
@fmeasefmease mentioned this pull request Aug 12, 2025
fmease added a commit to fmease/rust that referenced this pull request Aug 12, 2025
…mann
Tweak invalid builtin attribute output
- Add link to reference/docs when possible
- More accurate suggestions by supporting multiple alternative suggestions
```
error: malformed `crate_type` attribute input
--> $DIR/crate-type-macro-call.rs:1:1
|
LL | #![crate_type = foo!()]
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: for more information, visit <https://doc.rust-lang.org/reference/linkage.html>
help: the following are the possible correct uses
|
LL - #![crate_type = foo!()]
LL + #![crate_type = "bin"]
|
LL - #![crate_type = foo!()]
LL + #![crate_type = "cdylib"]
|
LL - #![crate_type = foo!()]
LL + #![crate_type = "dylib"]
|
LL - #![crate_type = foo!()]
LL + #![crate_type = "lib"]
|
= and 4 other candidates
```
fmease added a commit to fmease/rust that referenced this pull request Aug 12, 2025
…mann
Tweak invalid builtin attribute output
- Add link to reference/docs when possible
- More accurate suggestions by supporting multiple alternative suggestions
```
error: malformed `crate_type` attribute input
--> $DIR/crate-type-macro-call.rs:1:1
|
LL | #![crate_type = foo!()]
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: for more information, visit <https://doc.rust-lang.org/reference/linkage.html>
help: the following are the possible correct uses
|
LL - #![crate_type = foo!()]
LL + #![crate_type = "bin"]
|
LL - #![crate_type = foo!()]
LL + #![crate_type = "cdylib"]
|
LL - #![crate_type = foo!()]
LL + #![crate_type = "dylib"]
|
LL - #![crate_type = foo!()]
LL + #![crate_type = "lib"]
|
= and 4 other candidates
```
@fmeasefmease mentioned this pull request Aug 12, 2025
bors added a commit that referenced this pull request Aug 12, 2025
Rollup of 15 pull requests
Successful merges:
- #131477 (Apple: Always pass SDK root when linking with `cc`, and pass it via `SDKROOT` env var)
- #139806 (std: sys: pal: uefi: Overhaul Time)
- #144386 (Extract TraitImplHeader in AST/HIR)
- #144542 (Stabilize `sse4a` and `tbm` target features)
- #144921 (Don't emit `rustdoc::broken_intra_doc_links` for GitHub-flavored Markdown admonitions like `[!NOTE]`)
- #145155 (Port `#[allow_internal_unsafe]` to the new attribute system (attempt 2))
- #145214 (fix: re-enable self-assignment)
- #145216 (rustdoc: correct negative-to-implicit discriminant display)
- #145238 (Tweak invalid builtin attribute output)
- #145249 (Rename entered trace span variables from `_span` to `_trace`)
- #145251 (Support using #[unstable_feature_bound] on trait)
- #145253 (Document compiler and stdlib in stage1 in `pr-check-2` CI job)
- #145260 (Make explicit guarantees about `Vec`’s allocator)
- #145263 (Update books)
- #145273 (Account for new `assert!` desugaring in `!condition` suggestion)
r? `@ghost`
`@rustbot` modify labels: rollup
fmease added a commit to fmease/rust that referenced this pull request Aug 12, 2025
…mann
Tweak invalid builtin attribute output
- Add link to reference/docs when possible
- More accurate suggestions by supporting multiple alternative suggestions
```
error: malformed `crate_type` attribute input
--> $DIR/crate-type-macro-call.rs:1:1
|
LL | #![crate_type = foo!()]
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: for more information, visit <https://doc.rust-lang.org/reference/linkage.html>
help: the following are the possible correct uses
|
LL - #![crate_type = foo!()]
LL + #![crate_type = "bin"]
|
LL - #![crate_type = foo!()]
LL + #![crate_type = "cdylib"]
|
LL - #![crate_type = foo!()]
LL + #![crate_type = "dylib"]
|
LL - #![crate_type = foo!()]
LL + #![crate_type = "lib"]
|
= and 4 other candidates
```
@fmeasefmease mentioned this pull request Aug 12, 2025
bors added a commit that referenced this pull request Aug 12, 2025
Rollup of 14 pull requests
Successful merges:
- #131477 (Apple: Always pass SDK root when linking with `cc`, and pass it via `SDKROOT` env var)
- #139806 (std: sys: pal: uefi: Overhaul Time)
- #144210 (std: thread: Return error if setting thread stack size fails)
- #144386 (Extract TraitImplHeader in AST/HIR)
- #144921 (Don't emit `rustdoc::broken_intra_doc_links` for GitHub-flavored Markdown admonitions like `[!NOTE]`)
- #145155 (Port `#[allow_internal_unsafe]` to the new attribute system (attempt 2))
- #145214 (fix: re-enable self-assignment)
- #145216 (rustdoc: correct negative-to-implicit discriminant display)
- #145238 (Tweak invalid builtin attribute output)
- #145249 (Rename entered trace span variables from `_span` to `_trace`)
- #145251 (Support using #[unstable_feature_bound] on trait)
- #145253 (Document compiler and stdlib in stage1 in `pr-check-2` CI job)
- #145263 (Update books)
- #145273 (Account for new `assert!` desugaring in `!condition` suggestion)
r? `@ghost`
`@rustbot` modify labels: rollup
Zalathar added a commit to Zalathar/rust that referenced this pull request Aug 12, 2025
…mann
Tweak invalid builtin attribute output
- Add link to reference/docs when possible
- More accurate suggestions by supporting multiple alternative suggestions
```
error: malformed `crate_type` attribute input
--> $DIR/crate-type-macro-call.rs:1:1
|
LL | #![crate_type = foo!()]
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: for more information, visit <https://doc.rust-lang.org/reference/linkage.html>
help: the following are the possible correct uses
|
LL - #![crate_type = foo!()]
LL + #![crate_type = "bin"]
|
LL - #![crate_type = foo!()]
LL + #![crate_type = "cdylib"]
|
LL - #![crate_type = foo!()]
LL + #![crate_type = "dylib"]
|
LL - #![crate_type = foo!()]
LL + #![crate_type = "lib"]
|
= and 4 other candidates
```
@ZalatharZalathar mentioned this pull request Aug 12, 2025
bors added a commit that referenced this pull request Aug 12, 2025
Rollup of 17 pull requests
Successful merges:
- #131477 (Apple: Always pass SDK root when linking with `cc`, and pass it via `SDKROOT` env var)
- #139806 (std: sys: pal: uefi: Overhaul Time)
- #144210 (std: thread: Return error if setting thread stack size fails)
- #144386 (Extract TraitImplHeader in AST/HIR)
- #144921 (Don't emit `rustdoc::broken_intra_doc_links` for GitHub-flavored Markdown admonitions like `[!NOTE]`)
- #145155 (Port `#[allow_internal_unsafe]` to the new attribute system (attempt 2))
- #145214 (fix: re-enable self-assignment)
- #145216 (rustdoc: correct negative-to-implicit discriminant display)
- #145238 (Tweak invalid builtin attribute output)
- #145249 (Rename entered trace span variables from `_span` to `_trace`)
- #145251 (Support using #[unstable_feature_bound] on trait)
- #145253 (Document compiler and stdlib in stage1 in `pr-check-2` CI job)
- #145260 (Make explicit guarantees about `Vec`’s allocator)
- #145263 (Update books)
- #145273 (Account for new `assert!` desugaring in `!condition` suggestion)
- #145283 (Make I-miscompile imply I-prioritize)
- #145291 (bootstrap: Only warn about `rust.debug-assertions` if downloading rustc)
r? `@ghost`
`@rustbot` modify labels: rollup
@ZalatharZalathar mentioned this pull request Aug 12, 2025
bors added a commit that referenced this pull request Aug 12, 2025
Rollup of 17 pull requests
Successful merges:
- #131477 (Apple: Always pass SDK root when linking with `cc`, and pass it via `SDKROOT` env var)
- #139806 (std: sys: pal: uefi: Overhaul Time)
- #144386 (Extract TraitImplHeader in AST/HIR)
- #144921 (Don't emit `rustdoc::broken_intra_doc_links` for GitHub-flavored Markdown admonitions like `[!NOTE]`)
- #145155 (Port `#[allow_internal_unsafe]` to the new attribute system (attempt 2))
- #145214 (fix: re-enable self-assignment)
- #145216 (rustdoc: correct negative-to-implicit discriminant display)
- #145238 (Tweak invalid builtin attribute output)
- #145249 (Rename entered trace span variables from `_span` to `_trace`)
- #145251 (Support using #[unstable_feature_bound] on trait)
- #145253 (Document compiler and stdlib in stage1 in `pr-check-2` CI job)
- #145260 (Make explicit guarantees about `Vec`’s allocator)
- #145263 (Update books)
- #145273 (Account for new `assert!` desugaring in `!condition` suggestion)
- #145283 (Make I-miscompile imply I-prioritize)
- #145291 (bootstrap: Only warn about `rust.debug-assertions` if downloading rustc)
- #145292 (Fix a typo in range docs)
r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit d862ae2 into rust-lang:masterAug 12, 2025
10 checks passed
@rustbotrustbot added this to the 1.91.0 milestone Aug 12, 2025
rust-timer added a commit that referenced this pull request Aug 12, 2025
Rollup merge of #145238 - estebank:attr-overhaul, r=jdonszelmann
Tweak invalid builtin attribute output
- Add link to reference/docs when possible
- More accurate suggestions by supporting multiple alternative suggestions
```
error: malformed `crate_type` attribute input
--> $DIR/crate-type-macro-call.rs:1:1
|
LL | #![crate_type = foo!()]
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: for more information, visit <https://doc.rust-lang.org/reference/linkage.html>
help: the following are the possible correct uses
|
LL - #![crate_type = foo!()]
LL + #![crate_type = "bin"]
|
LL - #![crate_type = foo!()]
LL + #![crate_type = "cdylib"]
|
LL - #![crate_type = foo!()]
LL + #![crate_type = "dylib"]
|
LL - #![crate_type = foo!()]
LL + #![crate_type = "lib"]
|
= and 4 other candidates
```
github-actionsBot pushed a commit to rust-lang/miri that referenced this pull request Aug 13, 2025
Rollup of 17 pull requests
Successful merges:
- rust-lang/rust#131477 (Apple: Always pass SDK root when linking with `cc`, and pass it via `SDKROOT` env var)
- rust-lang/rust#139806 (std: sys: pal: uefi: Overhaul Time)
- rust-lang/rust#144386 (Extract TraitImplHeader in AST/HIR)
- rust-lang/rust#144921 (Don't emit `rustdoc::broken_intra_doc_links` for GitHub-flavored Markdown admonitions like `[!NOTE]`)
- rust-lang/rust#145155 (Port `#[allow_internal_unsafe]` to the new attribute system (attempt 2))
- rust-lang/rust#145214 (fix: re-enable self-assignment)
- rust-lang/rust#145216 (rustdoc: correct negative-to-implicit discriminant display)
- rust-lang/rust#145238 (Tweak invalid builtin attribute output)
- rust-lang/rust#145249 (Rename entered trace span variables from `_span` to `_trace`)
- rust-lang/rust#145251 (Support using #[unstable_feature_bound] on trait)
- rust-lang/rust#145253 (Document compiler and stdlib in stage1 in `pr-check-2` CI job)
- rust-lang/rust#145260 (Make explicit guarantees about `Vec`’s allocator)
- rust-lang/rust#145263 (Update books)
- rust-lang/rust#145273 (Account for new `assert!` desugaring in `!condition` suggestion)
- rust-lang/rust#145283 (Make I-miscompile imply I-prioritize)
- rust-lang/rust#145291 (bootstrap: Only warn about `rust.debug-assertions` if downloading rustc)
- rust-lang/rust#145292 (Fix a typo in range docs)
r? `@ghost`
`@rustbot` modify labels: rollup
github-actionsBot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Aug 18, 2025
Rollup of 17 pull requests
Successful merges:
- rust-lang/rust#131477 (Apple: Always pass SDK root when linking with `cc`, and pass it via `SDKROOT` env var)
- rust-lang/rust#139806 (std: sys: pal: uefi: Overhaul Time)
- rust-lang/rust#144386 (Extract TraitImplHeader in AST/HIR)
- rust-lang/rust#144921 (Don't emit `rustdoc::broken_intra_doc_links` for GitHub-flavored Markdown admonitions like `[!NOTE]`)
- rust-lang/rust#145155 (Port `#[allow_internal_unsafe]` to the new attribute system (attempt 2))
- rust-lang/rust#145214 (fix: re-enable self-assignment)
- rust-lang/rust#145216 (rustdoc: correct negative-to-implicit discriminant display)
- rust-lang/rust#145238 (Tweak invalid builtin attribute output)
- rust-lang/rust#145249 (Rename entered trace span variables from `_span` to `_trace`)
- rust-lang/rust#145251 (Support using #[unstable_feature_bound] on trait)
- rust-lang/rust#145253 (Document compiler and stdlib in stage1 in `pr-check-2` CI job)
- rust-lang/rust#145260 (Make explicit guarantees about `Vec`’s allocator)
- rust-lang/rust#145263 (Update books)
- rust-lang/rust#145273 (Account for new `assert!` desugaring in `!condition` suggestion)
- rust-lang/rust#145283 (Make I-miscompile imply I-prioritize)
- rust-lang/rust#145291 (bootstrap: Only warn about `rust.debug-assertions` if downloading rustc)
- rust-lang/rust#145292 (Fix a typo in range docs)
r? `@ghost`
`@rustbot` modify labels: rollup
flip1995 pushed a commit to flip1995/rust that referenced this pull request Aug 22, 2025
…mann
Tweak invalid builtin attribute output
- Add link to reference/docs when possible
- More accurate suggestions by supporting multiple alternative suggestions
```
error: malformed `crate_type` attribute input
--> $DIR/crate-type-macro-call.rs:1:1
|
LL | #![crate_type = foo!()]
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: for more information, visit <https://doc.rust-lang.org/reference/linkage.html>
help: the following are the possible correct uses
|
LL - #![crate_type = foo!()]
LL + #![crate_type = "bin"]
|
LL - #![crate_type = foo!()]
LL + #![crate_type = "cdylib"]
|
LL - #![crate_type = foo!()]
LL + #![crate_type = "dylib"]
|
LL - #![crate_type = foo!()]
LL + #![crate_type = "lib"]
|
= and 4 other candidates
```
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributesArea: Attributes (`#[…]`, `#![…]`)S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-clippyRelevant to the Clippy team.T-compilerRelevant 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.

6 participants

@estebank@rustbot@rust-log-analyzer@jdonszelmann@bors@jieyouxu