Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
d347270e
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,发现更多精彩内容 >>
提交
d347270e
编写于
6月 11, 2018
作者:
V
Vadim Petrochenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement `#[macro_export(local_inner_macros)]`
上级
971f7d34
变更
19
隐藏空白更改
内联
并排
Showing
19 changed file
with
134 addition
and
2 deletion
+134
-2
src/librustc/hir/lowering.rs
src/librustc/hir/lowering.rs
+1
-0
src/librustc/ich/impls_syntax.rs
src/librustc/ich/impls_syntax.rs
+1
-0
src/librustc_allocator/expand.rs
src/librustc_allocator/expand.rs
+1
-0
src/librustc_plugin/registry.rs
src/librustc_plugin/registry.rs
+3
-0
src/librustc_resolve/macros.rs
src/librustc_resolve/macros.rs
+8
-1
src/libsyntax/ext/base.rs
src/libsyntax/ext/base.rs
+3
-0
src/libsyntax/ext/derive.rs
src/libsyntax/ext/derive.rs
+1
-0
src/libsyntax/ext/expand.rs
src/libsyntax/ext/expand.rs
+9
-1
src/libsyntax/ext/tt/macro_rules.rs
src/libsyntax/ext/tt/macro_rules.rs
+7
-0
src/libsyntax/std_inject.rs
src/libsyntax/std_inject.rs
+1
-0
src/libsyntax/test.rs
src/libsyntax/test.rs
+1
-0
src/libsyntax_ext/lib.rs
src/libsyntax_ext/lib.rs
+2
-0
src/libsyntax_ext/proc_macro_registrar.rs
src/libsyntax_ext/proc_macro_registrar.rs
+1
-0
src/libsyntax_pos/hygiene.rs
src/libsyntax_pos/hygiene.rs
+3
-0
src/test/run-pass-fulldeps/auxiliary/plugin_args.rs
src/test/run-pass-fulldeps/auxiliary/plugin_args.rs
+1
-0
src/test/ui/hygiene/auxiliary/local_inner_macros.rs
src/test/ui/hygiene/auxiliary/local_inner_macros.rs
+29
-0
src/test/ui/hygiene/local_inner_macros.rs
src/test/ui/hygiene/local_inner_macros.rs
+31
-0
src/test/ui/hygiene/local_inner_macros_disabled.rs
src/test/ui/hygiene/local_inner_macros_disabled.rs
+21
-0
src/test/ui/hygiene/local_inner_macros_disabled.stderr
src/test/ui/hygiene/local_inner_macros_disabled.stderr
+10
-0
未找到文件。
src/librustc/hir/lowering.rs
浏览文件 @
d347270e
...
...
@@ -616,6 +616,7 @@ fn allow_internal_unstable(&self, reason: CompilerDesugaringKind, span: Span) ->
format
:
codemap
::
CompilerDesugaring
(
reason
),
allow_internal_unstable
:
true
,
allow_internal_unsafe
:
false
,
local_inner_macros
:
false
,
edition
:
codemap
::
hygiene
::
default_edition
(),
});
span
.with_ctxt
(
SyntaxContext
::
empty
()
.apply_mark
(
mark
))
...
...
src/librustc/ich/impls_syntax.rs
浏览文件 @
d347270e
...
...
@@ -395,6 +395,7 @@ fn hash_token<'a, 'gcx, W: StableHasherResult>(
format
,
allow_internal_unstable
,
allow_internal_unsafe
,
local_inner_macros
,
edition
});
...
...
src/librustc_allocator/expand.rs
浏览文件 @
d347270e
...
...
@@ -103,6 +103,7 @@ fn fold_item(&mut self, item: P<Item>) -> SmallVector<P<Item>> {
format
:
MacroAttribute
(
Symbol
::
intern
(
name
)),
allow_internal_unstable
:
true
,
allow_internal_unsafe
:
false
,
local_inner_macros
:
false
,
edition
:
hygiene
::
default_edition
(),
});
...
...
src/librustc_plugin/registry.rs
浏览文件 @
d347270e
...
...
@@ -108,6 +108,7 @@ pub fn register_syntax_extension(&mut self, name: ast::Name, extension: SyntaxEx
def_info
:
_
,
allow_internal_unstable
,
allow_internal_unsafe
,
local_inner_macros
,
unstable_feature
,
edition
,
}
=>
{
...
...
@@ -117,6 +118,7 @@ pub fn register_syntax_extension(&mut self, name: ast::Name, extension: SyntaxEx
def_info
:
Some
((
nid
,
self
.krate_span
)),
allow_internal_unstable
,
allow_internal_unsafe
,
local_inner_macros
,
unstable_feature
,
edition
,
}
...
...
@@ -152,6 +154,7 @@ pub fn register_macro(&mut self, name: &str, expander: MacroExpanderFn) {
def_info
:
None
,
allow_internal_unstable
:
false
,
allow_internal_unsafe
:
false
,
local_inner_macros
:
false
,
unstable_feature
:
None
,
edition
:
hygiene
::
default_edition
(),
});
...
...
src/librustc_resolve/macros.rs
浏览文件 @
d347270e
...
...
@@ -451,11 +451,18 @@ pub fn resolve_macro_to_def_inner(&mut self, scope: Mark, path: &ast::Path,
kind
:
MacroKind
,
force
:
bool
)
->
Result
<
Def
,
Determinacy
>
{
let
ast
::
Path
{
ref
segments
,
span
}
=
*
path
;
let
path
:
Vec
<
_
>
=
segments
.iter
()
.map
(|
seg
|
seg
.ident
)
.collect
();
let
mut
path
:
Vec
<
_
>
=
segments
.iter
()
.map
(|
seg
|
seg
.ident
)
.collect
();
let
invocation
=
self
.invocations
[
&
scope
];
let
module
=
invocation
.module
.get
();
self
.current_module
=
if
module
.is_trait
()
{
module
.parent
.unwrap
()
}
else
{
module
};
// Possibly apply the macro helper hack
if
self
.use_extern_macros
&&
kind
==
MacroKind
::
Bang
&&
path
.len
()
==
1
&&
path
[
0
]
.span
.ctxt
()
.outer
()
.expn_info
()
.map_or
(
false
,
|
info
|
info
.local_inner_macros
)
{
let
root
=
Ident
::
new
(
keywords
::
DollarCrate
.name
(),
path
[
0
]
.span
);
path
.insert
(
0
,
root
);
}
if
path
.len
()
>
1
{
if
!
self
.use_extern_macros
&&
self
.gated_errors
.insert
(
span
)
{
let
msg
=
"non-ident macro paths are experimental"
;
...
...
src/libsyntax/ext/base.rs
浏览文件 @
d347270e
...
...
@@ -621,6 +621,9 @@ pub enum SyntaxExtension {
/// Whether the contents of the macro can use `unsafe`
/// without triggering the `unsafe_code` lint.
allow_internal_unsafe
:
bool
,
/// Enables the macro helper hack (`ident!(...)` -> `$crate::ident!(...)`)
/// for a given macro.
local_inner_macros
:
bool
,
/// The macro's feature name if it is unstable, and the stability feature
unstable_feature
:
Option
<
(
Symbol
,
u32
)
>
,
/// Edition of the crate in which the macro is defined
...
...
src/libsyntax/ext/derive.rs
浏览文件 @
d347270e
...
...
@@ -64,6 +64,7 @@ pub fn add_derived_markers<T>(cx: &mut ExtCtxt, span: Span, traits: &[ast::Path]
format
:
ExpnFormat
::
MacroAttribute
(
Symbol
::
intern
(
&
pretty_name
)),
allow_internal_unstable
:
true
,
allow_internal_unsafe
:
false
,
local_inner_macros
:
false
,
edition
:
hygiene
::
default_edition
(),
});
...
...
src/libsyntax/ext/expand.rs
浏览文件 @
d347270e
...
...
@@ -542,6 +542,7 @@ fn expand_attr_invoc(&mut self,
format
:
MacroAttribute
(
Symbol
::
intern
(
&
format!
(
"{}"
,
attr
.path
))),
allow_internal_unstable
:
false
,
allow_internal_unsafe
:
false
,
local_inner_macros
:
false
,
edition
:
ext
.edition
(),
});
...
...
@@ -695,6 +696,7 @@ fn expand_bang_invoc(&mut self,
def_site_span
:
Option
<
Span
>
,
allow_internal_unstable
,
allow_internal_unsafe
,
local_inner_macros
,
// can't infer this type
unstable_feature
:
Option
<
(
Symbol
,
u32
)
>
,
edition
|
{
...
...
@@ -729,6 +731,7 @@ fn expand_bang_invoc(&mut self,
format
:
macro_bang_format
(
path
),
allow_internal_unstable
,
allow_internal_unsafe
,
local_inner_macros
,
edition
,
});
Ok
(())
...
...
@@ -737,7 +740,7 @@ fn expand_bang_invoc(&mut self,
let
opt_expanded
=
match
*
ext
{
DeclMacro
(
ref
expand
,
def_span
,
edition
)
=>
{
if
let
Err
(
dummy_span
)
=
validate_and_set_expn_info
(
self
,
def_span
.map
(|(
_
,
s
)|
s
),
false
,
false
,
None
,
false
,
false
,
false
,
None
,
edition
)
{
dummy_span
}
else
{
...
...
@@ -750,12 +753,14 @@ fn expand_bang_invoc(&mut self,
def_info
,
allow_internal_unstable
,
allow_internal_unsafe
,
local_inner_macros
,
unstable_feature
,
edition
,
}
=>
{
if
let
Err
(
dummy_span
)
=
validate_and_set_expn_info
(
self
,
def_info
.map
(|(
_
,
s
)|
s
),
allow_internal_unstable
,
allow_internal_unsafe
,
local_inner_macros
,
unstable_feature
,
edition
)
{
dummy_span
...
...
@@ -777,6 +782,7 @@ fn expand_bang_invoc(&mut self,
format
:
macro_bang_format
(
path
),
allow_internal_unstable
,
allow_internal_unsafe
:
false
,
local_inner_macros
:
false
,
edition
:
hygiene
::
default_edition
(),
});
...
...
@@ -816,6 +822,7 @@ fn expand_bang_invoc(&mut self,
// FIXME probably want to follow macro_rules macros here.
allow_internal_unstable
,
allow_internal_unsafe
:
false
,
local_inner_macros
:
false
,
edition
,
});
...
...
@@ -890,6 +897,7 @@ fn expand_derive_invoc(&mut self,
format
:
MacroAttribute
(
pretty_name
),
allow_internal_unstable
:
false
,
allow_internal_unsafe
:
false
,
local_inner_macros
:
false
,
edition
:
ext
.edition
(),
};
...
...
src/libsyntax/ext/tt/macro_rules.rs
浏览文件 @
d347270e
...
...
@@ -286,6 +286,12 @@ pub fn compile(sess: &ParseSess, features: &Features, def: &ast::Item, edition:
if
body
.legacy
{
let
allow_internal_unstable
=
attr
::
contains_name
(
&
def
.attrs
,
"allow_internal_unstable"
);
let
allow_internal_unsafe
=
attr
::
contains_name
(
&
def
.attrs
,
"allow_internal_unsafe"
);
let
mut
local_inner_macros
=
false
;
if
let
Some
(
macro_export
)
=
attr
::
find_by_name
(
&
def
.attrs
,
"macro_export"
)
{
if
let
Some
(
l
)
=
macro_export
.meta_item_list
()
{
local_inner_macros
=
attr
::
list_contains_name
(
&
l
,
"local_inner_macros"
);
}
}
let
unstable_feature
=
attr
::
find_stability
(
&
sess
.span_diagnostic
,
&
def
.attrs
,
def
.span
)
.and_then
(|
stability
|
{
...
...
@@ -301,6 +307,7 @@ pub fn compile(sess: &ParseSess, features: &Features, def: &ast::Item, edition:
def_info
:
Some
((
def
.id
,
def
.span
)),
allow_internal_unstable
,
allow_internal_unsafe
,
local_inner_macros
,
unstable_feature
,
edition
,
}
...
...
src/libsyntax/std_inject.rs
浏览文件 @
d347270e
...
...
@@ -29,6 +29,7 @@ fn ignored_span(sp: Span) -> Span {
format
:
MacroAttribute
(
Symbol
::
intern
(
"std_inject"
)),
allow_internal_unstable
:
true
,
allow_internal_unsafe
:
false
,
local_inner_macros
:
false
,
edition
:
hygiene
::
default_edition
(),
});
sp
.with_ctxt
(
SyntaxContext
::
empty
()
.apply_mark
(
mark
))
...
...
src/libsyntax/test.rs
浏览文件 @
d347270e
...
...
@@ -311,6 +311,7 @@ fn generate_test_harness(sess: &ParseSess,
format
:
MacroAttribute
(
Symbol
::
intern
(
"test"
)),
allow_internal_unstable
:
true
,
allow_internal_unsafe
:
false
,
local_inner_macros
:
false
,
edition
:
hygiene
::
default_edition
(),
});
...
...
src/libsyntax_ext/lib.rs
浏览文件 @
d347270e
...
...
@@ -76,6 +76,7 @@ pub fn register_builtins(resolver: &mut syntax::ext::base::Resolver,
def_info
:
None
,
allow_internal_unstable
:
false
,
allow_internal_unsafe
:
false
,
local_inner_macros
:
false
,
unstable_feature
:
None
,
edition
:
hygiene
::
default_edition
(),
});
...
...
@@ -132,6 +133,7 @@ pub fn register_builtins(resolver: &mut syntax::ext::base::Resolver,
def_info
:
None
,
allow_internal_unstable
:
true
,
allow_internal_unsafe
:
false
,
local_inner_macros
:
false
,
unstable_feature
:
None
,
edition
:
hygiene
::
default_edition
(),
});
...
...
src/libsyntax_ext/proc_macro_registrar.rs
浏览文件 @
d347270e
...
...
@@ -368,6 +368,7 @@ fn mk_registrar(cx: &mut ExtCtxt,
format
:
MacroAttribute
(
Symbol
::
intern
(
"proc_macro"
)),
allow_internal_unstable
:
true
,
allow_internal_unsafe
:
false
,
local_inner_macros
:
false
,
edition
:
hygiene
::
default_edition
(),
});
let
span
=
DUMMY_SP
.apply_mark
(
mark
);
...
...
src/libsyntax_pos/hygiene.rs
浏览文件 @
d347270e
...
...
@@ -496,6 +496,9 @@ pub struct ExpnInfo {
/// Whether the macro is allowed to use `unsafe` internally
/// even if the user crate has `#![forbid(unsafe_code)]`.
pub
allow_internal_unsafe
:
bool
,
/// Enables the macro helper hack (`ident!(...)` -> `$crate::ident!(...)`)
/// for a given macro.
pub
local_inner_macros
:
bool
,
/// Edition of the crate in which the macro is defined.
pub
edition
:
Edition
,
}
...
...
src/test/run-pass-fulldeps/auxiliary/plugin_args.rs
浏览文件 @
d347270e
...
...
@@ -54,6 +54,7 @@ pub fn plugin_registrar(reg: &mut Registry) {
def_info
:
None
,
allow_internal_unstable
:
false
,
allow_internal_unsafe
:
false
,
local_inner_macros
:
false
,
unstable_feature
:
None
,
edition
:
hygiene
::
default_edition
(),
});
...
...
src/test/ui/hygiene/auxiliary/local_inner_macros.rs
0 → 100644
浏览文件 @
d347270e
// Copyright 2018 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.
#[macro_export]
macro_rules!
helper1
{
()
=>
(
struct
S
;
)
}
#[macro_export(local_inner_macros)]
macro_rules!
helper2
{
()
=>
(
helper1!
();
)
}
#[macro_export(local_inner_macros)]
macro_rules!
public_macro
{
()
=>
(
helper2!
();
)
}
#[macro_export(local_inner_macros)]
macro_rules!
public_macro_dynamic
{
(
$helper
:
ident
)
=>
(
$helper
!
();
)
}
src/test/ui/hygiene/local_inner_macros.rs
0 → 100644
浏览文件 @
d347270e
// Copyright 2018 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.
// compile-pass
// aux-build:local_inner_macros.rs
#![feature(use_extern_macros)]
extern
crate
local_inner_macros
;
use
local_inner_macros
::{
public_macro
,
public_macro_dynamic
};
public_macro!
();
macro_rules!
local_helper
{
()
=>
(
struct
Z
;
)
}
public_macro_dynamic!
(
local_helper
);
fn
main
()
{
let
s
=
S
;
let
z
=
Z
;
}
src/test/ui/hygiene/local_inner_macros_disabled.rs
0 → 100644
浏览文件 @
d347270e
// Copyright 2018 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.
// `local_inner_macros` has no effect if `feature(use_extern_macros)` is not enabled
// aux-build:local_inner_macros.rs
// error-pattern: cannot find macro `helper2!` in this scope
#[macro_use(public_macro)]
extern
crate
local_inner_macros
;
public_macro!
();
fn
main
()
{}
src/test/ui/hygiene/local_inner_macros_disabled.stderr
0 → 100644
浏览文件 @
d347270e
error: cannot find macro `helper2!` in this scope
--> $DIR/local_inner_macros_disabled.rs:19:1
|
LL | public_macro!();
| ^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: aborting due to previous error
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录