提交 0ef4098a 编写于 作者: C Chayim Refael Friedman 提交者: GitHub

Do not suggest adding semicolon/changing delimiters for macros in item...

Do not suggest adding semicolon/changing delimiters for macros in item position that originates in macros
上级 b31f9cc2
......@@ -1775,30 +1775,34 @@ fn report_invalid_macro_expansion_item(&self, args: &MacArgs) {
span,
"macros that expand to items must be delimited with braces or followed by a semicolon",
);
if self.unclosed_delims.is_empty() {
let DelimSpan { open, close } = match args {
MacArgs::Empty | MacArgs::Eq(..) => unreachable!(),
MacArgs::Delimited(dspan, ..) => *dspan,
};
err.multipart_suggestion(
"change the delimiters to curly braces",
vec![(open, "{".to_string()), (close, '}'.to_string())],
Applicability::MaybeIncorrect,
);
} else {
// FIXME: This will make us not emit the help even for declarative
// macros within the same crate (that we can fix), which is sad.
if !span.from_expansion() {
if self.unclosed_delims.is_empty() {
let DelimSpan { open, close } = match args {
MacArgs::Empty | MacArgs::Eq(..) => unreachable!(),
MacArgs::Delimited(dspan, ..) => *dspan,
};
err.multipart_suggestion(
"change the delimiters to curly braces",
vec![(open, "{".to_string()), (close, '}'.to_string())],
Applicability::MaybeIncorrect,
);
} else {
err.span_suggestion(
span,
"change the delimiters to curly braces",
" { /* items */ }",
Applicability::HasPlaceholders,
);
}
err.span_suggestion(
span,
"change the delimiters to curly braces",
" { /* items */ }",
Applicability::HasPlaceholders,
span.shrink_to_hi(),
"add a semicolon",
';',
Applicability::MaybeIncorrect,
);
}
err.span_suggestion(
span.shrink_to_hi(),
"add a semicolon",
';',
Applicability::MaybeIncorrect,
);
err.emit();
}
......
// force-host
// no-prefer-dynamic
#![crate_type = "proc-macro"]
extern crate proc_macro;
use proc_macro::TokenStream;
fn compile_error() -> TokenStream {
r#"compile_error!("")"#.parse().unwrap()
}
#[proc_macro_derive(MyTrait)]
pub fn derive(input: TokenStream) -> TokenStream {
compile_error()
}
#[proc_macro_attribute]
pub fn attribute_macro(_attr: TokenStream, mut input: TokenStream) -> TokenStream {
input.extend(compile_error());
input
}
#[proc_macro]
pub fn fn_macro(_item: TokenStream) -> TokenStream {
compile_error()
}
// aux-build: issue-91800-macro.rs
#[macro_use]
extern crate issue_91800_macro;
#[derive(MyTrait)]
//~^ ERROR macros that expand to items must be delimited with braces or followed by a semicolon
//~| ERROR proc-macro derive produced unparseable tokens
#[attribute_macro]
//~^ ERROR macros that expand to items must be delimited with braces or followed by a semicolon
struct MyStruct;
fn_macro! {}
//~^ ERROR macros that expand to items must be delimited with braces or followed by a semicolon
fn main() {}
error: macros that expand to items must be delimited with braces or followed by a semicolon
--> $DIR/issue-91800.rs:6:10
|
LL | #[derive(MyTrait)]
| ^^^^^^^
|
= note: this error originates in the derive macro `MyTrait` (in Nightly builds, run with -Z macro-backtrace for more info)
error: proc-macro derive produced unparseable tokens
--> $DIR/issue-91800.rs:6:10
|
LL | #[derive(MyTrait)]
| ^^^^^^^
error:
--> $DIR/issue-91800.rs:6:10
|
LL | #[derive(MyTrait)]
| ^^^^^^^
|
= note: this error originates in the derive macro `MyTrait` (in Nightly builds, run with -Z macro-backtrace for more info)
error: macros that expand to items must be delimited with braces or followed by a semicolon
--> $DIR/issue-91800.rs:9:1
|
LL | #[attribute_macro]
| ^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the attribute macro `attribute_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
error:
--> $DIR/issue-91800.rs:9:1
|
LL | #[attribute_macro]
| ^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the attribute macro `attribute_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
error: macros that expand to items must be delimited with braces or followed by a semicolon
--> $DIR/issue-91800.rs:13:1
|
LL | fn_macro! {}
| ^^^^^^^^^^^^
|
= note: this error originates in the macro `fn_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
error:
--> $DIR/issue-91800.rs:13:1
|
LL | fn_macro! {}
| ^^^^^^^^^^^^
|
= note: this error originates in the macro `fn_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 7 previous errors
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册