Skip to content

Commit e28369a

Browse files
authored
ref: Upgrade to Rust Edition 2018 (#120)
* meta: Add disclaimer on Rust version * build: Switch to Rust Edition 2018 * ref: Fix edition 2018 idioms * ref: Rename sentry_crate_release to sentry::release_name * ref: Fix feature gated code * fix: Macro imports for error_chain * ref: Fix import in windows code
1 parent 02dda12 commit e28369a

30 files changed

+94
-172
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ description = """
1111
Sentry (getsentry.com) client for rust ;)
1212
"""
1313
build = "build.rs"
14+
edition = "2018"
1415
autoexamples = true
1516

1617
[package.metadata.docs.rs]

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ We currently only verify this crate against a recent version of Sentry hosted on
2525
[sentry.io](https://sentry.io/) but it should work with on-prem Sentry versions
2626
8.20 and later.
2727

28+
Additionally, the lowest Rust version we target is _1.31.0_.
29+
2830
## Resources
2931

3032
- [crates.io](https://crates.io/crates/sentry)

build.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#[cfg(feature = "with_rust_info")]
2-
extern crate rustc_version;
3-
41
use std::env;
52
use std::fs::File;
63
use std::io::Write;

examples/before-send.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
extern crate sentry;
2-
31
use std::sync::Arc;
42

53
fn main() {

examples/error-chain-demo.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#[macro_use]
22
extern crate error_chain;
3-
#[macro_use]
4-
extern crate sentry;
53

64
use sentry::integrations::error_chain::capture_error_chain;
75

@@ -25,7 +23,7 @@ fn main() {
2523
.parse()
2624
.unwrap(),
2725
),
28-
release: sentry_crate_release!(),
26+
release: sentry::release_name!(),
2927
..Default::default()
3028
});
3129

examples/event-processors.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
extern crate sentry;
2-
31
fn main() {
42
let client =
53
sentry::Client::from_config("https://[email protected]/1041156");

examples/failure-demo.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
extern crate failure;
2-
#[macro_use]
3-
extern crate failure_derive;
4-
#[macro_use]
5-
extern crate sentry;
6-
1+
use failure::Fail;
72
use sentry::integrations::failure::capture_error;
83

94
#[derive(Fail, Debug)]
@@ -25,7 +20,7 @@ fn main() {
2520
let _sentry = sentry::init((
2621
"https://[email protected]/1041156",
2722
sentry::ClientOptions {
28-
release: sentry_crate_release!(),
23+
release: sentry::release_name!(),
2924
..Default::default()
3025
},
3126
));

examples/init-with-client.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
extern crate sentry;
2-
31
fn main() {
42
let client =
53
sentry::Client::from_config("https://[email protected]/1041156");

examples/log-demo.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
extern crate log;
2-
extern crate pretty_env_logger;
3-
extern crate sentry;
4-
51
use log::{debug, error, info, warn};
6-
use sentry::sentry_crate_release;
72

83
fn main() {
94
let _sentry = sentry::init((
105
"https://[email protected]/1041156",
116
sentry::ClientOptions {
12-
release: sentry_crate_release!(),
7+
release: sentry::release_name!(),
138
..Default::default()
149
},
1510
));

examples/message-demo.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
extern crate sentry;
2-
31
fn main() {
42
let _sentry = sentry::init("https://[email protected]/1041156");
53
sentry::configure_scope(|scope| {

examples/panic-demo.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
#[macro_use]
2-
extern crate sentry;
3-
41
fn main() {
52
let _sentry = sentry::init((
63
"https://[email protected]/1041156",
74
sentry::ClientOptions {
8-
release: sentry_crate_release!(),
5+
release: sentry::release_name!(),
96
..Default::default()
107
},
118
));

examples/send-with-extra.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
extern crate sentry;
2-
31
fn main() {
42
let _sentry = sentry::init("https://[email protected]/1041156");
53

examples/thread-demo.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
#[macro_use]
2-
extern crate log;
3-
extern crate pretty_env_logger;
4-
#[macro_use]
5-
extern crate sentry;
6-
71
use std::sync::Arc;
82
use std::thread;
93

@@ -14,7 +8,7 @@ fn main() {
148
let _sentry = sentry::init((
159
"https://[email protected]/1041156",
1610
sentry::ClientOptions {
17-
release: sentry_crate_release!(),
11+
release: sentry::release_name!(),
1812
..Default::default()
1913
},
2014
));
@@ -25,12 +19,12 @@ fn main() {
2519
sentry::integrations::panic::register_panic_handler();
2620

2721
// the log integration sends to Hub::current()
28-
info!("Spawning thread");
22+
log::info!("Spawning thread");
2923

3024
thread::spawn(|| {
3125
// The thread spawned here gets a new hub cloned from the hub of the
3226
// main thread.
33-
info!("Spawned thread, configuring scope.");
27+
log::info!("Spawned thread, configuring scope.");
3428

3529
// now we want to create a new hub based on the thread's normal hub for
3630
// working with it explicitly.
@@ -47,7 +41,7 @@ fn main() {
4741
sentry::Hub::run(hub, || {
4842
// the log integration picks up the Hub::current which is now bound
4943
// to the outer hub.
50-
error!("Failing!");
44+
log::error!("Failing!");
5145
});
5246
})
5347
.join()

integrations/sentry-actix/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ documentation = "https://docs.rs/sentry-actix"
1010
description = """
1111
Sentry client extension for actix-web
1212
"""
13+
edition = "2018"
1314

1415
[dependencies]
1516
actix-web = { version = "0.7", default-features = false }

integrations/sentry-actix/examples/basic.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
extern crate actix_web;
2-
extern crate sentry;
3-
extern crate sentry_actix;
4-
51
use std::env;
62
use std::io;
73

integrations/sentry-actix/src/lib.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,6 @@
7474
//! });
7575
//! # }
7676
//! ```
77-
extern crate actix_web;
78-
extern crate failure;
79-
extern crate fragile;
80-
extern crate sentry;
8177
8278
use std::borrow::Cow;
8379
use std::cell::RefCell;
@@ -326,7 +322,7 @@ impl ActixWebHubExt for Hub {
326322

327323
fn capture_actix_error(&self, err: &Error) -> Uuid {
328324
let mut exceptions = vec![];
329-
let mut ptr: Option<&Fail> = Some(err.as_fail());
325+
let mut ptr: Option<&dyn Fail> = Some(err.as_fail());
330326
let mut idx = 0;
331327
while let Some(fail) = ptr {
332328
// Check whether the failure::Fail held by err is a failure::Error wrapped in Compat

src/backtrace_support.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use regex::{Captures, Regex};
55

66
use crate::protocol::{Frame, Stacktrace};
77

8-
lazy_static! {
8+
lazy_static::lazy_static! {
99
static ref HASH_FUNC_RE: Regex = Regex::new(r#"(?x)
1010
^(.*)::h[a-f0-9]{16}$
1111
"#).unwrap();
@@ -27,6 +27,7 @@ pub static ref WELL_KNOWN_SYS_MODULES: Vec<&'static str> = {
2727
}
2828
rv
2929
};
30+
3031
pub static ref WELL_KNOWN_BORDER_FRAMES: Vec<&'static str> = {
3132
#[allow(unused_mut)]
3233
let mut rv = vec![
@@ -44,6 +45,7 @@ pub static ref WELL_KNOWN_BORDER_FRAMES: Vec<&'static str> = {
4445
}
4546
rv
4647
};
48+
4749
pub static ref SECONDARY_BORDER_FRAMES: Vec<(&'static str, &'static str)> = {
4850
#![allow(unused_mut)]
4951
let mut rv = Vec::new();
@@ -74,7 +76,7 @@ pub fn strip_symbol(s: &str) -> &str {
7476

7577
pub fn demangle_symbol(s: &str) -> String {
7678
COMMON_RUST_SYMBOL_ESCAPES_RE
77-
.replace_all(s, |caps: &Captures| {
79+
.replace_all(s, |caps: &Captures<'_>| {
7880
match &caps[1] {
7981
"SP" => "@",
8082
"BP" => "*",

src/client.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ use crate::utils;
2121
/// The Sentry client object.
2222
pub struct Client {
2323
options: ClientOptions,
24-
transport: RwLock<Option<Arc<Box<Transport>>>>,
24+
transport: RwLock<Option<Arc<Box<dyn Transport>>>>,
2525
}
2626

2727
impl fmt::Debug for Client {
28-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
28+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2929
f.debug_struct("Client")
3030
.field("dsn", &self.dsn())
3131
.field("options", &self.options)
@@ -43,7 +43,7 @@ impl Clone for Client {
4343
}
4444

4545
/// Type alias for before event/breadcrumb handlers.
46-
pub type BeforeCallback<T> = Arc<Box<Fn(T) -> Option<T> + Send + Sync>>;
46+
pub type BeforeCallback<T> = Arc<Box<dyn Fn(T) -> Option<T> + Send + Sync>>;
4747

4848
/// Configuration settings for the client.
4949
pub struct ClientOptions {
@@ -54,7 +54,7 @@ pub struct ClientOptions {
5454
/// This is typically either a boxed function taking the client options by
5555
/// reference and returning a `Transport`, a boxed `Arc<Transport>` or
5656
/// alternatively the `DefaultTransportFactory`.
57-
pub transport: Box<TransportFactory>,
57+
pub transport: Box<dyn TransportFactory>,
5858
/// module prefixes that are always considered in_app
5959
pub in_app_include: Vec<&'static str>,
6060
/// module prefixes that are never in_app
@@ -107,7 +107,7 @@ pub struct ClientOptions {
107107
impl RefUnwindSafe for ClientOptions {}
108108

109109
impl fmt::Debug for ClientOptions {
110-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
110+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
111111
#[derive(Debug)]
112112
struct TransportFactory;
113113
#[derive(Debug)]
@@ -207,7 +207,7 @@ impl Default for ClientOptions {
207207
}
208208
}
209209

210-
lazy_static! {
210+
lazy_static::lazy_static! {
211211
static ref CRATE_RE: Regex = Regex::new(r"^(?:_<)?([a-zA-Z0-9_]+?)(?:\.\.|::)").unwrap();
212212
}
213213

@@ -385,7 +385,7 @@ impl Client {
385385
mut event: Event<'static>,
386386
scope: Option<&Scope>,
387387
) -> Option<Event<'static>> {
388-
lazy_static! {
388+
lazy_static::lazy_static! {
389389
static ref DEBUG_META: DebugMeta = DebugMeta {
390390
images: utils::debug_images(),
391391
..Default::default()

src/constants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub const VERSION: &str = env!("CARGO_PKG_VERSION");
55

66
include!(concat!(env!("OUT_DIR"), "/constants.gen.rs"));
77

8-
lazy_static! {
8+
lazy_static::lazy_static! {
99
pub static ref USER_AGENT: String = format!("sentry.rust/{}", VERSION);
1010
pub static ref SDK_INFO: ClientSdkInfo = ClientSdkInfo {
1111
name: "sentry-rust".into(),

src/hub.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::scope::{Scope, ScopeGuard};
1515
use crate::{client::Client, scope::Stack, utils};
1616

1717
#[cfg(feature = "with_client_implementation")]
18-
lazy_static! {
18+
lazy_static::lazy_static! {
1919
static ref PROCESS_HUB: (Arc<Hub>, thread::ThreadId) = (
2020
Arc::new(Hub::new(None, Arc::new(Default::default()))),
2121
thread::current().id()

src/integrations/failure.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use crate::hub::Hub;
3535
use crate::internals::Uuid;
3636
use crate::protocol::{Event, Exception, Frame, Level, Stacktrace};
3737

38-
lazy_static! {
38+
lazy_static::lazy_static! {
3939
static ref MODULE_SPLIT_RE: Regex = Regex::new(r"^(.*)::(.*?)$").unwrap();
4040
static ref FRAME_RE: Regex = Regex::new(
4141
r#"(?xm)
@@ -160,7 +160,7 @@ pub fn event_from_error(err: &failure::Error) -> Event<'static> {
160160
pub fn event_from_fail<F: Fail + ?Sized>(fail: &F) -> Event<'static> {
161161
let mut exceptions = vec![exception_from_single_fail(fail, fail.backtrace())];
162162

163-
let mut ptr: Option<&Fail> = None;
163+
let mut ptr: Option<&dyn Fail> = None;
164164
while let Some(cause) = ptr.map(Fail::cause).unwrap_or_else(|| fail.cause()) {
165165
exceptions.push(exception_from_single_fail(cause, cause.backtrace()));
166166
ptr = Some(cause);

0 commit comments

Comments
 (0)