Skip to content

Commit e5bfd02

Browse files
committed
Avoid including text direction codepoints in lint messages
1 parent 65bdb31 commit e5bfd02

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,6 +2170,7 @@ dependencies = [
21702170
name = "lint-docs"
21712171
version = "0.1.0"
21722172
dependencies = [
2173+
"rustc-literal-escaper",
21732174
"serde_json",
21742175
"tempfile",
21752176
"walkdir",

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
//! When removing a lint, make sure to also add a call to `register_removed` in
88
//! compiler/rustc_lint/src/lib.rs.
99
10-
#![allow(text_direction_codepoint_in_literal)]
11-
1210
use rustc_span::edition::Edition;
1311

1412
use crate::{FutureIncompatibilityReason, declare_lint, declare_lint_pass};
@@ -3796,7 +3794,7 @@ declare_lint! {
37963794
/// ```rust,compile_fail
37973795
/// #![deny(text_direction_codepoint_in_comment)]
37983796
/// fn main() {
3799-
/// println!("{:?}"); // '');
3797+
#[doc = " println!(\"{:?}\"); // '\u{202E}');"]
38003798
/// }
38013799
/// ```
38023800
///
@@ -3834,7 +3832,9 @@ declare_lint! {
38343832
/// ```rust,compile_fail
38353833
/// #![deny(text_direction_codepoint_in_literal)]
38363834
/// fn main() {
3837-
/// println!("{:?}", '‮');
3835+
// ` - convince tidy that backticks match
3836+
#[doc = " println!(\"{:?}\", '\u{202E}');"]
3837+
// `
38383838
/// }
38393839
/// ```
38403840
///

src/tools/lint-docs/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ description = "A script to extract the lint documentation for the rustc book."
77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

99
[dependencies]
10+
rustc-literal-escaper = "0.0.2"
1011
serde_json = "1.0.57"
1112
tempfile = "3.1.0"
1213
walkdir = "2.3.1"

src/tools/lint-docs/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::fs;
44
use std::path::{Path, PathBuf};
55
use std::process::Command;
66

7+
use rustc_literal_escaper::{Mode, unescape_unicode};
78
use walkdir::WalkDir;
89

910
mod groups;
@@ -214,6 +215,16 @@ impl<'a> LintExtractor<'a> {
214215
let line = line.trim();
215216
if let Some(text) = line.strip_prefix("/// ") {
216217
doc_lines.push(text.to_string());
218+
} else if let Some(text) = line.strip_prefix("#[doc = \"") {
219+
let escaped = text.strip_suffix("\"]").unwrap();
220+
let mut buf = String::new();
221+
unescape_unicode(escaped, Mode::Str, &mut |_, c| match c {
222+
Ok(c) => buf.push(c),
223+
Err(err) => {
224+
assert!(!err.is_fatal(), "failed to unescape string literal")
225+
}
226+
});
227+
doc_lines.push(buf);
217228
} else if line == "///" {
218229
doc_lines.push("".to_string());
219230
} else if line.starts_with("// ") {

0 commit comments

Comments
 (0)