Skip to content

Commit d935a14

Browse files
committed
Fix feature gate checking of static-nobundle and native_link_modifiers
1 parent 2b4196e commit d935a14

8 files changed

+75
-43
lines changed

compiler/rustc_metadata/src/native_libs.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ impl ItemLikeVisitor<'tcx> for Collector<'tcx> {
7777
modifier `-bundle` with library kind `static`",
7878
)
7979
.emit();
80+
if !self.tcx.features().static_nobundle {
81+
feature_err(
82+
&self.tcx.sess.parse_sess,
83+
sym::static_nobundle,
84+
item.span(),
85+
"kind=\"static-nobundle\" is unstable",
86+
)
87+
.emit();
88+
}
8089
NativeLibKind::Static { bundle: Some(false), whole_archive: None }
8190
}
8291
"dylib" => NativeLibKind::Dylib { as_needed: None },
@@ -252,17 +261,6 @@ impl Collector<'tcx> {
252261
)
253262
.emit();
254263
}
255-
if matches!(lib.kind, NativeLibKind::Static { bundle: Some(false), .. })
256-
&& !self.tcx.features().static_nobundle
257-
{
258-
feature_err(
259-
&self.tcx.sess.parse_sess,
260-
sym::static_nobundle,
261-
span.unwrap_or(rustc_span::DUMMY_SP),
262-
"kind=\"static-nobundle\" is unstable",
263-
)
264-
.emit();
265-
}
266264
// this just unwraps lib.name; we already established that it isn't empty above.
267265
if let (NativeLibKind::RawDylib, Some(lib_name)) = (lib.kind, lib.name) {
268266
let span = match span {

compiler/rustc_session/src/config.rs

+48-19
Original file line numberDiff line numberDiff line change
@@ -1618,8 +1618,20 @@ fn select_debuginfo(
16181618
}
16191619
}
16201620

1621-
fn parse_native_lib_kind(kind: &str, error_format: ErrorOutputType) -> NativeLibKind {
1622-
match kind {
1621+
fn parse_native_lib_kind(
1622+
matches: &getopts::Matches,
1623+
kind: &str,
1624+
error_format: ErrorOutputType,
1625+
) -> (NativeLibKind, Option<bool>) {
1626+
let is_nightly = nightly_options::match_is_nightly_build(matches);
1627+
let enable_unstable = nightly_options::is_unstable_enabled(matches);
1628+
1629+
let (kind, modifiers) = match kind.split_once(':') {
1630+
None => (kind, None),
1631+
Some((kind, modifiers)) => (kind, Some(modifiers)),
1632+
};
1633+
1634+
let kind = match kind {
16231635
"dylib" => NativeLibKind::Dylib { as_needed: None },
16241636
"framework" => NativeLibKind::Framework { as_needed: None },
16251637
"static" => NativeLibKind::Static { bundle: None, whole_archive: None },
@@ -1629,17 +1641,49 @@ fn parse_native_lib_kind(kind: &str, error_format: ErrorOutputType) -> NativeLib
16291641
"library kind `static-nobundle` has been superseded by specifying \
16301642
`-bundle` on library kind `static`. Try `static:-bundle`",
16311643
);
1644+
if modifiers.is_some() {
1645+
early_error(
1646+
error_format,
1647+
"linking modifier can't be used with library kind `static-nobundle`",
1648+
)
1649+
}
1650+
if !is_nightly {
1651+
early_error(
1652+
error_format,
1653+
"library kind `static-nobundle` are currently unstable and only accepted on \
1654+
the nightly compiler",
1655+
);
1656+
}
16321657
NativeLibKind::Static { bundle: Some(false), whole_archive: None }
16331658
}
16341659
s => early_error(
16351660
error_format,
16361661
&format!("unknown library kind `{}`, expected one of dylib, framework, or static", s),
16371662
),
1663+
};
1664+
match modifiers {
1665+
None => (kind, None),
1666+
Some(modifiers) => {
1667+
if !is_nightly {
1668+
early_error(
1669+
error_format,
1670+
"linking modifiers are currently unstable and only accepted on \
1671+
the nightly compiler",
1672+
);
1673+
}
1674+
if !enable_unstable {
1675+
early_error(
1676+
error_format,
1677+
"linking modifiers are currently unstable, \
1678+
the `-Z unstable-options` flag must also be passed to use it",
1679+
)
1680+
}
1681+
parse_native_lib_modifiers(kind, modifiers, error_format)
1682+
}
16381683
}
16391684
}
16401685

16411686
fn parse_native_lib_modifiers(
1642-
is_nightly: bool,
16431687
mut kind: NativeLibKind,
16441688
modifiers: &str,
16451689
error_format: ErrorOutputType,
@@ -1655,14 +1699,6 @@ fn parse_native_lib_modifiers(
16551699
),
16561700
};
16571701

1658-
if !is_nightly {
1659-
early_error(
1660-
error_format,
1661-
"linking modifiers are currently unstable and only accepted on \
1662-
the nightly compiler",
1663-
);
1664-
}
1665-
16661702
match (modifier, &mut kind) {
16671703
("bundle", NativeLibKind::Static { bundle, .. }) => {
16681704
*bundle = Some(value);
@@ -1709,7 +1745,6 @@ fn parse_native_lib_modifiers(
17091745
}
17101746

17111747
fn parse_libs(matches: &getopts::Matches, error_format: ErrorOutputType) -> Vec<NativeLib> {
1712-
let is_nightly = nightly_options::match_is_nightly_build(matches);
17131748
matches
17141749
.opt_strs("l")
17151750
.into_iter()
@@ -1723,13 +1758,7 @@ fn parse_libs(matches: &getopts::Matches, error_format: ErrorOutputType) -> Vec<
17231758
let (name, kind, verbatim) = match s.split_once('=') {
17241759
None => (s, NativeLibKind::Unspecified, None),
17251760
Some((kind, name)) => {
1726-
let (kind, verbatim) = match kind.split_once(':') {
1727-
None => (parse_native_lib_kind(kind, error_format), None),
1728-
Some((kind, modifiers)) => {
1729-
let kind = parse_native_lib_kind(kind, error_format);
1730-
parse_native_lib_modifiers(is_nightly, kind, modifiers, error_format)
1731-
}
1732-
};
1761+
let (kind, verbatim) = parse_native_lib_kind(matches, kind, error_format);
17331762
(name.to_string(), kind, verbatim)
17341763
}
17351764
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Test native_link_modifiers_bundle don't need static-nobundle
2+
// check-pass
3+
4+
#![feature(native_link_modifiers)]
5+
#![feature(native_link_modifiers_bundle)]
6+
7+
#[link(name = "foo", kind = "static", modifiers = "-bundle")]
8+
extern "C" {}
9+
10+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// compile-flags: -l static:-bundle=nonexistent
2+
3+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
error: linking modifiers are currently unstable, the `-Z unstable-options` flag must also be passed to use it
2+
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
//~ ERROR kind="static-nobundle" is unstable
2-
// Test the behavior of rustc when non-existent library is statically linked
3-
1+
// check-pass
42
// compile-flags: -l static-nobundle=nonexistent
53

64
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,2 @@
11
warning: library kind `static-nobundle` has been superseded by specifying `-bundle` on library kind `static`. Try `static:-bundle`
22

3-
error[E0658]: kind="static-nobundle" is unstable
4-
|
5-
= note: see issue #37403 <https://github.com/rust-lang/rust/issues/37403> for more information
6-
= help: add `#![feature(static_nobundle)]` to the crate attributes to enable
7-
8-
error: aborting due to previous error
9-
10-
For more information about this error, try `rustc --explain E0658`.

src/test/ui/feature-gates/feature-gate-static-nobundle.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ LL | #[link(name = "foo", kind = "static-nobundle")]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^
66

77
error[E0658]: kind="static-nobundle" is unstable
8-
--> $DIR/feature-gate-static-nobundle.rs:1:1
8+
--> $DIR/feature-gate-static-nobundle.rs:1:22
99
|
1010
LL | #[link(name = "foo", kind = "static-nobundle")]
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^
1212
|
1313
= note: see issue #37403 <https://github.com/rust-lang/rust/issues/37403> for more information
1414
= help: add `#![feature(static_nobundle)]` to the crate attributes to enable

0 commit comments

Comments
 (0)