Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
3fd36bc0
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,发现更多精彩内容 >>
提交
3fd36bc0
编写于
7月 12, 2023
作者:
G
Guillaume Gomez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add jump to doc
上级
b12ff66f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
84 addition
and
25 deletion
+84
-25
src/librustdoc/html/highlight.rs
src/librustdoc/html/highlight.rs
+5
-0
src/librustdoc/html/render/context.rs
src/librustdoc/html/render/context.rs
+6
-1
src/librustdoc/html/render/span_map.rs
src/librustdoc/html/render/span_map.rs
+73
-24
未找到文件。
src/librustdoc/html/highlight.rs
浏览文件 @
3fd36bc0
...
@@ -988,6 +988,11 @@ fn string_without_closing_tag<T: Display>(
...
@@ -988,6 +988,11 @@ fn string_without_closing_tag<T: Display>(
)
)
.ok
()
.ok
()
.map
(|(
url
,
_
,
_
)|
url
),
.map
(|(
url
,
_
,
_
)|
url
),
LinkFromSrc
::
Doc
(
def_id
)
=>
{
format
::
href_with_root_path
(
*
def_id
,
context
,
Some
(
&
href_context
.root_path
))
.ok
()
.map
(|(
doc_link
,
_
,
_
)|
doc_link
)
}
}
}
})
})
{
{
...
...
src/librustdoc/html/render/context.rs
浏览文件 @
3fd36bc0
...
@@ -349,7 +349,12 @@ pub(crate) fn href_from_span(&self, span: clean::Span, with_lines: bool) -> Opti
...
@@ -349,7 +349,12 @@ pub(crate) fn href_from_span(&self, span: clean::Span, with_lines: bool) -> Opti
let
e
=
ExternalCrate
{
crate_num
:
cnum
};
let
e
=
ExternalCrate
{
crate_num
:
cnum
};
(
e
.name
(
self
.tcx
()),
e
.src_root
(
self
.tcx
()))
(
e
.name
(
self
.tcx
()),
e
.src_root
(
self
.tcx
()))
}
}
ExternalLocation
::
Unknown
=>
return
None
,
ExternalLocation
::
Unknown
=>
{
let
e
=
ExternalCrate
{
crate_num
:
cnum
};
let
name
=
e
.name
(
self
.tcx
());
root
=
name
.to_string
();
(
name
,
e
.src_root
(
self
.tcx
()))
}
};
};
let
href
=
RefCell
::
new
(
PathBuf
::
new
());
let
href
=
RefCell
::
new
(
PathBuf
::
new
());
...
...
src/librustdoc/html/render/span_map.rs
浏览文件 @
3fd36bc0
use
crate
::
clean
::{
self
,
PrimitiveType
};
use
crate
::
clean
::{
self
,
rustc_span
,
PrimitiveType
};
use
crate
::
html
::
sources
;
use
crate
::
html
::
sources
;
use
rustc_data_structures
::
fx
::
FxHashMap
;
use
rustc_data_structures
::
fx
::
FxHashMap
;
use
rustc_hir
::
def
::{
DefKind
,
Res
};
use
rustc_hir
::
def
::{
DefKind
,
Res
};
use
rustc_hir
::
def_id
::
DefId
;
use
rustc_hir
::
def_id
::
{
DefId
,
LOCAL_CRATE
}
;
use
rustc_hir
::
intravisit
::{
self
,
Visitor
};
use
rustc_hir
::
intravisit
::{
self
,
Visitor
};
use
rustc_hir
::{
ExprKind
,
HirId
,
Mod
,
Node
};
use
rustc_hir
::{
ExprKind
,
HirId
,
Item
,
ItemKind
,
Mod
,
Node
};
use
rustc_middle
::
hir
::
nested_filter
;
use
rustc_middle
::
hir
::
nested_filter
;
use
rustc_middle
::
ty
::
TyCtxt
;
use
rustc_middle
::
ty
::
TyCtxt
;
use
rustc_span
::
hygiene
::
MacroKind
;
use
rustc_span
::
hygiene
::
MacroKind
;
...
@@ -25,6 +25,7 @@ pub(crate) enum LinkFromSrc {
...
@@ -25,6 +25,7 @@ pub(crate) enum LinkFromSrc {
Local
(
clean
::
Span
),
Local
(
clean
::
Span
),
External
(
DefId
),
External
(
DefId
),
Primitive
(
PrimitiveType
),
Primitive
(
PrimitiveType
),
Doc
(
DefId
),
}
}
/// This function will do at most two things:
/// This function will do at most two things:
...
@@ -65,24 +66,43 @@ struct SpanMapVisitor<'tcx> {
...
@@ -65,24 +66,43 @@ struct SpanMapVisitor<'tcx> {
impl
<
'tcx
>
SpanMapVisitor
<
'tcx
>
{
impl
<
'tcx
>
SpanMapVisitor
<
'tcx
>
{
/// This function is where we handle `hir::Path` elements and add them into the "span map".
/// This function is where we handle `hir::Path` elements and add them into the "span map".
fn
handle_path
(
&
mut
self
,
path
:
&
rustc_hir
::
Path
<
'_
>
)
{
fn
handle_path
(
&
mut
self
,
path
:
&
rustc_hir
::
Path
<
'_
>
)
{
let
info
=
match
path
.res
{
match
path
.res
{
// FIXME: For now, we handle `DefKind` if it's not a `DefKind::TyParam`.
// FIXME: For now, we handle `DefKind` if it's not a `DefKind::TyParam`.
// Would be nice to support them too alongside the other `DefKind`
// Would be nice to support them too alongside the other `DefKind`
// (such as primitive types!).
// (such as primitive types!).
Res
::
Def
(
kind
,
def_id
)
if
kind
!=
DefKind
::
TyParam
=>
Some
(
def_id
),
Res
::
Def
(
kind
,
def_id
)
if
kind
!=
DefKind
::
TyParam
=>
{
Res
::
Local
(
_
)
=>
None
,
let
link
=
if
def_id
.as_local
()
.is_some
()
{
LinkFromSrc
::
Local
(
rustc_span
(
def_id
,
self
.tcx
))
}
else
{
LinkFromSrc
::
External
(
def_id
)
};
self
.matches
.insert
(
path
.span
,
link
);
}
Res
::
Local
(
_
)
=>
{
if
let
Some
(
span
)
=
self
.tcx
.hir
()
.res_span
(
path
.res
)
{
self
.matches
.insert
(
path
.span
,
LinkFromSrc
::
Local
(
clean
::
Span
::
new
(
span
)));
}
}
Res
::
PrimTy
(
p
)
=>
{
Res
::
PrimTy
(
p
)
=>
{
// FIXME: Doesn't handle "path-like" primitives like arrays or tuples.
// FIXME: Doesn't handle "path-like" primitives like arrays or tuples.
self
.matches
.insert
(
path
.span
,
LinkFromSrc
::
Primitive
(
PrimitiveType
::
from
(
p
)));
self
.matches
.insert
(
path
.span
,
LinkFromSrc
::
Primitive
(
PrimitiveType
::
from
(
p
)));
return
;
}
}
Res
::
Err
=>
return
,
Res
::
Err
=>
{}
_
=>
return
,
_
=>
{}
};
}
if
let
Some
(
span
)
=
self
.tcx
.hir
()
.res_span
(
path
.res
)
{
}
self
.matches
.insert
(
path
.span
,
LinkFromSrc
::
Local
(
clean
::
Span
::
new
(
span
)));
}
else
if
let
Some
(
def_id
)
=
info
{
/// Used to generate links on items' definition to go to their documentation page.
self
.matches
.insert
(
path
.span
,
LinkFromSrc
::
External
(
def_id
));
pub
(
crate
)
fn
extract_info_from_hir_id
(
&
mut
self
,
hir_id
:
HirId
)
{
if
let
Some
(
Node
::
Item
(
item
))
=
self
.tcx
.hir
()
.find
(
hir_id
)
{
if
let
Some
(
span
)
=
self
.tcx
.def_ident_span
(
item
.owner_id
)
{
let
cspan
=
clean
::
Span
::
new
(
span
);
// If the span isn't from the current crate, we ignore it.
if
cspan
.inner
()
.is_dummy
()
||
cspan
.cnum
(
self
.tcx.sess
)
!=
LOCAL_CRATE
{
return
;
}
self
.matches
.insert
(
span
,
LinkFromSrc
::
Doc
(
item
.owner_id
.to_def_id
()));
}
}
}
}
}
...
@@ -117,10 +137,13 @@ fn handle_macro(&mut self, span: Span) -> bool {
...
@@ -117,10 +137,13 @@ fn handle_macro(&mut self, span: Span) -> bool {
_
=>
return
true
,
_
=>
return
true
,
};
};
let
link_from_src
=
match
data
.macro_def_id
{
let
link_from_src
=
match
data
.macro_def_id
{
Some
(
macro_def_id
)
if
macro_def_id
.is_local
()
=>
{
Some
(
macro_def_id
)
=>
{
LinkFromSrc
::
Local
(
clean
::
Span
::
new
(
data
.def_site
))
if
macro_def_id
.is_local
()
{
LinkFromSrc
::
Local
(
clean
::
Span
::
new
(
data
.def_site
))
}
else
{
LinkFromSrc
::
External
(
macro_def_id
)
}
}
}
Some
(
macro_def_id
)
=>
LinkFromSrc
::
External
(
macro_def_id
),
None
=>
return
true
,
None
=>
return
true
,
};
};
let
new_span
=
data
.call_site
;
let
new_span
=
data
.call_site
;
...
@@ -160,6 +183,9 @@ fn visit_mod(&mut self, m: &'tcx Mod<'tcx>, span: Span, id: HirId) {
...
@@ -160,6 +183,9 @@ fn visit_mod(&mut self, m: &'tcx Mod<'tcx>, span: Span, id: HirId) {
LinkFromSrc
::
Local
(
clean
::
Span
::
new
(
m
.spans.inner_span
)),
LinkFromSrc
::
Local
(
clean
::
Span
::
new
(
m
.spans.inner_span
)),
);
);
}
}
}
else
{
// If it's a "mod foo {}", we want to look to its documentation page.
self
.extract_info_from_hir_id
(
id
);
}
}
intravisit
::
walk_mod
(
self
,
m
,
id
);
intravisit
::
walk_mod
(
self
,
m
,
id
);
}
}
...
@@ -176,13 +202,12 @@ fn visit_expr(&mut self, expr: &'tcx rustc_hir::Expr<'tcx>) {
...
@@ -176,13 +202,12 @@ fn visit_expr(&mut self, expr: &'tcx rustc_hir::Expr<'tcx>) {
.tcx
.tcx
.typeck_body
(
hir
.maybe_body_owned_by
(
body_id
)
.expect
(
"a body which isn't a body"
));
.typeck_body
(
hir
.maybe_body_owned_by
(
body_id
)
.expect
(
"a body which isn't a body"
));
if
let
Some
(
def_id
)
=
typeck_results
.type_dependent_def_id
(
expr
.hir_id
)
{
if
let
Some
(
def_id
)
=
typeck_results
.type_dependent_def_id
(
expr
.hir_id
)
{
self
.matches
.insert
(
let
link
=
if
def_id
.as_local
()
.is_some
()
{
segment
.ident.span
,
LinkFromSrc
::
Local
(
rustc_span
(
def_id
,
self
.tcx
))
match
hir
.span_if_local
(
def_id
)
{
}
else
{
Some
(
span
)
=>
LinkFromSrc
::
Local
(
clean
::
Span
::
new
(
span
)),
LinkFromSrc
::
External
(
def_id
)
None
=>
LinkFromSrc
::
External
(
def_id
),
};
},
self
.matches
.insert
(
segment
.ident.span
,
link
);
);
}
}
}
else
if
self
.handle_macro
(
expr
.span
)
{
}
else
if
self
.handle_macro
(
expr
.span
)
{
// We don't want to go deeper into the macro.
// We don't want to go deeper into the macro.
...
@@ -190,4 +215,28 @@ fn visit_expr(&mut self, expr: &'tcx rustc_hir::Expr<'tcx>) {
...
@@ -190,4 +215,28 @@ fn visit_expr(&mut self, expr: &'tcx rustc_hir::Expr<'tcx>) {
}
}
intravisit
::
walk_expr
(
self
,
expr
);
intravisit
::
walk_expr
(
self
,
expr
);
}
}
fn
visit_item
(
&
mut
self
,
item
:
&
'tcx
Item
<
'tcx
>
)
{
match
item
.kind
{
ItemKind
::
Static
(
_
,
_
,
_
)
|
ItemKind
::
Const
(
_
,
_
)
|
ItemKind
::
Fn
(
_
,
_
,
_
)
|
ItemKind
::
Macro
(
_
,
_
)
|
ItemKind
::
TyAlias
(
_
,
_
)
|
ItemKind
::
Enum
(
_
,
_
)
|
ItemKind
::
Struct
(
_
,
_
)
|
ItemKind
::
Union
(
_
,
_
)
|
ItemKind
::
Trait
(
_
,
_
,
_
,
_
,
_
)
|
ItemKind
::
TraitAlias
(
_
,
_
)
=>
self
.extract_info_from_hir_id
(
item
.hir_id
()),
ItemKind
::
Impl
(
_
)
|
ItemKind
::
Use
(
_
,
_
)
|
ItemKind
::
ExternCrate
(
_
)
|
ItemKind
::
ForeignMod
{
..
}
|
ItemKind
::
GlobalAsm
(
_
)
|
ItemKind
::
OpaqueTy
(
_
)
// We already have "visit_mod" above so no need to check it here.
|
ItemKind
::
Mod
(
_
)
=>
{}
}
intravisit
::
walk_item
(
self
,
item
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录