Skip to content

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

Merged
merged 4 commits into from
Mar 5, 2018
Merged

Lint passing Cow by reference #2493

merged 4 commits into from
Mar 5, 2018

Conversation

bootandy
Copy link
Contributor

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

Add lint for reference to Cow to the same place in the code where
lint for reference to String lives.

rust-lang#2405
@bootandy bootandy closed this Feb 28, 2018
@bootandy
Copy link
Contributor Author

actually the same tests failed without this commit so the current test failures are unrelated

@bootandy bootandy reopened this Feb 28, 2018
@@ -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());
Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@clarfonthey
Copy link

I'd recommend changing &Cow<T> to &T personally

@oli-obk oli-obk merged commit 40ebff8 into rust-lang:master Mar 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants