Skip to content

Commit 90ac082

Browse files
authored
Rollup merge of #66905 - petrochenkov:rmplugin2, r=Centril
rustc_plugin: Remove some remaining plugin features - Plugin arguments (`#![plugin(my_plugin(args))]`) are no longer supported. - Registering additional plugins from command line (`-Z extra-plugins=my_plugin`) is no longer supported, `-Z crate-attr=plugin(my_plugin)` can be used instead. - Lint `plugin_as_library` is removed as mostly useless now, when plugins exist as a compatibility feature with greatly reduced functionality. - Plugins registering additional LLVM passes (`Registry::register_llvm_pass`) are no longer supported, `-C passes=my_passes` can be used instead. r? @Centril
2 parents dbe880e + e5944a5 commit 90ac082

36 files changed

+141
-405
lines changed

src/doc/rustc/src/lints/listing/warn-by-default.md

-12
Original file line numberDiff line numberDiff line change
@@ -307,18 +307,6 @@ warning: path statement with no effect
307307
|
308308
```
309309

310-
## plugin-as-library
311-
312-
This lint detects when compiler plugins are used as ordinary library in
313-
non-plugin crate. Some example code that triggers this lint:
314-
315-
```rust,ignore
316-
#![feature(plugin)]
317-
#![plugin(macro_crate_test)]
318-
319-
extern crate macro_crate_test;
320-
```
321-
322310
## private-in-public
323311

324312
This lint detects private items in public interfaces not caught by the old implementation. Some

src/doc/unstable-book/src/language-features/plugin.md

+1-6
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,10 @@ the crate attribute `#![plugin(...)]`. See the
2121
`rustc_driver::plugin` documentation for more about the
2222
mechanics of defining and loading a plugin.
2323

24-
If present, arguments passed as `#![plugin(foo(... args ...))]` are not
25-
interpreted by rustc itself. They are provided to the plugin through the
26-
`Registry`'s `args` method.
27-
2824
In the vast majority of cases, a plugin should *only* be used through
2925
`#![plugin]` and not through an `extern crate` item. Linking a plugin would
3026
pull in all of libsyntax and librustc as dependencies of your crate. This is
31-
generally unwanted unless you are building another plugin. The
32-
`plugin_as_library` lint checks these guidelines.
27+
generally unwanted unless you are building another plugin.
3328

3429
The usual practice is to put compiler plugins in their own crate, separate from
3530
any `macro_rules!` macros or ordinary Rust code meant to be used by consumers

src/librustc/lint/context.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ use rustc_error_codes::*;
4747
/// This is basically the subset of `Context` that we can
4848
/// build early in the compile pipeline.
4949
pub struct LintStore {
50-
/// Registered lints. The bool is true if the lint was
51-
/// added by a plugin.
50+
/// Registered lints.
5251
lints: Vec<&'static Lint>,
5352

5453
/// Constructor functions for each variety of lint pass.

src/librustc/session/config.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1364,8 +1364,6 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
13641364
"enable queries of the dependency graph for regression testing"),
13651365
no_analysis: bool = (false, parse_bool, [UNTRACKED],
13661366
"parse and expand the source, but run no analysis"),
1367-
extra_plugins: Vec<String> = (Vec::new(), parse_list, [TRACKED],
1368-
"load extra plugins"),
13691367
unstable_options: bool = (false, parse_bool, [UNTRACKED],
13701368
"adds unstable command line options to rustc interface"),
13711369
force_overflow_checks: Option<bool> = (None, parse_opt_bool, [TRACKED],

src/librustc/session/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ pub struct Session {
7676
/// (sub)diagnostics that have been set once, but should not be set again,
7777
/// in order to avoid redundantly verbose output (Issue #24690, #44953).
7878
pub one_time_diagnostics: Lock<FxHashSet<(DiagnosticMessageId, Option<Span>, String)>>,
79-
pub plugin_llvm_passes: OneThread<RefCell<Vec<String>>>,
8079
pub crate_types: Once<Vec<config::CrateType>>,
8180
/// The `crate_disambiguator` is constructed out of all the `-C metadata`
8281
/// arguments passed to the compiler. Its value together with the crate-name
@@ -1149,7 +1148,6 @@ fn build_session_(
11491148
local_crate_source_file,
11501149
working_dir,
11511150
one_time_diagnostics: Default::default(),
1152-
plugin_llvm_passes: OneThread::new(RefCell::new(Vec::new())),
11531151
crate_types: Once::new(),
11541152
crate_disambiguator: Once::new(),
11551153
features: Once::new(),

src/librustc_codegen_llvm/back/write.rs

-14
Original file line numberDiff line numberDiff line change
@@ -365,20 +365,6 @@ pub(crate) unsafe fn optimize(cgcx: &CodegenContext<LlvmCodegenBackend>,
365365

366366
add_sanitizer_passes(config, &mut extra_passes);
367367

368-
for pass_name in &cgcx.plugin_passes {
369-
if let Some(pass) = find_pass(pass_name) {
370-
extra_passes.push(pass);
371-
} else {
372-
diag_handler.err(&format!("a plugin asked for LLVM pass \
373-
`{}` but LLVM does not \
374-
recognize it", pass_name));
375-
}
376-
377-
if pass_name == "name-anon-globals" {
378-
have_name_anon_globals_pass = true;
379-
}
380-
}
381-
382368
// Some options cause LLVM bitcode to be emitted, which uses ThinLTOBuffers, so we need
383369
// to make sure we run LLVM's NameAnonGlobals pass when emitting bitcode; otherwise
384370
// we'll get errors in LLVM.

src/librustc_codegen_ssa/back/write.rs

-3
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,6 @@ pub struct CodegenContext<B: WriteBackendMethods> {
231231
pub total_cgus: usize,
232232
// Handler to use for diagnostics produced during codegen.
233233
pub diag_emitter: SharedEmitter,
234-
// LLVM passes added by plugins.
235-
pub plugin_passes: Vec<String>,
236234
// LLVM optimizations for which we want to print remarks.
237235
pub remark: Passes,
238236
// Worker thread number
@@ -1028,7 +1026,6 @@ fn start_executing_work<B: ExtraBackendMethods>(
10281026
time_passes: sess.time_extended(),
10291027
prof: sess.prof.clone(),
10301028
exported_symbols,
1031-
plugin_passes: sess.plugin_llvm_passes.borrow().clone(),
10321029
remark: sess.opts.cg.remark.clone(),
10331030
worker: 0,
10341031
incr_comp_session_dir: sess.incr_comp_session_dir_opt().map(|r| r.clone()),

src/librustc_feature/builtin_attrs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
283283
)
284284
),
285285
(
286-
sym::plugin, CrateLevel, template!(List: "name|name(args)"),
286+
sym::plugin, CrateLevel, template!(List: "name"),
287287
Gated(
288288
Stability::Deprecated(
289289
"https://github.com/rust-lang/rust/pull/64675",

src/librustc_interface/passes.rs

+7-20
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ use rustc_mir as mir;
3030
use rustc_parse::{parse_crate_from_file, parse_crate_from_source_str};
3131
use rustc_passes::{self, ast_validation, hir_stats, layout_test};
3232
use rustc_plugin_impl as plugin;
33-
use rustc_plugin_impl::registry::Registry;
3433
use rustc_privacy;
3534
use rustc_resolve::{Resolver, ResolverArenas};
3635
use rustc_traits;
@@ -106,8 +105,7 @@ declare_box_region_type!(
106105
(&mut Resolver<'_>) -> (Result<ast::Crate>, ResolverOutputs)
107106
);
108107

109-
/// Runs the "early phases" of the compiler: initial `cfg` processing,
110-
/// loading compiler plugins (including those from `addl_plugins`),
108+
/// Runs the "early phases" of the compiler: initial `cfg` processing, loading compiler plugins,
111109
/// syntax expansion, secondary `cfg` expansion, synthesis of a test
112110
/// harness if one is to be provided, injection of a dependency on the
113111
/// standard library and prelude, and name resolution.
@@ -209,33 +207,22 @@ pub fn register_plugins<'a>(
209207
middle::recursion_limit::update_limits(sess, &krate);
210208
});
211209

212-
let registrars = time(sess, "plugin loading", || {
213-
plugin::load::load_plugins(
214-
sess,
215-
metadata_loader,
216-
&krate,
217-
Some(sess.opts.debugging_opts.extra_plugins.clone()),
218-
)
219-
});
220-
221210
let mut lint_store = rustc_lint::new_lint_store(
222211
sess.opts.debugging_opts.no_interleave_lints,
223212
sess.unstable_options(),
224213
);
214+
register_lints(&sess, &mut lint_store);
225215

226-
(register_lints)(&sess, &mut lint_store);
227-
228-
let mut registry = Registry::new(sess, &mut lint_store, krate.span);
229-
216+
let registrars = time(sess, "plugin loading", || {
217+
plugin::load::load_plugins(sess, metadata_loader, &krate)
218+
});
230219
time(sess, "plugin registration", || {
220+
let mut registry = plugin::Registry { lint_store: &mut lint_store };
231221
for registrar in registrars {
232-
registry.args_hidden = Some(registrar.args);
233-
(registrar.fun)(&mut registry);
222+
registrar(&mut registry);
234223
}
235224
});
236225

237-
*sess.plugin_llvm_passes.borrow_mut() = registry.llvm_passes;
238-
239226
Ok((krate, Lrc::new(lint_store)))
240227
}
241228

src/librustc_interface/tests.rs

-4
Original file line numberDiff line numberDiff line change
@@ -650,10 +650,6 @@ fn test_debugging_options_tracking_hash() {
650650
opts.debugging_opts.continue_parse_after_error = true;
651651
assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
652652

653-
opts = reference.clone();
654-
opts.debugging_opts.extra_plugins = vec![String::from("plugin1"), String::from("plugin2")];
655-
assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
656-
657653
opts = reference.clone();
658654
opts.debugging_opts.force_overflow_checks = Some(true);
659655
assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());

src/librustc_lint/builtin.rs

+1-41
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
use std::fmt::Write;
2525

2626
use rustc::hir::def::{Res, DefKind};
27-
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
27+
use rustc::hir::def_id::DefId;
2828
use rustc::ty::{self, Ty, TyCtxt, layout::VariantIdx};
2929
use rustc::{lint, util};
3030
use rustc::lint::FutureIncompatibleInfo;
@@ -800,45 +800,6 @@ impl EarlyLintPass for UnusedDocComment {
800800
}
801801
}
802802

803-
declare_lint! {
804-
PLUGIN_AS_LIBRARY,
805-
Warn,
806-
"compiler plugin used as ordinary library in non-plugin crate"
807-
}
808-
809-
declare_lint_pass!(PluginAsLibrary => [PLUGIN_AS_LIBRARY]);
810-
811-
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PluginAsLibrary {
812-
fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item) {
813-
if cx.tcx.plugin_registrar_fn(LOCAL_CRATE).is_some() {
814-
// We're compiling a plugin; it's fine to link other plugins.
815-
return;
816-
}
817-
818-
match it.kind {
819-
hir::ItemKind::ExternCrate(..) => (),
820-
_ => return,
821-
};
822-
823-
let def_id = cx.tcx.hir().local_def_id(it.hir_id);
824-
let prfn = match cx.tcx.extern_mod_stmt_cnum(def_id) {
825-
Some(cnum) => cx.tcx.plugin_registrar_fn(cnum),
826-
None => {
827-
// Probably means we aren't linking the crate for some reason.
828-
//
829-
// Not sure if / when this could happen.
830-
return;
831-
}
832-
};
833-
834-
if prfn.is_some() {
835-
cx.span_lint(PLUGIN_AS_LIBRARY,
836-
it.span,
837-
"compiler plugin used as an ordinary library");
838-
}
839-
}
840-
}
841-
842803
declare_lint! {
843804
NO_MANGLE_CONST_ITEMS,
844805
Deny,
@@ -1268,7 +1229,6 @@ declare_lint_pass!(
12681229
MISSING_DEBUG_IMPLEMENTATIONS,
12691230
ANONYMOUS_PARAMETERS,
12701231
UNUSED_DOC_COMMENTS,
1271-
PLUGIN_AS_LIBRARY,
12721232
NO_MANGLE_CONST_ITEMS,
12731233
NO_MANGLE_GENERIC_ITEMS,
12741234
MUTABLE_TRANSMUTES,

src/librustc_lint/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,6 @@ macro_rules! late_lint_mod_passes {
157157
// Depends on types used in type definitions
158158
MissingCopyImplementations: MissingCopyImplementations,
159159

160-
PluginAsLibrary: PluginAsLibrary,
161-
162160
// Depends on referenced function signatures in expressions
163161
MutableTransmutes: MutableTransmutes,
164162

@@ -350,6 +348,7 @@ fn register_builtins(store: &mut lint::LintStore, no_interleave_lints: bool) {
350348
"converted into hard error, see https://github.com/rust-lang/rust/issues/35896");
351349
store.register_removed("nested_impl_trait",
352350
"converted into hard error, see https://github.com/rust-lang/rust/issues/59014");
351+
store.register_removed("plugin_as_library", "plugins have been deprecated and retired");
353352
}
354353

355354
fn register_internals(store: &mut lint::LintStore) {

src/librustc_plugin_impl/lib.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@
1010

1111
#![feature(nll)]
1212

13-
#![recursion_limit="256"]
13+
use rustc::lint::LintStore;
1414

15-
pub use registry::Registry;
16-
17-
pub mod registry;
18-
pub mod load;
1915
pub mod build;
16+
pub mod load;
17+
18+
/// Structure used to register plugins.
19+
///
20+
/// A plugin registrar function takes an `&mut Registry` and should call
21+
/// methods to register its plugins.
22+
pub struct Registry<'a> {
23+
/// The `LintStore` allows plugins to register new lints.
24+
pub lint_store: &'a mut LintStore,
25+
}

0 commit comments

Comments
 (0)