Skip to content

Commit 51fb73b

Browse files
committed
Point at span within local macros even when error happens in nested external macro
``` error[E0308]: mismatched types --> $DIR/macro-span-caller-replacement.rs:5:17 | LL | s = format!("{arg}"); | ^^^^^^^^^^^^^^^^ expected `&str`, found `String` ... LL | macro_with_format!(); | -------------------- in this macro invocation | = note: this error originates in the macro `format` which comes from the expansion of the macro `macro_with_format` (in Nightly builds, run with -Z macro-backtrace for more info) ```
1 parent 7c3ff67 commit 51fb73b

File tree

45 files changed

+520
-145
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+520
-145
lines changed

compiler/rustc_errors/src/emitter.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -473,9 +473,13 @@ pub trait Emitter {
473473
.chain(span.span_labels().iter().map(|sp_label| sp_label.span))
474474
.filter_map(|sp| {
475475
if !sp.is_dummy() && source_map.is_imported(sp) {
476-
let maybe_callsite = sp.source_callsite();
477-
if sp != maybe_callsite {
478-
return Some((sp, maybe_callsite));
476+
let mut span = sp;
477+
while let Some(callsite) = span.parent_callsite() {
478+
span = callsite;
479+
if source_map.is_imported(span) {
480+
continue;
481+
}
482+
return Some((sp, span));
479483
}
480484
}
481485
None

tests/ui/binop/binary-op-suggest-deref.stderr

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,13 +305,19 @@ LL | let _ = FOO & (*"Sized".to_string().into_boxed_str());
305305
help: the following other types implement trait `BitAnd<Rhs>`
306306
--> $SRC_DIR/core/src/ops/bit.rs:LL:COL
307307
|
308-
= note: `&i32` implements `BitAnd<i32>`
308+
= note: `i32` implements `BitAnd`
309+
::: $SRC_DIR/core/src/ops/bit.rs:LL:COL
309310
|
310-
= note: `&i32` implements `BitAnd`
311+
= note: in this macro invocation
312+
--> $SRC_DIR/core/src/internal_macros.rs:LL:COL
313+
|
314+
= note: `&i32` implements `BitAnd<i32>`
315+
::: $SRC_DIR/core/src/internal_macros.rs:LL:COL
311316
|
312317
= note: `i32` implements `BitAnd<&i32>`
318+
::: $SRC_DIR/core/src/internal_macros.rs:LL:COL
313319
|
314-
= note: `i32` implements `BitAnd`
320+
= note: `&i32` implements `BitAnd`
315321
= note: this error originates in the macro `bitand_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
316322

317323
error[E0277]: the size for values of type `str` cannot be known at compilation time

tests/ui/binop/binop-mul-i32-f32.stderr

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@ LL | x * y
88
help: the following other types implement trait `Mul<Rhs>`
99
--> $SRC_DIR/core/src/ops/arith.rs:LL:COL
1010
|
11-
= note: `&i32` implements `Mul<i32>`
11+
= note: `i32` implements `Mul`
12+
::: $SRC_DIR/core/src/ops/arith.rs:LL:COL
1213
|
13-
= note: `&i32` implements `Mul`
14+
= note: in this macro invocation
15+
--> $SRC_DIR/core/src/internal_macros.rs:LL:COL
16+
|
17+
= note: `&i32` implements `Mul<i32>`
18+
::: $SRC_DIR/core/src/internal_macros.rs:LL:COL
1419
|
1520
= note: `i32` implements `Mul<&i32>`
21+
::: $SRC_DIR/core/src/internal_macros.rs:LL:COL
1622
|
17-
= note: `i32` implements `Mul`
23+
= note: `&i32` implements `Mul`
1824
= note: this error originates in the macro `mul_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
1925

2026
error: aborting due to 1 previous error

tests/ui/const-generics/adt_const_params/const_param_ty_bad.stderr

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ LL | check(&mut () as *mut ());
8484
|
8585
help: the trait `ConstParamTy_` is implemented for `()`
8686
--> $SRC_DIR/core/src/marker.rs:LL:COL
87+
::: $SRC_DIR/core/src/marker.rs:LL:COL
88+
|
89+
= note: in this macro invocation
8790
note: required by a bound in `check`
8891
--> $DIR/const_param_ty_bad.rs:4:18
8992
|
@@ -101,6 +104,9 @@ LL | check(&() as *const ());
101104
|
102105
help: the trait `ConstParamTy_` is implemented for `()`
103106
--> $SRC_DIR/core/src/marker.rs:LL:COL
107+
::: $SRC_DIR/core/src/marker.rs:LL:COL
108+
|
109+
= note: in this macro invocation
104110
note: required by a bound in `check`
105111
--> $DIR/const_param_ty_bad.rs:4:18
106112
|

tests/ui/consts/const-eval/const-eval-overflow-3b.stderr

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,19 @@ LL | = [0; (i8::MAX + 1u8) as usize];
1414
help: the following other types implement trait `Add<Rhs>`
1515
--> $SRC_DIR/core/src/ops/arith.rs:LL:COL
1616
|
17-
= note: `&i8` implements `Add<i8>`
17+
= note: `i8` implements `Add`
18+
::: $SRC_DIR/core/src/ops/arith.rs:LL:COL
1819
|
19-
= note: `&i8` implements `Add`
20+
= note: in this macro invocation
21+
--> $SRC_DIR/core/src/internal_macros.rs:LL:COL
22+
|
23+
= note: `&i8` implements `Add<i8>`
24+
::: $SRC_DIR/core/src/internal_macros.rs:LL:COL
2025
|
2126
= note: `i8` implements `Add<&i8>`
27+
::: $SRC_DIR/core/src/internal_macros.rs:LL:COL
2228
|
23-
= note: `i8` implements `Add`
29+
= note: `&i8` implements `Add`
2430
= note: this error originates in the macro `add_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
2531

2632
error: aborting due to 2 previous errors

tests/ui/consts/const-eval/const-eval-overflow-4b.stderr

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,19 @@ LL | : [u32; (i8::MAX as i8 + 1u8) as usize]
1414
help: the following other types implement trait `Add<Rhs>`
1515
--> $SRC_DIR/core/src/ops/arith.rs:LL:COL
1616
|
17-
= note: `&i8` implements `Add<i8>`
17+
= note: `i8` implements `Add`
18+
::: $SRC_DIR/core/src/ops/arith.rs:LL:COL
1819
|
19-
= note: `&i8` implements `Add`
20+
= note: in this macro invocation
21+
--> $SRC_DIR/core/src/internal_macros.rs:LL:COL
22+
|
23+
= note: `&i8` implements `Add<i8>`
24+
::: $SRC_DIR/core/src/internal_macros.rs:LL:COL
2025
|
2126
= note: `i8` implements `Add<&i8>`
27+
::: $SRC_DIR/core/src/internal_macros.rs:LL:COL
2228
|
23-
= note: `i8` implements `Add`
29+
= note: `&i8` implements `Add`
2430
= note: this error originates in the macro `add_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
2531

2632
error[E0604]: only `u8` can be cast as `char`, not `i8`

tests/ui/consts/const-eval/issue-85155.stderr

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ LL | let _ = 1 / ((IMM >= MIN && IMM <= MAX) as usize);
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `post_monomorphization_error::ValidateConstImm::<2, 0, 1>::VALID` failed here
66

77
note: erroneous constant encountered
8-
--> $DIR/auxiliary/post_monomorphization_error.rs:19:5
8+
--> $DIR/auxiliary/post_monomorphization_error.rs:13:17
99
|
10+
LL | let _ = $crate::ValidateConstImm::<$imm, 0, { (1 << 1) - 1 }>::VALID;
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
...
1013
LL | static_assert_imm1!(IMM1);
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
14+
| ------------------------- in this macro invocation
1215
|
1316
= note: this note originates in the macro `static_assert_imm1` (in Nightly builds, run with -Z macro-backtrace for more info)
1417

tests/ui/consts/const-eval/parse_ints.stderr

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@ LL | const _TOO_LOW: () = { u64::from_str_radix("12345ABCD", 1); };
66
|
77
note: inside `core::num::<impl u64>::from_str_radix`
88
--> $SRC_DIR/core/src/num/mod.rs:LL:COL
9+
::: $SRC_DIR/core/src/num/mod.rs:LL:COL
10+
|
11+
= note: in this macro invocation
912
note: inside `core::num::<impl u64>::from_ascii_radix`
1013
--> $SRC_DIR/core/src/num/mod.rs:LL:COL
14+
::: $SRC_DIR/core/src/num/mod.rs:LL:COL
15+
|
16+
= note: in this macro invocation
1117
= note: this error originates in the macro `from_str_int_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
1218

1319
error[E0080]: evaluation panicked: from_ascii_radix: radix must lie in the range `[2, 36]`
@@ -18,8 +24,14 @@ LL | const _TOO_HIGH: () = { u64::from_str_radix("12345ABCD", 37); };
1824
|
1925
note: inside `core::num::<impl u64>::from_str_radix`
2026
--> $SRC_DIR/core/src/num/mod.rs:LL:COL
27+
::: $SRC_DIR/core/src/num/mod.rs:LL:COL
28+
|
29+
= note: in this macro invocation
2130
note: inside `core::num::<impl u64>::from_ascii_radix`
2231
--> $SRC_DIR/core/src/num/mod.rs:LL:COL
32+
::: $SRC_DIR/core/src/num/mod.rs:LL:COL
33+
|
34+
= note: in this macro invocation
2335
= note: this error originates in the macro `from_str_int_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
2436

2537
error: aborting due to 2 previous errors

tests/ui/consts/const-ptr-is-null.stderr

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,16 @@ LL | assert!(!ptr.wrapping_sub(512).is_null());
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `MAYBE_NULL` failed inside this call
66
|
77
note: inside `std::ptr::const_ptr::<impl *const i32>::is_null`
8+
--> $SRC_DIR/core/src/intrinsics/mod.rs:LL:COL
89
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
10+
::: $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
11+
|
12+
= note: in this macro invocation
913
note: inside `std::ptr::const_ptr::<impl *const T>::is_null::compiletime`
14+
--> $SRC_DIR/core/src/panic.rs:LL:COL
1015
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
16+
|
17+
= note: in this macro invocation
1118

1219
error: aborting due to 1 previous error
1320

tests/ui/consts/const_transmute_type_id2.stderr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ LL | assert!(a == b);
55
| ^^^^^^ evaluation of `_` failed inside this call
66
|
77
note: inside `<TypeId as PartialEq>::eq`
8+
--> $SRC_DIR/core/src/intrinsics/mod.rs:LL:COL
89
--> $SRC_DIR/core/src/any.rs:LL:COL
10+
::: $SRC_DIR/core/src/any.rs:LL:COL
11+
|
12+
= note: in this macro invocation
913
note: inside `<TypeId as PartialEq>::eq::compiletime`
1014
--> $SRC_DIR/core/src/any.rs:LL:COL
1115
= note: this error originates in the macro `$crate::intrinsics::const_eval_select` which comes from the expansion of the macro `crate::intrinsics::const_eval_select` (in Nightly builds, run with -Z macro-backtrace for more info)

0 commit comments

Comments
 (0)