+++ /dev/null
-// 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.
-
-// aux-build:attr-stmt-expr.rs
-
-//! Attributes producing expressions in invalid locations
-
-#![feature(stmt_expr_attributes, proc_macro_hygiene)]
-
-extern crate attr_stmt_expr;
-use attr_stmt_expr::{duplicate, no_output};
-
-fn main() {
- let _ = #[no_output] "Hello, world!";
- //~^ ERROR expected expression, found `<eof>`
-
- let _ = #[duplicate] "Hello, world!";
- //~^ ERROR macro expansion ignores token `,` and any following
-
- let _ = {
- #[no_output]
- "Hello, world!"
- };
-
- let _ = {
- #[duplicate]
- //~^ ERROR macro expansion ignores token `,` and any following
- "Hello, world!"
- };
-}
+++ /dev/null
-// 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.
-
-// aux-build:attr-stmt-expr.rs
-
-#![feature(proc_macro_hygiene)]
-
-extern crate attr_stmt_expr;
-use attr_stmt_expr::{expect_let, expect_print_stmt, expect_expr, expect_print_expr};
-
-fn print_str(string: &'static str) {
- // macros are handled a bit differently
- #[expect_print_expr]
- //~^ ERROR attributes on expressions are experimental
- //~| HELP add #![feature(stmt_expr_attributes)] to the crate attributes to enable
- println!("{}", string)
-}
-
-fn main() {
- #[expect_let]
- let string = "Hello, world!";
-
- #[expect_print_stmt]
- println!("{}", string);
-
- #[expect_expr]
- //~^ ERROR attributes on expressions are experimental
- //~| HELP add #![feature(stmt_expr_attributes)] to the crate attributes to enable
- print_str("string")
-}
+++ /dev/null
-// Copyright 2017 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.
-
-// aux-build:attribute-with-error.rs
-
-#![feature(custom_inner_attributes)]
-
-extern crate attribute_with_error;
-
-use attribute_with_error::foo;
-
-#[foo]
-fn test1() {
- let a: i32 = "foo";
- //~^ ERROR: mismatched types
- let b: i32 = "f'oo";
- //~^ ERROR: mismatched types
-}
-
-fn test2() {
- #![foo]
-
- // FIXME: should have a type error here and assert it works but it doesn't
-}
-
-trait A {
- // FIXME: should have a #[foo] attribute here and assert that it works
- fn foo(&self) {
- let a: i32 = "foo";
- //~^ ERROR: mismatched types
- }
-}
-
-struct B;
-
-impl A for B {
- #[foo]
- fn foo(&self) {
- let a: i32 = "foo";
- //~^ ERROR: mismatched types
- }
-}
-
-#[foo]
-fn main() {
-}
+++ /dev/null
-// Copyright 2016 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.
-
-// force-host
-// no-prefer-dynamic
-
-#![crate_type = "proc-macro"]
-
-extern crate proc_macro;
-
-#[proc_macro_derive]
-//~^ ERROR: attribute must be of form: #[proc_macro_derive(TraitName)]
-pub fn foo1(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
- input
-}
-
-#[proc_macro_derive = "foo"]
-//~^ ERROR: attribute must be of form: #[proc_macro_derive(TraitName)]
-pub fn foo2(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
- input
-}
-
-#[proc_macro_derive(
- a = "b"
-)]
-//~^^ ERROR: must only be one word
-pub fn foo3(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
- input
-}
-
-#[proc_macro_derive(b, c, d)]
-//~^ ERROR: attribute must have either one or two arguments
-pub fn foo4(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
- input
-}
-
-#[proc_macro_derive(d(e))]
-//~^ ERROR: must only be one word
-pub fn foo5(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
- input
-}
-
-#[proc_macro_derive(f, attributes(g = "h"))]
-//~^ ERROR: must only be one word
-pub fn foo6(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
- input
-}
-
-#[proc_macro_derive(i, attributes(j(k)))]
-//~^ ERROR: must only be one word
-pub fn foo7(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
- input
-}
-
-#[proc_macro_derive(l, attributes(m), n)]
-//~^ ERROR: attribute must have either one or two arguments
-pub fn foo8(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
- input
-}
+++ /dev/null
-// Copyright 2017 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.
-
-// aux-build:attributes-included.rs
-// compile-pass
-
-#![warn(unused)]
-
-extern crate attributes_included;
-
-use attributes_included::*;
-
-#[bar]
-#[inline]
-/// doc
-#[foo]
-#[inline]
-/// doc
-fn foo() {
- let a: i32 = "foo"; //~ WARN: unused variable
-}
-
-fn main() {
- foo()
-}
+++ /dev/null
-// 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.
-
-// force-host
-// no-prefer-dynamic
-
-#![crate_type = "proc-macro"]
-
-extern crate proc_macro;
-
-use proc_macro::TokenStream;
-
-#[proc_macro_attribute]
-pub fn expect_let(attr: TokenStream, item: TokenStream) -> TokenStream {
- assert!(attr.to_string().is_empty());
- assert_eq!(item.to_string(), "let string = \"Hello, world!\";");
- item
-}
-
-#[proc_macro_attribute]
-pub fn expect_print_stmt(attr: TokenStream, item: TokenStream) -> TokenStream {
- assert!(attr.to_string().is_empty());
- assert_eq!(item.to_string(), "println!(\"{}\" , string);");
- item
-}
-
-#[proc_macro_attribute]
-pub fn expect_expr(attr: TokenStream, item: TokenStream) -> TokenStream {
- assert!(attr.to_string().is_empty());
- assert_eq!(item.to_string(), "print_str(\"string\")");
- item
-}
-
-#[proc_macro_attribute]
-pub fn expect_print_expr(attr: TokenStream, item: TokenStream) -> TokenStream {
- assert!(attr.to_string().is_empty());
- assert_eq!(item.to_string(), "println!(\"{}\" , string)");
- item
-}
-
-#[proc_macro_attribute]
-pub fn duplicate(attr: TokenStream, item: TokenStream) -> TokenStream {
- assert!(attr.to_string().is_empty());
- format!("{}, {}", item, item).parse().unwrap()
-}
-
-#[proc_macro_attribute]
-pub fn no_output(attr: TokenStream, item: TokenStream) -> TokenStream {
- assert!(attr.to_string().is_empty());
- assert!(!item.to_string().is_empty());
- "".parse().unwrap()
-}
+++ /dev/null
-// Copyright 2017 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.
-
-// force-host
-// no-prefer-dynamic
-
-#![crate_type = "proc-macro"]
-
-extern crate proc_macro;
-
-use proc_macro::TokenStream;
-
-#[proc_macro_attribute]
-pub fn foo(_attr: TokenStream, input: TokenStream) -> TokenStream {
- input.into_iter().collect()
-}
+++ /dev/null
-// Copyright 2017 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.
-
-// force-host
-// no-prefer-dynamic
-
-#![crate_type = "proc-macro"]
-
-extern crate proc_macro;
-
-use proc_macro::{TokenStream, TokenTree, Delimiter, Literal, Spacing, Group};
-
-#[proc_macro_attribute]
-pub fn foo(attr: TokenStream, input: TokenStream) -> TokenStream {
- assert!(attr.is_empty());
- let input = input.into_iter().collect::<Vec<_>>();
- {
- let mut cursor = &input[..];
- assert_inline(&mut cursor);
- assert_doc(&mut cursor);
- assert_inline(&mut cursor);
- assert_doc(&mut cursor);
- assert_foo(&mut cursor);
- assert!(cursor.is_empty());
- }
- fold_stream(input.into_iter().collect())
-}
-
-#[proc_macro_attribute]
-pub fn bar(attr: TokenStream, input: TokenStream) -> TokenStream {
- assert!(attr.is_empty());
- let input = input.into_iter().collect::<Vec<_>>();
- {
- let mut cursor = &input[..];
- assert_inline(&mut cursor);
- assert_doc(&mut cursor);
- assert_invoc(&mut cursor);
- assert_inline(&mut cursor);
- assert_doc(&mut cursor);
- assert_foo(&mut cursor);
- assert!(cursor.is_empty());
- }
- input.into_iter().collect()
-}
-
-fn assert_inline(slice: &mut &[TokenTree]) {
- match &slice[0] {
- TokenTree::Punct(tt) => assert_eq!(tt.as_char(), '#'),
- _ => panic!("expected '#' char"),
- }
- match &slice[1] {
- TokenTree::Group(tt) => assert_eq!(tt.delimiter(), Delimiter::Bracket),
- _ => panic!("expected brackets"),
- }
- *slice = &slice[2..];
-}
-
-fn assert_doc(slice: &mut &[TokenTree]) {
- match &slice[0] {
- TokenTree::Punct(tt) => {
- assert_eq!(tt.as_char(), '#');
- assert_eq!(tt.spacing(), Spacing::Alone);
- }
- _ => panic!("expected #"),
- }
- let inner = match &slice[1] {
- TokenTree::Group(tt) => {
- assert_eq!(tt.delimiter(), Delimiter::Bracket);
- tt.stream()
- }
- _ => panic!("expected brackets"),
- };
- let tokens = inner.into_iter().collect::<Vec<_>>();
- let tokens = &tokens[..];
-
- if tokens.len() != 3 {
- panic!("expected three tokens in doc")
- }
-
- match &tokens[0] {
- TokenTree::Ident(tt) => assert_eq!("doc", &*tt.to_string()),
- _ => panic!("expected `doc`"),
- }
- match &tokens[1] {
- TokenTree::Punct(tt) => {
- assert_eq!(tt.as_char(), '=');
- assert_eq!(tt.spacing(), Spacing::Alone);
- }
- _ => panic!("expected equals"),
- }
- match tokens[2] {
- TokenTree::Literal(_) => {}
- _ => panic!("expected literal"),
- }
-
- *slice = &slice[2..];
-}
-
-fn assert_invoc(slice: &mut &[TokenTree]) {
- match &slice[0] {
- TokenTree::Punct(tt) => assert_eq!(tt.as_char(), '#'),
- _ => panic!("expected '#' char"),
- }
- match &slice[1] {
- TokenTree::Group(tt) => assert_eq!(tt.delimiter(), Delimiter::Bracket),
- _ => panic!("expected brackets"),
- }
- *slice = &slice[2..];
-}
-
-fn assert_foo(slice: &mut &[TokenTree]) {
- match &slice[0] {
- TokenTree::Ident(tt) => assert_eq!(&*tt.to_string(), "fn"),
- _ => panic!("expected fn"),
- }
- match &slice[1] {
- TokenTree::Ident(tt) => assert_eq!(&*tt.to_string(), "foo"),
- _ => panic!("expected foo"),
- }
- match &slice[2] {
- TokenTree::Group(tt) => {
- assert_eq!(tt.delimiter(), Delimiter::Parenthesis);
- assert!(tt.stream().is_empty());
- }
- _ => panic!("expected parens"),
- }
- match &slice[3] {
- TokenTree::Group(tt) => assert_eq!(tt.delimiter(), Delimiter::Brace),
- _ => panic!("expected braces"),
- }
- *slice = &slice[4..];
-}
-
-fn fold_stream(input: TokenStream) -> TokenStream {
- input.into_iter().map(fold_tree).collect()
-}
-
-fn fold_tree(input: TokenTree) -> TokenTree {
- match input {
- TokenTree::Group(b) => {
- TokenTree::Group(Group::new(b.delimiter(), fold_stream(b.stream())))
- }
- TokenTree::Punct(b) => TokenTree::Punct(b),
- TokenTree::Ident(a) => TokenTree::Ident(a),
- TokenTree::Literal(a) => {
- if a.to_string() != "\"foo\"" {
- TokenTree::Literal(a)
- } else {
- TokenTree::Literal(Literal::i32_unsuffixed(3))
- }
- }
- }
-}
+++ /dev/null
-// Copyright 2016 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.
-
-// force-host
-// no-prefer-dynamic
-
-#![crate_type = "proc-macro"]
-
-extern crate proc_macro;
-
-use proc_macro::TokenStream;
-
-#[proc_macro]
-pub fn bang_proc_macro2(_: TokenStream) -> TokenStream {
- "let x = foobar2;".parse().unwrap()
-}
+++ /dev/null
-// Copyright 2016 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.
-
-// force-host
-// no-prefer-dynamic
-
-#![crate_type = "proc-macro"]
-
-extern crate proc_macro;
-use proc_macro::TokenStream;
-
-#[proc_macro_derive(A)]
-pub fn derive_a(_: TokenStream) -> TokenStream {
- "".parse().unwrap()
-}
-
-#[proc_macro_derive(B)]
-pub fn derive_b(_: TokenStream) -> TokenStream {
- "".parse().unwrap()
-}
+++ /dev/null
-// Copyright 2016 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.
-
-// force-host
-// no-prefer-dynamic
-
-#![crate_type = "proc-macro"]
-
-extern crate proc_macro;
-
-use proc_macro::TokenStream;
-
-#[proc_macro_derive(A)]
-pub fn derive_a(input: TokenStream) -> TokenStream {
- "".parse().unwrap()
-}
+++ /dev/null
-// Copyright 2016 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.
-
-// force-host
-// no-prefer-dynamic
-
-#![crate_type = "proc-macro"]
-
-extern crate proc_macro;
-
-use proc_macro::TokenStream;
-
-#[proc_macro_derive(B, attributes(B))]
-pub fn derive_b(input: TokenStream) -> TokenStream {
- "".parse().unwrap()
-}
+++ /dev/null
-// Copyright 2016 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.
-
-// force-host
-// no-prefer-dynamic
-
-#![crate_type = "proc-macro"]
-
-extern crate proc_macro;
-
-use proc_macro::TokenStream;
-
-#[proc_macro_derive(A)]
-pub fn derive_a(_input: TokenStream) -> TokenStream {
- "struct A { inner }".parse().unwrap()
-}
-
+++ /dev/null
-// Copyright 2016 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.
-
-// force-host
-// no-prefer-dynamic
-
-#![crate_type = "proc-macro"]
-
-extern crate proc_macro;
-
-use proc_macro::TokenStream;
-
-#[proc_macro_derive(Clona)]
-pub fn derive_clonea(input: TokenStream) -> TokenStream {
- "".parse().unwrap()
-}
+++ /dev/null
-// Copyright 2016 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.
-
-// force-host
-// no-prefer-dynamic
-
-#![crate_type = "proc-macro"]
-
-extern crate proc_macro;
-
-use proc_macro::TokenStream;
-
-#[proc_macro_derive(FooWithLongName)]
-pub fn derive_foo(input: TokenStream) -> TokenStream {
- "".parse().unwrap()
-}
+++ /dev/null
-// Copyright 2016 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.
-
-// force-host
-// no-prefer-dynamic
-
-#![crate_type = "proc-macro"]
-
-extern crate proc_macro;
-
-use proc_macro::TokenStream;
-
-#[proc_macro_derive(Unstable)]
-pub fn derive(_input: TokenStream) -> TokenStream {
-
- "
- #[rustc_foo]
- fn foo() {}
- ".parse().unwrap()
-}
+++ /dev/null
-// Copyright 2016 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.
-
-// force-host
-// no-prefer-dynamic
-
-#![crate_type = "proc-macro"]
-
-extern crate proc_macro;
-
-use proc_macro::TokenStream;
-
-#[proc_macro_derive(Unstable)]
-pub fn derive(_input: TokenStream) -> TokenStream {
-
- "unsafe fn foo() -> u32 { ::std::intrinsics::init() }".parse().unwrap()
-}
+++ /dev/null
-// Copyright 2017 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.
-
-// force-host
-// no-prefer-dynamic
-
-#![crate_type = "proc-macro"]
-
-extern crate proc_macro;
-use proc_macro::TokenStream;
-
-#[proc_macro_attribute]
-pub fn emit_unchanged(_args: TokenStream, input: TokenStream) -> TokenStream {
- input
-}
+++ /dev/null
-// Copyright 2016 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.
-
-// force-host
-// no-prefer-dynamic
-
-#![crate_type = "proc-macro"]
-
-extern crate proc_macro;
-
-#[proc_macro_derive(A)]
-pub fn derive_a(_: proc_macro::TokenStream) -> proc_macro::TokenStream {
- "fn f() { println!(\"{}\", foo); }".parse().unwrap()
-}
+++ /dev/null
-// Copyright 2016 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.
-
-// force-host
-// no-prefer-dynamic
-
-#![crate_type = "proc-macro"]
-
-extern crate proc_macro;
-use proc_macro::TokenStream;
-
-#[proc_macro_derive(Derive)]
-pub fn derive(_: TokenStream) -> TokenStream {
- let code = "
- fn one(r: Restricted) {
- r.field;
- }
- fn two(r: Restricted) {
- r.field;
- }
- ";
-
- code.parse().unwrap()
-}
+++ /dev/null
-// 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.
-
-// force-host
-// no-prefer-dynamic
-
-#![crate_type = "proc-macro"]
-
-extern crate proc_macro;
-
-use proc_macro::*;
-
-#[proc_macro_attribute]
-pub fn attr2mac1(_: TokenStream, _: TokenStream) -> TokenStream {
- "macro_rules! foo1 { (a) => (a) }".parse().unwrap()
-}
-
-#[proc_macro_attribute]
-pub fn attr2mac2(_: TokenStream, _: TokenStream) -> TokenStream {
- "macro foo2(a) { a }".parse().unwrap()
-}
-
-#[proc_macro]
-pub fn mac2mac1(_: TokenStream) -> TokenStream {
- "macro_rules! foo3 { (a) => (a) }".parse().unwrap()
-}
-
-#[proc_macro]
-pub fn mac2mac2(_: TokenStream) -> TokenStream {
- "macro foo4(a) { a }".parse().unwrap()
-}
-
-#[proc_macro]
-pub fn tricky(_: TokenStream) -> TokenStream {
- "fn foo() {
- macro_rules! foo { (a) => (a) }
- }".parse().unwrap()
-}
+++ /dev/null
-// 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.
-
-// force-host
-// no-prefer-dynamic
-
-#![crate_type = "proc-macro"]
-
-extern crate proc_macro;
-
-use proc_macro::*;
-
-#[proc_macro]
-pub fn m(a: TokenStream) -> TokenStream {
- a
-}
-
-#[proc_macro_attribute]
-pub fn a(_a: TokenStream, b: TokenStream) -> TokenStream {
- b
-}
+++ /dev/null
-// 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.
-
-// force-host
-// no-prefer-dynamic
-
-#![crate_type = "proc-macro"]
-
-extern crate proc_macro;
-
-use proc_macro::TokenStream;
-
-#[proc_macro_attribute]
-pub fn nop_attr(_attr: TokenStream, input: TokenStream) -> TokenStream {
- assert!(_attr.to_string().is_empty());
- input
-}
-
-#[proc_macro_attribute]
-pub fn no_output(_attr: TokenStream, _input: TokenStream) -> TokenStream {
- assert!(_attr.to_string().is_empty());
- assert!(!_input.to_string().is_empty());
- "".parse().unwrap()
-}
-
-#[proc_macro]
-pub fn emit_input(input: TokenStream) -> TokenStream {
- input
-}
+++ /dev/null
-// Copyright 2016 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.
-
-// force-host
-// no-prefer-dynamic
-
-#![crate_type = "proc-macro"]
-
-extern crate proc_macro;
-
-use proc_macro::TokenStream;
-
-#[proc_macro_derive(A)]
-pub fn foo(input: TokenStream) -> TokenStream {
- input
-}
-
-#[proc_macro_derive(A)] //~ ERROR the name `A` is defined multiple times
-pub fn bar(input: TokenStream) -> TokenStream {
- input
-}
+++ /dev/null
-// Copyright 2016 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.
-
-// aux-build:derive-bad.rs
-
-#[macro_use]
-extern crate derive_bad;
-
-#[derive(
- A
-)]
-//~^^ ERROR proc-macro derive produced unparseable tokens
-//~| ERROR expected `:`, found `}`
-struct A;
-
-fn main() {}
+++ /dev/null
-// Copyright 2016 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.
-
-// aux-build:derive-a.rs
-
-#![allow(warnings)]
-
-#[macro_use]
-extern crate derive_a;
-
-#[derive_A] //~ ERROR attribute `derive_A` is currently unknown
-struct A;
-
-fn main() {}
+++ /dev/null
-// Copyright 2016 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.
-
-// aux-build:derive-unstable-2.rs
-
-#![allow(warnings)]
-
-#[macro_use]
-extern crate derive_unstable_2;
-
-#[derive(Unstable)]
-//~^ ERROR: reserved for internal compiler
-struct A;
-
-fn main() {
- foo();
-}
+++ /dev/null
-// Copyright 2016 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.
-
-// aux-build:derive-unstable.rs
-
-#![allow(warnings)]
-
-#[macro_use]
-extern crate derive_unstable;
-
-#[derive(Unstable)]
-//~^ ERROR: use of unstable library feature
-struct A;
-
-fn main() {
- unsafe { foo(); }
-}
+++ /dev/null
-// Copyright 2016 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.
-
-// error-pattern: cannot export macro_rules! macros from a `proc-macro` crate
-
-// force-host
-// no-prefer-dynamic
-
-#![crate_type = "proc-macro"]
-
-#[macro_export]
-macro_rules! foo {
- ($e:expr) => ($e)
-}
+++ /dev/null
-// Copyright 2016 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.
-
-// force-host
-// no-prefer-dynamic
-
-#![crate_type = "proc-macro"]
-#![allow(warnings)]
-
-pub fn a() {} //~ ERROR: cannot export any items
-pub struct B; //~ ERROR: cannot export any items
-pub enum C {} //~ ERROR: cannot export any items
-pub mod d {} //~ ERROR: cannot export any items
-
-mod e {}
-struct F;
-enum G {}
-fn h() {}
+++ /dev/null
-// Copyright 2016 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.
-
-extern crate proc_macro;
-
-#[proc_macro_derive(Foo)]
-//~^ ERROR: only usable with crates of the `proc-macro` crate type
-pub fn foo(a: proc_macro::TokenStream) -> proc_macro::TokenStream {
- a
-}
-
-// Issue #37590
-#[proc_macro_derive(Foo)]
-//~^ ERROR: the `#[proc_macro_derive]` attribute may only be used on bare functions
-pub struct Foo {
-}
-
-fn main() {}
+++ /dev/null
-// Copyright 2016 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.
-
-// aux-build:derive-a.rs
-
-#![allow(warnings)]
-
-#[macro_use]
-extern crate derive_a;
-
-use derive_a::derive_a;
-//~^ ERROR: unresolved import `derive_a::derive_a`
-
-fn main() {}
+++ /dev/null
-// Copyright 2016 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.
-
-// aux-build:derive-a-b.rs
-
-#[macro_use]
-extern crate derive_a_b;
-
-fn main() {
- // Test that constructing the `visible_parent_map` (in `cstore_impl.rs`) does not ICE.
- std::cell::Cell::new(0) //~ ERROR mismatched types
-}
+++ /dev/null
-// Copyright 2016 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.
-
-// aux-build:issue_38586.rs
-
-#[macro_use]
-extern crate issue_38586;
-
-#[derive(A)] //~ ERROR `foo`
-struct A;
-
-fn main() {}
+++ /dev/null
-// Copyright 2017 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.
-
-// aux-build:issue-41211.rs
-
-// FIXME: https://github.com/rust-lang/rust/issues/41430
-// This is a temporary regression test for the ICE reported in #41211
-
-#![feature(custom_inner_attributes)]
-
-#![emit_unchanged]
-//~^ ERROR attribute `emit_unchanged` is currently unknown to the compiler
-extern crate issue_41211;
-use issue_41211::emit_unchanged;
-
-fn main() {}
+++ /dev/null
-// Copyright 2016 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.
-
-// aux-build:issue_50493.rs
-
-#[macro_use]
-extern crate issue_50493;
-
-#[derive(Derive)] //~ ERROR field `field` of struct `Restricted` is private
-struct Restricted {
- pub(in restricted) field: usize, //~ visibilities can only be restricted to ancestor modules
-}
-
-mod restricted {}
-
-fn main() {}
-
+++ /dev/null
-// Copyright 2016 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.
-
-// aux-build:derive-b.rs
-
-#![allow(warnings)]
-
-#[macro_use]
-extern crate derive_b;
-
-#[derive(B)]
-struct A {
- a: &u64
-//~^ ERROR: missing lifetime specifier
-}
-
-fn main() {
-}
+++ /dev/null
-// Copyright 2016 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.
-
-// aux-build:bang_proc_macro2.rs
-
-#![feature(proc_macro_hygiene)]
-#![allow(unused_macros)]
-
-extern crate bang_proc_macro2;
-
-use bang_proc_macro2::bang_proc_macro2;
-
-fn main() {
- let foobar = 42;
- bang_proc_macro2!();
- //~^ ERROR cannot find value `foobar2` in this scope
- //~^^ did you mean `foobar`?
- println!("{}", x);
-}
+++ /dev/null
-// 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.
-
-// aux-build:test-macros.rs
-// ignore-wasm32
-
-extern crate test_macros;
-
-use test_macros::{nop_attr, no_output, emit_input};
-
-fn main() {
- assert_eq!(unsafe { rust_get_test_int() }, 0isize);
- assert_eq!(unsafe { rust_dbg_extern_identity_u32(0xDEADBEEF) }, 0xDEADBEEF);
-}
-
-#[link(name = "rust_test_helpers", kind = "static")]
-extern {
- #[no_output]
- //~^ ERROR macro invocations in `extern {}` blocks are experimental
- fn some_definitely_unknown_symbol_which_should_be_removed();
-
- #[nop_attr]
- //~^ ERROR macro invocations in `extern {}` blocks are experimental
- fn rust_get_test_int() -> isize;
-
- emit_input!(fn rust_dbg_extern_identity_u32(arg: u32) -> u32;);
- //~^ ERROR macro invocations in `extern {}` blocks are experimental
-}
+++ /dev/null
-// 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.
-
-// aux-build:more-gates.rs
-
-extern crate more_gates as foo;
-
-use foo::*;
-
-#[attr2mac1]
-//~^ ERROR: cannot expand to macro definitions
-pub fn a() {}
-#[attr2mac2]
-//~^ ERROR: cannot expand to macro definitions
-pub fn a() {}
-
-mac2mac1!(); //~ ERROR: cannot expand to macro definitions
-mac2mac2!(); //~ ERROR: cannot expand to macro definitions
-
-tricky!();
-//~^ ERROR: cannot expand to macro definitions
-
-fn main() {}
+++ /dev/null
-// Copyright 2016 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.
-
-// aux-build:derive-a.rs
-
-#![feature(rustc_attrs)]
-#![warn(unused_extern_crates)]
-
-extern crate derive_a;
-//~^ WARN unused extern crate
-
-#[rustc_error]
-fn main() {} //~ ERROR compilation successful
+++ /dev/null
-// Copyright 2016 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.
-
-// aux-build:derive-b.rs
-
-#[macro_use]
-extern crate derive_b;
-
-#[B]
-#[C] //~ ERROR attribute `C` is currently unknown to the compiler
-#[B(D)]
-#[B(E = "foo")]
-#[B(arbitrary tokens)]
-#[derive(B)]
-struct B;
-
-fn main() {}
+++ /dev/null
-// 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.
-
-// aux-build:proc-macro-gates.rs
-// gate-test-proc_macro_hygiene
-
-#![feature(stmt_expr_attributes)]
-
-extern crate proc_macro_gates as foo;
-
-use foo::*;
-
-fn _test_inner() {
- #![a] //~ ERROR: non-builtin inner attributes are unstable
-}
-
-#[a] //~ ERROR: custom attributes cannot be applied to modules
-mod _test2 {}
-
-mod _test2_inner {
- #![a] //~ ERROR: custom attributes cannot be applied to modules
- //~| ERROR: non-builtin inner attributes are unstable
-}
-
-#[a = y] //~ ERROR: must only be followed by a delimiter token
-fn _test3() {}
-
-fn attrs() {
- // Statement, item
- #[a] // OK
- struct S;
-
- // Statement, macro
- #[a] //~ ERROR: custom attributes cannot be applied to statements
- println!();
-
- // Statement, semi
- #[a] //~ ERROR: custom attributes cannot be applied to statements
- S;
-
- // Statement, local
- #[a] //~ ERROR: custom attributes cannot be applied to statements
- let _x = 2;
-
- // Expr
- let _x = #[a] 2; //~ ERROR: custom attributes cannot be applied to expressions
-
- // Opt expr
- let _x = [#[a] 2]; //~ ERROR: custom attributes cannot be applied to expressions
-
- // Expr macro
- let _x = #[a] println!(); //~ ERROR: custom attributes cannot be applied to expressions
-}
-
-fn main() {
- let _x: m!(u32) = 3; //~ ERROR: procedural macros cannot be expanded to types
- if let m!(Some(_x)) = Some(3) {} //~ ERROR: procedural macros cannot be expanded to patterns
-
- m!(struct S;); //~ ERROR: procedural macros cannot be expanded to statements
- m!(let _x = 3;); //~ ERROR: procedural macros cannot be expanded to statements
-
- let _x = m!(3); //~ ERROR: procedural macros cannot be expanded to expressions
- let _x = [m!(3)]; //~ ERROR: procedural macros cannot be expanded to expressions
-}
+++ /dev/null
-// 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.
-
-// aux-build:proc-macro-gates.rs
-
-#![feature(stmt_expr_attributes)]
-
-extern crate proc_macro_gates as foo;
-
-use foo::*;
-
-// NB. these errors aren't the best errors right now, but they're definitely
-// intended to be errors. Somehow using a custom attribute in these positions
-// should either require a feature gate or not be allowed on stable.
-
-fn _test6<#[a] T>() {}
-//~^ ERROR: unknown to the compiler
-
-fn _test7() {
- match 1 {
- #[a] //~ ERROR: unknown to the compiler
- 0 => {}
- _ => {}
- }
-}
-
-fn main() {
-}
+++ /dev/null
-// Copyright 2016 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.
-
-// force-host
-// no-prefer-dynamic
-
-#![crate_type = "proc-macro"]
-
-extern crate proc_macro;
-
-pub mod a { //~ `proc-macro` crate types cannot export any items
- use proc_macro::TokenStream;
-
- #[proc_macro_derive(B)]
- pub fn bar(a: TokenStream) -> TokenStream {
- //~^ ERROR: must currently reside in the root of the crate
- a
- }
-}
-
-#[proc_macro_derive(B)]
-fn bar(a: proc_macro::TokenStream) -> proc_macro::TokenStream {
-//~^ ERROR: functions tagged with `#[proc_macro_derive]` must be `pub`
- a
-}
+++ /dev/null
-// Copyright 2016 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.
-
-// force-host
-// no-prefer-dynamic
-
-#![crate_type = "proc-macro"]
-
-extern crate proc_macro;
-
-use proc_macro::TokenStream;
-
-#[proc_macro_derive(PartialEq)]
-//~^ ERROR: cannot override a built-in #[derive] mode
-pub fn foo(input: TokenStream) -> TokenStream {
- input
-}
+++ /dev/null
-// Copyright 2016 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.
-
-// aux-build:derive-a.rs
-
-#[macro_use]
-extern crate derive_a;
-#[macro_use]
-extern crate derive_a; //~ ERROR the name `derive_a` is defined multiple times
-
-fn main() {}
+++ /dev/null
-// Copyright 2016 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.
-
-// error-pattern: cannot mix `proc-macro` crate type with others
-
-// force-host
-// no-prefer-dynamic
-
-#![crate_type = "proc-macro"]
-#![crate_type = "rlib"]
+++ /dev/null
-// Copyright 2016 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.
-
-// error-pattern: cannot mix `proc-macro` crate type with others
-// compile-flags: --crate-type rlib --crate-type proc-macro
-// force-host
--- /dev/null
+// 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.
+
+// aux-build:attr-stmt-expr.rs
+
+//! Attributes producing expressions in invalid locations
+
+#![feature(stmt_expr_attributes, proc_macro_hygiene)]
+
+extern crate attr_stmt_expr;
+use attr_stmt_expr::{duplicate, no_output};
+
+fn main() {
+ let _ = #[no_output] "Hello, world!";
+ //~^ ERROR expected expression, found `<eof>`
+
+ let _ = #[duplicate] "Hello, world!";
+ //~^ ERROR macro expansion ignores token `,` and any following
+
+ let _ = {
+ #[no_output]
+ "Hello, world!"
+ };
+
+ let _ = {
+ #[duplicate]
+ //~^ ERROR macro expansion ignores token `,` and any following
+ "Hello, world!"
+ };
+}
--- /dev/null
+error: expected expression, found `<eof>`
+ --> $DIR/attr-invalid-exprs.rs:21:13
+ |
+LL | let _ = #[no_output] "Hello, world!";
+ | ^^^^^^^^^^^^
+
+error: macro expansion ignores token `,` and any following
+ --> $DIR/attr-invalid-exprs.rs:24:13
+ |
+LL | let _ = #[duplicate] "Hello, world!";
+ | ^^^^^^^^^^^^- help: you might be missing a semicolon here: `;`
+ | |
+ | caused by the macro expansion here
+ |
+ = note: the usage of `duplicate!` is likely invalid in expression context
+
+error: macro expansion ignores token `,` and any following
+ --> $DIR/attr-invalid-exprs.rs:33:9
+ |
+LL | #[duplicate]
+ | ^^^^^^^^^^^^- help: you might be missing a semicolon here: `;`
+ | |
+ | caused by the macro expansion here
+ |
+ = note: the usage of `duplicate!` is likely invalid in expression context
+
+error: aborting due to 3 previous errors
+
--- /dev/null
+// 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.
+
+// aux-build:attr-stmt-expr.rs
+
+#![feature(proc_macro_hygiene)]
+
+extern crate attr_stmt_expr;
+use attr_stmt_expr::{expect_let, expect_print_stmt, expect_expr, expect_print_expr};
+
+fn print_str(string: &'static str) {
+ // macros are handled a bit differently
+ #[expect_print_expr]
+ //~^ ERROR attributes on expressions are experimental
+ //~| HELP add #![feature(stmt_expr_attributes)] to the crate attributes to enable
+ println!("{}", string)
+}
+
+fn main() {
+ #[expect_let]
+ let string = "Hello, world!";
+
+ #[expect_print_stmt]
+ println!("{}", string);
+
+ #[expect_expr]
+ //~^ ERROR attributes on expressions are experimental
+ //~| HELP add #![feature(stmt_expr_attributes)] to the crate attributes to enable
+ print_str("string")
+}
--- /dev/null
+error[E0658]: attributes on expressions are experimental. (see issue #15701)
+ --> $DIR/attr-stmt-expr.rs:20:5
+ |
+LL | #[expect_print_expr]
+ | ^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: add #![feature(stmt_expr_attributes)] to the crate attributes to enable
+
+error[E0658]: attributes on expressions are experimental. (see issue #15701)
+ --> $DIR/attr-stmt-expr.rs:33:5
+ |
+LL | #[expect_expr]
+ | ^^^^^^^^^^^^^^
+ |
+ = help: add #![feature(stmt_expr_attributes)] to the crate attributes to enable
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0658`.
--- /dev/null
+// Copyright 2017 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.
+
+// aux-build:attribute-with-error.rs
+
+#![feature(custom_inner_attributes)]
+
+extern crate attribute_with_error;
+
+use attribute_with_error::foo;
+
+#[foo]
+fn test1() {
+ let a: i32 = "foo";
+ //~^ ERROR: mismatched types
+ let b: i32 = "f'oo";
+ //~^ ERROR: mismatched types
+}
+
+fn test2() {
+ #![foo]
+
+ // FIXME: should have a type error here and assert it works but it doesn't
+}
+
+trait A {
+ // FIXME: should have a #[foo] attribute here and assert that it works
+ fn foo(&self) {
+ let a: i32 = "foo";
+ //~^ ERROR: mismatched types
+ }
+}
+
+struct B;
+
+impl A for B {
+ #[foo]
+ fn foo(&self) {
+ let a: i32 = "foo";
+ //~^ ERROR: mismatched types
+ }
+}
+
+#[foo]
+fn main() {
+}
--- /dev/null
+error[E0308]: mismatched types
+ --> $DIR/attribute-with-error.rs:21:18
+ |
+LL | let a: i32 = "foo";
+ | ^^^^^ expected i32, found reference
+ |
+ = note: expected type `i32`
+ found type `&'static str`
+
+error[E0308]: mismatched types
+ --> $DIR/attribute-with-error.rs:23:18
+ |
+LL | let b: i32 = "f'oo";
+ | ^^^^^^ expected i32, found reference
+ |
+ = note: expected type `i32`
+ found type `&'static str`
+
+error[E0308]: mismatched types
+ --> $DIR/attribute-with-error.rs:36:22
+ |
+LL | let a: i32 = "foo";
+ | ^^^^^ expected i32, found reference
+ |
+ = note: expected type `i32`
+ found type `&'static str`
+
+error[E0308]: mismatched types
+ --> $DIR/attribute-with-error.rs:46:22
+ |
+LL | let a: i32 = "foo";
+ | ^^^^^ expected i32, found reference
+ |
+ = note: expected type `i32`
+ found type `&'static str`
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0308`.
--- /dev/null
+// Copyright 2016 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.
+
+// force-host
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+
+#[proc_macro_derive]
+//~^ ERROR: attribute must be of form: #[proc_macro_derive(TraitName)]
+pub fn foo1(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
+ input
+}
+
+#[proc_macro_derive = "foo"]
+//~^ ERROR: attribute must be of form: #[proc_macro_derive(TraitName)]
+pub fn foo2(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
+ input
+}
+
+#[proc_macro_derive(
+ a = "b"
+)]
+//~^^ ERROR: must only be one word
+pub fn foo3(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
+ input
+}
+
+#[proc_macro_derive(b, c, d)]
+//~^ ERROR: attribute must have either one or two arguments
+pub fn foo4(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
+ input
+}
+
+#[proc_macro_derive(d(e))]
+//~^ ERROR: must only be one word
+pub fn foo5(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
+ input
+}
+
+#[proc_macro_derive(f, attributes(g = "h"))]
+//~^ ERROR: must only be one word
+pub fn foo6(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
+ input
+}
+
+#[proc_macro_derive(i, attributes(j(k)))]
+//~^ ERROR: must only be one word
+pub fn foo7(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
+ input
+}
+
+#[proc_macro_derive(l, attributes(m), n)]
+//~^ ERROR: attribute must have either one or two arguments
+pub fn foo8(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
+ input
+}
--- /dev/null
+error: attribute must be of form: #[proc_macro_derive(TraitName)]
+ --> $DIR/attribute.rs:18:1
+ |
+LL | #[proc_macro_derive]
+ | ^^^^^^^^^^^^^^^^^^^^
+
+error: attribute must be of form: #[proc_macro_derive(TraitName)]
+ --> $DIR/attribute.rs:24:1
+ |
+LL | #[proc_macro_derive = "foo"]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: must only be one word
+ --> $DIR/attribute.rs:31:5
+ |
+LL | a = "b"
+ | ^^^^^^^
+
+error: attribute must have either one or two arguments
+ --> $DIR/attribute.rs:38:1
+ |
+LL | #[proc_macro_derive(b, c, d)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: must only be one word
+ --> $DIR/attribute.rs:44:21
+ |
+LL | #[proc_macro_derive(d(e))]
+ | ^^^^
+
+error: must only be one word
+ --> $DIR/attribute.rs:50:35
+ |
+LL | #[proc_macro_derive(f, attributes(g = "h"))]
+ | ^^^^^^^
+
+error: must only be one word
+ --> $DIR/attribute.rs:56:35
+ |
+LL | #[proc_macro_derive(i, attributes(j(k)))]
+ | ^^^^
+
+error: attribute must have either one or two arguments
+ --> $DIR/attribute.rs:62:1
+ |
+LL | #[proc_macro_derive(l, attributes(m), n)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 8 previous errors
+
--- /dev/null
+// Copyright 2017 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.
+
+// aux-build:attributes-included.rs
+// compile-pass
+
+#![warn(unused)]
+
+extern crate attributes_included;
+
+use attributes_included::*;
+
+#[bar]
+#[inline]
+/// doc
+#[foo]
+#[inline]
+/// doc
+fn foo() {
+ let a: i32 = "foo"; //~ WARN: unused variable
+}
+
+fn main() {
+ foo()
+}
--- /dev/null
+warning: unused variable: `a`
+ --> $DIR/attributes-included.rs:27:9
+ |
+LL | let a: i32 = "foo"; //~ WARN: unused variable
+ | ^ help: consider using `_a` instead
+ |
+note: lint level defined here
+ --> $DIR/attributes-included.rs:14:9
+ |
+LL | #![warn(unused)]
+ | ^^^^^^
+ = note: #[warn(unused_variables)] implied by #[warn(unused)]
+
--- /dev/null
+// 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.
+
+// force-host
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+
+use proc_macro::TokenStream;
+
+#[proc_macro_attribute]
+pub fn expect_let(attr: TokenStream, item: TokenStream) -> TokenStream {
+ assert!(attr.to_string().is_empty());
+ assert_eq!(item.to_string(), "let string = \"Hello, world!\";");
+ item
+}
+
+#[proc_macro_attribute]
+pub fn expect_print_stmt(attr: TokenStream, item: TokenStream) -> TokenStream {
+ assert!(attr.to_string().is_empty());
+ assert_eq!(item.to_string(), "println!(\"{}\" , string);");
+ item
+}
+
+#[proc_macro_attribute]
+pub fn expect_expr(attr: TokenStream, item: TokenStream) -> TokenStream {
+ assert!(attr.to_string().is_empty());
+ assert_eq!(item.to_string(), "print_str(\"string\")");
+ item
+}
+
+#[proc_macro_attribute]
+pub fn expect_print_expr(attr: TokenStream, item: TokenStream) -> TokenStream {
+ assert!(attr.to_string().is_empty());
+ assert_eq!(item.to_string(), "println!(\"{}\" , string)");
+ item
+}
+
+#[proc_macro_attribute]
+pub fn duplicate(attr: TokenStream, item: TokenStream) -> TokenStream {
+ assert!(attr.to_string().is_empty());
+ format!("{}, {}", item, item).parse().unwrap()
+}
+
+#[proc_macro_attribute]
+pub fn no_output(attr: TokenStream, item: TokenStream) -> TokenStream {
+ assert!(attr.to_string().is_empty());
+ assert!(!item.to_string().is_empty());
+ "".parse().unwrap()
+}
--- /dev/null
+// Copyright 2017 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.
+
+// force-host
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+
+use proc_macro::TokenStream;
+
+#[proc_macro_attribute]
+pub fn foo(_attr: TokenStream, input: TokenStream) -> TokenStream {
+ input.into_iter().collect()
+}
--- /dev/null
+// Copyright 2017 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.
+
+// force-host
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+
+use proc_macro::{TokenStream, TokenTree, Delimiter, Literal, Spacing, Group};
+
+#[proc_macro_attribute]
+pub fn foo(attr: TokenStream, input: TokenStream) -> TokenStream {
+ assert!(attr.is_empty());
+ let input = input.into_iter().collect::<Vec<_>>();
+ {
+ let mut cursor = &input[..];
+ assert_inline(&mut cursor);
+ assert_doc(&mut cursor);
+ assert_inline(&mut cursor);
+ assert_doc(&mut cursor);
+ assert_foo(&mut cursor);
+ assert!(cursor.is_empty());
+ }
+ fold_stream(input.into_iter().collect())
+}
+
+#[proc_macro_attribute]
+pub fn bar(attr: TokenStream, input: TokenStream) -> TokenStream {
+ assert!(attr.is_empty());
+ let input = input.into_iter().collect::<Vec<_>>();
+ {
+ let mut cursor = &input[..];
+ assert_inline(&mut cursor);
+ assert_doc(&mut cursor);
+ assert_invoc(&mut cursor);
+ assert_inline(&mut cursor);
+ assert_doc(&mut cursor);
+ assert_foo(&mut cursor);
+ assert!(cursor.is_empty());
+ }
+ input.into_iter().collect()
+}
+
+fn assert_inline(slice: &mut &[TokenTree]) {
+ match &slice[0] {
+ TokenTree::Punct(tt) => assert_eq!(tt.as_char(), '#'),
+ _ => panic!("expected '#' char"),
+ }
+ match &slice[1] {
+ TokenTree::Group(tt) => assert_eq!(tt.delimiter(), Delimiter::Bracket),
+ _ => panic!("expected brackets"),
+ }
+ *slice = &slice[2..];
+}
+
+fn assert_doc(slice: &mut &[TokenTree]) {
+ match &slice[0] {
+ TokenTree::Punct(tt) => {
+ assert_eq!(tt.as_char(), '#');
+ assert_eq!(tt.spacing(), Spacing::Alone);
+ }
+ _ => panic!("expected #"),
+ }
+ let inner = match &slice[1] {
+ TokenTree::Group(tt) => {
+ assert_eq!(tt.delimiter(), Delimiter::Bracket);
+ tt.stream()
+ }
+ _ => panic!("expected brackets"),
+ };
+ let tokens = inner.into_iter().collect::<Vec<_>>();
+ let tokens = &tokens[..];
+
+ if tokens.len() != 3 {
+ panic!("expected three tokens in doc")
+ }
+
+ match &tokens[0] {
+ TokenTree::Ident(tt) => assert_eq!("doc", &*tt.to_string()),
+ _ => panic!("expected `doc`"),
+ }
+ match &tokens[1] {
+ TokenTree::Punct(tt) => {
+ assert_eq!(tt.as_char(), '=');
+ assert_eq!(tt.spacing(), Spacing::Alone);
+ }
+ _ => panic!("expected equals"),
+ }
+ match tokens[2] {
+ TokenTree::Literal(_) => {}
+ _ => panic!("expected literal"),
+ }
+
+ *slice = &slice[2..];
+}
+
+fn assert_invoc(slice: &mut &[TokenTree]) {
+ match &slice[0] {
+ TokenTree::Punct(tt) => assert_eq!(tt.as_char(), '#'),
+ _ => panic!("expected '#' char"),
+ }
+ match &slice[1] {
+ TokenTree::Group(tt) => assert_eq!(tt.delimiter(), Delimiter::Bracket),
+ _ => panic!("expected brackets"),
+ }
+ *slice = &slice[2..];
+}
+
+fn assert_foo(slice: &mut &[TokenTree]) {
+ match &slice[0] {
+ TokenTree::Ident(tt) => assert_eq!(&*tt.to_string(), "fn"),
+ _ => panic!("expected fn"),
+ }
+ match &slice[1] {
+ TokenTree::Ident(tt) => assert_eq!(&*tt.to_string(), "foo"),
+ _ => panic!("expected foo"),
+ }
+ match &slice[2] {
+ TokenTree::Group(tt) => {
+ assert_eq!(tt.delimiter(), Delimiter::Parenthesis);
+ assert!(tt.stream().is_empty());
+ }
+ _ => panic!("expected parens"),
+ }
+ match &slice[3] {
+ TokenTree::Group(tt) => assert_eq!(tt.delimiter(), Delimiter::Brace),
+ _ => panic!("expected braces"),
+ }
+ *slice = &slice[4..];
+}
+
+fn fold_stream(input: TokenStream) -> TokenStream {
+ input.into_iter().map(fold_tree).collect()
+}
+
+fn fold_tree(input: TokenTree) -> TokenTree {
+ match input {
+ TokenTree::Group(b) => {
+ TokenTree::Group(Group::new(b.delimiter(), fold_stream(b.stream())))
+ }
+ TokenTree::Punct(b) => TokenTree::Punct(b),
+ TokenTree::Ident(a) => TokenTree::Ident(a),
+ TokenTree::Literal(a) => {
+ if a.to_string() != "\"foo\"" {
+ TokenTree::Literal(a)
+ } else {
+ TokenTree::Literal(Literal::i32_unsuffixed(3))
+ }
+ }
+ }
+}
--- /dev/null
+// Copyright 2016 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.
+
+// force-host
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+
+use proc_macro::TokenStream;
+
+#[proc_macro]
+pub fn bang_proc_macro2(_: TokenStream) -> TokenStream {
+ "let x = foobar2;".parse().unwrap()
+}
--- /dev/null
+// Copyright 2016 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.
+
+// force-host
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+use proc_macro::TokenStream;
+
+#[proc_macro_derive(A)]
+pub fn derive_a(_: TokenStream) -> TokenStream {
+ "".parse().unwrap()
+}
+
+#[proc_macro_derive(B)]
+pub fn derive_b(_: TokenStream) -> TokenStream {
+ "".parse().unwrap()
+}
--- /dev/null
+// Copyright 2016 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.
+
+// force-host
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+
+use proc_macro::TokenStream;
+
+#[proc_macro_derive(A)]
+pub fn derive_a(input: TokenStream) -> TokenStream {
+ "".parse().unwrap()
+}
--- /dev/null
+// Copyright 2016 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.
+
+// force-host
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+
+use proc_macro::TokenStream;
+
+#[proc_macro_derive(B, attributes(B))]
+pub fn derive_b(input: TokenStream) -> TokenStream {
+ "".parse().unwrap()
+}
--- /dev/null
+// Copyright 2016 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.
+
+// force-host
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+
+use proc_macro::TokenStream;
+
+#[proc_macro_derive(A)]
+pub fn derive_a(_input: TokenStream) -> TokenStream {
+ "struct A { inner }".parse().unwrap()
+}
+
--- /dev/null
+// Copyright 2016 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.
+
+// force-host
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+
+use proc_macro::TokenStream;
+
+#[proc_macro_derive(Unstable)]
+pub fn derive(_input: TokenStream) -> TokenStream {
+
+ "
+ #[rustc_foo]
+ fn foo() {}
+ ".parse().unwrap()
+}
--- /dev/null
+// Copyright 2016 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.
+
+// force-host
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+
+use proc_macro::TokenStream;
+
+#[proc_macro_derive(Unstable)]
+pub fn derive(_input: TokenStream) -> TokenStream {
+
+ "unsafe fn foo() -> u32 { ::std::intrinsics::init() }".parse().unwrap()
+}
--- /dev/null
+// Copyright 2017 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.
+
+// force-host
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+use proc_macro::TokenStream;
+
+#[proc_macro_attribute]
+pub fn emit_unchanged(_args: TokenStream, input: TokenStream) -> TokenStream {
+ input
+}
--- /dev/null
+// Copyright 2016 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.
+
+// force-host
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+
+#[proc_macro_derive(A)]
+pub fn derive_a(_: proc_macro::TokenStream) -> proc_macro::TokenStream {
+ "fn f() { println!(\"{}\", foo); }".parse().unwrap()
+}
--- /dev/null
+// Copyright 2016 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.
+
+// force-host
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+use proc_macro::TokenStream;
+
+#[proc_macro_derive(Derive)]
+pub fn derive(_: TokenStream) -> TokenStream {
+ let code = "
+ fn one(r: Restricted) {
+ r.field;
+ }
+ fn two(r: Restricted) {
+ r.field;
+ }
+ ";
+
+ code.parse().unwrap()
+}
--- /dev/null
+// 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.
+
+// force-host
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+
+use proc_macro::*;
+
+#[proc_macro_attribute]
+pub fn attr2mac1(_: TokenStream, _: TokenStream) -> TokenStream {
+ "macro_rules! foo1 { (a) => (a) }".parse().unwrap()
+}
+
+#[proc_macro_attribute]
+pub fn attr2mac2(_: TokenStream, _: TokenStream) -> TokenStream {
+ "macro foo2(a) { a }".parse().unwrap()
+}
+
+#[proc_macro]
+pub fn mac2mac1(_: TokenStream) -> TokenStream {
+ "macro_rules! foo3 { (a) => (a) }".parse().unwrap()
+}
+
+#[proc_macro]
+pub fn mac2mac2(_: TokenStream) -> TokenStream {
+ "macro foo4(a) { a }".parse().unwrap()
+}
+
+#[proc_macro]
+pub fn tricky(_: TokenStream) -> TokenStream {
+ "fn foo() {
+ macro_rules! foo { (a) => (a) }
+ }".parse().unwrap()
+}
--- /dev/null
+// 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.
+
+// force-host
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+
+use proc_macro::*;
+
+#[proc_macro]
+pub fn m(a: TokenStream) -> TokenStream {
+ a
+}
+
+#[proc_macro_attribute]
+pub fn a(_a: TokenStream, b: TokenStream) -> TokenStream {
+ b
+}
--- /dev/null
+// 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.
+
+// force-host
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+
+use proc_macro::TokenStream;
+
+#[proc_macro_attribute]
+pub fn nop_attr(_attr: TokenStream, input: TokenStream) -> TokenStream {
+ assert!(_attr.to_string().is_empty());
+ input
+}
+
+#[proc_macro_attribute]
+pub fn no_output(_attr: TokenStream, _input: TokenStream) -> TokenStream {
+ assert!(_attr.to_string().is_empty());
+ assert!(!_input.to_string().is_empty());
+ "".parse().unwrap()
+}
+
+#[proc_macro]
+pub fn emit_input(input: TokenStream) -> TokenStream {
+ input
+}
--- /dev/null
+// Copyright 2016 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.
+
+// force-host
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+
+use proc_macro::TokenStream;
+
+#[proc_macro_derive(A)]
+pub fn foo(input: TokenStream) -> TokenStream {
+ input
+}
+
+#[proc_macro_derive(A)] //~ ERROR the name `A` is defined multiple times
+pub fn bar(input: TokenStream) -> TokenStream {
+ input
+}
--- /dev/null
+error[E0428]: the name `A` is defined multiple times
+ --> $DIR/define-two.rs:25:21
+ |
+LL | #[proc_macro_derive(A)]
+ | - previous definition of the macro `A` here
+...
+LL | #[proc_macro_derive(A)] //~ ERROR the name `A` is defined multiple times
+ | ^ `A` redefined here
+ |
+ = note: `A` must be defined only once in the macro namespace of this module
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0428`.
--- /dev/null
+// Copyright 2016 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.
+
+// aux-build:derive-bad.rs
+
+#[macro_use]
+extern crate derive_bad;
+
+#[derive(
+ A
+)]
+//~^^ ERROR proc-macro derive produced unparseable tokens
+//~| ERROR expected `:`, found `}`
+struct A;
+
+fn main() {}
--- /dev/null
+error: expected `:`, found `}`
+ --> $DIR/derive-bad.rs:17:5
+ |
+LL | A
+ | ^ expected `:`
+
+error: proc-macro derive produced unparseable tokens
+ --> $DIR/derive-bad.rs:17:5
+ |
+LL | A
+ | ^
+
+error: aborting due to 2 previous errors
+
--- /dev/null
+// Copyright 2016 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.
+
+// aux-build:derive-a.rs
+
+#![allow(warnings)]
+
+#[macro_use]
+extern crate derive_a;
+
+#[derive_A] //~ ERROR attribute `derive_A` is currently unknown
+struct A;
+
+fn main() {}
--- /dev/null
+error[E0658]: attributes of the form `#[derive_*]` are reserved for the compiler (see issue #29644)
+ --> $DIR/derive-still-gated.rs:18:3
+ |
+LL | #[derive_A] //~ ERROR: attributes of the form `#[derive_*]` are reserved for the compiler
+ | ^^^^^^^^
+ |
+ = help: add #![feature(custom_derive)] to the crate attributes to enable
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0658`.
--- /dev/null
+// Copyright 2016 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.
+
+// aux-build:derive-unstable-2.rs
+
+#![allow(warnings)]
+
+#[macro_use]
+extern crate derive_unstable_2;
+
+#[derive(Unstable)]
+//~^ ERROR: reserved for internal compiler
+struct A;
+
+fn main() {
+ foo();
+}
--- /dev/null
+error[E0658]: unless otherwise specified, attributes with the prefix `rustc_` are reserved for internal compiler diagnostics (see issue #29642)
+ --> $DIR/expand-to-unstable-2.rs:18:10
+ |
+LL | #[derive(Unstable)]
+ | ^^^^^^^^
+ |
+ = help: add #![feature(rustc_attrs)] to the crate attributes to enable
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0658`.
--- /dev/null
+// Copyright 2016 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.
+
+// aux-build:derive-unstable.rs
+
+#![allow(warnings)]
+
+#[macro_use]
+extern crate derive_unstable;
+
+#[derive(Unstable)]
+//~^ ERROR: use of unstable library feature
+struct A;
+
+fn main() {
+ unsafe { foo(); }
+}
--- /dev/null
+error[E0658]: use of unstable library feature 'core_intrinsics': intrinsics are unlikely to ever be stabilized, instead they should be used through stabilized interfaces in the rest of the standard library
+ --> $DIR/expand-to-unstable.rs:18:10
+ |
+LL | #[derive(Unstable)]
+ | ^^^^^^^^
+ |
+ = help: add #![feature(core_intrinsics)] to the crate attributes to enable
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0658`.
--- /dev/null
+// Copyright 2016 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.
+
+// error-pattern: cannot export macro_rules! macros from a `proc-macro` crate
+
+// force-host
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+
+#[macro_export]
+macro_rules! foo {
+ ($e:expr) => ($e)
+}
--- /dev/null
+error: cannot export macro_rules! macros from a `proc-macro` crate type currently
+ --> $DIR/export-macro.rs:19:1
+ |
+LL | / macro_rules! foo {
+LL | | ($e:expr) => ($e)
+LL | | }
+ | |_^
+
+error: aborting due to previous error
+
--- /dev/null
+// Copyright 2016 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.
+
+// force-host
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+#![allow(warnings)]
+
+pub fn a() {} //~ ERROR: cannot export any items
+pub struct B; //~ ERROR: cannot export any items
+pub enum C {} //~ ERROR: cannot export any items
+pub mod d {} //~ ERROR: cannot export any items
+
+mod e {}
+struct F;
+enum G {}
+fn h() {}
--- /dev/null
+error: `proc-macro` crate types cannot export any items other than functions tagged with `#[proc_macro_derive]` currently
+ --> $DIR/exports.rs:17:1
+ |
+LL | pub fn a() {} //~ ERROR: cannot export any items
+ | ^^^^^^^^^^^^^
+
+error: `proc-macro` crate types cannot export any items other than functions tagged with `#[proc_macro_derive]` currently
+ --> $DIR/exports.rs:18:1
+ |
+LL | pub struct B; //~ ERROR: cannot export any items
+ | ^^^^^^^^^^^^^
+
+error: `proc-macro` crate types cannot export any items other than functions tagged with `#[proc_macro_derive]` currently
+ --> $DIR/exports.rs:19:1
+ |
+LL | pub enum C {} //~ ERROR: cannot export any items
+ | ^^^^^^^^^^^^^
+
+error: `proc-macro` crate types cannot export any items other than functions tagged with `#[proc_macro_derive]` currently
+ --> $DIR/exports.rs:20:1
+ |
+LL | pub mod d {} //~ ERROR: cannot export any items
+ | ^^^^^^^^^^^^
+
+error: aborting due to 4 previous errors
+
--- /dev/null
+// Copyright 2016 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.
+
+extern crate proc_macro;
+
+#[proc_macro_derive(Foo)]
+//~^ ERROR: only usable with crates of the `proc-macro` crate type
+pub fn foo(a: proc_macro::TokenStream) -> proc_macro::TokenStream {
+ a
+}
+
+// Issue #37590
+#[proc_macro_derive(Foo)]
+//~^ ERROR: the `#[proc_macro_derive]` attribute may only be used on bare functions
+pub struct Foo {
+}
+
+fn main() {}
--- /dev/null
+error: the `#[proc_macro_derive]` attribute is only usable with crates of the `proc-macro` crate type
+ --> $DIR/illegal-proc-macro-derive-use.rs:13:1
+ |
+LL | #[proc_macro_derive(Foo)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: the `#[proc_macro_derive]` attribute may only be used on bare functions
+ --> $DIR/illegal-proc-macro-derive-use.rs:20:1
+ |
+LL | #[proc_macro_derive(Foo)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 2 previous errors
+
--- /dev/null
+// Copyright 2016 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.
+
+// aux-build:derive-a.rs
+
+#![allow(warnings)]
+
+#[macro_use]
+extern crate derive_a;
+
+use derive_a::derive_a;
+//~^ ERROR: unresolved import `derive_a::derive_a`
+
+fn main() {}
--- /dev/null
+error[E0432]: unresolved import `derive_a::derive_a`
+ --> $DIR/import.rs:18:5
+ |
+LL | use derive_a::derive_a;
+ | ^^^^^^^^^^^^^^^^^^ no `derive_a` in the root
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0432`.
--- /dev/null
+// Copyright 2016 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.
+
+// aux-build:derive-a-b.rs
+
+#[macro_use]
+extern crate derive_a_b;
+
+fn main() {
+ // Test that constructing the `visible_parent_map` (in `cstore_impl.rs`) does not ICE.
+ std::cell::Cell::new(0) //~ ERROR mismatched types
+}
--- /dev/null
+error[E0308]: mismatched types
+ --> $DIR/issue-37788.rs:18:5
+ |
+LL | fn main() {
+ | - expected `()` because of default return type
+LL | // Test that constructing the `visible_parent_map` (in `cstore_impl.rs`) does not ICE.
+LL | std::cell::Cell::new(0) //~ ERROR mismatched types
+ | ^^^^^^^^^^^^^^^^^^^^^^^- help: try adding a semicolon: `;`
+ | |
+ | expected (), found struct `std::cell::Cell`
+ |
+ = note: expected type `()`
+ found type `std::cell::Cell<{integer}>`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
--- /dev/null
+// Copyright 2016 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.
+
+// aux-build:issue_38586.rs
+
+#[macro_use]
+extern crate issue_38586;
+
+#[derive(A)] //~ ERROR `foo`
+struct A;
+
+fn main() {}
--- /dev/null
+error[E0425]: cannot find value `foo` in this scope
+ --> $DIR/issue-38586.rs:16:10
+ |
+LL | #[derive(A)] //~ ERROR `foo`
+ | ^ not found in this scope
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0425`.
--- /dev/null
+// Copyright 2017 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.
+
+// aux-build:issue-41211.rs
+
+// FIXME: https://github.com/rust-lang/rust/issues/41430
+// This is a temporary regression test for the ICE reported in #41211
+
+#![feature(custom_inner_attributes)]
+
+#![emit_unchanged]
+//~^ ERROR attribute `emit_unchanged` is currently unknown to the compiler
+extern crate issue_41211;
+use issue_41211::emit_unchanged;
+
+fn main() {}
--- /dev/null
+error[E0658]: The attribute `emit_unchanged` is currently unknown to the compiler and may have meaning added to it in the future (see issue #29642)
+ --> $DIR/issue-41211.rs:18:4
+ |
+LL | #![emit_unchanged]
+ | ^^^^^^^^^^^^^^
+ |
+ = help: add #![feature(custom_attribute)] to the crate attributes to enable
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0658`.
--- /dev/null
+// Copyright 2016 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.
+
+// aux-build:issue_50493.rs
+
+#[macro_use]
+extern crate issue_50493;
+
+#[derive(Derive)] //~ ERROR field `field` of struct `Restricted` is private
+struct Restricted {
+ pub(in restricted) field: usize, //~ visibilities can only be restricted to ancestor modules
+}
+
+mod restricted {}
+
+fn main() {}
+
--- /dev/null
+error: visibilities can only be restricted to ancestor modules
+ --> $DIR/issue-50493.rs:18:12
+ |
+LL | pub(in restricted) field: usize, //~ visibilities can only be restricted to ancestor modules
+ | ^^^^^^^^^^
+
+error[E0616]: field `field` of struct `Restricted` is private
+ --> $DIR/issue-50493.rs:16:10
+ |
+LL | #[derive(Derive)] //~ ERROR field `field` of struct `Restricted` is private
+ | ^^^^^^
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0616`.
--- /dev/null
+// Copyright 2016 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.
+
+// aux-build:derive-b.rs
+
+#![allow(warnings)]
+
+#[macro_use]
+extern crate derive_b;
+
+#[derive(B)]
+struct A {
+ a: &u64
+//~^ ERROR: missing lifetime specifier
+}
+
+fn main() {
+}
--- /dev/null
+error[E0106]: missing lifetime specifier
+ --> $DIR/item-error.rs:20:8
+ |
+LL | a: &u64
+ | ^ expected lifetime parameter
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0106`.
--- /dev/null
+// Copyright 2016 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.
+
+// aux-build:bang_proc_macro2.rs
+
+#![feature(proc_macro_hygiene)]
+#![allow(unused_macros)]
+
+extern crate bang_proc_macro2;
+
+use bang_proc_macro2::bang_proc_macro2;
+
+fn main() {
+ let foobar = 42;
+ bang_proc_macro2!();
+ //~^ ERROR cannot find value `foobar2` in this scope
+ //~^^ did you mean `foobar`?
+ println!("{}", x);
+}
--- /dev/null
+error[E0425]: cannot find value `foobar2` in this scope
+ --> $DIR/lints_in_proc_macros.rs:22:5
+ |
+LL | bang_proc_macro2!();
+ | ^^^^^^^^^^^^^^^^^^^^ did you mean `foobar`?
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0425`.
--- /dev/null
+// 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.
+
+// aux-build:test-macros.rs
+// ignore-wasm32
+
+extern crate test_macros;
+
+use test_macros::{nop_attr, no_output, emit_input};
+
+fn main() {
+ assert_eq!(unsafe { rust_get_test_int() }, 0isize);
+ assert_eq!(unsafe { rust_dbg_extern_identity_u32(0xDEADBEEF) }, 0xDEADBEEF);
+}
+
+#[link(name = "rust_test_helpers", kind = "static")]
+extern {
+ #[no_output]
+ //~^ ERROR macro invocations in `extern {}` blocks are experimental
+ fn some_definitely_unknown_symbol_which_should_be_removed();
+
+ #[nop_attr]
+ //~^ ERROR macro invocations in `extern {}` blocks are experimental
+ fn rust_get_test_int() -> isize;
+
+ emit_input!(fn rust_dbg_extern_identity_u32(arg: u32) -> u32;);
+ //~^ ERROR macro invocations in `extern {}` blocks are experimental
+}
--- /dev/null
+error[E0658]: macro invocations in `extern {}` blocks are experimental (see issue #49476)
+ --> $DIR/macros-in-extern.rs:25:5
+ |
+LL | #[no_output]
+ | ^^^^^^^^^^^^
+ |
+ = help: add #![feature(macros_in_extern)] to the crate attributes to enable
+
+error[E0658]: macro invocations in `extern {}` blocks are experimental (see issue #49476)
+ --> $DIR/macros-in-extern.rs:29:5
+ |
+LL | #[nop_attr]
+ | ^^^^^^^^^^^
+ |
+ = help: add #![feature(macros_in_extern)] to the crate attributes to enable
+
+error[E0658]: macro invocations in `extern {}` blocks are experimental (see issue #49476)
+ --> $DIR/macros-in-extern.rs:33:5
+ |
+LL | emit_input!(fn rust_dbg_extern_identity_u32(arg: u32) -> u32;);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: add #![feature(macros_in_extern)] to the crate attributes to enable
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0658`.
--- /dev/null
+// 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.
+
+// aux-build:more-gates.rs
+
+extern crate more_gates as foo;
+
+use foo::*;
+
+#[attr2mac1]
+//~^ ERROR: cannot expand to macro definitions
+pub fn a() {}
+#[attr2mac2]
+//~^ ERROR: cannot expand to macro definitions
+pub fn a() {}
+
+mac2mac1!(); //~ ERROR: cannot expand to macro definitions
+mac2mac2!(); //~ ERROR: cannot expand to macro definitions
+
+tricky!();
+//~^ ERROR: cannot expand to macro definitions
+
+fn main() {}
--- /dev/null
+error[E0658]: procedural macros cannot expand to macro definitions (see issue #54727)
+ --> $DIR/more-gates.rs:17:1
+ |
+LL | #[attr2mac1]
+ | ^^^^^^^^^^^^
+ |
+ = help: add #![feature(proc_macro_hygiene)] to the crate attributes to enable
+
+error[E0658]: procedural macros cannot expand to macro definitions (see issue #54727)
+ --> $DIR/more-gates.rs:20:1
+ |
+LL | #[attr2mac2]
+ | ^^^^^^^^^^^^
+ |
+ = help: add #![feature(proc_macro_hygiene)] to the crate attributes to enable
+
+error[E0658]: procedural macros cannot expand to macro definitions (see issue #54727)
+ --> $DIR/more-gates.rs:24:1
+ |
+LL | mac2mac1!(); //~ ERROR: cannot expand to macro definitions
+ | ^^^^^^^^^^^^
+ |
+ = help: add #![feature(proc_macro_hygiene)] to the crate attributes to enable
+
+error[E0658]: procedural macros cannot expand to macro definitions (see issue #54727)
+ --> $DIR/more-gates.rs:25:1
+ |
+LL | mac2mac2!(); //~ ERROR: cannot expand to macro definitions
+ | ^^^^^^^^^^^^
+ |
+ = help: add #![feature(proc_macro_hygiene)] to the crate attributes to enable
+
+error[E0658]: procedural macros cannot expand to macro definitions (see issue #54727)
+ --> $DIR/more-gates.rs:27:1
+ |
+LL | tricky!();
+ | ^^^^^^^^^^
+ |
+ = help: add #![feature(proc_macro_hygiene)] to the crate attributes to enable
+
+error: aborting due to 5 previous errors
+
+For more information about this error, try `rustc --explain E0658`.
--- /dev/null
+// Copyright 2016 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.
+
+// aux-build:derive-a.rs
+
+#![feature(rustc_attrs)]
+#![warn(unused_extern_crates)]
+
+extern crate derive_a;
+//~^ WARN unused extern crate
+
+#[rustc_error]
+fn main() {} //~ ERROR compilation successful
--- /dev/null
+warning: unused extern crate
+ --> $DIR/no-macro-use-attr.rs:16:1
+ |
+LL | extern crate derive_a;
+ | ^^^^^^^^^^^^^^^^^^^^^^ help: remove it
+ |
+note: lint level defined here
+ --> $DIR/no-macro-use-attr.rs:14:9
+ |
+LL | #![warn(unused_extern_crates)]
+ | ^^^^^^^^^^^^^^^^^^^^
+
+error: compilation successful
+ --> $DIR/no-macro-use-attr.rs:20:1
+ |
+LL | fn main() {} //~ ERROR compilation successful
+ | ^^^^^^^^^^^^
+
+error: aborting due to previous error
+
--- /dev/null
+// Copyright 2016 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.
+
+// aux-build:derive-b.rs
+
+#[macro_use]
+extern crate derive_b;
+
+#[B]
+#[C] //~ ERROR attribute `C` is currently unknown to the compiler
+#[B(D)]
+#[B(E = "foo")]
+#[B(arbitrary tokens)]
+#[derive(B)]
+struct B;
+
+fn main() {}
--- /dev/null
+error[E0658]: The attribute `C` is currently unknown to the compiler and may have meaning added to it in the future (see issue #29642)
+ --> $DIR/proc-macro-attributes.rs:17:3
+ |
+LL | #[C] //~ ERROR attribute `C` is currently unknown to the compiler
+ | ^
+ |
+ = help: add #![feature(custom_attribute)] to the crate attributes to enable
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0658`.
--- /dev/null
+// 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.
+
+// aux-build:proc-macro-gates.rs
+// gate-test-proc_macro_hygiene
+
+#![feature(stmt_expr_attributes)]
+
+extern crate proc_macro_gates as foo;
+
+use foo::*;
+
+fn _test_inner() {
+ #![a] //~ ERROR: non-builtin inner attributes are unstable
+}
+
+#[a] //~ ERROR: custom attributes cannot be applied to modules
+mod _test2 {}
+
+mod _test2_inner {
+ #![a] //~ ERROR: custom attributes cannot be applied to modules
+ //~| ERROR: non-builtin inner attributes are unstable
+}
+
+#[a = y] //~ ERROR: must only be followed by a delimiter token
+fn _test3() {}
+
+fn attrs() {
+ // Statement, item
+ #[a] // OK
+ struct S;
+
+ // Statement, macro
+ #[a] //~ ERROR: custom attributes cannot be applied to statements
+ println!();
+
+ // Statement, semi
+ #[a] //~ ERROR: custom attributes cannot be applied to statements
+ S;
+
+ // Statement, local
+ #[a] //~ ERROR: custom attributes cannot be applied to statements
+ let _x = 2;
+
+ // Expr
+ let _x = #[a] 2; //~ ERROR: custom attributes cannot be applied to expressions
+
+ // Opt expr
+ let _x = [#[a] 2]; //~ ERROR: custom attributes cannot be applied to expressions
+
+ // Expr macro
+ let _x = #[a] println!(); //~ ERROR: custom attributes cannot be applied to expressions
+}
+
+fn main() {
+ let _x: m!(u32) = 3; //~ ERROR: procedural macros cannot be expanded to types
+ if let m!(Some(_x)) = Some(3) {} //~ ERROR: procedural macros cannot be expanded to patterns
+
+ m!(struct S;); //~ ERROR: procedural macros cannot be expanded to statements
+ m!(let _x = 3;); //~ ERROR: procedural macros cannot be expanded to statements
+
+ let _x = m!(3); //~ ERROR: procedural macros cannot be expanded to expressions
+ let _x = [m!(3)]; //~ ERROR: procedural macros cannot be expanded to expressions
+}
--- /dev/null
+error[E0658]: non-builtin inner attributes are unstable (see issue #54726)
+ --> $DIR/proc-macro-gates.rs:21:5
+ |
+LL | #![a] //~ ERROR: non-builtin inner attributes are unstable
+ | ^^^^^
+ |
+ = help: add #![feature(custom_inner_attributes)] to the crate attributes to enable
+
+error[E0658]: non-builtin inner attributes are unstable (see issue #54726)
+ --> $DIR/proc-macro-gates.rs:28:5
+ |
+LL | #![a] //~ ERROR: custom attributes cannot be applied to modules
+ | ^^^^^
+ |
+ = help: add #![feature(custom_inner_attributes)] to the crate attributes to enable
+
+error[E0658]: custom attributes cannot be applied to modules (see issue #54727)
+ --> $DIR/proc-macro-gates.rs:24:1
+ |
+LL | #[a] //~ ERROR: custom attributes cannot be applied to modules
+ | ^^^^
+ |
+ = help: add #![feature(proc_macro_hygiene)] to the crate attributes to enable
+
+error[E0658]: custom attributes cannot be applied to modules (see issue #54727)
+ --> $DIR/proc-macro-gates.rs:28:5
+ |
+LL | #![a] //~ ERROR: custom attributes cannot be applied to modules
+ | ^^^^^
+ |
+ = help: add #![feature(proc_macro_hygiene)] to the crate attributes to enable
+
+error: custom attribute invocations must be of the form #[foo] or #[foo(..)], the macro name must only be followed by a delimiter token
+ --> $DIR/proc-macro-gates.rs:32:1
+ |
+LL | #[a = y] //~ ERROR: must only be followed by a delimiter token
+ | ^^^^^^^^
+
+error[E0658]: custom attributes cannot be applied to statements (see issue #54727)
+ --> $DIR/proc-macro-gates.rs:41:5
+ |
+LL | #[a] //~ ERROR: custom attributes cannot be applied to statements
+ | ^^^^
+ |
+ = help: add #![feature(proc_macro_hygiene)] to the crate attributes to enable
+
+error[E0658]: custom attributes cannot be applied to statements (see issue #54727)
+ --> $DIR/proc-macro-gates.rs:45:5
+ |
+LL | #[a] //~ ERROR: custom attributes cannot be applied to statements
+ | ^^^^
+ |
+ = help: add #![feature(proc_macro_hygiene)] to the crate attributes to enable
+
+error[E0658]: custom attributes cannot be applied to statements (see issue #54727)
+ --> $DIR/proc-macro-gates.rs:49:5
+ |
+LL | #[a] //~ ERROR: custom attributes cannot be applied to statements
+ | ^^^^
+ |
+ = help: add #![feature(proc_macro_hygiene)] to the crate attributes to enable
+
+error[E0658]: custom attributes cannot be applied to expressions (see issue #54727)
+ --> $DIR/proc-macro-gates.rs:53:14
+ |
+LL | let _x = #[a] 2; //~ ERROR: custom attributes cannot be applied to expressions
+ | ^^^^
+ |
+ = help: add #![feature(proc_macro_hygiene)] to the crate attributes to enable
+
+error[E0658]: custom attributes cannot be applied to expressions (see issue #54727)
+ --> $DIR/proc-macro-gates.rs:56:15
+ |
+LL | let _x = [#[a] 2]; //~ ERROR: custom attributes cannot be applied to expressions
+ | ^^^^
+ |
+ = help: add #![feature(proc_macro_hygiene)] to the crate attributes to enable
+
+error[E0658]: custom attributes cannot be applied to expressions (see issue #54727)
+ --> $DIR/proc-macro-gates.rs:59:14
+ |
+LL | let _x = #[a] println!(); //~ ERROR: custom attributes cannot be applied to expressions
+ | ^^^^
+ |
+ = help: add #![feature(proc_macro_hygiene)] to the crate attributes to enable
+
+error[E0658]: procedural macros cannot be expanded to types (see issue #54727)
+ --> $DIR/proc-macro-gates.rs:63:13
+ |
+LL | let _x: m!(u32) = 3; //~ ERROR: procedural macros cannot be expanded to types
+ | ^^^^^^^
+ |
+ = help: add #![feature(proc_macro_hygiene)] to the crate attributes to enable
+
+error[E0658]: procedural macros cannot be expanded to patterns (see issue #54727)
+ --> $DIR/proc-macro-gates.rs:64:12
+ |
+LL | if let m!(Some(_x)) = Some(3) {} //~ ERROR: procedural macros cannot be expanded to patterns
+ | ^^^^^^^^^^^^
+ |
+ = help: add #![feature(proc_macro_hygiene)] to the crate attributes to enable
+
+error[E0658]: procedural macros cannot be expanded to statements (see issue #54727)
+ --> $DIR/proc-macro-gates.rs:66:5
+ |
+LL | m!(struct S;); //~ ERROR: procedural macros cannot be expanded to statements
+ | ^^^^^^^^^^^^^^
+ |
+ = help: add #![feature(proc_macro_hygiene)] to the crate attributes to enable
+
+error[E0658]: procedural macros cannot be expanded to statements (see issue #54727)
+ --> $DIR/proc-macro-gates.rs:67:5
+ |
+LL | m!(let _x = 3;); //~ ERROR: procedural macros cannot be expanded to statements
+ | ^^^^^^^^^^^^^^^^
+ |
+ = help: add #![feature(proc_macro_hygiene)] to the crate attributes to enable
+
+error[E0658]: procedural macros cannot be expanded to expressions (see issue #54727)
+ --> $DIR/proc-macro-gates.rs:69:14
+ |
+LL | let _x = m!(3); //~ ERROR: procedural macros cannot be expanded to expressions
+ | ^^^^^
+ |
+ = help: add #![feature(proc_macro_hygiene)] to the crate attributes to enable
+
+error[E0658]: procedural macros cannot be expanded to expressions (see issue #54727)
+ --> $DIR/proc-macro-gates.rs:70:15
+ |
+LL | let _x = [m!(3)]; //~ ERROR: procedural macros cannot be expanded to expressions
+ | ^^^^^
+ |
+ = help: add #![feature(proc_macro_hygiene)] to the crate attributes to enable
+
+error: aborting due to 17 previous errors
+
+For more information about this error, try `rustc --explain E0658`.
--- /dev/null
+// 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.
+
+// aux-build:proc-macro-gates.rs
+
+#![feature(stmt_expr_attributes)]
+
+extern crate proc_macro_gates as foo;
+
+use foo::*;
+
+// NB. these errors aren't the best errors right now, but they're definitely
+// intended to be errors. Somehow using a custom attribute in these positions
+// should either require a feature gate or not be allowed on stable.
+
+fn _test6<#[a] T>() {}
+//~^ ERROR: unknown to the compiler
+
+fn _test7() {
+ match 1 {
+ #[a] //~ ERROR: unknown to the compiler
+ 0 => {}
+ _ => {}
+ }
+}
+
+fn main() {
+}
--- /dev/null
+error[E0658]: The attribute `a` is currently unknown to the compiler and may have meaning added to it in the future (see issue #29642)
+ --> $DIR/proc-macro-gates2.rs:23:11
+ |
+LL | fn _test6<#[a] T>() {}
+ | ^^^^
+ |
+ = help: add #![feature(custom_attribute)] to the crate attributes to enable
+
+error[E0658]: The attribute `a` is currently unknown to the compiler and may have meaning added to it in the future (see issue #29642)
+ --> $DIR/proc-macro-gates2.rs:28:9
+ |
+LL | #[a] //~ ERROR: unknown to the compiler
+ | ^^^^
+ |
+ = help: add #![feature(custom_attribute)] to the crate attributes to enable
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0658`.
--- /dev/null
+// Copyright 2016 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.
+
+// force-host
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+
+pub mod a { //~ `proc-macro` crate types cannot export any items
+ use proc_macro::TokenStream;
+
+ #[proc_macro_derive(B)]
+ pub fn bar(a: TokenStream) -> TokenStream {
+ //~^ ERROR: must currently reside in the root of the crate
+ a
+ }
+}
+
+#[proc_macro_derive(B)]
+fn bar(a: proc_macro::TokenStream) -> proc_macro::TokenStream {
+//~^ ERROR: functions tagged with `#[proc_macro_derive]` must be `pub`
+ a
+}
--- /dev/null
+error: `proc-macro` crate types cannot export any items other than functions tagged with `#[proc_macro_derive]` currently
+ --> $DIR/pub-at-crate-root.rs:18:1
+ |
+LL | / pub mod a { //~ `proc-macro` crate types cannot export any items
+LL | | use proc_macro::TokenStream;
+LL | |
+LL | | #[proc_macro_derive(B)]
+... |
+LL | | }
+LL | | }
+ | |_^
+
+error: functions tagged with `#[proc_macro_derive]` must currently reside in the root of the crate
+ --> $DIR/pub-at-crate-root.rs:22:5
+ |
+LL | / pub fn bar(a: TokenStream) -> TokenStream {
+LL | | //~^ ERROR: must currently reside in the root of the crate
+LL | | a
+LL | | }
+ | |_____^
+
+error: functions tagged with `#[proc_macro_derive]` must be `pub`
+ --> $DIR/pub-at-crate-root.rs:29:1
+ |
+LL | / fn bar(a: proc_macro::TokenStream) -> proc_macro::TokenStream {
+LL | | //~^ ERROR: functions tagged with `#[proc_macro_derive]` must be `pub`
+LL | | a
+LL | | }
+ | |_^
+
+error: aborting due to 3 previous errors
+
--- /dev/null
+// Copyright 2016 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.
+
+// force-host
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+
+use proc_macro::TokenStream;
+
+#[proc_macro_derive(PartialEq)]
+//~^ ERROR: cannot override a built-in #[derive] mode
+pub fn foo(input: TokenStream) -> TokenStream {
+ input
+}
--- /dev/null
+error: cannot override a built-in #[derive] mode
+ --> $DIR/shadow-builtin.rs:20:21
+ |
+LL | #[proc_macro_derive(PartialEq)]
+ | ^^^^^^^^^
+
+error: aborting due to previous error
+
--- /dev/null
+// Copyright 2016 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.
+
+// aux-build:derive-a.rs
+
+#[macro_use]
+extern crate derive_a;
+#[macro_use]
+extern crate derive_a; //~ ERROR the name `derive_a` is defined multiple times
+
+fn main() {}
--- /dev/null
+error[E0259]: the name `derive_a` is defined multiple times
+ --> $DIR/shadow.rs:16:1
+ |
+LL | extern crate derive_a;
+ | ---------------------- previous import of the extern crate `derive_a` here
+LL | #[macro_use]
+LL | extern crate derive_a; //~ ERROR the name `derive_a` is defined multiple times
+ | ^^^^^^^^^^^^^^^^^^^^^^ `derive_a` reimported here
+ |
+ = note: `derive_a` must be defined only once in the type namespace of this module
+help: you can use `as` to change the binding name of the import
+ |
+LL | extern crate derive_a as other_derive_a; //~ ERROR the name `derive_a` is defined multiple times
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0259`.
--- /dev/null
+// Copyright 2016 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.
+
+// error-pattern: cannot mix `proc-macro` crate type with others
+
+// force-host
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+#![crate_type = "rlib"]
--- /dev/null
+error: cannot mix `proc-macro` crate type with others
+
+error: aborting due to previous error
+
--- /dev/null
+// Copyright 2016 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.
+
+// error-pattern: cannot mix `proc-macro` crate type with others
+// compile-flags: --crate-type rlib --crate-type proc-macro
+// force-host
--- /dev/null
+error: cannot mix `proc-macro` crate type with others
+
+error: aborting due to previous error
+