From 59ee773e66a307deb03f9739b530c73f17185314 Mon Sep 17 00:00:00 2001 From: Eduardo Pinho Date: Sun, 2 Jul 2023 14:41:30 +0100 Subject: [PATCH 1/5] Require minimum Rust 1.56 - change rust-toolchain accordingly - remove Cargo features 1_34 and 1_46 - simplify feature gated code - update guide and documentation to no longer mention existing features - mark Location as non_exhaustive, remove _other field - change CI min version test task to use Rust 1.56 - remove v1.34 compatibility tests --- .cirrus.yml | 8 ++-- Cargo.toml | 10 +---- compatibility-tests/v1_34/rust-toolchain | 1 - .../{v1_34 => v1_56}/Cargo.toml | 9 +---- compatibility-tests/v1_56/rust-toolchain | 1 + .../{v1_34 => v1_56}/src/lib.rs | 0 snafu-derive/Cargo.toml | 2 - snafu-derive/src/report.rs | 10 ----- snafu-derive/src/shared.rs | 6 +-- src/futures/try_future.rs | 8 ++-- src/futures/try_stream.rs | 8 ++-- src/guide/compatibility.md | 34 ---------------- src/lib.rs | 40 +++++-------------- 13 files changed, 28 insertions(+), 109 deletions(-) delete mode 100644 compatibility-tests/v1_34/rust-toolchain rename compatibility-tests/{v1_34 => v1_56}/Cargo.toml (51%) create mode 100644 compatibility-tests/v1_56/rust-toolchain rename compatibility-tests/{v1_34 => v1_56}/src/lib.rs (100%) diff --git a/.cirrus.yml b/.cirrus.yml index 17a7663c..143cf55e 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -182,10 +182,10 @@ std_backtraces_test_task: - cargo +beta doc --features=backtraces-impl-std before_cache_script: rm -rf $CARGO_HOME/registry/index -v1_34_test_task: - name: "Rust 1.34" +v1_56_test_task: + name: "Rust 1.56" container: - image: rust:1.34 + image: rust:1.56 cpu: 1 memory: 2Gi cargo_cache: @@ -193,7 +193,7 @@ v1_34_test_task: fingerprint_script: cat Cargo.toml primary_test_script: - rustup self update - - cd compatibility-tests/v1_34/ + - cd compatibility-tests/v1_56/ - rustc --version - cargo test before_cache_script: rm -rf $CARGO_HOME/registry/index diff --git a/Cargo.toml b/Cargo.toml index d4a31b09..28afe811 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ exclude = [ features = [ "std", "backtraces", "futures", "guide" ] [features] -default = ["std", "rust_1_46"] +default = ["std"] # Implement the `std::error::Error` trait. std = [] @@ -33,14 +33,8 @@ std = [] # Implement the `core::error::Error` trait. unstable-core-error = [] -# Add support for `async` / `.await` -rust_1_39 = ["snafu-derive/rust_1_39"] - -# Add support for `#[track_caller]` -rust_1_46 = ["rust_1_39", "snafu-derive/rust_1_46"] - # Add support for `Termination` for `Report` -rust_1_61 = ["rust_1_46", "snafu-derive/rust_1_61"] +rust_1_61 = ["snafu-derive/rust_1_61"] # Makes the backtrace type live backtraces = ["std", "backtrace"] diff --git a/compatibility-tests/v1_34/rust-toolchain b/compatibility-tests/v1_34/rust-toolchain deleted file mode 100644 index cfe5aeaf..00000000 --- a/compatibility-tests/v1_34/rust-toolchain +++ /dev/null @@ -1 +0,0 @@ -1.34 diff --git a/compatibility-tests/v1_34/Cargo.toml b/compatibility-tests/v1_56/Cargo.toml similarity index 51% rename from compatibility-tests/v1_34/Cargo.toml rename to compatibility-tests/v1_56/Cargo.toml index 51bb6127..61aadea4 100644 --- a/compatibility-tests/v1_34/Cargo.toml +++ b/compatibility-tests/v1_56/Cargo.toml @@ -1,15 +1,8 @@ [package] -name = "v1_34" +name = "v1_56" version = "0.1.0" authors = ["Jake Goulding "] edition = "2018" [dependencies] snafu = { path = "../..", default-features = false, features = ["backtraces"] } - -# These versions are the last versions to support Rust 1.34 -backtrace = "= 0.3.35" -cc = "= 1.0.79" -proc-macro2 = "= 1.0.65" -quote = "= 1.0.30" -rustc-demangle = "= 0.1.20" diff --git a/compatibility-tests/v1_56/rust-toolchain b/compatibility-tests/v1_56/rust-toolchain new file mode 100644 index 00000000..e01e6c12 --- /dev/null +++ b/compatibility-tests/v1_56/rust-toolchain @@ -0,0 +1 @@ +1.56 diff --git a/compatibility-tests/v1_34/src/lib.rs b/compatibility-tests/v1_56/src/lib.rs similarity index 100% rename from compatibility-tests/v1_34/src/lib.rs rename to compatibility-tests/v1_56/src/lib.rs diff --git a/snafu-derive/Cargo.toml b/snafu-derive/Cargo.toml index fdbf6d37..a6a5b0a1 100644 --- a/snafu-derive/Cargo.toml +++ b/snafu-derive/Cargo.toml @@ -11,8 +11,6 @@ repository = "https://github.com/shepmaster/snafu" license = "MIT OR Apache-2.0" [features] -rust_1_39 = [] -rust_1_46 = [] rust_1_61 = [] unstable-backtraces-impl-std = [] unstable-provider-api = [] diff --git a/snafu-derive/src/report.rs b/snafu-derive/src/report.rs index 0da67fcf..0341d2e9 100644 --- a/snafu-derive/src/report.rs +++ b/snafu-derive/src/report.rs @@ -1,17 +1,7 @@ use quote::quote; use syn::{spanned::Spanned, Item, ItemFn, ReturnType, Signature}; -// In versions of Rust before 1.39, we can't use the `.await` keyword -// in *our* source code, even if we never generate it in the *output* -// source code. Hiding it behind a conditionally-compiled module -// works. -#[cfg(not(feature = "rust_1_39"))] -mod no_async; -#[cfg(not(feature = "rust_1_39"))] -use no_async::async_body; -#[cfg(feature = "rust_1_39")] mod yes_async; -#[cfg(feature = "rust_1_39")] use yes_async::async_body; pub fn body( diff --git a/snafu-derive/src/shared.rs b/snafu-derive/src/shared.rs index f8b54a7f..c8a29a81 100644 --- a/snafu-derive/src/shared.rs +++ b/snafu-derive/src/shared.rs @@ -471,11 +471,7 @@ pub mod context_selector { } fn track_caller() -> proc_macro2::TokenStream { - if cfg!(feature = "rust_1_46") { - quote::quote! { #[track_caller] } - } else { - quote::quote! {} - } + quote::quote! { #[track_caller] } } } diff --git a/src/futures/try_future.rs b/src/futures/try_future.rs index 94d0d4a1..f7c373df 100644 --- a/src/futures/try_future.rs +++ b/src/futures/try_future.rs @@ -230,7 +230,7 @@ where { type Output = Result; - #[cfg_attr(feature = "rust_1_46", track_caller)] + #[track_caller] fn poll(self: Pin<&mut Self>, ctx: &mut TaskContext) -> Poll { let this = self.project(); let inner = this.inner; @@ -273,7 +273,7 @@ where { type Output = Result; - #[cfg_attr(feature = "rust_1_46", track_caller)] + #[track_caller] fn poll(self: Pin<&mut Self>, ctx: &mut TaskContext) -> Poll { let this = self.project(); let inner = this.inner; @@ -320,7 +320,7 @@ where { type Output = Result; - #[cfg_attr(feature = "rust_1_46", track_caller)] + #[track_caller] fn poll(self: Pin<&mut Self>, ctx: &mut TaskContext) -> Poll { let this = self.project(); let inner = this.inner; @@ -368,7 +368,7 @@ where { type Output = Result; - #[cfg_attr(feature = "rust_1_46", track_caller)] + #[track_caller] fn poll(self: Pin<&mut Self>, ctx: &mut TaskContext) -> Poll { let this = self.project(); let inner = this.inner; diff --git a/src/futures/try_stream.rs b/src/futures/try_stream.rs index 3f3489da..0aada739 100644 --- a/src/futures/try_stream.rs +++ b/src/futures/try_stream.rs @@ -233,7 +233,7 @@ where { type Item = Result; - #[cfg_attr(feature = "rust_1_46", track_caller)] + #[track_caller] fn poll_next(self: Pin<&mut Self>, ctx: &mut TaskContext) -> Poll> { let this = self.project(); let inner = this.inner; @@ -273,7 +273,7 @@ where { type Item = Result; - #[cfg_attr(feature = "rust_1_46", track_caller)] + #[track_caller] fn poll_next(self: Pin<&mut Self>, ctx: &mut TaskContext) -> Poll> { let this = self.project(); let inner = this.inner; @@ -315,7 +315,7 @@ where { type Item = Result; - #[cfg_attr(feature = "rust_1_46", track_caller)] + #[track_caller] fn poll_next(self: Pin<&mut Self>, ctx: &mut TaskContext) -> Poll> { let this = self.project(); let inner = this.inner; @@ -359,7 +359,7 @@ where { type Item = Result; - #[cfg_attr(feature = "rust_1_46", track_caller)] + #[track_caller] fn poll_next(self: Pin<&mut Self>, ctx: &mut TaskContext) -> Poll> { let this = self.project(); let inner = this.inner; diff --git a/src/guide/compatibility.md b/src/guide/compatibility.md index 4f121e7f..040b746d 100644 --- a/src/guide/compatibility.md +++ b/src/guide/compatibility.md @@ -12,37 +12,6 @@ SNAFU is tested and compatible back to Rust 1.34, released on } -## `rust_1_39` - -
-
Default
-
enabled
-
- -When enabled, SNAFU will assume that it's safe to target features -available in Rust 1.39. Notably, the `async` and `.await` keywords are -needed to allow [`report`][macro@crate::report] to be used on `async` -functions. - -## `rust_1_46` - -
-
Default
-
enabled
-
Implies
-
- -[`rust_1_39`](#rust_1_39) - -
-
- - -When enabled, SNAFU will assume that it's safe to target features -available in Rust 1.46. Notably, the `#[track_caller]` feature is -needed to allow [`Location`][crate::Location] to automatically discern -the source code location. - ## `rust_1_61`
@@ -50,9 +19,6 @@ the source code location.
disabled
Implies
- -[`rust_1_46`](#rust_1_46) -
diff --git a/src/lib.rs b/src/lib.rs index 93c29c05..bfc6e06b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -695,7 +695,7 @@ pub trait ResultExt: Sized { } impl ResultExt for Result { - #[cfg_attr(feature = "rust_1_46", track_caller)] + #[track_caller] fn context(self, context: C) -> Result where C: IntoError, @@ -708,7 +708,7 @@ impl ResultExt for Result { } } - #[cfg_attr(feature = "rust_1_46", track_caller)] + #[track_caller] fn with_context(self, context: F) -> Result where F: FnOnce(&mut E) -> C, @@ -726,7 +726,7 @@ impl ResultExt for Result { } #[cfg(any(feature = "std", test))] - #[cfg_attr(feature = "rust_1_46", track_caller)] + #[track_caller] fn whatever_context(self, context: S) -> Result where S: Into, @@ -741,7 +741,7 @@ impl ResultExt for Result { } #[cfg(any(feature = "std", test))] - #[cfg_attr(feature = "rust_1_46", track_caller)] + #[track_caller] fn with_whatever_context(self, context: F) -> Result where F: FnOnce(&mut E) -> S, @@ -920,7 +920,7 @@ pub trait OptionExt: Sized { } impl OptionExt for Option { - #[cfg_attr(feature = "rust_1_46", track_caller)] + #[track_caller] fn context(self, context: C) -> Result where C: IntoError, @@ -933,7 +933,7 @@ impl OptionExt for Option { } } - #[cfg_attr(feature = "rust_1_46", track_caller)] + #[track_caller] fn with_context(self, context: F) -> Result where F: FnOnce() -> C, @@ -948,7 +948,7 @@ impl OptionExt for Option { } #[cfg(any(feature = "std", test))] - #[cfg_attr(feature = "rust_1_46", track_caller)] + #[track_caller] fn whatever_context(self, context: S) -> Result where S: Into, @@ -961,7 +961,7 @@ impl OptionExt for Option { } #[cfg(any(feature = "std", test))] - #[cfg_attr(feature = "rust_1_46", track_caller)] + #[track_caller] fn with_whatever_context(self, context: F) -> Result where F: FnOnce() -> S, @@ -1153,7 +1153,7 @@ pub trait GenerateImplicitData { fn generate() -> Self; /// Build the data using the given source - #[cfg_attr(feature = "rust_1_46", track_caller)] + #[track_caller] fn generate_with_source(source: &dyn crate::Error) -> Self where Self: Sized, @@ -1278,14 +1278,6 @@ impl AsBacktrace for Backtrace { /// /// ## Limitations /// -/// ### Rust 1.46 -/// -/// You need to enable the [`rust_1_46` feature flag][flag] for -/// implicit location capture. If you cannot enable that, you can -/// still use the [`location!`] macro at the expense of more typing. -/// -/// [flag]: guide::compatibility#rust_1_46 -/// /// ### Disabled context selectors /// /// If you have [disabled the context selector][disabled], SNAFU will @@ -1347,6 +1339,7 @@ impl AsBacktrace for Backtrace { /// # } /// ``` #[derive(Copy, Clone)] +#[non_exhaustive] pub struct Location { /// The file where the error was reported pub file: &'static str, @@ -1354,24 +1347,15 @@ pub struct Location { pub line: u32, /// The column where the error was reported pub column: u32, - - // Use `#[non_exhaustive]` when we upgrade to Rust 1.40 - _other: (), } impl Location { /// Constructs a `Location` using the given information pub fn new(file: &'static str, line: u32, column: u32) -> Self { - Self { - file, - line, - column, - _other: (), - } + Self { file, line, column } } } -#[cfg(feature = "rust_1_46")] impl Default for Location { #[track_caller] fn default() -> Self { @@ -1380,12 +1364,10 @@ impl Default for Location { file: loc.file(), line: loc.line(), column: loc.column(), - _other: (), } } } -#[cfg(feature = "rust_1_46")] impl GenerateImplicitData for Location { #[inline] #[track_caller] From 534922529767757e4c67d6c0f37ae485f377ae1f Mon Sep 17 00:00:00 2001 From: Eduardo Pinho Date: Sun, 2 Jul 2023 18:49:20 +0100 Subject: [PATCH 2/5] inline `#[track_caller]` attribute --- snafu-derive/src/shared.rs | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/snafu-derive/src/shared.rs b/snafu-derive/src/shared.rs index c8a29a81..c92f9e9c 100644 --- a/snafu-derive/src/shared.rs +++ b/snafu-derive/src/shared.rs @@ -270,13 +270,11 @@ pub mod context_selector { let transfer_user_fields = self.transfer_user_fields(); let construct_implicit_fields = self.construct_implicit_fields(); - let track_caller = track_caller(); - quote! { impl<#(#user_field_generics,)*> #parameterized_selector_name { #[doc = "Consume the selector and return the associated error"] #[must_use] - #track_caller + #[track_caller] #visibility fn build<#(#original_generics_without_defaults,)*>(self) -> #parameterized_error_name where #(#extended_where_clauses),* @@ -288,7 +286,7 @@ pub mod context_selector { } #[doc = "Consume the selector and return a `Result` with the associated error"] - #track_caller + #[track_caller] #visibility fn fail<#(#original_generics_without_defaults,)* __T>(self) -> ::core::result::Result<__T, #parameterized_error_name> where #(#extended_where_clauses),* @@ -330,8 +328,6 @@ pub mod context_selector { None => (quote! { #crate_root::NoneError }, None, None), }; - let track_caller = track_caller(); - quote! { impl<#(#original_generics_without_defaults,)* #(#user_field_generics,)*> #crate_root::IntoError<#parameterized_error_name> for #parameterized_selector_name where @@ -340,7 +336,7 @@ pub mod context_selector { { type Source = #source_ty; - #track_caller + #[track_caller] fn into_error(self, error: Self::Source) -> #parameterized_error_name { #transform_source; #error_constructor_name { @@ -384,13 +380,11 @@ pub mod context_selector { let message_field_name = &message_field.name; - let track_caller = track_caller(); - quote! { impl #crate_root::FromString for #parameterized_error_name { type Source = #source_ty; - #track_caller + #[track_caller] fn without_source(message: String) -> Self { #error_constructor_name { #construct_implicit_fields @@ -399,7 +393,7 @@ pub mod context_selector { } } - #track_caller + #[track_caller] fn with_source(error: Self::Source, message: String) -> Self { #error_constructor_name { #construct_implicit_fields_with_source @@ -426,14 +420,12 @@ pub mod context_selector { transfer_source_field, } = build_source_info(source_field); - let track_caller = track_caller(); - quote! { impl<#(#original_generics_without_defaults,)* #(#user_field_generics,)*> ::core::convert::From<#source_field_type> for #parameterized_error_name where #(#where_clauses),* { - #track_caller + #[track_caller] fn from(error: #source_field_type) -> Self { #transform_source; #error_constructor_name { @@ -469,10 +461,6 @@ pub mod context_selector { transfer_source_field, } } - - fn track_caller() -> proc_macro2::TokenStream { - quote::quote! { #[track_caller] } - } } pub mod display { From 5ba99748f34021a45d7fbb37820a878624f88dd4 Mon Sep 17 00:00:00 2001 From: Eduardo Pinho Date: Sun, 2 Jul 2023 18:59:55 +0100 Subject: [PATCH 3/5] Update MSRV in compatibility.md - fix mention of Rust version compatibility --- src/guide/compatibility.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/guide/compatibility.md b/src/guide/compatibility.md index 040b746d..43d7e756 100644 --- a/src/guide/compatibility.md +++ b/src/guide/compatibility.md @@ -1,7 +1,7 @@ ## Rust version compatibility -SNAFU is tested and compatible back to Rust 1.34, released on -2019-05-14. Compatibility is controlled by Cargo feature flags. +SNAFU is tested and compatible back to Rust 1.56, released on +2021-10-21. Compatibility is controlled by Cargo feature flags.