Update MSRV to 1.84.0

And appease clippy (`__CARGO_FIX_YOLO=1 cargo clippy --fix` plus some
manual type shuffling).
This commit is contained in:
Lambda 2025-02-02 11:30:07 +00:00
parent 5616510727
commit 175a62007d
20 changed files with 83 additions and 89 deletions

View file

@ -79,7 +79,7 @@ version = "0.1.0"
edition = "2021" edition = "2021"
# See also `rust-toolchain.toml` # See also `rust-toolchain.toml`
rust-version = "1.81.0" rust-version = "1.84.0"
[lints] [lints]
workspace = true workspace = true

6
flake.lock generated
View file

@ -291,13 +291,13 @@
"rust-manifest": { "rust-manifest": {
"flake": false, "flake": false,
"locked": { "locked": {
"narHash": "sha256-tB9BZB6nRHDk5ELIVlGYlIjViLKBjQl52nC1avhcCwA=", "narHash": "sha256-dm4qOlaZ/uZ+O2TmOrWEjjMAzZNWAGE8S0ne79Fo8OA=",
"type": "file", "type": "file",
"url": "https://static.rust-lang.org/dist/channel-rust-1.81.0.toml" "url": "https://static.rust-lang.org/dist/channel-rust-1.84.0.toml"
}, },
"original": { "original": {
"type": "file", "type": "file",
"url": "https://static.rust-lang.org/dist/channel-rust-1.81.0.toml" "url": "https://static.rust-lang.org/dist/channel-rust-1.84.0.toml"
} }
}, },
"systems": { "systems": {

View file

@ -12,7 +12,7 @@
rust-manifest = { rust-manifest = {
# Keep version in sync with rust-toolchain.toml # Keep version in sync with rust-toolchain.toml
url = "https://static.rust-lang.org/dist/channel-rust-1.81.0.toml"; url = "https://static.rust-lang.org/dist/channel-rust-1.84.0.toml";
flake = false; flake = false;
}; };
}; };

View file

@ -9,7 +9,7 @@
# If you're having trouble making the relevant changes, bug a maintainer. # If you're having trouble making the relevant changes, bug a maintainer.
[toolchain] [toolchain]
channel = "1.81.0" channel = "1.84.0"
components = [ components = [
# For rust-analyzer # For rust-analyzer
"rust-src", "rust-src",

View file

@ -150,8 +150,8 @@ pub(crate) async fn upload_signing_keys_route(
services().users.add_cross_signing_keys( services().users.add_cross_signing_keys(
sender_user, sender_user,
master_key, master_key,
&body.self_signing_key, body.self_signing_key.as_ref(),
&body.user_signing_key, body.user_signing_key.as_ref(),
// notify so that other users see the new keys // notify so that other users see the new keys
true, true,
)?; )?;
@ -428,7 +428,7 @@ pub(crate) async fn get_keys_helper<F: Fn(&UserId) -> bool>(
let raw = serde_json::from_value(json) let raw = serde_json::from_value(json)
.expect("Raw::from_value always works"); .expect("Raw::from_value always works");
services().users.add_cross_signing_keys( services().users.add_cross_signing_keys(
&user, &raw, &None, &None, &user, &raw, None, None,
// Dont notify. A notification would trigger another key // Dont notify. A notification would trigger another key
// request resulting in an endless loop // request resulting in an endless loop
false, false,

View file

@ -133,62 +133,59 @@ pub(crate) async fn create_room_route(
}; };
let room_version = RoomVersion::try_from(&room_version_id)?; let room_version = RoomVersion::try_from(&room_version_id)?;
let content = match &body.creation_content { let content = if let Some(content) = &body.creation_content {
Some(content) => { let mut content = content
let mut content = content .deserialize_as::<CanonicalJsonObject>()
.deserialize_as::<CanonicalJsonObject>() .expect("Invalid creation content");
.expect("Invalid creation content");
if room_version.create_event_creator_prop { if room_version.create_event_creator_prop {
content.insert(
"creator".into(),
json!(&sender_user).try_into().map_err(|_| {
Error::BadRequest(
ErrorKind::BadJson,
"Invalid creation content",
)
})?,
);
}
content.insert( content.insert(
"room_version".into(), "creator".into(),
json!(room_version_id.as_str()).try_into().map_err(|_| { json!(&sender_user).try_into().map_err(|_| {
Error::BadRequest( Error::BadRequest(
ErrorKind::BadJson, ErrorKind::BadJson,
"Invalid creation content", "Invalid creation content",
) )
})?, })?,
); );
content
} }
None => { content.insert(
let content = if room_version.create_event_creator_prop { "room_version".into(),
RoomCreateEventContent::new_v1(sender_user.to_owned()) json!(room_version_id.as_str()).try_into().map_err(|_| {
} else { Error::BadRequest(
RoomCreateEventContent::new_v11() ErrorKind::BadJson,
}; "Invalid creation content",
let mut content = serde_json::from_str::<CanonicalJsonObject>( )
to_raw_value(&content) })?,
.map_err(|_| { );
Error::BadRequest( content
ErrorKind::BadJson, } else {
"Invalid creation content", let content = if room_version.create_event_creator_prop {
) RoomCreateEventContent::new_v1(sender_user.to_owned())
})? } else {
.get(), RoomCreateEventContent::new_v11()
) };
.unwrap(); let mut content = serde_json::from_str::<CanonicalJsonObject>(
content.insert( to_raw_value(&content)
"room_version".into(), .map_err(|_| {
json!(room_version_id.as_str()).try_into().map_err(|_| {
Error::BadRequest( Error::BadRequest(
ErrorKind::BadJson, ErrorKind::BadJson,
"Invalid creation content", "Invalid creation content",
) )
})?, })?
); .get(),
content )
} .unwrap();
content.insert(
"room_version".into(),
json!(room_version_id.as_str()).try_into().map_err(|_| {
Error::BadRequest(
ErrorKind::BadJson,
"Invalid creation content",
)
})?,
);
content
}; };
// Validate creation content // Validate creation content

View file

@ -232,11 +232,11 @@ pub(crate) async fn login_route(
let token = utils::random_string(TOKEN_LENGTH); let token = utils::random_string(TOKEN_LENGTH);
// Determine if device_id was provided and exists in the db for this user // Determine if device_id was provided and exists in the db for this user
let device_exists = body.device_id.as_ref().map_or(false, |device_id| { let device_exists = body.device_id.as_ref().is_some_and(|device_id| {
services() services()
.users .users
.all_device_ids(&user_id) .all_device_ids(&user_id)
.any(|x| x.as_ref().map_or(false, |v| v == device_id)) .any(|x| x.as_ref().is_ok_and(|v| v == device_id))
}); });
if device_exists { if device_exists {

View file

@ -60,10 +60,9 @@ pub(crate) async fn search_users_route(
.rooms .rooms
.state_accessor .state_accessor
.room_state_get(&room, &StateEventType::RoomJoinRules, "") .room_state_get(&room, &StateEventType::RoomJoinRules, "")
.map_or(false, |event| { .is_ok_and(|event| {
event.map_or(false, |event| { event.is_some_and(|event| {
serde_json::from_str(event.content.get()).map_or( serde_json::from_str(event.content.get()).is_ok_and(
false,
|r: RoomJoinRulesEventContent| { |r: RoomJoinRulesEventContent| {
r.join_rule == JoinRule::Public r.join_rule == JoinRule::Public
}, },

View file

@ -1030,8 +1030,8 @@ pub(crate) async fn send_transaction_message_route(
services().users.add_cross_signing_keys( services().users.add_cross_signing_keys(
&user_id, &user_id,
&master_key, &master_key,
&self_signing_key, self_signing_key.as_ref(),
&None, None,
true, true,
)?; )?;
} }

View file

@ -114,10 +114,10 @@ async fn federation_self_test() -> Result<()> {
) )
.await?; .await?;
if !response if response
.server .server
.as_ref() .as_ref()
.is_some_and(|s| s.name.as_deref() == Some(env!("CARGO_PKG_NAME"))) .is_none_or(|s| s.name.as_deref() != Some(env!("CARGO_PKG_NAME")))
{ {
error!(?response, "unexpected server version"); error!(?response, "unexpected server version");
return Err(Error::BadConfig( return Err(Error::BadConfig(

View file

@ -488,8 +488,8 @@ impl KeyValueDatabase {
for (userid, password) in self.userid_password.iter() { for (userid, password) in self.userid_password.iter() {
let password = utils::string_from_bytes(&password); let password = utils::string_from_bytes(&password);
let empty_hashed_password = password let empty_hashed_password =
.map_or(false, |password| { password.is_ok_and(|password| {
utils::verify_password("", password) utils::verify_password("", password)
}); });

View file

@ -182,9 +182,9 @@ impl service::rooms::state_cache::Data for KeyValueDatabase {
.ok(); .ok();
let in_room = bridge_user_id let in_room = bridge_user_id
.map_or(false, |id| self.is_joined(&id, room_id).unwrap_or(false)) .is_some_and(|id| self.is_joined(&id, room_id).unwrap_or(false))
|| self.room_members(room_id).any(|userid| { || self.room_members(room_id).any(|userid| {
userid.map_or(false, |userid| { userid.is_ok_and(|userid| {
appservice.users.is_match(userid.as_str()) appservice.users.is_match(userid.as_str())
}) })
}); });

View file

@ -86,12 +86,10 @@ impl service::sending::Data for KeyValueDatabase {
) -> Box<dyn Iterator<Item = Result<(SendingEventType, RequestKey)>> + 'a> ) -> Box<dyn Iterator<Item = Result<(SendingEventType, RequestKey)>> + 'a>
{ {
let prefix = destination.get_prefix(); let prefix = destination.get_prefix();
return Box::new(self.servernameevent_data.scan_prefix(prefix).map( Box::new(self.servernameevent_data.scan_prefix(prefix).map(|(k, v)| {
|(k, v)| { let k = RequestKey::new(k);
let k = RequestKey::new(k); parse_servercurrentevent(&k, v).map(|(_, ev)| (ev, k))
parse_servercurrentevent(&k, v).map(|(_, ev)| (ev, k)) }))
},
));
} }
fn mark_as_active( fn mark_as_active(

View file

@ -522,8 +522,8 @@ impl service::users::Data for KeyValueDatabase {
&self, &self,
user_id: &UserId, user_id: &UserId,
master_key: &Raw<CrossSigningKey>, master_key: &Raw<CrossSigningKey>,
self_signing_key: &Option<Raw<CrossSigningKey>>, self_signing_key: Option<&Raw<CrossSigningKey>>,
user_signing_key: &Option<Raw<CrossSigningKey>>, user_signing_key: Option<&Raw<CrossSigningKey>>,
notify: bool, notify: bool,
) -> Result<()> { ) -> Result<()> {
// TODO: Check signatures // TODO: Check signatures

View file

@ -443,8 +443,8 @@ impl Service {
&self.config.turn.secret &self.config.turn.secret
} }
pub(crate) fn emergency_password(&self) -> &Option<String> { pub(crate) fn emergency_password(&self) -> Option<&str> {
&self.config.emergency_password self.config.emergency_password.as_deref()
} }
/// If the emergency password option is set, attempts to set the emergency /// If the emergency password option is set, attempts to set the emergency
@ -455,10 +455,9 @@ impl Service {
let inner = || -> Result<bool> { let inner = || -> Result<bool> {
let admin_bot = self.admin_bot_user_id.as_ref(); let admin_bot = self.admin_bot_user_id.as_ref();
services().users.set_password( services()
admin_bot, .users
self.emergency_password().as_deref(), .set_password(admin_bot, self.emergency_password())?;
)?;
let (ruleset, res) = match self.emergency_password() { let (ruleset, res) = match self.emergency_password() {
Some(_) => (Ruleset::server_default(admin_bot), Ok(true)), Some(_) => (Ruleset::server_default(admin_bot), Ok(true)),

View file

@ -76,7 +76,7 @@ impl Service {
let mut results = Vec::new(); let mut results = Vec::new();
while let Some(current_room) = { while let Some(current_room) = {
while stack.last().map_or(false, Vec::is_empty) { while stack.last().is_some_and(Vec::is_empty) {
stack.pop(); stack.pop();
} }
if stack.is_empty() { if stack.is_empty() {

View file

@ -120,7 +120,7 @@ impl Service {
}) })
}) })
.transpose()? .transpose()?
.map_or(false, |ignored| { .is_some_and(|ignored| {
ignored ignored
.content .content
.ignored_users .ignored_users

View file

@ -726,9 +726,10 @@ impl Service {
let matching_users = |users: &NamespaceRegex| { let matching_users = |users: &NamespaceRegex| {
appservice.users.is_match(pdu.sender.as_str()) appservice.users.is_match(pdu.sender.as_str())
|| pdu.kind == TimelineEventType::RoomMember || pdu.kind == TimelineEventType::RoomMember
&& pdu.state_key.as_ref().map_or(false, |state_key| { && pdu
users.is_match(state_key) .state_key
}) .as_ref()
.is_some_and(|state_key| users.is_match(state_key))
}; };
let matching_aliases = |aliases: &NamespaceRegex| { let matching_aliases = |aliases: &NamespaceRegex| {
services() services()

View file

@ -464,8 +464,8 @@ impl Service {
&self, &self,
user_id: &UserId, user_id: &UserId,
master_key: &Raw<CrossSigningKey>, master_key: &Raw<CrossSigningKey>,
self_signing_key: &Option<Raw<CrossSigningKey>>, self_signing_key: Option<&Raw<CrossSigningKey>>,
user_signing_key: &Option<Raw<CrossSigningKey>>, user_signing_key: Option<&Raw<CrossSigningKey>>,
notify: bool, notify: bool,
) -> Result<()> { ) -> Result<()> {
self.db.add_cross_signing_keys( self.db.add_cross_signing_keys(

View file

@ -140,8 +140,8 @@ pub(crate) trait Data: Send + Sync {
&self, &self,
user_id: &UserId, user_id: &UserId,
master_key: &Raw<CrossSigningKey>, master_key: &Raw<CrossSigningKey>,
self_signing_key: &Option<Raw<CrossSigningKey>>, self_signing_key: Option<&Raw<CrossSigningKey>>,
user_signing_key: &Option<Raw<CrossSigningKey>>, user_signing_key: Option<&Raw<CrossSigningKey>>,
notify: bool, notify: bool,
) -> Result<()>; ) -> Result<()>;