Skip to content

Commit 6ec4584

Browse files
committed
Implement checks for meta-variables in macros
1 parent 82abc0d commit 6ec4584

16 files changed

+913
-47
lines changed

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,

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

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)