Skip to content
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

Merged
merged 4 commits into from
Aug 11, 2016

Conversation

scottcarr
Copy link
Contributor

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.

@rust-highfive
Copy link
Collaborator

r? @arielb1

(rust_highfive has picked a reviewer for you, use r? to override)

@scottcarr
Copy link
Contributor Author

r? @nikomatsakis

@rust-highfive rust-highfive assigned nikomatsakis and unassigned arielb1 Aug 5, 2016
@nikomatsakis
Copy link
Contributor

Do you think it makes sense to refactor similarly the other mir.foo_ty methods?

@nikomatsakis
Copy link
Contributor

Also, I think I would prefer to keep the ty method in the tcx.rs file -- so as to keep repr.rs relatively uncluttered. I think I still feel that way, though I can imagine it does harm discoverability in some sense (but it's easy enough to grep for all impls on Lvalue).

@nikomatsakis
Copy link
Contributor

@bors r+

why not.

@bors
Copy link
Contributor

bors commented Aug 10, 2016

📌 Commit f37bf6d has been approved by nikomatsakis

@bors
Copy link
Contributor

bors commented Aug 11, 2016

⌛ Testing commit f37bf6d with merge 42001ed...

bors added a commit that referenced this pull request Aug 11, 2016
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`.
@bors bors merged commit f37bf6d into rust-lang:master Aug 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants