Repository: rust-lang/cargo (rust)

Issue:
Remove support for rustc plugins
### Problem

Cargo still supports building and depending on rustc plugins despite this having been removed from rustc a while ago.

### Proposed Solution

Remove support for building rustc plugins.

### Notes

Support was removed in https://github.com/rust-lang/rust/pull/116412

Pull request description:
fix(toml): remove `lib.plugin` key support and make it warning
### What does this PR try to resolve?

Remove `lib.plugin` key, making it an "unused key" warning.

Remove some of the tests, which should look useless (I hope I'm understanding this 

- [x] Remove key, and related tests.
- [x] Adjust the documentation about the plugin.
- [ ] Some of the comments and function names have not yet finished being modified.

part of #13629

Closes #13246 

Patch:
diff --git a/crates/cargo-util-schemas/src/manifest/mod.rs b/crates/cargo-util-schemas/src/manifest/mod.rs
index 375d0de45..14659b81c 100644
--- a/crates/cargo-util-schemas/src/manifest/mod.rs
+++ b/crates/cargo-util-schemas/src/manifest/mod.rs
@@ -1223,7 +1223,6 @@ pub struct TomlTarget {
     pub doctest: Option<bool>,
     pub bench: Option<bool>,
     pub doc: Option<bool>,
-    pub plugin: Option<bool>,
     pub doc_scrape_examples: Option<bool>,
     pub proc_macro: Option<bool>,
     #[serde(rename = "proc_macro")]
diff --git a/crates/cargo-util/src/paths.rs b/crates/cargo-util/src/paths.rs
index 7a19479ad..9cfb73cdd 100644
--- a/crates/cargo-util/src/paths.rs
+++ b/crates/cargo-util/src/paths.rs
@@ -4,7 +4,7 @@ use anyhow::{Context, Result};
 use filetime::FileTime;
 use std::env;
 use std::ffi::{OsStr, OsString};
-use std::fs::{self, File, Metadata, OpenOptions, Permissions};
+use std::fs::{self, File, Metadata, OpenOptions};
 use std::io;
 use std::io::prelude::*;
 use std::iter;
@@ -185,34 +185,10 @@ pub fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> Result<()>
 /// write_atomic uses tempfile::persist to accomplish atomic writes.
 pub fn write_atomic<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> Result<()> {
     let path = path.as_ref();
-
-    // On unix platforms, get the permissions of the original file. Copy only the user/group/other
-    // read/write/execute permission bits. The tempfile lib defaults to an initial mode of 0o600,
-    // and we'll set the proper permissions after creating the file.
-    #[cfg(unix)]
-    let perms = path.metadata().ok().map(|meta| {
-        use std::os::unix::fs::PermissionsExt;
-
-        // these constants are u16 on macOS
-        let mask = u32::from(libc::S_IRWXU | libc::S_IRWXG | libc::S_IRWXO);
-        let mode = meta.permissions().mode() & mask;
-
-        Permissions::from_mode(mode)
-    });
-
     let mut tmp = TempFileBuilder::new()
         .prefix(path.file_name().unwrap())
         .tempfile_in(path.parent().unwrap())?;
     tmp.write_all(contents.as_ref())?;
-
-    // On unix platforms, set the permissions on the newly created file. We can use fchmod (called
-    // by the std lib; subject to change) which ignores the umask so that the new file has the same
-    // permissions as the old file.
-    #[cfg(unix)]
-    if let Some(perms) = perms {
-        tmp.as_file().set_permissions(perms)?;
-    }
-
     tmp.persist(path)?;
     Ok(())
 }
@@ -847,32 +823,6 @@ mod tests {
         assert_eq!(contents, original_contents);
     }
 
-    #[test]
-    #[cfg(unix)]
-    fn write_atomic_permissions() {
-        use std::os::unix::fs::PermissionsExt;
-
-        let original_perms = std::fs::Permissions::from_mode(u32::from(
-            libc::S_IRWXU | libc::S_IRGRP | libc::S_IWGRP | libc::S_IROTH,
-        ));
-
-        let tmp = tempfile::Builder::new().tempfile().unwrap();
-
-        // need to set the permissions after creating the file to avoid umask
-        tmp.as_file()
-            .set_permissions(original_perms.clone())
-            .unwrap();
-
-        // after this call, the file at `tmp.path()` will not be the same as the file held by `tmp`
-        write_atomic(tmp.path(), "new").unwrap();
-        assert_eq!(std::fs::read_to_string(tmp.path()).unwrap(), "new");
-
-        let new_perms = std::fs::metadata(tmp.path()).unwrap().permissions();
-
-        let mask = u32::from(libc::S_IRWXU | libc::S_IRWXG | libc::S_IRWXO);
-        assert_eq!(original_perms.mode(), new_perms.mode() & mask);
-    }
-
     #[test]
     fn join_paths_lists_paths_on_error() {
         let valid_paths = vec!["/testing/one", "/testing/two"];
diff --git a/src/cargo/core/manifest.rs b/src/cargo/core/manifest.rs
index 14245c410..a45a26a76 100644
--- a/src/cargo/core/manifest.rs
+++ b/src/cargo/core/manifest.rs
@@ -905,7 +905,7 @@ impl Target {
     pub fn documented(&self) -> bool {
         self.inner.doc
     }
-    // A plugin, proc-macro, or build-script.
+    // A proc-macro or build-script.
     pub fn for_host(&self) -> bool {
         self.inner.for_host
     }
diff --git a/src/cargo/core/resolver/resolve.rs b/src/cargo/core/resolver/resolve.rs
index 102f84134..d77ff9f35 100644
--- a/src/cargo/core/resolver/resolve.rs
+++ b/src/cargo/core/resolver/resolve.rs
@@ -205,7 +205,7 @@ impl Resolve {
         self.graph.path_to_top(pkg)
     }
 
-    pub fn register_used_patches<'a>(&mut self, patches: impl Iterator<Item = &'a Summary>) {
+    pub fn register_used_patches(&mut self, patches: &[Summary]) {
         for summary in patches {
             if !self.graph.contains(&summary.package_id()) {
                 self.unused_patches.push(summary.package_id())
diff --git a/src/cargo/ops/resolve.rs b/src/cargo/ops/resolve.rs
index 1ce91ea53..286649dc8 100644
--- a/src/cargo/ops/resolve.rs
+++ b/src/cargo/ops/resolve.rs
@@ -64,14 +64,9 @@ use crate::core::resolver::{
     self, HasDevUnits, Resolve, ResolveOpts, ResolveVersion, VersionOrdering, VersionPreferences,
 };
 use crate::core::summary::Summary;
-use crate::core::Dependency;
-use crate::core::GitReference;
-use crate::core::PackageId;
-use crate::core::PackageIdSpec;
-use crate::core::PackageIdSpecQuery;
-use crate::core::PackageSet;
-use crate::core::SourceId;
-use crate::core::Workspace;
+use crate::core::{
+    GitReference, PackageId, PackageIdSpec, PackageIdSpecQuery, PackageSet, SourceId, Workspace,
+};
 use crate::ops;
 use crate::sources::PathSource;
 use crate::util::cache_lock::CacheLockMode;
@@ -81,9 +76,6 @@ use anyhow::Context as _;
 use std::collections::{HashMap, HashSet};
 use tracing::{debug, trace};
 
-/// Filter for keep using Package ID from previous lockfile.
-type Keep<'a> = &'a dyn Fn(&PackageId) -> bool;
-
 /// Result for `resolve_ws_with_opts`.
 pub struct WorkspaceResolve<'gctx> {
     /// Packages to be downloaded.
@@ -320,7 +312,7 @@ pub fn resolve_with_previous<'gctx>(
     cli_features: &CliFeatures,
     has_dev_units: HasDevUnits,
     previous: Option<&Resolve>,
-    keep_previous: Option<Keep<'_>>,
+    keep_previous: Option<&dyn Fn(&PackageId) -> bool>,
     specs: &[PackageIdSpec],
     register_patches: bool,
 ) -> CargoResult<Resolve> {
@@ -330,16 +322,6 @@ pub fn resolve_with_previous<'gctx>(
         .gctx()
         .acquire_package_cache_lock(CacheLockMode::DownloadExclusive)?;
 
-    // Some packages are already loaded when setting up a workspace. This
-    // makes it so anything that was already loaded will not be loaded again.
-    // Without this there were cases where members would be parsed multiple times
-    ws.preload(registry);
-
-    // In case any members were not already loaded or the Workspace is_ephemeral.
-    for member in ws.members() {
-        registry.add_sources(Some(member.package_id().source_id()))?;
-    }
-
     // Try to keep all from previous resolve if no instruction given.
     let keep_previous = keep_previous.unwrap_or(&|_| true);
 
@@ -390,6 +372,16 @@ pub fn resolve_with_previous<'gctx>(
         registry.lock_patches();
     }
 
+    // Some packages are already loaded when setting up a workspace. This
+    // makes it so anything that was already loaded will not be loaded again.
+    // Without this there were cases where members would be parsed multiple times
+    ws.preload(registry);
+
+    // In case any members were not already loaded or the Workspace is_ephemeral.
+    for member in ws.members() {
+        registry.add_sources(Some(member.package_id().source_id()))?;
+    }
+
     let summaries: Vec<(Summary, ResolveOpts)> = ws
         .members_with_features(specs, cli_features)?
         .into_iter()
@@ -405,8 +397,26 @@ pub fn resolve_with_previous<'gctx>(
         })
         .collect();
 
-    let replace = lock_replacements(ws, previous, &keep);
+    let root_replace = ws.root_replace();
+
+    let replace = match previous {
+        Some(r) => root_replace
+            .iter()
+            .map(|(spec, dep)| {
+                for (&key, &val) in r.replacements().iter() {
+                    if spec.matches(key) && dep.matches_id(val) && keep(&val) {
+                        let mut dep = dep.clone();
+                        dep.lock_to(val);
+                        return (spec.clone(), dep);
+                    }
+                }
+                (spec.clone(), dep.clone())
+            })
+            .collect::<Vec<_>>(),
+        None => root_replace.to_vec(),
+    };
 
+    ws.preload(registry);
     let mut resolved = resolver::resolve(
         &summaries,
         &replace,
@@ -415,9 +425,12 @@ pub fn resolve_with_previous<'gctx>(
         ResolveVersion::with_rust_version(ws.rust_version()),
         Some(ws.gctx()),
     )?;
-
-    let patches = registry.patches().values().flat_map(|v| v.iter());
-    resolved.register_used_patches(patches);
+    let patches: Vec<_> = registry
+        .patches()
+        .values()
+        .flat_map(|v| v.iter().cloned())
+        .collect();
+    resolved.register_used_patches(&patches[..]);
 
     if register_patches && !resolved.unused_patches().is_empty() {
         emit_warnings_of_unused_patches(ws, &resolved, registry)?;
@@ -495,7 +508,7 @@ fn register_previous_locks(
     ws: &Workspace<'_>,
     registry: &mut PackageRegistry<'_>,
     resolve: &Resolve,
-    keep: Keep<'_>,
+    keep: &dyn Fn(&PackageId) -> bool,
     dev_deps: bool,
 ) {
     let path_pkg = |id: SourceId| {
@@ -792,7 +805,7 @@ fn register_patch_entries(
     ws: &Workspace<'_>,
     previous: Option<&Resolve>,
     version_prefs: &mut VersionPreferences,
-    keep_previous: Keep<'_>,
+    keep_previous: &dyn Fn(&PackageId) -> bool,
 ) -> CargoResult<HashSet<PackageId>> {
     let mut avoid_patch_ids = HashSet::new();
     for (url, patches) in ws.root_patch()?.iter() {
@@ -897,30 +910,3 @@ fn register_patch_entries(
 
     Ok(avoid_patch_ids)
 }
-
-/// Locks each `[replace]` entry to a specific Package ID
-/// if the lockfile contains any correspoding previous replacement.
-fn lock_replacements(
-    ws: &Workspace<'_>,
-    previous: Option<&Resolve>,
-    keep: Keep<'_>,
-) -> Vec<(PackageIdSpec, Dependency)> {
-    let root_replace = ws.root_replace();
-    let replace = match previous {
-        Some(r) => root_replace
-            .iter()
-            .map(|(spec, dep)| {
-                for (&key, &val) in r.replacements().iter() {
-                    if spec.matches(key) && dep.matches_id(val) && keep(&val) {
-                        let mut dep = dep.clone();
-                        dep.lock_to(val);
-                        return (spec.clone(), dep);
-                    }
-                }
-                (spec.clone(), dep.clone())
-            })
-            .collect::<Vec<_>>(),
-        None => root_replace.to_vec(),
-    };
-    replace
-}
diff --git a/src/cargo/util/toml/targets.rs b/src/cargo/util/toml/targets.rs
index 261ff67b3..5a4c4df83 100644
--- a/src/cargo/util/toml/targets.rs
+++ b/src/cargo/util/toml/targets.rs
@@ -188,17 +188,6 @@ fn to_lib_target(
     let path = lib.path.as_ref().expect("previously resolved");
     let path = package_root.join(&path.0);
 
-    if lib.plugin == Some(true) {
-        warnings.push(format!(
-            "support for rustc plugins has been removed from rustc. \
-            library `{}` should not specify `plugin = true`",
-            name_or_panic(lib)
-        ));
-        warnings.push(format!(
-            "support for `plugin = true` will be removed from cargo in the future"
-        ));
-    }
-
     // Per the Macros 1.1 RFC:
     //
     // > Initially if a crate is compiled with the `proc-macro` crate type
@@ -208,8 +197,8 @@ fn to_lib_target(
     //
     // A plugin requires exporting plugin_registrar so a crate cannot be
     // both at once.
-    let crate_types = match (lib.crate_types(), lib.plugin, lib.proc_macro()) {
-        (Some(kinds), _, _)
+    let crate_types = match (lib.crate_types(), lib.proc_macro()) {
+        (Some(kinds), _)
             if kinds.contains(&CrateType::Dylib.as_str().to_owned())
                 && kinds.contains(&CrateType::Cdylib.as_str().to_owned()) =>
         {
@@ -218,14 +207,7 @@ fn to_lib_target(
                 name_or_panic(lib)
             ));
         }
-        (Some(kinds), _, _) if kinds.contains(&"proc-macro".to_string()) => {
-            if let Some(true) = lib.plugin {
-                // This is a warning to retain backwards compatibility.
-                warnings.push(format!(
-                    "proc-macro library `{}` should not specify `plugin = true`",
-                    name_or_panic(lib)
-                ));
-            }
+        (Some(kinds), _) if kinds.contains(&"proc-macro".to_string()) => {
             warnings.push(format!(
                 "library `{}` should only specify `proc-macro = true` instead of setting `crate-type`",
                 name_or_panic(lib)
@@ -235,13 +217,9 @@ fn to_lib_target(
             }
             vec![CrateType::ProcMacro]
         }
-        (_, Some(true), Some(true)) => {
-            anyhow::bail!("`lib.plugin` and `lib.proc-macro` cannot both be `true`")
-        }
-        (Some(kinds), _, _) => kinds.iter().map(|s| s.into()).collect(),
-        (None, Some(true), _) => vec![CrateType::Dylib],
-        (None, _, Some(true)) => vec![CrateType::ProcMacro],
-        (None, _, _) => vec![CrateType::Lib],
+        (Some(kinds), _) => kinds.iter().map(|s| s.into()).collect(),
+        (None, Some(true)) => vec![CrateType::ProcMacro],
+        (None, _) => vec![CrateType::Lib],
     };
 
     let mut target = Target::lib_target(name_or_panic(lib), crate_types, path, edition);
@@ -863,11 +841,8 @@ fn configure(toml: &TomlTarget, target: &mut Target) -> CargoResult<()> {
             Some(false) => RustdocScrapeExamples::Disabled,
             Some(true) => RustdocScrapeExamples::Enabled,
         })
-        .set_for_host(match (toml.plugin, toml.proc_macro()) {
-            (None, None) => t2.for_host(),
-            (Some(true), _) | (_, Some(true)) => true,
-            (Some(false), _) | (_, Some(false)) => false,
-        });
+        .set_for_host(toml.proc_macro().unwrap_or_else(|| t2.for_host()));
+
     if let Some(edition) = toml.edition.clone() {
         target.set_edition(
             edition
diff --git a/src/doc/src/reference/cargo-targets.md b/src/doc/src/reference/cargo-targets.md
index 912931039..38a6f4be3 100644
--- a/src/doc/src/reference/cargo-targets.md
+++ b/src/doc/src/reference/cargo-targets.md
@@ -184,7 +184,6 @@ test = true            # Is tested by default.
 doctest = true         # Documentation examples are tested by default.
 bench = true           # Is benchmarked by default.
 doc = true             # Is documented by default.
-plugin = false         # Used as a compiler plugin (deprecated).
 proc-macro = false     # Set to `true` for a proc-macro library.
 harness = true         # Use libtest harness.
 edition = "2015"       # The edition of the target.
@@ -247,7 +246,7 @@ libraries and binaries.
 
 ### The `plugin` field
 
-This field is used for `rustc` plugins, which are being deprecated.
+This option is deprecated and unused.
 
 ### The `proc-macro` field
 
diff --git a/src/doc/src/reference/environment-variables.md b/src/doc/src/reference/environment-variables.md
index 45de5329b..9904b6626 100644
--- a/src/doc/src/reference/environment-variables.md
+++ b/src/doc/src/reference/environment-variables.md
@@ -299,7 +299,7 @@ Cargo includes the following paths:
   Cargo to properly set the environment if additional libraries on the system
   are needed in the search path.
 * The base output directory, such as `target/debug`, and the "deps" directory.
-  This is mostly for legacy support of `rustc` compiler plugins.
+  This is mostly for support of proc-macros.
 * The rustc sysroot library path. This generally is not important to most
   users.
 


Test patch:
diff --git a/tests/testsuite/bench.rs b/tests/testsuite/bench.rs
index 85efeaba5..eb9c92c1e 100644
--- a/tests/testsuite/bench.rs
+++ b/tests/testsuite/bench.rs
@@ -267,9 +267,9 @@ fn many_similar_names() {
         .build();
 
     p.cargo("bench")
-        .with_stdout_contains("test bin_bench ... bench:[..]")
-        .with_stdout_contains("test lib_bench ... bench:[..]")
-        .with_stdout_contains("test bench_bench ... bench:[..]")
+        .with_stdout_contains("test bin_bench ... bench:           0 ns/iter (+/- 0)")
+        .with_stdout_contains("test lib_bench ... bench:           0 ns/iter (+/- 0)")
+        .with_stdout_contains("test bench_bench ... bench:           0 ns/iter (+/- 0)")
         .run();
 }
 
diff --git a/tests/testsuite/build_script.rs b/tests/testsuite/build_script.rs
index ef7630923..65a004ee6 100644
--- a/tests/testsuite/build_script.rs
+++ b/tests/testsuite/build_script.rs
@@ -2177,61 +2177,6 @@ fn shared_dep_with_a_build_script() {
     p.cargo("build -v").run();
 }
 
-#[cargo_test]
-fn transitive_dep_host() {
-    let p = project()
-        .file(
-            "Cargo.toml",
-            r#"
-                [package]
-                name = "foo"
-                version = "0.5.0"
-                edition = "2015"
-                authors = []
-                build = "build.rs"
-
-                [build-dependencies.b]
-                path = "b"
-            "#,
-        )
-        .file("src/lib.rs", "")
-        .file("build.rs", "fn main() {}")
-        .file(
-            "a/Cargo.toml",
-            r#"
-                [package]
-                name = "a"
-                version = "0.5.0"
-                edition = "2015"
-                authors = []
-                links = "foo"
-                build = "build.rs"
-            "#,
-        )
-        .file("a/build.rs", "fn main() {}")
-        .file("a/src/lib.rs", "")
-        .file(
-            "b/Cargo.toml",
-            r#"
-                [package]
-                name = "b"
-                version = "0.5.0"
-                edition = "2015"
-                authors = []
-
-                [lib]
-                name = "b"
-                plugin = true
-
-                [dependencies.a]
-                path = "../a"
-            "#,
-        )
-        .file("b/src/lib.rs", "")
-        .build();
-    p.cargo("build").run();
-}
-
 #[cargo_test]
 fn test_a_lib_with_a_build_command() {
     let p = project()
diff --git a/tests/testsuite/cross_compile.rs b/tests/testsuite/cross_compile.rs
index bcb0a4190..85cc7174c 100644
--- a/tests/testsuite/cross_compile.rs
+++ b/tests/testsuite/cross_compile.rs
@@ -883,47 +883,6 @@ fn build_script_only_host() {
     p.cargo("build -v --target").arg(&target).run();
 }
 
-#[cargo_test]
-fn plugin_build_script_right_arch() {
-    if cross_compile::disabled() {
-        return;
-    }
-    let p = project()
-        .file(
-            "Cargo.toml",
-            r#"
-                [package]
-                name = "foo"
-                version = "0.0.1"
-                edition = "2015"
-                authors = []
-                build = "build.rs"
-
-                [lib]
-                name = "foo"
-                plugin = true
-            "#,
-        )
-        .file("build.rs", "fn main() {}")
-        .file("src/lib.rs", "")
-        .build();
-
-    p.cargo("build -v --target")
-        .arg(cross_compile::alternate())
-        .with_stderr(
-            "\
-[WARNING] support for rustc plugins has been removed from rustc. library `foo` should not specify `plugin = true`
-[WARNING] support for `plugin = true` will be removed from cargo in the future
-[COMPILING] foo v0.0.1 ([..])
-[RUNNING] `rustc [..] build.rs [..]`
-[RUNNING] `[..]/build-script-build`
-[RUNNING] `rustc [..] src/lib.rs [..]`
-[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
-",
-        )
-        .run();
-}
-
 #[cargo_test]
 fn build_script_with_platform_specific_dependencies() {
     if cross_compile::disabled() {
diff --git a/tests/testsuite/proc_macro.rs b/tests/testsuite/proc_macro.rs
index 86bfe086c..0d793f10c 100644
--- a/tests/testsuite/proc_macro.rs
+++ b/tests/testsuite/proc_macro.rs
@@ -346,7 +346,7 @@ fn proc_macro_crate_type_warning() {
 }
 
 #[cargo_test]
-fn proc_macro_crate_type_warning_plugin() {
+fn lib_plugin_unused_key_warning() {
     let foo = project()
         .file(
             "Cargo.toml",
@@ -356,7 +356,6 @@ fn proc_macro_crate_type_warning_plugin() {
                 version = "0.1.0"
                 edition = "2015"
                 [lib]
-                crate-type = ["proc-macro"]
                 plugin = true
             "#,
         )
@@ -364,18 +363,33 @@ fn proc_macro_crate_type_warning_plugin() {
         .build();
 
     foo.cargo("check")
-        .with_stderr_contains(
-            "[WARNING] support for rustc plugins has been removed from rustc. \
-            library `foo` should not specify `plugin = true`")
-        .with_stderr_contains(
-            "[WARNING] support for `plugin = true` will be removed from cargo in the future")
-        .with_stderr_contains(
-            "[WARNING] proc-macro library `foo` should not specify `plugin = true`")
-        .with_stderr_contains(
-            "[WARNING] library `foo` should only specify `proc-macro = true` instead of setting `crate-type`")
+        .with_stderr_contains("[WARNING] unused manifest key: lib.plugin")
         .run();
 }
 
+#[cargo_test]
+fn proc_macro_crate_type_warning_plugin() {
+    let foo = project()
+        .file(
+            "Cargo.toml",
+            r#"
+                [package]
+                name = "foo"
+                version = "0.1.0"
+                edition = "2015"
+                [lib]
+                crate-type = ["proc-macro"]
+            "#,
+        )
+        .file("src/lib.rs", "")
+        .build();
+
+    foo.cargo("check")
+    .with_stderr_contains(
+        "[WARNING] library `foo` should only specify `proc-macro = true` instead of setting `crate-type`")
+    .run();
+}
+
 #[cargo_test]
 fn proc_macro_crate_type_multiple() {
     let foo = project()
diff --git a/tests/testsuite/rustflags.rs b/tests/testsuite/rustflags.rs
index 1f7ca1bd7..564f70c33 100644
--- a/tests/testsuite/rustflags.rs
+++ b/tests/testsuite/rustflags.rs
@@ -1,9 +1,7 @@
 //! Tests for setting custom rustc flags.
 
 use cargo_test_support::registry::Package;
-use cargo_test_support::{
-    basic_lib_manifest, basic_manifest, paths, project, project_in_home, rustc_host,
-};
+use cargo_test_support::{basic_manifest, paths, project, project_in_home, rustc_host};
 use std::fs;
 
 #[cargo_test]
@@ -114,76 +112,6 @@ fn env_rustflags_build_script_dep() {
     foo.cargo("check").env("RUSTFLAGS", "--cfg foo").run();
 }
 
-#[cargo_test]
-fn env_rustflags_plugin() {
-    // RUSTFLAGS should be passed to rustc for plugins
-    // when --target is not specified.
-    // In this test if --cfg foo is not passed the build will fail.
-    let p = project()
-        .file(
-            "Cargo.toml",
-            r#"
-                [package]
-                name = "foo"
-                version = "0.0.1"
-
-                [lib]
-                name = "foo"
-                plugin = true
-            "#,
-        )
-        .file(
-            "src/lib.rs",
-            r#"
-                fn main() { }
-                #[cfg(not(foo))]
-                fn main() { }
-            "#,
-        )
-        .build();
-
-    p.cargo("check").env("RUSTFLAGS", "--cfg foo").run();
-}
-
-#[cargo_test]
-fn env_rustflags_plugin_dep() {
-    // RUSTFLAGS should be passed to rustc for plugins
-    // when --target is not specified.
-    // In this test if --cfg foo is not passed the build will fail.
-    let foo = project()
-        .file(
-            "Cargo.toml",
-            r#"
-                [package]
-                name = "foo"
-                version = "0.0.1"
-
-                [lib]
-                name = "foo"
-                plugin = true
-
-                [dependencies.bar]
-                path = "../bar"
-            "#,
-        )
-        .file("src/lib.rs", "fn foo() {}")
-        .build();
-    let _bar = project()
-        .at("bar")
-        .file("Cargo.toml", &basic_lib_manifest("bar"))
-        .file(
-            "src/lib.rs",
-            r#"
-                fn bar() { }
-                #[cfg(not(foo))]
-                fn bar() { }
-            "#,
-        )
-        .build();
-
-    foo.cargo("check").env("RUSTFLAGS", "--cfg foo").run();
-}
-
 #[cargo_test]
 fn env_rustflags_normal_source_with_target() {
     let p = project()
@@ -345,84 +273,6 @@ fn env_rustflags_build_script_dep_with_target() {
         .run();
 }
 
-#[cargo_test]
-fn env_rustflags_plugin_with_target() {
-    // RUSTFLAGS should not be passed to rustc for plugins
-    // when --target is specified.
-    // In this test if --cfg foo is passed the build will fail.
-    let p = project()
-        .file(
-            "Cargo.toml",
-            r#"
-                [package]
-                name = "foo"
-                version = "0.0.1"
-
-                [lib]
-                name = "foo"
-                plugin = true
-            "#,
-        )
-        .file(
-            "src/lib.rs",
-            r#"
-                fn main() { }
-                #[cfg(foo)]
-                fn main() { }
-            "#,
-        )
-        .build();
-
-    let host = rustc_host();
-    p.cargo("check --target")
-        .arg(host)
-        .env("RUSTFLAGS", "--cfg foo")
-        .run();
-}
-
-#[cargo_test]
-fn env_rustflags_plugin_dep_with_target() {
-    // RUSTFLAGS should not be passed to rustc for plugins
-    // when --target is specified.
-    // In this test if --cfg foo is passed the build will fail.
-    let foo = project()
-        .file(
-            "Cargo.toml",
-            r#"
-                [package]
-                name = "foo"
-                version = "0.0.1"
-
-                [lib]
-                name = "foo"
-                plugin = true
-
-                [dependencies.bar]
-                path = "../bar"
-            "#,
-        )
-        .file("src/lib.rs", "fn foo() {}")
-        .build();
-    let _bar = project()
-        .at("bar")
-        .file("Cargo.toml", &basic_lib_manifest("bar"))
-        .file(
-            "src/lib.rs",
-            r#"
-                fn bar() { }
-                #[cfg(foo)]
-                fn bar() { }
-            "#,
-        )
-        .build();
-
-    let host = rustc_host();
-    foo.cargo("check --target")
-        .arg(host)
-        .env("RUSTFLAGS", "--cfg foo")
-        .run();
-}
-
 #[cargo_test]
 fn env_rustflags_recompile() {
     let p = project().file("src/lib.rs", "").build();
@@ -583,90 +433,6 @@ fn build_rustflags_build_script_dep() {
     foo.cargo("check").run();
 }
 
-#[cargo_test]
-fn build_rustflags_plugin() {
-    // RUSTFLAGS should be passed to rustc for plugins
-    // when --target is not specified.
-    // In this test if --cfg foo is not passed the build will fail.
-    let p = project()
-        .file(
-            "Cargo.toml",
-            r#"
-                [package]
-                name = "foo"
-                version = "0.0.1"
-
-                [lib]
-                name = "foo"
-                plugin = true
-            "#,
-        )
-        .file(
-            "src/lib.rs",
-            r#"
-                fn main() { }
-                #[cfg(not(foo))]
-                fn main() { }
-            "#,
-        )
-        .file(
-            ".cargo/config.toml",
-            r#"
-            [build]
-            rustflags = ["--cfg", "foo"]
-            "#,
-        )
-        .build();
-
-    p.cargo("check").run();
-}
-
-#[cargo_test]
-fn build_rustflags_plugin_dep() {
-    // RUSTFLAGS should be passed to rustc for plugins
-    // when --target is not specified.
-    // In this test if --cfg foo is not passed the build will fail.
-    let foo = project()
-        .file(
-            "Cargo.toml",
-            r#"
-                [package]
-                name = "foo"
-                version = "0.0.1"
-
-                [lib]
-                name = "foo"
-                plugin = true
-
-                [dependencies.bar]
-                path = "../bar"
-            "#,
-        )
-        .file("src/lib.rs", "fn foo() {}")
-        .file(
-            ".cargo/config.toml",
-            r#"
-            [build]
-            rustflags = ["--cfg", "foo"]
-            "#,
-        )
-        .build();
-    let _bar = project()
-        .at("bar")
-        .file("Cargo.toml", &basic_lib_manifest("bar"))
-        .file(
-            "src/lib.rs",
-            r#"
-                fn bar() { }
-                #[cfg(not(foo))]
-                fn bar() { }
-            "#,
-        )
-        .build();
-
-    foo.cargo("check").run();
-}
-
 #[cargo_test]
 fn build_rustflags_normal_source_with_target() {
     let p = project()
@@ -800,92 +566,6 @@ fn build_rustflags_build_script_dep_with_target() {
     foo.cargo("check --target").arg(host).run();
 }
 
-#[cargo_test]
-fn build_rustflags_plugin_with_target() {
-    // RUSTFLAGS should not be passed to rustc for plugins
-    // when --target is specified.
-    // In this test if --cfg foo is passed the build will fail.
-    let p = project()
-        .file(
-            "Cargo.toml",
-            r#"
-                [package]
-                name = "foo"
-                version = "0.0.1"
-
-                [lib]
-                name = "foo"
-                plugin = true
-            "#,
-        )
-        .file(
-            "src/lib.rs",
-            r#"
-                fn main() { }
-                #[cfg(foo)]
-                fn main() { }
-            "#,
-        )
-        .file(
-            ".cargo/config.toml",
-            r#"
-            [build]
-            rustflags = ["--cfg", "foo"]
-            "#,
-        )
-        .build();
-
-    let host = rustc_host();
-    p.cargo("check --target").arg(host).run();
-}
-
-#[cargo_test]
-fn build_rustflags_plugin_dep_with_target() {
-    // RUSTFLAGS should not be passed to rustc for plugins
-    // when --target is specified.
-    // In this test if --cfg foo is passed the build will fail.
-    let foo = project()
-        .file(
-            "Cargo.toml",
-            r#"
-                [package]
-                name = "foo"
-                version = "0.0.1"
-
-                [lib]
-                name = "foo"
-                plugin = true
-
-                [dependencies.bar]
-                path = "../bar"
-            "#,
-        )
-        .file("src/lib.rs", "fn foo() {}")
-        .file(
-            ".cargo/config.toml",
-            r#"
-            [build]
-            rustflags = ["--cfg", "foo"]
-            "#,
-        )
-        .build();
-    let _bar = project()
-        .at("bar")
-        .file("Cargo.toml", &basic_lib_manifest("bar"))
-        .file(
-            "src/lib.rs",
-            r#"
-                fn bar() { }
-                #[cfg(foo)]
-                fn bar() { }
-            "#,
-        )
-        .build();
-
-    let host = rustc_host();
-    foo.cargo("check --target").arg(host).run();
-}
-
 #[cargo_test]
 fn build_rustflags_recompile() {
     let p = project().file("src/lib.rs", "").build();