Skip to content

Commit c512dea

Browse files
committed
Fix feature gate for #[link_args(..)] attribute so that it will fire
regardless of context of attribute. Extend the gating test to include the attribute in "weird" places.
1 parent 33e353e commit c512dea

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

src/libsyntax/feature_gate.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,12 @@ pub const BUILTIN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeG
552552
("ignore", Normal, Ungated),
553553
("no_implicit_prelude", Normal, Ungated),
554554
("reexport_test_harness_main", Normal, Ungated),
555-
("link_args", Normal, Ungated),
555+
("link_args", Normal, Gated(Stability::Unstable,
556+
"link_args",
557+
"the `link_args` attribute is experimental and not \
558+
portable across platforms, it is recommended to \
559+
use `#[link(name = \"foo\")] instead",
560+
cfg_fn!(link_args))),
556561
("macro_escape", Normal, Ungated),
557562

558563
// RFC #1445.
@@ -1185,12 +1190,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
11851190
}
11861191

11871192
ast::ItemKind::ForeignMod(ref foreign_module) => {
1188-
if attr::contains_name(&i.attrs[..], "link_args") {
1189-
gate_feature_post!(&self, link_args, i.span,
1190-
"the `link_args` attribute is not portable \
1191-
across platforms, it is recommended to \
1192-
use `#[link(name = \"foo\")]` instead")
1193-
}
11941193
self.check_abi(foreign_module.abi, i.span);
11951194
}
11961195

src/test/compile-fail/gated-link-args.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,22 @@
99
// except according to those terms.
1010

1111
// Test that `#[link_args]` attribute is gated by `link_args`
12-
// feature gate.
12+
// feature gate, both when it occurs where expected (atop
13+
// `extern { }` blocks) and where unexpected.
1314

1415
// gate-test-link_args
1516

16-
#[link_args = "aFdEfSeVEEE"]
17+
// sidestep warning (which is correct, but misleading for
18+
// purposes of this test)
19+
#![allow(unused_attributes)]
20+
21+
#![link_args = "-l unexpected_use_as_inner_attr_on_mod"]
22+
//~^ ERROR the `link_args` attribute is experimental
23+
24+
#[link_args = "-l expected_use_case"]
25+
//~^ ERROR the `link_args` attribute is experimental
1726
extern {}
18-
//~^ ERROR the `link_args` attribute is not portable across platforms
1927

20-
fn main() { }
28+
#[link_args = "-l unexected_use_on_non_extern_item"]
29+
//~^ ERROR: the `link_args` attribute is experimental
30+
fn main() {}

0 commit comments

Comments
 (0)