11//! Used by `rustc` when loading a plugin.
22
3+ use crate :: errors:: { LoadPluginError , MalformedPluginAttribute } ;
34use crate :: Registry ;
45use libloading:: Library ;
56use rustc_ast:: Crate ;
6- use rustc_errors:: struct_span_err;
77use rustc_metadata:: locator;
88use rustc_session:: cstore:: MetadataLoader ;
99use rustc_session:: Session ;
1010use rustc_span:: symbol:: { sym, Ident } ;
11- use rustc_span:: Span ;
1211
13- use std:: borrow:: ToOwned ;
1412use std:: env;
1513use std:: mem;
1614use std:: path:: PathBuf ;
1715
1816/// Pointer to a registrar function.
1917type 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.
2820pub 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