Skip to content

Commit 173a4a5

Browse files
committed
Auto merge of #62008 - ia0:issues_61053, r=<try>
Add meta-variable checks in macro definitions This is an implementation of #61053. It is not sound (some errors are not reported) and not complete (reports may not be actual errors). This is due to the possibility to define macros in macros in indirect ways. See module documentation of `macro_check` for more details. What remains to be done: - [x] Migrate from an error to an allow-by-default lint. - [x] Add more comments in particular for the handling of nested macros. - [x] Add more tests if needed. - [x] Try to avoid cloning too much (one idea is to use lists on the stack). - [ ] Run crater with deny-by-default lint (measure rate of false positives). - [ ] Remove extra commit for deny-by-default lint - [x] Create a PR to remove the old `question_mark_macro_sep` lint #62160
2 parents 8ec3942 + 7f8abab commit 173a4a5

22 files changed

+961
-72
lines changed

src/librustc/lint/builtin.rs

+7
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,12 @@ pub mod parser {
353353
Warn,
354354
"ill-formed attribute inputs that were previously accepted and used in practice"
355355
}
356+
357+
declare_lint! {
358+
pub META_VARIABLE_MISUSE,
359+
Deny,
360+
"possible meta-variable misuse at macro definition"
361+
}
356362
}
357363

358364
declare_lint! {
@@ -439,6 +445,7 @@ declare_lint_pass! {
439445
MACRO_USE_EXTERN_CRATE,
440446
MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
441447
parser::ILL_FORMED_ATTRIBUTE_INPUT,
448+
parser::META_VARIABLE_MISUSE,
442449
DEPRECATED_IN_FUTURE,
443450
AMBIGUOUS_ASSOCIATED_ITEMS,
444451
NESTED_IMPL_TRAIT,

src/librustc/lint/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::hir::def_id::{CrateNum, LOCAL_CRATE};
2727
use crate::hir::intravisit;
2828
use crate::hir;
2929
use crate::lint::builtin::BuiltinLintDiagnostics;
30-
use crate::lint::builtin::parser::ILL_FORMED_ATTRIBUTE_INPUT;
30+
use crate::lint::builtin::parser::{ILL_FORMED_ATTRIBUTE_INPUT, META_VARIABLE_MISUSE};
3131
use crate::session::{Session, DiagnosticMessageId};
3232
use crate::ty::TyCtxt;
3333
use crate::ty::query::Providers;
@@ -81,6 +81,7 @@ impl Lint {
8181
pub fn from_parser_lint_id(lint_id: BufferedEarlyLintId) -> &'static Self {
8282
match lint_id {
8383
BufferedEarlyLintId::IllFormedAttributeInput => ILL_FORMED_ATTRIBUTE_INPUT,
84+
BufferedEarlyLintId::MetaVariableMisuse => META_VARIABLE_MISUSE,
8485
}
8586
}
8687

src/libsyntax/early_buffered_lints.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use syntax_pos::MultiSpan;
1010
/// passed to `rustc::lint::Lint::from_parser_lint_id` to get a `rustc::lint::Lint`.
1111
pub enum BufferedEarlyLintId {
1212
IllFormedAttributeInput,
13+
MetaVariableMisuse,
1314
}
1415

1516
/// Stores buffered lint info which can later be passed to `librustc`.

0 commit comments

Comments
 (0)