Stop using IllFormedAttributeInputLint for macro_use
This commit is contained in:
parent
1da1a39c9a
commit
f357e51e89
9 changed files with 64 additions and 30 deletions
|
|
@ -3,7 +3,7 @@ use rustc_hir::attrs::MacroUseArgs;
|
|||
use rustc_session::lint::builtin::INVALID_MACRO_EXPORT_ARGUMENTS;
|
||||
|
||||
use super::prelude::*;
|
||||
use crate::session_diagnostics::IllFormedAttributeInputLint;
|
||||
use crate::session_diagnostics::{AttributeParseErrorReason, IllFormedAttributeInputLint};
|
||||
|
||||
pub(crate) struct MacroEscapeParser;
|
||||
impl<S: Stage> NoArgsAttributeParser<S> for MacroEscapeParser {
|
||||
|
|
@ -102,14 +102,7 @@ impl<S: Stage> AttributeParser<S> for MacroUseParser {
|
|||
}
|
||||
}
|
||||
ArgParser::NameValue(_) => {
|
||||
let suggestions = cx.suggestions();
|
||||
cx.emit_err(IllFormedAttributeInputLint {
|
||||
num_suggestions: suggestions.len(),
|
||||
suggestions: DiagArgValue::StrListSepByAnd(
|
||||
suggestions.into_iter().map(|s| format!("`{s}`").into()).collect(),
|
||||
),
|
||||
span,
|
||||
});
|
||||
cx.expected_list_or_no_args(span);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -468,6 +468,10 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
|
|||
self.emit_parse_error(span, AttributeParseErrorReason::ExpectedList)
|
||||
}
|
||||
|
||||
pub(crate) fn expected_list_or_no_args(&self, span: Span) -> ErrorGuaranteed {
|
||||
self.emit_parse_error(span, AttributeParseErrorReason::ExpectedListOrNoArgs)
|
||||
}
|
||||
|
||||
pub(crate) fn expected_no_args(&self, span: Span) -> ErrorGuaranteed {
|
||||
self.emit_parse_error(span, AttributeParseErrorReason::ExpectedNoArgs)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -519,6 +519,7 @@ pub(crate) enum AttributeParseErrorReason<'a> {
|
|||
ExpectedAtLeastOneArgument,
|
||||
ExpectedSingleArgument,
|
||||
ExpectedList,
|
||||
ExpectedListOrNoArgs,
|
||||
UnexpectedLiteral,
|
||||
ExpectedNameValue(Option<Symbol>),
|
||||
DuplicateKey(Symbol),
|
||||
|
|
@ -591,6 +592,9 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for AttributeParseError<'_> {
|
|||
AttributeParseErrorReason::ExpectedList => {
|
||||
diag.span_label(self.span, "expected this to be a list");
|
||||
}
|
||||
AttributeParseErrorReason::ExpectedListOrNoArgs => {
|
||||
diag.span_label(self.span, "expected a list or no arguments here");
|
||||
}
|
||||
AttributeParseErrorReason::DuplicateKey(key) => {
|
||||
diag.span_label(self.span, format!("found `{key}` used as a key more than once"));
|
||||
diag.code(E0538);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@
|
|||
//~^ NOTE the lint level is defined here
|
||||
|
||||
#[macro_use = 5]
|
||||
//~^ ERROR valid forms for the attribute are `#[macro_use(name1, name2, ...)]` and `#[macro_use]`
|
||||
//~^ ERROR malformed `macro_use` attribute input
|
||||
//~| NOTE expected a list or no arguments here
|
||||
//~| NOTE for more information, visit
|
||||
extern crate std as s1;
|
||||
|
||||
#[macro_use(5)]
|
||||
|
|
|
|||
|
|
@ -1,23 +1,33 @@
|
|||
error[E0469]: imported macro not found
|
||||
--> $DIR/invalid-macro-use.rs:51:13
|
||||
--> $DIR/invalid-macro-use.rs:53:13
|
||||
|
|
||||
LL | #[macro_use(a)]
|
||||
| ^
|
||||
|
||||
error[E0469]: imported macro not found
|
||||
--> $DIR/invalid-macro-use.rs:53:13
|
||||
--> $DIR/invalid-macro-use.rs:55:13
|
||||
|
|
||||
LL | #[macro_use(b)]
|
||||
| ^
|
||||
|
||||
error: valid forms for the attribute are `#[macro_use(name1, name2, ...)]` and `#[macro_use]`
|
||||
error[E0539]: malformed `macro_use` attribute input
|
||||
--> $DIR/invalid-macro-use.rs:4:1
|
||||
|
|
||||
LL | #[macro_use = 5]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^^^^ expected a list or no arguments here
|
||||
|
|
||||
= note: for more information, visit <https://doc.rust-lang.org/reference/macros-by-example.html#the-macro_use-attribute>
|
||||
help: try changing it to one of the following valid forms of the attribute
|
||||
|
|
||||
LL - #[macro_use = 5]
|
||||
LL + #[macro_use(name1, name2, ...)]
|
||||
|
|
||||
LL - #[macro_use = 5]
|
||||
LL + #[macro_use]
|
||||
|
|
||||
|
||||
error[E0539]: malformed `macro_use` attribute input
|
||||
--> $DIR/invalid-macro-use.rs:8:1
|
||||
--> $DIR/invalid-macro-use.rs:10:1
|
||||
|
|
||||
LL | #[macro_use(5)]
|
||||
| ^^^^^^^^^^^^-^^
|
||||
|
|
@ -35,7 +45,7 @@ LL + #[macro_use]
|
|||
|
|
||||
|
||||
error[E0565]: malformed `macro_use` attribute input
|
||||
--> $DIR/invalid-macro-use.rs:14:1
|
||||
--> $DIR/invalid-macro-use.rs:16:1
|
||||
|
|
||||
LL | #[macro_use(a = "b")]
|
||||
| ^^^^^^^^^^^^^^-----^^
|
||||
|
|
@ -53,7 +63,7 @@ LL + #[macro_use]
|
|||
|
|
||||
|
||||
error[E0565]: malformed `macro_use` attribute input
|
||||
--> $DIR/invalid-macro-use.rs:20:1
|
||||
--> $DIR/invalid-macro-use.rs:22:1
|
||||
|
|
||||
LL | #[macro_use(a(b))]
|
||||
| ^^^^^^^^^^^^^---^^
|
||||
|
|
@ -71,7 +81,7 @@ LL + #[macro_use]
|
|||
|
|
||||
|
||||
error[E0539]: malformed `macro_use` attribute input
|
||||
--> $DIR/invalid-macro-use.rs:26:1
|
||||
--> $DIR/invalid-macro-use.rs:28:1
|
||||
|
|
||||
LL | #[macro_use(a::b)]
|
||||
| ^^^^^^^^^^^^----^^
|
||||
|
|
@ -89,13 +99,13 @@ LL + #[macro_use]
|
|||
|
|
||||
|
||||
error: unused attribute
|
||||
--> $DIR/invalid-macro-use.rs:32:1
|
||||
--> $DIR/invalid-macro-use.rs:34:1
|
||||
|
|
||||
LL | #[macro_use(a)]
|
||||
| ^^^^^^^^^^^^^^^ help: remove this attribute
|
||||
|
|
||||
note: attribute also specified here
|
||||
--> $DIR/invalid-macro-use.rs:34:1
|
||||
--> $DIR/invalid-macro-use.rs:36:1
|
||||
|
|
||||
LL | #[macro_use]
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
@ -106,25 +116,25 @@ LL | #![deny(unused_attributes)]
|
|||
| ^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: unused attribute
|
||||
--> $DIR/invalid-macro-use.rs:40:1
|
||||
--> $DIR/invalid-macro-use.rs:42:1
|
||||
|
|
||||
LL | #[macro_use(a)]
|
||||
| ^^^^^^^^^^^^^^^ help: remove this attribute
|
||||
|
|
||||
note: attribute also specified here
|
||||
--> $DIR/invalid-macro-use.rs:38:1
|
||||
--> $DIR/invalid-macro-use.rs:40:1
|
||||
|
|
||||
LL | #[macro_use]
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: unused attribute
|
||||
--> $DIR/invalid-macro-use.rs:46:1
|
||||
--> $DIR/invalid-macro-use.rs:48:1
|
||||
|
|
||||
LL | #[macro_use]
|
||||
| ^^^^^^^^^^^^ help: remove this attribute
|
||||
|
|
||||
note: attribute also specified here
|
||||
--> $DIR/invalid-macro-use.rs:44:1
|
||||
--> $DIR/invalid-macro-use.rs:46:1
|
||||
|
|
||||
LL | #[macro_use]
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
|
|||
|
|
@ -214,7 +214,7 @@ static mut TLS: u8 = 42;
|
|||
#[no_link()]
|
||||
//~^ ERROR malformed
|
||||
#[macro_use = 1]
|
||||
//~^ ERROR valid forms for the attribute are `#[macro_use(name1, name2, ...)]` and `#[macro_use]`
|
||||
//~^ ERROR malformed
|
||||
extern crate wloop;
|
||||
//~^ ERROR can't find crate for `wloop` [E0463]
|
||||
|
||||
|
|
|
|||
|
|
@ -614,11 +614,21 @@ LL | #[non_exhaustive = 1]
|
|||
| | didn't expect any arguments here
|
||||
| help: must be of the form: `#[non_exhaustive]`
|
||||
|
||||
error: valid forms for the attribute are `#[macro_use(name1, name2, ...)]` and `#[macro_use]`
|
||||
error[E0539]: malformed `macro_use` attribute input
|
||||
--> $DIR/malformed-attrs.rs:216:1
|
||||
|
|
||||
LL | #[macro_use = 1]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^^^^ expected a list or no arguments here
|
||||
|
|
||||
= note: for more information, visit <https://doc.rust-lang.org/reference/macros-by-example.html#the-macro_use-attribute>
|
||||
help: try changing it to one of the following valid forms of the attribute
|
||||
|
|
||||
LL - #[macro_use = 1]
|
||||
LL + #[macro_use(name1, name2, ...)]
|
||||
|
|
||||
LL - #[macro_use = 1]
|
||||
LL + #[macro_use]
|
||||
|
|
||||
|
||||
error: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]`
|
||||
--> $DIR/malformed-attrs.rs:221:1
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ mod macro_escape {
|
|||
//~^ ERROR arguments to `macro_use` are not allowed here
|
||||
|
||||
#[macro_use = "2700"] struct S;
|
||||
//~^ ERROR valid forms for the attribute are `#[macro_use(name1, name2, ...)]` and `#[macro_use]`
|
||||
//~^ ERROR malformed
|
||||
//~| WARN cannot be used on
|
||||
//~| WARN previously accepted
|
||||
|
||||
|
|
|
|||
|
|
@ -16,11 +16,21 @@ error: arguments to `macro_use` are not allowed here
|
|||
LL | #![macro_use(my_macro)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: valid forms for the attribute are `#[macro_use(name1, name2, ...)]` and `#[macro_use]`
|
||||
error[E0539]: malformed `macro_use` attribute input
|
||||
--> $DIR/issue-43106-gating-of-macro_use.rs:15:5
|
||||
|
|
||||
LL | #[macro_use = "2700"] struct S;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ expected a list or no arguments here
|
||||
|
|
||||
= note: for more information, visit <https://doc.rust-lang.org/reference/macros-by-example.html#the-macro_use-attribute>
|
||||
help: try changing it to one of the following valid forms of the attribute
|
||||
|
|
||||
LL - #[macro_use = "2700"] struct S;
|
||||
LL + #[macro_use(name1, name2, ...)] struct S;
|
||||
|
|
||||
LL - #[macro_use = "2700"] struct S;
|
||||
LL + #[macro_use] struct S;
|
||||
|
|
||||
|
||||
warning: `#[macro_use]` attribute cannot be used on structs
|
||||
--> $DIR/issue-43106-gating-of-macro_use.rs:15:5
|
||||
|
|
@ -61,3 +71,4 @@ LL | #[macro_use] impl S { }
|
|||
|
||||
error: aborting due to 4 previous errors; 4 warnings emitted
|
||||
|
||||
For more information about this error, try `rustc --explain E0539`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue