Skip to content

Duplicate attribute diagnostic cleanups - #165935

Open
petrak-at-canonical wants to merge 3 commits into
rust-lang:mainfrom
petrak-at-canonical:duplicate-attr-diagnostic
Open

petrak-at-canonical wants to merge 3 commits into
rust-lang:mainfrom
petrak-at-canonical:duplicate-attr-diagnostic

Conversation

@petrak-at-canonical

Copy link
Copy Markdown
Contributor

Currently there are two different diagnostics for when you can't have a duplicate attribute on an item, UnusedDuplicate and UnusedMultiple. This PR deduplicates their behavior into UnusedMultiple. In a separate commit, it renames UnusedMultiple to DuplicateAttribute, a more sensible name.

Separately, the third commit fixes a small issue where diagnostics about attributes would be printed with .. as a path separator instead of ::

Thanks to Jonathan Brouwer for the suggestion to work on this!

r? @JonathanBrouwer

@rustbot

rustbot commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

Some changes occurred to diagnostic attributes.

cc @mejrs

@rustbot rustbot 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 Nov 13, 2026
@rust-log-analyzer

This comment has been minimized.

@petrak-at-canonical

Copy link
Copy Markdown
Contributor Author

I have the failures in rustdoc-ui fixed locally. Would you like the fixed version with or without commit 2? (the one that changes the names and so creates a very large diff)

Right now I cleverly have engineered a workflow where I have to create two versions of every patch

…teAttribute`

Currently, `UnusedDuplicate` is used when a duplicate attribute is a warning,
and `UnusedMultiple` is used when it is an error.
This commit removes the redundancy in favor of a new lint, `DuplicateAttribute`.

The error messages now look like "duplicate `X` attributes", instead of
"multiple `X` attributes" or "duplicate attribute".

Thanks to @JonathanBrouwer for the suggestion to work on this

@JonathanBrouwer JonathanBrouwer 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.

A few nitpicks, other than that this is great, thanks a lot!

View changes since this review

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 14, 2026
@rustbot

rustbot commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@JonathanBrouwer JonathanBrouwer 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.

@rust-bors

rust-bors Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 6de3ba1 has been tentatively approved by JonathanBrouwer

It will be put into the queue for this repository once PR CI succeeds.

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 16, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 16, 2026
…-diagnostic, r=JonathanBrouwer

Duplicate attribute diagnostic cleanups

Currently there are two different diagnostics for when you can't have a duplicate attribute on an item, `UnusedDuplicate` and `UnusedMultiple`. This PR deduplicates their behavior into `UnusedMultiple`. In a separate commit, it renames `UnusedMultiple` to `DuplicateAttribute`, a more sensible name.

Separately, the third commit fixes a small issue where diagnostics about attributes would be printed with `..` as a path separator instead of `::`

Thanks to Jonathan Brouwer for the suggestion to work on this!

r? @JonathanBrouwer
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 16, 2026
…-diagnostic, r=JonathanBrouwer

Duplicate attribute diagnostic cleanups

Currently there are two different diagnostics for when you can't have a duplicate attribute on an item, `UnusedDuplicate` and `UnusedMultiple`. This PR deduplicates their behavior into `UnusedMultiple`. In a separate commit, it renames `UnusedMultiple` to `DuplicateAttribute`, a more sensible name.

Separately, the third commit fixes a small issue where diagnostics about attributes would be printed with `..` as a path separator instead of `::`

Thanks to Jonathan Brouwer for the suggestion to work on this!

r? @JonathanBrouwer
rust-bors Bot pushed a commit that referenced this pull request Nov 16, 2026
…uwer

Rollup of 13 pull requests

Successful merges:

 - #166054 (stdarch subtree update)
 - #165289 (lexer: Update to Unicode 18)
 - #165960 (alloctests: use thread-local in `c_str_alloc_error`)
 - #166002 (#[optimize]: keep low opt levels unoptimized)
 - #166049 (rustc_target: Require altivec feature for ELFv2 powerpc64 targets)
 - #165200 (fix abi kind of thumb windows targets)
 - #165935 (Duplicate attribute diagnostic cleanups)
 - #165999 (Update TPDE submodule)
 - #166045 (rustdoc: Correctly filter deref impls on type aliases)
 - #166063 (Fix bad hyperlink)
 - #166066 (Update books)
 - #166072 (simplify Appearances iter)
 - #166075 (Remove dead code emitting `UnusedBuiltinAttribute`)
@Zalathar

Copy link
Copy Markdown
Member

@bors r-
@bors try jobs=test-x86_64-mingw-1

@rust-bors rust-bors Bot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 17, 2026
@rust-bors

rust-bors Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

This PR was contained in a rollup (#166080), which was unapproved.

View changes since this unapproval

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Nov 17, 2026
…, r=<try>

Duplicate attribute diagnostic cleanups


try-job: test-x86_64-mingw-1
@rust-bors

rust-bors Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

💔 Test for 0f4128d failed: CI. Failed job:

@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job test-x86_64-mingw-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
To only update this specific test, also pass `--test-args linkage-attr\raw-dylib\windows\link-ordinal-multiple.rs`

error: 1 errors occurred comparing output.
status: exit code: 1
command: PATH="D:\a\rust\rust\build\x86_64-pc-windows-gnu\stage2\bin;C:\Users\runneradmin\AppData\Roaming\Python\Python311\Scripts;C:\hostedtoolcache\windows\Python\3.11.9\x64\Scripts;C:\hostedtoolcache\windows\Python\3.11.9\x64;D:\a\rust\rust\ninja;D:\a\rust\rust\mingw64\bin;C:\msys64\usr\bin;D:\a\rust\rust\sccache;C:\Program Files\MongoDB\Server\7.0\bin;C:\vcpkg;C:\tools\zstd;C:\hostedtoolcache\windows\stack\3.11.1\x64;C:\cabal\bin;C:\ghcup\bin;C:\mingw64\bin;C:\Program Files\dotnet;C:\Program Files\MySQL\MySQL Server 8.4\bin;C:\Program Files\R\R-4.6.2\bin\x64;C:\SeleniumWebDrivers\GeckoDriver;C:\SeleniumWebDrivers\EdgeDriver;C:\SeleniumWebDrivers\ChromeDriver;C:\Program Files (x86)\sbt\bin;C:\Program Files (x86)\GitHub CLI;C:\Program Files\Git\bin;C:\Program Files (x86)\pipx_bin;C:\npm\prefix;C:\hostedtoolcache\windows\go\1.24.13\x64\bin;C:\hostedtoolcache\windows\Python\3.12.10\x64\Scripts;C:\hostedtoolcache\windows\Python\3.12.10\x64;C:\hostedtoolcache\windows\Ruby\3.3.13\x64\bin;C:\Program Files\OpenSSL\bin;C:\tools\kotlinc\bin;C:\hostedtoolcache\windows\Java_Temurin-Hotspot_jdk\17.0.21-9\x64\bin;C:\Program Files\ImageMagick-7.1.2-Q16-HDRI;C:\Program Files\Microsoft SDKs\Azure\CLI2\wbin;C:\ProgramData\kind;C:\ProgramData\Chocolatey\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files\WSL;C:\Program Files\PowerShell\7;C:\Program Files\Microsoft\Web Platform Installer;C:\Program Files\Microsoft SQL Server\170\Tools\Binn;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn;C:\Program Files\dotnet;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit;C:\Program Files (x86)\WiX Toolset v3.14\bin;C:\Program Files\Microsoft SQL Server\130\DTS\Binn;C:\Program Files\Microsoft SQL Server\140\DTS\Binn;C:\Program Files\Microsoft SQL Server\150\DTS\Binn;C:\Program Files\Microsoft SQL Server\160\DTS\Binn;C:\Program Files\Microsoft SQL Server\170\DTS\Binn;C:\ProgramData\chocolatey\lib\pulumi\tools\Pulumi\bin;C:\Program Files\CMake\bin;C:\Strawberry\c\bin;C:\Strawberry\perl\site\bin;C:\Strawberry\perl\bin;C:\ProgramData\chocolatey\lib\maven\apache-maven-3.9.16\bin;C:\Program Files\Microsoft Service Fabric\bin\Fabric\Fabric.Code;C:\Program Files\Microsoft SDKs\Service Fabric\Tools\ServiceFabricLocalClusterManager;C:\Program Files\LLVM\bin;C:\Program Files (x86)\LLVM\bin;C:\Program Files\nodejs;C:\Program Files\Git\cmd;C:\Program Files\Git\ucrt64\bin;C:\Program Files\Git\usr\bin;C:\Program Files\GitHub CLI;C:\tools\php;C:\Program Files (x86)\sbt\bin;C:\Program Files\Amazon\AWSCLIV2;C:\Program Files\Amazon\SessionManagerPlugin\bin;C:\Program Files\Amazon\AWSSAMCLI\bin;C:\Program Files\Microsoft SQL Server\130\Tools\Binn;C:\Program Files\mongosh;C:\Users\runneradmin\.dotnet\tools;C:\Users\runneradmin\.cargo\bin;C:\Users\runneradmin\AppData\Local\Microsoft\WindowsApps" "D:\\a\\rust\\rust\\build\\x86_64-pc-windows-gnu\\stage2\\bin\\rustc.exe" "D:\\a\\rust\\rust\\tests\\ui\\linkage-attr\\raw-dylib\\windows\\link-ordinal-multiple.rs" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=C:\\Users\\runneradmin\\.cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=D:\\a\\rust\\rust\\vendor" "--sysroot" "D:\\a\\rust\\rust\\build\\x86_64-pc-windows-gnu\\stage2" "--target=x86_64-pc-windows-gnu" "--check-cfg" "cfg(test,FALSE)" "-Zthreads=1" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "D:\\a\\rust\\rust\\build\\x86_64-pc-windows-gnu\\test\\ui\\linkage-attr\\raw-dylib\\windows\\link-ordinal-multiple" "-Znext-solver=coherence" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=D:\\a\\rust\\rust\\build\\x86_64-pc-windows-gnu\\native\\rust-test-helpers" "--edition=2015"
stdout: none
--- stderr -------------------------------
error: duplicate `link_ordinal` attributes
##[error]  --> D:\a\rust\rust\tests\ui\linkage-attr\raw-dylib\windows\link-ordinal-multiple.rs:5:5
   |
LL |     #[link_ordinal(2)] //~ ERROR duplicate `link_ordinal` attributes
   |     ^^^^^^^^^^^^^^^^^^ help: remove this attribute
   |
note: attribute also specified here
  --> D:\a\rust\rust\tests\ui\linkage-attr\raw-dylib\windows\link-ordinal-multiple.rs:4:5
   |
LL |     #[link_ordinal(1)]
   |     ^^^^^^^^^^^^^^^^^^

error: duplicate `link_ordinal` attributes
##[error]  --> D:\a\rust\rust\tests\ui\linkage-attr\raw-dylib\windows\link-ordinal-multiple.rs:8:5
   |
LL |     #[link_ordinal(2)] //~ ERROR duplicate `link_ordinal` attributes
   |     ^^^^^^^^^^^^^^^^^^ help: remove this attribute
   |
note: attribute also specified here
  --> D:\a\rust\rust\tests\ui\linkage-attr\raw-dylib\windows\link-ordinal-multiple.rs:7:5
   |
---
Currently active steps:
test::Ui { test_compiler: Compiler { stage: 2, host: x86_64-pc-windows-gnu, forced_compiler: false }, target: x86_64-pc-windows-gnu } at src\bootstrap\src\core\build_steps\test.rs:2032
test::Compiletest { test_compiler: Compiler { stage: 2, host: x86_64-pc-windows-gnu, forced_compiler: false }, target: x86_64-pc-windows-gnu, mode: ui, suite: "ui", path: "tests/ui", compare_mode: None } at src\bootstrap\src\core\build_steps\test.rs:2032
Build completed unsuccessfully in 1:07:24
make: *** [Makefile:119: ci-mingw-x] Error 1
  local time: Tue Nov 17 02:43:36 CUT 2026
  network time: Tue, 17 Nov 2026 02:43:37 GMT
##[error]Process completed with exit code 2.
##[group]Run echo "disk usage:"
echo "disk usage:"

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

5 participants