Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
7362bd57
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,发现更多精彩内容 >>
提交
7362bd57
编写于
2月 11, 2015
作者:
A
Alex Crichton
浏览文件
操作
浏览文件
下载
差异文件
rollup merge of #22167: kmcallister/undef-macro
Fixes #21062.
上级
48767165
d4288717
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
80 addition
and
26 deletion
+80
-26
src/librustc/plugin/load.rs
src/librustc/plugin/load.rs
+41
-26
src/test/compile-fail/macro-reexport-undef.rs
src/test/compile-fail/macro-reexport-undef.rs
+20
-0
src/test/compile-fail/macro-use-undef.rs
src/test/compile-fail/macro-use-undef.rs
+19
-0
未找到文件。
src/librustc/plugin/load.rs
浏览文件 @
7362bd57
...
...
@@ -17,7 +17,7 @@
use
std
::
mem
;
use
std
::
env
;
use
std
::
dynamic_lib
::
DynamicLibrary
;
use
std
::
collections
::
HashSet
;
use
std
::
collections
::
{
HashSet
,
HashMap
}
;
use
std
::
borrow
::
ToOwned
;
use
syntax
::
ast
;
use
syntax
::
attr
;
...
...
@@ -116,6 +116,8 @@ pub fn load_plugins(sess: &Session, krate: &ast::Crate,
return
loader
.plugins
;
}
pub
type
MacroSelection
=
HashMap
<
token
::
InternedString
,
Span
>
;
// note that macros aren't expanded yet, and therefore macros can't add plugins.
impl
<
'a
,
'v
>
Visitor
<
'v
>
for
PluginLoader
<
'a
>
{
fn
visit_item
(
&
mut
self
,
item
:
&
ast
::
Item
)
{
...
...
@@ -128,9 +130,9 @@ fn visit_item(&mut self, item: &ast::Item) {
}
}
// Parse the attributes relating to macro
/ plugin
loading.
let
mut
macro_selection
=
Some
(
HashSet
::
new
());
// None => load all
let
mut
reexport
=
Hash
Set
::
new
();
// Parse the attributes relating to macro loading.
let
mut
import
=
Some
(
HashMap
::
new
());
// None => load all
let
mut
reexport
=
Hash
Map
::
new
();
for
attr
in
&
item
.attrs
{
let
mut
used
=
true
;
match
&
attr
.name
()[]
{
...
...
@@ -147,14 +149,14 @@ fn visit_item(&mut self, item: &ast::Item) {
let
names
=
attr
.meta_item_list
();
if
names
.is_none
()
{
// no names => load all
macro_selection
=
None
;
import
=
None
;
}
if
let
(
Some
(
sel
),
Some
(
names
))
=
(
macro_selection
.as_mut
(),
names
)
{
for
name
in
names
{
if
let
ast
::
MetaWord
(
ref
name
)
=
name
.node
{
sel
.insert
(
name
.clone
());
if
let
(
Some
(
sel
),
Some
(
names
))
=
(
import
.as_mut
(),
names
)
{
for
attr
in
names
{
if
let
ast
::
MetaWord
(
ref
name
)
=
attr
.node
{
sel
.insert
(
name
.clone
()
,
attr
.span
);
}
else
{
self
.sess
.span_err
(
name
.span
,
"bad macro import"
);
self
.sess
.span_err
(
attr
.span
,
"bad macro import"
);
}
}
}
...
...
@@ -168,11 +170,11 @@ fn visit_item(&mut self, item: &ast::Item) {
}
};
for
name
in
names
{
if
let
ast
::
MetaWord
(
ref
name
)
=
name
.node
{
reexport
.insert
(
name
.clone
());
for
attr
in
names
{
if
let
ast
::
MetaWord
(
ref
name
)
=
attr
.node
{
reexport
.insert
(
name
.clone
()
,
attr
.span
);
}
else
{
self
.sess
.span_err
(
name
.span
,
"bad macro reexport"
);
self
.sess
.span_err
(
attr
.span
,
"bad macro reexport"
);
}
}
}
...
...
@@ -183,7 +185,7 @@ fn visit_item(&mut self, item: &ast::Item) {
}
}
self
.load_macros
(
item
,
macro_selection
,
Some
(
reexport
)
)
self
.load_macros
(
item
,
import
,
reexport
)
}
fn
visit_mac
(
&
mut
self
,
_
:
&
ast
::
Mac
)
{
...
...
@@ -195,10 +197,10 @@ fn visit_mac(&mut self, _: &ast::Mac) {
impl
<
'a
>
PluginLoader
<
'a
>
{
pub
fn
load_macros
<
'b
>
(
&
mut
self
,
vi
:
&
ast
::
Item
,
macro_selection
:
Option
<
HashSet
<
token
::
InternedString
>
>
,
reexport
:
Option
<
HashSet
<
token
::
InternedString
>>
)
{
if
let
(
Some
(
sel
),
Some
(
re
))
=
(
macro_selection
.as_ref
(),
reexport
.as_ref
()
)
{
if
sel
.is_empty
()
&&
re
.is_empty
()
{
import
:
Option
<
MacroSelection
>
,
reexport
:
MacroSelection
)
{
if
let
Some
(
sel
)
=
import
.as_ref
(
)
{
if
sel
.is_empty
()
&&
re
export
.is_empty
()
{
return
;
}
}
...
...
@@ -211,19 +213,32 @@ pub fn load_macros<'b>(&mut self,
let
pmd
=
self
.reader
.read_plugin_metadata
(
CrateOrString
::
Krate
(
vi
));
let
mut
seen
=
HashSet
::
new
();
for
mut
def
in
pmd
.exported_macros
()
{
let
name
=
token
::
get_ident
(
def
.ident
);
def
.use_locally
=
match
macro_selection
.as_ref
()
{
seen
.insert
(
name
.clone
());
def
.use_locally
=
match
import
.as_ref
()
{
None
=>
true
,
Some
(
sel
)
=>
sel
.contains
(
&
name
),
};
def
.export
=
if
let
Some
(
ref
re
)
=
reexport
{
re
.contains
(
&
name
)
}
else
{
false
// Don't reexport macros from crates loaded from the command line
Some
(
sel
)
=>
sel
.contains_key
(
&
name
),
};
def
.export
=
reexport
.contains_key
(
&
name
);
self
.plugins.macros
.push
(
def
);
}
if
let
Some
(
sel
)
=
import
.as_ref
()
{
for
(
name
,
span
)
in
sel
.iter
()
{
if
!
seen
.contains
(
name
)
{
self
.sess
.span_err
(
*
span
,
"imported macro not found"
);
}
}
}
for
(
name
,
span
)
in
reexport
.iter
()
{
if
!
seen
.contains
(
name
)
{
self
.sess
.span_err
(
*
span
,
"reexported macro not found"
);
}
}
}
pub
fn
load_plugin
<
'b
>
(
&
mut
self
,
...
...
src/test/compile-fail/macro-reexport-undef.rs
0 → 100644
浏览文件 @
7362bd57
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:two_macros.rs
// ignore-stage1
#[macro_use(macro_two)]
#[macro_reexport(no_way)]
//~ ERROR reexported macro not found
extern
crate
two_macros
;
pub
fn
main
()
{
macro_two!
();
}
src/test/compile-fail/macro-use-undef.rs
0 → 100644
浏览文件 @
7362bd57
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:two_macros.rs
// ignore-stage1
#[macro_use(macro_two,
no_way)]
//~ ERROR imported macro not found
extern
crate
two_macros
;
pub
fn
main
()
{
macro_two!
();
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录