Repository navigation
Add lint against duplicate parameter names in fns without body - #165366
Conversation
|
cc @Amanieu, @folkertdev, @sayantn |
This comment has been minimized.
This comment has been minimized.
|
Reminder, once the PR becomes ready for a review, use |
This comment has been minimized.
This comment has been minimized.
|
|
||
| for param in params { | ||
| if let ast::PatKind::Ident(_, ident, _) = param.pat.kind { | ||
| if ident.name == kw::SelfLower { |
There was a problem hiding this comment.
I'd prefer if we use param.is_self() here, though it does exactly the same it's a bit more clear
|
@rust-lang/lang I believe this is a valuable lint because:
|
|
@rustbot ready |
|
The lint we'd be adopting here is named Makes sense to me. Thanks @annieversary, @JonathanBrouwer. @rfcbot fcp merge lang |
|
@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. |
|
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. |
|
📋 Only approved PRs can be forced. |
|
@bors r+ force |
…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
|
💔 I suspect this PR failed tests as part of a rollup After fixing the problem, consider running a try job for the failed job before re-approving. |
|
This pull request was unapproved. This PR was contained in a rollup (#166345), which was unapproved. |
|
^ 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+ |
…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
…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)
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
…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)
|
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. Next Steps:
@rustbot label: +perf-regression Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)This perf run didn't have relevant results for this metric. CyclesThis perf run didn't have relevant results for this metric. Binary sizeThis perf run didn't have relevant results for this metric. Artifact size: 406.41 MiB -> 406.45 MiB (0.01%) |
|
It's hard for me to see what is noise and what is real, this had noticably more changed benchmarks than other rollup members |
…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)
|
perf triage:
@rustbot label: +perf-regression-triaged |
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.
Note: a few functions in the compiler fell into this, like
_vluti4q_lane_s16_x2, so I've also changed these.r? JonathanBrouwer