add regression test for proc_macro error subdiagnostics

This commit is contained in:
cyrgani 2025-12-11 18:15:15 +00:00
parent 377656d3dd
commit 43fa2a95c9
3 changed files with 41 additions and 0 deletions

View file

@ -0,0 +1,17 @@
#![feature(proc_macro_diagnostic)]
extern crate proc_macro;
use proc_macro::{Diagnostic, Level, Span};
#[proc_macro_attribute]
pub fn proc_emit_err(
_: proc_macro::TokenStream,
input: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
Diagnostic::new(Level::Error, "Parent message")
.span_error(Span::call_site(), "Child message")
.emit();
input
}

View file

@ -0,0 +1,13 @@
//@ proc-macro: sub-error-diag.rs
// Regression test for issue https://github.com/rust-lang/rust/issues/145305, which used to cause an ICE
// due to an assertion in the compiler that errors could not be subdiagnostics.
extern crate sub_error_diag;
//~? ERROR: Parent message
#[sub_error_diag::proc_emit_err]
//~^ ERROR: Child message
fn foo() {}
fn main() {}

View file

@ -0,0 +1,11 @@
error: Parent message
|
error: Child message
--> $DIR/sub-error-diag.rs:9:1
|
LL | #[sub_error_diag::proc_emit_err]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= 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)
error: aborting due to 1 previous error