Rollup merge of #99935 - CAD97:unstable-syntax-lints, r=petrochenkov
Reenable disabled early syntax gates as future-incompatibility lints - MCP: https://github.com/rust-lang/compiler-team/issues/535 The approach taken by this PR is - Introduce a new lint, `unstable_syntax_pre_expansion`, and reenable the early syntax gates to emit it - Use the diagnostic stashing mechanism to stash warnings the early warnings - When the hard error occurs post expansion, steal and cancel the early warning - Don't display any stashed warnings if errors are present to avoid the same noise problem that hiding type ascription errors is avoiding Commits are working commits, but in a coherent steps-to-implement manner. Can be squashed if desired. The preexisting `soft_unstable` lint seems like it would've been a good fit, but it is deny-by-default (appropriate for `#[bench]`) and these gates should be introduced as warn-by-default. It may be desirable to change the stash mechanism's behavior to not flush lint errors in the presence of other errors either (like is done for warnings here), but upgrading a stash-using lint from warn to error perhaps is enough of a request to see the lint that they shouldn't be hidden; additionally, fixing the last error to get new errors thrown at you always feels bad, so if we know the lint errors are present, we should show them. Using a new flag/mechanism for a "weak diagnostic" which is suppressed by other errors may also be desirable over assuming any stashed warnings are "weak," but this is the first user of stashing warnings and seems an appropriate use of stashing (it follows the "know more later to refine the diagnostic" pattern; here we learn that it's in a compiled position) so we get to define what it means to stash a non-hard-error diagnostic. cc `````@petrochenkov````` (seconded MCP)
This commit is contained in:
commit
8828af4d88
19 changed files with 417 additions and 46 deletions
|
@ -3212,6 +3212,56 @@ declare_lint! {
|
|||
};
|
||||
}
|
||||
|
||||
declare_lint! {
|
||||
/// The `unstable_syntax_pre_expansion` lint detects the use of unstable
|
||||
/// syntax that is discarded during attribute expansion.
|
||||
///
|
||||
/// ### Example
|
||||
///
|
||||
/// ```rust
|
||||
/// #[cfg(FALSE)]
|
||||
/// macro foo() {}
|
||||
/// ```
|
||||
///
|
||||
/// {{produces}}
|
||||
///
|
||||
/// ### Explanation
|
||||
///
|
||||
/// The input to active attributes such as `#[cfg]` or procedural macro
|
||||
/// attributes is required to be valid syntax. Previously, the compiler only
|
||||
/// gated the use of unstable syntax features after resolving `#[cfg]` gates
|
||||
/// and expanding procedural macros.
|
||||
///
|
||||
/// To avoid relying on unstable syntax, move the use of unstable syntax
|
||||
/// into a position where the compiler does not parse the syntax, such as a
|
||||
/// functionlike macro.
|
||||
///
|
||||
/// ```rust
|
||||
/// # #![deny(unstable_syntax_pre_expansion)]
|
||||
///
|
||||
/// macro_rules! identity {
|
||||
/// ( $($tokens:tt)* ) => { $($tokens)* }
|
||||
/// }
|
||||
///
|
||||
/// #[cfg(FALSE)]
|
||||
/// identity! {
|
||||
/// macro foo() {}
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// This is a [future-incompatible] lint to transition this
|
||||
/// to a hard error in the future. See [issue #65860] for more details.
|
||||
///
|
||||
/// [issue #65860]: https://github.com/rust-lang/rust/issues/65860
|
||||
/// [future-incompatible]: ../index.md#future-incompatible-lints
|
||||
pub UNSTABLE_SYNTAX_PRE_EXPANSION,
|
||||
Warn,
|
||||
"unstable syntax can change at any point in the future, causing a hard error!",
|
||||
@future_incompatible = FutureIncompatibleInfo {
|
||||
reference: "issue #65860 <https://github.com/rust-lang/rust/issues/65860>",
|
||||
};
|
||||
}
|
||||
|
||||
declare_lint_pass! {
|
||||
/// Does nothing as a lint pass, but registers some `Lint`s
|
||||
/// that are used by other parts of the compiler.
|
||||
|
@ -3280,6 +3330,7 @@ declare_lint_pass! {
|
|||
POINTER_STRUCTURAL_MATCH,
|
||||
NONTRIVIAL_STRUCTURAL_MATCH,
|
||||
SOFT_UNSTABLE,
|
||||
UNSTABLE_SYNTAX_PRE_EXPANSION,
|
||||
INLINE_NO_SANITIZE,
|
||||
BAD_ASM_STYLE,
|
||||
ASM_SUB_REGISTER,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue