syntax: Enforce attribute grammar in the parser
This commit is contained in:
parent
a5733050de
commit
097c40cf6e
20 changed files with 128 additions and 55 deletions
|
|
@ -17,10 +17,7 @@
|
|||
#![feature(plugin)]
|
||||
#![plugin(macro_crate_test)]
|
||||
|
||||
#[noop_attribute"x"] //~ ERROR expected one of
|
||||
fn night() { }
|
||||
|
||||
#[noop_attribute("hi"), rank = 2] //~ ERROR unexpected token
|
||||
#[noop_attribute("hi", rank = a)] //~ ERROR expected unsuffixed literal or identifier, found a
|
||||
fn knight() { }
|
||||
|
||||
#[noop_attribute("/user", data= = "<user")] //~ ERROR literal or identifier
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ extern crate derive_b;
|
|||
#[C] //~ ERROR: The attribute `C` is currently unknown to the compiler
|
||||
#[B(D)]
|
||||
#[B(E = "foo")]
|
||||
#[B arbitrary tokens] //~ ERROR arbitrary tokens in non-macro attributes are unstable
|
||||
#[B(arbitrary tokens)] //~ ERROR expected one of `(`, `)`, `,`, `::`, or `=`, found `tokens`
|
||||
struct B;
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -41,12 +41,6 @@ mod _test2_inner {
|
|||
#[a = y] //~ ERROR: must only be followed by a delimiter token
|
||||
fn _test3() {}
|
||||
|
||||
#[a = ] //~ ERROR: must only be followed by a delimiter token
|
||||
fn _test4() {}
|
||||
|
||||
#[a () = ] //~ ERROR: must only be followed by a delimiter token
|
||||
fn _test5() {}
|
||||
|
||||
fn attrs() {
|
||||
// Statement, item
|
||||
#[a] // OK
|
||||
|
|
|
|||
12
src/test/parse-fail/attr-bad-meta-2.rs
Normal file
12
src/test/parse-fail/attr-bad-meta-2.rs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#[path =] //~ ERROR unexpected token: `]`
|
||||
mod m {}
|
||||
12
src/test/parse-fail/attr-bad-meta-3.rs
Normal file
12
src/test/parse-fail/attr-bad-meta-3.rs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#[path() token] //~ ERROR expected `]`, found `token`
|
||||
mod m {}
|
||||
|
|
@ -8,6 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// asterisk is bogus
|
||||
#[path*] //~ ERROR arbitrary tokens in non-macro attributes are unstable
|
||||
#![feature(unrestricted_attribute_tokens)]
|
||||
|
||||
#[path*] //~ ERROR expected one of `(`, `::`, `=`, `[`, `]`, or `{`, found `*`
|
||||
mod m {}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ use proc_macro::TokenStream;
|
|||
#[proc_macro_derive(B, attributes(B, C))]
|
||||
pub fn derive(input: TokenStream) -> TokenStream {
|
||||
let input = input.to_string();
|
||||
assert!(input.contains("#[B arbitrary tokens]"));
|
||||
assert!(input.contains("#[B [ arbitrary tokens ]]"));
|
||||
assert!(input.contains("struct B {"));
|
||||
assert!(input.contains("#[C]"));
|
||||
"".parse().unwrap()
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
extern crate derive_b;
|
||||
|
||||
#[derive(Debug, PartialEq, derive_b::B, Eq, Copy, Clone)]
|
||||
#[cfg_attr(all(), B arbitrary tokens)]
|
||||
#[cfg_attr(all(), B[arbitrary tokens])]
|
||||
struct B {
|
||||
#[C]
|
||||
a: u64
|
||||
|
|
|
|||
|
|
@ -17,6 +17,6 @@ extern crate attribute_spans_preserved as foo;
|
|||
use foo::foo;
|
||||
|
||||
#[ foo ( let y: u32 = "z"; ) ] //~ ERROR: mismatched types
|
||||
#[ bar let x: u32 = "y"; ] //~ ERROR: mismatched types
|
||||
#[ bar { let x: u32 = "y"; } ] //~ ERROR: mismatched types
|
||||
fn main() {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@ LL | #[ foo ( let y: u32 = "z"; ) ] //~ ERROR: mismatched types
|
|||
found type `&'static str`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/attribute-spans-preserved.rs:20:21
|
||||
--> $DIR/attribute-spans-preserved.rs:20:23
|
||||
|
|
||||
LL | #[ bar let x: u32 = "y"; ] //~ ERROR: mismatched types
|
||||
| ^^^ expected u32, found reference
|
||||
LL | #[ bar { let x: u32 = "y"; } ] //~ ERROR: mismatched types
|
||||
| ^^^ expected u32, found reference
|
||||
|
|
||||
= note: expected type `u32`
|
||||
found type `&'static str`
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
fn main ( ) { let y : u32 = "z" ; let x : u32 = "y" ; }
|
||||
fn main ( ) { let y : u32 = "z" ; { let x : u32 = "y" ; } }
|
||||
|
|
|
|||
16
src/test/ui/attr-eq-token-tree.rs
Normal file
16
src/test/ui/attr-eq-token-tree.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// compile-pass
|
||||
|
||||
#![feature(custom_attribute, unrestricted_attribute_tokens)]
|
||||
|
||||
#[my_attr = !] // OK under feature gate
|
||||
fn main() {}
|
||||
|
|
@ -8,5 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#[doc = $not_there] //~ ERROR arbitrary tokens in non-macro attributes are unstable
|
||||
#![feature(unrestricted_attribute_tokens)]
|
||||
|
||||
#[doc = $not_there] //~ ERROR expected `]`, found `not_there`
|
||||
fn main() { }
|
||||
|
|
|
|||
|
|
@ -1,11 +1,8 @@
|
|||
error[E0658]: arbitrary tokens in non-macro attributes are unstable (see issue #44690)
|
||||
--> $DIR/macro-attribute.rs:11:1
|
||||
error: expected `]`, found `not_there`
|
||||
--> $DIR/macro-attribute.rs:13:10
|
||||
|
|
||||
LL | #[doc = $not_there] //~ ERROR arbitrary tokens in non-macro attributes are unstable
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: add #![feature(unrestricted_attribute_tokens)] to the crate attributes to enable
|
||||
LL | #[doc = $not_there] //~ ERROR expected `]`, found `not_there`
|
||||
| ^^^^^^^^^ expected `]`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
|
|
|
|||
16
src/test/ui/unrestricted-attribute-tokens.rs
Normal file
16
src/test/ui/unrestricted-attribute-tokens.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// compile-pass
|
||||
|
||||
#![feature(custom_attribute, unrestricted_attribute_tokens)]
|
||||
|
||||
#[my_attr(a b c d)]
|
||||
fn main() {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue