Skip to content

Enable some non-default clippy lints #520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,13 @@ rustflags = [
"-Wsemicolon_in_expressions_from_macros",
"-Wunused_import_braces",
"-Wunused_qualifications",
"-Wclippy::cloned_instead_of_copied",
"-Wclippy::dbg_macro",
"-Wclippy::inefficient_to_string",
"-Wclippy::macro_use_imports",
"-Wclippy::mut_mut",
"-Wclippy::needless_borrow",
"-Wclippy::nonstandard_macro_braces",
"-Wclippy::str_to_string",
"-Wclippy::todo",
]
4 changes: 2 additions & 2 deletions crates/matrix-crypto-ffi/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use matrix_sdk_crypto::{
store::CryptoStoreError as InnerStoreError, KeyExportError, MegolmError, OlmError,
SecretImportError as RustSecretImportError, SignatureError as InnerSignatureError,
};
use ruma::identifiers::Error as RumaIdentifierError;
use ruma::{identifiers::Error as RumaIdentifierError, UserId};

#[derive(Debug, thiserror::Error)]
pub enum KeyImportError {
Expand Down Expand Up @@ -33,7 +33,7 @@ pub enum SignatureError {
#[error(transparent)]
CryptoStore(#[from] InnerStoreError),
#[error("Unknown device {0} {1}")]
UnknownDevice(String, String),
UnknownDevice(Box<UserId>, String),
#[error("Unknown user identity {0}")]
UnknownUserIdentity(String),
}
Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-crypto-ffi/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl OlmMachine {
if let Some(device) = device {
Ok(self.runtime.block_on(device.verify())?.into())
} else {
Err(SignatureError::UnknownDevice(user_id.to_string(), device_id.to_string()))
Err(SignatureError::UnknownDevice(user_id, device_id.to_owned()))
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/matrix-crypto-ffi/src/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl From<SdkVerificationRequest> for OutgoingVerificationRequest {
room_id: r.room_id.to_string(),
content: serde_json::to_string(&r.content)
.expect("Can't serialize message content"),
event_type: r.content.event_type().to_string(),
event_type: r.content.event_type().to_owned(),
},
}
}
Expand Down Expand Up @@ -207,7 +207,7 @@ impl From<&RoomMessageRequest> for Request {
Self::RoomMessage {
request_id: r.txn_id.to_string(),
room_id: r.room_id.to_string(),
event_type: r.content.event_type().to_string(),
event_type: r.content.event_type().to_owned(),
content: serde_json::to_string(&r.content).expect("Can't serialize message content"),
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-sdk-appservice/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ pub(crate) fn transform_request_path(
) -> Result<http::Request<Bytes>> {
let uri = request.uri();
// remove trailing slash from path
let path = uri.path().trim_end_matches('/').to_string();
let path = uri.path().trim_end_matches('/').to_owned();

if !path.starts_with("/_matrix/app/v1/") {
let path = match path {
Expand Down
4 changes: 2 additions & 2 deletions crates/matrix-sdk-base/src/rooms/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,13 @@ fn calculate_room_name(
// the `else`?
format!("{}, and {} others", names.join(", "), (invited_joined - heroes_count))
} else {
"".to_string()
"".to_owned()
};

// User is alone.
if invited_joined <= 1 {
if names.is_empty() {
"Empty room".to_string()
"Empty room".to_owned()
} else {
format!("Empty room (was {})", names)
}
Expand Down
6 changes: 3 additions & 3 deletions crates/matrix-sdk-base/src/rooms/normal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,10 @@ impl Room {

if let Some(name) = &inner.base_info.name {
let name = name.trim();
return Ok(name.to_string());
return Ok(name.to_owned());
} else if let Some(alias) = &inner.base_info.canonical_alias {
let alias = alias.alias().trim();
return Ok(alias.to_string());
return Ok(alias.to_owned());
}
inner.summary.clone()
};
Expand Down Expand Up @@ -638,7 +638,7 @@ impl RoomInfo {
/// `false` means no update was applied as the were the same
pub fn set_prev_batch(&mut self, prev_batch: Option<&str>) -> bool {
if self.last_prev_batch.as_deref() != prev_batch {
self.last_prev_batch = prev_batch.map(|p| p.to_string());
self.last_prev_batch = prev_batch.map(|p| p.to_owned());
true
} else {
false
Expand Down
8 changes: 4 additions & 4 deletions crates/matrix-sdk-base/src/store/ambiguity_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl AmbiguityCache {
.and_then(|p| p.get(&member_event.state_key))
.and_then(|p| p.displayname.as_deref())
{
Some(d.to_string())
Some(d.to_owned())
} else if let Some(d) = self
.store
.get_profile(room_id, &member_event.state_key)
Expand All @@ -183,7 +183,7 @@ impl AmbiguityCache {
event.content.displayname.clone()
};

Some(display_name.unwrap_or_else(|| event.state_key.localpart().to_string()))
Some(display_name.unwrap_or_else(|| event.state_key.localpart().to_owned()))
} else {
None
}
Expand All @@ -200,7 +200,7 @@ impl AmbiguityCache {
self.store.get_users_with_display_name(room_id, old_name).await?
};

Some(AmbiguityMap { display_name: old_name.to_string(), users: old_display_name_map })
Some(AmbiguityMap { display_name: old_name.to_owned(), users: old_display_name_map })
} else {
None
};
Expand Down Expand Up @@ -235,7 +235,7 @@ impl AmbiguityCache {
};

Some(AmbiguityMap {
display_name: new_display_name.to_string(),
display_name: new_display_name.to_owned(),
users: new_display_name_map,
})
} else {
Expand Down
8 changes: 4 additions & 4 deletions crates/matrix-sdk-base/src/store/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ macro_rules! statestore_integration_tests {
let device_id = device_id!("device");

let session = Session {
access_token: "token".to_string(),
access_token: "token".to_owned(),
user_id: user_id.to_owned(),
device_id: device_id.to_owned(),
};
store.restore_session(session).await.unwrap();

changes.sync_token = Some("t392-516_47314_0_7_1_1_1_11444_1".to_string());
changes.sync_token = Some("t392-516_47314_0_7_1_1_1_11444_1".to_owned());

let presence_json: &JsonValue = &test_json::PRESENCE;
let presence_raw =
Expand Down Expand Up @@ -671,10 +671,10 @@ macro_rules! statestore_integration_tests {
check_timeline_events(room_id, &store, &stored_events, messages.end.as_deref()).await;

// Check if limited sync removes the stored timeline
let end_token = Some("end token".to_string());
let end_token = Some("end token".to_owned());
let timeline_slice = TimelineSlice::new(
Vec::new(),
"start token".to_string(),
"start token".to_owned(),
end_token.clone(),
true,
true,
Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-sdk-base/src/store/memory_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl MemoryStore {
}

async fn save_filter(&self, filter_name: &str, filter_id: &str) -> Result<()> {
self.filters.insert(filter_name.to_string(), filter_id.to_string());
self.filters.insert(filter_name.to_owned(), filter_id.to_owned());

Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions crates/matrix-sdk-base/src/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,9 +582,9 @@ impl StateChanges {
self.state
.entry(room_id.to_owned())
.or_insert_with(BTreeMap::new)
.entry(event.content().event_type().to_string())
.entry(event.content().event_type().to_owned())
.or_insert_with(BTreeMap::new)
.insert(event.state_key().to_string(), raw_event);
.insert(event.state_key().to_owned(), raw_event);
}

/// Update the `StateChanges` struct with the given room with a new
Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-sdk-base/src/store/store_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl StoreKey {
pub fn decrypt<T: for<'b> Deserialize<'b>>(&self, event: EncryptedEvent) -> Result<T, Error> {
if event.version != VERSION {
return Err(Error::Encryption(
"Error decrypting: Unknown ciphertext version".to_string(),
"Error decrypting: Unknown ciphertext version".to_owned(),
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ impl<'a, R: Read + ?Sized + 'a> AttachmentEncryptor<'a, R> {
.or_insert_with(|| Base64::new(hash.as_slice().to_owned()));

MediaEncryptionInfo {
version: VERSION.to_string(),
version: VERSION.to_owned(),
hashes: self.hashes,
iv: self.iv,
web_key: self.web_key,
Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-sdk-crypto/src/gossiping/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,7 @@ mod test {
own_device.set_trust_state(LocalTrust::Unset);

for _ in 1..=3 {
other_outbound.encrypt_helper("foo".to_string()).await;
other_outbound.encrypt_helper("foo".to_owned()).await;
}
other_outbound
.mark_shared_with(
Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-sdk-crypto/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ impl OlmMachine {
let master_key = i
.master_public_key()
.await
.and_then(|m| m.get_first_key().map(|m| m.to_string()));
.and_then(|m| m.get_first_key().map(|m| m.to_owned()));
debug!(
master_key =? master_key,
"Restored the cross signing identity"
Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-sdk-crypto/src/olm/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl Session {

Ok(EncryptedEventScheme::OlmV1Curve25519AesSha2(OlmV1Curve25519AesSha2Content::new(
content,
self.our_identity_keys.curve25519().to_string(),
self.our_identity_keys.curve25519().to_owned(),
))
.into())
}
Expand Down
4 changes: 2 additions & 2 deletions crates/matrix-sdk-crypto/src/olm/utility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ impl Utility {
let json_object = json.as_object_mut().ok_or(SignatureError::NotAnObject)?;

if let Some(u) = unsigned {
json_object.insert("unsigned".to_string(), u);
json_object.insert("unsigned".to_owned(), u);
}

json_object.insert("signatures".to_string(), signatures);
json_object.insert("signatures".to_owned(), signatures);

ret
}
Expand Down
4 changes: 2 additions & 2 deletions crates/matrix-sdk-crypto/src/store/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,8 @@ macro_rules! cryptostore_integration_tests {
let info: SecretInfo = RequestedKeyInfo::new(
EventEncryptionAlgorithm::MegolmV1AesSha2,
room_id!("!test:localhost").to_owned(),
"test_sender_key".to_string(),
"test_session_id".to_string(),
"test_sender_key".to_owned(),
"test_session_id".to_owned(),
)
.into();

Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-sdk-crypto/src/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ impl Store {
.inner
.get_device(self.user_id(), self.device_id())
.await?
.and_then(|d| d.display_name().map(|d| d.to_string())))
.and_then(|d| d.display_name().map(|d| d.to_owned())))
}

/// Get the read-only device associated with `device_id` for `user_id`
Expand Down
4 changes: 2 additions & 2 deletions crates/matrix-sdk-crypto/src/verification/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ impl Cancelled {
FlowId::ToDevice(s) => AnyToDeviceEventContent::KeyVerificationCancel(
ToDeviceKeyVerificationCancelEventContent::new(
s.clone(),
self.reason.to_string(),
self.reason.to_owned(),
self.cancel_code.clone(),
),
)
Expand All @@ -342,7 +342,7 @@ impl Cancelled {
r.clone(),
AnyMessageEventContent::KeyVerificationCancel(
KeyVerificationCancelEventContent::new(
self.reason.to_string(),
self.reason.to_owned(),
self.cancel_code.clone(),
Relation::new(e.clone()),
),
Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-sdk-crypto/src/verification/qrcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ impl QrVerification {

let inner: QrVerificationData = SelfVerificationNoMasterKey::new(
flow_id.as_str().to_owned(),
store.account.identity_keys().ed25519().to_string(),
store.account.identity_keys().ed25519().to_owned(),
own_master_key,
secret,
)
Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-sdk-indexeddb/src/safe_encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub trait SafeEncode {
&JsValue::from([&key, KEY_SEPARATOR].concat()),
&JsValue::from([&key, RANGE_END].concat()),
)
.map_err(|e| e.as_string().unwrap_or_else(|| "Creating key range failed".to_string()))
.map_err(|e| e.as_string().unwrap_or_else(|| "Creating key range failed".to_owned()))
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-sdk-sled/bin/state_inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ impl Inspector {
RoomId::parse(r).map(|_| ()).map_err(|_| "Invalid room id given".to_owned())
}))
.arg(Arg::new("event-type").required(true).validator(|e| {
EventType::try_from(e).map(|_| ()).map_err(|_| "Invalid event type".to_string())
EventType::try_from(e).map(|_| ()).map_err(|_| "Invalid event type".to_owned())
})),
]
}
Expand Down
7 changes: 1 addition & 6 deletions crates/matrix-sdk/examples/cross_signing_bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,10 @@ async fn login(
let asked = asked_ref;
let client = &client_ref;
let user_id = &user_id;
let password = &password;

// Wait for sync to be done then ask the user to bootstrap.
if !asked.load(Ordering::SeqCst) {
tokio::spawn(bootstrap(
(*client).clone(),
(*user_id).clone(),
password.to_string(),
));
tokio::spawn(bootstrap((*client).clone(), (*user_id).clone(), password.to_owned()));
}

asked.store(true, Ordering::SeqCst);
Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-sdk/examples/wasm_command_bot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl WasmBot {
}

async fn on_sync_response(&self, response: SyncResponse) -> LoopCtrl {
console::log_1(&"Synced".to_string().into());
console::log_1(&"Synced".to_owned().into());

for (room_id, room) in response.rooms.join {
for event in room.timeline.events {
Expand Down
Loading