Skip to content

Commit 6e9c0b0

Browse files
committed
Address review comments.
1 parent bf4bc7d commit 6e9c0b0

File tree

10 files changed

+63
-55
lines changed

10 files changed

+63
-55
lines changed

src/librustc/middle/cstore.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub enum NativeLibraryKind {
9696
NativeStaticNobundle,
9797
/// macOS-specific
9898
NativeFramework,
99-
/// windows dynamic library without import library
99+
/// Windows dynamic library without import library.
100100
NativeRawDylib,
101101
/// default way to specify a dynamic library
102102
NativeUnknown,

src/librustc_metadata/native_libs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl Collector<'tcx> {
176176
sym::raw_dylib,
177177
span.unwrap_or_else(|| syntax_pos::DUMMY_SP),
178178
GateIssue::Language,
179-
"kind=\"raw-dylib\" is feature gated");
179+
"kind=\"raw-dylib\" is unstable");
180180
}
181181
self.libs.push(lib);
182182
}

src/librustc_typeck/collect.rs

+45-36
Original file line numberDiff line numberDiff line change
@@ -2604,33 +2604,8 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
26042604
} else if attr.check_name(sym::link_name) {
26052605
codegen_fn_attrs.link_name = attr.value_str();
26062606
} else if attr.check_name(sym::link_ordinal) {
2607-
use syntax::ast::{Lit, LitIntType, LitKind};
2608-
let meta_item_list = attr.meta_item_list();
2609-
let sole_meta_lit = if let Some(meta_item_list) = &meta_item_list {
2610-
if meta_item_list.len() == 1 {
2611-
meta_item_list.get(0).and_then(|item| item.literal())
2612-
} else {
2613-
None
2614-
}
2615-
} else {
2616-
None
2617-
};
2618-
if let Some(Lit { node: LitKind::Int(ordinal, LitIntType::Unsuffixed), .. }) =
2619-
sole_meta_lit
2620-
{
2621-
if *ordinal <= std::usize::MAX as u128 {
2622-
codegen_fn_attrs.link_ordinal = Some(*ordinal as usize);
2623-
} else {
2624-
let msg = format!(
2625-
"too large ordinal value in link_ordinal \
2626-
value: `{}`",
2627-
&ordinal
2628-
);
2629-
tcx.sess.span_err(attr.span, &msg);
2630-
}
2631-
} else {
2632-
let msg = "illegal ordinal format in link_ordinal";
2633-
tcx.sess.span_err(attr.span, &msg);
2607+
if let ordinal @ Some(_) = check_link_ordinal(tcx, attr) {
2608+
codegen_fn_attrs.link_ordinal = ordinal;
26342609
}
26352610
}
26362611
}
@@ -2709,6 +2684,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
27092684
// purpose functions as they wouldn't have the right target features
27102685
// enabled. For that reason we also forbid #[inline(always)] as it can't be
27112686
// respected.
2687+
27122688
if codegen_fn_attrs.target_features.len() > 0 {
27132689
if codegen_fn_attrs.inline == InlineAttr::Always {
27142690
if let Some(span) = inline_span {
@@ -2733,15 +2709,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
27332709
codegen_fn_attrs.export_name = Some(name);
27342710
codegen_fn_attrs.link_name = Some(name);
27352711
}
2736-
if codegen_fn_attrs.link_name.is_some() && codegen_fn_attrs.link_ordinal.is_some() {
2737-
if let Some(span) = inline_span {
2738-
tcx.sess.span_err(
2739-
span,
2740-
"cannot use `#[link_name]` with \
2741-
`#[link_ordinal]`",
2742-
);
2743-
}
2744-
}
2712+
check_link_name_xor_ordinal(tcx, &codegen_fn_attrs, inline_span);
27452713

27462714
// Internal symbols to the standard library all have no_mangle semantics in
27472715
// that they have defined symbol names present in the function name. This
@@ -2752,3 +2720,44 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
27522720

27532721
codegen_fn_attrs
27542722
}
2723+
2724+
fn check_link_ordinal(tcx: TyCtxt<'_>, attr: &ast::Attribute) -> Option<usize> {
2725+
use syntax::ast::{Lit, LitIntType, LitKind};
2726+
let meta_item_list = attr.meta_item_list();
2727+
let meta_item_list: Option<&[ast::NestedMetaItem]> = meta_item_list.as_ref().map(Vec::as_ref);
2728+
let sole_meta_list = match meta_item_list {
2729+
Some([item]) => item.literal(),
2730+
_ => None,
2731+
};
2732+
if let Some(Lit { node: LitKind::Int(ordinal, LitIntType::Unsuffixed), .. }) = sole_meta_list {
2733+
if *ordinal <= std::usize::MAX as u128 {
2734+
Some(*ordinal as usize)
2735+
} else {
2736+
let msg = format!(
2737+
"too large ordinal value in link_ordinal value: `{}`",
2738+
&ordinal
2739+
);
2740+
tcx.sess.span_err(attr.span, &msg);
2741+
None
2742+
}
2743+
} else {
2744+
tcx.sess.span_err(attr.span, "illegal ordinal format in link_ordinal");
2745+
None
2746+
}
2747+
}
2748+
2749+
fn check_link_name_xor_ordinal(
2750+
tcx: TyCtxt<'_>,
2751+
codegen_fn_attrs: &CodegenFnAttrs,
2752+
inline_span: Option<Span>,
2753+
) {
2754+
if codegen_fn_attrs.link_name.is_none() || codegen_fn_attrs.link_ordinal.is_none() {
2755+
return;
2756+
}
2757+
let msg = "cannot use `#[link_name]` with `#[link_ordinal]`";
2758+
if let Some(span) = inline_span {
2759+
tcx.sess.span_err(span, msg);
2760+
} else {
2761+
tcx.sess.err(msg);
2762+
}
2763+
}

src/libsyntax/feature_gate/active.rs

+1
Original file line numberDiff line numberDiff line change
@@ -542,4 +542,5 @@ pub const INCOMPLETE_FEATURES: &[Symbol] = &[
542542
sym::const_generics,
543543
sym::or_patterns,
544544
sym::let_chains,
545+
sym::raw_dylib,
545546
];

src/libsyntax/feature_gate/builtin_attrs.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,10 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
277277
it is recommended to use `#[link(name = \"foo\")] instead",
278278
),
279279
gated!(
280-
link_ordinal,
281-
Whitelisted,
282-
template!(List: "ordinal"),
283-
raw_dylib,
280+
link_ordinal, Whitelisted, template!(List: "ordinal"), raw_dylib,
284281
experimental!(link_ordinal)
285282
),
283+
286284
// Plugins:
287285
ungated!(plugin_registrar, Normal, template!(Word)),
288286
gated!(

src/test/ui/feature-gates/feature-gate-raw-dylib-2.rs

-8
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#[link(name="foo")]
2+
extern {
3+
#[link_ordinal(42)]
4+
//~^ ERROR: the `#[link_ordinal]` attribute is an experimental feature
5+
fn foo();
6+
}
7+
8+
fn main() {}

src/test/ui/feature-gates/feature-gate-raw-dylib-2.stderr renamed to src/test/ui/rfc-2627-raw-dylib/feature-gate-raw-dylib-2.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0658]: the `#[link_ordinal]` attribute is an experimental feature
2-
--> $DIR/feature-gate-raw-dylib-2.rs:3:1
2+
--> $DIR/feature-gate-raw-dylib-2.rs:3:5
33
|
4-
LL | #[link_ordinal(42)]
5-
| ^^^^^^^^^^^^^^^^^^^
4+
LL | #[link_ordinal(42)]
5+
| ^^^^^^^^^^^^^^^^^^^
66
|
77
= note: for more information, see https://github.com/rust-lang/rust/issues/58713
88
= help: add `#![feature(raw_dylib)]` to the crate attributes to enable
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#[link(name="foo", kind="raw-dylib")]
2-
//~^ ERROR: kind="raw-dylib" is feature gated
2+
//~^ ERROR: kind="raw-dylib" is unstable
33
extern {}
44

55
fn main() {}

src/test/ui/feature-gates/feature-gate-raw-dylib.stderr renamed to src/test/ui/rfc-2627-raw-dylib/feature-gate-raw-dylib.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0658]: kind="raw-dylib" is feature gated
1+
error[E0658]: kind="raw-dylib" is unstable
22
--> $DIR/feature-gate-raw-dylib.rs:1:1
33
|
44
LL | #[link(name="foo", kind="raw-dylib")]

0 commit comments

Comments
 (0)