Produce expansion info for more builtin macros
This commit is contained in:
parent
a59a6d8a56
commit
c4d5a1e17b
6 changed files with 15 additions and 5 deletions
|
@ -44,7 +44,7 @@ use std::collections::HashSet;
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
use syntax::feature_gate::{AttributeGate, AttributeType, Stability, deprecated_attributes};
|
use syntax::feature_gate::{AttributeGate, AttributeType, Stability, deprecated_attributes};
|
||||||
use syntax_pos::Span;
|
use syntax_pos::{Span, SyntaxContext};
|
||||||
use syntax::symbol::keywords;
|
use syntax::symbol::keywords;
|
||||||
|
|
||||||
use rustc::hir::{self, PatKind};
|
use rustc::hir::{self, PatKind};
|
||||||
|
@ -75,9 +75,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for WhileTrue {
|
||||||
if let hir::ExprWhile(ref cond, ..) = e.node {
|
if let hir::ExprWhile(ref cond, ..) = e.node {
|
||||||
if let hir::ExprLit(ref lit) = cond.node {
|
if let hir::ExprLit(ref lit) = cond.node {
|
||||||
if let ast::LitKind::Bool(true) = lit.node {
|
if let ast::LitKind::Bool(true) = lit.node {
|
||||||
cx.span_lint(WHILE_TRUE,
|
if lit.span.ctxt() == SyntaxContext::empty() {
|
||||||
e.span,
|
cx.span_lint(WHILE_TRUE,
|
||||||
"denote infinite loops with loop { ... }");
|
e.span,
|
||||||
|
"denote infinite loops with loop { ... }");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ pub fn expand_cfg<'cx>(cx: &mut ExtCtxt,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
tts: &[tokenstream::TokenTree])
|
tts: &[tokenstream::TokenTree])
|
||||||
-> Box<base::MacResult + 'static> {
|
-> Box<base::MacResult + 'static> {
|
||||||
|
let sp = sp.with_ctxt(sp.ctxt().apply_mark(cx.current_expansion.mark));
|
||||||
let mut p = cx.new_parser_from_tts(tts);
|
let mut p = cx.new_parser_from_tts(tts);
|
||||||
let cfg = panictry!(p.parse_meta_item());
|
let cfg = panictry!(p.parse_meta_item());
|
||||||
|
|
||||||
|
|
|
@ -57,5 +57,6 @@ pub fn expand_syntax_ext(cx: &mut base::ExtCtxt,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let sp = sp.with_ctxt(sp.ctxt().apply_mark(cx.current_expansion.mark));
|
||||||
base::MacEager::expr(cx.expr_str(sp, Symbol::intern(&accumulator)))
|
base::MacEager::expr(cx.expr_str(sp, Symbol::intern(&accumulator)))
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,6 +92,6 @@ pub fn expand_syntax_ext<'cx>(cx: &'cx mut ExtCtxt,
|
||||||
|
|
||||||
Box::new(Result {
|
Box::new(Result {
|
||||||
ident: res,
|
ident: res,
|
||||||
span: sp,
|
span: sp.with_ctxt(sp.ctxt().apply_mark(cx.current_expansion.mark)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt,
|
||||||
Some(v) => v,
|
Some(v) => v,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let sp = sp.with_ctxt(sp.ctxt().apply_mark(cx.current_expansion.mark));
|
||||||
let e = match env::var(&*var.as_str()) {
|
let e = match env::var(&*var.as_str()) {
|
||||||
Err(..) => {
|
Err(..) => {
|
||||||
cx.expr_path(cx.path_all(sp,
|
cx.expr_path(cx.path_all(sp,
|
||||||
|
|
|
@ -36,3 +36,8 @@ mod foo {
|
||||||
fn main() {
|
fn main() {
|
||||||
while true {} //~ ERROR: infinite loops
|
while true {} //~ ERROR: infinite loops
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[deny(while_true)]
|
||||||
|
fn bar() {
|
||||||
|
while cfg!(unix) {} // no error
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue