Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upDesugared x.index(y) is not equivalent to x[y] #30127
Comments
huonw
added
I-nominated
T-lang
labels
Nov 30, 2015
This comment has been minimized.
This comment has been minimized.
|
This might be a bug caused by missing checks for overloaded operators, depends when the destructors run. |
This comment has been minimized.
This comment has been minimized.
|
triage: P-medium |
rust-highfive
added
P-medium
and removed
I-nominated
labels
Jan 7, 2016
This comment has been minimized.
This comment has been minimized.
|
triage: P-high The high priority is just to investigate and make sure we understand what is going on. |
rust-highfive
added
P-high
and removed
P-medium
labels
Jan 7, 2016
nikomatsakis
self-assigned this
Jan 7, 2016
pnkfelix
self-assigned this
Jun 23, 2016
brson
unassigned
nikomatsakis
Jun 23, 2016
This comment has been minimized.
This comment has been minimized.
|
@pnkfelix Offers to take this one. |
brson
added
the
A-lifetimes
label
Jun 23, 2016
This comment has been minimized.
This comment has been minimized.
|
This is (indeed) by design. (Ideally we would figure out a way to tweak the Rvalue lifetime rules so that the two forms are equivalent, but I do not know if that is feasible.) The reason this is occurring: when determining the lifetime for an rvalue, there are a couple different tricks for extending the lifetimes of temporary rvalues to last as long as the scope of some variable binding, rather than the statement the rvalues happen to appear within. (These still need to be documented somewhere outside of the code, see also #12032.) The particular detail here is we descend expressions according to a grammar to determine which rvalues should have their lifetimes extended, and right now, that grammar looks like this:
Note that the above does not have method call That's the heart of why this is happening: the temporary lifetime rules are based on the syntax that has not had the index expressions desugared to method calls, so you end up with more convenient rules in terms of how long the receiver lives in those cases. I think it might be interesting to try to extend the rules here so that the grammar looks like this:
Update: we probably would also want the lifetime Its also possible that the extension under consideration belongs in the |
This comment has been minimized.
This comment has been minimized.
|
(removing P-high on basis of prior investigation.) |
pnkfelix
removed
the
P-high
label
Jul 12, 2016
This comment has been minimized.
This comment has been minimized.
|
triage: P-medium |
rust-highfive
added
the
P-medium
label
Jul 12, 2016
pnkfelix
added a commit
to pnkfelix/rust
that referenced
this issue
Jul 12, 2016
This comment has been minimized.
This comment has been minimized.
|
Hmm, my idea from above won't work because we do not have a |
This comment has been minimized.
This comment has been minimized.
|
@pnkfelix Could we compute the extents later, before regionck, but after type inference? |
This comment has been minimized.
This comment has been minimized.
|
@eddyb it may be possible, but it would require a pretty serious refactoring of the code, since we compute these extents in the same |
This comment has been minimized.
This comment has been minimized.
|
@eddyb (plus I'm not sure its actually what we want ... part of the overall idea has been to have a relatively simple syntactic rule for deriving the temporary r-value lifetimes. The idea I wrote above is ... somewhat in conflict with that goal.) |
This comment has been minimized.
This comment has been minimized.
|
@pnkfelix @eddyb I think that the extension would be subsumed by the proposal in rust-lang/rfcs#66 -- however, the need to refactor (and compute the temporary lifetimes during typeck) is the main reason that this RFC has not been implemented. |
This comment has been minimized.
This comment has been minimized.
|
@pnkfelix Argh. I just revisited this for some reason. Those temporary rules were designed before deref and |
This comment has been minimized.
This comment has been minimized.
|
I am going to unassign @pnkfelix since I don't think they're actively investigating. |
Mark-Simulacrum
unassigned
pnkfelix
May 15, 2017
Mark-Simulacrum
added
C-bug
I-needs-decision
labels
Jul 24, 2017
memoryruins
referenced this issue
Jan 29, 2019
Open
issue triage: closures, lifetimes, and nll #57964
This comment has been minimized.
This comment has been minimized.
|
Triage: this compiles and does not error on 2018, but if we try to print
2015 errors without trying to print:
|
huonw commentedNov 30, 2015
If the
let _desugars are commented out, it compiles fine.It seems a method call is treated differently to the
[]syntax. This may be a purposeful consequence of the design of temporary lifetimes, I don't know.