Skip to content

Commit 01d6ed5

Browse files
committed
restore emplacement syntax (obsolete)
1 parent 0746522 commit 01d6ed5

File tree

11 files changed

+97
-6
lines changed

11 files changed

+97
-6
lines changed

src/librustc/hir/lowering.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -2935,7 +2935,10 @@ impl<'a> LoweringContext<'a> {
29352935
fn lower_expr(&mut self, e: &Expr) -> hir::Expr {
29362936
let kind = match e.node {
29372937
ExprKind::Box(ref inner) => hir::ExprBox(P(self.lower_expr(inner))),
2938-
2938+
ExprKind::ObsoleteInPlace(..) => {
2939+
self.sess.abort_if_errors();
2940+
span_bug!(e.span, "encountered ObsoleteInPlace expr during lowering");
2941+
}
29392942
ExprKind::Array(ref exprs) => {
29402943
hir::ExprArray(exprs.iter().map(|x| self.lower_expr(x)).collect())
29412944
}

src/librustc_passes/ast_validation.rs

+6
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,12 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
172172
ExprKind::InlineAsm(..) if !self.session.target.target.options.allow_asm => {
173173
span_err!(self.session, expr.span, E0472, "asm! is unsupported on this target");
174174
}
175+
ExprKind::ObsoleteInPlace(..) => {
176+
self.err_handler()
177+
.struct_span_err(expr.span, "emplacement syntax is obsolete (for now, anyway)")
178+
.note("for more information, see <https://github.com/rust-lang/rust/issues/27779#issuecomment-378416911>")
179+
.emit();
180+
}
175181
_ => {}
176182
}
177183

src/libsyntax/ast.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,7 @@ impl Expr {
10081008
pub fn precedence(&self) -> ExprPrecedence {
10091009
match self.node {
10101010
ExprKind::Box(_) => ExprPrecedence::Box,
1011+
ExprKind::ObsoleteInPlace(..) => ExprPrecedence::ObsoleteInPlace,
10111012
ExprKind::Array(_) => ExprPrecedence::Array,
10121013
ExprKind::Call(..) => ExprPrecedence::Call,
10131014
ExprKind::MethodCall(..) => ExprPrecedence::MethodCall,
@@ -1066,6 +1067,8 @@ pub enum RangeLimits {
10661067
pub enum ExprKind {
10671068
/// A `box x` expression.
10681069
Box(P<Expr>),
1070+
/// First expr is the place; second expr is the value.
1071+
ObsoleteInPlace(P<Expr>, P<Expr>),
10691072
/// An array (`[a, b, c, d]`)
10701073
Array(Vec<P<Expr>>),
10711074
/// A function call

src/libsyntax/feature_gate.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1684,6 +1684,9 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
16841684
gate_feature_post!(&self, type_ascription, e.span,
16851685
"type ascription is experimental");
16861686
}
1687+
ast::ExprKind::ObsoleteInPlace(..) => {
1688+
// these get a hard error in ast-validation
1689+
}
16871690
ast::ExprKind::Yield(..) => {
16881691
gate_feature_post!(&self, generators,
16891692
e.span,

src/libsyntax/fold.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,9 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span, attrs}: Expr, folder: &mu
11941194
ExprKind::Box(e) => {
11951195
ExprKind::Box(folder.fold_expr(e))
11961196
}
1197+
ExprKind::ObsoleteInPlace(a, b) => {
1198+
ExprKind::ObsoleteInPlace(folder.fold_expr(a), folder.fold_expr(b))
1199+
}
11971200
ExprKind::Array(exprs) => {
11981201
ExprKind::Array(folder.fold_exprs(exprs))
11991202
}

src/libsyntax/parse/parser.rs

+13
Original file line numberDiff line numberDiff line change
@@ -2839,6 +2839,17 @@ impl<'a> Parser<'a> {
28392839
let (span, e) = self.interpolated_or_expr_span(e)?;
28402840
(lo.to(span), ExprKind::AddrOf(m, e))
28412841
}
2842+
token::Ident(..) if self.token.is_keyword(keywords::In) => {
2843+
self.bump();
2844+
let place = self.parse_expr_res(
2845+
Restrictions::NO_STRUCT_LITERAL,
2846+
None,
2847+
)?;
2848+
let blk = self.parse_block()?;
2849+
let span = blk.span;
2850+
let blk_expr = self.mk_expr(span, ExprKind::Block(blk, None), ThinVec::new());
2851+
(lo.to(span), ExprKind::ObsoleteInPlace(place, blk_expr))
2852+
}
28422853
token::Ident(..) if self.token.is_keyword(keywords::Box) => {
28432854
self.bump();
28442855
let e = self.parse_prefix_expr(None);
@@ -3042,6 +3053,8 @@ impl<'a> Parser<'a> {
30423053
}
30433054
AssocOp::Assign =>
30443055
self.mk_expr(span, ExprKind::Assign(lhs, rhs), ThinVec::new()),
3056+
AssocOp::ObsoleteInPlace =>
3057+
self.mk_expr(span, ExprKind::ObsoleteInPlace(lhs, rhs), ThinVec::new()),
30453058
AssocOp::AssignOp(k) => {
30463059
let aop = match k {
30473060
token::Plus => BinOpKind::Add,

src/libsyntax/print/pprust.rs

+7
Original file line numberDiff line numberDiff line change
@@ -2057,6 +2057,13 @@ impl<'a> State<'a> {
20572057
self.word_space("box")?;
20582058
self.print_expr_maybe_paren(expr, parser::PREC_PREFIX)?;
20592059
}
2060+
ast::ExprKind::ObsoleteInPlace(ref place, ref expr) => {
2061+
let prec = AssocOp::ObsoleteInPlace.precedence() as i8;
2062+
self.print_expr_maybe_paren(place, prec + 1)?;
2063+
self.s.space()?;
2064+
self.word_space("<-")?;
2065+
self.print_expr_maybe_paren(expr, prec)?;
2066+
}
20602067
ast::ExprKind::Array(ref exprs) => {
20612068
self.print_expr_vec(&exprs[..], attrs)?;
20622069
}

src/libsyntax/util/parser.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ pub enum AssocOp {
5656
GreaterEqual,
5757
/// `=`
5858
Assign,
59+
/// `<-`
60+
ObsoleteInPlace,
5961
/// `?=` where ? is one of the BinOpToken
6062
AssignOp(BinOpToken),
6163
/// `as`
@@ -84,6 +86,7 @@ impl AssocOp {
8486
use self::AssocOp::*;
8587
match *t {
8688
Token::BinOpEq(k) => Some(AssignOp(k)),
89+
Token::LArrow => Some(ObsoleteInPlace),
8790
Token::Eq => Some(Assign),
8891
Token::BinOp(BinOpToken::Star) => Some(Multiply),
8992
Token::BinOp(BinOpToken::Slash) => Some(Divide),
@@ -153,6 +156,7 @@ impl AssocOp {
153156
LAnd => 6,
154157
LOr => 5,
155158
DotDot | DotDotEq => 4,
159+
ObsoleteInPlace => 3,
156160
Assign | AssignOp(_) => 2,
157161
}
158162
}
@@ -162,7 +166,7 @@ impl AssocOp {
162166
use self::AssocOp::*;
163167
// NOTE: it is a bug to have an operators that has same precedence but different fixities!
164168
match *self {
165-
Assign | AssignOp(_) => Fixity::Right,
169+
ObsoleteInPlace | Assign | AssignOp(_) => Fixity::Right,
166170
As | Multiply | Divide | Modulus | Add | Subtract | ShiftLeft | ShiftRight | BitAnd |
167171
BitXor | BitOr | Less | Greater | LessEqual | GreaterEqual | Equal | NotEqual |
168172
LAnd | LOr | Colon => Fixity::Left,
@@ -174,16 +178,16 @@ impl AssocOp {
174178
use self::AssocOp::*;
175179
match *self {
176180
Less | Greater | LessEqual | GreaterEqual | Equal | NotEqual => true,
177-
Assign | AssignOp(_) | As | Multiply | Divide | Modulus | Add | Subtract |
178-
ShiftLeft | ShiftRight | BitAnd | BitXor | BitOr | LAnd | LOr |
181+
ObsoleteInPlace | Assign | AssignOp(_) | As | Multiply | Divide | Modulus | Add |
182+
Subtract | ShiftLeft | ShiftRight | BitAnd | BitXor | BitOr | LAnd | LOr |
179183
DotDot | DotDotEq | Colon => false
180184
}
181185
}
182186

183187
pub fn is_assign_like(&self) -> bool {
184188
use self::AssocOp::*;
185189
match *self {
186-
Assign | AssignOp(_) => true,
190+
Assign | AssignOp(_) | ObsoleteInPlace => true,
187191
Less | Greater | LessEqual | GreaterEqual | Equal | NotEqual | As | Multiply | Divide |
188192
Modulus | Add | Subtract | ShiftLeft | ShiftRight | BitAnd | BitXor | BitOr | LAnd |
189193
LOr | DotDot | DotDotEq | Colon => false
@@ -211,7 +215,7 @@ impl AssocOp {
211215
BitOr => Some(BinOpKind::BitOr),
212216
LAnd => Some(BinOpKind::And),
213217
LOr => Some(BinOpKind::Or),
214-
Assign | AssignOp(_) | As | DotDot | DotDotEq | Colon => None
218+
ObsoleteInPlace | Assign | AssignOp(_) | As | DotDot | DotDotEq | Colon => None
215219
}
216220
}
217221
}
@@ -238,6 +242,7 @@ pub enum ExprPrecedence {
238242

239243
Binary(BinOpKind),
240244

245+
ObsoleteInPlace,
241246
Cast,
242247
Type,
243248

@@ -304,6 +309,7 @@ impl ExprPrecedence {
304309

305310
// Binop-like expr kinds, handled by `AssocOp`.
306311
ExprPrecedence::Binary(op) => AssocOp::from_ast_binop(op).precedence() as i8,
312+
ExprPrecedence::ObsoleteInPlace => AssocOp::ObsoleteInPlace.precedence() as i8,
307313
ExprPrecedence::Cast => AssocOp::As.precedence() as i8,
308314
ExprPrecedence::Type => AssocOp::Colon.precedence() as i8,
309315

src/libsyntax/visit.rs

+4
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,10 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
660660
ExprKind::Box(ref subexpression) => {
661661
visitor.visit_expr(subexpression)
662662
}
663+
ExprKind::ObsoleteInPlace(ref place, ref subexpression) => {
664+
visitor.visit_expr(place);
665+
visitor.visit_expr(subexpression)
666+
}
663667
ExprKind::Array(ref subexpressions) => {
664668
walk_list!(visitor, visit_expr, subexpressions);
665669
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error: emplacement syntax is obsolete (for now, anyway)
2+
--> $DIR/bad.rs:19:5
3+
|
4+
LL | x <- y; //[bad]~ ERROR emplacement syntax is obsolete
5+
| ^^^^^^
6+
|
7+
= note: for more information, see <https://github.com/rust-lang/rust/issues/27779#issuecomment-378416911>
8+
9+
error: emplacement syntax is obsolete (for now, anyway)
10+
--> $DIR/bad.rs:20:5
11+
|
12+
LL | in(foo) { bar }; //[bad]~ ERROR emplacement syntax is obsolete
13+
| ^^^^^^^^^^^^^^^
14+
|
15+
= note: for more information, see <https://github.com/rust-lang/rust/issues/27779#issuecomment-378416911>
16+
17+
error: aborting due to 2 previous errors
18+

src/test/ui/obsolete-in-place/bad.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Check that `<-` and `in` syntax gets a hard error.
12+
13+
// revisions: good bad
14+
//[good] run-pass
15+
16+
#[cfg(bad)]
17+
fn main() {
18+
let (x, y, foo, bar);
19+
x <- y; //[bad]~ ERROR emplacement syntax is obsolete
20+
in(foo) { bar }; //[bad]~ ERROR emplacement syntax is obsolete
21+
}
22+
23+
#[cfg(good)]
24+
fn main() {
25+
}

0 commit comments

Comments
 (0)