-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Introduce matches(T: Trait)
condition to rustc_on_unimplemented
#44755
Comments
Mentoring notesThis is somewhat of a moderately big feature and I'm not sure myself of the best way to implement it. The current code that implements
I think the best syntax for our feature is what I had in the description ( The I think the most annoying thing here is how to convert the trait name to the Then, we need to create our Once we have the Don't forget to add tests and to add the implementation for |
I'm starting on this. |
@cramertj cool! feel free to ask me for help. |
@arielb1 I've pushed up my WIP branch for this here. Can you take a look and let me know if the approach seems reasonable? Additionally, what's the best/easiest way to check if the |
The typeck part of your PR is basically OK. I'll like one of the resolution guys (e.g. @petrochenkov) go over your pull request and check that it doesn't use the wrong functions. To check that your type implements the trait, you should probably pass a closure to You can create the TraitRef {
def_id: your_def_id,
substs: tcx.mk_substs_trait(your_self_ty, &[])
} |
@arielb1 Great! Thank you so much for the quick feedback. |
My apologies-- I've been really busy with other things and had forgotten about this. If someone else wants to pick it up, they're welcome to it. If not, I'll try to schedule some time to finish this up soon. |
…nikomatsakis Add filtering options to `rustc_on_unimplemented` - Add filtering options to `rustc_on_unimplemented` for local traits, filtering on `Self` and type arguments. - Add a way to provide custom notes. - Tweak binops text. - Add filter to detect wether `Self` is local or belongs to another crate. - Add filter to `Iterator` diagnostic for `&str`. Partly addresses rust-lang#44755 with a different syntax, as a first approach. Fixes rust-lang#46216, fixes rust-lang#37522, CC rust-lang#34297, rust-lang#46806.
We want to allow
rustc_on_unimplemented
to check arbitrary type conditions to make the error message depend on the input types. The sanest way to do that is to allow conditioning on traits. For example, for #42526 we want something like:The syntax I prefer is
matches("TRAIT_NAME", Self="SELF_NAME", "PARAM_1_NAME", ..)
whereTRAIT_NAME
andSELF_NAME
are mandatory, but probably any syntax can work (this is all feature gated under therustc_on_unimplemented
attribute, so we can experiment).At least for now, we can limit the parameters to be type parameters from our generics - the
on_unimplemented
code already knows how to look these up. You can use these to implement anything you like with the proper trait bound.Mentoring notes here.
The text was updated successfully, but these errors were encountered: