Skip to content

Commit 43fa2a9

Browse files
committed
add regression test for proc_macro error subdiagnostics
1 parent 377656d commit 43fa2a9

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#![feature(proc_macro_diagnostic)]
2+
3+
extern crate proc_macro;
4+
5+
use proc_macro::{Diagnostic, Level, Span};
6+
7+
#[proc_macro_attribute]
8+
pub fn proc_emit_err(
9+
_: proc_macro::TokenStream,
10+
input: proc_macro::TokenStream,
11+
) -> proc_macro::TokenStream {
12+
Diagnostic::new(Level::Error, "Parent message")
13+
.span_error(Span::call_site(), "Child message")
14+
.emit();
15+
16+
input
17+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@ proc-macro: sub-error-diag.rs
2+
3+
// Regression test for issue https://github.com/rust-lang/rust/issues/145305, which used to cause an ICE
4+
// due to an assertion in the compiler that errors could not be subdiagnostics.
5+
6+
extern crate sub_error_diag;
7+
8+
//~? ERROR: Parent message
9+
#[sub_error_diag::proc_emit_err]
10+
//~^ ERROR: Child message
11+
fn foo() {}
12+
13+
fn main() {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: Parent message
2+
|
3+
error: Child message
4+
--> $DIR/sub-error-diag.rs:9:1
5+
|
6+
LL | #[sub_error_diag::proc_emit_err]
7+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8+
= note: this error originates in the attribute macro `sub_error_diag::proc_emit_err` (in Nightly builds, run with -Z macro-backtrace for more info)
9+
10+
error: aborting due to 1 previous error
11+

0 commit comments

Comments
 (0)