summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_plugin_impl/src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:06:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:06:31 +0000
commit2ff14448863ac1a1dd9533461708e29aae170c2d (patch)
tree85b9fea2bbfe3f06473cfa381eed11f273b57c5c /compiler/rustc_plugin_impl/src
parentAdding debian version 1.64.0+dfsg1-1. (diff)
downloadrustc-2ff14448863ac1a1dd9533461708e29aae170c2d.tar.xz
rustc-2ff14448863ac1a1dd9533461708e29aae170c2d.zip
Adding debian version 1.65.0+dfsg1-2.debian/1.65.0+dfsg1-2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_plugin_impl/src')
-rw-r--r--compiler/rustc_plugin_impl/src/errors.rs20
-rw-r--r--compiler/rustc_plugin_impl/src/lib.rs3
-rw-r--r--compiler/rustc_plugin_impl/src/load.rs16
3 files changed, 28 insertions, 11 deletions
diff --git a/compiler/rustc_plugin_impl/src/errors.rs b/compiler/rustc_plugin_impl/src/errors.rs
new file mode 100644
index 000000000..2bdb6e4fe
--- /dev/null
+++ b/compiler/rustc_plugin_impl/src/errors.rs
@@ -0,0 +1,20 @@
+//! Errors emitted by plugin_impl
+
+use rustc_macros::SessionDiagnostic;
+use rustc_span::Span;
+
+#[derive(SessionDiagnostic)]
+#[diag(plugin_impl::load_plugin_error)]
+pub struct LoadPluginError {
+ #[primary_span]
+ pub span: Span,
+ pub msg: String,
+}
+
+#[derive(SessionDiagnostic)]
+#[diag(plugin_impl::malformed_plugin_attribute, code = "E0498")]
+pub struct MalformedPluginAttribute {
+ #[primary_span]
+ #[label]
+ pub span: Span,
+}
diff --git a/compiler/rustc_plugin_impl/src/lib.rs b/compiler/rustc_plugin_impl/src/lib.rs
index 1195045bd..9ac27c65d 100644
--- a/compiler/rustc_plugin_impl/src/lib.rs
+++ b/compiler/rustc_plugin_impl/src/lib.rs
@@ -8,9 +8,12 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![recursion_limit = "256"]
+#![deny(rustc::untranslatable_diagnostic)]
+#![deny(rustc::diagnostic_outside_of_impl)]
use rustc_lint::LintStore;
+mod errors;
pub mod load;
/// Structure used to register plugins.
diff --git a/compiler/rustc_plugin_impl/src/load.rs b/compiler/rustc_plugin_impl/src/load.rs
index 618682da4..8e75e969a 100644
--- a/compiler/rustc_plugin_impl/src/load.rs
+++ b/compiler/rustc_plugin_impl/src/load.rs
@@ -1,16 +1,14 @@
//! Used by `rustc` when loading a plugin.
+use crate::errors::{LoadPluginError, MalformedPluginAttribute};
use crate::Registry;
use libloading::Library;
use rustc_ast::Crate;
-use rustc_errors::struct_span_err;
use rustc_metadata::locator;
use rustc_session::cstore::MetadataLoader;
use rustc_session::Session;
use rustc_span::symbol::{sym, Ident};
-use rustc_span::Span;
-use std::borrow::ToOwned;
use std::env;
use std::mem;
use std::path::PathBuf;
@@ -18,12 +16,6 @@ use std::path::PathBuf;
/// Pointer to a registrar function.
type PluginRegistrarFn = fn(&mut Registry<'_>);
-fn call_malformed_plugin_attribute(sess: &Session, span: Span) {
- struct_span_err!(sess, span, E0498, "malformed `plugin` attribute")
- .span_label(span, "malformed attribute")
- .emit();
-}
-
/// Read plugin metadata and dynamically load registrar functions.
pub fn load_plugins(
sess: &Session,
@@ -42,7 +34,9 @@ pub fn load_plugins(
Some(ident) if plugin.is_word() => {
load_plugin(&mut plugins, sess, metadata_loader, ident)
}
- _ => call_malformed_plugin_attribute(sess, plugin.span()),
+ _ => {
+ sess.emit_err(MalformedPluginAttribute { span: plugin.span() });
+ }
}
}
}
@@ -60,7 +54,7 @@ fn load_plugin(
let fun = dylink_registrar(lib).unwrap_or_else(|err| {
// This is fatal: there are almost certainly macros we need inside this crate, so
// continuing would spew "macro undefined" errors.
- sess.span_fatal(ident.span, &err.to_string());
+ sess.emit_fatal(LoadPluginError { span: ident.span, msg: err.to_string() });
});
plugins.push(fun);
}