summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorSeo Sanghyeon <sanxiyn@gmail.com>2016-05-19 00:03:00 +0900
committerSeo Sanghyeon <sanxiyn@gmail.com>2016-05-19 00:03:00 +0900
commitedf1773fb7b56b39e68411d87c86f870697b997b (patch)
tree52cdb260e41885dbce7ca887d926f1d99b308136 /src
parentcdbf01570fb8947cecb6c3e7dc16ecaf104b51b6 (diff)
downloadrust-edf1773fb7b56b39e68411d87c86f870697b997b.tar.gz
rust-edf1773fb7b56b39e68411d87c86f870697b997b.zip
Be smart about span of parenthesized expression in macro
Diffstat (limited to 'src')
-rw-r--r--src/librustc/hir/lowering.rs5
-rw-r--r--src/test/compile-fail/paren-span.rs31
2 files changed, 35 insertions, 1 deletions
diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs
index ea47b0924bc..5b539439435 100644
--- a/src/librustc/hir/lowering.rs
+++ b/src/librustc/hir/lowering.rs
@@ -1261,7 +1261,10 @@ impl<'a> LoweringContext<'a> {
                 }
                 ExprKind::Paren(ref ex) => {
                     return self.lower_expr(ex).map(|mut ex| {
-                        ex.span = e.span;
+                        // include parens in span, but only if it is a super-span.
+                        if e.span.contains(ex.span) {
+                            ex.span = e.span;
+                        }
                         // merge attributes into the inner expression.
                         ex.attrs.update(|attrs| {
                             attrs.prepend(e.attrs.clone())
diff --git a/src/test/compile-fail/paren-span.rs b/src/test/compile-fail/paren-span.rs
new file mode 100644
index 00000000000..8ed5050f3de
--- /dev/null
+++ b/src/test/compile-fail/paren-span.rs
@@ -0,0 +1,31 @@
+// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Be smart about span of parenthesized expression in macro.
+
+macro_rules! paren {
+    ($e:expr) => (($e))
+    //            ^^^^ do not highlight here
+}
+
+mod m {
+    pub struct S {
+        x: i32
+    }
+    pub fn make() -> S {
+        S { x: 0 }
+    }
+}
+
+fn main() {
+    let s = m::make();
+    paren!(s.x); //~ ERROR field `x` of struct `m::S` is private
+    //     ^^^ highlight here
+}