Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
076c5d44
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,发现更多精彩内容 >>
提交
076c5d44
编写于
10月 31, 2016
作者:
J
Jeffrey Seyfried
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix shadowing checking.
上级
6c4b5514
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
21 addition
and
8 deletion
+21
-8
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+8
-2
src/librustc_resolve/macros.rs
src/librustc_resolve/macros.rs
+13
-6
未找到文件。
src/librustc_resolve/lib.rs
浏览文件 @
076c5d44
...
...
@@ -77,7 +77,7 @@
use
std
::
rc
::
Rc
;
use
resolve_imports
::{
ImportDirective
,
NameResolution
};
use
macros
::{
InvocationData
,
LegacyBinding
};
use
macros
::{
InvocationData
,
LegacyBinding
,
LegacyScope
};
// NB: This module needs to be declared first so diagnostics are
// registered before they are used.
...
...
@@ -1077,6 +1077,7 @@ pub struct Resolver<'a> {
crate_loader
:
&
'a
mut
CrateLoader
,
macro_names
:
FnvHashSet
<
Name
>
,
builtin_macros
:
FnvHashMap
<
Name
,
Rc
<
SyntaxExtension
>>
,
lexical_macro_resolutions
:
Vec
<
(
Name
,
LegacyScope
<
'a
>
)
>
,
// Maps the `Mark` of an expansion to its containing module or block.
invocations
:
FnvHashMap
<
Mark
,
&
'a
InvocationData
<
'a
>>
,
...
...
@@ -1267,6 +1268,7 @@ pub fn new(session: &'a Session,
crate_loader
:
crate_loader
,
macro_names
:
FnvHashSet
(),
builtin_macros
:
FnvHashMap
(),
lexical_macro_resolutions
:
Vec
::
new
(),
invocations
:
invocations
,
}
}
...
...
@@ -3363,9 +3365,13 @@ fn report_errors(&mut self) {
}
fn
report_shadowing_errors
(
&
mut
self
)
{
for
(
name
,
scope
)
in
replace
(
&
mut
self
.lexical_macro_resolutions
,
Vec
::
new
())
{
self
.resolve_macro_name
(
scope
,
name
);
}
let
mut
reported_errors
=
FnvHashSet
();
for
binding
in
replace
(
&
mut
self
.disallowed_shadowing
,
Vec
::
new
())
{
if
self
.resolve_macro_name
(
binding
.parent
,
binding
.name
,
false
)
.is_some
()
&&
if
self
.resolve_macro_name
(
binding
.parent
,
binding
.name
)
.is_some
()
&&
reported_errors
.insert
((
binding
.name
,
binding
.span
))
{
let
msg
=
format!
(
"`{}` is already in scope"
,
binding
.name
);
self
.session
.struct_span_err
(
binding
.span
,
&
msg
)
...
...
src/librustc_resolve/macros.rs
浏览文件 @
076c5d44
...
...
@@ -174,7 +174,7 @@ fn resolve_macro(&mut self, scope: Mark, path: &ast::Path, force: bool)
if
let
LegacyScope
::
Expansion
(
parent
)
=
invocation
.legacy_scope
.get
()
{
invocation
.legacy_scope
.set
(
LegacyScope
::
simplify_expansion
(
parent
));
}
self
.resolve_macro_name
(
invocation
.legacy_scope
.get
(),
name
,
true
)
.ok_or_else
(||
{
self
.resolve_macro_name
(
invocation
.legacy_scope
.get
(),
name
)
.ok_or_else
(||
{
if
force
{
let
msg
=
format!
(
"macro undefined: '{}!'"
,
name
);
let
mut
err
=
self
.session
.struct_span_err
(
path
.span
,
&
msg
);
...
...
@@ -189,17 +189,18 @@ fn resolve_macro(&mut self, scope: Mark, path: &ast::Path, force: bool)
}
impl
<
'a
>
Resolver
<
'a
>
{
pub
fn
resolve_macro_name
(
&
mut
self
,
mut
scope
:
LegacyScope
<
'a
>
,
name
:
ast
::
Name
,
record_used
:
bool
)
pub
fn
resolve_macro_name
(
&
mut
self
,
mut
scope
:
LegacyScope
<
'a
>
,
name
:
ast
::
Name
)
->
Option
<
Rc
<
SyntaxExtension
>>
{
let
mut
possible_time_travel
=
None
;
let
mut
relative_depth
:
u32
=
0
;
loop
{
scope
=
match
scope
{
LegacyScope
::
Empty
=>
break
,
LegacyScope
::
Expansion
(
invocation
)
=>
{
if
let
LegacyScope
::
Empty
=
invocation
.expansion
.get
()
{
if
possible_time_travel
.is_none
()
{
possible_time_travel
=
Some
(
scope
);
}
invocation
.legacy_scope
.get
()
}
else
{
relative_depth
+=
1
;
...
...
@@ -212,7 +213,10 @@ pub fn resolve_macro_name(&mut self,
}
LegacyScope
::
Binding
(
binding
)
=>
{
if
binding
.name
==
name
{
if
record_used
&&
relative_depth
>
0
{
if
let
Some
(
scope
)
=
possible_time_travel
{
// Check for disallowed shadowing later
self
.lexical_macro_resolutions
.push
((
name
,
scope
));
}
else
if
relative_depth
>
0
{
self
.disallowed_shadowing
.push
(
binding
);
}
return
Some
(
binding
.ext
.clone
());
...
...
@@ -222,6 +226,9 @@ pub fn resolve_macro_name(&mut self,
};
}
if
let
Some
(
scope
)
=
possible_time_travel
{
self
.lexical_macro_resolutions
.push
((
name
,
scope
));
}
self
.builtin_macros
.get
(
&
name
)
.cloned
()
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录