Be smart about span of parenthesized expression in macro
This commit is contained in:
parent
cdbf01570f
commit
edf1773fb7
@ -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())
|
||||
|
31
src/test/compile-fail/paren-span.rs
Normal file
31
src/test/compile-fail/paren-span.rs
Normal file
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user