Skip to content
Permalink
Browse files

rustc_lint: Remove lint `plugin_as_library`

  • Loading branch information
petrochenkov committed Nov 30, 2019
1 parent db357a6 commit cf1ffb0355e608453acc9803d6f317c16011d517
@@ -307,18 +307,6 @@ warning: path statement with no effect
|
```

## plugin-as-library

This lint detects when compiler plugins are used as ordinary library in
non-plugin crate. Some example code that triggers this lint:

```rust,ignore
#![feature(plugin)]
#![plugin(macro_crate_test)]
extern crate macro_crate_test;
```

## private-in-public

This lint detects private items in public interfaces not caught by the old implementation. Some
@@ -24,8 +24,7 @@ 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 libsyntax and librustc as dependencies of your crate. This is
generally unwanted unless you are building another plugin. The
`plugin_as_library` lint checks these guidelines.
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
@@ -24,7 +24,7 @@
use std::fmt::Write;

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

declare_lint! {
PLUGIN_AS_LIBRARY,
Warn,
"compiler plugin used as ordinary library in non-plugin crate"
}

declare_lint_pass!(PluginAsLibrary => [PLUGIN_AS_LIBRARY]);

impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PluginAsLibrary {
fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item) {
if cx.tcx.plugin_registrar_fn(LOCAL_CRATE).is_some() {
// We're compiling a plugin; it's fine to link other plugins.
return;
}

match it.kind {
hir::ItemKind::ExternCrate(..) => (),
_ => return,
};

let def_id = cx.tcx.hir().local_def_id(it.hir_id);
let prfn = match cx.tcx.extern_mod_stmt_cnum(def_id) {
Some(cnum) => cx.tcx.plugin_registrar_fn(cnum),
None => {
// Probably means we aren't linking the crate for some reason.
//
// Not sure if / when this could happen.
return;
}
};

if prfn.is_some() {
cx.span_lint(PLUGIN_AS_LIBRARY,
it.span,
"compiler plugin used as an ordinary library");
}
}
}

declare_lint! {
NO_MANGLE_CONST_ITEMS,
Deny,
@@ -1268,7 +1229,6 @@ declare_lint_pass!(
MISSING_DEBUG_IMPLEMENTATIONS,
ANONYMOUS_PARAMETERS,
UNUSED_DOC_COMMENTS,
PLUGIN_AS_LIBRARY,
NO_MANGLE_CONST_ITEMS,
NO_MANGLE_GENERIC_ITEMS,
MUTABLE_TRANSMUTES,
@@ -157,8 +157,6 @@ macro_rules! late_lint_mod_passes {
// Depends on types used in type definitions
MissingCopyImplementations: MissingCopyImplementations,

PluginAsLibrary: PluginAsLibrary,

// Depends on referenced function signatures in expressions
MutableTransmutes: MutableTransmutes,

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

fn register_internals(store: &mut lint::LintStore) {
@@ -1,9 +1,4 @@
// run-pass

#![allow(plugin_as_library)]
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_imports)]
// check-pass
// aux-build:macro-crate-test.rs
// ignore-stage1

@@ -1,11 +1,10 @@
// check-pass
// aux-build:empty-plugin.rs
// ignore-cross-compile
//
// empty_plugin will not compile on a cross-compiled target because
// libsyntax is not compiled for it.

#![deny(plugin_as_library)]
extern crate empty_plugin; // OK, plugin crates are still crates

extern crate empty_plugin; //~ ERROR compiler plugin used as an ordinary library

fn main() { }
fn main() {}

This file was deleted.

0 comments on commit cf1ffb0

Please sign in to comment.
You can’t perform that action at this time.