Replace elided variable in let_unit with () when used
Situation: `let_unit` lints when an expression binds a unit (`()`) to a variable. In some cases this binding may be passed down to another function. Currently, the lint removes the binding without considering usage. Change: All usages of the elided variable are now replaced with `()`. fixes: #12594
This commit is contained in:
parent
124e68bef8
commit
eee4db928f
4 changed files with 100 additions and 3 deletions
|
|
@ -177,3 +177,21 @@ async fn issue10433() {
|
|||
}
|
||||
|
||||
pub async fn issue11502(a: ()) {}
|
||||
|
||||
pub fn issue12594() {
|
||||
fn returns_unit() {}
|
||||
|
||||
fn returns_result<T>(res: T) -> Result<T, ()> {
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
fn actual_test() {
|
||||
// create first a unit value'd value
|
||||
returns_unit();
|
||||
returns_result(()).unwrap();
|
||||
returns_result(()).unwrap();
|
||||
// make sure we replace only the first variable
|
||||
let res = 1;
|
||||
returns_result(res).unwrap();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -177,3 +177,21 @@ async fn issue10433() {
|
|||
}
|
||||
|
||||
pub async fn issue11502(a: ()) {}
|
||||
|
||||
pub fn issue12594() {
|
||||
fn returns_unit() {}
|
||||
|
||||
fn returns_result<T>(res: T) -> Result<T, ()> {
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
fn actual_test() {
|
||||
// create first a unit value'd value
|
||||
let res = returns_unit();
|
||||
returns_result(res).unwrap();
|
||||
returns_result(res).unwrap();
|
||||
// make sure we replace only the first variable
|
||||
let res = 1;
|
||||
returns_result(res).unwrap();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,5 +51,24 @@ LL + Some(_) => (),
|
|||
LL + };
|
||||
|
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
error: this let-binding has unit value
|
||||
--> tests/ui/let_unit.rs:190:9
|
||||
|
|
||||
LL | let res = returns_unit();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: omit the `let` binding
|
||||
|
|
||||
LL | returns_unit();
|
||||
|
|
||||
help: variable `res` of type `()` can be replaced with explicit `()`
|
||||
|
|
||||
LL | returns_result(()).unwrap();
|
||||
| ~~
|
||||
help: variable `res` of type `()` can be replaced with explicit `()`
|
||||
|
|
||||
LL | returns_result(()).unwrap();
|
||||
| ~~
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue