mirror of
https://github.com/rust-lang/rust.git
synced 2025-11-01 13:34:38 +00:00
This eliminates the case in `failed_to_match_macro` to check for a function-like invocation of a macro with no function-like rules. Instead, macro kind mismatches now result in an unresolved macro, and we detect this case in `unresolved_macro_suggestions`, which now carefully distinguishes between a kind mismatch and other errors. This also handles cases of forward-referenced attributes and cyclic attributes. Expand test coverage to include all of these cases.
53 lines
1.4 KiB
Rust
53 lines
1.4 KiB
Rust
#![feature(macro_attr)]
|
|
|
|
macro_rules! local_attr {
|
|
attr() { $($body:tt)* } => {
|
|
compile_error!(concat!("local_attr: ", stringify!($($body)*)));
|
|
};
|
|
//~^^ ERROR: local_attr
|
|
}
|
|
|
|
//~v NOTE: `fn_only` exists, but has no `attr` rules
|
|
macro_rules! fn_only {
|
|
{} => {}
|
|
}
|
|
|
|
//~v NOTE: `attr_only` exists, but has no rules for function-like invocation
|
|
macro_rules! attr_only {
|
|
attr() {} => {}
|
|
}
|
|
|
|
fn main() {
|
|
//~v NOTE: in this expansion of #[local_attr]
|
|
#[local_attr]
|
|
struct S;
|
|
|
|
//~vv ERROR: cannot find macro `local_attr` in this scope
|
|
//~| NOTE: `local_attr` is in scope, but it is an attribute
|
|
local_attr!(arg);
|
|
|
|
//~v ERROR: cannot find attribute `fn_only` in this scope
|
|
#[fn_only]
|
|
struct S;
|
|
|
|
attr_only!(); //~ ERROR: cannot find macro `attr_only` in this scope
|
|
}
|
|
|
|
//~vv ERROR: cannot find attribute `forward_referenced_attr` in this scope
|
|
//~| NOTE: consider moving the definition of `forward_referenced_attr` before this call
|
|
#[forward_referenced_attr]
|
|
struct S;
|
|
|
|
//~v NOTE: a macro with the same name exists, but it appears later
|
|
macro_rules! forward_referenced_attr {
|
|
attr() {} => {}
|
|
}
|
|
|
|
//~vv ERROR: cannot find attribute `cyclic_attr` in this scope
|
|
//~| NOTE: consider moving the definition of `cyclic_attr` before this call
|
|
#[cyclic_attr]
|
|
//~v NOTE: a macro with the same name exists, but it appears later
|
|
macro_rules! cyclic_attr {
|
|
attr() {} => {}
|
|
}
|