Skip to content

Commit 6ad5110

Browse files
Port the #[link] attribute to the new parser
1 parent 3213d0e commit 6ad5110

File tree

15 files changed

+543
-631
lines changed

15 files changed

+543
-631
lines changed

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,17 @@ impl NativeLibKind {
268268
)
269269
}
270270
}
271+
272+
#[derive(Debug, Encodable, Decodable, Clone, HashStable_Generic, PrintAttribute)]
273+
pub struct LinkEntry {
274+
pub span: Span,
275+
pub kind: NativeLibKind,
276+
pub name: Symbol,
277+
pub cfg: Option<CfgEntry>,
278+
pub verbatim: Option<bool>,
279+
pub import_name_type: Option<(PeImportNameType, Span)>,
280+
}
281+
271282
/// Represents parsed *built-in* inert attributes.
272283
///
273284
/// ## Overview
@@ -422,6 +433,9 @@ pub enum AttributeKind {
422433
/// Represents `#[inline]` and `#[rustc_force_inline]`.
423434
Inline(InlineAttr, Span),
424435

436+
/// Represents `#[link]`.
437+
Link(ThinVec<LinkEntry>, Span),
438+
425439
/// Represents `#[link_name]`.
426440
LinkName { name: Symbol, span: Span },
427441

compiler/rustc_attr_data_structures/src/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ impl AttributeKind {
4040
Fundamental { .. } => Yes,
4141
Ignore { .. } => No,
4242
Inline(..) => No,
43+
Link(..) => No,
4344
LinkName { .. } => Yes,
4445
LinkOrdinal { .. } => No,
4546
LinkSection { .. } => No,

compiler/rustc_attr_parsing/messages.ftl

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,56 @@ attr_parsing_unused_multiple =
158158
159159
-attr_parsing_previously_accepted =
160160
this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
161+
162+
163+
attr_parsing_as_needed_compatibility =
164+
linking modifier `as-needed` is only compatible with `dylib` and `framework` linking kinds
165+
166+
attr_parsing_bundle_needs_static =
167+
linking modifier `bundle` is only compatible with `static` linking kind
168+
169+
attr_parsing_empty_link_name =
170+
link name must not be empty
171+
.label = empty link name
172+
173+
attr_parsing_import_name_type_raw =
174+
import name type can only be used with link kind `raw-dylib`
175+
176+
attr_parsing_import_name_type_x86 =
177+
import name type is only supported on x86
178+
179+
attr_parsing_incompatible_wasm_link =
180+
`wasm_import_module` is incompatible with other arguments in `#[link]` attributes
181+
182+
attr_parsing_invalid_link_modifier =
183+
invalid linking modifier syntax, expected '+' or '-' prefix before one of: bundle, verbatim, whole-archive, as-needed
184+
185+
attr_parsing_link_arg_unstable =
186+
link kind `link-arg` is unstable
187+
188+
attr_parsing_link_cfg_unstable =
189+
link cfg is unstable
190+
191+
attr_parsing_link_framework_apple =
192+
link kind `framework` is only supported on Apple targets
193+
194+
attr_parsing_link_requires_name =
195+
`#[link]` attribute requires a `name = "string"` argument
196+
.label = missing `name` argument
197+
198+
attr_parsing_multiple_modifiers =
199+
multiple `{$modifier}` modifiers in a single `modifiers` argument
200+
201+
attr_parsing_multiple_renamings =
202+
multiple renamings were specified for library `{$lib_name}`
203+
attr_parsing_raw_dylib_no_nul =
204+
link name must not contain NUL characters if link kind is `raw-dylib`
205+
206+
attr_parsing_raw_dylib_elf_unstable =
207+
link kind `raw-dylib` is unstable on ELF platforms
208+
209+
attr_parsing_raw_dylib_only_windows =
210+
link kind `raw-dylib` is only supported on Windows targets
211+
212+
attr_parsing_whole_archive_needs_static =
213+
linking modifier `whole-archive` is only compatible with `static` linking kind

compiler/rustc_attr_parsing/src/attributes/cfg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub fn parse_cfg_attr<'c, S: Stage>(
3232
parse_cfg_entry(cx, single)
3333
}
3434

35-
fn parse_cfg_entry<S: Stage>(
35+
pub(crate) fn parse_cfg_entry<S: Stage>(
3636
cx: &mut AcceptContext<'_, '_, S>,
3737
item: &MetaItemOrLitParser<'_>,
3838
) -> Option<CfgEntry> {

0 commit comments

Comments
 (0)