Skip to content

Commit c4d5a1e

Browse files
committed
Produce expansion info for more builtin macros
1 parent a59a6d8 commit c4d5a1e

File tree

6 files changed

+15
-5
lines changed

6 files changed

+15
-5
lines changed

src/librustc_lint/builtin.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use std::collections::HashSet;
4444
use syntax::ast;
4545
use syntax::attr;
4646
use syntax::feature_gate::{AttributeGate, AttributeType, Stability, deprecated_attributes};
47-
use syntax_pos::Span;
47+
use syntax_pos::{Span, SyntaxContext};
4848
use syntax::symbol::keywords;
4949

5050
use rustc::hir::{self, PatKind};
@@ -75,9 +75,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for WhileTrue {
7575
if let hir::ExprWhile(ref cond, ..) = e.node {
7676
if let hir::ExprLit(ref lit) = cond.node {
7777
if let ast::LitKind::Bool(true) = lit.node {
78-
cx.span_lint(WHILE_TRUE,
79-
e.span,
80-
"denote infinite loops with loop { ... }");
78+
if lit.span.ctxt() == SyntaxContext::empty() {
79+
cx.span_lint(WHILE_TRUE,
80+
e.span,
81+
"denote infinite loops with loop { ... }");
82+
}
8183
}
8284
}
8385
}

src/libsyntax_ext/cfg.rs

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub fn expand_cfg<'cx>(cx: &mut ExtCtxt,
2424
sp: Span,
2525
tts: &[tokenstream::TokenTree])
2626
-> Box<base::MacResult + 'static> {
27+
let sp = sp.with_ctxt(sp.ctxt().apply_mark(cx.current_expansion.mark));
2728
let mut p = cx.new_parser_from_tts(tts);
2829
let cfg = panictry!(p.parse_meta_item());
2930

src/libsyntax_ext/concat.rs

+1
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,6 @@ pub fn expand_syntax_ext(cx: &mut base::ExtCtxt,
5757
}
5858
}
5959
}
60+
let sp = sp.with_ctxt(sp.ctxt().apply_mark(cx.current_expansion.mark));
6061
base::MacEager::expr(cx.expr_str(sp, Symbol::intern(&accumulator)))
6162
}

src/libsyntax_ext/concat_idents.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,6 @@ pub fn expand_syntax_ext<'cx>(cx: &'cx mut ExtCtxt,
9292

9393
Box::new(Result {
9494
ident: res,
95-
span: sp,
95+
span: sp.with_ctxt(sp.ctxt().apply_mark(cx.current_expansion.mark)),
9696
})
9797
}

src/libsyntax_ext/env.rs

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt,
3232
Some(v) => v,
3333
};
3434

35+
let sp = sp.with_ctxt(sp.ctxt().apply_mark(cx.current_expansion.mark));
3536
let e = match env::var(&*var.as_str()) {
3637
Err(..) => {
3738
cx.expr_path(cx.path_all(sp,

src/test/compile-fail/lint-impl-fn.rs

+5
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,8 @@ mod foo {
3636
fn main() {
3737
while true {} //~ ERROR: infinite loops
3838
}
39+
40+
#[deny(while_true)]
41+
fn bar() {
42+
while cfg!(unix) {} // no error
43+
}

0 commit comments

Comments
 (0)