Skip to content

Commit 782b482

Browse files
committed
ordinals are 16 bits
1 parent cb272d5 commit 782b482

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

src/librustc_middle/middle/codegen_fn_attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub struct CodegenFnAttrs {
2121
/// imported function has in the dynamic library. Note that this must not
2222
/// be set when `link_name` is set. This is for foreign items with the
2323
/// "raw-dylib" kind.
24-
pub link_ordinal: Option<usize>,
24+
pub link_ordinal: Option<u16>,
2525
/// The `#[target_feature(enable = "...")]` attribute and the enabled
2626
/// features (only enabled features are supported right now).
2727
pub target_features: Vec<Symbol>,

src/librustc_typeck/collect.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2660,7 +2660,7 @@ fn should_inherit_track_caller(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
26602660
false
26612661
}
26622662

2663-
fn check_link_ordinal(tcx: TyCtxt<'_>, attr: &ast::Attribute) -> Option<usize> {
2663+
fn check_link_ordinal(tcx: TyCtxt<'_>, attr: &ast::Attribute) -> Option<u16> {
26642664
use rustc_ast::ast::{Lit, LitIntType, LitKind};
26652665
let meta_item_list = attr.meta_item_list();
26662666
let meta_item_list: Option<&[ast::NestedMetaItem]> = meta_item_list.as_ref().map(Vec::as_ref);
@@ -2669,13 +2669,13 @@ fn check_link_ordinal(tcx: TyCtxt<'_>, attr: &ast::Attribute) -> Option<usize> {
26692669
_ => None,
26702670
};
26712671
if let Some(Lit { kind: LitKind::Int(ordinal, LitIntType::Unsuffixed), .. }) = sole_meta_list {
2672-
if *ordinal <= usize::MAX as u128 {
2673-
Some(*ordinal as usize)
2672+
if *ordinal <= u16::MAX as u128 {
2673+
Some(*ordinal as u16)
26742674
} else {
26752675
let msg = format!("ordinal value in `link_ordinal` is too large: `{}`", &ordinal);
26762676
tcx.sess
26772677
.struct_span_err(attr.span, &msg)
2678-
.note("the value may not exceed `usize::MAX`")
2678+
.note("the value may not exceed `u16::MAX`")
26792679
.emit();
26802680
None
26812681
}

src/test/ui/rfc-2627-raw-dylib/link-ordinal-too-large.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ error: ordinal value in `link_ordinal` is too large: `18446744073709551616`
1313
LL | #[link_ordinal(18446744073709551616)]
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1515
|
16-
= note: the value may not exceed `usize::MAX`
16+
= note: the value may not exceed `u16::MAX`
1717

1818
error: aborting due to previous error; 1 warning emitted
1919

0 commit comments

Comments
 (0)