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