Skip to content

Add lint against duplicate parameter names in fns without body - #165366

Merged
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
annieversary:duplicate-parameter-names
Nov 22, 2026
Merged

rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
annieversary:duplicate-parameter-names

Conversation

@annieversary

@annieversary annieversary commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

View all comments

Adds a lint to warn against duplicate parameter names in functions without bodies (in traits and extern blocks); function pointers; and parenthesised generic arguments.

This behaviour is allowed due to the compiler not checking the names of parameters in these cases, but it's confusing that this is allowed. Turning a signature with duplicated parameter names into a function with a body would error, so we should be warning against it.

trait Test {
    fn trait_fn(x: usize, x: usize);
    //~^ WARN identifier `x` is bound more than once in this parameter list
}

unsafe extern "C" {
    fn extern_fn(x: usize, x: usize);
    //~^ WARN identifier `x` is bound more than once in this parameter list
}

type FnPointer = fn(x: usize, x: u64);
//~^ WARN identifier `x` is bound more than once in this parameter list

fn impl_trait(f: impl FnOnce(x: usize, x: usize)) {}
//~^ WARN identifier `x` is bound more than once in this parameter list

Note: a few functions in the compiler fell into this, like _vluti4q_lane_s16_x2, so I've also changed these.

r? JonathanBrouwer

@rustbot

rustbot commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

stdarch is developed in its own repository. If possible, consider making this change to rust-lang/stdarch instead.

cc @Amanieu, @folkertdev, @sayantn

@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. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Nov 2, 2026
@rust-log-analyzer

This comment has been minimized.

@JonathanBrouwer JonathanBrouwer changed the title add warning against duplicate parameter names in fns without body Add lint against duplicate parameter names in fns without body Nov 3, 2026

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

Looks good in general, happy to see this!
Just some minor comments before we send this to lang

View changes since this review

Comment thread compiler/rustc_lint/src/builtin.rs Resolved
Comment thread compiler/rustc_lint/src/builtin.rs Resolved
Comment thread tests/ui/fn/fn-ptr-pattern.rs Resolved
@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 3, 2026
@rustbot

rustbot commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

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

@rust-log-analyzer

This comment has been minimized.

Comment thread compiler/rustc_lint/src/builtin.rs Outdated

for param in params {
if let ast::PatKind::Ident(_, ident, _) = param.pat.kind {
if ident.name == kw::SelfLower {

@JonathanBrouwer JonathanBrouwer Nov 4, 2026 •

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.

I'd prefer if we use param.is_self() here, though it does exactly the same it's a bit more clear

View changes since the review

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

Other than that and fixing CI this should be good

View changes since this review

@JonathanBrouwer JonathanBrouwer added I-lang-nominated Nominated for discussion during a lang team meeting. S-waiting-on-t-lang Status: Awaiting decision from T-lang labels Nov 4, 2026
@JonathanBrouwer

Copy link
Copy Markdown
Member

@rust-lang/lang
This PR proposes a new lint against duplicate parameter names in functions without a body, see the PR description for the 4 examples in which it triggers.

I believe this is a valuable lint because:

  • Duplicate parameter names are confusing even if they have no semantic meaning, and usually accidental
  • If we want to have named arguments in the future (for which there is no accepted RFC yet), we'll need to discourage people from using this as the names would then have semantic meaning
    fn example(f: fn(x: usize, x: usize)) {
      f(x: 1, x: 2) // ???
    }

@annieversary

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot 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 Nov 5, 2026

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

r=me with lang approval

View changes since this review

@traviscross traviscross added the I-lang-radar Items that are on lang's radar and will need eventual work or consideration. label Nov 11, 2026
@traviscross

Copy link
Copy Markdown
Contributor

The lint we'd be adopting here is named DUPLICATE_PARAMETER_NAMES and is warn-by-default.

Makes sense to me. Thanks @annieversary, @JonathanBrouwer.

@rfcbot fcp merge lang

@rust-rfcbot rust-rfcbot added the T-lang Relevant to the language team label Nov 11, 2026
@rust-rfcbot

rust-rfcbot commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

@traviscross has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns.
See this document for info about what commands tagged team members can give me.

@rust-rfcbot rust-rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Nov 11, 2026
@traviscross traviscross added the P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang label Nov 11, 2026
@clarfonthey clarfonthey removed the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Nov 11, 2026
@clarfonthey

clarfonthey commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

We really do need to make the pings not label-based, since proposing an FCP for lang will still ping libs if any library code was modified.

@rust-bors

rust-bors Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

📋 Only approved PRs can be forced.

@JonathanBrouwer

Copy link
Copy Markdown
Member

@bors r+ force

@rust-bors

rust-bors Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 456b3c7 has been approved by JonathanBrouwer

It is now in the queue for this repository.

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 22, 2026
…ames, r=JonathanBrouwer

Add lint against duplicate parameter names in fns without body

Adds a lint to warn against duplicate parameter names in functions without bodies (in traits and extern blocks); function pointers; and parenthesised generic arguments.

This behaviour is allowed due to the compiler not checking the names of parameters in these cases, but it's confusing that this is allowed. Turning a signature with duplicated parameter names into a function with a body would error, so we should be warning against it.

```rust
trait Test {
    fn trait_fn(x: usize, x: usize);
    //~^ WARN identifier `x` is bound more than once in this parameter list
}

unsafe extern "C" {
    fn extern_fn(x: usize, x: usize);
    //~^ WARN identifier `x` is bound more than once in this parameter list
}

type FnPointer = fn(x: usize, x: u64);
//~^ WARN identifier `x` is bound more than once in this parameter list

fn impl_trait(f: impl FnOnce(x: usize, x: usize)) {}
//~^ WARN identifier `x` is bound more than once in this parameter list
```

Note: a few functions in the compiler fell into this, like `_vluti4q_lane_s16_x2`, so I've also changed these.

r? JonathanBrouwer
@JonathanBrouwer

Copy link
Copy Markdown
Member

💔 I suspect this PR failed tests as part of a rollup
@bors r-

After fixing the problem, consider running a try job for the failed job before re-approving.

running 50 tests
i........................................
compiler/rustc_lint/src/builtin.rs - builtin::DUPLICATE_PARAMETER_NAMES (line 748) ... F
........                                                                                                                                                                                                                                                                                                            

failures:

---- compiler/rustc_lint/src/builtin.rs - builtin::DUPLICATE_PARAMETER_NAMES (line 748) stdout ----
warning: unknown lint: `duplicate_parameter_names`
   --> compiler/rustc_lint/src/builtin.rs:749:9
    |
749 | #![deny(duplicate_parameter_names)]
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: `#[warn(unknown_lints)]` on by default

warning: 1 warning emitted

Test compiled successfully, but it's marked `compile_fail`.
\ (no newline at end of output)
---- compiler/rustc_lint/src/builtin.rs - builtin::DUPLICATE_PARAMETER_NAMES (line 748) stdout end ----

@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 22, 2026
@rust-bors

rust-bors Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

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

View changes since this unapproval

@JonathanBrouwer

Copy link
Copy Markdown
Member

^ This needs to have the infamous lint doctest bootstrap gate, I've saved you the misery of finding the exact magic incantation needed to satisfy the bootstrap gods, and commited it for you :)

@bors r+

@rust-bors

rust-bors Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 2bd564d 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 22, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 22, 2026
…ames, r=JonathanBrouwer

Add lint against duplicate parameter names in fns without body

Adds a lint to warn against duplicate parameter names in functions without bodies (in traits and extern blocks); function pointers; and parenthesised generic arguments.

This behaviour is allowed due to the compiler not checking the names of parameters in these cases, but it's confusing that this is allowed. Turning a signature with duplicated parameter names into a function with a body would error, so we should be warning against it.

```rust
trait Test {
    fn trait_fn(x: usize, x: usize);
    //~^ WARN identifier `x` is bound more than once in this parameter list
}

unsafe extern "C" {
    fn extern_fn(x: usize, x: usize);
    //~^ WARN identifier `x` is bound more than once in this parameter list
}

type FnPointer = fn(x: usize, x: u64);
//~^ WARN identifier `x` is bound more than once in this parameter list

fn impl_trait(f: impl FnOnce(x: usize, x: usize)) {}
//~^ WARN identifier `x` is bound more than once in this parameter list
```

Note: a few functions in the compiler fell into this, like `_vluti4q_lane_s16_x2`, so I've also changed these.

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

Rollup of 13 pull requests

Successful merges:

 - #166266 (miri subtree update)
 - #155216 (match: Use an aggregate equality comparison for constant array/slice patterns)
 - #166142 (Lower to `hir::Param`s for extern functions)
 - #163315 (s390x: replace -Ctarget-feature=+backchain with -Cforce-frame-pointers)
 - #165238 (make conflicting_repr_hints a hard error)
 - #165366 (Add lint against duplicate parameter names in fns without body)
 - #166269 (libcore: Revert some comment changes)
 - #166287 (Use `core::ptr` in `implicit_provenance_casts` help for `no_std` crates)
 - #166306 (bootstrap: Stop passing `-Ztrim-paths` to cargo now that it's stable in beta)
 - #166309 (Add `#[must_use]` to `Ip*Addr::as_octets` methods)
 - #166315 (rustc_diagnostic_item macros added on some iter functions)
 - #166331 (Include Build IDs in VEX V5 executables)
 - #166349 (compiletest: Remove some old special-case code paths)
@rust-bors
rust-bors Bot merged commit 7db3c38 into rust-lang:main Nov 22, 2026
14 checks passed
@rustbot rustbot added this to the 1.102.0 milestone Nov 22, 2026
rust-bors Bot pushed a commit that referenced this pull request Nov 22, 2026
Rollup merge of #165366 - annieversary:duplicate-parameter-names, r=JonathanBrouwer

Add lint against duplicate parameter names in fns without body

Adds a lint to warn against duplicate parameter names in functions without bodies (in traits and extern blocks); function pointers; and parenthesised generic arguments.

This behaviour is allowed due to the compiler not checking the names of parameters in these cases, but it's confusing that this is allowed. Turning a signature with duplicated parameter names into a function with a body would error, so we should be warning against it.

```rust
trait Test {
    fn trait_fn(x: usize, x: usize);
    //~^ WARN identifier `x` is bound more than once in this parameter list
}

unsafe extern "C" {
    fn extern_fn(x: usize, x: usize);
    //~^ WARN identifier `x` is bound more than once in this parameter list
}

type FnPointer = fn(x: usize, x: u64);
//~^ WARN identifier `x` is bound more than once in this parameter list

fn impl_trait(f: impl FnOnce(x: usize, x: usize)) {}
//~^ WARN identifier `x` is bound more than once in this parameter list
```

Note: a few functions in the compiler fell into this, like `_vluti4q_lane_s16_x2`, so I've also changed these.

r? JonathanBrouwer
github-actions Bot pushed a commit to rust-lang/stdarch that referenced this pull request Nov 23, 2026
…uwer

Rollup of 13 pull requests

Successful merges:

 - rust-lang/rust#166266 (miri subtree update)
 - rust-lang/rust#155216 (match: Use an aggregate equality comparison for constant array/slice patterns)
 - rust-lang/rust#166142 (Lower to `hir::Param`s for extern functions)
 - rust-lang/rust#163315 (s390x: replace -Ctarget-feature=+backchain with -Cforce-frame-pointers)
 - rust-lang/rust#165238 (make conflicting_repr_hints a hard error)
 - rust-lang/rust#165366 (Add lint against duplicate parameter names in fns without body)
 - rust-lang/rust#166269 (libcore: Revert some comment changes)
 - rust-lang/rust#166287 (Use `core::ptr` in `implicit_provenance_casts` help for `no_std` crates)
 - rust-lang/rust#166306 (bootstrap: Stop passing `-Ztrim-paths` to cargo now that it's stable in beta)
 - rust-lang/rust#166309 (Add `#[must_use]` to `Ip*Addr::as_octets` methods)
 - rust-lang/rust#166315 (rustc_diagnostic_item macros added on some iter functions)
 - rust-lang/rust#166331 (Include Build IDs in VEX V5 executables)
 - rust-lang/rust#166349 (compiletest: Remove some old special-case code paths)
@rust-timer

Copy link
Copy Markdown
Collaborator

Note

This PR was benchmarked as part of triage of its containing rollup: triage URL.

Finished benchmarking commit (b290e35): comparison URL.

Overall result: ❌✅ regressions and improvements - please read:

Our benchmarks found a performance regression caused by this PR.
This might be an actual regression, but it can also be just noise.

Next Steps:

  • If the regression was expected or you think it can be justified,
    please write a comment with sufficient written justification, and add
    @rustbot label: +perf-regression-triaged to it, to mark the regression as triaged.
  • If you think that you know of a way to resolve the regression, try to create
    a new PR with a fix for the regression.
  • If you do not understand the regression or you think that it is just noise,
    you can ask the @rust-lang/wg-compiler-performance working group for help (members of this group
    were already notified of this PR).

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
0.2% [0.2%, 0.2%] 2
Regressions ❌
(secondary)
0.2% [0.0%, 0.5%] 21
Improvements ✅
(primary)
-0.2% [-0.2%, -0.2%] 3
Improvements ✅
(secondary)
-1.0% [-1.0%, -0.9%] 6
All ❌✅ (primary) -0.0% [-0.2%, 0.2%] 5

Max RSS (memory usage)

This perf run didn't have relevant results for this metric.

Cycles

This perf run didn't have relevant results for this metric.

Binary size

This perf run didn't have relevant results for this metric.

Artifact size: 406.41 MiB -> 406.45 MiB (0.01%)

@rustbot rustbot added the perf-regression Performance regression. label Nov 23, 2026
@JonathanBrouwer

Copy link
Copy Markdown
Member

It's hard for me to see what is noise and what is real, this had noticably more changed benchmarks than other rollup members

github-merge-queue Bot pushed a commit to rust-lang/miri that referenced this pull request Nov 23, 2026
…uwer

Rollup of 13 pull requests

Successful merges:

 - rust-lang/rust#166266 (miri subtree update)
 - rust-lang/rust#155216 (match: Use an aggregate equality comparison for constant array/slice patterns)
 - rust-lang/rust#166142 (Lower to `hir::Param`s for extern functions)
 - rust-lang/rust#163315 (s390x: replace -Ctarget-feature=+backchain with -Cforce-frame-pointers)
 - rust-lang/rust#165238 (make conflicting_repr_hints a hard error)
 - rust-lang/rust#165366 (Add lint against duplicate parameter names in fns without body)
 - rust-lang/rust#166269 (libcore: Revert some comment changes)
 - rust-lang/rust#166287 (Use `core::ptr` in `implicit_provenance_casts` help for `no_std` crates)
 - rust-lang/rust#166306 (bootstrap: Stop passing `-Ztrim-paths` to cargo now that it's stable in beta)
 - rust-lang/rust#166309 (Add `#[must_use]` to `Ip*Addr::as_octets` methods)
 - rust-lang/rust#166315 (rustc_diagnostic_item macros added on some iter functions)
 - rust-lang/rust#166331 (Include Build IDs in VEX V5 executables)
 - rust-lang/rust#166349 (compiletest: Remove some old special-case code paths)
@panstromek

Copy link
Copy Markdown
Contributor

perf triage:

include-blob and ctfe-stress are noise. libc and externs are real regressions - it makes sense because they contain a lot of functions without the body (externs is just 3k extern function definitions, libc is similar but real world). This is exactly what the lint checks. I guess there might a way to optimize the lint a bit more, but it doesn't feel super urgent to me. I'll file an issue, maybe somebody picks it up.

@rustbot label: +perf-regression-triaged

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

Labels

disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. I-lang-radar Items that are on lang's radar and will need eventual work or consideration. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. 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. T-lang Relevant to the language team to-announce Announce this issue on triage meeting

Projects

None yet

Development

Successfully merging this pull request may close these issues.