Add SEMICOLON_IN_EXPRESSIONS_FROM_MACROS
lint
cc #79813 This PR adds an allow-by-default future-compatibility lint `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS`. It fires when a trailing semicolon in a macro body is ignored due to the macro being used in expression position: ```rust macro_rules! foo { () => { true; // WARN } } fn main() { let val = match true { true => false, _ => foo!() }; } ``` The lint takes its level from the macro call site, and can be allowed for a particular macro by adding `#[allow(semicolon_in_expressions_from_macros)]`. The lint is set to warn for all internal rustc crates (when being built by a stage1 compiler). After the next beta bump, we can enable the lint for the bootstrap compiler as well.
This commit is contained in:
parent
0e190206e2
commit
f9025512e7
10 changed files with 150 additions and 1 deletions
|
@ -1,3 +1,4 @@
|
|||
// ignore-tidy-filelength
|
||||
//! Some lints that are built in to the compiler.
|
||||
//!
|
||||
//! These are the built-in lints that are emitted direct in the main
|
||||
|
@ -2833,6 +2834,52 @@ declare_lint! {
|
|||
"detects `#[unstable]` on stable trait implementations for stable types"
|
||||
}
|
||||
|
||||
declare_lint! {
|
||||
/// The `semicolon_in_expressions_from_macros` lint detects trailing semicolons
|
||||
/// in macro bodies when the macro is invoked in expression position.
|
||||
/// This was previous accepted, but is being phased out.
|
||||
///
|
||||
/// ### Example
|
||||
///
|
||||
/// ```rust,compile_fail
|
||||
/// #![deny(semicolon_in_expressions_from_macros)]
|
||||
/// macro_rules! foo {
|
||||
/// () => { true; }
|
||||
/// }
|
||||
///
|
||||
/// fn main() {
|
||||
/// let val = match true {
|
||||
/// true => false,
|
||||
/// _ => foo!()
|
||||
/// };
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// {{produces}}
|
||||
///
|
||||
/// ### Explanation
|
||||
///
|
||||
/// Previous, Rust ignored trailing semicolon in a macro
|
||||
/// body when a macro was invoked in expression position.
|
||||
/// However, this makes the treatment of semicolons in the language
|
||||
/// inconsistent, and could lead to unexpected runtime behavior
|
||||
/// in some circumstances (e.g. if the macro author expects
|
||||
/// a value to be dropped).
|
||||
///
|
||||
/// This is a [future-incompatible] lint to transition this
|
||||
/// to a hard error in the future. See [issue #79813] for more details.
|
||||
///
|
||||
/// [issue #79813]: https://github.com/rust-lang/rust/issues/79813
|
||||
/// [future-incompatible]: ../index.md#future-incompatible-lints
|
||||
pub SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
|
||||
Allow,
|
||||
"trailing semicolon in macro body used as expression",
|
||||
@future_incompatible = FutureIncompatibleInfo {
|
||||
reference: "issue #79813 <https://github.com/rust-lang/rust/issues/79813>",
|
||||
edition: None,
|
||||
};
|
||||
}
|
||||
|
||||
declare_lint_pass! {
|
||||
/// Does nothing as a lint pass, but registers some `Lint`s
|
||||
/// that are used by other parts of the compiler.
|
||||
|
@ -2920,6 +2967,7 @@ declare_lint_pass! {
|
|||
USELESS_DEPRECATED,
|
||||
UNSUPPORTED_NAKED_FUNCTIONS,
|
||||
MISSING_ABI,
|
||||
SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
|
||||
]
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue