These are chat archives for rust-lang/rust

4th
Oct 2018
David Novakovic
@dpnova
Oct 04 2018 00:46
moin - I'm getting errors about #42640 when ring is building... anyone familiar with that?
(I'm a rust noob btw)
David Novakovic
@dpnova
Oct 04 2018 03:10
needed to update rust
Kelly Thomas Kline
@kellytk
Oct 04 2018 07:22
In attempting to assign a new Instant value to a field of a struct that's a field of another struct, despite having a &mut self reference to the top struct. (rust-lang/rust#35937) I would appreciate tips for solving the problem
red75prime
@red75prime
Oct 04 2018 07:37
What is the code? a.b.c = d; should work if a is &mut A
Kelly Thomas Kline
@kellytk
Oct 04 2018 07:50
@red75prime The error occurs on line https://ghostbin.com/paste/fy58s#L24 tell me if you'd like more context
red75prime
@red75prime
Oct 04 2018 07:51
if let Some(mut s) = ...
Kelly Thomas Kline
@kellytk
Oct 04 2018 07:54
That's what I thought, and tried, however that doesn't change the error, and VS Code reports mut s as unnecessary to be mutable
red75prime
@red75prime
Oct 04 2018 07:59
Ah, yes. s is &Sesion. let session = self.sessions.get_mut(&message.id); then
Kelly Thomas Kline
@kellytk
Oct 04 2018 08:07
That helped however https://ghostbin.com/paste/v6b2f#L23 generates an error: "use of moved value used here after move note: move occurs because session has type std::option::Option<&mut session::Session> which does not implement the Copy trait"
red75prime
@red75prime
Oct 04 2018 08:14
session was destructured in if let Some(s) = session. If you want to keep it, you'll need to take s by reference let mut session = ...; if let Some(ref mut s) = session { ...
Kelly Thomas Kline
@kellytk
Oct 04 2018 08:17
I don't care about session, as it's Option<Session> I only care about the s within it. I tried the changes you suggested and the errors remain
Thiez
@Thiez
Oct 04 2018 08:30
I agree it sounds like your code should work just fine.
If it doesn't, perhaps you could create a minimal example on the playground that exhibits the error?
Kelly Thomas Kline
@kellytk
Oct 04 2018 09:50
I had made a dumb oversight and it's fixed now, thanks @red75prime and @Thiez. Do you happen to know how to fix https://play.rust-lang.org/?gist=15c20e257f87a5ffa136c65f54a1c326&version=stable&mode=debug&edition=2015
Thiez
@Thiez
Oct 04 2018 09:52
Sure: https://play.rust-lang.org/?gist=8312285d7220beed131cecd224bc1c36&version=stable&mode=debug&edition=2015 note that you won't have to do this anymore when NLL (non-lexical-lifetimes) become stable
(that is, your original code will run if you declare #![feature(nll)] and compile with nightly)
Basically session is a mutable pointer into self, through self.sessions. And because Rust requires &mut pointers to be unique, you cannot call handle2 because that function also wants to borrow self. If Rust were to allow these pointers to exist at the same time, it would allow memory unsafety.
Kelly Thomas Kline
@kellytk
Oct 04 2018 09:56
Thank you. I've been curious whether or not I'd encounter that issue :-)
Thiez
@Thiez
Oct 04 2018 09:57
It might be the case that handle2 doesn't observe self.sessions at all, in which case it would theoretically be fine, but such things are hard to reason about for the compiler so it is a bit conservative, and I think it is very unlikely that Rust will be modified to allow this
np.