Skip to content

Commit 5a59808

Browse files
committed
Don't let non-primary spans take priority over primary spans.
1 parent fc52b56 commit 5a59808

File tree

5 files changed

+49
-2
lines changed

5 files changed

+49
-2
lines changed

src/rustc_stderr.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,14 @@ impl RustcSpan {
144144
/// Returns the most expanded line number *in the given file*, if possible.
145145
fn line(&self, file: &Path, primary: bool) -> Option<spanned::Span> {
146146
if let Some(exp) = &self.expansion {
147-
if let Some(line) = exp.span.line(file, primary && !self.is_primary) {
147+
if let Some(line) = exp.span.line(file, !primary || self.is_primary) {
148148
return Some(line);
149+
} else if self.file_name != file {
150+
return if !primary && self.is_primary {
151+
exp.span.line(file, false)
152+
} else {
153+
None
154+
};
149155
}
150156
}
151157
((!primary || self.is_primary) && self.file_name == file).then_some(spanned::Span {

tests/integrations/basic/Cargo.stdout

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ tests/actual_tests/foomp.rs ... ok
2020
tests/actual_tests/joined_above.rs ... ok
2121
tests/actual_tests/joined_below.rs ... ok
2222
tests/actual_tests/joined_mixed.rs ... ok
23+
tests/actual_tests/mac_span.rs ... ok
2324
tests/actual_tests/match_diagnostic_code.rs ... ok
2425
tests/actual_tests/no_rustfix.rs ... ok
2526
tests/actual_tests/stdin.rs ... ok
2627
tests/actual_tests/unicode.rs ... ok
2728
tests/actual_tests/windows_paths.rs ... ok
2829
tests/actual_tests/subdir/aux_proc_macro.rs ... ok
2930

30-
test result: ok. 15 passed;
31+
test result: ok. 16 passed;
3132

3233

3334
running 0 tests
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![deny(unused_variables)]
2+
3+
macro_rules! m {
4+
() => {{
5+
let _x = 0; //~ unused_variables
6+
}};
7+
}
8+
9+
fn main() {
10+
m!();
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![deny(unused_variables)]
2+
3+
macro_rules! m {
4+
() => {{
5+
let x = 0; //~ unused_variables
6+
}};
7+
}
8+
9+
fn main() {
10+
m!();
11+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error: unused variable: `x`
2+
--> tests/actual_tests/mac_span.rs:5:13
3+
|
4+
5 | let x = 0;
5+
| ^ help: if this is intentional, prefix it with an underscore: `_x`
6+
...
7+
10 | m!();
8+
| ---- in this macro invocation
9+
|
10+
note: the lint level is defined here
11+
--> tests/actual_tests/mac_span.rs:1:9
12+
|
13+
1 | #![deny(unused_variables)]
14+
| ^^^^^^^^^^^^^^^^
15+
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
16+
17+
error: aborting due to 1 previous error
18+

0 commit comments

Comments
 (0)