Use a binding's field identifier to produce more descriptive output. Fall back to a binding's identifier if a field identifier is not available. Additionally, make the privatize.rs compiletest more specific and wrap the identifier in backticks to aid readability. As an aside, should I send a PR to rename ```compile-fail/privatize.rs``` to ```compile-fail/deny_public_fields.rs``` as privatize isn't mentioned in the codebase any more? ``` $ find . -name "*privatize*" ./tests/compiletest/plugin/compile-fail/privatize.rs ``` --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #17438 (github issue number if applicable). <!-- Either: --> - [x] There are tests for these changes <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 3f2d7476890bffdaad6fdc0e66aa7ac7bc995a87
28 lines
923 B
Rust
28 lines
923 B
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
extern crate proc_macro;
|
|
extern crate syn;
|
|
extern crate synstructure;
|
|
|
|
#[proc_macro_derive(DenyPublicFields)]
|
|
pub fn expand_token_stream(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
|
expand_string(&input.to_string()).parse().unwrap()
|
|
}
|
|
|
|
fn expand_string(input: &str) -> String {
|
|
let type_ = syn::parse_macro_input(input).unwrap();
|
|
|
|
let style = synstructure::BindStyle::Ref.into();
|
|
synstructure::each_field(&type_, &style, |binding| {
|
|
if binding.field.vis != syn::Visibility::Inherited {
|
|
panic!("Field `{}` should not be public",
|
|
binding.field.ident.as_ref().unwrap_or(&binding.ident));
|
|
}
|
|
"".to_owned()
|
|
});
|
|
|
|
"".to_owned()
|
|
}
|