Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
e6ee8a0d
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,发现更多精彩内容 >>
提交
e6ee8a0d
编写于
6月 20, 2019
作者:
E
Eduard-Mihai Burtescu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rustc: produce AST instead of HIR from `hir::lowering::Resolver` methods.
上级
53ae6d2e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
46 addition
and
46 deletion
+46
-46
src/librustc/hir/lowering.rs
src/librustc/hir/lowering.rs
+20
-10
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+15
-27
src/librustdoc/passes/collect_intra_doc_links.rs
src/librustdoc/passes/collect_intra_doc_links.rs
+11
-9
未找到文件。
src/librustc/hir/lowering.rs
浏览文件 @
e6ee8a0d
...
...
@@ -148,11 +148,11 @@ pub struct LoweringContext<'a> {
pub
trait
Resolver
{
/// Resolve a path generated by the lowerer when expanding `for`, `if let`, etc.
fn
resolve_
hir
_path
(
fn
resolve_
ast
_path
(
&
mut
self
,
path
:
&
ast
::
Path
,
is_value
:
bool
,
)
->
hir
::
Path
;
)
->
Res
<
NodeId
>
;
/// Obtain resolution for a `NodeId` with a single resolution.
fn
get_partial_res
(
&
mut
self
,
id
:
NodeId
)
->
Option
<
PartialRes
>
;
...
...
@@ -167,7 +167,7 @@ fn resolve_hir_path(
/// This should only return `None` during testing.
fn
definitions
(
&
mut
self
)
->
&
mut
Definitions
;
/// Given suffix `["b", "c", "d"]`, creates a
HIR
path for `[::crate_root]::b::c::d` and
/// Given suffix `["b", "c", "d"]`, creates a
n AST
path for `[::crate_root]::b::c::d` and
/// resolves it based on `is_value`.
fn
resolve_str_path
(
&
mut
self
,
...
...
@@ -175,7 +175,7 @@ fn resolve_str_path(
crate_root
:
Option
<
Symbol
>
,
components
:
&
[
Symbol
],
is_value
:
bool
,
)
->
hir
::
Path
;
)
->
(
ast
::
Path
,
Res
<
NodeId
>
)
;
}
/// Context of `impl Trait` in code, which determines whether it is allowed in an HIR subtree,
...
...
@@ -5546,16 +5546,26 @@ fn std_path(
params
:
Option
<
P
<
hir
::
GenericArgs
>>
,
is_value
:
bool
,
)
->
hir
::
Path
{
let
mut
path
=
self
.resolver
let
(
path
,
res
)
=
self
.resolver
.resolve_str_path
(
span
,
self
.crate_root
,
components
,
is_value
);
path
.segments
.last_mut
()
.unwrap
()
.args
=
params
;
for
seg
in
path
.segments
.iter_mut
()
{
if
seg
.hir_id
.is_some
()
{
seg
.hir_id
=
Some
(
self
.next_id
());
let
mut
segments
:
Vec
<
_
>
=
path
.segments
.iter
()
.map
(|
segment
|
{
let
res
=
self
.expect_full_res
(
segment
.id
);
hir
::
PathSegment
{
ident
:
segment
.ident
,
hir_id
:
Some
(
self
.lower_node_id
(
segment
.id
)),
res
:
Some
(
self
.lower_res
(
res
)),
infer_args
:
true
,
args
:
None
,
}
})
.collect
();
segments
.last_mut
()
.unwrap
()
.args
=
params
;
hir
::
Path
{
span
,
res
:
res
.map_id
(|
_
|
panic!
(
"unexpected node_id"
)),
segments
:
segments
.into
(),
}
path
}
fn
ty_path
(
&
mut
self
,
mut
hir_id
:
hir
::
HirId
,
span
:
Span
,
qpath
:
hir
::
QPath
)
->
hir
::
Ty
{
...
...
src/librustc_resolve/lib.rs
浏览文件 @
e6ee8a0d
...
...
@@ -1744,12 +1744,12 @@ fn parent(self, id: DefId) -> Option<DefId> {
/// This interface is used through the AST→HIR step, to embed full paths into the HIR. After that
/// the resolver is no longer needed as all the relevant information is inline.
impl
<
'a
>
hir
::
lowering
::
Resolver
for
Resolver
<
'a
>
{
fn
resolve_
hir
_path
(
fn
resolve_
ast
_path
(
&
mut
self
,
path
:
&
ast
::
Path
,
is_value
:
bool
,
)
->
hir
::
Path
{
self
.resolve_
hir
_path_cb
(
path
,
is_value
,
)
->
Res
{
self
.resolve_
ast
_path_cb
(
path
,
is_value
,
|
resolver
,
span
,
error
|
resolve_error
(
resolver
,
span
,
error
))
}
...
...
@@ -1759,7 +1759,7 @@ fn resolve_str_path(
crate_root
:
Option
<
Symbol
>
,
components
:
&
[
Symbol
],
is_value
:
bool
)
->
hir
::
Path
{
)
->
(
ast
::
Path
,
Res
)
{
let
root
=
if
crate_root
.is_some
()
{
kw
::
PathRoot
}
else
{
...
...
@@ -1777,7 +1777,8 @@ fn resolve_str_path(
segments
,
};
self
.resolve_hir_path
(
&
path
,
is_value
)
let
res
=
self
.resolve_ast_path
(
&
path
,
is_value
);
(
path
,
res
)
}
fn
get_partial_res
(
&
mut
self
,
id
:
NodeId
)
->
Option
<
PartialRes
>
{
...
...
@@ -1803,7 +1804,7 @@ impl<'a> Resolver<'a> {
/// and also it's a private type. Fortunately rustdoc doesn't need to know the error,
/// just that an error occurred.
pub
fn
resolve_str_path_error
(
&
mut
self
,
span
:
Span
,
path_str
:
&
str
,
is_value
:
bool
)
->
Result
<
hir
::
Path
,
()
>
{
->
Result
<
(
ast
::
Path
,
Res
)
,
()
>
{
let
mut
errored
=
false
;
let
path
=
if
path_str
.starts_with
(
"::"
)
{
...
...
@@ -1826,29 +1827,29 @@ pub fn resolve_str_path_error(&mut self, span: Span, path_str: &str, is_value: b
.collect
(),
}
};
let
path
=
self
.resolve_hir
_path_cb
(
&
path
,
is_value
,
|
_
,
_
,
_
|
errored
=
true
);
if
errored
||
path
.
res
==
def
::
Res
::
Err
{
let
res
=
self
.resolve_ast
_path_cb
(
&
path
,
is_value
,
|
_
,
_
,
_
|
errored
=
true
);
if
errored
||
res
==
def
::
Res
::
Err
{
Err
(())
}
else
{
Ok
(
path
)
Ok
(
(
path
,
res
)
)
}
}
/// Like `resolve_hir_path`, but takes a callback in case there was an error.
fn
resolve_hir_path_cb
<
F
>
(
/// Like `resolve_ast_path`, but takes a callback in case there was an error.
// FIXME(eddyb) use `Result` or something instead of callbacks.
fn
resolve_ast_path_cb
<
F
>
(
&
mut
self
,
path
:
&
ast
::
Path
,
is_value
:
bool
,
error_callback
:
F
,
)
->
hir
::
Path
)
->
Res
where
F
:
for
<
'c
,
'b
>
FnOnce
(
&
'c
mut
Resolver
<
'_
>
,
Span
,
ResolutionError
<
'b
>
)
{
let
namespace
=
if
is_value
{
ValueNS
}
else
{
TypeNS
};
let
span
=
path
.span
;
let
segments
=
&
path
.segments
;
let
path
=
Segment
::
from_path
(
&
path
);
// FIXME(Manishearth): intra-doc links won't get warned of epoch changes.
let
res
=
match
self
.resolve_path_without_parent_scope
(
&
path
,
Some
(
namespace
),
true
,
match
self
.resolve_path_without_parent_scope
(
&
path
,
Some
(
namespace
),
true
,
span
,
CrateLint
::
No
)
{
PathResult
::
Module
(
ModuleOrUniformRoot
::
Module
(
module
))
=>
module
.res
()
.unwrap
(),
...
...
@@ -1869,19 +1870,6 @@ fn resolve_hir_path_cb<F>(
});
Res
::
Err
}
};
let
segments
:
Vec
<
_
>
=
segments
.iter
()
.map
(|
seg
|
{
let
mut
hir_seg
=
hir
::
PathSegment
::
from_ident
(
seg
.ident
);
hir_seg
.res
=
Some
(
self
.partial_res_map
.get
(
&
seg
.id
)
.map_or
(
def
::
Res
::
Err
,
|
p
|
{
p
.base_res
()
.map_id
(|
_
|
panic!
(
"unexpected node_id"
))
}));
hir_seg
})
.collect
();
hir
::
Path
{
span
,
res
:
res
.map_id
(|
_
|
panic!
(
"unexpected node_id"
)),
segments
:
segments
.into
(),
}
}
...
...
src/librustdoc/passes/collect_intra_doc_links.rs
浏览文件 @
e6ee8a0d
...
...
@@ -71,15 +71,16 @@ fn resolve(&self,
})
});
if
let
Ok
(
result
)
=
result
{
if
let
Ok
((
_
,
res
))
=
result
{
let
res
=
res
.map_id
(|
_
|
panic!
(
"unexpected node_id"
));
// In case this is a trait item, skip the
// early return and try looking for the trait.
let
value
=
match
res
ult
.res
{
let
value
=
match
res
{
Res
::
Def
(
DefKind
::
Method
,
_
)
|
Res
::
Def
(
DefKind
::
AssocConst
,
_
)
=>
true
,
Res
::
Def
(
DefKind
::
AssocTy
,
_
)
=>
false
,
Res
::
Def
(
DefKind
::
Variant
,
_
)
=>
return
handle_variant
(
cx
,
res
ult
.res
),
Res
::
Def
(
DefKind
::
Variant
,
_
)
=>
return
handle_variant
(
cx
,
res
),
// Not a trait item; just return what we found.
_
=>
return
Ok
((
res
ult
.res
,
None
))
_
=>
return
Ok
((
res
,
None
))
};
if
value
!=
(
ns
==
ValueNS
)
{
...
...
@@ -129,10 +130,11 @@ fn resolve(&self,
// FIXME: `with_scope` requires the `NodeId` of a module.
let
node_id
=
cx
.tcx
.hir
()
.hir_to_node_id
(
id
);
let
ty
=
cx
.enter_resolver
(|
resolver
|
resolver
.with_scope
(
node_id
,
|
resolver
|
{
let
(
_
,
ty_res
)
=
cx
.enter_resolver
(|
resolver
|
resolver
.with_scope
(
node_id
,
|
resolver
|
{
resolver
.resolve_str_path_error
(
DUMMY_SP
,
&
path
,
false
)
}))
?
;
match
ty
.res
{
let
ty_res
=
ty_res
.map_id
(|
_
|
panic!
(
"unexpected node_id"
));
match
ty_res
{
Res
::
Def
(
DefKind
::
Struct
,
did
)
|
Res
::
Def
(
DefKind
::
Union
,
did
)
|
Res
::
Def
(
DefKind
::
Enum
,
did
)
...
...
@@ -147,7 +149,7 @@ fn resolve(&self,
ty
::
AssocKind
::
Const
if
ns
==
ValueNS
=>
"associatedconstant"
,
_
=>
return
Err
(())
};
Ok
((
ty
.
res
,
Some
(
format!
(
"{}.{}"
,
out
,
item_name
))))
Ok
((
ty
_
res
,
Some
(
format!
(
"{}.{}"
,
out
,
item_name
))))
}
else
{
match
cx
.tcx
.type_of
(
did
)
.sty
{
ty
::
Adt
(
def
,
_
)
=>
{
...
...
@@ -159,7 +161,7 @@ fn resolve(&self,
.iter
()
.find
(|
item
|
item
.ident.name
==
item_name
)
}
{
Ok
((
ty
.
res
,
Ok
((
ty
_
res
,
Some
(
format!
(
"{}.{}"
,
if
def
.is_enum
()
{
"variant"
...
...
@@ -193,7 +195,7 @@ fn resolve(&self,
_
=>
return
Err
(())
};
Ok
((
ty
.
res
,
Some
(
format!
(
"{}.{}"
,
kind
,
item_name
))))
Ok
((
ty
_
res
,
Some
(
format!
(
"{}.{}"
,
kind
,
item_name
))))
}
else
{
Err
(())
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录