Skip to content

Commit 39c8814

Browse files
authored
Rollup merge of rust-lang#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 rust-lang#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.
2 parents 41e8b97 + 8c2413c commit 39c8814

File tree

7 files changed

+35
-11
lines changed

7 files changed

+35
-11
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4321,6 +4321,7 @@ dependencies = [
43214321
"rustc_ast",
43224322
"rustc_errors",
43234323
"rustc_lint",
4324+
"rustc_macros",
43244325
"rustc_metadata",
43254326
"rustc_session",
43264327
"rustc_span",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
plugin_impl_load_plugin_error = {$msg}
2+
3+
plugin_impl_malformed_plugin_attribute = malformed `plugin` attribute
4+
.label = malformed attribute

compiler/rustc_error_messages/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ fluent_messages! {
4141
lint => "../locales/en-US/lint.ftl",
4242
parser => "../locales/en-US/parser.ftl",
4343
passes => "../locales/en-US/passes.ftl",
44+
plugin_impl => "../locales/en-US/plugin_impl.ftl",
4445
privacy => "../locales/en-US/privacy.ftl",
4546
typeck => "../locales/en-US/typeck.ftl",
4647
}

compiler/rustc_plugin_impl/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ doctest = false
1111
libloading = "0.7.1"
1212
rustc_errors = { path = "../rustc_errors" }
1313
rustc_lint = { path = "../rustc_lint" }
14+
rustc_macros = { path = "../rustc_macros" }
1415
rustc_metadata = { path = "../rustc_metadata" }
1516
rustc_ast = { path = "../rustc_ast" }
1617
rustc_session = { path = "../rustc_session" }
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//! Errors emitted by plugin_impl
2+
3+
use rustc_macros::SessionDiagnostic;
4+
use rustc_span::Span;
5+
6+
#[derive(SessionDiagnostic)]
7+
#[diag(plugin_impl::load_plugin_error)]
8+
pub struct LoadPluginError {
9+
#[primary_span]
10+
pub span: Span,
11+
pub msg: String,
12+
}
13+
14+
#[derive(SessionDiagnostic)]
15+
#[diag(plugin_impl::malformed_plugin_attribute, code = "E0498")]
16+
pub struct MalformedPluginAttribute {
17+
#[primary_span]
18+
#[label]
19+
pub span: Span,
20+
}

compiler/rustc_plugin_impl/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88
99
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
1010
#![recursion_limit = "256"]
11+
#![deny(rustc::untranslatable_diagnostic)]
12+
#![deny(rustc::diagnostic_outside_of_impl)]
1113

1214
use rustc_lint::LintStore;
1315

16+
mod errors;
1417
pub mod load;
1518

1619
/// Structure used to register plugins.

compiler/rustc_plugin_impl/src/load.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,21 @@
11
//! Used by `rustc` when loading a plugin.
22
3+
use crate::errors::{LoadPluginError, MalformedPluginAttribute};
34
use crate::Registry;
45
use libloading::Library;
56
use rustc_ast::Crate;
6-
use rustc_errors::struct_span_err;
77
use rustc_metadata::locator;
88
use rustc_session::cstore::MetadataLoader;
99
use rustc_session::Session;
1010
use rustc_span::symbol::{sym, Ident};
11-
use rustc_span::Span;
1211

13-
use std::borrow::ToOwned;
1412
use std::env;
1513
use std::mem;
1614
use std::path::PathBuf;
1715

1816
/// Pointer to a registrar function.
1917
type PluginRegistrarFn = fn(&mut Registry<'_>);
2018

21-
fn call_malformed_plugin_attribute(sess: &Session, span: Span) {
22-
struct_span_err!(sess, span, E0498, "malformed `plugin` attribute")
23-
.span_label(span, "malformed attribute")
24-
.emit();
25-
}
26-
2719
/// Read plugin metadata and dynamically load registrar functions.
2820
pub fn load_plugins(
2921
sess: &Session,
@@ -42,7 +34,9 @@ pub fn load_plugins(
4234
Some(ident) if plugin.is_word() => {
4335
load_plugin(&mut plugins, sess, metadata_loader, ident)
4436
}
45-
_ => call_malformed_plugin_attribute(sess, plugin.span()),
37+
_ => {
38+
sess.emit_err(MalformedPluginAttribute { span: plugin.span() });
39+
}
4640
}
4741
}
4842
}
@@ -60,7 +54,7 @@ fn load_plugin(
6054
let fun = dylink_registrar(lib).unwrap_or_else(|err| {
6155
// This is fatal: there are almost certainly macros we need inside this crate, so
6256
// continuing would spew "macro undefined" errors.
63-
sess.span_fatal(ident.span, &err.to_string());
57+
sess.emit_fatal(LoadPluginError { span: ident.span, msg: err.to_string() });
6458
});
6559
plugins.push(fun);
6660
}

0 commit comments

Comments
 (0)