-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Add convenience wrappers for type_dependent_defs
#59094
Comments
hey @oli-obk, happy to take this one if its still available |
Wow that was fast! Yes of course! If you have any questions, don't hesitate to ask here or on discord/zulip. |
@oli-obk Hi again :). if let Some(def) = self.tables.type_dependent_defs().get(expr.hir_id) {
let def_id = def.def_id();
// do something with `def_id`
} else {
// do something else
} It seems to me like we can introduce fourth method: Allowing us to rewrite previous example as: if let Some(def_id) = self.tables.opt_type_dependent_def_id(expr.hir_id) {
// do something with `def_id`
} else {
// do something else
} Leading to little bit cleaner code. Let me know what you think. |
Good idea! |
…ers, r=oli-obk Type dependent defs wrappers First of all, forgive me if something would seem lame to you or I offend some rule (although I tried to read through docs), this is my first PR. Issue: rust-lang#59094 This PR adds 3 helper methods to `TypeckTables`: * `opt_type_dependent_def` * `opt_type_dependent_def_id` * `type_dependent_def_id` I didn't add `type_dependent_def` as was proposed in the issue simply because it wasn't used anywhere in the code. Only non-option wrapped`type_dependent_defs()[]` accesses were found in clippy which always called `def_id()` on result. Speaking of clippy, should I open separate PR in its own repo, given it's used as submodule here? Sry it took me so long, as I said I'm new here and I had tough week :).
…ers, r=oli-obk Type dependent defs wrappers First of all, forgive me if something would seem lame to you or I offend some rule (although I tried to read through docs), this is my first PR. Issue: rust-lang#59094 This PR adds 3 helper methods to `TypeckTables`: * `opt_type_dependent_def` * `opt_type_dependent_def_id` * `type_dependent_def_id` I didn't add `type_dependent_def` as was proposed in the issue simply because it wasn't used anywhere in the code. Only non-option wrapped`type_dependent_defs()[]` accesses were found in clippy which always called `def_id()` on result. Speaking of clippy, should I open separate PR in its own repo, given it's used as submodule here? Sry it took me so long, as I said I'm new here and I had tough week :).
This can be closed now right? |
Most uses of that method mostly directly unwrap or just want to know the
DefId
. So we could use several kind of convenience wrappers:fn opt_type_dependent_def(&self, id: HirId) -> Option<Def>
fn type_dependent_def(&self, id: HirId) -> Def
fn type_dependent_def_id(&self, id: HirId) -> DefId
The text was updated successfully, but these errors were encountered: