File tree Expand file tree Collapse file tree 5 files changed +49
-2
lines changed
Expand file tree Collapse file tree 5 files changed +49
-2
lines changed Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff line change @@ -20,14 +20,15 @@ tests/actual_tests/foomp.rs ... ok
2020tests/actual_tests/joined_above.rs ... ok
2121tests/actual_tests/joined_below.rs ... ok
2222tests/actual_tests/joined_mixed.rs ... ok
23+ tests/actual_tests/mac_span.rs ... ok
2324tests/actual_tests/match_diagnostic_code.rs ... ok
2425tests/actual_tests/no_rustfix.rs ... ok
2526tests/actual_tests/stdin.rs ... ok
2627tests/actual_tests/unicode.rs ... ok
2728tests/actual_tests/windows_paths.rs ... ok
2829tests/actual_tests/subdir/aux_proc_macro.rs ... ok
2930
30- test result: ok. 15 passed;
31+ test result: ok. 16 passed;
3132
3233
3334running 0 tests
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+
You can’t perform that action at this time.
0 commit comments