From c4d5a1e17ba26ef3c049548470f85538eb94edfc Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Fri, 1 Sep 2017 17:45:46 +0200 Subject: [PATCH] Produce expansion info for more builtin macros --- src/librustc_lint/builtin.rs | 10 ++++++---- src/libsyntax_ext/cfg.rs | 1 + src/libsyntax_ext/concat.rs | 1 + src/libsyntax_ext/concat_idents.rs | 2 +- src/libsyntax_ext/env.rs | 1 + src/test/compile-fail/lint-impl-fn.rs | 5 +++++ 6 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 52b645638b86f..780d34d570170 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -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}; @@ -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 { ... }"); + } } } } diff --git a/src/libsyntax_ext/cfg.rs b/src/libsyntax_ext/cfg.rs index 98da49545f927..1d8dc4064685b 100644 --- a/src/libsyntax_ext/cfg.rs +++ b/src/libsyntax_ext/cfg.rs @@ -24,6 +24,7 @@ pub fn expand_cfg<'cx>(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenTree]) -> Box { + 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()); diff --git a/src/libsyntax_ext/concat.rs b/src/libsyntax_ext/concat.rs index bfe18dc4060c9..c79e7867c5f5e 100644 --- a/src/libsyntax_ext/concat.rs +++ b/src/libsyntax_ext/concat.rs @@ -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))) } diff --git a/src/libsyntax_ext/concat_idents.rs b/src/libsyntax_ext/concat_idents.rs index 6f4c112acb6c6..8d0104e512bfb 100644 --- a/src/libsyntax_ext/concat_idents.rs +++ b/src/libsyntax_ext/concat_idents.rs @@ -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)), }) } diff --git a/src/libsyntax_ext/env.rs b/src/libsyntax_ext/env.rs index affebbabbbda4..fcad065be52bc 100644 --- a/src/libsyntax_ext/env.rs +++ b/src/libsyntax_ext/env.rs @@ -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, diff --git a/src/test/compile-fail/lint-impl-fn.rs b/src/test/compile-fail/lint-impl-fn.rs index 608aec327b63a..54a720d75b5ad 100644 --- a/src/test/compile-fail/lint-impl-fn.rs +++ b/src/test/compile-fail/lint-impl-fn.rs @@ -36,3 +36,8 @@ mod foo { fn main() { while true {} //~ ERROR: infinite loops } + +#[deny(while_true)] +fn bar() { + while cfg!(unix) {} // no error +}