Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
a2f3e4a5
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,发现更多精彩内容 >>
提交
a2f3e4a5
编写于
7月 19, 2021
作者:
G
Guillaume Gomez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Change span for intra-doc links errors
上级
aea2e446
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
73 addition
and
24 deletion
+73
-24
src/librustdoc/passes/collect_intra_doc_links.rs
src/librustdoc/passes/collect_intra_doc_links.rs
+73
-24
未找到文件。
src/librustdoc/passes/collect_intra_doc_links.rs
浏览文件 @
a2f3e4a5
...
...
@@ -19,7 +19,7 @@
use
rustc_session
::
lint
::
Lint
;
use
rustc_span
::
hygiene
::{
MacroKind
,
SyntaxContext
};
use
rustc_span
::
symbol
::{
sym
,
Ident
,
Symbol
};
use
rustc_span
::
DUMMY_SP
;
use
rustc_span
::
{
BytePos
,
DUMMY_SP
}
;
use
smallvec
::{
smallvec
,
SmallVec
};
use
pulldown_cmark
::
LinkType
;
...
...
@@ -1193,7 +1193,7 @@ fn resolve_link(
let
report_mismatch
=
|
specified
:
Disambiguator
,
resolved
:
Disambiguator
|
{
// The resolved item did not match the disambiguator; give a better error than 'not found'
let
msg
=
format!
(
"incompatible link kind for `{}`"
,
path_str
);
let
callback
=
|
diag
:
&
mut
DiagnosticBuilder
<
'_
>
,
sp
|
{
let
callback
=
|
diag
:
&
mut
DiagnosticBuilder
<
'_
>
,
sp
:
Option
<
rustc_span
::
Span
>
|
{
let
note
=
format!
(
"this link resolved to {} {}, which is not {} {}"
,
resolved
.article
(),
...
...
@@ -1201,8 +1201,12 @@ fn resolve_link(
specified
.article
(),
specified
.descr
()
);
diag
.note
(
&
note
);
suggest_disambiguator
(
resolved
,
diag
,
path_str
,
dox
,
sp
,
&
ori_link
.range
);
if
let
Some
(
sp
)
=
sp
{
diag
.span_label
(
sp
,
&
note
);
}
else
{
diag
.note
(
&
note
);
}
suggest_disambiguator
(
resolved
,
diag
,
path_str
,
&
ori_link
.link
,
sp
);
};
report_diagnostic
(
self
.cx.tcx
,
BROKEN_INTRA_DOC_LINKS
,
&
msg
,
&
diag_info
,
callback
);
};
...
...
@@ -1699,6 +1703,51 @@ fn as_help(&self, path_str: &str) -> String {
Self
::
RemoveDisambiguator
=>
path_str
.into
(),
}
}
fn
as_help_span
(
&
self
,
path_str
:
&
str
,
ori_link
:
&
str
,
sp
:
rustc_span
::
Span
,
)
->
Vec
<
(
rustc_span
::
Span
,
String
)
>
{
let
inner_sp
=
match
ori_link
.find
(
'('
)
{
Some
(
index
)
=>
sp
.with_hi
(
sp
.lo
()
+
BytePos
(
index
as
_
)),
None
=>
sp
,
};
let
inner_sp
=
match
ori_link
.find
(
'!'
)
{
Some
(
index
)
=>
inner_sp
.with_hi
(
inner_sp
.lo
()
+
BytePos
(
index
as
_
)),
None
=>
inner_sp
,
};
let
inner_sp
=
match
ori_link
.find
(
'@'
)
{
Some
(
index
)
=>
inner_sp
.with_lo
(
inner_sp
.lo
()
+
BytePos
(
index
as
u32
+
1
)),
None
=>
inner_sp
,
};
match
self
{
Self
::
Prefix
(
prefix
)
=>
{
// FIXME: if this is an implied shortcut link, it's bad style to suggest `@`
let
mut
sugg
=
vec!
[(
sp
.with_hi
(
inner_sp
.lo
()),
format!
(
"{}@"
,
prefix
))];
if
sp
.hi
()
!=
inner_sp
.hi
()
{
sugg
.push
((
inner_sp
.shrink_to_hi
()
.with_hi
(
sp
.hi
()),
String
::
new
()));
}
sugg
}
Self
::
Function
=>
{
let
mut
sugg
=
vec!
[(
inner_sp
.shrink_to_hi
()
.with_hi
(
sp
.hi
()),
"()"
.to_string
())];
if
sp
.lo
()
!=
inner_sp
.lo
()
{
sugg
.push
((
inner_sp
.shrink_to_lo
()
.with_lo
(
sp
.lo
()),
String
::
new
()));
}
sugg
}
Self
::
Macro
=>
{
let
mut
sugg
=
vec!
[(
inner_sp
.shrink_to_hi
(),
"!"
.to_string
())];
if
sp
.lo
()
!=
inner_sp
.lo
()
{
sugg
.push
((
inner_sp
.shrink_to_lo
()
.with_lo
(
sp
.lo
()),
String
::
new
()));
}
sugg
}
Self
::
RemoveDisambiguator
=>
return
vec!
[(
sp
,
path_str
.into
())],
}
}
}
/// Reports a diagnostic for an intra-doc link.
...
...
@@ -1732,7 +1781,16 @@ fn report_diagnostic(
tcx
.struct_span_lint_hir
(
lint
,
hir_id
,
sp
,
|
lint
|
{
let
mut
diag
=
lint
.build
(
msg
);
let
span
=
super
::
source_span_for_markdown_range
(
tcx
,
dox
,
link_range
,
&
item
.attrs
);
let
span
=
super
::
source_span_for_markdown_range
(
tcx
,
dox
,
link_range
,
&
item
.attrs
)
.map
(|
sp
|
{
if
dox
.bytes
()
.nth
(
link_range
.start
)
==
Some
(
b
'`'
)
&&
dox
.bytes
()
.nth
(
link_range
.end
-
1
)
==
Some
(
b
'`'
)
{
sp
.with_lo
(
sp
.lo
()
+
BytePos
(
1
))
.with_hi
(
sp
.hi
()
-
BytePos
(
1
))
}
else
{
sp
}
});
if
let
Some
(
sp
)
=
span
{
diag
.set_span
(
sp
);
...
...
@@ -1938,9 +1996,8 @@ fn split(path: &str) -> Option<(&str, &str)> {
disambiguator
,
diag
,
path_str
,
diag_info
.
dox
,
diag_info
.
ori_link
,
sp
,
&
diag_info
.link_range
,
)
}
...
...
@@ -2007,7 +2064,7 @@ fn anchor_failure(cx: &DocContext<'_>, diag_info: DiagnosticInfo<'_>, failure: A
if
let
Some
((
fragment_offset
,
_
))
=
diag_info
.ori_link
.char_indices
()
.filter
(|(
_
,
x
)|
*
x
==
'#'
)
.nth
(
anchor_idx
)
{
sp
=
sp
.with_lo
(
sp
.lo
()
+
rustc_span
::
BytePos
(
fragment_offset
as
_
));
sp
=
sp
.with_lo
(
sp
.lo
()
+
BytePos
(
fragment_offset
as
_
));
}
diag
.span_label
(
sp
,
"invalid anchor"
);
}
...
...
@@ -2075,14 +2132,7 @@ fn ambiguity_error(
for
res
in
candidates
{
let
disambiguator
=
Disambiguator
::
from_res
(
res
);
suggest_disambiguator
(
disambiguator
,
diag
,
path_str
,
diag_info
.dox
,
sp
,
&
diag_info
.link_range
,
);
suggest_disambiguator
(
disambiguator
,
diag
,
path_str
,
diag_info
.ori_link
,
sp
);
}
});
}
...
...
@@ -2093,21 +2143,20 @@ fn suggest_disambiguator(
disambiguator
:
Disambiguator
,
diag
:
&
mut
DiagnosticBuilder
<
'_
>
,
path_str
:
&
str
,
dox
:
&
str
,
ori_link
:
&
str
,
sp
:
Option
<
rustc_span
::
Span
>
,
link_range
:
&
Range
<
usize
>
,
)
{
let
suggestion
=
disambiguator
.suggestion
();
let
help
=
format!
(
"to link to the {}, {}"
,
disambiguator
.descr
(),
suggestion
.descr
());
if
let
Some
(
sp
)
=
sp
{
let
msg
=
if
dox
.bytes
()
.nth
(
link_range
.start
)
==
Some
(
b
'`'
)
{
format!
(
"`{}`"
,
suggestion
.as_help
(
path_str
))
let
mut
spans
=
suggestion
.as_help_span
(
path_str
,
ori_link
,
sp
);
if
spans
.len
()
>
1
{
diag
.multipart_suggestion
(
&
help
,
spans
,
Applicability
::
MaybeIncorrect
);
}
else
{
suggestion
.as_help
(
path_str
)
};
diag
.span_suggestion
(
sp
,
&
help
,
msg
,
Applicability
::
MaybeIncorrect
);
let
(
sp
,
suggestion_text
)
=
spans
.pop
()
.unwrap
();
diag
.span_suggestion_verbose
(
sp
,
&
help
,
suggestion_text
,
Applicability
::
MaybeIncorrect
);
}
}
else
{
diag
.help
(
&
format!
(
"{}: {}"
,
help
,
suggestion
.as_help
(
path_str
)));
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录