Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
28ebec51
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,发现更多精彩内容 >>
提交
28ebec51
编写于
2月 26, 2014
作者:
F
Felix S. Klock II
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Introduce Scope<'a> shorthand for &'a ScopeChain<'a>.
上级
189c0085
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
13 addition
and
11 deletion
+13
-11
src/librustc/middle/resolve_lifetime.rs
src/librustc/middle/resolve_lifetime.rs
+13
-11
未找到文件。
src/librustc/middle/resolve_lifetime.rs
浏览文件 @
28ebec51
...
...
@@ -40,11 +40,13 @@ struct LifetimeContext {
enum
ScopeChain
<
'a
>
{
ItemScope
(
&
'a
OptVec
<
ast
::
Lifetime
>
),
FnScope
(
ast
::
NodeId
,
&
'a
OptVec
<
ast
::
Lifetime
>
,
&
'a
ScopeChain
<
'a
>
),
BlockScope
(
ast
::
NodeId
,
&
'a
ScopeChain
<
'a
>
),
FnScope
(
ast
::
NodeId
,
&
'a
OptVec
<
ast
::
Lifetime
>
,
Scope
<
'a
>
),
BlockScope
(
ast
::
NodeId
,
Scope
<
'a
>
),
RootScope
}
type
Scope
<
'a
>
=
&
'a
ScopeChain
<
'a
>
;
pub
fn
krate
(
sess
:
session
::
Session
,
krate
:
&
ast
::
Crate
)
->
@
RefCell
<
NamedRegionMap
>
{
let
mut
ctxt
=
LifetimeContext
{
...
...
@@ -56,10 +58,10 @@ pub fn krate(sess: session::Session, krate: &ast::Crate)
ctxt
.named_region_map
}
impl
<
'a
>
Visitor
<
&
'a
ScopeChain
<
'a
>>
for
LifetimeContext
{
impl
<
'a
>
Visitor
<
Scope
<
'a
>>
for
LifetimeContext
{
fn
visit_item
(
&
mut
self
,
item
:
&
ast
::
Item
,
_
:
&
'a
ScopeChain
<
'a
>
)
{
_
:
Scope
<
'a
>
)
{
let
scope
=
match
item
.node
{
ast
::
ItemFn
(
..
)
|
// fn lifetimes get added in visit_fn below
ast
::
ItemMod
(
..
)
|
...
...
@@ -84,7 +86,7 @@ fn visit_item(&mut self,
fn
visit_fn
(
&
mut
self
,
fk
:
&
visit
::
FnKind
,
fd
:
&
ast
::
FnDecl
,
b
:
&
ast
::
Block
,
s
:
Span
,
n
:
ast
::
NodeId
,
scope
:
&
'a
ScopeChain
<
'a
>
)
{
scope
:
Scope
<
'a
>
)
{
match
*
fk
{
visit
::
FkItemFn
(
_
,
generics
,
_
,
_
)
|
visit
::
FkMethod
(
_
,
generics
,
_
)
=>
{
...
...
@@ -101,7 +103,7 @@ fn visit_fn(&mut self, fk: &visit::FnKind, fd: &ast::FnDecl,
}
fn
visit_ty
(
&
mut
self
,
ty
:
&
ast
::
Ty
,
scope
:
&
'a
ScopeChain
<
'a
>
)
{
scope
:
Scope
<
'a
>
)
{
match
ty
.node
{
ast
::
TyClosure
(
closure
)
=>
{
let
scope1
=
FnScope
(
ty
.id
,
&
closure
.lifetimes
,
scope
);
...
...
@@ -125,7 +127,7 @@ fn visit_ty(&mut self, ty: &ast::Ty,
fn
visit_ty_method
(
&
mut
self
,
m
:
&
ast
::
TypeMethod
,
scope
:
&
'a
ScopeChain
<
'a
>
)
{
scope
:
Scope
<
'a
>
)
{
let
scope1
=
FnScope
(
m
.id
,
&
m
.generics.lifetimes
,
scope
);
self
.check_lifetime_names
(
&
m
.generics.lifetimes
);
debug!
(
"pushing fn scope id={} due to ty_method"
,
m
.id
);
...
...
@@ -135,7 +137,7 @@ fn visit_ty_method(&mut self,
fn
visit_block
(
&
mut
self
,
b
:
&
ast
::
Block
,
scope
:
&
'a
ScopeChain
<
'a
>
)
{
scope
:
Scope
<
'a
>
)
{
let
scope1
=
BlockScope
(
b
.id
,
scope
);
debug!
(
"pushing block scope {}"
,
b
.id
);
visit
::
walk_block
(
self
,
b
,
&
scope1
);
...
...
@@ -144,7 +146,7 @@ fn visit_block(&mut self,
fn
visit_lifetime_ref
(
&
mut
self
,
lifetime_ref
:
&
ast
::
Lifetime
,
scope
:
&
'a
ScopeChain
<
'a
>
)
{
scope
:
Scope
<
'a
>
)
{
if
lifetime_ref
.name
==
special_idents
::
statik
.name
{
self
.insert_lifetime
(
lifetime_ref
,
ast
::
DefStaticRegion
);
return
;
...
...
@@ -156,7 +158,7 @@ fn visit_lifetime_ref(&mut self,
impl
LifetimeContext
{
fn
resolve_lifetime_ref
(
&
self
,
lifetime_ref
:
&
ast
::
Lifetime
,
scope
:
&
ScopeChain
)
{
scope
:
Scope
)
{
// Walk up the scope chain, tracking the number of fn scopes
// that we pass through, until we find a lifetime with the
// given name or we run out of scopes. If we encounter a code
...
...
@@ -211,7 +213,7 @@ fn resolve_lifetime_ref(&self,
fn
resolve_free_lifetime_ref
(
&
self
,
scope_id
:
ast
::
NodeId
,
lifetime_ref
:
&
ast
::
Lifetime
,
scope
:
&
ScopeChain
)
{
scope
:
Scope
)
{
// Walk up the scope chain, tracking the outermost free scope,
// until we encounter a scope that contains the named lifetime
// or we run out of scopes.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录