summaryrefslogtreecommitdiffstats
path: root/src/test/ui-fulldeps/internal-lints/diagnostics.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/ui-fulldeps/internal-lints/diagnostics.rs')
-rw-r--r--src/test/ui-fulldeps/internal-lints/diagnostics.rs30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/test/ui-fulldeps/internal-lints/diagnostics.rs b/src/test/ui-fulldeps/internal-lints/diagnostics.rs
index d6f63d44b..e9e809fa4 100644
--- a/src/test/ui-fulldeps/internal-lints/diagnostics.rs
+++ b/src/test/ui-fulldeps/internal-lints/diagnostics.rs
@@ -1,6 +1,7 @@
// compile-flags: -Z unstable-options
#![crate_type = "lib"]
+#![feature(rustc_attrs)]
#![feature(rustc_private)]
#![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)]
@@ -10,13 +11,15 @@ extern crate rustc_macros;
extern crate rustc_session;
extern crate rustc_span;
-use rustc_errors::{AddSubdiagnostic, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, fluent};
+use rustc_errors::{
+ AddSubdiagnostic, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, Handler, fluent
+};
use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic};
-use rustc_session::{parse::ParseSess, SessionDiagnostic};
+use rustc_session::SessionDiagnostic;
use rustc_span::Span;
#[derive(SessionDiagnostic)]
-#[error(parser::expect_path)]
+#[diag(parser::expect_path)]
struct DeriveSessionDiagnostic {
#[primary_span]
span: Span,
@@ -32,8 +35,8 @@ struct Note {
pub struct UntranslatableInSessionDiagnostic;
impl<'a> SessionDiagnostic<'a, ErrorGuaranteed> for UntranslatableInSessionDiagnostic {
- fn into_diagnostic(self, sess: &'a ParseSess) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
- sess.struct_err("untranslatable diagnostic")
+ fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
+ handler.struct_err("untranslatable diagnostic")
//~^ ERROR diagnostics should be created using translatable messages
}
}
@@ -41,8 +44,8 @@ impl<'a> SessionDiagnostic<'a, ErrorGuaranteed> for UntranslatableInSessionDiagn
pub struct TranslatableInSessionDiagnostic;
impl<'a> SessionDiagnostic<'a, ErrorGuaranteed> for TranslatableInSessionDiagnostic {
- fn into_diagnostic(self, sess: &'a ParseSess) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
- sess.struct_err(fluent::parser::expect_path)
+ fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
+ handler.struct_err(fluent::parser::expect_path)
}
}
@@ -63,11 +66,18 @@ impl AddSubdiagnostic for TranslatableInAddSubdiagnostic {
}
}
-pub fn make_diagnostics<'a>(sess: &'a ParseSess) {
- let _diag = sess.struct_err(fluent::parser::expect_path);
+pub fn make_diagnostics<'a>(handler: &'a Handler) {
+ let _diag = handler.struct_err(fluent::parser::expect_path);
//~^ ERROR diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls
- let _diag = sess.struct_err("untranslatable diagnostic");
+ let _diag = handler.struct_err("untranslatable diagnostic");
//~^ ERROR diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls
//~^^ ERROR diagnostics should be created using translatable messages
}
+
+// Check that `rustc_lint_diagnostics`-annotated functions aren't themselves linted.
+
+#[rustc_lint_diagnostics]
+pub fn skipped_because_of_annotation<'a>(handler: &'a Handler) {
+ let _diag = handler.struct_err("untranslatable diagnostic"); // okay!
+}