Skip to content

Commit

Permalink
Update itertools to 0.12.0 and added .DS_Store to gitignore (#103)
Browse files Browse the repository at this point in the history
* Update itertools to 0.12.0 and added .DS_Store to gitignore

* Fixed a number of clippy suggestions

---------

Co-authored-by: kaitlin-smith <[email protected]>
Co-authored-by: someguynamedjosh <[email protected]>
  • Loading branch information
3 people authored Jan 21, 2024
1 parent b71fb15 commit 6542536
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 52 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target
Cargo.lock
scratch
.DS_Store
2 changes: 1 addition & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ tokio = { version = "1.27.0", features = [ "macros", "rt" ], optional = true }

[dev-dependencies]
rustversion = "1.0.11"
trybuild = "=1.0.50"
trybuild = "=1.0.85"
tokio = { version = "1.25.0", features = [ "macros", "rt" ] }
3 changes: 1 addition & 2 deletions examples/src/ok_tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alloc::{boxed::Box, borrow::ToOwned};
use alloc::{borrow::ToOwned, boxed::Box};
use core::fmt::Debug;

use ouroboros::self_referencing;
Expand Down Expand Up @@ -102,7 +102,6 @@ fn box_and_ref() {
#[cfg(all(not(feature = "miri"), feature = "std"))]
#[tokio::test]
async fn async_new() {
use std::future::Future;
let bar = BoxAndRefAsyncBuilder {
data: 12,
dref_builder: |data| Box::pin(async move { data }),
Expand Down
16 changes: 5 additions & 11 deletions ouroboros_macro/src/covariance_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ pub fn apparent_std_container_type(raw_type: &Type) -> Option<(&'static str, &Ty
} else {
return None;
};
let segment = if let Some(segment) = tpath.path.segments.last() {
segment
} else {
return None;
};
let segment = tpath.path.segments.last()?;
let args = if let PathArguments::AngleBracketed(args) = &segment.arguments {
args
} else {
Expand Down Expand Up @@ -49,7 +45,7 @@ pub fn type_is_covariant_over_this_lifetime(ty: &syn::Type) -> Option<bool> {
return Some(true);
}
match ty {
Array(arr) => type_is_covariant_over_this_lifetime(&*arr.elem),
Array(arr) => type_is_covariant_over_this_lifetime(&arr.elem),
BareFn(f) => {
debug_assert!(uses_this_lifetime(f.to_token_stream()));
None
Expand Down Expand Up @@ -80,13 +76,11 @@ pub fn type_is_covariant_over_this_lifetime(ty: &syn::Type) -> Option<bool> {
if !type_is_covariant_over_this_lifetime(ty)? {
return Some(false);
}
} else {
if uses_this_lifetime(ty.to_token_stream()) {
return None;
}
} else if uses_this_lifetime(ty.to_token_stream()) {
return None;
}
} else if let syn::GenericArgument::Lifetime(lt) = arg {
if lt.ident.to_string() == "this" && !all_parameters_are_covariant {
if lt.ident == "this" && !all_parameters_are_covariant {
return None;
}
}
Expand Down
10 changes: 5 additions & 5 deletions ouroboros_macro/src/generate/constructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ pub fn create_builder_and_constructor(
for field in &info.fields {
let field_name = &field.name;

let arg_type = field.make_constructor_arg_type(&info, builder_type)?;
let arg_type = field.make_constructor_arg_type(info, builder_type)?;
if let ArgType::Plain(plain_type) = arg_type {
// No fancy builder function, we can just move the value directly into the struct.
params.push(quote! { #field_name: #plain_type });
builder_struct_fields.push(quote! { #field_name: #plain_type });
builder_struct_field_names.push(quote! { #field_name });
doc_table += &format!(
"| `{}` | Directly pass in the value this field should contain |\n",
field_name.to_string()
field_name
);
} else if let ArgType::TraitBound(bound_type) = arg_type {
// Trait bounds are much trickier. We need a special syntax to accept them in the
Expand All @@ -85,22 +85,22 @@ pub fn create_builder_and_constructor(
params.push(quote! { #builder_name : impl #bound_type });
doc_table += &format!(
"| `{}` | Use a function or closure: `(",
builder_name.to_string()
builder_name
);
let mut builder_args = Vec::new();
for (index, borrow) in field.borrows.iter().enumerate() {
let borrowed_name = &info.fields[borrow.index].name;
builder_args.push(format_ident!("{}_illegal_static_reference", borrowed_name));
doc_table += &format!(
"{}: &{}_",
borrowed_name.to_string(),
borrowed_name,
if borrow.mutable { "mut " } else { "" },
);
if index < field.borrows.len() - 1 {
doc_table += ", ";
}
}
doc_table += &format!(") -> {}: _` | \n", field_name.to_string());
doc_table += &format!(") -> {}: _` | \n", field_name);
if builder_type.is_async() {
code.push(quote! { let #field_name = #builder_name (#(#builder_args),*).await; });
} else {
Expand Down
7 changes: 4 additions & 3 deletions ouroboros_macro/src/generate/derives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ use syn::{Error, GenericParam, TypeParamBound};

fn add_trait_bound(param: &GenericParam, bound: &TypeParamBound) -> GenericParam {
let mut new = param.clone();
match &mut new {
GenericParam::Type(t) => t.bounds.push(bound.clone()),
_ => (),

if let GenericParam::Type(t) = &mut new {
t.bounds.push(bound.clone())
}

new
}

Expand Down
2 changes: 1 addition & 1 deletion ouroboros_macro/src/generate/summon_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub fn generate_checker_summoner(info: &StructInfo) -> Result<TokenStream, Error
for field in &info.fields {
let field_name = &field.name;

let arg_type = field.make_constructor_arg_type(&info, BuilderType::Sync)?;
let arg_type = field.make_constructor_arg_type(info, BuilderType::Sync)?;
if let ArgType::Plain(plain_type) = arg_type {
// No fancy builder function, we can just move the value directly into the struct.
params.push(quote! { #field_name: #plain_type });
Expand Down
8 changes: 4 additions & 4 deletions ouroboros_macro/src/generate/try_constructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub fn create_try_builder_and_constructor(
builder_struct_field_names.push(quote! { #field_name });
doc_table += &format!(
"| `{}` | Directly pass in the value this field should contain |\n",
field_name.to_string()
field_name
);
if !field.self_referencing {
if field.is_borrowed() {
Expand All @@ -127,22 +127,22 @@ pub fn create_try_builder_and_constructor(
{}
doc_table += &format!(
"| `{}` | Use a function or closure: `(",
builder_name.to_string()
builder_name
);
let mut builder_args = Vec::new();
for (index, borrow) in field.borrows.iter().enumerate() {
let borrowed_name = &info.fields[borrow.index].name;
builder_args.push(format_ident!("{}_illegal_static_reference", borrowed_name));
doc_table += &format!(
"{}: &{}_",
borrowed_name.to_string(),
borrowed_name,
if borrow.mutable { "mut " } else { "" },
);
if index < field.borrows.len() - 1 {
doc_table += ", ";
}
}
doc_table += &format!(") -> Result<{}: _, Error_>` | \n", field_name.to_string());
doc_table += &format!(") -> Result<{}: _, Error_>` | \n", field_name);
let builder_value = if builder_type.is_async() {
quote! { #builder_name (#(#builder_args),*).await }
} else {
Expand Down
12 changes: 6 additions & 6 deletions ouroboros_macro/src/generate/with_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn make_with_all_mut_function(
&*this.#field_name
)
} };
let lt = Lifetime::new(&format!("'{}", lifetime.to_string()), Span::call_site());
let lt = Lifetime::new(&format!("'{}", lifetime), Span::call_site());
mut_fields.push(quote! { #visibility #field_name: &#lt #field_type });
mut_field_assignments.push(ass);
} else if field.field_type == FieldType::BorrowedMut {
Expand All @@ -53,14 +53,14 @@ pub fn make_with_all_mut_function(

let mut new_generic_params = info.generic_params().clone();
for lt in &lifetime_idents {
let lt = Lifetime::new(&format!("'{}", lt.to_string()), Span::call_site());
let lt = Lifetime::new(&format!("'{}", lt), Span::call_site());
new_generic_params.insert(0, syn::parse_quote! { #lt });
}
new_generic_params.insert(0, syn::parse_quote! { 'outer_borrow });
let mut new_generic_args = info.generic_arguments();
let mut lifetimes = Vec::new();
for lt in &lifetime_idents {
let lt = Lifetime::new(&format!("'{}", lt.to_string()), Span::call_site());
let lt = Lifetime::new(&format!("'{}", lt), Span::call_site());
lifetimes.push(lt.clone());
new_generic_args.insert(0, quote! { #lt });
}
Expand All @@ -81,15 +81,15 @@ pub fn make_with_all_mut_function(
syn::parse_quote! { where }
};
for lt in &lifetime_idents {
let lt = Lifetime::new(&format!("'{}", lt.to_string()), Span::call_site());
let lt = Lifetime::new(&format!("'{}", lt), Span::call_site());
let extra: WhereClause = syn::parse_quote! { where #fake_lifetime: #lt };
generic_where
.predicates
.extend(extra.predicates.into_iter());
}
for (outlives, lt) in lifetime_idents.iter().tuple_windows() {
let lt = Lifetime::new(&format!("'{}", lt.to_string()), Span::call_site());
let outlives = Lifetime::new(&format!("'{}", outlives.to_string()), Span::call_site());
let lt = Lifetime::new(&format!("'{}", lt), Span::call_site());
let outlives = Lifetime::new(&format!("'{}", outlives), Span::call_site());
let extra: WhereClause = syn::parse_quote! { where #lt: #outlives };
generic_where
.predicates
Expand Down
7 changes: 2 additions & 5 deletions ouroboros_macro/src/info_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ pub enum BuilderType {

impl BuilderType {
pub fn is_async(&self) -> bool {
match self {
BuilderType::Sync => false,
_ => true,
}
!matches!(self, BuilderType::Sync)
}
}

Expand All @@ -84,7 +81,7 @@ impl StructInfo {
// The lifetime to use in place of 'this for internal implementations,
// should never be exposed to the user.
pub fn fake_lifetime(&self) -> Ident {
return self.first_lifetime.clone();
self.first_lifetime.clone()
}

pub fn generic_params(&self) -> &Punctuated<GenericParam, Comma> {
Expand Down
2 changes: 1 addition & 1 deletion ouroboros_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ pub fn self_referencing(attr: TokenStream, item: TokenStream) -> TokenStream {
"pub_extras" => options.do_pub_extras = true,
_ => {
return Error::new_spanned(
&ident,
ident,
"Unknown identifier, expected 'no_doc' or 'pub_extras'.",
)
.to_compile_error()
Expand Down
21 changes: 9 additions & 12 deletions ouroboros_macro/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ fn parse_derive_attribute(attr: &Attribute) -> Result<Vec<Derive>, Error> {
attr.span(),
format!(
"malformed derive input, derive attributes are of the form `#[derive({})]`",
body.tokens.to_string()
body.tokens
),
));
}
Expand Down Expand Up @@ -226,7 +226,7 @@ pub fn parse_struct(def: &ItemStruct) -> Result<StructInfo, Error> {
if !has_non_tail {
return Err(Error::new(
Span::call_site(),
&format!(
format!(
concat!(
"Self-referencing struct cannot be made entirely of tail fields, try adding ",
"#[borrows({0})] to a field defined after {0}."
Expand All @@ -244,18 +244,15 @@ pub fn parse_struct(def: &ItemStruct) -> Result<StructInfo, Error> {
let mut derives = Vec::new();
for attr in &def.attrs {
let p = &attr.path().segments;
if p.len() == 0 {
return Err(Error::new(p.span(), &format!("Unsupported attribute")));
if p.is_empty() {
return Err(Error::new(p.span(), "Unsupported attribute".to_string()));
}
let name = p[0].ident.to_string();
let good = match &name[..] {
"clippy" | "allow" | "deny" | "doc" => true,
_ => false,
};
let good = matches!(&name[..], "clippy" | "allow" | "deny" | "doc");
if good {
attributes.push(attr.clone())
} else if name == "derive" {
if derives.len() > 0 {
if !derives.is_empty() {
return Err(Error::new(
attr.span(),
"Multiple derive attributes not allowed",
Expand All @@ -264,11 +261,11 @@ pub fn parse_struct(def: &ItemStruct) -> Result<StructInfo, Error> {
derives = parse_derive_attribute(attr)?;
}
} else {
return Err(Error::new(p.span(), &format!("Unsupported attribute")));
return Err(Error::new(p.span(), "Unsupported attribute".to_string()));
}
}

return Ok(StructInfo {
Ok(StructInfo {
derives,
ident: def.ident.clone(),
internal_ident: format_ident!("{}Internal", def.ident),
Expand All @@ -277,5 +274,5 @@ pub fn parse_struct(def: &ItemStruct) -> Result<StructInfo, Error> {
vis,
first_lifetime,
attributes,
});
})
}
1 change: 0 additions & 1 deletion ouroboros_macro/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ pub fn submodule_contents_visibility(original_visibility: &Visibility) -> Visibi
new_visibility.in_token = Some(
restricted
.in_token
.clone()
.unwrap_or_else(|| syn::parse_quote! { in }),
);
new_visibility.path.segments = std::iter::once(syn::parse_quote! { super })
Expand Down

0 comments on commit 6542536

Please sign in to comment.