-
-
Notifications
You must be signed in to change notification settings - Fork 78
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
feat: New lint trait_no_longer_object_safe #659
Conversation
devanbenz
commented
Feb 12, 2024
- Adds a new lint for traits to see if they are still object safe
@obi1kenobi Having a few issues with this PR. I'm noticing that the test is failing with the following error:
It looks like its picking up a query from a different lint. When I go through and try to debug what exactly is happening I see that https://github.com/devanbenz/cargo-semver-checks/blob/ea9a307765ea5d80b12bf8ada784019ad3f23cab/src/query.rs#L140 is outputting trait_no_longer_object_safe in the test crates returned array which looks okay. Looking here https://github.com/devanbenz/cargo-semver-checks/blob/ea9a307765ea5d80b12bf8ada784019ad3f23cab/src/query.rs#L325 getting the output of crate_pair_path I'm seeing
Which is the incorrect crate path 🤔 |
// Non-object safe traits | ||
pub trait RefTrait { | ||
fn by_ref(self) -> Self; | ||
} |
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.
Would you mind configuring your editor to always end files with a newline, then fixing up all the new files?
IIRC you use one of the IntelliJ editors, so something like Settings → Editor → General → Ensure line feed at file end on Save
should do the trick.
human_readable_name: "trait no longer object safe", | ||
description: "A trait is no longer object safe", | ||
required_update: Major, | ||
reference_link: Some("https://doc.rust-lang.org/stable/reference/items/traits.html?highlight=object#object-safety"), |
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.
Let's avoid the ?highlight=object
bit, we can just reference the heading and let the user read without extraneous visual highlights.
reference_link: Some("https://doc.rust-lang.org/stable/reference/items/traits.html?highlight=object#object-safety"), | |
reference_link: Some("https://doc.rust-lang.org/stable/reference/items/traits.html#object-safety"), |
SemverQuery( | ||
id: "trait_no_longer_object_safe", | ||
human_readable_name: "trait no longer object safe", | ||
description: "A trait is no longer object safe", |
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.
"Object safe" is likely to be an unfamiliar concept to many Rustaceans, so this would be a great spot to explain it a bit more.
description: "A trait is no longer object safe", | |
description: "A trait is no longer object safe, meaning it can no longer be used as `dyn Trait`", |
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.
yep! I plan on going through and cleaning up the messages :)
This is the key line in that test output:
This means that comparing a crate to itself (i.e. no changes whatsoever) triggered a lint. This is always a false-positive, since there was no source code change at all. There's a minor logic error bug in your query. Make sure the object-safety property is different between the baseline and current :) Two ideas for follow-up PRs, if you're open to them:
|
Amazing - was able to resolve. Going to take note of those pr ideas you indicated :D |
Assuming that this is failing due to nightly v stable 🤔 |
Let's do this:
I think this is the least complex solution that gets us most of the benefits without big drawbacks. |
975dfdf
to
32ce33f
Compare
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.
Will merge after applying a couple of minor nit fixes + after you've had a chance to open the draft PR with the test crate and test outputs.
@obi1kenobi #661 opened a draft PR with the tests |