From 7f7aabd1fb01307ecd20ba4d4240181c3a078de4 Mon Sep 17 00:00:00 2001 From: est31 Date: Tue, 23 Apr 2019 17:08:13 +0200 Subject: [PATCH] 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]: https://github.com/rust-lang/rust/pull/59114 --- mehlon-server/lib.rs | 38 ++++++++++++++++-------------------- mehlon-server/map_storage.rs | 14 ++++++------- mehlon-server/mapgen.rs | 6 +----- 3 files changed, 25 insertions(+), 33 deletions(-) diff --git a/mehlon-server/lib.rs b/mehlon-server/lib.rs index 93f7c32..240ea3f 100644 --- a/mehlon-server/lib.rs +++ b/mehlon-server/lib.rs @@ -400,27 +400,23 @@ impl Server { } fn handle_players_waiting_for_kv(&mut self) { let mut players_to_add = Vec::new(); - // TODO with NLL, these {} become unneccessary - // See: https://github.com/rust-lang/rust/issues/57804 - { - let pwfk = &mut self.players_waiting_for_kv; - self.map.run_for_kv_results(&mut |id, _payload, key, value| { - if key != "position" { - return; - } - if let Some((conn, nick)) = pwfk.remove(&id) { - let pos = if let Some(buf) = value { - PlayerPosition::deserialize(&buf) - .ok() - .unwrap_or_else(PlayerPosition::default) - } else { - // No value could be found - PlayerPosition::default() - }; - players_to_add.push((conn, id, nick, pos)); - } - }); - } + let pwfk = &mut self.players_waiting_for_kv; + self.map.run_for_kv_results(&mut |id, _payload, key, value| { + if key != "position" { + return; + } + if let Some((conn, nick)) = pwfk.remove(&id) { + let pos = if let Some(buf) = value { + PlayerPosition::deserialize(&buf) + .ok() + .unwrap_or_else(PlayerPosition::default) + } else { + // No value could be found + PlayerPosition::default() + }; + players_to_add.push((conn, id, nick, pos)); + } + }); for (conn, id, nick, pos) in players_to_add { self.add_player(conn, id, nick, pos); } diff --git a/mehlon-server/map_storage.rs b/mehlon-server/map_storage.rs index 81640f4..918856c 100644 --- a/mehlon-server/map_storage.rs +++ b/mehlon-server/map_storage.rs @@ -436,9 +436,13 @@ pub type DynStorageBackend = Box; fn sqlite_backend_from_config(config :&mut Config, auth_needed :bool) -> Option<(DynStorageBackend, Option)> { - // TODO: once we have NLL, remove the "cloned" below - // See: https://github.com/rust-lang/rust/issues/57804 - let p = config.map_storage_path.as_ref().cloned()?; + let p = config.map_storage_path.as_ref()?; + + let p_config = Path::new(&p); + let p_auth = p_config.with_file_name(p_config.file_stem() + .and_then(|v| v.to_str()).unwrap_or("").to_owned() + + "-auth.sqlite"); + let sqlite_backend = match SqliteStorageBackend::open_or_create(&p) { Ok(mut b) => { manage_mapgen_meta_toml(&mut b, config).unwrap(); @@ -450,10 +454,6 @@ fn sqlite_backend_from_config(config :&mut Config, auth_needed :bool) }, }; let storage_backend = Box::new(sqlite_backend); - let p_config = Path::new(&p); - let p_auth = p_config.with_file_name(p_config.file_stem() - .and_then(|v| v.to_str()).unwrap_or("").to_owned() - + "-auth.sqlite"); let local_auth = if auth_needed { Some(SqliteLocalAuth::open_or_create(p_auth).unwrap()) } else { diff --git a/mehlon-server/mapgen.rs b/mehlon-server/mapgen.rs index 331daaa..f100883 100644 --- a/mehlon-server/mapgen.rs +++ b/mehlon-server/mapgen.rs @@ -383,11 +383,7 @@ impl MapgenMap { sth_to_generate = true; } } - // TODO: once we have NLL, remove the continue, and - // remove the /* */ around the else below. - // See: https://github.com/rust-lang/rust/issues/57804 - continue; - } /* else */ { + } else { if let Some(data) = self.storage.load_chunk(pos).unwrap() { let chn = MapChunk { data,