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;
|
2023-04-16 12:33:00 +00:00
|
|
|
extern crate rustc_fluent_macro;
|
2022-06-10 14:50:06 +00:00
|
|
|
extern crate rustc_macros;
|
|
|
|
extern crate rustc_session;
|
|
|
|
extern crate rustc_span;
|
|
|
|
|
2022-09-05 16:05:14 +00:00
|
|
|
use rustc_errors::{
|
2023-12-18 03:12:39 +00:00
|
|
|
AddToDiagnostic, Diagnostic, DiagnosticBuilder, DiagnosticMessage, EmissionGuarantee, DiagCtxt,
|
2024-02-06 05:35:19 +00:00
|
|
|
IntoDiagnostic, Level, SubdiagnosticMessageOp,
|
2022-09-05 16:05:14 +00:00
|
|
|
};
|
2023-04-16 12:33:00 +00:00
|
|
|
use rustc_macros::{Diagnostic, Subdiagnostic};
|
2022-06-10 14:50:06 +00:00
|
|
|
use rustc_span::Span;
|
|
|
|
|
2023-11-21 22:53:07 +00:00
|
|
|
rustc_fluent_macro::fluent_messages! { "./diagnostics.ftl" }
|
2022-10-13 09:13:02 +00:00
|
|
|
|
2022-09-18 15:46:56 +00:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 09:13:02 +00:00
|
|
|
#[diag(no_crate_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-10-13 09:13:02 +00:00
|
|
|
#[note(no_crate_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
|
|
|
|
2023-12-18 03:12:39 +00:00
|
|
|
impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for UntranslatableInIntoDiagnostic {
|
|
|
|
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G> {
|
|
|
|
DiagnosticBuilder::new(dcx, level, "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
|
|
|
|
2023-12-18 03:12:39 +00:00
|
|
|
impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for TranslatableInIntoDiagnostic {
|
|
|
|
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G> {
|
|
|
|
DiagnosticBuilder::new(dcx, level, crate::fluent_generated::no_crate_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 {
|
2024-02-06 05:35:19 +00:00
|
|
|
fn add_to_diagnostic_with<F: SubdiagnosticMessageOp>(self, diag: &mut Diagnostic, _: F)
|
2022-10-03 13:09:05 +00:00
|
|
|
{
|
2022-06-10 14:50:06 +00:00
|
|
|
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 {
|
2024-02-06 05:35:19 +00:00
|
|
|
fn add_to_diagnostic_with<F: SubdiagnosticMessageOp>(self, diag: &mut Diagnostic, _: F) {
|
2022-10-13 09:13:02 +00:00
|
|
|
diag.note(crate::fluent_generated::no_crate_note);
|
2022-06-10 14:50:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-18 03:13:53 +00:00
|
|
|
pub fn make_diagnostics<'a>(dcx: &'a DiagCtxt) {
|
|
|
|
let _diag = dcx.struct_err(crate::fluent_generated::no_crate_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
|
|
|
|
2023-12-18 03:13:53 +00:00
|
|
|
let _diag = dcx.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]
|
2023-12-18 03:13:53 +00:00
|
|
|
pub fn skipped_because_of_annotation<'a>(dcx: &'a DiagCtxt) {
|
|
|
|
let _diag = dcx.struct_err("untranslatable diagnostic"); // okay!
|
2022-08-31 11:06:22 +00:00
|
|
|
}
|