Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
4120f756
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4120f756
编写于
4月 26, 2021
作者:
J
Joshua Nelson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add back missing help for ignore blocks
This also gives a better error message when a span is missing.
上级
b574c67b
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
40 addition
and
34 deletion
+40
-34
src/doc/rustdoc/src/lints.md
src/doc/rustdoc/src/lints.md
+1
-1
src/librustdoc/passes/check_code_block_syntax.rs
src/librustdoc/passes/check_code_block_syntax.rs
+26
-28
src/test/rustdoc-ui/ignore-block-help.rs
src/test/rustdoc-ui/ignore-block-help.rs
+4
-1
src/test/rustdoc-ui/ignore-block-help.stderr
src/test/rustdoc-ui/ignore-block-help.stderr
+6
-1
src/test/rustdoc-ui/invalid-syntax.rs
src/test/rustdoc-ui/invalid-syntax.rs
+1
-1
src/test/rustdoc-ui/invalid-syntax.stderr
src/test/rustdoc-ui/invalid-syntax.stderr
+2
-2
未找到文件。
src/doc/rustdoc/src/lints.md
浏览文件 @
4120f756
...
...
@@ -328,7 +328,7 @@ warning: Rust code block is empty
--> src/lib.rs:8:5
|
8 | /// ```rust
| ^^^^^^^
|
^^^^^^^
```
## bare_urls
...
...
src/librustdoc/passes/check_code_block_syntax.rs
浏览文件 @
4120f756
...
...
@@ -61,7 +61,7 @@ fn check_rust_syntax(&self, item: &clean::Item, dox: &str, code_block: RustCodeB
};
let
hir_id
=
self
.cx.tcx
.hir
()
.local_def_id_to_hir_id
(
local_id
);
let
suggest_using_text
=
code_block
.syntax
.is_none
()
&&
code_block
.is_fenced
;
let
empty_block
=
code_block
.syntax
.is_none
()
&&
code_block
.is_fenced
;
let
is_ignore
=
code_block
.is_ignore
;
// The span and whether it is precise or not.
...
...
@@ -78,40 +78,38 @@ fn check_rust_syntax(&self, item: &clean::Item, dox: &str, code_block: RustCodeB
// lambda that will use the lint to start a new diagnostic and add
// a suggestion to it when needed.
let
diag_builder
=
|
lint
:
LintDiagnosticBuilder
<
'_
>
|
{
let
mut
diag
=
if
precise_span
{
let
msg
=
if
buffer
.has_errors
{
"could not parse code block as Rust code"
}
else
{
"Rust code block is empty"
};
let
mut
diag
=
lint
.build
(
msg
);
if
suggest_using_text
{
let
extended_msg
=
if
is_ignore
{
"`ignore` code blocks require valid Rust code for syntax highlighting.
\
Mark blocks that do not contain Rust code as text"
}
else
{
"mark blocks that do not contain Rust code as text"
};
let
explanation
=
if
is_ignore
{
"`ignore` code blocks require valid Rust code for syntax highlighting;
\
mark blocks that do not contain Rust code as text"
}
else
{
"mark blocks that do not contain Rust code as text"
};
let
msg
=
if
buffer
.has_errors
{
"could not parse code block as Rust code"
}
else
{
"Rust code block is empty"
};
let
mut
diag
=
lint
.build
(
msg
);
if
precise_span
{
if
is_ignore
{
// giving an accurate suggestion is hard because `ignore` might not have come first in the list.
// just give a `help` instead.
diag
.span_help
(
sp
.from_inner
(
InnerSpan
::
new
(
0
,
3
)),
&
format!
(
"{}: ```text"
,
explanation
),
);
}
else
if
empty_block
{
diag
.span_suggestion
(
sp
.from_inner
(
InnerSpan
::
new
(
0
,
3
)),
ex
tended_msg
,
ex
planation
,
String
::
from
(
"```text"
),
Applicability
::
MachineApplicable
,
);
}
diag
}
else
{
let
mut
diag
=
lint
.build
(
"doc comment contains an invalid Rust code block"
);
if
suggest_using_text
{
diag
.help
(
"mark blocks that do not contain Rust code as text: ```text"
);
}
diag
};
}
else
if
empty_block
||
is_ignore
{
diag
.help
(
&
format!
(
"{}: ```text"
,
explanation
));
}
// FIXME(#67563): Provide more context for these errors by displaying the spans inline.
for
message
in
buffer
.messages
.iter
()
{
...
...
src/test/rustdoc-ui/ignore-block-help.rs
浏览文件 @
4120f756
...
...
@@ -3,5 +3,8 @@
/// ```ignore (to-prevent-tidy-error)
/// let heart = '❤️';
/// ```
//~^^^ WARN
//~^^^ WARNING could not parse code block
//~| NOTE on by default
//~| NOTE character literal may only contain one codepoint
//~| HELP `ignore` code blocks require valid Rust code
pub
struct
X
;
src/test/rustdoc-ui/ignore-block-help.stderr
浏览文件 @
4120f756
...
...
@@ -7,7 +7,12 @@ LL | | /// let heart = '❤️';
LL | | /// ```
| |_______^
|
= note: `#[warn(invalid_rust_codeblock)]` on by default
= note: `#[warn(rustdoc::invalid_rust_codeblock)]` on by default
help: `ignore` code blocks require valid Rust code for syntax highlighting; mark blocks that do not contain Rust code as text: ```text
--> $DIR/ignore-block-help.rs:3:5
|
LL | /// ```ignore (to-prevent-tidy-error)
| ^^^
= note: error from rustc: character literal may only contain one codepoint
warning: 1 warning emitted
...
...
src/test/rustdoc-ui/invalid-syntax.rs
浏览文件 @
4120f756
...
...
@@ -71,7 +71,7 @@ pub fn blargh() {}
/// \_
#[doc
=
"```"
]
pub
fn
crazy_attrs
()
{}
//~^^^^ WARNING
doc comment contains an invalid Rust
code block
//~^^^^ WARNING
could not parse
code block
/// ```rust
/// ```
...
...
src/test/rustdoc-ui/invalid-syntax.stderr
浏览文件 @
4120f756
...
...
@@ -7,7 +7,7 @@ LL | | /// \__________pkt->size___________/ \_result->size_/ \__pkt->si
LL | | /// ```
| |_______^
|
= note: `#[warn(invalid_rust_codeblock)]` on by default
= note: `#[warn(
rustdoc::
invalid_rust_codeblock)]` on by default
= note: error from rustc: unknown start of token: \
= note: error from rustc: unknown start of token: \
= note: error from rustc: unknown start of token: \
...
...
@@ -91,7 +91,7 @@ LL | | /// ```
|
= note: error from rustc: unknown start of token: \
warning:
doc comment contains an invalid Rust code block
warning:
could not parse code block as Rust code
--> $DIR/invalid-syntax.rs:70:1
|
LL | / #[doc = "```"]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录