-
Notifications
You must be signed in to change notification settings - Fork 123
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
Support Error in no_std environments #268
Changes from 7 commits
053be64
1934137
575ac74
d9d71b2
079cbb7
8ce404c
a38e5d5
1965ae4
06cbb91
1a8d07a
cc40c3b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#[cfg(not(feature = "testing-helpers"))] | ||
fn detect_nightly() {} | ||
|
||
#[cfg(feature = "testing-helpers")] | ||
fn detect_nightly() { | ||
use rustc_version::{version_meta, Channel}; | ||
|
||
if version_meta().unwrap().channel == Channel::Nightly { | ||
println!("cargo:rustc-cfg=nightly"); | ||
} | ||
} | ||
|
||
fn main() { | ||
detect_nightly(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
#!/usr/bin/env bash | ||
set -euxo pipefail | ||
|
||
for feature in $(tomljson Cargo.toml | jq --raw-output '.features | keys[]' | grep -v 'default\|std\|testing-helpers'); do | ||
cargo test -p derive_more --tests --no-default-features --features "$feature,testing-helpers"; | ||
for feature in $(tomljson Cargo.toml | jq --raw-output '.features | keys[]' | grep -v 'default\|std\|full\|testing-helpers'); do | ||
if [ "${1:-}" = 'std' ]; then | ||
cargo test -p derive_more --tests --no-default-features --features "$feature,std,testing-helpers"; | ||
else | ||
cargo test -p derive_more --tests --no-default-features --features "$feature,testing-helpers"; | ||
fi | ||
done |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ pub fn expand( | |
let state = State::with_attr_params( | ||
input, | ||
trait_name, | ||
quote! { ::std::error }, | ||
quote!{ ::derive_more::__private::Error }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @JelteF how about just We can bring the trait in scope together with the macro. This may be handy for much cases. And we can do this for all the traits (in a separate PR, surely). Still, if someone needs only a macro, we could have done it like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah, I think that's probably a good idea. Because of this change I'm working on adding the following line to all our tests:
And automatically importing the traits, possibly from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll leave it as __private here and we can make it public in the follow up PR where we do this for all traits. |
||
trait_name.to_lowercase(), | ||
allowed_attr_params(), | ||
)?; | ||
|
@@ -39,7 +39,7 @@ pub fn expand( | |
|
||
let source = source.map(|source| { | ||
quote! { | ||
fn source(&self) -> Option<&(dyn ::std::error::Error + 'static)> { | ||
fn source(&self) -> Option<&(dyn ::derive_more::__private::Error + 'static)> { | ||
use ::derive_more::__private::AsDynError; | ||
#source | ||
} | ||
|
@@ -48,7 +48,7 @@ pub fn expand( | |
|
||
let provide = provide.map(|provide| { | ||
quote! { | ||
fn provide<'_demand>(&'_demand self, demand: &mut ::std::any::Demand<'_demand>) { | ||
fn provide<'_demand>(&'_demand self, demand: &mut ::core::any::Demand<'_demand>) { | ||
#provide | ||
} | ||
} | ||
|
@@ -62,7 +62,7 @@ pub fn expand( | |
&generics, | ||
quote! { | ||
where | ||
#ident #ty_generics: ::std::fmt::Debug + ::std::fmt::Display | ||
#ident #ty_generics: ::core::fmt::Debug + ::core::fmt::Display | ||
}, | ||
); | ||
} | ||
|
@@ -73,7 +73,7 @@ pub fn expand( | |
&generics, | ||
quote! { | ||
where | ||
#(#bounds: ::std::fmt::Debug + ::std::fmt::Display + ::std::error::Error + 'static),* | ||
#(#bounds: ::core::fmt::Debug + ::core::fmt::Display + ::derive_more::__private::Error + 'static),* | ||
}, | ||
); | ||
} | ||
|
@@ -82,7 +82,7 @@ pub fn expand( | |
|
||
let render = quote! { | ||
#[automatically_derived] | ||
impl #impl_generics ::std::error::Error for #ident #ty_generics #where_clause { | ||
impl #impl_generics ::derive_more::__private::Error for #ident #ty_generics #where_clause { | ||
#source | ||
#provide | ||
} | ||
|
@@ -207,7 +207,7 @@ impl<'input, 'state> ParsedFields<'input, 'state> { | |
let source_provider = self.source.map(|source| { | ||
let source_expr = &self.data.members[source]; | ||
quote! { | ||
::std::error::Error::provide(&#source_expr, demand); | ||
::derive_more::__private::Error::provide(&#source_expr, demand); | ||
} | ||
}); | ||
let backtrace_provider = self | ||
|
@@ -217,7 +217,7 @@ impl<'input, 'state> ParsedFields<'input, 'state> { | |
.then(|| { | ||
let backtrace_expr = &self.data.members[backtrace]; | ||
quote! { | ||
demand.provide_ref::<std::backtrace::Backtrace>(&#backtrace_expr); | ||
demand.provide_ref::<::std::backtrace::Backtrace>(&#backtrace_expr); | ||
} | ||
}); | ||
|
||
|
@@ -237,7 +237,7 @@ impl<'input, 'state> ParsedFields<'input, 'state> { | |
let pattern = self.data.matcher(&[source], &[quote! { source }]); | ||
Some(quote! { | ||
#pattern => { | ||
::std::error::Error::provide(source, demand); | ||
::derive_more::__private::Error::provide(source, demand); | ||
} | ||
}) | ||
} | ||
|
@@ -248,16 +248,16 @@ impl<'input, 'state> ParsedFields<'input, 'state> { | |
); | ||
Some(quote! { | ||
#pattern => { | ||
demand.provide_ref::<std::backtrace::Backtrace>(backtrace); | ||
::std::error::Error::provide(source, demand); | ||
demand.provide_ref::<::std::backtrace::Backtrace>(backtrace); | ||
::derive_more::__private::Error::provide(source, demand); | ||
} | ||
}) | ||
} | ||
None => { | ||
let pattern = self.data.matcher(&[backtrace], &[quote! { backtrace }]); | ||
Some(quote! { | ||
#pattern => { | ||
demand.provide_ref::<std::backtrace::Backtrace>(backtrace); | ||
demand.provide_ref::<::std::backtrace::Backtrace>(backtrace); | ||
} | ||
}) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#![cfg_attr(not(feature = "std"), no_std)] | ||
#![cfg_attr(nightly, feature(error_generic_member_access, provide_any))] | ||
#![cfg_attr(not(feature = "std"), feature(error_in_core))] | ||
|
||
mod error; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JelteF I think here will be enough just to run tests 2 times sequentially, rather than matrix over the input parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's quite nice to see if both no_std and std are broken with a quick glance at the job output. Also it would double our CI time, since it would be the longest running job by ~2x the previous one. So I changed this back to use a matrix. I did make the matrix a bit more descriptive though, so that the job output is clearer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JelteF you should edit branch protection rules, because now CI awaits
test features
job to complete, while we havetest features (std)
andtest features (no_std)
now only.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. If you approve the PR it should merge automatically.