W1001: a variable used as a call target is reported unused
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 14
- Forks
- 2
- Avg merge
- 12h 42m
- Merged PRs (30d)
- 61
Description
A variable that holds a closure's function pointer and is then called is reported as unused.
import core::ops;
fn apply(f : Closure1<i32, i32>, v : i32) -> i32 {
let p = f.func;
return p(f.env, v);
}
fn main() -> i32 {
print(apply(| x : i32 | x + 1, 5));
return 0;
}
Warning[W1001] at 4:3: Unused variable 'p'
help: prefix with underscore to suppress -- replace with `_p`
p is the callee, so the use is real and the suggested fix would be wrong -- renaming it to _p leaves it called under a name that says it is unused.
The binding cannot be avoided today. Calling the field directly is refused:
return (f.func)(f.env, v);
Error: Function pointers are not natively callable yet; use closure interfaces.
So every closure call written by hand trips this. stdlib/core/option.vx and stdlib/core/result.vx both use the let p = f.func; p(f.env, v) idiom, and the warning appears for whichever of their combinators a program actually instantiates -- which is why it shows up on some builds and not others.
A use in argument position is counted correctly; only the callee position is missed:
return Result<U, E>::Ok(p(f.env, v)); // no warning
return p(f.env, v); // warned
Not urgent -- it is a warning, and the code is correct -- but it teaches a wrong fix.
Contributor guide
No contributing guide indexed for this repository
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
Start by running the supplied closure example and inspect the unused-variable analysis for the callee position. Compare the behavior with the argument-position example, then check the related idiom in stdlib/core/option.vx and stdlib/core/result.vx. Done means a variable used as a call target is not reported as unused, while genuinely unused bindings still produce W1001.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100