about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2021-04-05 00:24:33 +0200
committerGitHub <noreply@github.com>2021-04-05 00:24:33 +0200
commit3c2e4ff525a710987c4e01805edf051740cb022b (patch)
tree5d5d3047093a747e9f411de20de4227ec8c0cf78
parentfbe89e20e83bd726b34ee0462ac96f2515f5945d (diff)
parent5839bff0bac6063147c8905388713a787577208f (diff)
downloadrust-3c2e4ff525a710987c4e01805edf051740cb022b.tar.gz
rust-3c2e4ff525a710987c4e01805edf051740cb022b.zip
Rollup merge of #83820 - petrochenkov:nolinkargs, r=nagisa
Remove attribute `#[link_args]`

Closes https://github.com/rust-lang/rust/issues/29596

The attribute could always be replaced with `-C link-arg`, but cargo didn't provide a reasonable way to pass such flags to rustc.
Now cargo supports `cargo:rustc-link-arg*` directives in build scripts (https://doc.rust-lang.org/cargo/reference/unstable.html#extra-link-arg), so this attribute can be removed.
-rw-r--r--compiler/rustc_codegen_ssa/src/back/link.rs11
-rw-r--r--compiler/rustc_codegen_ssa/src/base.rs1
-rw-r--r--compiler/rustc_codegen_ssa/src/lib.rs1
-rw-r--r--compiler/rustc_feature/src/active.rs3
-rw-r--r--compiler/rustc_feature/src/builtin_attrs.rs5
-rw-r--r--compiler/rustc_feature/src/removed.rs4
-rw-r--r--compiler/rustc_metadata/src/lib.rs1
-rw-r--r--compiler/rustc_metadata/src/link_args.rs57
-rw-r--r--compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs5
-rw-r--r--compiler/rustc_middle/src/query/mod.rs5
-rw-r--r--library/std/src/lib.rs1
-rw-r--r--src/doc/unstable-book/src/language-features/link-args.md32
-rw-r--r--src/test/incremental/hashes/extern_mods.rs16
-rw-r--r--src/test/run-make-fulldeps/link-args-order/Makefile2
-rw-r--r--src/test/run-make-fulldeps/link-args-order/empty.rs5
-rw-r--r--src/test/ui/feature-gates/feature-gate-link_args.rs17
-rw-r--r--src/test/ui/feature-gates/feature-gate-link_args.stderr30
-rw-r--r--src/test/ui/issues/issue-15487.rs13
-rw-r--r--src/test/ui/linkage-attr/invalid-link-args.rs14
-rw-r--r--src/tools/clippy/tests/ui/crate_level_checks/no_std_main_recursion.rs4
-rw-r--r--src/tools/clippy/tests/ui/empty_loop_no_std.rs4
21 files changed, 12 insertions, 219 deletions
diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs
index 217b8f43229..ea75943d6f3 100644
--- a/compiler/rustc_codegen_ssa/src/back/link.rs
+++ b/compiler/rustc_codegen_ssa/src/back/link.rs
@@ -1411,15 +1411,10 @@ fn add_link_script(cmd: &mut dyn Linker, sess: &Session, tmpdir: &Path, crate_ty
     }
 }
 
-/// Add arbitrary "user defined" args defined from command line and by `#[link_args]` attributes.
+/// Add arbitrary "user defined" args defined from command line.
 /// FIXME: Determine where exactly these args need to be inserted.
-fn add_user_defined_link_args(
-    cmd: &mut dyn Linker,
-    sess: &Session,
-    codegen_results: &CodegenResults,
-) {
+fn add_user_defined_link_args(cmd: &mut dyn Linker, sess: &Session) {
     cmd.args(&sess.opts.cg.link_args);
-    cmd.args(&*codegen_results.crate_info.link_args);
 }
 
 /// Add arbitrary "late link" args defined by the target spec.
@@ -1761,7 +1756,7 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
     add_rpath_args(cmd, sess, codegen_results, out_filename);
 
     // OBJECT-FILES-MAYBE, CUSTOMIZATION-POINT
-    add_user_defined_link_args(cmd, sess, codegen_results);
+    add_user_defined_link_args(cmd, sess);
 
     // NO-OPT-OUT, OBJECT-FILES-NO, AUDIT-ORDER
     cmd.finalize();
diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs
index 08e31c3b37f..318eed76acf 100644
--- a/compiler/rustc_codegen_ssa/src/base.rs
+++ b/compiler/rustc_codegen_ssa/src/base.rs
@@ -754,7 +754,6 @@ impl CrateInfo {
             is_no_builtins: Default::default(),
             native_libraries: Default::default(),
             used_libraries: tcx.native_libraries(LOCAL_CRATE).iter().map(Into::into).collect(),
-            link_args: tcx.link_args(LOCAL_CRATE),
             crate_name: Default::default(),
             used_crates_dynamic: cstore::used_crates(tcx, LinkagePreference::RequireDynamic),
             used_crates_static: cstore::used_crates(tcx, LinkagePreference::RequireStatic),
diff --git a/compiler/rustc_codegen_ssa/src/lib.rs b/compiler/rustc_codegen_ssa/src/lib.rs
index 56b4ef79383..f0f45b067b3 100644
--- a/compiler/rustc_codegen_ssa/src/lib.rs
+++ b/compiler/rustc_codegen_ssa/src/lib.rs
@@ -139,7 +139,6 @@ pub struct CrateInfo {
     pub native_libraries: FxHashMap<CrateNum, Vec<NativeLib>>,
     pub crate_name: FxHashMap<CrateNum, String>,
     pub used_libraries: Vec<NativeLib>,
-    pub link_args: Lrc<Vec<String>>,
     pub used_crate_source: FxHashMap<CrateNum, Lrc<CrateSource>>,
     pub used_crates_static: Vec<(CrateNum, LibSource)>,
     pub used_crates_dynamic: Vec<(CrateNum, LibSource)>,
diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs
index 040260f5cf5..abbeb9554e3 100644
--- a/compiler/rustc_feature/src/active.rs
+++ b/compiler/rustc_feature/src/active.rs
@@ -258,9 +258,6 @@ declare_features! (
     // feature-group-start: actual feature gates
     // -------------------------------------------------------------------------
 
-    /// Allows using the `#[link_args]` attribute.
-    (active, link_args, "1.0.0", Some(29596), None),
-
     /// Allows defining identifiers beyond ASCII.
     (active, non_ascii_idents, "1.0.0", Some(55467), None),
 
diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs
index 072062dd615..7df9b3f0a79 100644
--- a/compiler/rustc_feature/src/builtin_attrs.rs
+++ b/compiler/rustc_feature/src/builtin_attrs.rs
@@ -280,11 +280,6 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
     // Linking:
     gated!(naked, AssumedUsed, template!(Word), naked_functions, experimental!(naked)),
     gated!(
-        link_args, Normal, template!(NameValueStr: "args"),
-        "the `link_args` attribute is experimental and not portable across platforms, \
-        it is recommended to use `#[link(name = \"foo\")] instead",
-    ),
-    gated!(
         link_ordinal, AssumedUsed, template!(List: "ordinal"), raw_dylib,
         experimental!(link_ordinal)
     ),
diff --git a/compiler/rustc_feature/src/removed.rs b/compiler/rustc_feature/src/removed.rs
index 8ba67a00f8d..e1491576616 100644
--- a/compiler/rustc_feature/src/removed.rs
+++ b/compiler/rustc_feature/src/removed.rs
@@ -128,6 +128,10 @@ declare_features! (
     /// Allows comparing raw pointers during const eval.
     (removed, const_compare_raw_pointers, "1.46.0", Some(53020), None,
      Some("cannot be allowed in const eval in any meaningful way")),
+    /// Allows using the `#[link_args]` attribute.
+    (removed, link_args, "1.53.0", Some(29596), None,
+     Some("removed in favor of using `-C link-arg=ARG` on command line, \
+           which is available from cargo build scripts with `cargo:rustc-link-arg` now")),
 
     // -------------------------------------------------------------------------
     // feature-group-end: removed features
diff --git a/compiler/rustc_metadata/src/lib.rs b/compiler/rustc_metadata/src/lib.rs
index fe93f4230e9..c4d9e3f77f0 100644
--- a/compiler/rustc_metadata/src/lib.rs
+++ b/compiler/rustc_metadata/src/lib.rs
@@ -26,7 +26,6 @@ pub use rmeta::{provide, provide_extern};
 
 mod dependency_format;
 mod foreign_modules;
-mod link_args;
 mod native_libs;
 mod rmeta;
 
diff --git a/compiler/rustc_metadata/src/link_args.rs b/compiler/rustc_metadata/src/link_args.rs
deleted file mode 100644
index 9e1ac33368c..00000000000
--- a/compiler/rustc_metadata/src/link_args.rs
+++ /dev/null
@@ -1,57 +0,0 @@
-use rustc_hir as hir;
-use rustc_hir::itemlikevisit::ItemLikeVisitor;
-use rustc_middle::ty::TyCtxt;
-use rustc_span::symbol::{sym, Symbol};
-use rustc_target::spec::abi::Abi;
-
-crate fn collect(tcx: TyCtxt<'_>) -> Vec<String> {
-    let mut collector = Collector { tcx, args: Vec::new() };
-    tcx.hir().krate().visit_all_item_likes(&mut collector);
-
-    for attr in tcx.hir().attrs(hir::CRATE_HIR_ID).iter() {
-        if attr.has_name(sym::link_args) {
-            if let Some(linkarg) = attr.value_str() {
-                collector.add_link_args(linkarg);
-            }
-        }
-    }
-
-    collector.args
-}
-
-struct Collector<'tcx> {
-    tcx: TyCtxt<'tcx>,
-    args: Vec<String>,
-}
-
-impl<'tcx> ItemLikeVisitor<'tcx> for Collector<'tcx> {
-    fn visit_item(&mut self, it: &'tcx hir::Item<'tcx>) {
-        let abi = match it.kind {
-            hir::ItemKind::ForeignMod { abi, .. } => abi,
-            _ => return,
-        };
-        if abi == Abi::Rust || abi == Abi::RustIntrinsic || abi == Abi::PlatformIntrinsic {
-            return;
-        }
-
-        // First, add all of the custom #[link_args] attributes
-        let sess = &self.tcx.sess;
-        for m in
-            self.tcx.hir().attrs(it.hir_id()).iter().filter(|a| sess.check_name(a, sym::link_args))
-        {
-            if let Some(linkarg) = m.value_str() {
-                self.add_link_args(linkarg);
-            }
-        }
-    }
-
-    fn visit_trait_item(&mut self, _it: &'tcx hir::TraitItem<'tcx>) {}
-    fn visit_impl_item(&mut self, _it: &'tcx hir::ImplItem<'tcx>) {}
-    fn visit_foreign_item(&mut self, _it: &'tcx hir::ForeignItem<'tcx>) {}
-}
-
-impl<'tcx> Collector<'tcx> {
-    fn add_link_args(&mut self, args: Symbol) {
-        self.args.extend(args.as_str().split(' ').filter(|s| !s.is_empty()).map(|s| s.to_string()))
-    }
-}
diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
index e10041a2971..bebee9dac3b 100644
--- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
+++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
@@ -1,6 +1,5 @@
 use crate::creader::{CStore, LoadedMacro};
 use crate::foreign_modules;
-use crate::link_args;
 use crate::native_libs;
 use crate::rmeta::{self, encoder};
 
@@ -295,10 +294,6 @@ pub fn provide(providers: &mut Providers) {
                 foreign_modules::collect(tcx).into_iter().map(|m| (m.def_id, m)).collect();
             Lrc::new(modules)
         },
-        link_args: |tcx, cnum| {
-            assert_eq!(cnum, LOCAL_CRATE);
-            Lrc::new(link_args::collect(tcx))
-        },
 
         // Returns a map from a sufficiently visible external item (i.e., an
         // external item that is visible from at least one local module) to a
diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs
index bf39b1da8f0..bac69e282a5 100644
--- a/compiler/rustc_middle/src/query/mod.rs
+++ b/compiler/rustc_middle/src/query/mod.rs
@@ -1253,11 +1253,6 @@ rustc_queries! {
         desc { |tcx| "native_library_kind({})", tcx.def_path_str(def_id) }
     }
 
-    query link_args(_: CrateNum) -> Lrc<Vec<String>> {
-        eval_always
-        desc { "looking up link arguments for a crate" }
-    }
-
     /// Does lifetime resolution, but does not descend into trait items. This
     /// should only be used for resolving lifetimes of on trait definitions,
     /// and is used to avoid cycles. Importantly, `resolve_lifetimes` still visits
diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs
index 6ab68100b1d..106ac51d87c 100644
--- a/library/std/src/lib.rs
+++ b/library/std/src/lib.rs
@@ -282,7 +282,6 @@
 #![feature(intra_doc_pointers)]
 #![feature(iter_zip)]
 #![feature(lang_items)]
-#![feature(link_args)]
 #![feature(linkage)]
 #![feature(llvm_asm)]
 #![feature(log_syntax)]
diff --git a/src/doc/unstable-book/src/language-features/link-args.md b/src/doc/unstable-book/src/language-features/link-args.md
deleted file mode 100644
index da36e158001..00000000000
--- a/src/doc/unstable-book/src/language-features/link-args.md
+++ /dev/null
@@ -1,32 +0,0 @@
-# `link_args`
-
-The tracking issue for this feature is: [#29596]
-
-[#29596]: https://github.com/rust-lang/rust/issues/29596
-
-------------------------
-
-You can tell `rustc` how to customize linking, and that is via the `link_args`
-attribute. This attribute is applied to `extern` blocks and specifies raw flags
-which need to get passed to the linker when producing an artifact. An example
-usage would be:
-
-```rust,no_run
-#![feature(link_args)]
-
-#[link_args = "-foo -bar -baz"]
-extern "C" {}
-# fn main() {}
-```
-
-Note that this feature is currently hidden behind the `feature(link_args)` gate
-because this is not a sanctioned way of performing linking. Right now `rustc`
-shells out to the system linker (`gcc` on most systems, `link.exe` on MSVC), so
-it makes sense to provide extra command line arguments, but this will not
-always be the case. In the future `rustc` may use LLVM directly to link native
-libraries, in which case `link_args` will have no meaning. You can achieve the
-same effect as the `link_args` attribute with the `-C link-args` argument to
-`rustc`.
-
-It is highly recommended to *not* use this attribute, and rather use the more
-formal `#[link(...)]` attribute on `extern` blocks instead.
diff --git a/src/test/incremental/hashes/extern_mods.rs b/src/test/incremental/hashes/extern_mods.rs
index 7a923134331..93e70d3792c 100644
--- a/src/test/incremental/hashes/extern_mods.rs
+++ b/src/test/incremental/hashes/extern_mods.rs
@@ -12,7 +12,6 @@
 #![allow(warnings)]
 #![feature(rustc_attrs)]
 #![feature(unboxed_closures)]
-#![feature(link_args)]
 #![crate_type = "rlib"]
 
 // Change function name --------------------------------------------------------
@@ -146,21 +145,6 @@ extern "C" {
     pub fn add_function2();
 }
 
-// Change link-args ------------------------------------------------------------
-#[cfg(cfail1)]
-#[link_args = "-foo -bar"]
-extern "C" {
-    pub fn change_link_args(c: i32);
-}
-
-#[cfg(not(cfail1))]
-#[rustc_dirty(cfg = "cfail2", except = "hir_owner,hir_owner_nodes")]
-#[rustc_clean(cfg = "cfail3")]
-#[link_args = "-foo -bar -baz"]
-extern "C" {
-    pub fn change_link_args(c: i32);
-}
-
 // Change link-name ------------------------------------------------------------
 #[cfg(cfail1)]
 #[link(name = "foo")]
diff --git a/src/test/run-make-fulldeps/link-args-order/Makefile b/src/test/run-make-fulldeps/link-args-order/Makefile
index 98c1e0eac3b..f94e882ccb6 100644
--- a/src/test/run-make-fulldeps/link-args-order/Makefile
+++ b/src/test/run-make-fulldeps/link-args-order/Makefile
@@ -6,5 +6,5 @@ RUSTC_FLAGS = -C linker-flavor=ld -C link-arg=a -C link-args="b c" -C link-args=
 RUSTC_FLAGS_PRE = -C linker-flavor=ld -Z pre-link-arg=a -Z pre-link-args="b c" -Z pre-link-args="d e" -Z pre-link-arg=f
 
 all:
-	$(RUSTC) $(RUSTC_FLAGS) empty.rs 2>&1 | $(CGREP) '"a" "b" "c" "d" "e" "f" "g"'
+	$(RUSTC) $(RUSTC_FLAGS) empty.rs 2>&1 | $(CGREP) '"a" "b" "c" "d" "e" "f"'
 	$(RUSTC) $(RUSTC_FLAGS_PRE) empty.rs 2>&1 | $(CGREP) '"a" "b" "c" "d" "e" "f"'
diff --git a/src/test/run-make-fulldeps/link-args-order/empty.rs b/src/test/run-make-fulldeps/link-args-order/empty.rs
index 2439171004b..f328e4d9d04 100644
--- a/src/test/run-make-fulldeps/link-args-order/empty.rs
+++ b/src/test/run-make-fulldeps/link-args-order/empty.rs
@@ -1,6 +1 @@
-#![feature(link_args)]
-
-#[link_args = "g"]
-extern "C" {}
-
 fn main() {}
diff --git a/src/test/ui/feature-gates/feature-gate-link_args.rs b/src/test/ui/feature-gates/feature-gate-link_args.rs
deleted file mode 100644
index e1c651f46fb..00000000000
--- a/src/test/ui/feature-gates/feature-gate-link_args.rs
+++ /dev/null
@@ -1,17 +0,0 @@
-// Test that `#[link_args]` attribute is gated by `link_args`
-// feature gate, both when it occurs where expected (atop
-// `extern { }` blocks) and where unexpected.
-
-// sidestep warning (which is correct, but misleading for
-// purposes of this test)
-#![allow(unused_attributes)]
-#![link_args = "-l unexpected_use_as_inner_attr_on_mod"]
-//~^ ERROR the `link_args` attribute is experimental
-
-#[link_args = "-l expected_use_case"]
-//~^ ERROR the `link_args` attribute is experimental
-extern "C" {}
-
-#[link_args = "-l unexected_use_on_non_extern_item"]
-//~^ ERROR: the `link_args` attribute is experimental
-fn main() {}
diff --git a/src/test/ui/feature-gates/feature-gate-link_args.stderr b/src/test/ui/feature-gates/feature-gate-link_args.stderr
deleted file mode 100644
index ae4918f5c9f..00000000000
--- a/src/test/ui/feature-gates/feature-gate-link_args.stderr
+++ /dev/null
@@ -1,30 +0,0 @@
-error[E0658]: the `link_args` attribute is experimental and not portable across platforms, it is recommended to use `#[link(name = "foo")] instead
-  --> $DIR/feature-gate-link_args.rs:11:1
-   |
-LL | #[link_args = "-l expected_use_case"]
-   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-   |
-   = note: see issue #29596 <https://github.com/rust-lang/rust/issues/29596> for more information
-   = help: add `#![feature(link_args)]` to the crate attributes to enable
-
-error[E0658]: the `link_args` attribute is experimental and not portable across platforms, it is recommended to use `#[link(name = "foo")] instead
-  --> $DIR/feature-gate-link_args.rs:15:1
-   |
-LL | #[link_args = "-l unexected_use_on_non_extern_item"]
-   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-   |
-   = note: see issue #29596 <https://github.com/rust-lang/rust/issues/29596> for more information
-   = help: add `#![feature(link_args)]` to the crate attributes to enable
-
-error[E0658]: the `link_args` attribute is experimental and not portable across platforms, it is recommended to use `#[link(name = "foo")] instead
-  --> $DIR/feature-gate-link_args.rs:8:1
-   |
-LL | #![link_args = "-l unexpected_use_as_inner_attr_on_mod"]
-   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-   |
-   = note: see issue #29596 <https://github.com/rust-lang/rust/issues/29596> for more information
-   = help: add `#![feature(link_args)]` to the crate attributes to enable
-
-error: aborting due to 3 previous errors
-
-For more information about this error, try `rustc --explain E0658`.
diff --git a/src/test/ui/issues/issue-15487.rs b/src/test/ui/issues/issue-15487.rs
deleted file mode 100644
index 34ac53be5be..00000000000
--- a/src/test/ui/issues/issue-15487.rs
+++ /dev/null
@@ -1,13 +0,0 @@
-// run-pass
-#![allow(unused_attributes)]
-// ignore-windows
-// ignore-wasm32-bare no libs to link
-// ignore-sgx no libs to link
-#![feature(link_args)]
-
-#[link_args = "-lc  -lm"]
-#[link_args = " -lc"]
-#[link_args = "-lc "]
-extern "C" {}
-
-fn main() {}
diff --git a/src/test/ui/linkage-attr/invalid-link-args.rs b/src/test/ui/linkage-attr/invalid-link-args.rs
deleted file mode 100644
index 7418691d014..00000000000
--- a/src/test/ui/linkage-attr/invalid-link-args.rs
+++ /dev/null
@@ -1,14 +0,0 @@
-// build-fail
-// dont-check-compiler-stderr
-// ignore-msvc due to linker-flavor=ld
-// error-pattern:aFdEfSeVEEE
-// compile-flags: -C linker-flavor=ld
-
-/* Make sure invalid link_args are printed to stderr. */
-
-#![feature(link_args)]
-
-#[link_args = "aFdEfSeVEEE"]
-extern "C" {}
-
-fn main() {}
diff --git a/src/tools/clippy/tests/ui/crate_level_checks/no_std_main_recursion.rs b/src/tools/clippy/tests/ui/crate_level_checks/no_std_main_recursion.rs
index 25b1417be97..be4348e2bb7 100644
--- a/src/tools/clippy/tests/ui/crate_level_checks/no_std_main_recursion.rs
+++ b/src/tools/clippy/tests/ui/crate_level_checks/no_std_main_recursion.rs
@@ -1,8 +1,8 @@
+// compile-flags: -Clink-arg=-nostartfiles
 // ignore-macos
 // ignore-windows
 
-#![feature(lang_items, link_args, start, libc)]
-#![link_args = "-nostartfiles"]
+#![feature(lang_items, start, libc)]
 #![no_std]
 
 use core::panic::PanicInfo;
diff --git a/src/tools/clippy/tests/ui/empty_loop_no_std.rs b/src/tools/clippy/tests/ui/empty_loop_no_std.rs
index 4553d3ec505..235e0fc5179 100644
--- a/src/tools/clippy/tests/ui/empty_loop_no_std.rs
+++ b/src/tools/clippy/tests/ui/empty_loop_no_std.rs
@@ -1,9 +1,9 @@
+// compile-flags: -Clink-arg=-nostartfiles
 // ignore-macos
 // ignore-windows
 
 #![warn(clippy::empty_loop)]
-#![feature(lang_items, link_args, start, libc)]
-#![link_args = "-nostartfiles"]
+#![feature(lang_items, start, libc)]
 #![no_std]
 
 use core::panic::PanicInfo;