diff options
| author | bors <bors@rust-lang.org> | 2019-01-16 15:01:20 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-01-16 15:01:20 +0000 |
| commit | ceb2512144d1fc26330e85fb9d41c22ba1866259 (patch) | |
| tree | 698f2e468d5964e3e7368af3c48e706d035df6da /src/libsyntax_ext | |
| parent | cccaf9a8c69219c8267e406f92fef895fbba80f2 (diff) | |
| parent | d3411d3ee8a350e2b8ec202a4a493e69c827245c (diff) | |
| download | rust-ceb2512144d1fc26330e85fb9d41c22ba1866259.tar.gz rust-ceb2512144d1fc26330e85fb9d41c22ba1866259.zip | |
Auto merge of #57321 - petrochenkov:atokens, r=nikomatsakis
Implement basic input validation for built-in attributes Correct top-level shape (`#[attr]` vs `#[attr(...)]` vs `#[attr = ...]`) is enforced for built-in attributes, built-in attributes must also fit into the "meta-item" syntax (aka the "classic attribute syntax"). For some subset of attributes (found by crater run), errors are lowered to deprecation warnings. NOTE: This PR previously included https://github.com/rust-lang/rust/pull/57367 as well.
Diffstat (limited to 'src/libsyntax_ext')
| -rw-r--r-- | src/libsyntax_ext/proc_macro_decls.rs | 27 | ||||
| -rw-r--r-- | src/libsyntax_ext/test.rs | 16 |
2 files changed, 8 insertions, 35 deletions
diff --git a/src/libsyntax_ext/proc_macro_decls.rs b/src/libsyntax_ext/proc_macro_decls.rs index 38f7ca500b2..1d272712cac 100644 --- a/src/libsyntax_ext/proc_macro_decls.rs +++ b/src/libsyntax_ext/proc_macro_decls.rs @@ -105,12 +105,7 @@ impl<'a> CollectProcMacros<'a> { // `#[proc_macro_derive(Foo, attributes(A, ..))]` let list = match attr.meta_item_list() { Some(list) => list, - None => { - self.handler.span_err(attr.span(), - "attribute must be of form: \ - #[proc_macro_derive(TraitName)]"); - return - } + None => return, }; if list.len() != 1 && list.len() != 2 { self.handler.span_err(attr.span(), @@ -182,13 +177,7 @@ impl<'a> CollectProcMacros<'a> { } } - fn collect_attr_proc_macro(&mut self, item: &'a ast::Item, attr: &'a ast::Attribute) { - if !attr.is_word() { - self.handler.span_err(attr.span, "`#[proc_macro_attribute]` attribute \ - does not take any arguments"); - return; - } - + fn collect_attr_proc_macro(&mut self, item: &'a ast::Item) { if self.in_root && item.vis.node.is_pub() { self.attr_macros.push(ProcMacroDef { span: item.span, @@ -205,13 +194,7 @@ impl<'a> CollectProcMacros<'a> { } } - fn collect_bang_proc_macro(&mut self, item: &'a ast::Item, attr: &'a ast::Attribute) { - if !attr.is_word() { - self.handler.span_err(attr.span, "`#[proc_macro]` attribute \ - does not take any arguments"); - return; - } - + fn collect_bang_proc_macro(&mut self, item: &'a ast::Item) { if self.in_root && item.vis.node.is_pub() { self.bang_macros.push(ProcMacroDef { span: item.span, @@ -308,9 +291,9 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> { if attr.check_name("proc_macro_derive") { self.collect_custom_derive(item, attr); } else if attr.check_name("proc_macro_attribute") { - self.collect_attr_proc_macro(item, attr); + self.collect_attr_proc_macro(item); } else if attr.check_name("proc_macro") { - self.collect_bang_proc_macro(item, attr); + self.collect_bang_proc_macro(item); }; let prev_in_root = mem::replace(&mut self.in_root, false); diff --git a/src/libsyntax_ext/test.rs b/src/libsyntax_ext/test.rs index a19d0458edd..11c734b299c 100644 --- a/src/libsyntax_ext/test.rs +++ b/src/libsyntax_ext/test.rs @@ -214,20 +214,8 @@ fn should_panic(cx: &ExtCtxt, i: &ast::Item) -> ShouldPanic { match attr::find_by_name(&i.attrs, "should_panic") { Some(attr) => { let ref sd = cx.parse_sess.span_diagnostic; - if attr.is_value_str() { - sd.struct_span_warn( - attr.span(), - "attribute must be of the form: \ - `#[should_panic]` or \ - `#[should_panic(expected = \"error message\")]`" - ).note("Errors in this attribute were erroneously allowed \ - and will become a hard error in a future release.") - .emit(); - return ShouldPanic::Yes(None); - } + match attr.meta_item_list() { - // Handle #[should_panic] - None => ShouldPanic::Yes(None), // Handle #[should_panic(expected = "foo")] Some(list) => { let msg = list.iter() @@ -247,6 +235,8 @@ fn should_panic(cx: &ExtCtxt, i: &ast::Item) -> ShouldPanic { ShouldPanic::Yes(msg) } }, + // Handle #[should_panic] and #[should_panic = "expected"] + None => ShouldPanic::Yes(attr.value_str()) } } None => ShouldPanic::No, |
