Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
01d6ed52
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,发现更多精彩内容 >>
提交
01d6ed52
编写于
5月 24, 2018
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
restore emplacement syntax (obsolete)
上级
07465222
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
97 addition
and
6 deletion
+97
-6
src/librustc/hir/lowering.rs
src/librustc/hir/lowering.rs
+4
-1
src/librustc_passes/ast_validation.rs
src/librustc_passes/ast_validation.rs
+6
-0
src/libsyntax/ast.rs
src/libsyntax/ast.rs
+3
-0
src/libsyntax/feature_gate.rs
src/libsyntax/feature_gate.rs
+3
-0
src/libsyntax/fold.rs
src/libsyntax/fold.rs
+3
-0
src/libsyntax/parse/parser.rs
src/libsyntax/parse/parser.rs
+13
-0
src/libsyntax/print/pprust.rs
src/libsyntax/print/pprust.rs
+7
-0
src/libsyntax/util/parser.rs
src/libsyntax/util/parser.rs
+11
-5
src/libsyntax/visit.rs
src/libsyntax/visit.rs
+4
-0
src/test/ui/obsolete-in-place/bad.bad.stderr
src/test/ui/obsolete-in-place/bad.bad.stderr
+18
-0
src/test/ui/obsolete-in-place/bad.rs
src/test/ui/obsolete-in-place/bad.rs
+25
-0
未找到文件。
src/librustc/hir/lowering.rs
浏览文件 @
01d6ed52
...
...
@@ -2935,7 +2935,10 @@ fn lower_anon_const(&mut self, c: &AnonConst) -> hir::AnonConst {
fn
lower_expr
(
&
mut
self
,
e
:
&
Expr
)
->
hir
::
Expr
{
let
kind
=
match
e
.node
{
ExprKind
::
Box
(
ref
inner
)
=>
hir
::
ExprBox
(
P
(
self
.lower_expr
(
inner
))),
ExprKind
::
ObsoleteInPlace
(
..
)
=>
{
self
.sess
.abort_if_errors
();
span_bug!
(
e
.span
,
"encountered ObsoleteInPlace expr during lowering"
);
}
ExprKind
::
Array
(
ref
exprs
)
=>
{
hir
::
ExprArray
(
exprs
.iter
()
.map
(|
x
|
self
.lower_expr
(
x
))
.collect
())
}
...
...
src/librustc_passes/ast_validation.rs
浏览文件 @
01d6ed52
...
...
@@ -172,6 +172,12 @@ fn visit_expr(&mut self, expr: &'a Expr) {
ExprKind
::
InlineAsm
(
..
)
if
!
self
.session.target.target.options.allow_asm
=>
{
span_err!
(
self
.session
,
expr
.span
,
E0472
,
"asm! is unsupported on this target"
);
}
ExprKind
::
ObsoleteInPlace
(
..
)
=>
{
self
.err_handler
()
.struct_span_err
(
expr
.span
,
"emplacement syntax is obsolete (for now, anyway)"
)
.note
(
"for more information, see <https://github.com/rust-lang/rust/issues/27779#issuecomment-378416911>"
)
.emit
();
}
_
=>
{}
}
...
...
src/libsyntax/ast.rs
浏览文件 @
01d6ed52
...
...
@@ -1008,6 +1008,7 @@ pub(super) fn to_ty(&self) -> Option<P<Ty>> {
pub
fn
precedence
(
&
self
)
->
ExprPrecedence
{
match
self
.node
{
ExprKind
::
Box
(
_
)
=>
ExprPrecedence
::
Box
,
ExprKind
::
ObsoleteInPlace
(
..
)
=>
ExprPrecedence
::
ObsoleteInPlace
,
ExprKind
::
Array
(
_
)
=>
ExprPrecedence
::
Array
,
ExprKind
::
Call
(
..
)
=>
ExprPrecedence
::
Call
,
ExprKind
::
MethodCall
(
..
)
=>
ExprPrecedence
::
MethodCall
,
...
...
@@ -1066,6 +1067,8 @@ pub enum RangeLimits {
pub
enum
ExprKind
{
/// A `box x` expression.
Box
(
P
<
Expr
>
),
/// First expr is the place; second expr is the value.
ObsoleteInPlace
(
P
<
Expr
>
,
P
<
Expr
>
),
/// An array (`[a, b, c, d]`)
Array
(
Vec
<
P
<
Expr
>>
),
/// A function call
...
...
src/libsyntax/feature_gate.rs
浏览文件 @
01d6ed52
...
...
@@ -1684,6 +1684,9 @@ fn visit_expr(&mut self, e: &'a ast::Expr) {
gate_feature_post!
(
&
self
,
type_ascription
,
e
.span
,
"type ascription is experimental"
);
}
ast
::
ExprKind
::
ObsoleteInPlace
(
..
)
=>
{
// these get a hard error in ast-validation
}
ast
::
ExprKind
::
Yield
(
..
)
=>
{
gate_feature_post!
(
&
self
,
generators
,
e
.span
,
...
...
src/libsyntax/fold.rs
浏览文件 @
01d6ed52
...
...
@@ -1194,6 +1194,9 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span, attrs}: Expr, folder: &mu
ExprKind
::
Box
(
e
)
=>
{
ExprKind
::
Box
(
folder
.fold_expr
(
e
))
}
ExprKind
::
ObsoleteInPlace
(
a
,
b
)
=>
{
ExprKind
::
ObsoleteInPlace
(
folder
.fold_expr
(
a
),
folder
.fold_expr
(
b
))
}
ExprKind
::
Array
(
exprs
)
=>
{
ExprKind
::
Array
(
folder
.fold_exprs
(
exprs
))
}
...
...
src/libsyntax/parse/parser.rs
浏览文件 @
01d6ed52
...
...
@@ -2839,6 +2839,17 @@ pub fn parse_prefix_expr(&mut self,
let
(
span
,
e
)
=
self
.interpolated_or_expr_span
(
e
)
?
;
(
lo
.to
(
span
),
ExprKind
::
AddrOf
(
m
,
e
))
}
token
::
Ident
(
..
)
if
self
.token
.is_keyword
(
keywords
::
In
)
=>
{
self
.bump
();
let
place
=
self
.parse_expr_res
(
Restrictions
::
NO_STRUCT_LITERAL
,
None
,
)
?
;
let
blk
=
self
.parse_block
()
?
;
let
span
=
blk
.span
;
let
blk_expr
=
self
.mk_expr
(
span
,
ExprKind
::
Block
(
blk
,
None
),
ThinVec
::
new
());
(
lo
.to
(
span
),
ExprKind
::
ObsoleteInPlace
(
place
,
blk_expr
))
}
token
::
Ident
(
..
)
if
self
.token
.is_keyword
(
keywords
::
Box
)
=>
{
self
.bump
();
let
e
=
self
.parse_prefix_expr
(
None
);
...
...
@@ -3042,6 +3053,8 @@ pub fn parse_assoc_expr_with(&mut self,
}
AssocOp
::
Assign
=>
self
.mk_expr
(
span
,
ExprKind
::
Assign
(
lhs
,
rhs
),
ThinVec
::
new
()),
AssocOp
::
ObsoleteInPlace
=>
self
.mk_expr
(
span
,
ExprKind
::
ObsoleteInPlace
(
lhs
,
rhs
),
ThinVec
::
new
()),
AssocOp
::
AssignOp
(
k
)
=>
{
let
aop
=
match
k
{
token
::
Plus
=>
BinOpKind
::
Add
,
...
...
src/libsyntax/print/pprust.rs
浏览文件 @
01d6ed52
...
...
@@ -2057,6 +2057,13 @@ fn print_expr_outer_attr_style(&mut self,
self
.word_space
(
"box"
)
?
;
self
.print_expr_maybe_paren
(
expr
,
parser
::
PREC_PREFIX
)
?
;
}
ast
::
ExprKind
::
ObsoleteInPlace
(
ref
place
,
ref
expr
)
=>
{
let
prec
=
AssocOp
::
ObsoleteInPlace
.precedence
()
as
i8
;
self
.print_expr_maybe_paren
(
place
,
prec
+
1
)
?
;
self
.s
.space
()
?
;
self
.word_space
(
"<-"
)
?
;
self
.print_expr_maybe_paren
(
expr
,
prec
)
?
;
}
ast
::
ExprKind
::
Array
(
ref
exprs
)
=>
{
self
.print_expr_vec
(
&
exprs
[
..
],
attrs
)
?
;
}
...
...
src/libsyntax/util/parser.rs
浏览文件 @
01d6ed52
...
...
@@ -56,6 +56,8 @@ pub enum AssocOp {
GreaterEqual
,
/// `=`
Assign
,
/// `<-`
ObsoleteInPlace
,
/// `?=` where ? is one of the BinOpToken
AssignOp
(
BinOpToken
),
/// `as`
...
...
@@ -84,6 +86,7 @@ pub fn from_token(t: &Token) -> Option<AssocOp> {
use
self
::
AssocOp
::
*
;
match
*
t
{
Token
::
BinOpEq
(
k
)
=>
Some
(
AssignOp
(
k
)),
Token
::
LArrow
=>
Some
(
ObsoleteInPlace
),
Token
::
Eq
=>
Some
(
Assign
),
Token
::
BinOp
(
BinOpToken
::
Star
)
=>
Some
(
Multiply
),
Token
::
BinOp
(
BinOpToken
::
Slash
)
=>
Some
(
Divide
),
...
...
@@ -153,6 +156,7 @@ pub fn precedence(&self) -> usize {
LAnd
=>
6
,
LOr
=>
5
,
DotDot
|
DotDotEq
=>
4
,
ObsoleteInPlace
=>
3
,
Assign
|
AssignOp
(
_
)
=>
2
,
}
}
...
...
@@ -162,7 +166,7 @@ pub fn fixity(&self) -> Fixity {
use
self
::
AssocOp
::
*
;
// NOTE: it is a bug to have an operators that has same precedence but different fixities!
match
*
self
{
Assign
|
AssignOp
(
_
)
=>
Fixity
::
Right
,
ObsoleteInPlace
|
Assign
|
AssignOp
(
_
)
=>
Fixity
::
Right
,
As
|
Multiply
|
Divide
|
Modulus
|
Add
|
Subtract
|
ShiftLeft
|
ShiftRight
|
BitAnd
|
BitXor
|
BitOr
|
Less
|
Greater
|
LessEqual
|
GreaterEqual
|
Equal
|
NotEqual
|
LAnd
|
LOr
|
Colon
=>
Fixity
::
Left
,
...
...
@@ -174,8 +178,8 @@ pub fn is_comparison(&self) -> bool {
use
self
::
AssocOp
::
*
;
match
*
self
{
Less
|
Greater
|
LessEqual
|
GreaterEqual
|
Equal
|
NotEqual
=>
true
,
Assign
|
AssignOp
(
_
)
|
As
|
Multiply
|
Divide
|
Modulus
|
Add
|
Subtract
|
ShiftLeft
|
ShiftRight
|
BitAnd
|
BitXor
|
BitOr
|
LAnd
|
LOr
|
ObsoleteInPlace
|
Assign
|
AssignOp
(
_
)
|
As
|
Multiply
|
Divide
|
Modulus
|
Add
|
S
ubtract
|
S
hiftLeft
|
ShiftRight
|
BitAnd
|
BitXor
|
BitOr
|
LAnd
|
LOr
|
DotDot
|
DotDotEq
|
Colon
=>
false
}
}
...
...
@@ -183,7 +187,7 @@ pub fn is_comparison(&self) -> bool {
pub
fn
is_assign_like
(
&
self
)
->
bool
{
use
self
::
AssocOp
::
*
;
match
*
self
{
Assign
|
AssignOp
(
_
)
=>
true
,
Assign
|
AssignOp
(
_
)
|
ObsoleteInPlace
=>
true
,
Less
|
Greater
|
LessEqual
|
GreaterEqual
|
Equal
|
NotEqual
|
As
|
Multiply
|
Divide
|
Modulus
|
Add
|
Subtract
|
ShiftLeft
|
ShiftRight
|
BitAnd
|
BitXor
|
BitOr
|
LAnd
|
LOr
|
DotDot
|
DotDotEq
|
Colon
=>
false
...
...
@@ -211,7 +215,7 @@ pub fn to_ast_binop(&self) -> Option<BinOpKind> {
BitOr
=>
Some
(
BinOpKind
::
BitOr
),
LAnd
=>
Some
(
BinOpKind
::
And
),
LOr
=>
Some
(
BinOpKind
::
Or
),
Assign
|
AssignOp
(
_
)
|
As
|
DotDot
|
DotDotEq
|
Colon
=>
None
ObsoleteInPlace
|
Assign
|
AssignOp
(
_
)
|
As
|
DotDot
|
DotDotEq
|
Colon
=>
None
}
}
}
...
...
@@ -238,6 +242,7 @@ pub enum ExprPrecedence {
Binary
(
BinOpKind
),
ObsoleteInPlace
,
Cast
,
Type
,
...
...
@@ -304,6 +309,7 @@ pub fn order(self) -> i8 {
// Binop-like expr kinds, handled by `AssocOp`.
ExprPrecedence
::
Binary
(
op
)
=>
AssocOp
::
from_ast_binop
(
op
)
.precedence
()
as
i8
,
ExprPrecedence
::
ObsoleteInPlace
=>
AssocOp
::
ObsoleteInPlace
.precedence
()
as
i8
,
ExprPrecedence
::
Cast
=>
AssocOp
::
As
.precedence
()
as
i8
,
ExprPrecedence
::
Type
=>
AssocOp
::
Colon
.precedence
()
as
i8
,
...
...
src/libsyntax/visit.rs
浏览文件 @
01d6ed52
...
...
@@ -660,6 +660,10 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
ExprKind
::
Box
(
ref
subexpression
)
=>
{
visitor
.visit_expr
(
subexpression
)
}
ExprKind
::
ObsoleteInPlace
(
ref
place
,
ref
subexpression
)
=>
{
visitor
.visit_expr
(
place
);
visitor
.visit_expr
(
subexpression
)
}
ExprKind
::
Array
(
ref
subexpressions
)
=>
{
walk_list!
(
visitor
,
visit_expr
,
subexpressions
);
}
...
...
src/test/ui/obsolete-in-place/bad.bad.stderr
0 → 100644
浏览文件 @
01d6ed52
error: emplacement syntax is obsolete (for now, anyway)
--> $DIR/bad.rs:19:5
|
LL | x <- y; //[bad]~ ERROR emplacement syntax is obsolete
| ^^^^^^
|
= note: for more information, see <https://github.com/rust-lang/rust/issues/27779#issuecomment-378416911>
error: emplacement syntax is obsolete (for now, anyway)
--> $DIR/bad.rs:20:5
|
LL | in(foo) { bar }; //[bad]~ ERROR emplacement syntax is obsolete
| ^^^^^^^^^^^^^^^
|
= note: for more information, see <https://github.com/rust-lang/rust/issues/27779#issuecomment-378416911>
error: aborting due to 2 previous errors
src/test/ui/obsolete-in-place/bad.rs
0 → 100644
浏览文件 @
01d6ed52
// 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.
// Check that `<-` and `in` syntax gets a hard error.
// revisions: good bad
//[good] run-pass
#[cfg(bad)]
fn
main
()
{
let
(
x
,
y
,
foo
,
bar
);
x
<-
y
;
//[bad]~ ERROR emplacement syntax is obsolete
in
(
foo
)
{
bar
};
//[bad]~ ERROR emplacement syntax is obsolete
}
#[cfg(good)]
fn
main
()
{
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录