Merge branch 'valkum-master-patch-25423' into 'master'

Make clippy happy (needless-return, etc.)

See merge request famedly/conduit!23
This commit is contained in:
Timo Kösters 2021-03-04 12:35:12 +00:00
commit bd6507eafb
7 changed files with 19 additions and 17 deletions

View file

@ -25,7 +25,7 @@ where
let mut parts = http_request.uri().clone().into_parts();
let old_path_and_query = parts.path_and_query.unwrap().as_str().to_owned();
let symbol = if old_path_and_query.contains("?") {
let symbol = if old_path_and_query.contains('?') {
"&"
} else {
"?"

View file

@ -95,7 +95,7 @@ pub async fn get_pushrule_route(
if let Some(rule) = rule {
Ok(get_pushrule::Response { rule }.into())
} else {
Err(Error::BadRequest(ErrorKind::NotFound, "Push rule not found.").into())
Err(Error::BadRequest(ErrorKind::NotFound, "Push rule not found."))
}
}

View file

@ -119,8 +119,7 @@ pub async fn login_route(
let device_exists = body.device_id.as_ref().map_or(false, |device_id| {
db.users
.all_device_ids(&user_id)
.find(|x| x.as_ref().map_or(false, |v| v == device_id))
.is_some()
.any(|x| x.as_ref().map_or(false, |v| v == device_id))
});
if device_exists {

View file

@ -9,9 +9,10 @@ use trust_dns_resolver::TokioAsyncResolver;
pub const COUNTER: &str = "c";
type WellKnownMap = HashMap<Box<ServerName>, (String, Option<String>)>;
#[derive(Clone)]
pub struct Globals {
pub actual_destination_cache: Arc<RwLock<HashMap<Box<ServerName>, (String, Option<String>)>>>, // actual_destination, host
pub actual_destination_cache: Arc<RwLock<WellKnownMap>>, // actual_destination, host
pub(super) globals: sled::Tree,
config: Config,
keypair: Arc<ruma::signatures::Ed25519KeyPair>,

View file

@ -183,7 +183,7 @@ impl Rooms {
)))
})
} else {
return Ok(None);
Ok(None)
}
}
@ -449,6 +449,7 @@ impl Rooms {
///
/// By this point the incoming event should be fully authenticated, no auth happens
/// in `append_pdu`.
#[allow(clippy::too_many_arguments)]
pub fn append_pdu(
&self,
pdu: &PduEvent,
@ -970,7 +971,7 @@ impl Rooms {
.get("users")
.and_then(|users| users.as_sequence())
.map_or_else(
|| Vec::new(),
Vec::new,
|users| {
users
.iter()
@ -1002,7 +1003,7 @@ impl Rooms {
.and_then(|string| {
UserId::parse_with_server_name(string, globals.server_name()).ok()
});
#[allow(clippy::blocks_in_if_conditions)]
if bridge_user_id.map_or(false, |bridge_user_id| {
self.is_joined(&bridge_user_id, room_id).unwrap_or(false)
}) || users.iter().any(|users| {

View file

@ -102,7 +102,7 @@ impl Sending {
match response {
Ok((server, is_appservice)) => {
let mut prefix = if is_appservice {
"+".as_bytes().to_vec()
b"+".to_vec()
} else {
Vec::new()
};
@ -148,7 +148,7 @@ impl Sending {
Err((server, is_appservice, e)) => {
info!("Couldn't send transaction to {}\n{}", server, e);
let mut prefix = if is_appservice {
"+".as_bytes().to_vec()
b"+".to_vec()
} else {
Vec::new()
};
@ -180,7 +180,7 @@ impl Sending {
.map_err(|_| Error::bad_database("ServerName in servernamepduid bytes are invalid."))
.map(|server_str| {
// Appservices start with a plus
if server_str.starts_with("+") {
if server_str.starts_with('+') {
(server_str[1..].to_owned(), true)
} else {
(server_str, false)
@ -196,6 +196,7 @@ impl Sending {
.map(|pdu_id| (server, is_appservice, pdu_id))
)
.filter(|(server, is_appservice, _)| {
#[allow(clippy::blocks_in_if_conditions)]
if last_failed_try.get(server).map_or(false, |(tries, instant)| {
// Fail if a request has failed recently (exponential backoff)
let mut min_elapsed_duration = Duration::from_secs(60) * *tries * *tries;
@ -209,7 +210,7 @@ impl Sending {
}
let mut prefix = if *is_appservice {
"+".as_bytes().to_vec()
b"+".to_vec()
} else {
Vec::new()
};
@ -247,7 +248,7 @@ impl Sending {
#[tracing::instrument(skip(self))]
pub fn send_pdu_appservice(&self, appservice_id: &str, pdu_id: &[u8]) -> Result<()> {
let mut key = "+".as_bytes().to_vec();
let mut key = b"+".to_vec();
key.extend_from_slice(appservice_id.as_bytes());
key.push(0xff);
key.extend_from_slice(pdu_id);
@ -385,7 +386,7 @@ impl Sending {
})?;
// Appservices start with a plus
let (server, is_appservice) = if server.starts_with("+") {
let (server, is_appservice) = if server.starts_with('+') {
(&server[1..], true)
} else {
(&*server, false)

View file

@ -222,7 +222,7 @@ fn add_port_to_hostname(destination_str: String) -> String {
#[tracing::instrument(skip(globals))]
async fn find_actual_destination(
globals: &crate::database::globals::Globals,
destination: &Box<ServerName>,
destination: &'_ ServerName,
) -> (String, Option<String>) {
let mut host = None;
@ -279,9 +279,9 @@ async fn find_actual_destination(
}
#[tracing::instrument(skip(globals))]
async fn query_srv_record<'a>(
async fn query_srv_record(
globals: &crate::database::globals::Globals,
hostname: &'a str,
hostname: &'_ str,
) -> Option<String> {
if let Ok(Some(host_port)) = globals
.dns_resolver()