Skip to content
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

Require minimum Rust 1.56 #381

Merged
merged 5 commits into from
Aug 18, 2023
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
8 changes: 4 additions & 4 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,18 @@ 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:
folder: $CARGO_HOME/registry
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
Expand Down
11 changes: 3 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "snafu"
version = "0.7.5"
authors = ["Jake Goulding <jake.goulding@gmail.com>"]
edition = "2018"
rust-version = "1.56"

readme = "README.md"
description = "An ergonomic error handling library"
Expand All @@ -25,22 +26,16 @@ exclude = [
features = [ "std", "backtraces", "futures", "guide" ]

[features]
default = ["std", "rust_1_46"]
default = ["std"]

# Implement the `std::error::Error` trait.
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"]
Expand Down
1 change: 0 additions & 1 deletion compatibility-tests/v1_34/rust-toolchain

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
[package]
name = "v1_34"
name = "v1_56"
version = "0.1.0"
authors = ["Jake Goulding <jake.goulding@gmail.com>"]
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"
1 change: 1 addition & 0 deletions compatibility-tests/v1_56/rust-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.56
3 changes: 1 addition & 2 deletions snafu-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "snafu-derive"
version = "0.7.5"
authors = ["Jake Goulding <jake.goulding@gmail.com>"]
edition = "2018"
rust-version = "1.56"

description = "An ergonomic error handling library"
documentation = "https://docs.rs/snafu"
Expand All @@ -11,8 +12,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 = []
Expand Down
29 changes: 15 additions & 14 deletions snafu-derive/src/report.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
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(
_attr: proc_macro::TokenStream,
item: proc_macro::TokenStream,
Expand Down Expand Up @@ -65,7 +52,21 @@ pub fn body(
};

let block = if asyncness.is_some() {
async_body(block)?
if cfg!(feature = "rust_1_61") {
quote! {
{
let __snafu_body = async #block;
<::snafu::Report<_> as ::core::convert::From<_>>::from(__snafu_body.await)
}
}
} else {
quote! {
{
let __snafu_body = async #block;
::core::result::Result::map_err(__snafu_body.await, ::snafu::Report::from_error)
}
}
}
} else {
if cfg!(feature = "rust_1_61") {
quote! {
Expand Down
8 changes: 0 additions & 8 deletions snafu-derive/src/report/no_async.rs

This file was deleted.

19 changes: 0 additions & 19 deletions snafu-derive/src/report/yes_async.rs

This file was deleted.

28 changes: 6 additions & 22 deletions snafu-derive/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),*
Expand All @@ -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),*
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -469,14 +461,6 @@ pub mod context_selector {
transfer_source_field,
}
}

fn track_caller() -> proc_macro2::TokenStream {
if cfg!(feature = "rust_1_46") {
quote::quote! { #[track_caller] }
} else {
quote::quote! {}
}
}
}

pub mod display {
Expand Down
8 changes: 4 additions & 4 deletions src/futures/try_future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ where
{
type Output = Result<Fut::Ok, E>;

#[cfg_attr(feature = "rust_1_46", track_caller)]
#[track_caller]
fn poll(self: Pin<&mut Self>, ctx: &mut TaskContext) -> Poll<Self::Output> {
let this = self.project();
let inner = this.inner;
Expand Down Expand Up @@ -273,7 +273,7 @@ where
{
type Output = Result<Fut::Ok, E>;

#[cfg_attr(feature = "rust_1_46", track_caller)]
#[track_caller]
fn poll(self: Pin<&mut Self>, ctx: &mut TaskContext) -> Poll<Self::Output> {
let this = self.project();
let inner = this.inner;
Expand Down Expand Up @@ -320,7 +320,7 @@ where
{
type Output = Result<Fut::Ok, E>;

#[cfg_attr(feature = "rust_1_46", track_caller)]
#[track_caller]
fn poll(self: Pin<&mut Self>, ctx: &mut TaskContext) -> Poll<Self::Output> {
let this = self.project();
let inner = this.inner;
Expand Down Expand Up @@ -368,7 +368,7 @@ where
{
type Output = Result<Fut::Ok, E>;

#[cfg_attr(feature = "rust_1_46", track_caller)]
#[track_caller]
fn poll(self: Pin<&mut Self>, ctx: &mut TaskContext) -> Poll<Self::Output> {
let this = self.project();
let inner = this.inner;
Expand Down
8 changes: 4 additions & 4 deletions src/futures/try_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ where
{
type Item = Result<St::Ok, E>;

#[cfg_attr(feature = "rust_1_46", track_caller)]
#[track_caller]
fn poll_next(self: Pin<&mut Self>, ctx: &mut TaskContext) -> Poll<Option<Self::Item>> {
let this = self.project();
let inner = this.inner;
Expand Down Expand Up @@ -273,7 +273,7 @@ where
{
type Item = Result<St::Ok, E>;

#[cfg_attr(feature = "rust_1_46", track_caller)]
#[track_caller]
fn poll_next(self: Pin<&mut Self>, ctx: &mut TaskContext) -> Poll<Option<Self::Item>> {
let this = self.project();
let inner = this.inner;
Expand Down Expand Up @@ -315,7 +315,7 @@ where
{
type Item = Result<St::Ok, E>;

#[cfg_attr(feature = "rust_1_46", track_caller)]
#[track_caller]
fn poll_next(self: Pin<&mut Self>, ctx: &mut TaskContext) -> Poll<Option<Self::Item>> {
let this = self.project();
let inner = this.inner;
Expand Down Expand Up @@ -359,7 +359,7 @@ where
{
type Item = Result<St::Ok, E>;

#[cfg_attr(feature = "rust_1_46", track_caller)]
#[track_caller]
fn poll_next(self: Pin<&mut Self>, ctx: &mut TaskContext) -> Poll<Option<Self::Item>> {
let this = self.project();
let inner = this.inner;
Expand Down
38 changes: 2 additions & 36 deletions src/guide/compatibility.md
Original file line number Diff line number Diff line change
@@ -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.

<style>
.snafu-ff-meta>dt {
Expand All @@ -12,47 +12,13 @@ SNAFU is tested and compatible back to Rust 1.34, released on
}
</style>

## `rust_1_39`

<dl class="snafu-ff-meta">
<dt>Default</dt>
<dd>enabled</dd>
</dl>

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`

<dl class="snafu-ff-meta">
<dt>Default</dt>
<dd>enabled</dd>
<dt>Implies</dt>
<dd>

[`rust_1_39`](#rust_1_39)

</dd>
</dl>
</dl>

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`

<dl class="snafu-ff-meta">
<dt>Default</dt>
<dd>disabled</dd>
<dt>Implies</dt>
<dd>

[`rust_1_46`](#rust_1_46)

</dd>
</dl>

Expand Down
Loading