Skip to content

Commit d96c01e

Browse files
committed
Auto merge of #60803 - varkor:remove-in-place-syntax, r=petrochenkov
Remove `ObsoleteInPlace` The in place syntax has been deprecated for over a year. As it is, this is accumulated cruft: the error messages are unlikely to be helpful any more and it conflicts with some useful syntax (e.g. const generics in some instances). It may be that removing `Token::LArrow` is backwards-incompatible. We should do a crater run to check. cc @eddyb
2 parents 4680580 + 36f6542 commit d96c01e

File tree

15 files changed

+55
-108
lines changed

15 files changed

+55
-108
lines changed

src/librustc/hir/lowering.rs

-4
Original file line numberDiff line numberDiff line change
@@ -4062,10 +4062,6 @@ impl<'a> LoweringContext<'a> {
40624062
fn lower_expr(&mut self, e: &Expr) -> hir::Expr {
40634063
let kind = match e.node {
40644064
ExprKind::Box(ref inner) => hir::ExprKind::Box(P(self.lower_expr(inner))),
4065-
ExprKind::ObsoleteInPlace(..) => {
4066-
self.sess.abort_if_errors();
4067-
span_bug!(e.span, "encountered ObsoleteInPlace expr during lowering");
4068-
}
40694065
ExprKind::Array(ref exprs) => {
40704066
hir::ExprKind::Array(exprs.iter().map(|x| self.lower_expr(x)).collect())
40714067
}

src/librustc_passes/ast_validation.rs

-23
Original file line numberDiff line numberDiff line change
@@ -454,29 +454,6 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
454454
ExprKind::InlineAsm(..) if !self.session.target.target.options.allow_asm => {
455455
span_err!(self.session, expr.span, E0472, "asm! is unsupported on this target");
456456
}
457-
ExprKind::ObsoleteInPlace(ref place, ref val) => {
458-
let mut err = self.err_handler().struct_span_err(
459-
expr.span,
460-
"emplacement syntax is obsolete (for now, anyway)",
461-
);
462-
err.note(
463-
"for more information, see \
464-
<https://github.com/rust-lang/rust/issues/27779#issuecomment-378416911>"
465-
);
466-
match val.node {
467-
ExprKind::Lit(ref v) if v.node.is_numeric() => {
468-
err.span_suggestion(
469-
place.span.between(val.span),
470-
"if you meant to write a comparison against a negative value, add a \
471-
space in between `<` and `-`",
472-
"< -".to_string(),
473-
Applicability::MaybeIncorrect
474-
);
475-
}
476-
_ => {}
477-
}
478-
err.emit();
479-
}
480457
_ => {}
481458
}
482459

src/libsyntax/ast.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,6 @@ impl Expr {
10371037
pub fn precedence(&self) -> ExprPrecedence {
10381038
match self.node {
10391039
ExprKind::Box(_) => ExprPrecedence::Box,
1040-
ExprKind::ObsoleteInPlace(..) => ExprPrecedence::ObsoleteInPlace,
10411040
ExprKind::Array(_) => ExprPrecedence::Array,
10421041
ExprKind::Call(..) => ExprPrecedence::Call,
10431042
ExprKind::MethodCall(..) => ExprPrecedence::MethodCall,
@@ -1099,8 +1098,6 @@ pub enum RangeLimits {
10991098
pub enum ExprKind {
11001099
/// A `box x` expression.
11011100
Box(P<Expr>),
1102-
/// First expr is the place; second expr is the value.
1103-
ObsoleteInPlace(P<Expr>, P<Expr>),
11041101
/// An array (`[a, b, c, d]`)
11051102
Array(Vec<P<Expr>>),
11061103
/// A function call

src/libsyntax/feature_gate.rs

-3
Original file line numberDiff line numberDiff line change
@@ -2117,9 +2117,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
21172117
"type ascription is experimental");
21182118
}
21192119
}
2120-
ast::ExprKind::ObsoleteInPlace(..) => {
2121-
// these get a hard error in ast-validation
2122-
}
21232120
ast::ExprKind::Yield(..) => {
21242121
gate_feature_post!(&self, generators,
21252122
e.span,

src/libsyntax/mut_visit.rs

-4
Original file line numberDiff line numberDiff line change
@@ -1099,10 +1099,6 @@ pub fn noop_visit_anon_const<T: MutVisitor>(AnonConst { id, value }: &mut AnonCo
10991099
pub fn noop_visit_expr<T: MutVisitor>(Expr { node, id, span, attrs }: &mut Expr, vis: &mut T) {
11001100
match node {
11011101
ExprKind::Box(expr) => vis.visit_expr(expr),
1102-
ExprKind::ObsoleteInPlace(a, b) => {
1103-
vis.visit_expr(a);
1104-
vis.visit_expr(b);
1105-
}
11061102
ExprKind::Array(exprs) => visit_exprs(exprs, vis),
11071103
ExprKind::Repeat(expr, count) => {
11081104
vis.visit_expr(expr);

src/libsyntax/parse/parser.rs

-16
Original file line numberDiff line numberDiff line change
@@ -3252,17 +3252,6 @@ impl<'a> Parser<'a> {
32523252
let (span, e) = self.interpolated_or_expr_span(e)?;
32533253
(lo.to(span), ExprKind::AddrOf(m, e))
32543254
}
3255-
token::Ident(..) if self.token.is_keyword(kw::In) => {
3256-
self.bump();
3257-
let place = self.parse_expr_res(
3258-
Restrictions::NO_STRUCT_LITERAL,
3259-
None,
3260-
)?;
3261-
let blk = self.parse_block()?;
3262-
let span = blk.span;
3263-
let blk_expr = self.mk_expr(span, ExprKind::Block(blk, None), ThinVec::new());
3264-
(lo.to(span), ExprKind::ObsoleteInPlace(place, blk_expr))
3265-
}
32663255
token::Ident(..) if self.token.is_keyword(kw::Box) => {
32673256
self.bump();
32683257
let e = self.parse_prefix_expr(None);
@@ -3500,8 +3489,6 @@ impl<'a> Parser<'a> {
35003489
self.mk_expr(span, binary, ThinVec::new())
35013490
}
35023491
AssocOp::Assign => self.mk_expr(span, ExprKind::Assign(lhs, rhs), ThinVec::new()),
3503-
AssocOp::ObsoleteInPlace =>
3504-
self.mk_expr(span, ExprKind::ObsoleteInPlace(lhs, rhs), ThinVec::new()),
35053492
AssocOp::AssignOp(k) => {
35063493
let aop = match k {
35073494
token::Plus => BinOpKind::Add,
@@ -3820,9 +3807,6 @@ impl<'a> Parser<'a> {
38203807
String::new(),
38213808
Applicability::MachineApplicable,
38223809
);
3823-
err.note("if you meant to use emplacement syntax, it is obsolete (for now, anyway)");
3824-
err.note("for more information on the status of emplacement syntax, see <\
3825-
https://github.com/rust-lang/rust/issues/27779#issuecomment-378416911>");
38263810
err.emit();
38273811
}
38283812
let expr = self.parse_expr_res(Restrictions::NO_STRUCT_LITERAL, None)?;

src/libsyntax/print/pprust.rs

-7
Original file line numberDiff line numberDiff line change
@@ -2005,13 +2005,6 @@ impl<'a> State<'a> {
20052005
self.word_space("box")?;
20062006
self.print_expr_maybe_paren(expr, parser::PREC_PREFIX)?;
20072007
}
2008-
ast::ExprKind::ObsoleteInPlace(ref place, ref expr) => {
2009-
let prec = AssocOp::ObsoleteInPlace.precedence() as i8;
2010-
self.print_expr_maybe_paren(place, prec + 1)?;
2011-
self.s.space()?;
2012-
self.word_space("<-")?;
2013-
self.print_expr_maybe_paren(expr, prec)?;
2014-
}
20152008
ast::ExprKind::Array(ref exprs) => {
20162009
self.print_expr_vec(&exprs[..], attrs)?;
20172010
}

src/libsyntax/util/parser.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ pub enum AssocOp {
4545
GreaterEqual,
4646
/// `=`
4747
Assign,
48-
/// `<-`
49-
ObsoleteInPlace,
5048
/// `?=` where ? is one of the BinOpToken
5149
AssignOp(BinOpToken),
5250
/// `as`
@@ -75,7 +73,6 @@ impl AssocOp {
7573
use AssocOp::*;
7674
match *t {
7775
Token::BinOpEq(k) => Some(AssignOp(k)),
78-
Token::LArrow => Some(ObsoleteInPlace),
7976
Token::Eq => Some(Assign),
8077
Token::BinOp(BinOpToken::Star) => Some(Multiply),
8178
Token::BinOp(BinOpToken::Slash) => Some(Divide),
@@ -145,7 +142,6 @@ impl AssocOp {
145142
LAnd => 6,
146143
LOr => 5,
147144
DotDot | DotDotEq => 4,
148-
ObsoleteInPlace => 3,
149145
Assign | AssignOp(_) => 2,
150146
}
151147
}
@@ -155,7 +151,7 @@ impl AssocOp {
155151
use AssocOp::*;
156152
// NOTE: it is a bug to have an operators that has same precedence but different fixities!
157153
match *self {
158-
ObsoleteInPlace | Assign | AssignOp(_) => Fixity::Right,
154+
Assign | AssignOp(_) => Fixity::Right,
159155
As | Multiply | Divide | Modulus | Add | Subtract | ShiftLeft | ShiftRight | BitAnd |
160156
BitXor | BitOr | Less | Greater | LessEqual | GreaterEqual | Equal | NotEqual |
161157
LAnd | LOr | Colon => Fixity::Left,
@@ -167,7 +163,7 @@ impl AssocOp {
167163
use AssocOp::*;
168164
match *self {
169165
Less | Greater | LessEqual | GreaterEqual | Equal | NotEqual => true,
170-
ObsoleteInPlace | Assign | AssignOp(_) | As | Multiply | Divide | Modulus | Add |
166+
Assign | AssignOp(_) | As | Multiply | Divide | Modulus | Add |
171167
Subtract | ShiftLeft | ShiftRight | BitAnd | BitXor | BitOr | LAnd | LOr |
172168
DotDot | DotDotEq | Colon => false
173169
}
@@ -176,7 +172,7 @@ impl AssocOp {
176172
pub fn is_assign_like(&self) -> bool {
177173
use AssocOp::*;
178174
match *self {
179-
Assign | AssignOp(_) | ObsoleteInPlace => true,
175+
Assign | AssignOp(_) => true,
180176
Less | Greater | LessEqual | GreaterEqual | Equal | NotEqual | As | Multiply | Divide |
181177
Modulus | Add | Subtract | ShiftLeft | ShiftRight | BitAnd | BitXor | BitOr | LAnd |
182178
LOr | DotDot | DotDotEq | Colon => false
@@ -204,7 +200,7 @@ impl AssocOp {
204200
BitOr => Some(BinOpKind::BitOr),
205201
LAnd => Some(BinOpKind::And),
206202
LOr => Some(BinOpKind::Or),
207-
ObsoleteInPlace | Assign | AssignOp(_) | As | DotDot | DotDotEq | Colon => None
203+
Assign | AssignOp(_) | As | DotDot | DotDotEq | Colon => None
208204
}
209205
}
210206

@@ -256,7 +252,6 @@ pub enum ExprPrecedence {
256252

257253
Binary(BinOpKind),
258254

259-
ObsoleteInPlace,
260255
Cast,
261256
Type,
262257

@@ -314,7 +309,6 @@ impl ExprPrecedence {
314309

315310
// Binop-like expr kinds, handled by `AssocOp`.
316311
ExprPrecedence::Binary(op) => AssocOp::from_ast_binop(op).precedence() as i8,
317-
ExprPrecedence::ObsoleteInPlace => AssocOp::ObsoleteInPlace.precedence() as i8,
318312
ExprPrecedence::Cast => AssocOp::As.precedence() as i8,
319313
ExprPrecedence::Type => AssocOp::Colon.precedence() as i8,
320314

src/libsyntax/visit.rs

-4
Original file line numberDiff line numberDiff line change
@@ -676,10 +676,6 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
676676
ExprKind::Box(ref subexpression) => {
677677
visitor.visit_expr(subexpression)
678678
}
679-
ExprKind::ObsoleteInPlace(ref place, ref subexpression) => {
680-
visitor.visit_expr(place);
681-
visitor.visit_expr(subexpression)
682-
}
683679
ExprKind::Array(ref subexpressions) => {
684680
walk_list!(visitor, visit_expr, subexpressions);
685681
}
+12-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
error: emplacement syntax is obsolete (for now, anyway)
2-
--> $DIR/bad.rs:9:5
3-
|
4-
LL | x <- y;
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)
1+
error: expected expression, found keyword `in`
102
--> $DIR/bad.rs:10:5
113
|
124
LL | in(foo) { bar };
13-
| ^^^^^^^^^^^^^^^
5+
| ^^ expected expression
6+
7+
error[E0282]: type annotations needed
8+
--> $DIR/bad.rs:9:8
9+
|
10+
LL | let (x, y, foo, bar);
11+
| ---------------- consider giving the pattern a type
12+
LL | x <- y;
13+
| ^^^ cannot infer type
1414
|
15-
= note: for more information, see <https://github.com/rust-lang/rust/issues/27779#issuecomment-378416911>
15+
= note: type must be known at this point
1616

1717
error: aborting due to 2 previous errors
1818

19+
For more information about this error, try `rustc --explain E0282`.

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

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
// Check that `<-` and `in` syntax gets a hard error.
22

3-
// revisions: good bad
4-
//[good] run-pass
5-
6-
#[cfg(bad)]
7-
fn main() {
8-
let (x, y, foo, bar);
9-
x <- y; //[bad]~ ERROR emplacement syntax is obsolete
10-
in(foo) { bar }; //[bad]~ ERROR emplacement syntax is obsolete
3+
fn foo() {
4+
let (x, y) = (0, 0);
5+
x <- y; //~ ERROR expected one of
6+
//~^ ERROR mismatched types
117
}
128

13-
#[cfg(good)]
149
fn main() {
10+
let (foo, bar) = (0, 0);
11+
in(foo) { bar }; //~ ERROR expected expression, found keyword `in`
1512
}
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `<-`
2+
--> $DIR/bad.rs:5:7
3+
|
4+
LL | x <- y;
5+
| ^^ expected one of 8 possible tokens here
6+
7+
error: expected expression, found keyword `in`
8+
--> $DIR/bad.rs:11:5
9+
|
10+
LL | in(foo) { bar };
11+
| ^^ expected expression
12+
13+
error[E0308]: mismatched types
14+
--> $DIR/bad.rs:5:5
15+
|
16+
LL | fn foo() {
17+
| - possibly return type missing here?
18+
LL | let (x, y) = (0, 0);
19+
LL | x <- y;
20+
| ^ expected (), found integer
21+
|
22+
= note: expected type `()`
23+
found type `{integer}`
24+
25+
error: aborting due to 3 previous errors
26+
27+
For more information about this error, try `rustc --explain E0308`.

src/test/ui/parser/if-in-in.stderr

-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ LL | for i in in 1..2 {
55
| ---^^
66
| |
77
| help: remove the duplicated `in`
8-
|
9-
= note: if you meant to use emplacement syntax, it is obsolete (for now, anyway)
10-
= note: for more information on the status of emplacement syntax, see <https://github.com/rust-lang/rust/issues/27779#issuecomment-378416911>
118

129
error: aborting due to previous error
1310

src/test/ui/placement-syntax.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
fn main() {
22
let x = -5;
3-
if x<-1 {
4-
//~^ ERROR emplacement syntax is obsolete
3+
if x<-1 { //~ ERROR expected `{`, found `<-`
54
println!("ok");
65
}
76
}

src/test/ui/placement-syntax.stderr

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
error: emplacement syntax is obsolete (for now, anyway)
2-
--> $DIR/placement-syntax.rs:3:8
1+
error: expected `{`, found `<-`
2+
--> $DIR/placement-syntax.rs:3:9
33
|
44
LL | if x<-1 {
5-
| ^^^^
6-
|
7-
= note: for more information, see <https://github.com/rust-lang/rust/issues/27779#issuecomment-378416911>
8-
help: if you meant to write a comparison against a negative value, add a space in between `<` and `-`
9-
|
10-
LL | if x< -1 {
11-
| ^^^
5+
| -- ^^ expected `{`
6+
| |
7+
| this `if` statement has a condition, but no block
128

139
error: aborting due to previous error
1410

0 commit comments

Comments
 (0)