Skip to content

Commit f8fe49e

Browse files
Introduce inline_fluent macro
1 parent a9f81ea commit f8fe49e

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

compiler/rustc_attr_parsing/src/attributes/cfg.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::convert::identity;
33
use rustc_ast::token::Delimiter;
44
use rustc_ast::tokenstream::DelimSpan;
55
use rustc_ast::{AttrItem, Attribute, CRATE_NODE_ID, LitKind, ast, token};
6-
use rustc_errors::{Applicability, PResult};
6+
use rustc_errors::{Applicability, PResult, inline_fluent};
77
use rustc_feature::{
88
AttrSuggestionStyle, AttributeTemplate, Features, GatedCfg, find_gated_cfg, template,
99
};
@@ -141,7 +141,7 @@ fn parse_cfg_entry_target<S: Stage>(
141141
cx.sess(),
142142
sym::cfg_target_compact,
143143
meta_span,
144-
"compact `cfg(target(..))` is experimental and subject to change",
144+
inline_fluent!("compact `cfg(target(..))` is experimental and subject to change"),
145145
)
146146
.emit();
147147
}

compiler/rustc_attr_parsing/src/attributes/link_attrs.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use rustc_errors::inline_fluent;
12
use rustc_feature::Features;
23
use rustc_hir::attrs::AttributeKind::{LinkName, LinkOrdinal, LinkSection};
34
use rustc_hir::attrs::*;
@@ -304,7 +305,7 @@ impl LinkParser {
304305
sess,
305306
sym::raw_dylib_elf,
306307
nv.value_span,
307-
"link kind `raw-dylib` is unstable on ELF platforms",
308+
inline_fluent!("link kind `raw-dylib` is unstable on ELF platforms"),
308309
)
309310
.emit();
310311
} else {
@@ -319,7 +320,7 @@ impl LinkParser {
319320
sess,
320321
sym::link_arg_attribute,
321322
nv.value_span,
322-
"link kind `link-arg` is unstable",
323+
inline_fluent!("link kind `link-arg` is unstable"),
323324
)
324325
.emit();
325326
}
@@ -384,7 +385,8 @@ impl LinkParser {
384385
return true;
385386
};
386387
if !features.link_cfg() {
387-
feature_err(sess, sym::link_cfg, item.span(), "link cfg is unstable").emit();
388+
feature_err(sess, sym::link_cfg, item.span(), inline_fluent!("link cfg is unstable"))
389+
.emit();
388390
}
389391
*cfg = parse_cfg_entry(cx, link_cfg).ok();
390392
true

compiler/rustc_errors/src/translation.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,14 @@ impl Translator {
166166
}
167167
}
168168
}
169+
170+
/// This macro creates a translatable `DiagMessage` from a literal string.
171+
/// It should be used in places where a translatable message is needed, but struct diagnostics are undesired.
172+
///
173+
/// This is a macro because in the future we may want to globally register these messages.
174+
#[macro_export]
175+
macro_rules! inline_fluent {
176+
($inline: literal) => {
177+
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed($inline))
178+
};
179+
}

0 commit comments

Comments
 (0)