Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
0682a75f
R
Rust
项目概览
int
/
Rust
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
0682a75f
编写于
1月 08, 2017
作者:
E
Eduard-Mihai Burtescu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rustc: clean up the style of middle::resolve_lifetime.
上级
7a2a669b
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
109 addition
and
79 deletion
+109
-79
src/librustc/middle/resolve_lifetime.rs
src/librustc/middle/resolve_lifetime.rs
+99
-69
src/librustc_typeck/astconv.rs
src/librustc_typeck/astconv.rs
+5
-5
src/librustc_typeck/variance/constraints.rs
src/librustc_typeck/variance/constraints.rs
+1
-1
src/librustdoc/clean/mod.rs
src/librustdoc/clean/mod.rs
+4
-4
未找到文件。
src/librustc/middle/resolve_lifetime.rs
浏览文件 @
0682a75f
...
...
@@ -15,9 +15,6 @@
//! used between functions, and they operate in a purely top-down
//! way. Therefore we break lifetime name resolution into a separate pass.
pub
use
self
::
DefRegion
::
*
;
use
self
::
ScopeChain
::
*
;
use
dep_graph
::
DepNode
;
use
hir
::
map
::
Map
;
use
session
::
Session
;
...
...
@@ -36,22 +33,19 @@
use
hir
::
intravisit
::{
self
,
Visitor
,
FnKind
,
NestedVisitorMap
};
#[derive(Clone,
Copy,
PartialEq,
Eq,
Hash,
RustcEncodable,
RustcDecodable,
Debug)]
pub
enum
DefRegion
{
DefStaticRegion
,
DefEarlyBoundRegion
(
/* index */
u32
,
/* lifetime decl */
ast
::
NodeId
),
DefLateBoundRegion
(
ty
::
DebruijnIndex
,
/* lifetime decl */
ast
::
NodeId
),
DefFreeRegion
(
region
::
CallSiteScopeData
,
/* lifetime decl */
ast
::
NodeId
),
pub
enum
Region
{
Static
,
EarlyBound
(
/* index */
u32
,
/* lifetime decl */
ast
::
NodeId
),
LateBound
(
ty
::
DebruijnIndex
,
/* lifetime decl */
ast
::
NodeId
),
Free
(
region
::
CallSiteScopeData
,
/* lifetime decl */
ast
::
NodeId
),
}
// Maps the id of each lifetime reference to the lifetime decl
// that it corresponds to.
pub
struct
NamedRegionMap
{
// maps from every use of a named (not anonymous) lifetime to a
// `
Def
Region` describing how that region is bound
pub
defs
:
NodeMap
<
Def
Region
>
,
// `Region` describing how that region is bound
pub
defs
:
NodeMap
<
Region
>
,
// the set of lifetime def ids that are late-bound; late-bound ids
// are named regions appearing in fn arguments that do not appear
...
...
@@ -63,7 +57,7 @@ struct LifetimeContext<'a, 'tcx: 'a> {
sess
:
&
'a
Session
,
hir_map
:
&
'a
Map
<
'tcx
>
,
map
:
&
'a
mut
NamedRegionMap
,
scope
:
Scope
<
'a
>
,
scope
:
Scope
Ref
<
'a
>
,
// Deep breath. Our representation for poly trait refs contains a single
// binder and thus we only allow a single level of quantification. However,
// the syntax of Rust permits quantification in two places, e.g., `T: for <'a> Foo<'a>`
...
...
@@ -86,25 +80,36 @@ struct LifetimeContext<'a, 'tcx: 'a> {
}
#[derive(PartialEq,
Debug)]
enum
ScopeChain
<
'a
>
{
/// EarlyScope(['a, 'b, ...], start, s) extends s with early-bound
/// lifetimes, with consecutive parameter indices from `start`.
/// That is, 'a has index `start`, 'b has index `start + 1`, etc.
enum
Scope
<
'a
>
{
/// Extends `s` with early-bound `lifetimes`, having consecutive parameter
/// indices from `start`, i.e. `lifetimes[i]` has index `start + i`.
/// Indices before `start` correspond to other generic parameters
/// of a parent item (trait/impl of a method), or `Self` in traits.
EarlyScope
(
&
'a
[
hir
::
LifetimeDef
],
u32
,
Scope
<
'a
>
),
/// LateScope(['a, 'b, ...], s) extends s with late-bound
/// lifetimes introduced by the declaration binder_id.
LateScope
(
&
'a
[
hir
::
LifetimeDef
],
Scope
<
'a
>
),
/// lifetimes introduced by a fn are scoped to the call-site for that fn.
FnScope
{
fn_id
:
ast
::
NodeId
,
body_id
:
ast
::
NodeId
,
s
:
Scope
<
'a
>
},
RootScope
Early
{
lifetimes
:
&
'a
[
hir
::
LifetimeDef
],
start
:
u32
,
s
:
ScopeRef
<
'a
>
},
/// Extends `s` with late-bound `lifetimes`.
Late
{
lifetimes
:
&
'a
[
hir
::
LifetimeDef
],
s
:
ScopeRef
<
'a
>
},
/// Lifetimes introduced by a fn are scoped to the call-site for that fn.
Fn
{
fn_id
:
ast
::
NodeId
,
body_id
:
ast
::
NodeId
,
s
:
ScopeRef
<
'a
>
},
Root
}
type
Scope
<
'a
>
=
&
'a
ScopeChain
<
'a
>
;
type
Scope
Ref
<
'a
>
=
&
'a
Scope
<
'a
>
;
static
ROOT_SCOPE
:
ScopeChain
<
'static
>
=
RootScope
;
const
ROOT_SCOPE
:
ScopeRef
<
'static
>
=
&
Scope
::
Root
;
pub
fn
krate
(
sess
:
&
Session
,
hir_map
:
&
Map
)
...
...
@@ -120,7 +125,7 @@ pub fn krate(sess: &Session,
sess
:
sess
,
hir_map
:
hir_map
,
map
:
&
mut
map
,
scope
:
&
ROOT_SCOPE
,
scope
:
ROOT_SCOPE
,
trait_ref_hack
:
false
,
labels_in_fn
:
vec!
[],
},
krate
);
...
...
@@ -140,7 +145,7 @@ fn visit_item(&mut self, item: &'tcx hir::Item) {
let
saved_labels_in_fn
=
replace
(
&
mut
self
.labels_in_fn
,
vec!
[]);
// Items always introduce a new root scope
self
.with
(
RootScope
,
|
_
,
this
|
{
self
.with
(
Scope
::
Root
,
|
_
,
this
|
{
match
item
.node
{
hir
::
ItemFn
(
..
)
=>
{
// Fn lifetimes get added in visit_fn below:
...
...
@@ -169,7 +174,12 @@ fn visit_item(&mut self, item: &'tcx hir::Item) {
}
else
{
0
};
this
.with
(
EarlyScope
(
lifetimes
,
start
,
&
ROOT_SCOPE
),
|
old_scope
,
this
|
{
let
early
=
Scope
::
Early
{
lifetimes
:
lifetimes
,
start
:
start
,
s
:
ROOT_SCOPE
};
this
.with
(
early
,
|
old_scope
,
this
|
{
this
.check_lifetime_defs
(
old_scope
,
lifetimes
);
intravisit
::
walk_item
(
this
,
item
);
});
...
...
@@ -187,7 +197,7 @@ fn visit_foreign_item(&mut self, item: &'tcx hir::ForeignItem) {
let
saved
=
replace
(
&
mut
self
.labels_in_fn
,
vec!
[]);
// Items always introduce a new root scope
self
.with
(
RootScope
,
|
_
,
this
|
{
self
.with
(
Scope
::
Root
,
|
_
,
this
|
{
match
item
.node
{
hir
::
ForeignItemFn
(
ref
decl
,
_
,
ref
generics
)
=>
{
this
.visit_early_late
(
item
.id
,
decl
,
generics
,
|
this
|
{
...
...
@@ -233,7 +243,11 @@ fn visit_fn(&mut self, fk: FnKind<'tcx>, decl: &'tcx hir::FnDecl,
fn
visit_ty
(
&
mut
self
,
ty
:
&
'tcx
hir
::
Ty
)
{
match
ty
.node
{
hir
::
TyBareFn
(
ref
c
)
=>
{
self
.with
(
LateScope
(
&
c
.lifetimes
,
self
.scope
),
|
old_scope
,
this
|
{
let
late
=
Scope
::
Late
{
lifetimes
:
&
c
.lifetimes
,
s
:
self
.scope
};
self
.with
(
late
,
|
old_scope
,
this
|
{
// a bare fn has no bounds, so everything
// contained within is scoped within its binder.
this
.check_lifetime_defs
(
old_scope
,
&
c
.lifetimes
);
...
...
@@ -245,7 +259,7 @@ fn visit_ty(&mut self, ty: &'tcx hir::Ty) {
// a trait ref, which introduces a binding scope.
match
path
.def
{
Def
::
Trait
(
..
)
=>
{
self
.with
(
LateScope
(
&
[],
self
.scope
)
,
|
_
,
this
|
{
self
.with
(
Scope
::
Late
{
lifetimes
:
&
[],
s
:
self
.scope
}
,
|
_
,
this
|
{
this
.visit_path
(
path
,
ty
.id
);
});
}
...
...
@@ -283,7 +297,7 @@ fn visit_lifetime(&mut self, lifetime_ref: &'tcx hir::Lifetime) {
return
;
}
if
lifetime_ref
.name
==
keywords
::
StaticLifetime
.name
()
{
self
.insert_lifetime
(
lifetime_ref
,
DefStaticRegion
);
self
.insert_lifetime
(
lifetime_ref
,
Region
::
Static
);
return
;
}
self
.resolve_lifetime_ref
(
lifetime_ref
);
...
...
@@ -304,8 +318,11 @@ fn visit_generics(&mut self, generics: &'tcx hir::Generics) {
..
})
=>
{
if
!
bound_lifetimes
.is_empty
()
{
self
.trait_ref_hack
=
true
;
let
result
=
self
.with
(
LateScope
(
bound_lifetimes
,
self
.scope
),
|
old_scope
,
this
|
{
let
late
=
Scope
::
Late
{
lifetimes
:
bound_lifetimes
,
s
:
self
.scope
};
let
result
=
self
.with
(
late
,
|
old_scope
,
this
|
{
this
.check_lifetime_defs
(
old_scope
,
bound_lifetimes
);
this
.visit_ty
(
&
bounded_ty
);
walk_list!
(
this
,
visit_ty_param_bound
,
bounds
);
...
...
@@ -346,7 +363,11 @@ fn visit_poly_trait_ref(&mut self,
span_err!
(
self
.sess
,
trait_ref
.span
,
E0316
,
"nested quantification of lifetimes"
);
}
self
.with
(
LateScope
(
&
trait_ref
.bound_lifetimes
,
self
.scope
),
|
old_scope
,
this
|
{
let
late
=
Scope
::
Late
{
lifetimes
:
&
trait_ref
.bound_lifetimes
,
s
:
self
.scope
};
self
.with
(
late
,
|
old_scope
,
this
|
{
this
.check_lifetime_defs
(
old_scope
,
&
trait_ref
.bound_lifetimes
);
for
lifetime
in
&
trait_ref
.bound_lifetimes
{
this
.visit_lifetime_def
(
lifetime
);
...
...
@@ -412,7 +433,7 @@ fn signal_shadowing_problem(sess: &Session, name: ast::Name, orig: Original, sha
fn
extract_labels
(
ctxt
:
&
mut
LifetimeContext
,
b
:
hir
::
BodyId
)
{
struct
GatherLabels
<
'a
>
{
sess
:
&
'a
Session
,
scope
:
Scope
<
'a
>
,
scope
:
Scope
Ref
<
'a
>
,
labels_in_fn
:
&
'a
mut
Vec
<
(
ast
::
Name
,
Span
)
>
,
}
...
...
@@ -471,16 +492,16 @@ fn expression_label(ex: &hir::Expr) -> Option<(ast::Name, Span)> {
}
fn
check_if_label_shadows_lifetime
<
'a
>
(
sess
:
&
'a
Session
,
mut
scope
:
Scope
<
'a
>
,
mut
scope
:
Scope
Ref
<
'a
>
,
label
:
ast
::
Name
,
label_span
:
Span
)
{
loop
{
match
*
scope
{
FnScope
{
s
,
..
}
=>
{
scope
=
s
;
}
RootScope
=>
{
return
;
}
Scope
::
Fn
{
s
,
..
}
=>
{
scope
=
s
;
}
Scope
::
Root
=>
{
return
;
}
EarlyScope
(
lifetimes
,
_
,
s
)
|
LateScope
(
lifetimes
,
s
)
=>
{
Scope
::
Early
{
lifetimes
,
s
,
..
}
|
Scope
::
Late
{
lifetimes
,
s
}
=>
{
for
lifetime_def
in
lifetimes
{
// FIXME (#24278): non-hygienic comparison
if
label
==
lifetime_def
.lifetime.name
{
...
...
@@ -524,7 +545,7 @@ fn add_scope_and_walk_fn(&mut self,
// `self.labels_in_fn`.
extract_labels
(
self
,
fb
);
self
.with
(
FnScope
{
fn_id
:
fn_id
,
body_id
:
fb
.node_id
,
s
:
self
.scope
},
self
.with
(
Scope
::
Fn
{
fn_id
:
fn_id
,
body_id
:
fb
.node_id
,
s
:
self
.scope
},
|
_
old_scope
,
this
|
this
.visit_nested_body
(
fb
))
}
...
...
@@ -535,8 +556,8 @@ fn hack<F>(&mut self, f: F) where
f
(
self
)
}
fn
with
<
F
>
(
&
mut
self
,
wrap_scope
:
Scope
Chain
,
f
:
F
)
where
F
:
for
<
'b
>
FnOnce
(
Scope
,
&
mut
LifetimeContext
<
'b
,
'tcx
>
),
fn
with
<
F
>
(
&
mut
self
,
wrap_scope
:
Scope
,
f
:
F
)
where
F
:
for
<
'b
>
FnOnce
(
Scope
Ref
,
&
mut
LifetimeContext
<
'b
,
'tcx
>
),
{
let
LifetimeContext
{
sess
,
hir_map
,
ref
mut
map
,
..
}
=
*
self
;
let
mut
this
=
LifetimeContext
{
...
...
@@ -591,7 +612,7 @@ fn visit_early_late<F>(&mut self,
// Find the start of nested early scopes, e.g. in methods.
let
mut
start
=
0
;
if
let
EarlyScope
(
..
)
=
*
self
.scope
{
if
let
Scope
::
Early
{
..
}
=
*
self
.scope
{
let
parent
=
self
.hir_map
.expect_item
(
self
.hir_map
.get_parent
(
fn_id
));
if
let
hir
::
ItemTrait
(
..
)
=
parent
.node
{
start
+=
1
;
// Self comes first.
...
...
@@ -605,8 +626,17 @@ fn visit_early_late<F>(&mut self,
}
}
self
.with
(
EarlyScope
(
&
early
,
start
as
u32
,
self
.scope
),
move
|
old_scope
,
this
|
{
this
.with
(
LateScope
(
&
late
,
this
.scope
),
move
|
_
,
this
|
{
let
early
=
Scope
::
Early
{
lifetimes
:
&
early
,
start
:
start
as
u32
,
s
:
self
.scope
};
self
.with
(
early
,
move
|
old_scope
,
this
|
{
let
late
=
Scope
::
Late
{
lifetimes
:
&
late
,
s
:
this
.scope
};
this
.with
(
late
,
move
|
_
,
this
|
{
this
.check_lifetime_defs
(
old_scope
,
&
generics
.lifetimes
);
this
.hack
(
walk
);
// FIXME(#37666) workaround in place of `walk(this)`
});
...
...
@@ -624,22 +654,22 @@ fn resolve_lifetime_ref(&mut self, lifetime_ref: &hir::Lifetime) {
let
mut
scope
=
self
.scope
;
loop
{
match
*
scope
{
FnScope
{
fn_id
,
body_id
,
s
}
=>
{
Scope
::
Fn
{
fn_id
,
body_id
,
s
}
=>
{
return
self
.resolve_free_lifetime_ref
(
region
::
CallSiteScopeData
{
fn_id
:
fn_id
,
body_id
:
body_id
},
lifetime_ref
,
s
);
}
RootScope
=>
{
Scope
::
Root
=>
{
break
;
}
EarlyScope
(
lifetimes
,
start
,
s
)
=>
{
Scope
::
Early
{
lifetimes
,
start
,
s
}
=>
{
match
search_lifetimes
(
lifetimes
,
lifetime_ref
)
{
Some
((
index
,
lifetime_def
))
=>
{
let
decl_id
=
lifetime_def
.id
;
let
def
=
DefEarlyBoundRegion
(
start
+
index
,
decl_id
);
let
def
=
Region
::
EarlyBound
(
start
+
index
,
decl_id
);
self
.insert_lifetime
(
lifetime_ref
,
def
);
return
;
}
...
...
@@ -649,12 +679,12 @@ fn resolve_lifetime_ref(&mut self, lifetime_ref: &hir::Lifetime) {
}
}
LateScope
(
lifetimes
,
s
)
=>
{
Scope
::
Late
{
lifetimes
,
s
}
=>
{
match
search_lifetimes
(
lifetimes
,
lifetime_ref
)
{
Some
((
_
index
,
lifetime_def
))
=>
{
let
decl_id
=
lifetime_def
.id
;
let
debruijn
=
ty
::
DebruijnIndex
::
new
(
late_depth
+
1
);
let
def
=
DefLateBoundRegion
(
debruijn
,
decl_id
);
let
def
=
Region
::
LateBound
(
debruijn
,
decl_id
);
self
.insert_lifetime
(
lifetime_ref
,
def
);
return
;
}
...
...
@@ -674,7 +704,7 @@ fn resolve_lifetime_ref(&mut self, lifetime_ref: &hir::Lifetime) {
fn
resolve_free_lifetime_ref
(
&
mut
self
,
scope_data
:
region
::
CallSiteScopeData
,
lifetime_ref
:
&
hir
::
Lifetime
,
scope
:
Scope
)
{
scope
:
Scope
Ref
)
{
debug!
(
"resolve_free_lifetime_ref
\
scope_data: {:?} lifetime_ref: {:?} scope: {:?}"
,
scope_data
,
lifetime_ref
,
scope
);
...
...
@@ -690,19 +720,19 @@ fn resolve_free_lifetime_ref(&mut self,
scope_data: {:?} scope: {:?} search_result: {:?}"
,
scope_data
,
scope
,
search_result
);
match
*
scope
{
FnScope
{
fn_id
,
body_id
,
s
}
=>
{
Scope
::
Fn
{
fn_id
,
body_id
,
s
}
=>
{
scope_data
=
region
::
CallSiteScopeData
{
fn_id
:
fn_id
,
body_id
:
body_id
};
scope
=
s
;
}
RootScope
=>
{
Scope
::
Root
=>
{
break
;
}
EarlyScope
(
lifetimes
,
_
,
s
)
|
LateScope
(
lifetimes
,
s
)
=>
{
Scope
::
Early
{
lifetimes
,
s
,
..
}
|
Scope
::
Late
{
lifetimes
,
s
}
=>
{
search_result
=
search_lifetimes
(
lifetimes
,
lifetime_ref
);
if
search_result
.is_some
()
{
break
;
...
...
@@ -714,7 +744,7 @@ fn resolve_free_lifetime_ref(&mut self,
match
search_result
{
Some
((
_
depth
,
lifetime
))
=>
{
let
def
=
DefFreeRegion
(
scope_data
,
lifetime
.id
);
let
def
=
Region
::
Free
(
scope_data
,
lifetime
.id
);
self
.insert_lifetime
(
lifetime_ref
,
def
);
}
...
...
@@ -732,7 +762,7 @@ fn unresolved_lifetime_ref(&self, lifetime_ref: &hir::Lifetime) {
.emit
();
}
fn
check_lifetime_defs
(
&
mut
self
,
old_scope
:
Scope
,
lifetimes
:
&
[
hir
::
LifetimeDef
])
{
fn
check_lifetime_defs
(
&
mut
self
,
old_scope
:
Scope
Ref
,
lifetimes
:
&
[
hir
::
LifetimeDef
])
{
for
i
in
0
..
lifetimes
.len
()
{
let
lifetime_i
=
&
lifetimes
[
i
];
...
...
@@ -773,7 +803,7 @@ fn check_lifetime_defs(&mut self, old_scope: Scope, lifetimes: &[hir::LifetimeDe
}
fn
check_lifetime_def_for_shadowing
(
&
self
,
mut
old_scope
:
Scope
,
mut
old_scope
:
Scope
Ref
,
lifetime
:
&
hir
::
Lifetime
)
{
for
&
(
label
,
label_span
)
in
&
self
.labels_in_fn
{
...
...
@@ -789,16 +819,16 @@ fn check_lifetime_def_for_shadowing(&self,
loop
{
match
*
old_scope
{
FnScope
{
s
,
..
}
=>
{
Scope
::
Fn
{
s
,
..
}
=>
{
old_scope
=
s
;
}
RootScope
=>
{
Scope
::
Root
=>
{
return
;
}
EarlyScope
(
lifetimes
,
_
,
s
)
|
LateScope
(
lifetimes
,
s
)
=>
{
Scope
::
Early
{
lifetimes
,
s
,
..
}
|
Scope
::
Late
{
lifetimes
,
s
}
=>
{
if
let
Some
((
_
,
lifetime_def
))
=
search_lifetimes
(
lifetimes
,
lifetime
)
{
signal_shadowing_problem
(
self
.sess
,
...
...
@@ -816,7 +846,7 @@ fn check_lifetime_def_for_shadowing(&self,
fn
insert_lifetime
(
&
mut
self
,
lifetime_ref
:
&
hir
::
Lifetime
,
def
:
Def
Region
)
{
def
:
Region
)
{
if
lifetime_ref
.id
==
ast
::
DUMMY_NODE_ID
{
span_bug!
(
lifetime_ref
.span
,
"lifetime reference not renumbered,
\
...
...
src/librustc_typeck/astconv.rs
浏览文件 @
0682a75f
...
...
@@ -247,11 +247,11 @@ fn try_opt_ast_region_to_region(&self,
let
name
=
opt_lifetime
.map
(|
l
|
l
.name
);
let
resolved
=
opt_lifetime
.and_then
(|
l
|
tcx
.named_region_map.defs
.get
(
&
l
.id
));
let
r
=
tcx
.mk_region
(
match
resolved
{
Some
(
&
rl
::
DefStaticRegion
)
=>
{
Some
(
&
rl
::
Region
::
Static
)
=>
{
ty
::
ReStatic
}
Some
(
&
rl
::
DefLateBoundRegion
(
debruijn
,
id
))
=>
{
Some
(
&
rl
::
Region
::
LateBound
(
debruijn
,
id
))
=>
{
// If this region is declared on a function, it will have
// an entry in `late_bound`, but if it comes from
// `for<'a>` in some type or something, it won't
...
...
@@ -268,15 +268,15 @@ fn try_opt_ast_region_to_region(&self,
issue_32330
))
}
Some
(
&
rl
::
DefEarlyBoundRegion
(
index
,
_
))
=>
{
Some
(
&
rl
::
Region
::
EarlyBound
(
index
,
_
))
=>
{
ty
::
ReEarlyBound
(
ty
::
EarlyBoundRegion
{
index
:
index
,
name
:
name
.unwrap
()
})
}
Some
(
&
rl
::
DefFreeRegion
(
scope
,
id
))
=>
{
// As in
DefLateBoundRegion
above, could be missing for some late-bound
Some
(
&
rl
::
Region
::
Free
(
scope
,
id
))
=>
{
// As in
Region::LateBound
above, could be missing for some late-bound
// regions, but also for early-bound regions.
let
issue_32330
=
tcx
.named_region_map
.late_bound
...
...
src/librustc_typeck/variance/constraints.rs
浏览文件 @
0682a75f
...
...
@@ -154,7 +154,7 @@ fn find_binding_for_lifetime(&self, param_id: ast::NodeId) -> ast::NodeId {
let
tcx
=
self
.terms_cx.tcx
;
assert
!
(
is_lifetime
(
&
tcx
.hir
,
param_id
));
match
tcx
.named_region_map.defs
.get
(
&
param_id
)
{
Some
(
&
rl
::
DefEarlyBoundRegion
(
_
,
lifetime_decl_id
))
=>
lifetime_decl_id
,
Some
(
&
rl
::
Region
::
EarlyBound
(
_
,
lifetime_decl_id
))
=>
lifetime_decl_id
,
Some
(
_
)
=>
bug!
(
"should not encounter non early-bound cases"
),
// The lookup should only fail when `param_id` is
...
...
src/librustdoc/clean/mod.rs
浏览文件 @
0682a75f
...
...
@@ -28,7 +28,7 @@
use
syntax_pos
::{
self
,
DUMMY_SP
,
Pos
};
use
rustc
::
middle
::
privacy
::
AccessLevels
;
use
rustc
::
middle
::
resolve_lifetime
::
DefRegion
::
*
;
use
rustc
::
middle
::
resolve_lifetime
as
rl
;
use
rustc
::
middle
::
lang_items
;
use
rustc
::
hir
::
def
::{
Def
,
CtorKind
};
use
rustc
::
hir
::
def_id
::{
CrateNum
,
DefId
,
CRATE_DEF_INDEX
,
LOCAL_CRATE
};
...
...
@@ -765,9 +765,9 @@ impl Clean<Lifetime> for hir::Lifetime {
fn
clean
(
&
self
,
cx
:
&
DocContext
)
->
Lifetime
{
let
def
=
cx
.tcx.named_region_map.defs
.get
(
&
self
.id
)
.cloned
();
match
def
{
Some
(
DefEarlyBoundRegion
(
_
,
node_id
))
|
Some
(
DefLateBoundRegion
(
_
,
node_id
))
|
Some
(
DefFreeRegion
(
_
,
node_id
))
=>
{
Some
(
rl
::
Region
::
EarlyBound
(
_
,
node_id
))
|
Some
(
rl
::
Region
::
LateBound
(
_
,
node_id
))
|
Some
(
rl
::
Region
::
Free
(
_
,
node_id
))
=>
{
if
let
Some
(
lt
)
=
cx
.lt_substs
.borrow
()
.get
(
&
node_id
)
.cloned
()
{
return
lt
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录