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

New lint: trait removed supertrait #470

Merged
merged 15 commits into from
Jun 17, 2023
Merged

New lint: trait removed supertrait #470

merged 15 commits into from
Jun 17, 2023

Conversation

era
Copy link
Contributor

@era era commented Jun 12, 2023

Resolves #232

Besides the new lint, this PR also includes a newer version of trustfall-rustdoc-adapter because we need the supertrait field.

Copy link
Owner

@obi1kenobi obi1kenobi left a comment

Choose a reason for hiding this comment

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

This looks really good so far. The lint query is correct and the new test crate is nicely set up. We're 90% of the way there and I'm excited to merge this very soon!

Two remaining things to consider: user ergonomics when this lint reports a problem, and expanded test coverage to prevent future debugging.

Users of cargo-semver-checks might not know that removing a supertrait is a breaking change. Let's channel the helpfulness of rustc and tailor the error message and description in the lint to make them maximally helpful. This is one of the major challenges of writing software aimed at a very large audience like "everyone writing Rust" 😅 But that also makes it really rewarding to get it right!

Consider expanding the test suite a bit with more true-positive cases as well as guard test cases against possible false-positives.

  • Example true-positive cases: removing one of multiple supertraits, removing supertrait when the subtrait is generic, or removing a generic supertrait.
  • Example false-positive guard cases: removing a lifetime trait bound (pub trait Foo<'a> : Bar + 'a then lose the 'a), changing the generic trait bound in a breaking way (to a different type, to a different lifetime, etc.) or in a non-breaking way (e.g. from i64 to Into<i64>).

The guard cases are as important as the true-positive test cases, since false-positives are very harmful: they make users have a bad experience and make them not trust the tool, and they cause support load for us when issues get opened and we have to triage and fix them. An ounce of prevention is worth a pound of cure :)

To come up with good guard cases, consider:

  • similar code changes that are non-breaking, and shouldn't be caught
  • similar changes that are breaking but should be caught by another lint — we have a policy that any breakage should be reported by one lint and one lint only, for the sake of user ergonomics.

Ping me with any questions! I'm super excited by all the awesome work you've been doing, and I'm very happy to support you along the way! 🚀

src/lints/trait_removed_supertrait.ron Outdated Show resolved Hide resolved
src/lints/trait_removed_supertrait.ron Outdated Show resolved Hide resolved
src/lints/trait_removed_supertrait.ron Outdated Show resolved Hide resolved
src/lints/trait_removed_supertrait.ron Outdated Show resolved Hide resolved
src/lints/trait_removed_supertrait.ron Outdated Show resolved Hide resolved
era and others added 5 commits June 13, 2023 08:23
Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>
Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>
Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>
Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>
src/lints/trait_removed_supertrait.ron Outdated Show resolved Hide resolved
human_readable_name: "supertrait removed or renamed",
description: "It is a breaking change to loosen generic bounds on a type since this can break users expecting the tightened bounds.",
required_update: Major,
reference_link: None,
Copy link
Owner

Choose a reason for hiding this comment

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

Any chance we can find something to cite here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I should have asked about this earlier, on the semver reference does not seem to be an entry for this lint.

There is this that is somewhat similar but it's definitely not the exact case nor does the explanation help (IMHO).

The documentation about supertraits helps to understand what is breaking indirectly.

Is it worth adding any of those links?

Copy link
Owner

Choose a reason for hiding this comment

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

Yes, the docs link for supertraits is the best option. It's not perfect, but it's certainly better than nothing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, I will add it :)

"public": "public",
"zero": 0,
},
error_message: "A supertrait was removed from a trait.",
Copy link
Owner

Choose a reason for hiding this comment

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

Perhaps tweak this to include a hint of why this might be a problem. Feel free to use some of the language from the description field.

test_outputs/trait_removed_supertrait.output.ron Outdated Show resolved Hide resolved
test_outputs/trait_removed_supertrait.output.ron Outdated Show resolved Hide resolved
test_outputs/trait_removed_supertrait.output.ron Outdated Show resolved Hide resolved
test_outputs/trait_removed_supertrait.output.ron Outdated Show resolved Hide resolved
era and others added 6 commits June 16, 2023 07:55
Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>
Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>
Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>
Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>
Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>
Copy link
Owner

@obi1kenobi obi1kenobi left a comment

Choose a reason for hiding this comment

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

This is great. Last couple of minor things and this is ready to merge and release!

human_readable_name: "supertrait removed or renamed",
description: "It is a breaking change to loosen generic bounds on a type since this can break users expecting the tightened bounds.",
required_update: Major,
reference_link: None,
Copy link
Owner

Choose a reason for hiding this comment

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

Yes, the docs link for supertraits is the best option. It's not perfect, but it's certainly better than nothing.

src/lints/trait_removed_supertrait.ron Outdated Show resolved Hide resolved
era and others added 2 commits June 17, 2023 09:47
Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>
@era era marked this pull request as ready for review June 17, 2023 08:50
@era
Copy link
Contributor Author

era commented Jun 17, 2023

Thank you again for all the mentoring during the PR, I'm super grateful for all the time you invested in it and all the comments you add.

Super thank you!

@obi1kenobi obi1kenobi merged commit cd1d4be into obi1kenobi:main Jun 17, 2023
@obi1kenobi
Copy link
Owner

No worries, I'm happy I could help. Thank you for all the hard work you've been putting in to make cargo-semver-checks better!

Now that you've seen a few different sides of cargo-semver-checks, do you have a preference between writing new lints versus improving the user-facing side of the tool?

How can I best support you and make sure you're set up for success?

@era
Copy link
Contributor Author

era commented Jun 19, 2023

No preferences :), I liked the process of both. I will review the list you gave me and pick something interesting from there.

And at the moment I don't need anything specific, I think now I have a better macro picture of the whole components. Thank you again for all the reviews!

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.

New lint: trait removed supertrait
2 participants