Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't warn on unused arguments in unimplemented functions #78136

Closed
bugaevc opened this issue Oct 20, 2020 · 2 comments
Closed

Don't warn on unused arguments in unimplemented functions #78136

bugaevc opened this issue Oct 20, 2020 · 2 comments
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@bugaevc
Copy link

bugaevc commented Oct 20, 2020

The following code:

fn foo(arg: i32) {
    todo!()
}

fn main() {
    foo(35);
}

(playground)

Currently emits a warning:

warning: unused variable: `arg`
 --> src/main.rs:1:8
  |
1 | fn foo(arg: i32) {
  |        ^^^ help: if this is intentional, prefix it with an underscore: `_arg`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: 1 warning emitted

But todo!() clearly indicates that the argument is unused neither because it's intended to be ignored (in which case it'd be appropriate to rename it to _arg), nor because the author forgot to use it — but simply because the relevant code to use it has not been written yet.

Since todo!() itself does not trigger any warnings (meaning, rustc is fine with trying to compile code with parts that are explicitly not implemented yet), it doesn't seem appropriate to warn about unused variables that are "covered" by todo!().

@JohnTitor JohnTitor added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 20, 2020
charles-r-earp added a commit to charles-r-earp/rust that referenced this issue Dec 9, 2020
@Dylan-DPC
Copy link
Member

Closing this since it is intended based on the comment here

@Dylan-DPC Dylan-DPC closed this as not planned Won't fix, can't repro, duplicate, stale Jan 7, 2024
@Vlad-Shcherbina
Copy link

That comment says that usages in unreachable parts of the code don't count. This makes sense as an intended behavior.

And saying that the function with the body made of a single unreachable()! doesn't use its arguments is a consistent interpretation of the original general rule. Though it has nothing to do with unreachable()!. The function with an empty body would not use its arguments for the exact same reason (because there are no occurences of the variables in the reachable parts of the function body).

However, this issue is not about the general rule being implemented incorrectly. It's an observation that the general rule, in this particular case, leads to suboptimal developer experience.

So it's worth at least considering making an exception from the rule for this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants