]> git.lizzy.rs Git - rust.git/commitdiff
Produce expansion info for more builtin macros
authorOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Fri, 1 Sep 2017 15:45:46 +0000 (17:45 +0200)
committerOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Mon, 4 Sep 2017 09:03:19 +0000 (11:03 +0200)
src/librustc_lint/builtin.rs
src/libsyntax_ext/cfg.rs
src/libsyntax_ext/concat.rs
src/libsyntax_ext/concat_idents.rs
src/libsyntax_ext/env.rs
src/test/compile-fail/lint-impl-fn.rs

index 52b645638b86f37377a2829c9e2c729af1036500..780d34d570170247f5faf8ffb64114afa02f52cd 100644 (file)
@@ -44,7 +44,7 @@
 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 @@ fn check_expr(&mut self, cx: &LateContext, e: &hir::Expr) {
         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 { ... }");
+                    }
                 }
             }
         }
index 98da49545f9272c3dac300ac81ca78d11843493a..1d8dc4064685bdc06a34e2d70e150c2ad172c670 100644 (file)
@@ -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());
 
index bfe18dc4060c929820c2a6c363bf213c84193846..c79e7867c5f5ef8602bdd2defde8642ba5b8b0cb 100644 (file)
@@ -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)))
 }
index 6f4c112acb6c6430eadb8b34608e2c08bdb5ae8c..8d0104e512bfb41cee35e57c50110faab655fcdf 100644 (file)
@@ -92,6 +92,6 @@ fn make_ty(self: Box<Self>) -> Option<P<ast::Ty>> {
 
     Box::new(Result {
         ident: res,
-        span: sp,
+        span: sp.with_ctxt(sp.ctxt().apply_mark(cx.current_expansion.mark)),
     })
 }
index affebbabbbda4d22398157c6513ea5d7bf933860..fcad065be52bcaf1868a5594dc95e1ea5d89fea5 100644 (file)
@@ -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,
index 608aec327b63ac4ddf3f4d6e31910ac249070199..54a720d75b5ad1a067a78c1c53bf12ec79a70f99 100644 (file)
@@ -36,3 +36,8 @@ fn bar(&self) { while true {} }
 fn main() {
     while true {} //~ ERROR: infinite loops
 }
+
+#[deny(while_true)]
+fn bar() {
+    while cfg!(unix) {} // no error
+}