Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
ce1fed7f
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,发现更多精彩内容 >>
提交
ce1fed7f
编写于
12月 07, 2017
作者:
A
Agustin Chiappe Berrini
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
address comments
上级
65ccf24c
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
32 addition
and
42 deletion
+32
-42
src/librustc_passes/ast_validation.rs
src/librustc_passes/ast_validation.rs
+15
-18
src/libsyntax/parse/lexer/mod.rs
src/libsyntax/parse/lexer/mod.rs
+1
-1
src/libsyntax/parse/token.rs
src/libsyntax/parse/token.rs
+8
-2
src/libsyntax_pos/symbol.rs
src/libsyntax_pos/symbol.rs
+0
-18
src/test/compile-fail/issue-10412.rs
src/test/compile-fail/issue-10412.rs
+6
-2
src/test/compile-fail/lifetime-no-keyword.rs
src/test/compile-fail/lifetime-no-keyword.rs
+2
-1
未找到文件。
src/librustc_passes/ast_validation.rs
浏览文件 @
ce1fed7f
...
...
@@ -21,8 +21,10 @@
use
syntax
::
ast
::
*
;
use
syntax
::
attr
;
use
syntax
::
codemap
::
Spanned
;
use
syntax
::
parse
::
token
;
use
syntax
::
visit
::{
self
,
Visitor
};
use
syntax_pos
::
Span
;
use
syntax_pos
::
symbol
::
keywords
;
use
errors
;
struct
AstValidator
<
'a
>
{
...
...
@@ -35,15 +37,15 @@ fn err_handler(&self) -> &errors::Handler {
}
fn
check_lifetime
(
&
self
,
lifetime
:
&
Lifetime
)
{
if
!
lifetime
.ident
.without_first_quote
()
.is_valid
()
&&
!
lifetime
.ident.name
.is_static_keyword
()
{
let
valid_names
=
[
keywords
::
StaticLifetime
.name
(),
keywords
::
Invalid
.name
()];
if
!
valid_names
.contains
(
&
lifetime
.ident.name
)
&&
token
::
Ident
(
lifetime
.ident
.without_first_quote
())
.is_reserved_ident
()
{
self
.err_handler
()
.span_err
(
lifetime
.span
,
"lifetimes cannot use keyword names"
);
}
}
fn
check_label
(
&
self
,
label
:
Ident
,
span
:
Span
)
{
if
label
.name
.is_static_keyword
()
||
!
label
.without_first_quote
()
.is_valid
()
||
label
.name
==
"'_"
{
if
token
::
Ident
(
label
.without_first_quote
())
.is_reserved_ident
()
||
label
.name
==
"'_"
{
self
.err_handler
()
.span_err
(
span
,
&
format!
(
"invalid label name `{}`"
,
label
.name
));
}
}
...
...
@@ -207,9 +209,14 @@ fn visit_use_tree(&mut self, use_tree: &'a UseTree, id: NodeId, _nested: bool) {
visit
::
walk_use_tree
(
self
,
use_tree
,
id
);
}
fn
visit_lifetime
(
&
mut
self
,
lifetime
:
&
'a
Lifetime
)
{
self
.check_lifetime
(
lifetime
);
visit
::
walk_lifetime
(
self
,
lifetime
);
}
fn
visit_item
(
&
mut
self
,
item
:
&
'a
Item
)
{
match
item
.node
{
ItemKind
::
Impl
(
..
,
ref
generics
,
Some
(
..
),
_
,
ref
impl_items
)
=>
{
ItemKind
::
Impl
(
..
,
Some
(
..
),
_
,
ref
impl_items
)
=>
{
self
.invalid_visibility
(
&
item
.vis
,
item
.span
,
None
);
for
impl_item
in
impl_items
{
self
.invalid_visibility
(
&
impl_item
.vis
,
impl_item
.span
,
None
);
...
...
@@ -217,13 +224,11 @@ fn visit_item(&mut self, item: &'a Item) {
self
.check_trait_fn_not_const
(
sig
.constness
);
}
}
generics
.lifetimes
.iter
()
.for_each
(|
l
|
self
.check_lifetime
(
&
l
.lifetime
))
}
ItemKind
::
Impl
(
..
,
ref
generics
,
None
,
_
,
_
)
=>
{
ItemKind
::
Impl
(
..
,
None
,
_
,
_
)
=>
{
self
.invalid_visibility
(
&
item
.vis
,
item
.span
,
Some
(
"place qualifiers on individual impl items instead"
));
generics
.lifetimes
.iter
()
.for_each
(|
l
|
self
.check_lifetime
(
&
l
.lifetime
))
}
ItemKind
::
AutoImpl
(
..
)
=>
{
self
.invalid_visibility
(
&
item
.vis
,
item
.span
,
None
);
...
...
@@ -234,14 +239,13 @@ fn visit_item(&mut self, item: &'a Item) {
Some
(
"place qualifiers on individual foreign items
\
instead"
));
}
ItemKind
::
Enum
(
ref
def
,
ref
generics
)
=>
{
ItemKind
::
Enum
(
ref
def
,
_
)
=>
{
for
variant
in
&
def
.variants
{
self
.invalid_non_exhaustive_attribute
(
variant
);
for
field
in
variant
.node.data
.fields
()
{
self
.invalid_visibility
(
&
field
.vis
,
field
.span
,
None
);
}
}
generics
.lifetimes
.iter
()
.for_each
(|
l
|
self
.check_lifetime
(
&
l
.lifetime
))
}
ItemKind
::
Trait
(
is_auto
,
_
,
ref
generics
,
ref
bounds
,
ref
trait_items
)
=>
{
if
is_auto
==
IsAuto
::
Yes
{
...
...
@@ -278,7 +282,6 @@ fn visit_item(&mut self, item: &'a Item) {
}
}
}
generics
.lifetimes
.iter
()
.for_each
(|
l
|
self
.check_lifetime
(
&
l
.lifetime
))
}
ItemKind
::
Mod
(
_
)
=>
{
// Ensure that `path` attributes on modules are recorded as used (c.f. #35584).
...
...
@@ -289,7 +292,7 @@ fn visit_item(&mut self, item: &'a Item) {
self
.session
.buffer_lint
(
lint
,
item
.id
,
item
.span
,
msg
);
}
}
ItemKind
::
Union
(
ref
vdata
,
ref
generics
)
=>
{
ItemKind
::
Union
(
ref
vdata
,
_
)
=>
{
if
!
vdata
.is_struct
()
{
self
.err_handler
()
.span_err
(
item
.span
,
"tuple and unit unions are not permitted"
);
...
...
@@ -298,12 +301,6 @@ fn visit_item(&mut self, item: &'a Item) {
self
.err_handler
()
.span_err
(
item
.span
,
"unions cannot have zero fields"
);
}
generics
.lifetimes
.iter
()
.for_each
(|
l
|
self
.check_lifetime
(
&
l
.lifetime
))
}
ItemKind
::
Fn
(
..
,
ref
generics
,
_
)
|
ItemKind
::
Ty
(
_
,
ref
generics
)
|
ItemKind
::
Struct
(
_
,
ref
generics
)
=>
{
generics
.lifetimes
.iter
()
.for_each
(|
l
|
self
.check_lifetime
(
&
l
.lifetime
))
}
_
=>
{}
}
...
...
src/libsyntax/parse/lexer/mod.rs
浏览文件 @
ce1fed7f
...
...
@@ -14,7 +14,7 @@
use
errors
::{
FatalError
,
DiagnosticBuilder
};
use
parse
::{
token
,
ParseSess
};
use
str
::
char_at
;
use
symbol
::
{
Symbol
}
;
use
symbol
::
Symbol
;
use
std_unicode
::
property
::
Pattern_White_Space
;
use
std
::
borrow
::
Cow
;
...
...
src/libsyntax/parse/token.rs
浏览文件 @
ce1fed7f
...
...
@@ -364,12 +364,18 @@ pub fn is_special_ident(&self) -> bool {
/// Returns `true` if the token is a keyword used in the language.
pub
fn
is_used_keyword
(
&
self
)
->
bool
{
self
.ident
()
.map
(|
id
|
id
.name
.is_used_keyword
())
.unwrap_or
(
false
)
match
self
.ident
()
{
Some
(
id
)
=>
id
.name
>=
keywords
::
As
.name
()
&&
id
.name
<=
keywords
::
While
.name
(),
_
=>
false
,
}
}
/// Returns `true` if the token is a keyword reserved for possible future use.
pub
fn
is_unused_keyword
(
&
self
)
->
bool
{
self
.ident
()
.map
(|
id
|
id
.name
.is_unused_keyword
())
.unwrap_or
(
false
)
match
self
.ident
()
{
Some
(
id
)
=>
id
.name
>=
keywords
::
Abstract
.name
()
&&
id
.name
<=
keywords
::
Yield
.name
(),
_
=>
false
,
}
}
pub
fn
glue
(
self
,
joint
:
Token
)
->
Option
<
Token
>
{
...
...
src/libsyntax_pos/symbol.rs
浏览文件 @
ce1fed7f
...
...
@@ -42,10 +42,6 @@ pub fn without_first_quote(&self) -> Ident {
pub
fn
modern
(
self
)
->
Ident
{
Ident
{
name
:
self
.name
,
ctxt
:
self
.ctxt
.modern
()
}
}
pub
fn
is_valid
(
&
self
)
->
bool
{
!
self
.name
.is_used_keyword
()
&&
!
self
.name
.is_unused_keyword
()
}
}
impl
fmt
::
Debug
for
Ident
{
...
...
@@ -122,20 +118,6 @@ pub fn as_u32(self) -> u32 {
self
.0
}
/// Returns `true` if the token is a keyword used in the language.
pub
fn
is_used_keyword
(
&
self
)
->
bool
{
self
>=
&
keywords
::
As
.name
()
&&
self
<=
&
keywords
::
While
.name
()
}
/// Returns `true` if the token is a keyword reserved for possible future use.
pub
fn
is_unused_keyword
(
&
self
)
->
bool
{
self
>=
&
keywords
::
Abstract
.name
()
&&
self
<=
&
keywords
::
Yield
.name
()
}
pub
fn
is_static_keyword
(
&
self
)
->
bool
{
self
==
&
keywords
::
StaticLifetime
.name
()
}
pub
fn
without_first_quote
(
&
self
)
->
Symbol
{
Symbol
::
from
(
self
.as_str
()
.trim_left_matches
(
'\''
))
}
...
...
src/test/compile-fail/issue-10412.rs
浏览文件 @
ce1fed7f
...
...
@@ -9,17 +9,21 @@
// except according to those terms.
trait
Serializable
<
'self
,
T
>
{
//~ ERROR lifetimes cannot use keyword names
fn
serialize
(
val
:
&
'self
T
)
->
Vec
<
u8
>
;
fn
serialize
(
val
:
&
'self
T
)
->
Vec
<
u8
>
;
//~^ ERROR lifetimes cannot use keyword names
fn
deserialize
(
repr
:
&
[
u8
])
->
&
'self
T
;
//~^ ERROR lifetimes cannot use keyword names
}
impl
<
'self
>
Serializable
<
str
>
for
&
'self
str
{
impl
<
'self
>
Serializable
<
str
>
for
&
'self
str
{
//~ ERROR lifetimes cannot use keyword names
//~^ ERROR lifetimes cannot use keyword names
//~| ERROR missing lifetime specifier
fn
serialize
(
val
:
&
'self
str
)
->
Vec
<
u8
>
{
//~^ ERROR lifetimes cannot use keyword names
vec!
[
1
]
}
fn
deserialize
(
repr
:
&
[
u8
])
->
&
'self
str
{
//~^ ERROR lifetimes cannot use keyword names
"hi"
}
}
...
...
src/test/compile-fail/lifetime-no-keyword.rs
浏览文件 @
ce1fed7f
...
...
@@ -11,6 +11,7 @@
fn
foo
<
'a
>
(
a
:
&
'a
isize
)
{
}
fn
bar
(
a
:
&
'static
isize
)
{
}
fn
baz
<
'let
>
(
a
:
&
'let
isize
)
{
}
//~ ERROR lifetimes cannot use keyword names
//~^ ERROR lifetimes cannot use keyword names
fn
zab
<
'self
>
(
a
:
&
'self
isize
)
{
}
//~ ERROR lifetimes cannot use keyword names
//~^ ERROR lifetimes cannot use keyword names
fn
main
()
{
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录