diff options
| author | bors <bors@rust-lang.org> | 2023-11-03 22:32:56 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-11-03 22:32:56 +0000 |
| commit | 5020f7c3b8bd8bf57077389bca5c19f7911fde7a (patch) | |
| tree | 73721e981942f66e90251e65628bc41fecc27032 /src/doc | |
| parent | 1bb6553b967b69eed9ed8147e78b4f65cfc48e11 (diff) | |
| parent | 5c462a32bd31d19cacbd15786fb0fa40558eda91 (diff) | |
| download | rust-5020f7c3b8bd8bf57077389bca5c19f7911fde7a.tar.gz rust-5020f7c3b8bd8bf57077389bca5c19f7911fde7a.zip | |
Auto merge of #116412 - nnethercote:rm-plugin-support, r=bjorn3
Remove support for compiler plugins. They've been deprecated for four years. This commit includes the following changes. - It eliminates the `rustc_plugin_impl` crate. - It changes the language used for lints in `compiler/rustc_driver_impl/src/lib.rs` and `compiler/rustc_lint/src/context.rs`. External lints are now called "loaded" lints, rather than "plugins" to avoid confusion with the old plugins. This only has a tiny effect on the output of `-W help`. - E0457 and E0498 are no longer used. - E0463 is narrowed, now only relating to unfound crates, not plugins. - The `plugin` feature was moved from "active" to "removed". - It removes the entire plugins chapter from the unstable book. - It removes quite a few tests, mostly all of those in `tests/ui-fulldeps/plugin/`. Closes #29597. r? `@ghost`
Diffstat (limited to 'src/doc')
| m--------- | src/doc/book | 0 | ||||
| -rw-r--r-- | src/doc/guide-plugins.md | 3 | ||||
| -rw-r--r-- | src/doc/unstable-book/src/language-features/plugin.md | 114 |
3 files changed, 1 insertions, 116 deletions
diff --git a/src/doc/book b/src/doc/book -Subproject 3dca2fc50b922a8efb94903b9fee8bb42ab48f3 +Subproject 5b6c1ceaa62ecbd6caef08df39b33b3938e99de diff --git a/src/doc/guide-plugins.md b/src/doc/guide-plugins.md index 6c511548789..ccb9bb2ee83 100644 --- a/src/doc/guide-plugins.md +++ b/src/doc/guide-plugins.md @@ -1,4 +1,3 @@ % The (old) Rust Compiler Plugins Guide -This content has moved into -[the Unstable Book](unstable-book/language-features/plugin.html). +Support for plugins has been removed. diff --git a/src/doc/unstable-book/src/language-features/plugin.md b/src/doc/unstable-book/src/language-features/plugin.md deleted file mode 100644 index d9421a428f1..00000000000 --- a/src/doc/unstable-book/src/language-features/plugin.md +++ /dev/null @@ -1,114 +0,0 @@ -# `plugin` - -The tracking issue for this feature is: [#29597] - -[#29597]: https://github.com/rust-lang/rust/issues/29597 - - -This feature is part of "compiler plugins." It will often be used with the -`rustc_private` feature. - ------------------------- - -`rustc` can load compiler plugins, which are user-provided libraries that -extend the compiler's behavior with new lint checks, etc. - -A plugin is a dynamic library crate with a designated *registrar* function that -registers extensions with `rustc`. Other crates can load these extensions using -the crate attribute `#![plugin(...)]`. See the -`rustc_driver::plugin` documentation for more about the -mechanics of defining and loading a plugin. - -In the vast majority of cases, a plugin should *only* be used through -`#![plugin]` and not through an `extern crate` item. Linking a plugin would -pull in all of librustc_ast and librustc as dependencies of your crate. This is -generally unwanted unless you are building another plugin. - -The usual practice is to put compiler plugins in their own crate, separate from -any `macro_rules!` macros or ordinary Rust code meant to be used by consumers -of a library. - -# Lint plugins - -Plugins can extend [Rust's lint -infrastructure](../../reference/attributes/diagnostics.md#lint-check-attributes) with -additional checks for code style, safety, etc. Now let's write a plugin -[`lint-plugin-test.rs`](https://github.com/rust-lang/rust/blob/master/tests/ui-fulldeps/plugin/auxiliary/lint-plugin-test.rs) -that warns about any item named `lintme`. - -```rust,ignore (requires-stage-2) -#![feature(rustc_private)] - -extern crate rustc_ast; - -// Load rustc as a plugin to get macros -extern crate rustc_driver; -extern crate rustc_lint; -#[macro_use] -extern crate rustc_session; - -use rustc_ast::ast; -use rustc_driver::plugin::Registry; -use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; - -declare_lint!(TEST_LINT, Warn, "Warn about items named 'lintme'"); - -declare_lint_pass!(Pass => [TEST_LINT]); - -impl EarlyLintPass for Pass { - fn check_item(&mut self, cx: &EarlyContext, it: &ast::Item) { - if it.ident.name.as_str() == "lintme" { - cx.lint(TEST_LINT, "item is named 'lintme'", |lint| lint.set_span(it.span)); - } - } -} - -#[no_mangle] -fn __rustc_plugin_registrar(reg: &mut Registry) { - reg.lint_store.register_lints(&[&TEST_LINT]); - reg.lint_store.register_early_pass(|| Box::new(Pass)); -} -``` - -Then code like - -```rust,ignore (requires-plugin) -#![feature(plugin)] -#![plugin(lint_plugin_test)] - -fn lintme() { } -``` - -will produce a compiler warning: - -```txt -foo.rs:4:1: 4:16 warning: item is named 'lintme', #[warn(test_lint)] on by default -foo.rs:4 fn lintme() { } - ^~~~~~~~~~~~~~~ -``` - -The components of a lint plugin are: - -* one or more `declare_lint!` invocations, which define static `Lint` structs; - -* a struct holding any state needed by the lint pass (here, none); - -* a `LintPass` - implementation defining how to check each syntax element. A single - `LintPass` may call `span_lint` for several different `Lint`s, but should - register them all through the `get_lints` method. - -Lint passes are syntax traversals, but they run at a late stage of compilation -where type information is available. `rustc`'s [built-in -lints](https://github.com/rust-lang/rust/blob/master/compiler/rustc_lint_defs/src/builtin.rs) -mostly use the same infrastructure as lint plugins, and provide examples of how -to access type information. - -Lints defined by plugins are controlled by the usual [attributes and compiler -flags](../../reference/attributes/diagnostics.md#lint-check-attributes), e.g. -`#[allow(test_lint)]` or `-A test-lint`. These identifiers are derived from the -first argument to `declare_lint!`, with appropriate case and punctuation -conversion. - -You can run `rustc -W help foo.rs` to see a list of lints known to `rustc`, -including those provided by plugins loaded by `foo.rs`. |
