Skip to content

Fix feature gate for #[link_args(..)] attribute #43109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,12 @@ pub const BUILTIN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeG
("ignore", Normal, Ungated),
("no_implicit_prelude", Normal, Ungated),
("reexport_test_harness_main", Normal, Ungated),
("link_args", Normal, Ungated),
("link_args", Normal, Gated(Stability::Unstable,
"link_args",
"the `link_args` attribute is experimental and not \
portable across platforms, it is recommended to \
use `#[link(name = \"foo\")] instead",
cfg_fn!(link_args))),
("macro_escape", Normal, Ungated),

// RFC #1445.
Expand Down Expand Up @@ -1185,12 +1190,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
}

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

Expand Down
18 changes: 14 additions & 4 deletions src/test/compile-fail/gated-link-args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,22 @@
// except according to those terms.

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

// gate-test-link_args

#[link_args = "aFdEfSeVEEE"]
// 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 {}
//~^ ERROR the `link_args` attribute is not portable across platforms

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