Skip to content

Commit 454d947

Browse files
authored
Unrolled build for #154405
Rollup merge of #154405 - chenyukang:yukang-fix-153096-doc-comment-bidi-help, r=JohnTitor Improve doc comment unicode guidance Fixes #153096 This PR does not suggest HTML bidi markup, because doc comments are still Rust source first, not only rendered rustdoc output. HTML only helps in the rendered documentation rather than making them explicit in source.
2 parents fda6d37 + 16b9fdd commit 454d947

File tree

6 files changed

+39
-11
lines changed

6 files changed

+39
-11
lines changed

‎compiler/rustc_parse/src/errors.rs‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4344,7 +4344,7 @@ impl Subdiagnostic for HiddenUnicodeCodepointsDiagLabels {
43444344

43454345
pub(crate) enum HiddenUnicodeCodepointsDiagSub {
43464346
Escape { spans: Vec<(char, Span)> },
4347-
NoEscape { spans: Vec<(char, Span)> },
4347+
NoEscape { spans: Vec<(char, Span)>, is_doc_comment: bool },
43484348
}
43494349

43504350
// Used because of multiple multipart_suggestion and note
@@ -4370,7 +4370,7 @@ impl Subdiagnostic for HiddenUnicodeCodepointsDiagSub {
43704370
Applicability::MachineApplicable,
43714371
);
43724372
}
4373-
HiddenUnicodeCodepointsDiagSub::NoEscape { spans } => {
4373+
HiddenUnicodeCodepointsDiagSub::NoEscape { spans, is_doc_comment } => {
43744374
// FIXME: in other suggestions we've reversed the inner spans of doc comments. We
43754375
// should do the same here to provide the same good suggestions as we do for
43764376
// literals above.
@@ -4383,7 +4383,11 @@ impl Subdiagnostic for HiddenUnicodeCodepointsDiagSub {
43834383
.join(", "),
43844384
);
43854385
diag.note(msg!("if their presence wasn't intentional, you can remove them"));
4386-
diag.note(msg!("if you want to keep them but make them visible in your source code, you can escape them: {$escaped}"));
4386+
if is_doc_comment {
4387+
diag.note(msg!(r#"if you need to keep them and make them explicit in source, rewrite this doc comment as a `#[doc = "..."]` attribute and use Unicode escapes such as {$escaped}"#));
4388+
} else {
4389+
diag.note(msg!("if you want to keep them but make them visible in your source code, you can escape them: {$escaped}"));
4390+
}
43874391
}
43884392
}
43894393
}

‎compiler/rustc_parse/src/lexer/mod.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
546546
self.mk_sp(start, self.pos),
547547
0,
548548
false,
549+
true,
549550
"doc comment",
550551
);
551552
}
@@ -580,6 +581,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
580581
span,
581582
padding,
582583
point_at_inner_spans,
584+
false,
583585
label,
584586
);
585587
}
@@ -590,6 +592,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
590592
span: Span,
591593
padding: u32,
592594
point_at_inner_spans: bool,
595+
is_doc_comment: bool,
593596
label: &str,
594597
) {
595598
// Obtain the `Span`s for each of the forbidden chars.
@@ -610,7 +613,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
610613
let sub = if point_at_inner_spans && !spans.is_empty() {
611614
errors::HiddenUnicodeCodepointsDiagSub::Escape { spans }
612615
} else {
613-
errors::HiddenUnicodeCodepointsDiagSub::NoEscape { spans }
616+
errors::HiddenUnicodeCodepointsDiagSub::NoEscape { spans, is_doc_comment }
614617
};
615618

616619
self.psess.buffer_lint(

‎tests/ui/parser/macro/unicode-control-codepoints-macros.stderr‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | /// �test� RTL in doc in vec
66
|
77
= note: these kind of unicode codepoints change the way text flows on applications that support them, but can cause confusion because they change the order of characters on the screen
88
= note: if their presence wasn't intentional, you can remove them
9-
= note: if you want to keep them but make them visible in your source code, you can escape them: '\u{202e}', '\u{2066}'
9+
= note: if you need to keep them and make them explicit in source, rewrite this doc comment as a `#[doc = "..."]` attribute and use Unicode escapes such as '\u{202e}', '\u{2066}'
1010
= note: `#[deny(text_direction_codepoint_in_literal)]` on by default
1111

1212
error: unicode codepoint changing visible direction of text present in doc comment
@@ -19,7 +19,7 @@ LL | | */
1919
|
2020
= note: these kind of unicode codepoints change the way text flows on applications that support them, but can cause confusion because they change the order of characters on the screen
2121
= note: if their presence wasn't intentional, you can remove them
22-
= note: if you want to keep them but make them visible in your source code, you can escape them: '\u{202e}', '\u{2066}'
22+
= note: if you need to keep them and make them explicit in source, rewrite this doc comment as a `#[doc = "..."]` attribute and use Unicode escapes such as '\u{202e}', '\u{2066}'
2323

2424
error: unicode codepoint changing visible direction of text present in doc comment
2525
--> $DIR/unicode-control-codepoints-macros.rs:33:9
@@ -31,7 +31,7 @@ LL | | */
3131
|
3232
= note: these kind of unicode codepoints change the way text flows on applications that support them, but can cause confusion because they change the order of characters on the screen
3333
= note: if their presence wasn't intentional, you can remove them
34-
= note: if you want to keep them but make them visible in your source code, you can escape them: '\u{202e}', '\u{2066}'
34+
= note: if you need to keep them and make them explicit in source, rewrite this doc comment as a `#[doc = "..."]` attribute and use Unicode escapes such as '\u{202e}', '\u{2066}'
3535

3636
error: unicode codepoint changing visible direction of text present in doc comment
3737
--> $DIR/unicode-control-codepoints-macros.rs:41:9
@@ -41,7 +41,7 @@ LL | /// �test� RTL in doc in proc macro
4141
|
4242
= note: these kind of unicode codepoints change the way text flows on applications that support them, but can cause confusion because they change the order of characters on the screen
4343
= note: if their presence wasn't intentional, you can remove them
44-
= note: if you want to keep them but make them visible in your source code, you can escape them: '\u{202e}', '\u{2066}'
44+
= note: if you need to keep them and make them explicit in source, rewrite this doc comment as a `#[doc = "..."]` attribute and use Unicode escapes such as '\u{202e}', '\u{2066}'
4545

4646
error: unicode codepoint changing visible direction of text present in doc comment
4747
--> $DIR/unicode-control-codepoints-macros.rs:46:9
@@ -51,7 +51,7 @@ LL | /// �test� RTL in doc in proc macro
5151
|
5252
= note: these kind of unicode codepoints change the way text flows on applications that support them, but can cause confusion because they change the order of characters on the screen
5353
= note: if their presence wasn't intentional, you can remove them
54-
= note: if you want to keep them but make them visible in your source code, you can escape them: '\u{202e}', '\u{2066}'
54+
= note: if you need to keep them and make them explicit in source, rewrite this doc comment as a `#[doc = "..."]` attribute and use Unicode escapes such as '\u{202e}', '\u{2066}'
5555

5656
error: aborting due to 5 previous errors
5757

‎tests/ui/parser/unicode-control-codepoints.stderr‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ LL | /** '�'); */fn foo() {}
232232
|
233233
= note: these kind of unicode codepoints change the way text flows on applications that support them, but can cause confusion because they change the order of characters on the screen
234234
= note: if their presence wasn't intentional, you can remove them
235-
= note: if you want to keep them but make them visible in your source code, you can escape them: '\u{202e}'
235+
= note: if you need to keep them and make them explicit in source, rewrite this doc comment as a `#[doc = "..."]` attribute and use Unicode escapes such as '\u{202e}'
236236

237237
error: unicode codepoint changing visible direction of text present in doc comment
238238
--> $DIR/unicode-control-codepoints.rs:46:1
@@ -244,7 +244,7 @@ LL | | * '�'); */fn bar() {}
244244
|
245245
= note: these kind of unicode codepoints change the way text flows on applications that support them, but can cause confusion because they change the order of characters on the screen
246246
= note: if their presence wasn't intentional, you can remove them
247-
= note: if you want to keep them but make them visible in your source code, you can escape them: '\u{202e}'
247+
= note: if you need to keep them and make them explicit in source, rewrite this doc comment as a `#[doc = "..."]` attribute and use Unicode escapes such as '\u{202e}'
248248

249249
error: aborting due to 20 previous errors
250250

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//@ edition: 2024
2+
3+
#[allow(unused)]
4+
/// ⁨א⁩, ⁨ב⁩, ⁨ג⁩, ⁨ד⁩, ⁨ה⁩
5+
//~^ ERROR unicode codepoint changing visible direction of text present in doc comment
6+
fn foo() {}
7+
8+
fn main() {}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error: unicode codepoint changing visible direction of text present in doc comment
2+
--> $DIR/unicode-control-doc-comment-issue-153096.rs:4:1
3+
|
4+
LL | /// �א�, �ב�, �ג�, �ד�, �ה�
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ this doc comment contains invisible unicode text flow control codepoints
6+
|
7+
= note: these kind of unicode codepoints change the way text flows on applications that support them, but can cause confusion because they change the order of characters on the screen
8+
= note: if their presence wasn't intentional, you can remove them
9+
= note: if you need to keep them and make them explicit in source, rewrite this doc comment as a `#[doc = "..."]` attribute and use Unicode escapes such as '\u{2068}', '\u{2069}', '\u{2068}', '\u{2069}', '\u{2068}', '\u{2069}', '\u{2068}', '\u{2069}', '\u{2068}', '\u{2069}'
10+
= note: `#[deny(text_direction_codepoint_in_literal)]` on by default
11+
12+
error: aborting due to 1 previous error
13+

0 commit comments

Comments
 (0)