Skip to content

Commit 3c2f864

Browse files
committed
session: opt for enabling directionality markers
Add an option for enabling and disabling Fluent's directionality isolation markers in output. Disabled by default as these can render in some terminals and applications. Signed-off-by: David Wood <[email protected]>
1 parent e27389b commit 3c2f864

File tree

13 files changed

+27
-18
lines changed

13 files changed

+27
-18
lines changed

compiler/rustc_driver/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,7 @@ static DEFAULT_HOOK: SyncLazy<Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send +
11731173
/// hook.
11741174
pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
11751175
let fallback_bundle =
1176-
rustc_errors::fallback_fluent_bundle().expect("failed to load fallback fluent bundle");
1176+
rustc_errors::fallback_fluent_bundle(false).expect("failed to load fallback fluent bundle");
11771177
let emitter = Box::new(rustc_errors::emitter::EmitterWriter::stderr(
11781178
rustc_errors::ColorConfig::Auto,
11791179
None,

compiler/rustc_error_messages/src/lib.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ pub fn fluent_bundle(
101101
sysroot: &Path,
102102
requested_locale: Option<LanguageIdentifier>,
103103
additional_ftl_path: Option<&Path>,
104+
with_directionality_markers: bool,
104105
) -> Result<Option<Lrc<FluentBundle>>, TranslationBundleError> {
105106
if requested_locale.is_none() && additional_ftl_path.is_none() {
106107
return Ok(None);
@@ -120,7 +121,7 @@ pub fn fluent_bundle(
120121
// vice-versa). These are disabled because they are sometimes visible in the error output, but
121122
// may be worth investigating in future (for example: if type names are left-to-right and the
122123
// surrounding diagnostic messages are right-to-left, then these might be helpful).
123-
bundle.set_use_isolating(false);
124+
bundle.set_use_isolating(with_directionality_markers);
124125

125126
// If the user requests the default locale then don't try to load anything.
126127
if !requested_fallback_locale && let Some(requested_locale) = requested_locale {
@@ -169,13 +170,15 @@ pub fn fluent_bundle(
169170

170171
/// Return the default `FluentBundle` with standard "en-US" diagnostic messages.
171172
#[instrument(level = "trace")]
172-
pub fn fallback_fluent_bundle() -> Result<Lrc<FluentBundle>, TranslationBundleError> {
173+
pub fn fallback_fluent_bundle(
174+
with_directionality_markers: bool,
175+
) -> Result<Lrc<FluentBundle>, TranslationBundleError> {
173176
let fallback_resource = FluentResource::try_new(FALLBACK_FLUENT_RESOURCE.to_string())
174177
.map_err(TranslationBundleError::from)?;
175178
trace!(?fallback_resource);
176179
let mut fallback_bundle = FluentBundle::new(vec![langid!("en-US")]);
177180
// See comment in `fluent_bundle`.
178-
fallback_bundle.set_use_isolating(false);
181+
fallback_bundle.set_use_isolating(with_directionality_markers);
179182
fallback_bundle.add_resource(fallback_resource).map_err(TranslationBundleError::from)?;
180183
let fallback_bundle = Lrc::new(fallback_bundle);
181184
Ok(fallback_bundle)

compiler/rustc_errors/src/json/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn test_positions(code: &str, span: (u32, u32), expected_output: SpanTestData) {
4040
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
4141
sm.new_source_file(Path::new("test.rs").to_owned().into(), code.to_owned());
4242
let fallback_bundle =
43-
crate::fallback_fluent_bundle().expect("failed to load fallback fluent bundle");
43+
crate::fallback_fluent_bundle(false).expect("failed to load fallback fluent bundle");
4444

4545
let output = Arc::new(Mutex::new(Vec::new()));
4646
let je = JsonEmitter::new(

compiler/rustc_expand/src/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ fn test_harness(file_text: &str, span_labels: Vec<SpanLabel>, expected_output: &
127127
create_default_session_if_not_set_then(|_| {
128128
let output = Arc::new(Mutex::new(Vec::new()));
129129

130-
let fallback_bundle =
131-
rustc_errors::fallback_fluent_bundle().expect("failed to load fallback fluent bundle");
130+
let fallback_bundle = rustc_errors::fallback_fluent_bundle(false)
131+
.expect("failed to load fallback fluent bundle");
132132
let source_map = Lrc::new(SourceMap::new(FilePathMapping::empty()));
133133
source_map.new_source_file(Path::new("test.rs").to_owned().into(), file_text.to_owned());
134134

compiler/rustc_session/src/options.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1482,6 +1482,8 @@ options! {
14821482
"language identifier for diagnostic output"),
14831483
translate_additional_ftl: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
14841484
"additional fluent translation to preferentially use (for testing translation)"),
1485+
translate_directionality_markers: bool = (false, parse_bool, [TRACKED],
1486+
"emit directionality isolation markers in translated diagnostics"),
14851487
tune_cpu: Option<String> = (None, parse_opt_string, [TRACKED],
14861488
"select processor to schedule for (`rustc --print target-cpus` for details)"),
14871489
thinlto: Option<bool> = (None, parse_opt_bool, [TRACKED],

compiler/rustc_session/src/parse.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ impl ParseSess {
175175
/// Used for testing.
176176
pub fn new(file_path_mapping: FilePathMapping) -> Self {
177177
let fallback_bundle =
178-
fallback_fluent_bundle().expect("failed to load fallback fluent bundle");
178+
fallback_fluent_bundle(false).expect("failed to load fallback fluent bundle");
179179
let sm = Lrc::new(SourceMap::new(file_path_mapping));
180180
let handler = Handler::with_tty_emitter(
181181
ColorConfig::Auto,
@@ -214,7 +214,7 @@ impl ParseSess {
214214

215215
pub fn with_silent_emitter(fatal_note: Option<String>) -> Self {
216216
let fallback_bundle =
217-
fallback_fluent_bundle().expect("failed to load fallback fluent bundle");
217+
fallback_fluent_bundle(false).expect("failed to load fallback fluent bundle");
218218
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
219219
let fatal_handler =
220220
Handler::with_tty_emitter(ColorConfig::Auto, false, None, None, None, fallback_bundle);

compiler/rustc_session/src/session.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1218,9 +1218,12 @@ pub fn build_session(
12181218
&sysroot,
12191219
sopts.debugging_opts.translate_lang.clone(),
12201220
sopts.debugging_opts.translate_additional_ftl.as_deref(),
1221+
sopts.debugging_opts.translate_directionality_markers,
12211222
)
12221223
.expect("failed to load fluent bundle");
1223-
let fallback_bundle = fallback_fluent_bundle().expect("failed to load fallback fluent bundle");
1224+
let fallback_bundle =
1225+
fallback_fluent_bundle(sopts.debugging_opts.translate_directionality_markers)
1226+
.expect("failed to load fallback fluent bundle");
12241227
let emitter =
12251228
default_emitter(&sopts, registry, source_map.clone(), bundle, fallback_bundle, write_dest);
12261229

@@ -1455,7 +1458,8 @@ pub enum IncrCompSession {
14551458
}
14561459

14571460
fn early_error_handler(output: config::ErrorOutputType) -> rustc_errors::Handler {
1458-
let fallback_bundle = fallback_fluent_bundle().expect("failed to load fallback fluent bundle");
1461+
let fallback_bundle =
1462+
fallback_fluent_bundle(false).expect("failed to load fallback fluent bundle");
14591463
let emitter: Box<dyn Emitter + sync::Send> = match output {
14601464
config::ErrorOutputType::HumanReadable(kind) => {
14611465
let (short, color_config) = kind.unzip();

src/librustdoc/core.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ crate fn new_handler(
144144
debugging_opts: &DebuggingOptions,
145145
) -> rustc_errors::Handler {
146146
let fallback_bundle =
147-
rustc_errors::fallback_fluent_bundle().expect("failed to load fallback fluent bundle");
147+
rustc_errors::fallback_fluent_bundle(false).expect("failed to load fallback fluent bundle");
148148
let emitter: Box<dyn Emitter + sync::Send> = match error_format {
149149
ErrorOutputType::HumanReadable(kind) => {
150150
let (short, color_config) = kind.unzip();

src/librustdoc/doctest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ crate fn make_test(
537537
// Any errors in parsing should also appear when the doctest is compiled for real, so just
538538
// send all the errors that librustc_ast emits directly into a `Sink` instead of stderr.
539539
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
540-
let fallback_bundle = rustc_errors::fallback_fluent_bundle()
540+
let fallback_bundle = rustc_errors::fallback_fluent_bundle(false)
541541
.expect("failed to load fallback fluent bundle");
542542
supports_color = EmitterWriter::stderr(
543543
ColorConfig::Auto,

src/librustdoc/passes/check_code_block_syntax.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ struct SyntaxChecker<'a, 'tcx> {
3232
impl<'a, 'tcx> SyntaxChecker<'a, 'tcx> {
3333
fn check_rust_syntax(&self, item: &clean::Item, dox: &str, code_block: RustCodeBlock) {
3434
let buffer = Lrc::new(Lock::new(Buffer::default()));
35-
let fallback_bundle =
36-
rustc_errors::fallback_fluent_bundle().expect("failed to load fallback fluent bundle");
35+
let fallback_bundle = rustc_errors::fallback_fluent_bundle(false)
36+
.expect("failed to load fallback fluent bundle");
3737
let emitter = BufferEmitter { buffer: Lrc::clone(&buffer), fallback_bundle };
3838

3939
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));

src/tools/clippy/clippy_lints/src/doc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) {
621621
let filename = FileName::anon_source_code(&code);
622622

623623
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
624-
let fallback_bundle = rustc_errors::fallback_fluent_bundle()
624+
let fallback_bundle = rustc_errors::fallback_fluent_bundle(false)
625625
.expect("failed to load fallback fluent bundle");
626626
let emitter = EmitterWriter::new(
627627
Box::new(io::sink()),

src/tools/clippy/src/driver.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ fn report_clippy_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
165165
// Separate the output with an empty line
166166
eprintln!();
167167

168-
let fallback_bundle = rustc_errors::fallback_fluent_bundle()
168+
let fallback_bundle = rustc_errors::fallback_fluent_bundle(false)
169169
.expect("failed to load fallback fluent bundle");
170170
let emitter = Box::new(rustc_errors::emitter::EmitterWriter::stderr(
171171
rustc_errors::ColorConfig::Auto,

src/tools/rustfmt/src/parse/session.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ fn default_handler(
114114
let emitter = if hide_parse_errors {
115115
silent_emitter()
116116
} else {
117-
let fallback_bundle = rustc_errors::fallback_fluent_bundle()
117+
let fallback_bundle = rustc_errors::fallback_fluent_bundle(false)
118118
.expect("failed to load fallback fluent bundle");
119119
Box::new(EmitterWriter::stderr(
120120
color_cfg,

0 commit comments

Comments
 (0)