resolve: Implement a lint for out-of-scope use of macro_rules
This commit is contained in:
parent
0195758c1a
commit
c4c7859e40
12 changed files with 283 additions and 102 deletions
|
@ -4945,3 +4945,42 @@ declare_lint! {
|
|||
reference: "issue #123757 <https://github.com/rust-lang/rust/issues/123757>",
|
||||
};
|
||||
}
|
||||
|
||||
declare_lint! {
|
||||
/// The `out_of_scope_macro_calls` lint detects `macro_rules` called when they are not in scope,
|
||||
/// above their definition, which may happen in key-value attributes.
|
||||
///
|
||||
/// ### Example
|
||||
///
|
||||
/// ```rust
|
||||
/// #![doc = in_root!()]
|
||||
///
|
||||
/// macro_rules! in_root { () => { "" } }
|
||||
///
|
||||
/// fn main() {}
|
||||
/// ```
|
||||
///
|
||||
/// {{produces}}
|
||||
///
|
||||
/// ### Explanation
|
||||
///
|
||||
/// The scope in which a `macro_rules` item is visible starts at that item and continues
|
||||
/// below it. This is more similar to `let` than to other items, which are in scope both above
|
||||
/// and below their definition.
|
||||
/// Due to a bug `macro_rules` were accidentally in scope inside some key-value attributes
|
||||
/// above their definition. The lint catches such cases.
|
||||
/// To address the issue turn the `macro_rules` into a regularly scoped item by importing it
|
||||
/// with `use`.
|
||||
///
|
||||
/// This is a [future-incompatible] lint to transition this to a
|
||||
/// hard error in the future.
|
||||
///
|
||||
/// [future-incompatible]: ../index.md#future-incompatible-lints
|
||||
pub OUT_OF_SCOPE_MACRO_CALLS,
|
||||
Warn,
|
||||
"detects out of scope calls to `macro_rules` in key-value attributes",
|
||||
@future_incompatible = FutureIncompatibleInfo {
|
||||
reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps,
|
||||
reference: "issue #124535 <https://github.com/rust-lang/rust/issues/124535>",
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue