-
-
Notifications
You must be signed in to change notification settings - Fork 93
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 a witness hint for struct_missing lint #1206
base: main
Are you sure you want to change the base?
Conversation
Yes, the witness also needs to work for structs that have fields 👍
Unfortunately, not all structs can be constructed with a literal. This includes structs that have private fields and This is the crux of why writing witnesses is hard! We need to come up with a way to demonstrate breakage that works for:
Solving problems like this requires thinking hard about all the possible ways one can use the given element of Rust — in this case, a struct.
Unfortunately, I don't think field types are in our schema yet. We need to design what that schema would look like and then implement it. That particular case isn't beginner-friendly, but if you'd like to work up to it over the span of a few weeks, I'd be happy to suggest an easier schema evolution task that's more suitable for starting out. No pressure, purely if that's something you're interested in! |
I think fn downstream(value: path::to::Struct) {
let path::to::Struct {..} = value;
} works in all of the cases that you mentioned (modulo generic parameters in the function signature for simplicity), but it's not the most user-friendly/understandable for tuple structs/unit structs, so this would be more helpful as a full witness than a witness hint, I think. I agree that this one is maybe not the best first witness hint to add. |
Maybe we just avoid overcomplicating it for the witness hint and just do In principle someone may have added an module by that name (enum/union/trait are impossible because of the
If we're losing understandability in the hint then it feels like we're not serving our users' best interests. Obviously the full (non-hint) witness needs to work perfectly in all cases, but there we can also afford to e.g. pull public fields / check for other types by the same name / check if the struct is a unit, tuple, or plain etc. and then if need be generate a customized witness for each case. |
There is another lint namely
I feel that working on this would be worth the time :)
If the following can provide a taste of how the above problem (adding field type to schema) could be approached, I would be happy to look into both parallelly. No problems there. |
I'm a bit confused, are the types required there? I think the closure could infer its arguments in most cases (unless they are generic), and the struct literal instantiation doesn't seem like it would require types.
Sounds good! As a starting point, let's have you try to add information on First, I'd recommend familiarizing yourself with the In parallel, I'd recommend writing a lint or two, so you get familiarized with the query syntax and its use cases. Follow our contributing guide to get started, and pick out an The schema that queries follow describes all the types of data we have access to. While reading about |
Did this just in an attempt to make witness more informative. Well, if it's addition doesn't affect much, does the rest of witness look fine for
Will update you on this 👍 |
I'm confused by the current witness code, and by the question 👆 Asking because you mention |
I am asking about |
What are |
Yes |
Yeah, looks great! |
(PR for Idea Verification) Though given the current test_crates for struct_missing this should work. Yet I feel that it should also cover the cases when the struct contains fields? And if it does it should have witness output that would be something like
let witness = |a: <type>, b: <type>| struct_missing::WillBeRemovedStruct{foo: a, bar: b};
for a structpub struct WillBeRemovedStruct{foo: <type>, bar:<type>}
that is being completely removed. Shouldn't it?Also, extracting field names seems/is straightforward but field types is something I can't figure out how to extract. Any help?