-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
59cdb9c
commit 9c4db7b
Showing
10 changed files
with
112 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "ouroboros_examples" | ||
version = "0.12.0" | ||
version = "0.13.0" | ||
authors = ["Joshua Maros <[email protected]>"] | ||
edition = "2018" | ||
license = "MIT OR Apache-2.0" | ||
|
@@ -19,7 +19,7 @@ default = [] | |
miri = [] | ||
|
||
[dependencies] | ||
ouroboros = { version = "0.12.0", path = "../ouroboros" } | ||
ouroboros = { version = "0.13.0", path = "../ouroboros" } | ||
stable_deref_trait = "1.2" | ||
|
||
[dev-dependencies] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "ouroboros" | ||
version = "0.12.0" | ||
version = "0.13.0" | ||
authors = ["Joshua Maros <[email protected]>"] | ||
edition = "2018" | ||
license = "MIT OR Apache-2.0" | ||
|
@@ -11,5 +11,5 @@ repository = "https://github.com/joshua-maros/ouroboros" | |
|
||
[dependencies] | ||
aliasable = "0.1.3" | ||
ouroboros_macro = { version = "0.12.0", path = "../ouroboros_macro" } | ||
ouroboros_macro = { version = "0.13.0", path = "../ouroboros_macro" } | ||
stable_deref_trait = "1.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "ouroboros_macro" | ||
version = "0.12.0" | ||
version = "0.13.0" | ||
authors = ["Joshua Maros <[email protected]>"] | ||
edition = "2018" | ||
license = "MIT OR Apache-2.0" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use proc_macro2::TokenStream; | ||
use quote::quote; | ||
use syn::Error; | ||
|
||
use crate::info_structures::{ArgType, StructInfo}; | ||
|
||
pub fn generate_borrowchk_summoner(info: &StructInfo) -> Result<TokenStream, Error> { | ||
let mut code: Vec<TokenStream> = Vec::new(); | ||
let mut params: Vec<TokenStream> = Vec::new(); | ||
let mut value_consumers: Vec<TokenStream> = Vec::new(); | ||
let mut template_consumers: Vec<TokenStream> = Vec::new(); | ||
for field in &info.fields { | ||
let field_name = &field.name; | ||
|
||
let arg_type = field.make_constructor_arg_type(&info, false)?; | ||
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 }); | ||
} else if let ArgType::TraitBound(bound_type) = arg_type { | ||
// Trait bounds are much trickier. We need a special syntax to accept them in the | ||
// contructor, and generic parameters need to be added to the builder struct to make | ||
// it work. | ||
let builder_name = field.builder_name(); | ||
params.push(quote! { #builder_name : impl #bound_type }); | ||
let mut builder_args = Vec::new(); | ||
for (_, borrow) in field.borrows.iter().enumerate() { | ||
let borrowed_name = &info.fields[borrow.index].name; | ||
builder_args.push(quote! { &#borrowed_name }); | ||
} | ||
code.push(quote! { let #field_name = #builder_name (#(#builder_args),*); }); | ||
} | ||
if field.is_borrowed() { | ||
let boxed = quote! { ::ouroboros::macro_help::aliasable_boxed(#field_name) }; | ||
code.push(quote! { let #field_name = #boxed; }); | ||
}; | ||
if !field.is_mutably_borrowed() { | ||
value_consumers.push(quote! { #field_name: &#field_name }); | ||
} | ||
} | ||
for (_ty, ident) in info.generic_consumers() { | ||
template_consumers.push(quote! { #ident: ::core::marker::PhantomData }); | ||
} | ||
let generic_params = info.generic_params(); | ||
Ok(quote! { | ||
fn check_if_okay_according_to_borrow_checker<#generic_params>( | ||
#(#params,)* | ||
) { | ||
#(#code;)* | ||
BorrowedFields { | ||
#(#value_consumers,)* | ||
#(#template_consumers,)* | ||
}; | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters