Skip to content

fix: Make Rust 1.48 clippy happy #294

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 3 commits into from
Nov 20, 2020
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
1 change: 0 additions & 1 deletion sentry-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,4 @@ log_ = { package = "log", version = "0.4.8", optional = true, features = ["std"]
sentry = { version = "0.21.0", path = "../sentry", default-features = false, features = ["test"] }
thiserror = "1.0.15"
anyhow = "1.0.30"
failure = "0.1.8"
tokio = { version = "0.2", features = ["rt-core", "macros"] }
7 changes: 0 additions & 7 deletions sentry-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,4 @@ fn test_parse_type_from_debug() {
anyhow::Error::from("NaN".parse::<usize>().unwrap_err())
);
assert_eq!(parse(&err), "ParseIntError");

// `failure` is using normal debug formatting
let err = format!(
"{:?}",
failure::Error::from("NaN".parse::<usize>().unwrap_err())
);
assert_eq!(parse(&err), "ParseIntError");
}
22 changes: 11 additions & 11 deletions sentry-core/src/scope/real.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ pub type EventProcessor = Box<dyn Fn(Event<'static>) -> Option<Event<'static>> +
#[derive(Clone)]
pub struct Scope {
pub(crate) level: Option<Level>,
pub(crate) fingerprint: Option<Arc<Vec<Cow<'static, str>>>>,
pub(crate) transaction: Option<Arc<String>>,
pub(crate) fingerprint: Option<Arc<[Cow<'static, str>]>>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this a Cow?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it’s defined that way in Event, and its a matter if you want to make it a Cow ahead of applying the scope to the Event, or whenever you do that, so without changing the Event, I think doing it this way is simpler.

pub(crate) transaction: Option<Arc<str>>,
pub(crate) breadcrumbs: im::Vector<Breadcrumb>,
pub(crate) user: Option<Arc<User>>,
pub(crate) extra: im::HashMap<String, Value>,
Expand Down Expand Up @@ -167,13 +167,13 @@ impl Scope {

/// Sets the fingerprint.
pub fn set_fingerprint(&mut self, fingerprint: Option<&[&str]>) {
self.fingerprint = fingerprint
.map(|fp| Arc::new(fp.iter().map(|x| Cow::Owned((*x).to_string())).collect()))
self.fingerprint =
fingerprint.map(|fp| fp.iter().map(|s| Cow::Owned((*s).into())).collect())
}

/// Sets the transaction.
pub fn set_transaction(&mut self, transaction: Option<&str>) {
self.transaction = transaction.map(|txn| Arc::new(txn.to_string()));
self.transaction = transaction.map(Arc::from);
}

/// Sets the user for the current scope.
Expand Down Expand Up @@ -231,8 +231,8 @@ impl Scope {
}

if event.user.is_none() {
if let Some(ref user) = self.user {
event.user = Some((**user).clone());
if let Some(user) = self.user.as_deref() {
event.user = Some(user.clone());
}
}

Expand All @@ -244,16 +244,16 @@ impl Scope {
event.contexts.extend(self.contexts.clone().into_iter());

if event.transaction.is_none() {
if let Some(ref txn) = self.transaction {
event.transaction = Some((**txn).clone());
if let Some(txn) = self.transaction.as_deref() {
event.transaction = Some(txn.to_owned());
}
}

if event.fingerprint.len() == 1
&& (event.fingerprint[0] == "{{ default }}" || event.fingerprint[0] == "{{default}}")
{
if let Some(ref fp) = self.fingerprint {
event.fingerprint = Cow::Owned((**fp).clone());
if let Some(fp) = self.fingerprint.as_deref() {
event.fingerprint = Cow::Owned(fp.to_owned());
}
}

Expand Down
2 changes: 1 addition & 1 deletion sentry-types/src/dsn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl FromStr for Dsn {

let project_id = path_segments
.next()
.ok_or_else(|| ParseDsnError::NoProjectId)?
.ok_or(ParseDsnError::NoProjectId)?
.parse()
.map_err(ParseDsnError::InvalidProjectId)?;
let path = match path_segments.next().unwrap_or("") {
Expand Down
3 changes: 0 additions & 3 deletions sentry/src/defaults.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#![cfg_attr(feature = "error-chain", allow(deprecated))]
#![cfg_attr(feature = "failure", allow(deprecated))]

use std::env;
use std::{borrow::Cow, sync::Arc};

Expand Down
2 changes: 0 additions & 2 deletions sentry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@
//!
//! * `anyhow`: Enables support for the `anyhow` crate.
//! * `debug-images`: Attaches a list of loaded libraries to events (currently only supported on unix).
//! * `error-chain`: Enables support for the `error-chain` crate.
//! * `failure`: Enables support for the `failure` crate.
//! * `log`: Enables support for the `log` crate.
//! * `env_logger`: Enables support for the `log` crate with additional `env_logger` support.
//! * `slog`: Enables support for the `slog` crate.
Expand Down