diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2018-02-01 11:51:49 -0800 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2018-02-01 11:51:49 -0800 |
| commit | aaec60836761da35a8d0cf6179769eb9bc9f63c3 (patch) | |
| tree | ba16a12cb639464d40d9a97470ee6afe1bf297b6 /src/test | |
| parent | bacb5c58dfdde7c35e99b2b0d8171238cc33cf6c (diff) | |
| download | rust-aaec60836761da35a8d0cf6179769eb9bc9f63c3.tar.gz rust-aaec60836761da35a8d0cf6179769eb9bc9f63c3.zip | |
Minimize weird spans involving macro context
Sometimes the parser attempts to synthesize spans from within a macro context with the span for the captured argument, leading to non-sensical spans with very bad output. Given that an incorrect span is worse than a partially incomplete span, when detecting this situation return only one of the spans without mergin them.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/macros/span-covering-argument-1.rs | 23 | ||||
| -rw-r--r-- | src/test/ui/macros/span-covering-argument-1.stderr | 13 | ||||
| -rw-r--r-- | src/test/ui/span/macro-span-replacement.stderr | 4 |
3 files changed, 38 insertions, 2 deletions
diff --git a/src/test/ui/macros/span-covering-argument-1.rs b/src/test/ui/macros/span-covering-argument-1.rs new file mode 100644 index 00000000000..bfc137fc7b2 --- /dev/null +++ b/src/test/ui/macros/span-covering-argument-1.rs @@ -0,0 +1,23 @@ +// Copyright 2018 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. + +macro_rules! bad { + ($s:ident whatever) => { + { + let $s = 0; + *&mut $s = 0; + //~^ ERROR cannot borrow immutable local variable `foo` as mutable [E0596] + } + } +} + +fn main() { + bad!(foo whatever); +} diff --git a/src/test/ui/macros/span-covering-argument-1.stderr b/src/test/ui/macros/span-covering-argument-1.stderr new file mode 100644 index 00000000000..677d2f10fd6 --- /dev/null +++ b/src/test/ui/macros/span-covering-argument-1.stderr @@ -0,0 +1,13 @@ +error[E0596]: cannot borrow immutable local variable `foo` as mutable + --> $DIR/span-covering-argument-1.rs:15:19 + | +14 | let $s = 0; + | -- consider changing this to `mut $s` +15 | *&mut $s = 0; + | ^^ cannot borrow mutably +... +22 | bad!(foo whatever); + | ------------------- in this macro invocation + +error: aborting due to previous error + diff --git a/src/test/ui/span/macro-span-replacement.stderr b/src/test/ui/span/macro-span-replacement.stderr index 2a0e71e192c..728cd12e2c6 100644 --- a/src/test/ui/span/macro-span-replacement.stderr +++ b/src/test/ui/span/macro-span-replacement.stderr @@ -1,8 +1,8 @@ warning: struct is never used: `S` - --> $DIR/macro-span-replacement.rs:17:9 + --> $DIR/macro-span-replacement.rs:17:14 | 17 | $b $a; //~ WARN struct is never used - | ^^^^^^ + | ^ ... 22 | m!(S struct); | ------------- in this macro invocation |
