2022-06-10 15:50:06 +01:00
|
|
|
// compile-flags: -Z unstable-options
|
|
|
|
|
|
|
|
#![crate_type = "lib"]
|
2022-08-31 12:06:22 +01:00
|
|
|
#![feature(rustc_attrs)]
|
2022-06-10 15:50:06 +01:00
|
|
|
#![feature(rustc_private)]
|
|
|
|
#![deny(rustc::untranslatable_diagnostic)]
|
|
|
|
#![deny(rustc::diagnostic_outside_of_impl)]
|
|
|
|
|
|
|
|
extern crate rustc_errors;
|
|
|
|
extern crate rustc_macros;
|
|
|
|
extern crate rustc_session;
|
|
|
|
extern crate rustc_span;
|
|
|
|
|
2022-09-05 00:15:50 -04:00
|
|
|
use rustc_errors::{AddSubdiagnostic, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, Handler, fluent};
|
2022-06-10 15:50:06 +01:00
|
|
|
use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic};
|
2022-09-05 00:15:50 -04:00
|
|
|
use rustc_session::SessionDiagnostic;
|
2022-06-10 15:50:06 +01:00
|
|
|
use rustc_span::Span;
|
|
|
|
|
|
|
|
#[derive(SessionDiagnostic)]
|
2022-08-19 15:40:48 +02:00
|
|
|
#[diag(parser::expect_path)]
|
2022-06-10 15:50:06 +01:00
|
|
|
struct DeriveSessionDiagnostic {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(SessionSubdiagnostic)]
|
2022-06-23 16:12:52 +01:00
|
|
|
#[note(parser::add_paren)]
|
2022-06-10 15:50:06 +01:00
|
|
|
struct Note {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct UntranslatableInSessionDiagnostic;
|
|
|
|
|
|
|
|
impl<'a> SessionDiagnostic<'a, ErrorGuaranteed> for UntranslatableInSessionDiagnostic {
|
2022-09-05 00:15:50 -04:00
|
|
|
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
|
|
|
|
handler.struct_err("untranslatable diagnostic")
|
2022-06-10 15:50:06 +01:00
|
|
|
//~^ ERROR diagnostics should be created using translatable messages
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct TranslatableInSessionDiagnostic;
|
|
|
|
|
|
|
|
impl<'a> SessionDiagnostic<'a, ErrorGuaranteed> for TranslatableInSessionDiagnostic {
|
2022-09-05 00:15:50 -04:00
|
|
|
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
|
|
|
|
handler.struct_err(fluent::parser::expect_path)
|
2022-06-10 15:50:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct UntranslatableInAddSubdiagnostic;
|
|
|
|
|
|
|
|
impl AddSubdiagnostic for UntranslatableInAddSubdiagnostic {
|
|
|
|
fn add_to_diagnostic(self, diag: &mut Diagnostic) {
|
|
|
|
diag.note("untranslatable diagnostic");
|
|
|
|
//~^ ERROR diagnostics should be created using translatable messages
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct TranslatableInAddSubdiagnostic;
|
|
|
|
|
|
|
|
impl AddSubdiagnostic for TranslatableInAddSubdiagnostic {
|
|
|
|
fn add_to_diagnostic(self, diag: &mut Diagnostic) {
|
|
|
|
diag.note(fluent::typeck::note);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-05 00:15:50 -04:00
|
|
|
pub fn make_diagnostics<'a>(handler: &'a Handler) {
|
|
|
|
let _diag = handler.struct_err(fluent::parser::expect_path);
|
2022-06-10 15:50:06 +01:00
|
|
|
//~^ ERROR diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls
|
|
|
|
|
2022-09-05 00:15:50 -04:00
|
|
|
let _diag = handler.struct_err("untranslatable diagnostic");
|
2022-06-10 15:50:06 +01:00
|
|
|
//~^ ERROR diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls
|
|
|
|
//~^^ ERROR diagnostics should be created using translatable messages
|
|
|
|
}
|
2022-08-31 12:06:22 +01:00
|
|
|
|
|
|
|
// Check that `rustc_lint_diagnostics`-annotated functions aren't themselves linted.
|
|
|
|
|
|
|
|
#[rustc_lint_diagnostics]
|
2022-09-05 00:15:50 -04:00
|
|
|
pub fn skipped_because_of_annotation<'a>(handler: &'a Handler) {
|
|
|
|
let _diag = handler.struct_err("untranslatable diagnostic"); // okay!
|
2022-08-31 12:06:22 +01:00
|
|
|
}
|