Merge branch 'xvar/add-clone-on-ref-ptr-clippy-lint' into 'master'

Added #![deny(clippy::clone_on_ref_ptr)] to all crates and fixed resulting lint errors

See merge request veloren/veloren!1411
This commit is contained in:
Forest Anderson 2020-09-28 19:32:03 +00:00
commit 25ab132d73
22 changed files with 51 additions and 37 deletions

View File

@ -1,5 +1,6 @@
#![deny(unsafe_code)]
#![allow(clippy::option_map_unit_fn)]
#![deny(clippy::clone_on_ref_ptr)]
use client::{Client, Event};
use common::{clock::Clock, comp};

View File

@ -1,4 +1,5 @@
#![deny(unsafe_code)]
#![deny(clippy::clone_on_ref_ptr)]
#![feature(label_break_value, option_zip)]
pub mod cmd;

View File

@ -1,7 +1,8 @@
#![deny(unsafe_code)]
#![allow(clippy::option_map_unit_fn)]
#![allow(incomplete_features)]
#![type_length_limit = "1664759"]
#![allow(clippy::option_map_unit_fn)]
#![deny(clippy::clone_on_ref_ptr)]
#![feature(
arbitrary_enum_discriminant,
associated_type_defaults,

View File

@ -371,7 +371,8 @@ impl State {
// Run systems to update the world.
// Create and run a dispatcher for ecs systems.
let mut dispatch_builder = DispatcherBuilder::new().with_pool(self.thread_pool.clone());
let mut dispatch_builder =
DispatcherBuilder::new().with_pool(Arc::clone(&self.thread_pool));
sys::add_local_systems(&mut dispatch_builder);
// TODO: Consider alternative ways to do this
add_foreign_systems(&mut dispatch_builder);

View File

@ -189,7 +189,7 @@ impl<'a, V: RectRasterableVol + ReadVol> CachedVolGrid2d<'a, V> {
.get(&ck)
.ok_or(VolGrid2dError::NoSuchChunk)?;
// Store most recently looked up chunk in the cache
self.cache = Some((ck, chunk.clone()));
self.cache = Some((ck, Arc::clone(&chunk)));
chunk
};
let co = VolGrid2d::<V>::chunk_offs(pos);

View File

@ -375,7 +375,7 @@ impl Network {
self.participant_disconnect_sender
.lock()
.await
.insert(pid, participant.a2s_disconnect_s.clone());
.insert(pid, Arc::clone(&participant.a2s_disconnect_s));
Ok(participant)
}
@ -414,10 +414,10 @@ impl Network {
/// [`listen`]: crate::api::Network::listen
pub async fn connected(&self) -> Result<Participant, NetworkError> {
let participant = self.connected_receiver.lock().await.next().await?;
self.participant_disconnect_sender
.lock()
.await
.insert(participant.remote_pid, participant.a2s_disconnect_s.clone());
self.participant_disconnect_sender.lock().await.insert(
participant.remote_pid,
Arc::clone(&participant.a2s_disconnect_s),
);
Ok(participant)
}
}

View File

@ -1,6 +1,7 @@
#![deny(unsafe_code)]
#![cfg_attr(test, deny(rust_2018_idioms))]
#![cfg_attr(test, deny(warnings))]
#![deny(clippy::clone_on_ref_ptr)]
#![feature(try_trait)]
//! Crate to handle high level networking of messages with different

View File

@ -147,7 +147,7 @@ impl BParticipant {
let (w2b_frames_s, w2b_frames_r) = mpsc::unbounded::<C2pFrame>();
let (prios, a2p_msg_s, b2p_notify_empty_stream_s) = PrioManager::new(
#[cfg(feature = "metrics")]
self.metrics.clone(),
Arc::clone(&self.metrics),
self.remote_pid_string.clone(),
);
@ -486,7 +486,7 @@ impl BParticipant {
// This channel is now configured, and we are running it in scope of the
// participant.
let w2b_frames_s = w2b_frames_s.clone();
let channels = self.channels.clone();
let channels = Arc::clone(&self.channels);
async move {
let (channel, b2w_frame_s, b2r_read_shutdown) = Channel::new(cid);
let mut lock = channels.write().await;
@ -772,7 +772,7 @@ impl BParticipant {
self.streams.write().await.insert(sid, StreamInfo {
prio,
promises,
send_closed: send_closed.clone(),
send_closed: Arc::clone(&send_closed),
b2a_msg_recv_s: Mutex::new(b2a_msg_recv_s),
});
#[cfg(feature = "metrics")]

View File

@ -216,7 +216,7 @@ impl Scheduler {
Protocols::Tcp(TcpProtocol::new(
stream,
#[cfg(feature = "metrics")]
self.metrics.clone(),
Arc::clone(&self.metrics),
)),
false,
)
@ -241,14 +241,14 @@ impl Scheduler {
info!("Connecting Udp to: {}", addr);
let (udp_data_sender, udp_data_receiver) = mpsc::unbounded::<Vec<u8>>();
let protocol = UdpProtocol::new(
socket.clone(),
Arc::clone(&socket),
addr,
#[cfg(feature = "metrics")]
self.metrics.clone(),
Arc::clone(&self.metrics),
udp_data_receiver,
);
self.pool.spawn_ok(
Self::udp_single_channel_connect(socket.clone(), udp_data_sender)
Self::udp_single_channel_connect(Arc::clone(&socket), udp_data_sender)
.instrument(tracing::info_span!("udp", ?addr)),
);
(Protocols::Udp(protocol), true)
@ -396,7 +396,7 @@ impl Scheduler {
let protocol = TcpProtocol::new(
stream,
#[cfg(feature = "metrics")]
self.metrics.clone(),
Arc::clone(&self.metrics),
);
self.init_protocol(Protocols::Tcp(protocol), None, true)
.await;
@ -439,10 +439,10 @@ impl Scheduler {
let (udp_data_sender, udp_data_receiver) = mpsc::unbounded::<Vec<u8>>();
listeners.insert(remote_addr, udp_data_sender);
let protocol = UdpProtocol::new(
socket.clone(),
Arc::clone(&socket),
remote_addr,
#[cfg(feature = "metrics")]
self.metrics.clone(),
Arc::clone(&self.metrics),
udp_data_receiver,
);
self.init_protocol(Protocols::Udp(protocol), None, false)
@ -499,10 +499,10 @@ impl Scheduler {
// the whole server easily for new clients UDP doesnt work at all, as
// the UDP listening is done in another place.
let cid = self.channel_ids.fetch_add(1, Ordering::Relaxed);
let participants = self.participants.clone();
let participants = Arc::clone(&self.participants);
#[cfg(feature = "metrics")]
let metrics = self.metrics.clone();
let pool = self.pool.clone();
let metrics = Arc::clone(&self.metrics);
let pool = Arc::clone(&self.pool);
let local_pid = self.local_pid;
let local_secret = self.local_secret;
// this is necessary for UDP to work at all and to remove code duplication
@ -514,7 +514,7 @@ impl Scheduler {
local_pid,
local_secret,
#[cfg(feature = "metrics")]
metrics.clone(),
Arc::clone(&metrics),
send_handshake,
);
match handshake
@ -541,7 +541,7 @@ impl Scheduler {
pid,
sid,
#[cfg(feature = "metrics")]
metrics.clone(),
Arc::clone(&metrics),
);
let participant = Participant::new(

View File

@ -1,4 +1,5 @@
#![deny(unsafe_code)]
#![deny(clippy::clone_on_ref_ptr)]
mod tui_runner;
mod tuilog;

View File

@ -111,7 +111,7 @@ impl Tui {
}));
let mut msg_s = self.msg_s.take().unwrap();
let running = self.running.clone();
let running = Arc::clone(&self.running);
if basic {
std::thread::spawn(move || {

View File

@ -85,7 +85,7 @@ impl ChunkGenerator {
}
pub fn cancel_all(&mut self) {
let metrics = self.metrics.clone();
let metrics = Arc::clone(&self.metrics);
self.pending_chunks.drain().for_each(|(_, cancel)| {
cancel.store(true, Ordering::Relaxed);
metrics.chunks_canceled.inc();

View File

@ -1,5 +1,6 @@
#![deny(unsafe_code)]
#![allow(clippy::option_map_unit_fn)]
#![deny(clippy::clone_on_ref_ptr)]
#![feature(bool_to_option, drain_filter, option_zip)]
#![cfg_attr(not(feature = "worldgen"), feature(const_panic))]
@ -548,7 +549,7 @@ impl Server {
None,
pos,
thread_pool,
world.clone(),
Arc::clone(&world),
index.clone(),
);
});
@ -853,7 +854,7 @@ impl Server {
Some(entity),
key,
&mut self.thread_pool,
self.world.clone(),
Arc::clone(&self.world),
self.index.clone(),
);
}

View File

@ -337,7 +337,7 @@ impl ServerMetrics {
pub fn run(&mut self, addr: SocketAddr) -> Result<(), Box<dyn Error>> {
self.running.store(true, Ordering::Relaxed);
let running2 = self.running.clone();
let running2 = Arc::clone(&self.running);
let registry = self
.registry
@ -381,7 +381,7 @@ impl ServerMetrics {
pub fn tick(&self) -> u64 { self.tick.fetch_add(1, Ordering::Relaxed) + 1 }
pub fn tick_clone(&self) -> Arc<AtomicU64> { self.tick.clone() }
pub fn tick_clone(&self) -> Arc<AtomicU64> { Arc::clone(&self.tick) }
}
impl Drop for ServerMetrics {

View File

@ -1,3 +1,5 @@
#![deny(clippy::clone_on_ref_ptr)]
use std::error::Error;
use structopt::StructOpt;

View File

@ -22,7 +22,7 @@ impl Sound {
Ok(Sound(Arc::new(buf)))
}
pub fn cursor(&self) -> io::Cursor<Sound> { io::Cursor::new(Sound(self.0.clone())) }
pub fn cursor(&self) -> io::Cursor<Sound> { io::Cursor::new(Sound(Arc::clone(&self.0))) }
pub fn decoder(&self) -> rodio::Decoder<io::Cursor<Sound>> {
rodio::Decoder::new(self.cursor()).unwrap()

View File

@ -65,9 +65,11 @@ use conrod_core::{
use specs::{Join, WorldExt};
use std::{
collections::{HashMap, VecDeque},
sync::Arc,
time::Instant,
};
use vek::*;
const XP_COLOR: Color = Color::Rgba(0.59, 0.41, 0.67, 1.0);
const TEXT_COLOR: Color = Color::Rgba(1.0, 1.0, 1.0, 1.0);
const TEXT_GRAY_COLOR: Color = Color::Rgba(0.5, 0.5, 0.5, 1.0);
@ -591,7 +593,7 @@ impl Hud {
// Load world map
let world_map = (
ui.add_graphic_with_rotations(Graphic::Image(
client.world_map.0.clone(),
Arc::clone(&client.world_map.0),
Some(water_color),
)),
client.world_map.1.map(u32::from),

View File

@ -1,5 +1,7 @@
#![deny(unsafe_code)]
#![allow(clippy::option_map_unit_fn, incomplete_features)]
#![allow(incomplete_features)]
#![allow(clippy::option_map_unit_fn)]
#![deny(clippy::clone_on_ref_ptr)]
#![feature(array_map, bool_to_option, const_generics, drain_filter, or_patterns)]
#![recursion_limit = "2048"]

View File

@ -111,7 +111,7 @@ impl PlayState for CharSelectionState {
return PlayStateResult::Switch(Box::new(SessionState::new(
global_state,
self.client.clone(),
Rc::clone(&self.client),
)));
},
}

View File

@ -28,7 +28,7 @@ use common::{
vol::ReadVol,
};
use specs::{Join, WorldExt};
use std::{cell::RefCell, rc::Rc, time::Duration};
use std::{cell::RefCell, rc::Rc, sync::Arc, time::Duration};
use tracing::{error, info};
use vek::*;
@ -981,7 +981,7 @@ impl PlayState for SessionState {
)
.unwrap();
self.voxygen_i18n.log_missing_entries();
self.hud.update_language(self.voxygen_i18n.clone());
self.hud.update_language(Arc::clone(&self.voxygen_i18n));
},
HudEvent::ChangeFullscreenMode(new_fullscreen_settings) => {
global_state
@ -1086,7 +1086,7 @@ impl PlayState for SessionState {
} else if let ClientState::Registered = client_state {
PlayStateResult::Switch(Box::new(CharSelectionState::new(
global_state,
self.client.clone(),
Rc::clone(&self.client),
)))
} else {
error!("Client not in the expected state, exiting session play state");

View File

@ -46,7 +46,7 @@ impl Singleplayer {
let settings2 = settings.clone();
let paused = Arc::new(AtomicBool::new(false));
let paused1 = paused.clone();
let paused1 = Arc::clone(&paused);
let (result_sender, result_receiver) = bounded(1);

View File

@ -1,6 +1,7 @@
#![deny(unsafe_code)]
#![allow(incomplete_features)]
#![allow(clippy::option_map_unit_fn)]
#![deny(clippy::clone_on_ref_ptr)]
#![feature(
arbitrary_enum_discriminant,
bool_to_option,