Skip to content

Commit

Permalink
Auto merge of #44248 - oli-obk:spans, r=jseyfried
Browse files Browse the repository at this point in the history
Produce expansion info for more builtin macros

r? @jseyfried

fixes #43268
  • Loading branch information
bors committed Sep 5, 2017
2 parents 22d6598 + c4d5a1e commit 2f681bf
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/librustc_lint/builtin.rs
Expand Up @@ -44,7 +44,7 @@ use std::collections::HashSet;
use syntax::ast;
use syntax::attr;
use syntax::feature_gate::{AttributeGate, AttributeType, Stability, deprecated_attributes};
use syntax_pos::Span;
use syntax_pos::{Span, SyntaxContext};
use syntax::symbol::keywords;

use rustc::hir::{self, PatKind};
Expand Down Expand Up @@ -75,9 +75,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for WhileTrue {
if let hir::ExprWhile(ref cond, ..) = e.node {
if let hir::ExprLit(ref lit) = cond.node {
if let ast::LitKind::Bool(true) = lit.node {
cx.span_lint(WHILE_TRUE,
e.span,
"denote infinite loops with loop { ... }");
if lit.span.ctxt() == SyntaxContext::empty() {
cx.span_lint(WHILE_TRUE,
e.span,
"denote infinite loops with loop { ... }");
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/libsyntax_ext/cfg.rs
Expand Up @@ -24,6 +24,7 @@ pub fn expand_cfg<'cx>(cx: &mut ExtCtxt,
sp: Span,
tts: &[tokenstream::TokenTree])
-> 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 cfg = panictry!(p.parse_meta_item());

Expand Down
1 change: 1 addition & 0 deletions src/libsyntax_ext/concat.rs
Expand Up @@ -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)))
}
2 changes: 1 addition & 1 deletion src/libsyntax_ext/concat_idents.rs
Expand Up @@ -92,6 +92,6 @@ pub fn expand_syntax_ext<'cx>(cx: &'cx mut ExtCtxt,

Box::new(Result {
ident: res,
span: sp,
span: sp.with_ctxt(sp.ctxt().apply_mark(cx.current_expansion.mark)),
})
}
1 change: 1 addition & 0 deletions src/libsyntax_ext/env.rs
Expand Up @@ -32,6 +32,7 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt,
Some(v) => v,
};

let sp = sp.with_ctxt(sp.ctxt().apply_mark(cx.current_expansion.mark));
let e = match env::var(&*var.as_str()) {
Err(..) => {
cx.expr_path(cx.path_all(sp,
Expand Down
5 changes: 5 additions & 0 deletions src/test/compile-fail/lint-impl-fn.rs
Expand Up @@ -36,3 +36,8 @@ mod foo {
fn main() {
while true {} //~ ERROR: infinite loops
}

#[deny(while_true)]
fn bar() {
while cfg!(unix) {} // no error
}

0 comments on commit 2f681bf

Please sign in to comment.