-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Implemented option_option lint #2299
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
Conversation
clippy_lints/src/types.rs
Outdated
cx, | ||
OPTION_OPTION, | ||
ast_ty.span, | ||
"consider using `Option<T>` instead of `Option<Option<T>>`", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... "or a custom enum if you need to distinguish all 3 cases"
clippy_lints/src/types.rs
Outdated
OPTION_OPTION, | ||
ast_ty.span, | ||
"consider using `Option<T>` instead of `Option<Option<T>>`", | ||
"`Option<_>` is easier to use than `Option<Option<_>`", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this needs the additional help. Just use span_lint
I made the requested changes. |
output_nested(); | ||
|
||
// The lint allows this | ||
let local: Option<Option<u8>> = None; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know why this isn't linted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the discussion in #97. I thought the lint shouldn't apply to local bindings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked through the discussion and could not find anything. Can you quote what you mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#97 (comment)
"It should catch Option<Option<..>>
types in function signatures and perhaps typedefs."
I took this to mean only function signatures, struct definitions and enum definitions. I might have been incorrect.
In any case, I think it would be strange to allow the type in expressions but not allow naming those expressions local bindings. Maybe we should move this discussion back into the issue if you want to discuss further.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Being conservative is fine here.
Rename `vec` to `ty` in `match_type_parameter`. This variable is a type and not a vector. Previously it would only refer to `Vec<_>` so the name used to make sense.
This implements the lint introduced in issue #97