Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
c9f0ff38
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,发现更多精彩内容 >>
提交
c9f0ff38
编写于
1月 02, 2015
作者:
K
Keegan McAllister
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Reserve the keyword 'macro'
上级
aa69cbde
变更
12
显示空白变更内容
内联
并排
Showing
12 changed file
with
55 addition
and
39 deletion
+55
-39
src/doc/reference.md
src/doc/reference.md
+6
-6
src/etc/vim/syntax/rust.vim
src/etc/vim/syntax/rust.vim
+1
-1
src/librustc_back/svh.rs
src/librustc_back/svh.rs
+7
-7
src/librustc_driver/pretty.rs
src/librustc_driver/pretty.rs
+2
-2
src/libsyntax/ext/expand.rs
src/libsyntax/ext/expand.rs
+6
-6
src/libsyntax/feature_gate.rs
src/libsyntax/feature_gate.rs
+2
-2
src/libsyntax/fold.rs
src/libsyntax/fold.rs
+4
-4
src/libsyntax/parse/parser.rs
src/libsyntax/parse/parser.rs
+3
-3
src/libsyntax/parse/token.rs
src/libsyntax/parse/token.rs
+1
-0
src/libsyntax/show_span.rs
src/libsyntax/show_span.rs
+2
-2
src/libsyntax/visit.rs
src/libsyntax/visit.rs
+6
-6
src/test/compile-fail/macro-keyword.rs
src/test/compile-fail/macro-keyword.rs
+15
-0
未找到文件。
src/doc/reference.md
浏览文件 @
c9f0ff38
...
...
@@ -193,12 +193,12 @@ grammar as double-quoted strings. Other tokens have exact rules given.
| break | const | continue | crate | do |
| else | enum | extern | false | final |
| fn | for | if | impl | in |
| let | loop | ma
tch | mod | move
|
| m
ut | offsetof | override | priv | pub
|
| pu
re | ref | return | sizeof | static
|
| s
elf | struct | super | true | trait
|
| t
ype | typeof | unsafe | unsized | use
|
|
virtual | where | while | yield
|
| let | loop | ma
cro | match | mod
|
| m
ove | mut | offsetof | override | priv
|
| pu
b | pure | ref | return | sizeof
|
| s
tatic | self | struct | super | true
|
| t
rait | type | typeof | unsafe | unsized
|
|
use | virtual | where | while | yield
|
Each of these keywords has special meaning in its grammar, and all of them are
...
...
src/etc/vim/syntax/rust.vim
浏览文件 @
c9f0ff38
...
...
@@ -56,7 +56,7 @@ syn match rustMacroRepeatCount ".\?[*+]" contained
syn
match
rustMacroVariable
"$\w\+"
" Reserved (but not yet used) keywords {{{2
syn
keyword rustReservedKeyword alignof be
do
offsetof priv pure sizeof typeof unsized yield abstract final override
syn
keyword rustReservedKeyword alignof be
do
offsetof priv pure sizeof typeof unsized yield abstract final override
macro
" Built-in types {{{2
syn
keyword rustType int uint float char bool u8 u16 u32 u64 f32
...
...
src/librustc_back/svh.rs
浏览文件 @
c9f0ff38
...
...
@@ -327,11 +327,11 @@ fn content<K:InternKey>(k: K) -> token::InternedString { k.get_content() }
impl
<
'a
,
'v
>
Visitor
<
'v
>
for
StrictVersionHashVisitor
<
'a
>
{
fn
visit_mac
(
&
mut
self
,
mac
ro
:
&
Mac
)
{
fn
visit_mac
(
&
mut
self
,
mac
:
&
Mac
)
{
// macro invocations, namely macro_rules definitions,
// *can* appear as items, even in the expanded crate AST.
if
macro_name
(
mac
ro
)
.get
()
==
"macro_rules"
{
if
macro_name
(
mac
)
.get
()
==
"macro_rules"
{
// Pretty-printing definition to a string strips out
// surface artifacts (currently), such as the span
// information, yielding a content-based hash.
...
...
@@ -341,7 +341,7 @@ fn visit_mac(&mut self, macro: &Mac) {
// trees might be faster. Implementing this is far
// easier in short term.
let
macro_defn_as_string
=
pprust
::
to_string
(|
pp_state
|
{
pp_state
.print_mac
(
mac
ro
,
token
::
Paren
)
pp_state
.print_mac
(
mac
,
token
::
Paren
)
});
macro_defn_as_string
.hash
(
self
.st
);
}
else
{
...
...
@@ -349,14 +349,14 @@ fn visit_mac(&mut self, macro: &Mac) {
// invocation at this stage except `macro_rules!`.
panic!
(
"reached macro somehow: {}"
,
pprust
::
to_string
(|
pp_state
|
{
pp_state
.print_mac
(
mac
ro
,
token
::
Paren
)
pp_state
.print_mac
(
mac
,
token
::
Paren
)
}));
}
visit
::
walk_mac
(
self
,
mac
ro
);
visit
::
walk_mac
(
self
,
mac
);
fn
macro_name
(
mac
ro
:
&
Mac
)
->
token
::
InternedString
{
match
&
mac
ro
.node
{
fn
macro_name
(
mac
:
&
Mac
)
->
token
::
InternedString
{
match
&
mac
.node
{
&
MacInvocTT
(
ref
path
,
ref
_
tts
,
ref
_
stx_ctxt
)
=>
{
let
s
=
path
.segments
[];
assert_eq!
(
s
.len
(),
1
);
...
...
src/librustc_driver/pretty.rs
浏览文件 @
c9f0ff38
...
...
@@ -484,8 +484,8 @@ fn expr_to_block(rules: ast::BlockCheckMode,
// in general the pretty printer processes unexpanded code, so
// we override the default `fold_mac` method which panics.
fn
fold_mac
(
&
mut
self
,
_
macro
:
ast
::
Mac
)
->
ast
::
Mac
{
fold
::
noop_fold_mac
(
_
macro
,
self
)
fn
fold_mac
(
&
mut
self
,
mac
:
ast
::
Mac
)
->
ast
::
Mac
{
fold
::
noop_fold_mac
(
mac
,
self
)
}
}
...
...
src/libsyntax/ext/expand.rs
浏览文件 @
c9f0ff38
...
...
@@ -986,8 +986,8 @@ fn fold_ident(&mut self, id: Ident) -> Ident {
ctxt
:
mtwt
::
apply_renames
(
self
.renames
,
id
.ctxt
),
}
}
fn
fold_mac
(
&
mut
self
,
mac
ro
:
ast
::
Mac
)
->
ast
::
Mac
{
fold
::
noop_fold_mac
(
mac
ro
,
self
)
fn
fold_mac
(
&
mut
self
,
mac
:
ast
::
Mac
)
->
ast
::
Mac
{
fold
::
noop_fold_mac
(
mac
,
self
)
}
}
...
...
@@ -1023,8 +1023,8 @@ fn fold_pat(&mut self, pat: P<ast::Pat>) -> P<ast::Pat> {
_
=>
unreachable!
()
})
}
fn
fold_mac
(
&
mut
self
,
mac
ro
:
ast
::
Mac
)
->
ast
::
Mac
{
fold
::
noop_fold_mac
(
mac
ro
,
self
)
fn
fold_mac
(
&
mut
self
,
mac
:
ast
::
Mac
)
->
ast
::
Mac
{
fold
::
noop_fold_mac
(
mac
,
self
)
}
}
...
...
@@ -1286,8 +1286,8 @@ struct MacroExterminator<'a>{
}
impl
<
'a
,
'v
>
Visitor
<
'v
>
for
MacroExterminator
<
'a
>
{
fn
visit_mac
(
&
mut
self
,
mac
ro
:
&
ast
::
Mac
)
{
self
.sess.span_diagnostic
.span_bug
(
mac
ro
.span
,
fn
visit_mac
(
&
mut
self
,
mac
:
&
ast
::
Mac
)
{
self
.sess.span_diagnostic
.span_bug
(
mac
.span
,
"macro exterminator: expected AST
\
with no macro invocations"
);
}
...
...
src/libsyntax/feature_gate.rs
浏览文件 @
c9f0ff38
...
...
@@ -165,8 +165,8 @@ struct MacroVisitor<'a> {
}
impl
<
'a
,
'v
>
Visitor
<
'v
>
for
MacroVisitor
<
'a
>
{
fn
visit_mac
(
&
mut
self
,
mac
ro
:
&
ast
::
Mac
)
{
let
ast
::
MacInvocTT
(
ref
path
,
_
,
_
)
=
mac
ro
.node
;
fn
visit_mac
(
&
mut
self
,
mac
:
&
ast
::
Mac
)
{
let
ast
::
MacInvocTT
(
ref
path
,
_
,
_
)
=
mac
.node
;
let
id
=
path
.segments
.last
()
.unwrap
()
.identifier
;
if
id
==
token
::
str_to_ident
(
"macro_rules"
)
{
...
...
src/libsyntax/fold.rs
浏览文件 @
c9f0ff38
...
...
@@ -194,13 +194,13 @@ fn fold_local(&mut self, l: P<Local>) -> P<Local> {
noop_fold_local
(
l
,
self
)
}
fn
fold_mac
(
&
mut
self
,
_
mac
ro
:
Mac
)
->
Mac
{
fn
fold_mac
(
&
mut
self
,
_
mac
:
Mac
)
->
Mac
{
panic!
(
"fold_mac disabled by default"
);
// NB: see note about macros above.
// if you really want a folder that
// works on macros, use this
// definition in your trait impl:
// fold::noop_fold_mac(_mac
ro
, self)
// fold::noop_fold_mac(_mac, self)
}
fn
fold_explicit_self
(
&
mut
self
,
es
:
ExplicitSelf
)
->
ExplicitSelf
{
...
...
@@ -1487,8 +1487,8 @@ impl Folder for ToZzIdentFolder {
fn
fold_ident
(
&
mut
self
,
_
:
ast
::
Ident
)
->
ast
::
Ident
{
token
::
str_to_ident
(
"zz"
)
}
fn
fold_mac
(
&
mut
self
,
mac
ro
:
ast
::
Mac
)
->
ast
::
Mac
{
fold
::
noop_fold_mac
(
mac
ro
,
self
)
fn
fold_mac
(
&
mut
self
,
mac
:
ast
::
Mac
)
->
ast
::
Mac
{
fold
::
noop_fold_mac
(
mac
,
self
)
}
}
...
...
src/libsyntax/parse/parser.rs
浏览文件 @
c9f0ff38
...
...
@@ -3881,13 +3881,13 @@ fn parse_block_tail_(&mut self, lo: BytePos, s: BlockCheckMode,
&
mut
stmts
,
&
mut
expr
);
}
StmtMac
(
mac
ro
,
MacStmtWithoutBraces
)
=>
{
StmtMac
(
mac
,
MacStmtWithoutBraces
)
=>
{
// statement macro without braces; might be an
// expr depending on whether a semicolon follows
match
self
.token
{
token
::
Semi
=>
{
stmts
.push
(
P
(
Spanned
{
node
:
StmtMac
(
mac
ro
,
node
:
StmtMac
(
mac
,
MacStmtWithSemicolon
),
span
:
span
,
}));
...
...
@@ -3896,7 +3896,7 @@ fn parse_block_tail_(&mut self, lo: BytePos, s: BlockCheckMode,
_
=>
{
let
e
=
self
.mk_mac_expr
(
span
.lo
,
span
.hi
,
mac
ro
.and_then
(|
m
|
m
.node
));
mac
.and_then
(|
m
|
m
.node
));
let
e
=
self
.parse_dot_or_call_expr_with
(
e
);
self
.handle_expression_like_statement
(
...
...
src/libsyntax/parse/token.rs
浏览文件 @
c9f0ff38
...
...
@@ -574,6 +574,7 @@ pub mod keywords {
(
56
,
Abstract
,
"abstract"
);
(
57
,
Final
,
"final"
);
(
58
,
Override
,
"override"
);
(
59
,
Macro
,
"macro"
);
}
}
...
...
src/libsyntax/show_span.rs
浏览文件 @
c9f0ff38
...
...
@@ -28,8 +28,8 @@ fn visit_expr(&mut self, e: &ast::Expr) {
visit
::
walk_expr
(
self
,
e
);
}
fn
visit_mac
(
&
mut
self
,
mac
ro
:
&
ast
::
Mac
)
{
visit
::
walk_mac
(
self
,
mac
ro
);
fn
visit_mac
(
&
mut
self
,
mac
:
&
ast
::
Mac
)
{
visit
::
walk_mac
(
self
,
mac
);
}
}
...
...
src/libsyntax/visit.rs
浏览文件 @
c9f0ff38
...
...
@@ -115,13 +115,13 @@ fn visit_lifetime_def(&mut self, lifetime: &'v LifetimeDef) {
fn
visit_explicit_self
(
&
mut
self
,
es
:
&
'v
ExplicitSelf
)
{
walk_explicit_self
(
self
,
es
)
}
fn
visit_mac
(
&
mut
self
,
_
mac
ro
:
&
'v
Mac
)
{
fn
visit_mac
(
&
mut
self
,
_
mac
:
&
'v
Mac
)
{
panic!
(
"visit_mac disabled by default"
);
// NB: see note about macros above.
// if you really want a visitor that
// works on macros, use this
// definition in your trait impl:
// visit::walk_mac(self, _mac
ro
)
// visit::walk_mac(self, _mac)
}
fn
visit_path
(
&
mut
self
,
path
:
&
'v
Path
,
_
id
:
ast
::
NodeId
)
{
walk_path
(
self
,
path
)
...
...
@@ -334,7 +334,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
visitor
.visit_trait_item
(
method
)
}
}
ItemMac
(
ref
mac
ro
)
=>
visitor
.visit_mac
(
macro
),
ItemMac
(
ref
mac
)
=>
visitor
.visit_mac
(
mac
),
}
for
attr
in
item
.attrs
.iter
()
{
visitor
.visit_attribute
(
attr
);
...
...
@@ -546,7 +546,7 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) {
visitor
.visit_pat
(
&**
postpattern
)
}
}
PatMac
(
ref
mac
ro
)
=>
visitor
.visit_mac
(
macro
),
PatMac
(
ref
mac
)
=>
visitor
.visit_mac
(
mac
),
}
}
...
...
@@ -746,7 +746,7 @@ pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt) {
StmtExpr
(
ref
expression
,
_
)
|
StmtSemi
(
ref
expression
,
_
)
=>
{
visitor
.visit_expr
(
&**
expression
)
}
StmtMac
(
ref
mac
ro
,
_
)
=>
visitor
.visit_mac
(
&**
macro
),
StmtMac
(
ref
mac
,
_
)
=>
visitor
.visit_mac
(
&**
mac
),
}
}
...
...
@@ -893,7 +893,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
ExprRet
(
ref
optional_expression
)
=>
{
walk_expr_opt
(
visitor
,
optional_expression
)
}
ExprMac
(
ref
mac
ro
)
=>
visitor
.visit_mac
(
macro
),
ExprMac
(
ref
mac
)
=>
visitor
.visit_mac
(
mac
),
ExprParen
(
ref
subexpression
)
=>
{
visitor
.visit_expr
(
&**
subexpression
)
}
...
...
src/test/compile-fail/macro-keyword.rs
0 → 100644
浏览文件 @
c9f0ff38
// 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.
fn
macro
()
{
//~ ERROR `macro` is a reserved keyword
}
pub
fn
main
()
{
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录