Skip to content

Commit

Permalink
Auto merge of #62008 - ia0:issues_61053, r=petrochenkov
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Jul 20, 2019
2 parents 5c26b52 + 6ec4584 commit e9d2227
Show file tree
Hide file tree
Showing 18 changed files with 946 additions and 68 deletions.
7 changes: 7 additions & 0 deletions src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,12 @@ pub mod parser {
Warn,
"ill-formed attribute inputs that were previously accepted and used in practice"
}

declare_lint! {
pub META_VARIABLE_MISUSE,
Allow,
"possible meta-variable misuse at macro definition"
}
}

declare_lint! {
Expand Down Expand Up @@ -448,6 +454,7 @@ declare_lint_pass! {
MACRO_USE_EXTERN_CRATE,
MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
parser::ILL_FORMED_ATTRIBUTE_INPUT,
parser::META_VARIABLE_MISUSE,
DEPRECATED_IN_FUTURE,
AMBIGUOUS_ASSOCIATED_ITEMS,
NESTED_IMPL_TRAIT,
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::hir::def_id::{CrateNum, LOCAL_CRATE};
use crate::hir::intravisit;
use crate::hir;
use crate::lint::builtin::BuiltinLintDiagnostics;
use crate::lint::builtin::parser::ILL_FORMED_ATTRIBUTE_INPUT;
use crate::lint::builtin::parser::{ILL_FORMED_ATTRIBUTE_INPUT, META_VARIABLE_MISUSE};
use crate::session::{Session, DiagnosticMessageId};
use crate::ty::TyCtxt;
use crate::ty::query::Providers;
Expand Down Expand Up @@ -82,6 +82,7 @@ impl Lint {
pub fn from_parser_lint_id(lint_id: BufferedEarlyLintId) -> &'static Self {
match lint_id {
BufferedEarlyLintId::IllFormedAttributeInput => ILL_FORMED_ATTRIBUTE_INPUT,
BufferedEarlyLintId::MetaVariableMisuse => META_VARIABLE_MISUSE,
}
}

Expand Down
1 change: 1 addition & 0 deletions src/libsyntax/early_buffered_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use syntax_pos::MultiSpan;
/// passed to `rustc::lint::Lint::from_parser_lint_id` to get a `rustc::lint::Lint`.
pub enum BufferedEarlyLintId {
IllFormedAttributeInput,
MetaVariableMisuse,
}

/// Stores buffered lint info which can later be passed to `librustc`.
Expand Down
Loading

0 comments on commit e9d2227

Please sign in to comment.