2022-06-10 14:50:06 +00:00
|
|
|
// compile-flags: -Z unstable-options
|
|
|
|
|
|
|
|
#![crate_type = "lib"]
|
2022-08-31 11:06:22 +00:00
|
|
|
#![feature(rustc_attrs)]
|
2022-06-10 14:50:06 +00: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 16:05:14 +00:00
|
|
|
use rustc_errors::{
|
2022-09-18 15:46:16 +00:00
|
|
|
AddToDiagnostic, IntoDiagnostic, Diagnostic, DiagnosticBuilder,
|
2022-09-18 15:45:41 +00:00
|
|
|
ErrorGuaranteed, Handler, fluent
|
2022-09-05 16:05:14 +00:00
|
|
|
};
|
2022-09-18 15:47:31 +00:00
|
|
|
use rustc_macros::{Diagnostic, Subdiagnostic};
|
2022-06-10 14:50:06 +00:00
|
|
|
use rustc_span::Span;
|
|
|
|
|
2022-09-18 15:46:56 +00:00
|
|
|
#[derive(Diagnostic)]
|
2022-09-28 09:21:33 +00:00
|
|
|
#[diag(compiletest::example)]
|
2022-09-15 04:01:44 +00:00
|
|
|
struct DeriveDiagnostic {
|
2022-06-10 14:50:06 +00:00
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
}
|
|
|
|
|
2022-09-18 15:47:31 +00:00
|
|
|
#[derive(Subdiagnostic)]
|
2022-09-28 09:21:33 +00:00
|
|
|
#[note(compiletest::example)]
|
2022-06-10 14:50:06 +00:00
|
|
|
struct Note {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
}
|
|
|
|
|
2022-09-15 04:01:44 +00:00
|
|
|
pub struct UntranslatableInIntoDiagnostic;
|
2022-06-10 14:50:06 +00:00
|
|
|
|
2022-09-15 04:01:44 +00:00
|
|
|
impl<'a> IntoDiagnostic<'a, ErrorGuaranteed> for UntranslatableInIntoDiagnostic {
|
2022-09-05 04:15:50 +00:00
|
|
|
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
|
|
|
|
handler.struct_err("untranslatable diagnostic")
|
2022-06-10 14:50:06 +00:00
|
|
|
//~^ ERROR diagnostics should be created using translatable messages
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-15 04:01:44 +00:00
|
|
|
pub struct TranslatableInIntoDiagnostic;
|
2022-06-10 14:50:06 +00:00
|
|
|
|
2022-09-15 04:01:44 +00:00
|
|
|
impl<'a> IntoDiagnostic<'a, ErrorGuaranteed> for TranslatableInIntoDiagnostic {
|
2022-09-05 04:15:50 +00:00
|
|
|
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
|
2022-09-28 09:21:33 +00:00
|
|
|
handler.struct_err(fluent::compiletest::example)
|
2022-06-10 14:50:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-18 15:46:16 +00:00
|
|
|
pub struct UntranslatableInAddToDiagnostic;
|
2022-06-10 14:50:06 +00:00
|
|
|
|
2022-09-18 15:46:16 +00:00
|
|
|
impl AddToDiagnostic for UntranslatableInAddToDiagnostic {
|
2022-06-10 14:50:06 +00:00
|
|
|
fn add_to_diagnostic(self, diag: &mut Diagnostic) {
|
|
|
|
diag.note("untranslatable diagnostic");
|
|
|
|
//~^ ERROR diagnostics should be created using translatable messages
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-18 15:46:16 +00:00
|
|
|
pub struct TranslatableInAddToDiagnostic;
|
2022-06-10 14:50:06 +00:00
|
|
|
|
2022-09-18 15:46:16 +00:00
|
|
|
impl AddToDiagnostic for TranslatableInAddToDiagnostic {
|
2022-06-10 14:50:06 +00:00
|
|
|
fn add_to_diagnostic(self, diag: &mut Diagnostic) {
|
2022-09-28 09:21:33 +00:00
|
|
|
diag.note(fluent::compiletest::note);
|
2022-06-10 14:50:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-05 04:15:50 +00:00
|
|
|
pub fn make_diagnostics<'a>(handler: &'a Handler) {
|
2022-09-28 09:21:33 +00:00
|
|
|
let _diag = handler.struct_err(fluent::compiletest::example);
|
2022-09-18 15:46:16 +00:00
|
|
|
//~^ ERROR diagnostics should only be created in `IntoDiagnostic`/`AddToDiagnostic` impls
|
2022-06-10 14:50:06 +00:00
|
|
|
|
2022-09-05 04:15:50 +00:00
|
|
|
let _diag = handler.struct_err("untranslatable diagnostic");
|
2022-09-18 15:46:16 +00:00
|
|
|
//~^ ERROR diagnostics should only be created in `IntoDiagnostic`/`AddToDiagnostic` impls
|
2022-06-10 14:50:06 +00:00
|
|
|
//~^^ ERROR diagnostics should be created using translatable messages
|
|
|
|
}
|
2022-08-31 11:06:22 +00:00
|
|
|
|
|
|
|
// Check that `rustc_lint_diagnostics`-annotated functions aren't themselves linted.
|
|
|
|
|
|
|
|
#[rustc_lint_diagnostics]
|
2022-09-05 04:15:50 +00:00
|
|
|
pub fn skipped_because_of_annotation<'a>(handler: &'a Handler) {
|
|
|
|
let _diag = handler.struct_err("untranslatable diagnostic"); // okay!
|
2022-08-31 11:06:22 +00:00
|
|
|
}
|