-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
refactor lvalue_ty to be method of lvalue #35403
Conversation
r? @arielb1 (rust_highfive has picked a reviewer for you, use r? to override) |
Do you think it makes sense to refactor similarly the other |
Also, I think I would prefer to keep the |
@bors r+ why not. |
📌 Commit f37bf6d has been approved by |
refactor lvalue_ty to be method of lvalue Currently `Mir` (and `MirContext`) implement a method `lvalue_ty` (and actually many more `foo_ty`). But this should be a method of `Lvalue`. If you have an `lvalue` and you want to get its type, the natural thing to write is: ``` lvalue.ty() ``` Of course it needs context, but still: ``` lvalue.ty(mir, tcx) ``` Makes more sense than ``` mir.lvalue_ty(lvalue, tcx) ``` I actually think we should go a step farther and have traits so we could get the type of some value generically, but that's up for debate. The thing I'm running into a lot in the compiler is I have a value of type `Foo` and I know that there is some related type `Bar` which I can get through some combination of method calls, but it's often not as direct as I would imagine. Unless you already know the code, its not clear why you would look in `Mir` for a method to get the type of an `Lvalue`.
Currently
Mir
(andMirContext
) implement a methodlvalue_ty
(and actually many morefoo_ty
). But this should be a method ofLvalue
.If you have an
lvalue
and you want to get its type, the natural thing to write is:Of course it needs context, but still:
Makes more sense than
I actually think we should go a step farther and have traits so we could get the type of some value generically, but that's up for debate. The thing I'm running into a lot in the compiler is I have a value of type
Foo
and I know that there is some related typeBar
which I can get through some combination of method calls, but it's often not as direct as I would imagine. Unless you already know the code, its not clear why you would look inMir
for a method to get the type of anLvalue
.