-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Lint passing Cow by reference #2493
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
Add lint for reference to Cow to the same place in the code where lint for reference to String lives. rust-lang#2405
actually the same tests failed without this commit so the current test failures are unrelated |
clippy_lints/src/ptr.rs
Outdated
@@ -213,6 +213,21 @@ fn check_fn(cx: &LateContext, decl: &FnDecl, fn_id: NodeId, opt_body_id: Option< | |||
}, | |||
); | |||
} | |||
} else if match_type(cx, ty, &paths::COW) { | |||
let as_str = format!("{}", snippet_opt(cx, arg.span).unwrap()); |
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.
Is it ok to call unwrap() like this? I could import the function snippet() instead as that doesn't return a Result object
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'll review more next week, but clippy dogfood will disallow the unwrap and the trivial format.
If there is no snippet, we should not be producing a suggestion.
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.
Interestingly the dogfood test passed for me locally with this code.
I will update this code as you suggested, thanks.
I'd recommend changing |
Add `rustc --explain E0308` line to relevant tests
Add lint for reference to Cow to the same place in the code where
the lint for detecting a reference to String lives.
Fixes #2405