Skip to content

Commit c5f6a06

Browse files
committed
Avoid including text direction codepoints in lint messages
1 parent 92445ef commit c5f6a06

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -2101,6 +2101,7 @@ dependencies = [
21012101
name = "lint-docs"
21022102
version = "0.1.0"
21032103
dependencies = [
2104+
"rustc-literal-escaper",
21042105
"serde_json",
21052106
"tempfile",
21062107
"walkdir",

compiler/rustc_lint_defs/src/builtin.rs

+4-6
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};
@@ -3795,7 +3793,7 @@ declare_lint! {
37953793
/// ```rust,compile_fail
37963794
/// #![deny(text_direction_codepoint_in_comment)]
37973795
/// fn main() {
3798-
/// println!("{:?}"); // '');
3796+
#[doc = " println!(\"{:?}\"); // '\u{202E}');"]
37993797
/// }
38003798
/// ```
38013799
///
@@ -3830,12 +3828,12 @@ declare_lint! {
38303828
///
38313829
/// ### Example
38323830
///
3833-
/// ```rust,compile_fail
3831+
/// ````rust,compile_fail
38343832
/// #![deny(text_direction_codepoint_in_literal)]
38353833
/// fn main() {
3836-
/// println!("{:?}", '');
3834+
#[doc = " println!(\"{:?}\", '\u{202E}');"]
38373835
/// }
3838-
/// ```
3836+
/// ````
38393837
///
38403838
/// {{produces}}
38413839
///

src/tools/lint-docs/Cargo.toml

+1
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

+11
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)