Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
64cd30e0
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,发现更多精彩内容 >>
提交
64cd30e0
编写于
2月 18, 2015
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Declare `&foo[]` to be obsolete syntax. Modify the obsolete mechanism to
support warnings.
上级
dfc5c0f1
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
28 addition
and
15 deletion
+28
-15
src/libsyntax/parse/obsolete.rs
src/libsyntax/parse/obsolete.rs
+21
-5
src/libsyntax/parse/parser.rs
src/libsyntax/parse/parser.rs
+4
-5
src/test/compile-fail/slice-1.rs
src/test/compile-fail/slice-1.rs
+3
-5
未找到文件。
src/libsyntax/parse/obsolete.rs
浏览文件 @
64cd30e0
...
...
@@ -28,6 +28,7 @@ pub enum ObsoleteSyntax {
ProcExpr
,
ClosureType
,
ClosureKind
,
EmptyIndex
,
}
pub
trait
ParserObsoleteMethods
{
...
...
@@ -48,35 +49,46 @@ fn report(&mut self,
impl
<
'a
>
ParserObsoleteMethods
for
parser
::
Parser
<
'a
>
{
/// Reports an obsolete syntax non-fatal error.
fn
obsolete
(
&
mut
self
,
sp
:
Span
,
kind
:
ObsoleteSyntax
)
{
let
(
kind_str
,
desc
)
=
match
kind
{
let
(
kind_str
,
desc
,
error
)
=
match
kind
{
ObsoleteSyntax
::
ForSized
=>
(
"for Sized?"
,
"no longer required. Traits (and their `Self` type) do not have the `Sized` bound
\
by default"
,
true
,
),
ObsoleteSyntax
::
ProcType
=>
(
"the `proc` type"
,
"use unboxed closures instead"
,
true
,
),
ObsoleteSyntax
::
ProcExpr
=>
(
"`proc` expression"
,
"use a `move ||` expression instead"
,
true
,
),
ObsoleteSyntax
::
ClosureType
=>
(
"`|usize| -> bool` closure type"
,
"use unboxed closures instead, no type annotation needed"
true
,
),
ObsoleteSyntax
::
ClosureKind
=>
(
"`:`, `&mut:`, or `&:`"
,
"rely on inference instead"
true
,
),
ObsoleteSyntax
::
Sized
=>
(
"`Sized? T` for removing the `Sized` bound"
,
"write `T: ?Sized` instead"
true
,
),
ObsoleteSyntax
::
EmptyIndex
=>
(
"[]"
,
"write `[..]` instead"
,
false
,
// warning for now
),
};
self
.report
(
sp
,
kind
,
kind_str
,
desc
);
self
.report
(
sp
,
kind
,
kind_str
,
desc
,
error
);
}
/// Reports an obsolete syntax non-fatal error, and returns
...
...
@@ -90,9 +102,13 @@ fn report(&mut self,
sp
:
Span
,
kind
:
ObsoleteSyntax
,
kind_str
:
&
str
,
desc
:
&
str
)
{
self
.span_err
(
sp
,
&
format!
(
"obsolete syntax: {}"
,
kind_str
)[]);
desc
:
&
str
,
error
:
bool
)
{
if
error
{
self
.span_err
(
sp
,
&
format!
(
"obsolete syntax: {}"
,
kind_str
)[]);
}
else
{
self
.span_warn
(
sp
,
&
format!
(
"obsolete syntax: {}"
,
kind_str
)[]);
}
if
!
self
.obsolete_set
.contains
(
&
kind
)
{
self
.sess
...
...
src/libsyntax/parse/parser.rs
浏览文件 @
64cd30e0
...
...
@@ -2552,8 +2552,9 @@ pub fn parse_dot_or_call_expr_with(&mut self, e0: P<Expr>) -> P<Expr> {
parameters
:
ast
::
PathParameters
::
none
(),
}
})
.collect
();
let
span
=
mk_sp
(
lo
,
hi
);
let
path
=
ast
::
Path
{
span
:
mk_sp
(
lo
,
hi
)
,
span
:
span
,
global
:
true
,
segments
:
segments
,
};
...
...
@@ -2562,10 +2563,8 @@ pub fn parse_dot_or_call_expr_with(&mut self, e0: P<Expr>) -> P<Expr> {
let
ix
=
self
.mk_expr
(
bracket_pos
,
hi
,
range
);
let
index
=
self
.mk_index
(
e
,
ix
);
e
=
self
.mk_expr
(
lo
,
hi
,
index
);
// Enable after snapshot.
// self.span_warn(e.span, "deprecated slicing syntax: `[]`");
// self.span_note(e.span,
// "use `&expr[..]` to construct a slice of the whole of expr");
self
.obsolete
(
span
,
ObsoleteSyntax
::
EmptyIndex
);
}
else
{
let
ix
=
self
.parse_expr
();
hi
=
self
.span.hi
;
...
...
src/test/compile-fail/slice-1.rs
浏览文件 @
64cd30e0
...
...
@@ -9,14 +9,12 @@
// except according to those terms.
// Test slicing &expr[] is deprecated and gives a helpful error message.
//
// ignore-test
struct
Foo
;
fn
main
()
{
let
x
=
Foo
;
&
x
[];
//~ WARNING deprecated slicing syntax: `[]`
//~^ NOTE use `&expr[..]` to construct a slice of the whole of expr
//~^^ ERROR cannot index a value of type `Foo`
&
x
[];
//~^ WARN obsolete syntax
//~| ERROR cannot index
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录