Auto merge of #53053 - petrochenkov:custattr, r=alexcrichton

resolve:  Support custom attributes when macro modularization is enabled

Basically, if resolution of a single-segment attribute is a determined error, then we interpret it as a custom attribute.

Since custom attributes are integrated into general macro resolution, `feature(custom_attribute)` now requires and implicitly enables macro modularization (`feature(use_extern_macros)`).
Actually, a few other "advanced" macro features now implicitly enable macro modularization too (and one bug was found and fixed in process of enabling it).

The first two commits are preliminary cleanups/refactorings.
This commit is contained in:
bors 2018-08-08 08:37:56 +00:00
commit ffb09dfb3a
66 changed files with 295 additions and 320 deletions

View file

@ -0,0 +1,18 @@
// 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.
// Unresolved multi-segment attributes are not treated as custom.
#![feature(custom_attribute, proc_macro_path_invoc)]
mod existent {}
#[existent::nonexistent] //~ ERROR failed to resolve. Could not find `nonexistent` in `existent`
fn main() {}

View file

@ -0,0 +1,9 @@
error[E0433]: failed to resolve. Could not find `nonexistent` in `existent`
--> $DIR/custom-attribute-multisegment.rs:17:13
|
LL | #[existent::nonexistent] //~ ERROR failed to resolve. Could not find `nonexistent` in `existent`
| ^^^^^^^^^^^ Could not find `nonexistent` in `existent`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0433`.

View file

@ -27,9 +27,9 @@ macro_rules! emits_nothing(
#[link(name = "rust_test_helpers", kind = "static")]
extern {
returns_isize!(rust_get_test_int);
//~^ ERROR macro invocations in `extern {}` blocks are experimental.
//~^ ERROR macro invocations in `extern {}` blocks are experimental
takes_u32_returns_u32!(rust_dbg_extern_identity_u32);
//~^ ERROR macro invocations in `extern {}` blocks are experimental.
//~^ ERROR macro invocations in `extern {}` blocks are experimental
emits_nothing!();
//~^ ERROR macro invocations in `extern {}` blocks are experimental.
//~^ ERROR macro invocations in `extern {}` blocks are experimental
}

View file

@ -1,4 +1,4 @@
error[E0658]: macro and proc-macro invocations in `extern {}` blocks are experimental. (see issue #49476)
error[E0658]: macro invocations in `extern {}` blocks are experimental (see issue #49476)
--> $DIR/feature-gate-macros_in_extern.rs:29:5
|
LL | returns_isize!(rust_get_test_int);
@ -6,7 +6,7 @@ LL | returns_isize!(rust_get_test_int);
|
= help: add #![feature(macros_in_extern)] to the crate attributes to enable
error[E0658]: macro and proc-macro invocations in `extern {}` blocks are experimental. (see issue #49476)
error[E0658]: macro invocations in `extern {}` blocks are experimental (see issue #49476)
--> $DIR/feature-gate-macros_in_extern.rs:31:5
|
LL | takes_u32_returns_u32!(rust_dbg_extern_identity_u32);
@ -14,7 +14,7 @@ LL | takes_u32_returns_u32!(rust_dbg_extern_identity_u32);
|
= help: add #![feature(macros_in_extern)] to the crate attributes to enable
error[E0658]: macro and proc-macro invocations in `extern {}` blocks are experimental. (see issue #49476)
error[E0658]: macro invocations in `extern {}` blocks are experimental (see issue #49476)
--> $DIR/feature-gate-macros_in_extern.rs:33:5
|
LL | emits_nothing!();

View file

@ -10,7 +10,7 @@
// aux-build:two_macros.rs
#![feature(item_like_imports, use_extern_macros)]
#![feature(use_extern_macros)]
extern crate two_macros; // two identity macros `m` and `n`

View file

@ -10,5 +10,5 @@
fn main() {
concat!(test!());
//~^ ERROR expected a macro, found non-macro attribute
//~^ ERROR expected a macro, found built-in attribute
}

View file

@ -1,4 +1,4 @@
error: expected a macro, found non-macro attribute
error: expected a macro, found built-in attribute
--> $DIR/issue-11692-2.rs:12:13
|
LL | concat!(test!());

View file

@ -10,9 +10,9 @@
#![feature(use_extern_macros)]
#[derive(inline)] //~ ERROR expected a macro, found non-macro attribute
#[derive(inline)] //~ ERROR expected a macro, found built-in attribute
struct S;
fn main() {
inline!(); //~ ERROR expected a macro, found non-macro attribute
inline!(); //~ ERROR expected a macro, found built-in attribute
}

View file

@ -1,13 +1,13 @@
error: expected a macro, found non-macro attribute
error: expected a macro, found built-in attribute
--> $DIR/macro-path-prelude-fail-3.rs:13:10
|
LL | #[derive(inline)] //~ ERROR expected a macro, found non-macro attribute
LL | #[derive(inline)] //~ ERROR expected a macro, found built-in attribute
| ^^^^^^
error: expected a macro, found non-macro attribute
error: expected a macro, found built-in attribute
--> $DIR/macro-path-prelude-fail-3.rs:17:5
|
LL | inline!(); //~ ERROR expected a macro, found non-macro attribute
LL | inline!(); //~ ERROR expected a macro, found built-in attribute
| ^^^^^^
error: aborting due to 2 previous errors

View file

@ -11,9 +11,5 @@
// If macro modularization (`use_extern_macros`) is not enabled,
// then tool attributes are treated as custom attributes.
// compile-pass
#![feature(custom_attribute)]
#[rustfmt::bar]
#[rustfmt::bar] //~ ERROR attribute `rustfmt::bar` is currently unknown to the compiler
fn main() {}

View file

@ -0,0 +1,11 @@
error[E0658]: The attribute `rustfmt::bar` is currently unknown to the compiler and may have meaning added to it in the future (see issue #29642)
--> $DIR/tool-attributes-disabled-2.rs:14:1
|
LL | #[rustfmt::bar] //~ ERROR attribute `rustfmt::bar` 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`.

View file

@ -8,15 +8,15 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(tool_attributes)]
#![feature(tool_attributes, custom_attribute)]
type A = rustfmt; //~ ERROR expected type, found tool module `rustfmt`
type B = rustfmt::skip; //~ ERROR expected type, found non-macro attribute `rustfmt::skip`
type B = rustfmt::skip; //~ ERROR expected type, found tool attribute `rustfmt::skip`
#[derive(rustfmt)] //~ ERROR cannot find derive macro `rustfmt` in this scope
struct S;
#[rustfmt] //~ ERROR cannot find attribute macro `rustfmt` in this scope
#[rustfmt] // OK, interpreted as a custom attribute
fn check() {}
#[rustfmt::skip] // OK
@ -24,5 +24,5 @@ fn main() {
rustfmt; //~ ERROR expected value, found tool module `rustfmt`
rustfmt!(); //~ ERROR cannot find macro `rustfmt!` in this scope
rustfmt::skip; //~ ERROR expected value, found non-macro attribute `rustfmt::skip`
rustfmt::skip; //~ ERROR expected value, found tool attribute `rustfmt::skip`
}

View file

@ -4,12 +4,6 @@ error: cannot find derive macro `rustfmt` in this scope
LL | #[derive(rustfmt)] //~ ERROR cannot find derive macro `rustfmt` in this scope
| ^^^^^^^
error: cannot find attribute macro `rustfmt` in this scope
--> $DIR/tool-attributes-misplaced-1.rs:19:3
|
LL | #[rustfmt] //~ ERROR cannot find attribute macro `rustfmt` in this scope
| ^^^^^^^
error: cannot find macro `rustfmt!` in this scope
--> $DIR/tool-attributes-misplaced-1.rs:25:5
|
@ -22,10 +16,10 @@ error[E0573]: expected type, found tool module `rustfmt`
LL | type A = rustfmt; //~ ERROR expected type, found tool module `rustfmt`
| ^^^^^^^ not a type
error[E0573]: expected type, found non-macro attribute `rustfmt::skip`
error[E0573]: expected type, found tool attribute `rustfmt::skip`
--> $DIR/tool-attributes-misplaced-1.rs:14:10
|
LL | type B = rustfmt::skip; //~ ERROR expected type, found non-macro attribute `rustfmt::skip`
LL | type B = rustfmt::skip; //~ ERROR expected type, found tool attribute `rustfmt::skip`
| ^^^^^^^^^^^^^ not a type
error[E0423]: expected value, found tool module `rustfmt`
@ -34,13 +28,13 @@ error[E0423]: expected value, found tool module `rustfmt`
LL | rustfmt; //~ ERROR expected value, found tool module `rustfmt`
| ^^^^^^^ not a value
error[E0423]: expected value, found non-macro attribute `rustfmt::skip`
error[E0423]: expected value, found tool attribute `rustfmt::skip`
--> $DIR/tool-attributes-misplaced-1.rs:27:5
|
LL | rustfmt::skip; //~ ERROR expected value, found non-macro attribute `rustfmt::skip`
LL | rustfmt::skip; //~ ERROR expected value, found tool attribute `rustfmt::skip`
| ^^^^^^^^^^^^^ not a value
error: aborting due to 7 previous errors
error: aborting due to 6 previous errors
Some errors occurred: E0423, E0573.
For more information about an error, try `rustc --explain E0423`.

View file

@ -10,9 +10,9 @@
#![feature(tool_attributes)]
#[derive(rustfmt::skip)] //~ ERROR expected a macro, found non-macro attribute
#[derive(rustfmt::skip)] //~ ERROR expected a macro, found tool attribute
struct S;
fn main() {
rustfmt::skip!(); //~ ERROR expected a macro, found non-macro attribute
rustfmt::skip!(); //~ ERROR expected a macro, found tool attribute
}

View file

@ -1,13 +1,13 @@
error: expected a macro, found non-macro attribute
error: expected a macro, found tool attribute
--> $DIR/tool-attributes-misplaced-2.rs:13:10
|
LL | #[derive(rustfmt::skip)] //~ ERROR expected a macro, found non-macro attribute
LL | #[derive(rustfmt::skip)] //~ ERROR expected a macro, found tool attribute
| ^^^^^^^^^^^^^
error: expected a macro, found non-macro attribute
error: expected a macro, found tool attribute
--> $DIR/tool-attributes-misplaced-2.rs:17:5
|
LL | rustfmt::skip!(); //~ ERROR expected a macro, found non-macro attribute
LL | rustfmt::skip!(); //~ ERROR expected a macro, found tool attribute
| ^^^^^^^^^^^^^
error: aborting due to 2 previous errors