Skip to content

Commit 35979a9

Browse files
committed
Add span information to ExprKind::Assign
1 parent 5ab4735 commit 35979a9

File tree

25 files changed

+69
-62
lines changed

25 files changed

+69
-62
lines changed

src/librustc/hir/intravisit.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1043,9 +1043,9 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
10431043
walk_list!(visitor, visit_label, opt_label);
10441044
visitor.visit_block(block);
10451045
}
1046-
ExprKind::Assign(ref left_hand_expression, ref right_hand_expression) => {
1047-
visitor.visit_expr(right_hand_expression);
1048-
visitor.visit_expr(left_hand_expression)
1046+
ExprKind::Assign(ref lhs, ref rhs, _) => {
1047+
visitor.visit_expr(rhs);
1048+
visitor.visit_expr(lhs)
10491049
}
10501050
ExprKind::AssignOp(_, ref left_expression, ref right_expression) => {
10511051
visitor.visit_expr(right_expression);

src/librustc/hir/lowering/expr.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ impl LoweringContext<'_, '_> {
122122
self.lower_block(blk, opt_label.is_some()),
123123
self.lower_label(opt_label),
124124
),
125-
ExprKind::Assign(ref el, ref er) => {
126-
hir::ExprKind::Assign(P(self.lower_expr(el)), P(self.lower_expr(er)))
125+
ExprKind::Assign(ref el, ref er, span) => {
126+
hir::ExprKind::Assign(P(self.lower_expr(el)), P(self.lower_expr(er)), span)
127127
}
128128
ExprKind::AssignOp(op, ref el, ref er) => hir::ExprKind::AssignOp(
129129
self.lower_binop(op),
@@ -994,8 +994,11 @@ impl LoweringContext<'_, '_> {
994994
let (val_pat, val_pat_hid) = self.pat_ident(pat.span, val_ident);
995995
let val_expr = P(self.expr_ident(pat.span, val_ident, val_pat_hid));
996996
let next_expr = P(self.expr_ident(pat.span, next_ident, next_pat_hid));
997-
let assign =
998-
P(self.expr(pat.span, hir::ExprKind::Assign(next_expr, val_expr), ThinVec::new()));
997+
let assign = P(self.expr(
998+
pat.span,
999+
hir::ExprKind::Assign(next_expr, val_expr, pat.span),
1000+
ThinVec::new(),
1001+
));
9991002
let some_pat = self.pat_some(pat.span, val_pat);
10001003
self.arm(some_pat, assign)
10011004
};

src/librustc/hir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1628,7 +1628,7 @@ pub enum ExprKind {
16281628
Block(P<Block>, Option<Label>),
16291629

16301630
/// An assignment (e.g., `a = foo()`).
1631-
Assign(P<Expr>, P<Expr>),
1631+
Assign(P<Expr>, P<Expr>, Span),
16321632
/// An assignment with an operator.
16331633
///
16341634
/// E.g., `a += 1`.

src/librustc/hir/print.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,7 @@ impl<'a> State<'a> {
12891289
self.ibox(0);
12901290
self.print_block(&blk);
12911291
}
1292-
hir::ExprKind::Assign(ref lhs, ref rhs) => {
1292+
hir::ExprKind::Assign(ref lhs, ref rhs, _) => {
12931293
let prec = AssocOp::Assign.precedence() as i8;
12941294
self.print_expr_maybe_paren(&lhs, prec + 1);
12951295
self.s.space();
@@ -2265,7 +2265,7 @@ fn contains_exterior_struct_lit(value: &hir::Expr) -> bool {
22652265
match value.kind {
22662266
hir::ExprKind::Struct(..) => true,
22672267

2268-
hir::ExprKind::Assign(ref lhs, ref rhs)
2268+
hir::ExprKind::Assign(ref lhs, ref rhs, _)
22692269
| hir::ExprKind::AssignOp(_, ref lhs, ref rhs)
22702270
| hir::ExprKind::Binary(_, ref lhs, ref rhs) => {
22712271
// `X { y: 1 } + X { y: 2 }`

src/librustc_lint/unused.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ impl EarlyLintPass for UnusedParens {
490490
(value, "`return` value", false, Some(left), None)
491491
}
492492

493-
Assign(_, ref value) => (value, "assigned value", false, None, None),
493+
Assign(_, ref value, _) => (value, "assigned value", false, None, None),
494494
AssignOp(.., ref value) => (value, "assigned value", false, None, None),
495495
// either function/method call, or something this lint doesn't care about
496496
ref call_or_other => {

src/librustc_mir/hair/cx/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ fn make_mirror_unadjusted<'a, 'tcx>(cx: &mut Cx<'a, 'tcx>, expr: &'tcx hir::Expr
227227

228228
hir::ExprKind::Block(ref blk, _) => ExprKind::Block { body: &blk },
229229

230-
hir::ExprKind::Assign(ref lhs, ref rhs) => {
230+
hir::ExprKind::Assign(ref lhs, ref rhs, _) => {
231231
ExprKind::Assign { lhs: lhs.to_ref(), rhs: rhs.to_ref() }
232232
}
233233

src/librustc_parse/parser/expr.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,9 @@ impl<'a> Parser<'a> {
281281
let binary = self.mk_binary(source_map::respan(cur_op_span, ast_op), lhs, rhs);
282282
self.mk_expr(span, binary, AttrVec::new())
283283
}
284-
AssocOp::Assign => self.mk_expr(span, ExprKind::Assign(lhs, rhs), AttrVec::new()),
284+
AssocOp::Assign => {
285+
self.mk_expr(span, ExprKind::Assign(lhs, rhs, cur_op_span), AttrVec::new())
286+
}
285287
AssocOp::AssignOp(k) => {
286288
let aop = match k {
287289
token::Plus => BinOpKind::Add,

src/librustc_passes/liveness.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
10791079
.unwrap_or_else(|| span_bug!(expr.span, "continue to unknown label"))
10801080
}
10811081

1082-
hir::ExprKind::Assign(ref l, ref r) => {
1082+
hir::ExprKind::Assign(ref l, ref r, _) => {
10831083
// see comment on places in
10841084
// propagate_through_place_components()
10851085
let succ = self.write_place(&l, succ, ACC_WRITE);
@@ -1373,7 +1373,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Liveness<'a, 'tcx> {
13731373

13741374
fn check_expr<'tcx>(this: &mut Liveness<'_, 'tcx>, expr: &'tcx Expr) {
13751375
match expr.kind {
1376-
hir::ExprKind::Assign(ref l, _) => {
1376+
hir::ExprKind::Assign(ref l, ..) => {
13771377
this.check_place(&l);
13781378
}
13791379

src/librustc_privacy/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> {
12511251
return;
12521252
}
12531253
match expr.kind {
1254-
hir::ExprKind::Assign(.., ref rhs) | hir::ExprKind::Match(ref rhs, ..) => {
1254+
hir::ExprKind::Assign(_, ref rhs, _) | hir::ExprKind::Match(ref rhs, ..) => {
12551255
// Do not report duplicate errors for `x = y` and `match x { ... }`.
12561256
if self.check_expr_pat_type(rhs.hir_id, rhs.span) {
12571257
return;

src/librustc_typeck/check/demand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
492492
String::new()
493493
};
494494
if let Some(hir::Node::Expr(hir::Expr {
495-
kind: hir::ExprKind::Assign(left_expr, _),
495+
kind: hir::ExprKind::Assign(left_expr, ..),
496496
..
497497
})) = self.tcx.hir().find(self.tcx.hir().get_parent_node(expr.hir_id))
498498
{

src/librustc_typeck/check/expr.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
219219
ExprKind::Box(ref subexpr) => self.check_expr_box(subexpr, expected),
220220
ExprKind::Lit(ref lit) => self.check_lit(&lit, expected),
221221
ExprKind::Binary(op, ref lhs, ref rhs) => self.check_binop(expr, op, lhs, rhs),
222-
ExprKind::AssignOp(op, ref lhs, ref rhs) => self.check_binop_assign(expr, op, lhs, rhs),
222+
ExprKind::Assign(ref lhs, ref rhs, ref span) => {
223+
self.check_binop_assign(expr, op, lhs, rhs)
224+
}
223225
ExprKind::Unary(unop, ref oprnd) => {
224226
self.check_expr_unary(unop, oprnd, expected, needs, expr)
225227
}
@@ -245,7 +247,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
245247
}
246248
}
247249
ExprKind::Ret(ref expr_opt) => self.check_expr_return(expr_opt.as_deref(), expr),
248-
ExprKind::Assign(ref lhs, ref rhs) => self.check_expr_assign(expr, expected, lhs, rhs),
249250
ExprKind::Loop(ref body, _, source) => {
250251
self.check_expr_loop(body, source, expected, expr)
251252
}
@@ -767,6 +768,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
767768
expected: Expectation<'tcx>,
768769
lhs: &'tcx hir::Expr,
769770
rhs: &'tcx hir::Expr,
771+
span: &Span,
770772
) -> Ty<'tcx> {
771773
let lhs_ty = self.check_expr_with_needs(&lhs, Needs::MutPlace);
772774
let rhs_ty = self.check_expr_coercable_to_type(&rhs, lhs_ty);
@@ -789,7 +791,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
789791
}
790792
err.emit();
791793
} else {
792-
self.check_lhs_assignable(lhs, "E0070", &expr.span);
794+
self.check_lhs_assignable(lhs, "E0070", span);
793795
}
794796

795797
self.require_type_is_sized(lhs_ty, lhs.span, traits::AssignmentLhsSized);

src/librustc_typeck/expr_use_visitor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
286286
}
287287
}
288288

289-
hir::ExprKind::Assign(ref lhs, ref rhs) => {
289+
hir::ExprKind::Assign(ref lhs, ref rhs, _) => {
290290
self.mutate_expr(lhs);
291291
self.consume_expr(rhs);
292292
}

src/libsyntax/ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,7 @@ pub enum ExprKind {
12161216
TryBlock(P<Block>),
12171217

12181218
/// An assignment (`a = foo()`).
1219-
Assign(P<Expr>, P<Expr>),
1219+
Assign(P<Expr>, P<Expr>, Span),
12201220
/// An assignment with an operator.
12211221
///
12221222
/// E.g., `a += 1`.

src/libsyntax/mut_visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,7 @@ pub fn noop_visit_expr<T: MutVisitor>(Expr { kind, id, span, attrs }: &mut Expr,
11681168
vis.visit_block(body);
11691169
}
11701170
ExprKind::Await(expr) => vis.visit_expr(expr),
1171-
ExprKind::Assign(el, er) => {
1171+
ExprKind::Assign(el, er, _) => {
11721172
vis.visit_expr(el);
11731173
vis.visit_expr(er);
11741174
}

src/libsyntax/print/pprust.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2041,7 +2041,7 @@ impl<'a> State<'a> {
20412041
self.print_expr_maybe_paren(expr, parser::PREC_POSTFIX);
20422042
self.s.word(".await");
20432043
}
2044-
ast::ExprKind::Assign(ref lhs, ref rhs) => {
2044+
ast::ExprKind::Assign(ref lhs, ref rhs, _) => {
20452045
let prec = AssocOp::Assign.precedence() as i8;
20462046
self.print_expr_maybe_paren(lhs, prec + 1);
20472047
self.s.space();

src/libsyntax/util/parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ pub fn contains_exterior_struct_lit(value: &ast::Expr) -> bool {
378378
match value.kind {
379379
ast::ExprKind::Struct(..) => true,
380380

381-
ast::ExprKind::Assign(ref lhs, ref rhs)
381+
ast::ExprKind::Assign(ref lhs, ref rhs, _)
382382
| ast::ExprKind::AssignOp(_, ref lhs, ref rhs)
383383
| ast::ExprKind::Binary(_, ref lhs, ref rhs) => {
384384
// X { y: 1 } + X { y: 2 }

src/libsyntax/visit.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -766,9 +766,9 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
766766
visitor.visit_block(body);
767767
}
768768
ExprKind::Await(ref expr) => visitor.visit_expr(expr),
769-
ExprKind::Assign(ref left_hand_expression, ref right_hand_expression) => {
770-
visitor.visit_expr(left_hand_expression);
771-
visitor.visit_expr(right_hand_expression);
769+
ExprKind::Assign(ref lhs, ref rhs, _) => {
770+
visitor.visit_expr(lhs);
771+
visitor.visit_expr(rhs);
772772
}
773773
ExprKind::AssignOp(_, ref left_expression, ref right_expression) => {
774774
visitor.visit_expr(left_expression);

src/test/ui-fulldeps/pprust-expr-roundtrip.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ fn iter_exprs(depth: usize, f: &mut dyn FnMut(P<Expr>)) {
126126
DUMMY_SP)));
127127
},
128128
12 => {
129-
iter_exprs(depth - 1, &mut |e| g(ExprKind::Assign(e, make_x())));
130-
iter_exprs(depth - 1, &mut |e| g(ExprKind::Assign(make_x(), e)));
129+
iter_exprs(depth - 1, &mut |e| g(ExprKind::Assign(e, make_x(), DUMMY_SP)));
130+
iter_exprs(depth - 1, &mut |e| g(ExprKind::Assign(make_x(), e, DUMMY_SP)));
131131
},
132132
13 => {
133133
iter_exprs(depth - 1, &mut |e| g(ExprKind::Field(e, Ident::from_str("f"))));

src/test/ui/bad/bad-expr-lhs.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0070]: invalid left-hand side of assignment
2-
--> $DIR/bad-expr-lhs.rs:2:5
2+
--> $DIR/bad-expr-lhs.rs:2:7
33
|
44
LL | 1 = 2;
5-
| -^^^^
5+
| - ^
66
| |
77
| cannot assign to this expression
88

@@ -15,29 +15,29 @@ LL | 1 += 2;
1515
| cannot assign to this expression
1616

1717
error[E0070]: invalid left-hand side of assignment
18-
--> $DIR/bad-expr-lhs.rs:4:5
18+
--> $DIR/bad-expr-lhs.rs:4:12
1919
|
2020
LL | (1, 2) = (3, 4);
21-
| ------^^^^^^^^^
21+
| ------ ^
2222
| |
2323
| cannot assign to this expression
2424

2525
error[E0070]: invalid left-hand side of assignment
26-
--> $DIR/bad-expr-lhs.rs:7:5
26+
--> $DIR/bad-expr-lhs.rs:7:12
2727
|
2828
LL | (a, b) = (3, 4);
29-
| ------^^^^^^^^^
29+
| ------ ^
3030
| |
3131
| cannot assign to this expression
3232
|
3333
= note: destructuring assignments are not yet supported
3434
= note: for more information, see https://github.com/rust-lang/rfcs/issues/372
3535

3636
error[E0070]: invalid left-hand side of assignment
37-
--> $DIR/bad-expr-lhs.rs:9:5
37+
--> $DIR/bad-expr-lhs.rs:9:10
3838
|
3939
LL | None = Some(3);
40-
| ----^^^^^^^^^^
40+
| ---- ^
4141
| |
4242
| cannot assign to this expression
4343

src/test/ui/bad/destructuring-assignment.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0070]: invalid left-hand side of assignment
2-
--> $DIR/destructuring-assignment.rs:6:5
2+
--> $DIR/destructuring-assignment.rs:6:12
33
|
44
LL | (a, b) = (3, 4);
5-
| ------^^^^^^^^^
5+
| ------ ^
66
| |
77
| cannot assign to this expression
88
|
@@ -31,10 +31,10 @@ LL | (a, b) += (3, 4);
3131
= note: for more information, see https://github.com/rust-lang/rfcs/issues/372
3232

3333
error[E0070]: invalid left-hand side of assignment
34-
--> $DIR/destructuring-assignment.rs:10:5
34+
--> $DIR/destructuring-assignment.rs:10:12
3535
|
3636
LL | [a, b] = [3, 4];
37-
| ------^^^^^^^^^
37+
| ------ ^
3838
| |
3939
| cannot assign to this expression
4040
|
@@ -63,10 +63,10 @@ LL | [a, b] += [3, 4];
6363
= note: for more information, see https://github.com/rust-lang/rfcs/issues/372
6464

6565
error[E0070]: invalid left-hand side of assignment
66-
--> $DIR/destructuring-assignment.rs:16:5
66+
--> $DIR/destructuring-assignment.rs:16:22
6767
|
6868
LL | S { x: a, y: b } = s;
69-
| ----------------^^^^
69+
| ---------------- ^
7070
| |
7171
| cannot assign to this expression
7272
|
@@ -95,21 +95,21 @@ LL | S { x: a, y: b } += s;
9595
= note: for more information, see https://github.com/rust-lang/rfcs/issues/372
9696

9797
error[E0070]: invalid left-hand side of assignment
98-
--> $DIR/destructuring-assignment.rs:20:5
98+
--> $DIR/destructuring-assignment.rs:20:21
9999
|
100100
LL | S { x: a, ..s } = S { x: 3, y: 4 };
101-
| ---------------^^^^^^^^^^^^^^^^^^^
101+
| --------------- ^
102102
| |
103103
| cannot assign to this expression
104104
|
105105
= note: destructuring assignments are not yet supported
106106
= note: for more information, see https://github.com/rust-lang/rfcs/issues/372
107107

108108
error[E0070]: invalid left-hand side of assignment
109-
--> $DIR/destructuring-assignment.rs:24:5
109+
--> $DIR/destructuring-assignment.rs:24:17
110110
|
111111
LL | ((a, b), c) = ((3, 4), 5);
112-
| -----------^^^^^^^^^^^^^^
112+
| ----------- ^
113113
| |
114114
| cannot assign to this expression
115115
|

src/test/ui/error-codes/E0070.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
error[E0070]: invalid left-hand side of assignment
2-
--> $DIR/E0070.rs:6:5
2+
--> $DIR/E0070.rs:6:16
33
|
44
LL | SOME_CONST = 14;
5-
| ----------^^^^^
5+
| ---------- ^
66
| |
77
| cannot assign to this expression
88

99
error[E0070]: invalid left-hand side of assignment
10-
--> $DIR/E0070.rs:7:5
10+
--> $DIR/E0070.rs:7:7
1111
|
1212
LL | 1 = 3;
13-
| -^^^^
13+
| - ^
1414
| |
1515
| cannot assign to this expression
1616

@@ -21,10 +21,10 @@ LL | some_other_func() = 4;
2121
| ^ expected `()`, found integer
2222

2323
error[E0070]: invalid left-hand side of assignment
24-
--> $DIR/E0070.rs:8:5
24+
--> $DIR/E0070.rs:8:23
2525
|
2626
LL | some_other_func() = 4;
27-
| -----------------^^^^
27+
| ----------------- ^
2828
| |
2929
| cannot assign to this expression
3030

src/test/ui/issues/issue-13407.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ LL | A::C = 1;
1111
| ^ expected struct `A::C`, found integer
1212

1313
error[E0070]: invalid left-hand side of assignment
14-
--> $DIR/issue-13407.rs:6:5
14+
--> $DIR/issue-13407.rs:6:10
1515
|
1616
LL | A::C = 1;
17-
| ----^^^^
17+
| ---- ^
1818
| |
1919
| cannot assign to this expression
2020

0 commit comments

Comments
 (0)