You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If Trait is implemented for (), then a function returning impl Trait can accidentally return () as that implementor simply by a misplaced semicolon. Clippy could have a lint against
any return position impl Trait
whose concrete type is (),
but where that () value did not come from a literal () expression in tail position or return.
This lint would fit into the suspicious category.
Advantage
Users will be able to find such bugs quicker, without needing to first test the behavior of the returned opaquely-typed value and find that it is wrong.
An author might be intentionally passing through () by calling another function that currently returns () but will change in the future, and not want to satisfy the lint by adding ; () because that would disconnect the relationship between the two.
Example
The lint should fire on this code, because it returns () even though it looks like it returns something more meaningful:
fnkey() -> implEq{[1,10,2,0].sort()}
The lint should not fire on this code:
fnkey() -> implEq{[1,10,2,0].sort();// pretend I wrote something more useful here()}
It should also lint any part of the return value that is impl Trait; for example, the impl Trait might be wrapped in Result (or a tuple, or a Vec, or many other things):
fntry_get_key() -> Result<implEq,Error>{Ok([1,10,2,0].sort())// should fire}fnis_on_purpose_really() -> Result<implEq,Error>{Ok(())// should not fire}
It is debatable whether it should fire on this code:
fnhmm() -> implEq{let x = ();
x
}
but the let_unit_value lint fires in that case anyway.
The text was updated successfully, but these errors were encountered:
We were fortunately able to turn this into a warning in axum-core 0.4.4 by adding #[must_use] to IntoResponse::into_response, but it would have been less bad before had this clippy lint existed.
What it does
If
Trait
is implemented for()
, then a function returningimpl Trait
can accidentally return()
as that implementor simply by a misplaced semicolon. Clippy could have a lint againstimpl Trait
()
,()
value did not come from a literal()
expression in tail position orreturn
.This lint would fit into the
suspicious
category.Advantage
Users will be able to find such bugs quicker, without needing to first test the behavior of the returned opaquely-typed value and find that it is wrong.
See also prior discussion on IRLO.
Drawbacks
An author might be intentionally passing through
()
by calling another function that currently returns()
but will change in the future, and not want to satisfy the lint by adding; ()
because that would disconnect the relationship between the two.Example
The lint should fire on this code, because it returns
()
even though it looks like it returns something more meaningful:The lint should not fire on this code:
It should also lint any part of the return value that is
impl Trait
; for example, theimpl Trait
might be wrapped inResult
(or a tuple, or aVec
, or many other things):It is debatable whether it should fire on this code:
but the
let_unit_value
lint fires in that case anyway.The text was updated successfully, but these errors were encountered: