Skip to content

Commit ade2667

Browse files
authored
Rollup merge of rust-lang#83820 - petrochenkov:nolinkargs, r=nagisa
Remove attribute `#[link_args]` Closes rust-lang#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.
2 parents 7056647 + 5839bff commit ade2667

File tree

21 files changed

+12
-219
lines changed

21 files changed

+12
-219
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -1411,15 +1411,10 @@ fn add_link_script(cmd: &mut dyn Linker, sess: &Session, tmpdir: &Path, crate_ty
14111411
}
14121412
}
14131413

1414-
/// Add arbitrary "user defined" args defined from command line and by `#[link_args]` attributes.
1414+
/// Add arbitrary "user defined" args defined from command line.
14151415
/// FIXME: Determine where exactly these args need to be inserted.
1416-
fn add_user_defined_link_args(
1417-
cmd: &mut dyn Linker,
1418-
sess: &Session,
1419-
codegen_results: &CodegenResults,
1420-
) {
1416+
fn add_user_defined_link_args(cmd: &mut dyn Linker, sess: &Session) {
14211417
cmd.args(&sess.opts.cg.link_args);
1422-
cmd.args(&*codegen_results.crate_info.link_args);
14231418
}
14241419

14251420
/// Add arbitrary "late link" args defined by the target spec.
@@ -1761,7 +1756,7 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
17611756
add_rpath_args(cmd, sess, codegen_results, out_filename);
17621757

17631758
// OBJECT-FILES-MAYBE, CUSTOMIZATION-POINT
1764-
add_user_defined_link_args(cmd, sess, codegen_results);
1759+
add_user_defined_link_args(cmd, sess);
17651760

17661761
// NO-OPT-OUT, OBJECT-FILES-NO, AUDIT-ORDER
17671762
cmd.finalize();

compiler/rustc_codegen_ssa/src/base.rs

-1
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,6 @@ impl CrateInfo {
754754
is_no_builtins: Default::default(),
755755
native_libraries: Default::default(),
756756
used_libraries: tcx.native_libraries(LOCAL_CRATE).iter().map(Into::into).collect(),
757-
link_args: tcx.link_args(LOCAL_CRATE),
758757
crate_name: Default::default(),
759758
used_crates_dynamic: cstore::used_crates(tcx, LinkagePreference::RequireDynamic),
760759
used_crates_static: cstore::used_crates(tcx, LinkagePreference::RequireStatic),

compiler/rustc_codegen_ssa/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ pub struct CrateInfo {
139139
pub native_libraries: FxHashMap<CrateNum, Vec<NativeLib>>,
140140
pub crate_name: FxHashMap<CrateNum, String>,
141141
pub used_libraries: Vec<NativeLib>,
142-
pub link_args: Lrc<Vec<String>>,
143142
pub used_crate_source: FxHashMap<CrateNum, Lrc<CrateSource>>,
144143
pub used_crates_static: Vec<(CrateNum, LibSource)>,
145144
pub used_crates_dynamic: Vec<(CrateNum, LibSource)>,

compiler/rustc_feature/src/active.rs

-3
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,6 @@ declare_features! (
258258
// feature-group-start: actual feature gates
259259
// -------------------------------------------------------------------------
260260

261-
/// Allows using the `#[link_args]` attribute.
262-
(active, link_args, "1.0.0", Some(29596), None),
263-
264261
/// Allows defining identifiers beyond ASCII.
265262
(active, non_ascii_idents, "1.0.0", Some(55467), None),
266263

compiler/rustc_feature/src/builtin_attrs.rs

-5
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,6 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
279279

280280
// Linking:
281281
gated!(naked, AssumedUsed, template!(Word), naked_functions, experimental!(naked)),
282-
gated!(
283-
link_args, Normal, template!(NameValueStr: "args"),
284-
"the `link_args` attribute is experimental and not portable across platforms, \
285-
it is recommended to use `#[link(name = \"foo\")] instead",
286-
),
287282
gated!(
288283
link_ordinal, AssumedUsed, template!(List: "ordinal"), raw_dylib,
289284
experimental!(link_ordinal)

compiler/rustc_feature/src/removed.rs

+4
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ declare_features! (
128128
/// Allows comparing raw pointers during const eval.
129129
(removed, const_compare_raw_pointers, "1.46.0", Some(53020), None,
130130
Some("cannot be allowed in const eval in any meaningful way")),
131+
/// Allows using the `#[link_args]` attribute.
132+
(removed, link_args, "1.53.0", Some(29596), None,
133+
Some("removed in favor of using `-C link-arg=ARG` on command line, \
134+
which is available from cargo build scripts with `cargo:rustc-link-arg` now")),
131135

132136
// -------------------------------------------------------------------------
133137
// feature-group-end: removed features

compiler/rustc_metadata/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ pub use rmeta::{provide, provide_extern};
2626

2727
mod dependency_format;
2828
mod foreign_modules;
29-
mod link_args;
3029
mod native_libs;
3130
mod rmeta;
3231

compiler/rustc_metadata/src/link_args.rs

-57
This file was deleted.

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::creader::{CStore, LoadedMacro};
22
use crate::foreign_modules;
3-
use crate::link_args;
43
use crate::native_libs;
54
use crate::rmeta::{self, encoder};
65

@@ -295,10 +294,6 @@ pub fn provide(providers: &mut Providers) {
295294
foreign_modules::collect(tcx).into_iter().map(|m| (m.def_id, m)).collect();
296295
Lrc::new(modules)
297296
},
298-
link_args: |tcx, cnum| {
299-
assert_eq!(cnum, LOCAL_CRATE);
300-
Lrc::new(link_args::collect(tcx))
301-
},
302297

303298
// Returns a map from a sufficiently visible external item (i.e., an
304299
// external item that is visible from at least one local module) to a

compiler/rustc_middle/src/query/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -1253,11 +1253,6 @@ rustc_queries! {
12531253
desc { |tcx| "native_library_kind({})", tcx.def_path_str(def_id) }
12541254
}
12551255

1256-
query link_args(_: CrateNum) -> Lrc<Vec<String>> {
1257-
eval_always
1258-
desc { "looking up link arguments for a crate" }
1259-
}
1260-
12611256
/// Does lifetime resolution, but does not descend into trait items. This
12621257
/// should only be used for resolving lifetimes of on trait definitions,
12631258
/// and is used to avoid cycles. Importantly, `resolve_lifetimes` still visits

library/std/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,6 @@
282282
#![feature(intra_doc_pointers)]
283283
#![feature(iter_zip)]
284284
#![feature(lang_items)]
285-
#![feature(link_args)]
286285
#![feature(linkage)]
287286
#![feature(llvm_asm)]
288287
#![feature(log_syntax)]

src/doc/unstable-book/src/language-features/link-args.md

-32
This file was deleted.

src/test/incremental/hashes/extern_mods.rs

-16
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#![allow(warnings)]
1313
#![feature(rustc_attrs)]
1414
#![feature(unboxed_closures)]
15-
#![feature(link_args)]
1615
#![crate_type = "rlib"]
1716

1817
// Change function name --------------------------------------------------------
@@ -146,21 +145,6 @@ extern "C" {
146145
pub fn add_function2();
147146
}
148147

149-
// Change link-args ------------------------------------------------------------
150-
#[cfg(cfail1)]
151-
#[link_args = "-foo -bar"]
152-
extern "C" {
153-
pub fn change_link_args(c: i32);
154-
}
155-
156-
#[cfg(not(cfail1))]
157-
#[rustc_dirty(cfg = "cfail2", except = "hir_owner,hir_owner_nodes")]
158-
#[rustc_clean(cfg = "cfail3")]
159-
#[link_args = "-foo -bar -baz"]
160-
extern "C" {
161-
pub fn change_link_args(c: i32);
162-
}
163-
164148
// Change link-name ------------------------------------------------------------
165149
#[cfg(cfail1)]
166150
#[link(name = "foo")]

src/test/run-make-fulldeps/link-args-order/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ RUSTC_FLAGS = -C linker-flavor=ld -C link-arg=a -C link-args="b c" -C link-args=
66
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
77

88
all:
9-
$(RUSTC) $(RUSTC_FLAGS) empty.rs 2>&1 | $(CGREP) '"a" "b" "c" "d" "e" "f" "g"'
9+
$(RUSTC) $(RUSTC_FLAGS) empty.rs 2>&1 | $(CGREP) '"a" "b" "c" "d" "e" "f"'
1010
$(RUSTC) $(RUSTC_FLAGS_PRE) empty.rs 2>&1 | $(CGREP) '"a" "b" "c" "d" "e" "f"'
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
#![feature(link_args)]
2-
3-
#[link_args = "g"]
4-
extern "C" {}
5-
61
fn main() {}

src/test/ui/feature-gates/feature-gate-link_args.rs

-17
This file was deleted.

src/test/ui/feature-gates/feature-gate-link_args.stderr

-30
This file was deleted.

src/test/ui/issues/issue-15487.rs

-13
This file was deleted.

src/test/ui/linkage-attr/invalid-link-args.rs

-14
This file was deleted.

src/tools/clippy/tests/ui/crate_level_checks/no_std_main_recursion.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
// compile-flags: -Clink-arg=-nostartfiles
12
// ignore-macos
23
// ignore-windows
34

4-
#![feature(lang_items, link_args, start, libc)]
5-
#![link_args = "-nostartfiles"]
5+
#![feature(lang_items, start, libc)]
66
#![no_std]
77

88
use core::panic::PanicInfo;

src/tools/clippy/tests/ui/empty_loop_no_std.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
// compile-flags: -Clink-arg=-nostartfiles
12
// ignore-macos
23
// ignore-windows
34

45
#![warn(clippy::empty_loop)]
5-
#![feature(lang_items, link_args, start, libc)]
6-
#![link_args = "-nostartfiles"]
6+
#![feature(lang_items, start, libc)]
77
#![no_std]
88

99
use core::panic::PanicInfo;

0 commit comments

Comments
 (0)