-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New lint: Returning unit type when expecting Ord #5080
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
Comments
Should extend this to all places that expect function |
Yes, that's pretty much what my titles says I think. |
It's probably not a good first issue, you have to look at the bounds of the generic function and check if the last statement of the closure is an explicit |
Yeah, to make it generally apply to |
This lint catches cases where the last statement of a closure expecting an instance of Ord has a trailing semi-colon. It compiles since the closure ends up return () which also implements Ord but causes unexpected results in cases such as sort_by_key. Fixes rust-lang#5080
This lint catches cases where the last statement of a closure expecting an instance of Ord has a trailing semi-colon. It compiles since the closure ends up return () which also implements Ord but causes unexpected results in cases such as sort_by_key. Fixes rust-lang#5080
This lint catches cases where the last statement of a closure expecting an instance of Ord has a trailing semi-colon. It compiles since the closure ends up return () which also implements Ord but causes unexpected results in cases such as sort_by_key. Fixes rust-lang#5080
This lint catches cases where the last statement of a closure expecting an instance of Ord has a trailing semi-colon. It compiles since the closure ends up return () which also implements Ord but causes unexpected results in cases such as sort_by_key. Fixes rust-lang#5080
This lint catches cases where the last statement of a closure expecting an instance of Ord has a trailing semi-colon. It compiles since the closure ends up return () which also implements Ord but causes unexpected results in cases such as sort_by_key. Fixes rust-lang#5080
This lint catches cases where the last statement of a closure expecting an instance of Ord has a trailing semi-colon. It compiles since the closure ends up return () which also implements Ord but causes unexpected results in cases such as sort_by_key. Fixes rust-lang#5080
I think this could be generalized to any function that implicitly returns fn my_fn() -> SomeType {
...
}
fn foo<T>() -> T where T: SomeBound() {
...
my_fn();
} If both |
From what I've seen |
Reprise: new lint: Unintentional return of unit from closures expecting Ord This lint catches cases where the last statement of a closure expecting an instance of Ord has a trailing semi-colon. It compiles since the closure ends up return () which also implements Ord but causes unexpected results in cases such as sort_by_key. Fixes #5080 Reprise of #5348 where I addressed all the comments there
Reprise: new lint: Unintentional return of unit from closures expecting Ord This lint catches cases where the last statement of a closure expecting an instance of Ord has a trailing semi-colon. It compiles since the closure ends up return () which also implements Ord but causes unexpected results in cases such as sort_by_key. Fixes #5080 Reprise of #5348 where I addressed all the comments there changelog: add lint [`unit_return_expecting_ord`]
Uh oh!
There was an error while loading. Please reload this page.
I had a very weird bug today, I was trying to sort my list using a somewhat complicated key expression with
sort_by_key
, but no sorting was happening it was like getting a random order.Turns out I had an extra semicolon at the end of my expression, making my key return
()
instead which implementsOrd
(alwaysEqual
).Example:
The text was updated successfully, but these errors were encountered: