Skip to content
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

add owned_cow lint #13948

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

add owned_cow lint #13948

wants to merge 3 commits into from

Conversation

llogiq
Copy link
Contributor

@llogiq llogiq commented Jan 5, 2025

Closes #13697


changelog: add [owned_cow] lint

@rustbot
Copy link
Collaborator

rustbot commented Jan 5, 2025

r? @y21

rustbot has assigned @y21.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jan 5, 2025
@llogiq llogiq force-pushed the too-owned branch 5 times, most recently from e442270 to 3f8fe08 Compare January 5, 2025 13:15
///
/// ### Example
/// ```no_run
/// let wrogn: std::borrow::Cow<'_, String>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

 ___________________
< looks like a typo >
 -------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a deliberate misspelling. Spelling "wrong" wrongly is a humourous way of normalizing making errors, learning from them and fixing them.

@samueltardieu
Copy link
Contributor

The hits on darling_core look like a FP, as it suggests changing Cow<'a, str> with &'a str in a public struct field definition.

@llogiq
Copy link
Contributor Author

llogiq commented Jan 5, 2025

@samueltardieu for me, it suggests replacing the String in Cow<'a, String> with str, which for me is a true positive. The lint has no code to suggest &str, and I cannot repro anything like that here either.

@samueltardieu
Copy link
Contributor

@samueltardieu for me, it suggests replacing the String in Cow<'a, String> with str, which for me is a true positive. The lint has no code to suggest &str, and I cannot repro anything like that here either.

Indeed, I misread it, sorry for the false alarm!

clippy_lints/src/too_owned.rs Outdated Show resolved Hide resolved
tests/ui/too_owned.rs Outdated Show resolved Hide resolved
clippy_lints/src/too_owned.rs Outdated Show resolved Hide resolved
clippy_lints/src/too_owned.rs Outdated Show resolved Hide resolved
clippy_lints/src/too_owned.rs Outdated Show resolved Hide resolved
&& let Some(args) = last_seg.args
&& let [_lt, carg] = args.args
&& let hir::GenericArg::Type(cty) = carg
&& let Some((span, repl)) = replacement(cx, cty)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth adding a span checks like !is_external_macro(...) to avoid cases where the user can't do anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The types checks already appear to do that.

/// let right: std::borrow::Cow<'_, str>;
/// ```
#[clippy::version = "1.85.0"]
pub OWNED_COW,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just here to say that I love the lint name 🐄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TooOwned
6 participants