Skip to content

Commit

Permalink
Don't let non-primary spans take priority over primary spans.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarcho committed Feb 21, 2024
1 parent fc52b56 commit d373962
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/rustc_stderr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl RustcSpan {
/// Returns the most expanded line number *in the given file*, if possible.
fn line(&self, file: &Path, primary: bool) -> Option<spanned::Span> {
if let Some(exp) = &self.expansion {
if let Some(line) = exp.span.line(file, primary && !self.is_primary) {
if let Some(line) = exp.span.line(file, !primary || self.is_primary) {
return Some(line);
}
}
Expand Down
3 changes: 2 additions & 1 deletion tests/integrations/basic/Cargo.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ tests/actual_tests/foomp.rs ... ok
tests/actual_tests/joined_above.rs ... ok
tests/actual_tests/joined_below.rs ... ok
tests/actual_tests/joined_mixed.rs ... ok
tests/actual_tests/mac_span.rs ... ok
tests/actual_tests/match_diagnostic_code.rs ... ok
tests/actual_tests/no_rustfix.rs ... ok
tests/actual_tests/stdin.rs ... ok
tests/actual_tests/unicode.rs ... ok
tests/actual_tests/windows_paths.rs ... ok
tests/actual_tests/subdir/aux_proc_macro.rs ... ok

test result: ok. 15 passed;
test result: ok. 16 passed;


running 0 tests
Expand Down
11 changes: 11 additions & 0 deletions tests/integrations/basic/tests/actual_tests/mac_span.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#![deny(unused_variables)]

macro_rules! m {
() => {{
let _x = 0; //~ unused_variables
}};
}

fn main() {
m!();
}
11 changes: 11 additions & 0 deletions tests/integrations/basic/tests/actual_tests/mac_span.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#![deny(unused_variables)]

macro_rules! m {
() => {{
let x = 0; //~ unused_variables
}};
}

fn main() {
m!();
}
18 changes: 18 additions & 0 deletions tests/integrations/basic/tests/actual_tests/mac_span.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error: unused variable: `x`
--> tests/actual_tests/mac_span.rs:5:13
|
5 | let x = 0;
| ^ help: if this is intentional, prefix it with an underscore: `_x`
...
10 | m!();
| ---- in this macro invocation
|
note: the lint level is defined here
--> tests/actual_tests/mac_span.rs:1:9
|
1 | #![deny(unused_variables)]
| ^^^^^^^^^^^^^^^^
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 1 previous error

0 comments on commit d373962

Please sign in to comment.