about summary refs log tree commit diff
path: root/compiler/rustc_plugin_impl
diff options
context:
space:
mode:
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>2022-08-23 20:40:04 +0530
committerGitHub <noreply@github.com>2022-08-23 20:40:04 +0530
commit35f2d125ca6194cd4b6eabdf19d7c49f050eab28 (patch)
tree0c1319a576dec756e8fc7b234b9c76aa8470335f /compiler/rustc_plugin_impl
parentf42cdf76e16693b5d5e677a41dd31c7d5cc42a14 (diff)
parent8c2413c4c609127db344044d6740c9de03aa7ce2 (diff)
downloadrust-35f2d125ca6194cd4b6eabdf19d7c49f050eab28.tar.gz
rust-35f2d125ca6194cd4b6eabdf19d7c49f050eab28.zip
Rollup merge of #100768 - Facel3ss1:plugin-impl-translation, r=davidtwco
Migrate `rustc_plugin_impl` to `SessionDiagnostic`

Migration of the `rustc_plugin_impl` crate.
~Draft PR because it is blocked on #100694 for `#[fatal(...)]` support~ (this has been merged, and I've changed over to `#[diag(...)]` now too), but I would also like to know if what I did with `LoadPluginError` is okay, because all it does is display the error message from `libloading` ([See conversation on zulip](https://rust-lang.zulipchat.com/#narrow/stream/147480-t-compiler.2Fwg-diagnostics/topic/.23100717.20diagnostic.20translation/near/294327843)). This crate is apparently for a deprecated feature which is used by servo, so I don't know how much this matters anyway.
Diffstat (limited to 'compiler/rustc_plugin_impl')
-rw-r--r--compiler/rustc_plugin_impl/Cargo.toml1
-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
4 files changed, 29 insertions, 11 deletions
diff --git a/compiler/rustc_plugin_impl/Cargo.toml b/compiler/rustc_plugin_impl/Cargo.toml
index b6ea533c80b..c409b6c3e54 100644
--- a/compiler/rustc_plugin_impl/Cargo.toml
+++ b/compiler/rustc_plugin_impl/Cargo.toml
@@ -11,6 +11,7 @@ doctest = false
 libloading = "0.7.1"
 rustc_errors = { path = "../rustc_errors" }
 rustc_lint = { path = "../rustc_lint" }
+rustc_macros = { path = "../rustc_macros" }
 rustc_metadata = { path = "../rustc_metadata" }
 rustc_ast = { path = "../rustc_ast" }
 rustc_session = { path = "../rustc_session" }
diff --git a/compiler/rustc_plugin_impl/src/errors.rs b/compiler/rustc_plugin_impl/src/errors.rs
new file mode 100644
index 00000000000..2bdb6e4feca
--- /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 1195045bdea..9ac27c65da8 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 618682da4e5..8e75e969ae0 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);
 }