Enforce public visibility of all fields of structs deriving Outgoing

This commit is contained in:
Devin Ragotzy 2020-10-03 05:39:32 -04:00 committed by GitHub
parent 8049631827
commit b3196d7f64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 6 deletions

View File

@ -12,10 +12,10 @@ ruma_api! {
request: {
#[ruma_api(header = LOCATION)]
location: Option<String>,
pub location: Option<String>,
}
response: {
#[ruma_api(header = LOCATION)]
stuff: Option<String>,
pub stuff: Option<String>,
}
}

View File

@ -1,8 +1,8 @@
#[allow(unused)]
#[derive(Copy, Clone, Debug, ruma_common::Outgoing, serde::Serialize)]
pub struct OtherThing<'t> {
some: &'t str,
t: &'t [u8],
pub some: &'t str,
pub t: &'t [u8],
}
mod empty_response {

View File

@ -106,6 +106,9 @@ pub fn expand_derive_outgoing(input: DeriveInput) -> syn::Result<TokenStream> {
DataKind::Struct(mut fields, struct_kind) => {
let mut found_lifetime = false;
for field in &mut fields {
if !matches!(field.vis, syn::Visibility::Public(_)) {
return Err(syn::Error::new_spanned(field, "All fields must be marked `pub`"));
}
if strip_lifetimes(&mut field.ty) {
found_lifetime = true;
}

View File

@ -16,8 +16,8 @@ pub struct IncomingThing<T> {
#[allow(unused)]
#[derive(Copy, Clone, Debug, Outgoing, serde::Serialize)]
pub struct OtherThing<'t> {
some: &'t str,
t: &'t [u8],
pub some: &'t str,
pub t: &'t [u8],
}
#[derive(Outgoing)]