Skip to content

Commit e9d2227

Browse files
committed
Auto merge of #62008 - ia0:issues_61053, r=petrochenkov
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 5c26b52 + 6ec4584 commit e9d2227

18 files changed

+946
-68
lines changed

Diff for: src/librustc/lint/builtin.rs

+7
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,12 @@ pub mod parser {
362362
Warn,
363363
"ill-formed attribute inputs that were previously accepted and used in practice"
364364
}
365+
366+
declare_lint! {
367+
pub META_VARIABLE_MISUSE,
368+
Allow,
369+
"possible meta-variable misuse at macro definition"
370+
}
365371
}
366372

367373
declare_lint! {
@@ -448,6 +454,7 @@ declare_lint_pass! {
448454
MACRO_USE_EXTERN_CRATE,
449455
MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
450456
parser::ILL_FORMED_ATTRIBUTE_INPUT,
457+
parser::META_VARIABLE_MISUSE,
451458
DEPRECATED_IN_FUTURE,
452459
AMBIGUOUS_ASSOCIATED_ITEMS,
453460
NESTED_IMPL_TRAIT,

Diff for: 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;
@@ -82,6 +82,7 @@ impl Lint {
8282
pub fn from_parser_lint_id(lint_id: BufferedEarlyLintId) -> &'static Self {
8383
match lint_id {
8484
BufferedEarlyLintId::IllFormedAttributeInput => ILL_FORMED_ATTRIBUTE_INPUT,
85+
BufferedEarlyLintId::MetaVariableMisuse => META_VARIABLE_MISUSE,
8586
}
8687
}
8788

Diff for: 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)