summaryrefslogtreecommitdiff
path: root/src/utils.rs
diff options
context:
space:
mode:
authorDavid LeGare <legare@google.com>2022-03-02 16:21:21 +0000
committerDavid LeGare <legare@google.com>2022-03-02 16:21:21 +0000
commitfa4ad9538a1237993e6c6eb4ed6d95947b010cd7 (patch)
tree6b24ddd0d0285a3b0e3ee80782f20a11ca2703dc /src/utils.rs
parent8a162e8e9f240ea957a52fb2796bfa36a6af671c (diff)
downloadpin-project-internal-fa4ad9538a1237993e6c6eb4ed6d95947b010cd7.tar.gz
Update pin-project-internal to 1.0.10
Test: cd external/rust/crates && atest --host -c Change-Id: Ifa47ca5b4f7f69191a41e910d5a2a312ea69d5ad
Diffstat (limited to 'src/utils.rs')
-rw-r--r--src/utils.rs26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/utils.rs b/src/utils.rs
index 3fa07e7..27373ef 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -15,12 +15,18 @@ use syn::{
pub(crate) type Variants = Punctuated<Variant, Token![,]>;
-macro_rules! error {
- ($span:expr, $msg:expr) => {
- syn::Error::new_spanned(&$span, $msg)
+macro_rules! format_err {
+ ($span:expr, $msg:expr $(,)?) => {
+ syn::Error::new_spanned(&$span as &dyn quote::ToTokens, &$msg as &dyn std::fmt::Display)
};
($span:expr, $($tt:tt)*) => {
- error!($span, format!($($tt)*))
+ format_err!($span, format!($($tt)*))
+ };
+}
+
+macro_rules! bail {
+ ($($tt:tt)*) => {
+ return Err(format_err!($($tt)*))
};
}
@@ -98,7 +104,11 @@ pub(crate) fn determine_visibility(vis: &Visibility) -> Visibility {
/// This is almost equivalent to `syn::parse2::<Nothing>()`, but produces
/// a better error message and does not require ownership of `tokens`.
pub(crate) fn parse_as_empty(tokens: &TokenStream) -> Result<()> {
- if tokens.is_empty() { Ok(()) } else { Err(error!(tokens, "unexpected token: {}", tokens)) }
+ if tokens.is_empty() {
+ Ok(())
+ } else {
+ bail!(tokens, "unexpected token: `{}`", tokens)
+ }
}
pub(crate) fn respan<T>(node: &T, span: Span) -> T
@@ -131,14 +141,14 @@ pub(crate) trait SliceExt {
impl SliceExt for [Attribute] {
/// # Errors
///
- /// * There are multiple specified attributes.
- /// * The `Attribute::tokens` field of the specified attribute is not empty.
+ /// - There are multiple specified attributes.
+ /// - The `Attribute::tokens` field of the specified attribute is not empty.
fn position_exact(&self, ident: &str) -> Result<Option<usize>> {
self.iter()
.try_fold((0, None), |(i, mut prev), attr| {
if attr.path.is_ident(ident) {
if prev.replace(i).is_some() {
- return Err(error!(attr, "duplicate #[{}] attribute", ident));
+ bail!(attr, "duplicate #[{}] attribute", ident);
}
parse_as_empty(&attr.tokens)?;
}