Skip to content

Commit 7f7aabd

Browse files
committed
Apply NLL simplifications as it's now stable on the 2015 edition
Starting with today's rustc nightly 6d599337f 2019-04-22, NLL, or more precisely two phase borrows are enabled on the 2015 edition used by us [1]. Due to this, we can apply simplifications to the codebase that needed two phase borrows to come to fruition. [1]: rust-lang/rust#59114
1 parent e7c7f39 commit 7f7aabd

File tree

3 files changed

+25
-33
lines changed

3 files changed

+25
-33
lines changed

mehlon-server/lib.rs

+17-21
Original file line numberDiff line numberDiff line change
@@ -400,27 +400,23 @@ impl<S :NetworkServerSocket> Server<S> {
400400
}
401401
fn handle_players_waiting_for_kv(&mut self) {
402402
let mut players_to_add = Vec::new();
403-
// TODO with NLL, these {} become unneccessary
404-
// See: https://github.com/rust-lang/rust/issues/57804
405-
{
406-
let pwfk = &mut self.players_waiting_for_kv;
407-
self.map.run_for_kv_results(&mut |id, _payload, key, value| {
408-
if key != "position" {
409-
return;
410-
}
411-
if let Some((conn, nick)) = pwfk.remove(&id) {
412-
let pos = if let Some(buf) = value {
413-
PlayerPosition::deserialize(&buf)
414-
.ok()
415-
.unwrap_or_else(PlayerPosition::default)
416-
} else {
417-
// No value could be found
418-
PlayerPosition::default()
419-
};
420-
players_to_add.push((conn, id, nick, pos));
421-
}
422-
});
423-
}
403+
let pwfk = &mut self.players_waiting_for_kv;
404+
self.map.run_for_kv_results(&mut |id, _payload, key, value| {
405+
if key != "position" {
406+
return;
407+
}
408+
if let Some((conn, nick)) = pwfk.remove(&id) {
409+
let pos = if let Some(buf) = value {
410+
PlayerPosition::deserialize(&buf)
411+
.ok()
412+
.unwrap_or_else(PlayerPosition::default)
413+
} else {
414+
// No value could be found
415+
PlayerPosition::default()
416+
};
417+
players_to_add.push((conn, id, nick, pos));
418+
}
419+
});
424420
for (conn, id, nick, pos) in players_to_add {
425421
self.add_player(conn, id, nick, pos);
426422
}

mehlon-server/map_storage.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,13 @@ pub type DynStorageBackend = Box<dyn StorageBackend + Send>;
436436

437437
fn sqlite_backend_from_config(config :&mut Config, auth_needed :bool)
438438
-> Option<(DynStorageBackend, Option<SqliteLocalAuth>)> {
439-
// TODO: once we have NLL, remove the "cloned" below
440-
// See: https://github.com/rust-lang/rust/issues/57804
441-
let p = config.map_storage_path.as_ref().cloned()?;
439+
let p = config.map_storage_path.as_ref()?;
440+
441+
let p_config = Path::new(&p);
442+
let p_auth = p_config.with_file_name(p_config.file_stem()
443+
.and_then(|v| v.to_str()).unwrap_or("").to_owned()
444+
+ "-auth.sqlite");
445+
442446
let sqlite_backend = match SqliteStorageBackend::open_or_create(&p) {
443447
Ok(mut b) => {
444448
manage_mapgen_meta_toml(&mut b, config).unwrap();
@@ -450,10 +454,6 @@ fn sqlite_backend_from_config(config :&mut Config, auth_needed :bool)
450454
},
451455
};
452456
let storage_backend = Box::new(sqlite_backend);
453-
let p_config = Path::new(&p);
454-
let p_auth = p_config.with_file_name(p_config.file_stem()
455-
.and_then(|v| v.to_str()).unwrap_or("").to_owned()
456-
+ "-auth.sqlite");
457457
let local_auth = if auth_needed {
458458
Some(SqliteLocalAuth::open_or_create(p_auth).unwrap())
459459
} else {

mehlon-server/mapgen.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -383,11 +383,7 @@ impl MapgenMap {
383383
sth_to_generate = true;
384384
}
385385
}
386-
// TODO: once we have NLL, remove the continue, and
387-
// remove the /* */ around the else below.
388-
// See: https://github.com/rust-lang/rust/issues/57804
389-
continue;
390-
} /* else */ {
386+
} else {
391387
if let Some(data) = self.storage.load_chunk(pos).unwrap() {
392388
let chn = MapChunk {
393389
data,

0 commit comments

Comments
 (0)