Open
Description
Inspiration: this StackOverflow post
Given the following code:
fn largest<T>(list: &[T]) -> &T
where T: PartialOrd + Copy
{
let largest = &list[0];
for item in list.iter() {
if item > largest {
let largest = item;
}
}
largest
}
The current output is:
warning: unused variable: `largest`
--> src/main.rs:8:17
|
8 | let largest = item;
| ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_largest`
|
= note: `#[warn(unused_variables)]` on by default
Ideally the output should look like:
warning: unused variable: `largest`
--> src/main.rs:8:17
|
8 | let largest = item;
| ^^^^^^^
...
4 | let largest = &list[0];
| ------- note: variable with the same name defined here
...
8 | let largest = item;
| ^^^ help: remove this `let` to assign instead of creating a new variable
|
= note: `#[warn(unused_variables)]` on by default
Some discussion on how to implement this on Zulip.
Metadata
Metadata
Assignees
Labels
Area: Control flowArea: Messages for errors, warnings, and lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Name/path resolution done by `rustc_resolve` specificallyCategory: An issue proposing an enhancement or a PR with one.Relevant to the compiler team, which will review and decide on the PR/issue.