Skip to content

Commit

Permalink
Merge pull request #84 from alex/bump-syn
Browse files Browse the repository at this point in the history
Switch to syn 2.0
  • Loading branch information
someguynamedjosh committed Jun 15, 2023
2 parents b6bc986 + a7fffdd commit 51e80e9
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 23 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/default.yml
Expand Up @@ -14,15 +14,15 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
RUST: ["1.48", stable, beta, nightly]
RUST: ["1.56", stable, beta, nightly]
steps:
- uses: actions/checkout@v2
- name: Set Rust version
run: rustup default ${{ matrix.RUST }}
- name: Build
run: cargo build --verbose ${{ matrix.RUST != '1.48' && '--features=__tokio' || '' }}
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose ${{ matrix.RUST != '1.48' && '--features=__tokio' || '' }}
run: cargo test --verbose

no-std-test:
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions examples/Cargo.toml
Expand Up @@ -14,11 +14,10 @@ rustdoc-args = ["--document-private-items"]
[lib]

[features]
default = []
default = ["std"]
# Disables any tests that are not compatible or not intended to run under Miri
miri = []
std = []
__tokio = ["tokio", "std"]

[dependencies]
ouroboros = { version = "0.17.0", path = "../ouroboros" }
Expand All @@ -27,3 +26,4 @@ tokio = { version = "1.27.0", features = [ "macros", "rt" ], optional = true }
[dev-dependencies]
rustversion = "1.0.11"
trybuild = "=1.0.50"
tokio = { version = "1.25.0", features = [ "macros", "rt" ] }
6 changes: 3 additions & 3 deletions examples/src/ok_tests.rs
Expand Up @@ -90,7 +90,7 @@ fn box_and_ref() {

// Miri crashes with Pin<Box<Future>> types due to
// https://github.com/rust-lang/miri/issues/1038
#[cfg(all(not(feature = "miri"), feature = "tokio"))]
#[cfg(all(not(feature = "miri"), feature = "std"))]
#[tokio::test]
async fn async_new() {
use std::future::Future;
Expand All @@ -106,7 +106,7 @@ async fn async_new() {

// Miri crashes with Pin<Box<Future>> types due to
// https://github.com/rust-lang/miri/issues/1038
#[cfg(all(not(feature = "miri"), feature = "tokio"))]
#[cfg(all(not(feature = "miri"), feature = "std"))]
#[tokio::test]
async fn async_try_new() {
let bar = BoxAndRefAsyncTryBuilder {
Expand All @@ -122,7 +122,7 @@ async fn async_try_new() {

// Miri crashes with Pin<Box<Future>> types due to
// https://github.com/rust-lang/miri/issues/1038
#[cfg(all(not(feature = "miri"), feature = "tokio"))]
#[cfg(all(not(feature = "miri"), feature = "std"))]
#[tokio::test]
async fn async_try_new_err() {
let result = BoxAndRefAsyncTryBuilder {
Expand Down
2 changes: 1 addition & 1 deletion ouroboros_macro/Cargo.toml
Expand Up @@ -16,7 +16,7 @@ heck = "0.4.1"
proc-macro2 = "1.0"
proc-macro-error = "1.0.4"
quote = "1.0"
syn = { version = "1.0", features = ["full"] }
syn = { version = "2.0", features = ["full"] }

[features]
std = []
4 changes: 2 additions & 2 deletions ouroboros_macro/src/info_structures.rs
Expand Up @@ -3,7 +3,7 @@ use proc_macro2::{Ident, TokenStream};
use quote::{format_ident, quote, ToTokens};
use syn::{
punctuated::Punctuated, token::Comma, Attribute, ConstParam, Error, GenericParam, Generics,
LifetimeDef, Type, TypeParam, Visibility,
LifetimeParam, Type, TypeParam, Visibility,
};

#[derive(Clone, Copy)]
Expand Down Expand Up @@ -123,7 +123,7 @@ impl StructInfo {
Type(TypeParam { ident, .. }) | Const(ConstParam { ident, .. }) => {
ident.to_token_stream()
}
Lifetime(LifetimeDef { lifetime, .. }) => lifetime.to_token_stream(),
Lifetime(LifetimeParam { lifetime, .. }) => lifetime.to_token_stream(),
});
quote! { <'_, '_, #(#params,)*> }
}
Expand Down
7 changes: 5 additions & 2 deletions ouroboros_macro/src/lib.rs
Expand Up @@ -53,8 +53,11 @@ fn self_referencing_impl(
create_try_builder_and_constructor(&info, options, BuilderType::Sync)?;
let (async_try_builder_struct_name, async_try_builder_def, async_try_constructor_def) =
create_try_builder_and_constructor(&info, options, BuilderType::Async)?;
let (async_send_try_builder_struct_name, async_send_try_builder_def, async_send_try_constructor_def) =
create_try_builder_and_constructor(&info, options, BuilderType::AsyncSend)?;
let (
async_send_try_builder_struct_name,
async_send_try_builder_def,
async_send_try_constructor_def,
) = create_try_builder_and_constructor(&info, options, BuilderType::AsyncSend)?;

let with_defs = make_with_functions(&info, options)?;
let (with_all_struct_defs, with_all_fn_defs) = make_with_all_function(&info, options)?;
Expand Down
25 changes: 15 additions & 10 deletions ouroboros_macro/src/parse.rs
@@ -1,6 +1,6 @@
use proc_macro2::{Delimiter, Span, TokenTree};
use quote::format_ident;
use syn::{spanned::Spanned, Attribute, Error, Fields, GenericParam, ItemStruct};
use syn::{spanned::Spanned, Attribute, Error, Fields, GenericParam, ItemStruct, Meta};

use crate::{
covariance_detection::type_is_covariant_over_this_lifetime,
Expand All @@ -15,12 +15,14 @@ fn handle_borrows_attr(
) -> Result<(), Error> {
let mut borrow_mut = false;
let mut waiting_for_comma = false;
let tokens = attr.tokens.clone();
let possible_error = Error::new_spanned(&tokens, "Invalid syntax for borrows() macro.");
let tokens = if let Some(TokenTree::Group(group)) = tokens.into_iter().next() {
group.stream()
} else {
return Err(possible_error);
let tokens = match &attr.meta {
Meta::List(ml) => ml.tokens.clone(),
_ => {
return Err(Error::new_spanned(
&attr.meta,
"Invalid syntax for borrows() macro.",
))
}
};
for token in tokens {
if let TokenTree::Ident(ident) = token {
Expand Down Expand Up @@ -113,7 +115,10 @@ fn parse_derive_token(token: &TokenTree) -> Result<Option<Derive>, Error> {
}

fn parse_derive_attribute(attr: &Attribute) -> Result<Vec<Derive>, Error> {
let body = &attr.tokens;
let body = match &attr.meta {
Meta::List(ml) => &ml.tokens,
_ => unreachable!(),
};
if let Some(TokenTree::Group(body)) = body.clone().into_iter().next() {
if body.delimiter() != Delimiter::Parenthesis {
panic!("TODO: nice error, bad define syntax")
Expand Down Expand Up @@ -156,7 +161,7 @@ pub fn parse_struct(def: &ItemStruct) -> Result<StructInfo, Error> {
let mut covariant = type_is_covariant_over_this_lifetime(&field.ty);
let mut remove_attrs = Vec::new();
for (index, attr) in field.attrs.iter().enumerate() {
let path = &attr.path;
let path = &attr.path();
if path.leading_colon.is_some() {
continue;
}
Expand Down Expand Up @@ -246,7 +251,7 @@ pub fn parse_struct(def: &ItemStruct) -> Result<StructInfo, Error> {
let mut attributes = Vec::new();
let mut derives = Vec::new();
for attr in &def.attrs {
let p = &attr.path.segments;
let p = &attr.path().segments;
if p.len() == 0 {
return Err(Error::new(p.span(), &format!("Unsupported attribute")));
}
Expand Down

0 comments on commit 51e80e9

Please sign in to comment.