-
-
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: add trait_added_supertrait
#892
feat: add trait_added_supertrait
#892
Conversation
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.
This looks good, and don't worry about the matches in other crates. That's very common — we even actively encourage it in cases where it helps us ensure that precisely one lint fires per discovered problem.
For example, if a pub struct gets deleted, we don't also want to complain that each of its public fields and methods got deleted too. The test for "what triggers the struct fields deleted" lint then contains instances where the entire struct is deleted, and we use the tests to ensure we don't match it.
Assuming you feel the reference link I suggested is good, or you can find a better one, this is good to merge!
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.
Sorry, I just realized something else as well. In #5 we listed a real world instance of this breakage where a trait gained Debug
as a supertrait (the built-in one): https://github.com/smithy-lang/smithy-rs/pull/2577/files#diff-82252c5a4ad7e9d34be9254db1afe172d0f01c067b121de20ff7f7f29d7cf223L24
Would you mind adding a couple of test cases that add supertraits like Debug
, Sync
, and PartialEq
to make sure those get detected correctly too?
Added tests with |
Another test case to add, maybe: given: pub mod one {
/// Trait #1
pub trait MyTrait {}
}
pub mod two {
/// trait #2
pub trait MyTrait {}
} old: use one::MyTrait;
pub trait Subtrait: MyTrait {} new: use two::MyTrait;
pub trait Subtrait: MyTrait {} where |
To me, it looks like a bug in the trustfall rustdoc adapter: it doesn't seem to show supertraits from other crates. Querying the |
Yes, in general we can't see traits from other crates. Recall that rustdoc JSON only contains data for the crate being analyzed, so other crates' items (including traits) are not present in the JSON. This unfortunately includes Rust's built-in crates To work around this limitation until we have the ability to connect multiple rustdoc JSONs, we have a hardcoded list of traits from Rust's builtins that we pretend are part of the JSON and should be able to lint. The code to pretend those traits exist when they are implemented by a type is here. Unfortunately, it appears that the implementation of traits' Thanks for catching it! It should be an easy fix, if you'd like to try your hand at writing some Trustfall adapter code @mrnossiom! We'd want to update this test and its corresponding test crate to contain some |
@mrnossiom no pressure, just checking in to see if you're interested in putting together the fix for |
Hi Predrag, I'm afraid I don't currently have the time to make the fix myself. But I'll be happy to finish the work of this PR's scope once the fix is merged. |
No worries at all, I can take care of it and unblock this PR. |
The fix is in and I've updated the adapter library versions here, so if you pull the issue should go away. While working on the fix, I thought of another interesting edge case we want to ensure isn't going to cause a false-positive: pub trait Example: std::fmt::Debug {}
// becomes
pub trait Example: core::fmt::Debug {} This shouldn't get flagged since the name change is essentially only cosmetic — we don't currently track |
Just checking in to see if you're still able to and interested in working on this PR. It's no trouble at all if you had other stuff come up, and you can always contribute more on other things if/when you have the time and energy for it. Heads-up that I'll be travelling quite a bit in October as well as for a part of the rest of September, so it would be a bit easier for me to review changes and support you before the end of the month as opposed to later on. |
470e000
to
46df559
Compare
The current lint doesn't flag the edge case you mentioned, but I feel like it should. If you have any idea why tell me else I'll look further into it this weekend. |
Co-authored-by: Max Carr <[email protected]>
This message was referencing this edge case, right? pub trait Example: std::fmt::Debug {}
// becomes
pub trait Example: core::fmt::Debug {} If so, the correct behavior is to not flag this — we want the test case as a guard against false-positives here. The reason is that So I believe everything is in order with this lint and I think it's safe to merge. Do you agree? Happy to merge it if so, just wanted to confirm with you in case I've missed something 👍 |
It's just that there is no special handling for I don't know if that's acceptable, else I have no other concern for this PR. |
You're right, there's definitely an issue there, though not with However, because of #638, bounds like There's another (quite remote) false-positive issue here, around blanket impls: adding a supertrait bound can be "non-binding" (essentially, irrelevant and non-breaking) if there's already a blanket impl for that supertrait over all types that could impl the trait. This is #923. We will resolve all three of these eventually, and the name-matching (#922) is a much bigger concern than blanket impls (#923). But given that #638 prevents the vast majority of the cases where the name-matching would be a problem, I think we'll help vastly more people by shipping this lint as-is and improving it later. Thanks for bringing this up — I appreciate it! You have an excellent eye for detail, and I really enjoy working with you as a result 🚀 |
Lint for "non-sealed trait added new supertraits"
See #870
Closes #441
I blessed the tests, but it makes duplicate reports for
trait_newly_sealed
(as sealing a trait requires adding a supertrait) which may be annoying.