Diagnostics do not consider lifetime parameters to be "generics"
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
fn example<'one: 'two, 'two, Three, const Four: usize, Five>() {}
fn main() {
example::<()>();
}
Current output
error[E0107]: function takes 3 generic arguments but 1 generic argument was supplied
--> src/main.rs:4:5
|
4 | example::<()>();
| ^^^^^^^ -- supplied 1 generic argument
| |
| expected 3 generic arguments
|
note: function defined here, with 3 generic parameters: `Three`, `Four`, `Five`
--> src/main.rs:1:4
|
1 | fn example<'one: 'two, 'two, Three, const Four: usize, Five>() {}
| ^^^^^^^ ----- ----------------- ----
help: add missing generic arguments
|
4 | example::<(), Four, Five>();
| ++++++++++++
Desired output
error[E0107]: function takes 3 non-lifetime arguments but 1 non-lifetime argument was supplied
--> src/main.rs:4:5
|
4 | example::<()>();
| ^^^^^^^ -- supplied 1 non-lifetime argument
| |
| expected 3 non-lifetime arguments
|
note: function defined here, with 3 non-lifetime parameters: `Three`, `Four`, `Five`
--> src/main.rs:1:4
|
1 | fn example<'one: 'two, 'two, Three, const Four: usize, Five>() {}
| ^^^^^^^ ----- ----------------- ----
help: add missing non-lifetime arguments
|
4 | example::<(), Four, Five>();
| ++++++++++++
Rationale and extra context
Lifetimes parameters are also generic parameters, so the statement that the example has 3 generic arguments is counterfactual. For function items in particular, early-bound lifetimes are also generic parameters of the function item type.
See this URLO topic for an example of someone who understands the distinction between late and early lifetime parameters being confused by the current diagnostic (being mislead that a function's lifetime parameter was late bound because it "only had 2 generic parameters" based on the diagnostic).
Other cases
//! This version shows that the compiler currently outputs two
//! separate warnings, one for lifetime parameters and one for
//! non-lifetime parameters
fn example<'one: 'two, 'two, Three, const Four: usize, Five>() {}
fn main() {
example::<'static, ()>();
}
/*
error[E0107]: function takes 2 lifetime arguments but 1 lifetime argument was supplied
--> src/main.rs:4:5
|
4 | example::<'static, ()>();
| ^^^^^^^ ------- supplied 1 lifetime argument
| |
| expected 2 lifetime arguments
|
note: function defined here, with 2 lifetime parameters: `'one`, `'two`
--> src/main.rs:1:4
|
1 | fn example<'one: 'two, 'two, Three, const Four: usize, Five>() {}
| ^^^^^^^ ---- ----
help: add missing lifetime argument
|
4 | example::<'static, 'static, ()>();
| +++++++++
error[E0107]: function takes 3 generic arguments but 1 generic argument was supplied
--> src/main.rs:4:5
|
4 | example::<'static, ()>();
| ^^^^^^^ -- supplied 1 generic argument
| |
| expected 3 generic arguments
|
note: function defined here, with 3 generic parameters: `Three`, `Four`, `Five`
--> src/main.rs:1:4
|
1 | fn example<'one: 'two, 'two, Three, const Four: usize, Five>() {}
| ^^^^^^^ ----- ----------------- ----
help: add missing generic arguments
|
4 | example::<'static, (), Four, Five>();
| ++++++++++++
*/
*/
Rust Version
Rust playground
Stable channel
Build using the Stable version: 1.80.0
Beta channel
Build using the Beta version: 1.81.0-beta.2
(2024-07-25 08328a323ecd80b443a8)
Nightly channel
Build using the Nightly version: 1.82.0-nightly
(2024-08-02 fd8d6fbe505ecf913f5e)
Anything else?
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no repository file or test. Reproduce the E0107 examples on the stable channel, then trace the compiler diagnostic that reports generic and lifetime argument counts. Done means the diagnostics consistently describe non-lifetime parameters as non-lifetime arguments while preserving the separate lifetime case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100