Skip to content

Commit ddd4500

Browse files
committed
Add span information to ExprKind::Assign
1 parent c740839 commit ddd4500

File tree

25 files changed

+65
-62
lines changed

25 files changed

+65
-62
lines changed

src/librustc/hir/intravisit.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1056,9 +1056,9 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
10561056
walk_list!(visitor, visit_label, opt_label);
10571057
visitor.visit_block(block);
10581058
}
1059-
ExprKind::Assign(ref left_hand_expression, ref right_hand_expression) => {
1060-
visitor.visit_expr(right_hand_expression);
1061-
visitor.visit_expr(left_hand_expression)
1059+
ExprKind::Assign(ref lhs, ref rhs, _) => {
1060+
visitor.visit_expr(rhs);
1061+
visitor.visit_expr(lhs)
10621062
}
10631063
ExprKind::AssignOp(_, ref left_expression, ref right_expression) => {
10641064
visitor.visit_expr(right_expression);

src/librustc/hir/lowering/expr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ impl LoweringContext<'_, '_> {
112112
opt_label.is_some()),
113113
self.lower_label(opt_label))
114114
}
115-
ExprKind::Assign(ref el, ref er) => {
116-
hir::ExprKind::Assign(P(self.lower_expr(el)), P(self.lower_expr(er)))
115+
ExprKind::Assign(ref el, ref er, span) => {
116+
hir::ExprKind::Assign(P(self.lower_expr(el)), P(self.lower_expr(er)), span)
117117
}
118118
ExprKind::AssignOp(op, ref el, ref er) => hir::ExprKind::AssignOp(
119119
self.lower_binop(op),
@@ -1084,7 +1084,7 @@ impl LoweringContext<'_, '_> {
10841084
let next_expr = P(self.expr_ident(pat.span, next_ident, next_pat_hid));
10851085
let assign = P(self.expr(
10861086
pat.span,
1087-
hir::ExprKind::Assign(next_expr, val_expr),
1087+
hir::ExprKind::Assign(next_expr, val_expr, pat.span),
10881088
ThinVec::new(),
10891089
));
10901090
let some_pat = self.pat_some(pat.span, val_pat);

src/librustc/hir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1659,7 +1659,7 @@ pub enum ExprKind {
16591659
Block(P<Block>, Option<Label>),
16601660

16611661
/// An assignment (e.g., `a = foo()`).
1662-
Assign(P<Expr>, P<Expr>),
1662+
Assign(P<Expr>, P<Expr>, Span),
16631663
/// An assignment with an operator.
16641664
///
16651665
/// E.g., `a += 1`.

src/librustc/hir/print.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1312,7 +1312,7 @@ impl<'a> State<'a> {
13121312
self.ibox(0);
13131313
self.print_block(&blk);
13141314
}
1315-
hir::ExprKind::Assign(ref lhs, ref rhs) => {
1315+
hir::ExprKind::Assign(ref lhs, ref rhs, _) => {
13161316
let prec = AssocOp::Assign.precedence() as i8;
13171317
self.print_expr_maybe_paren(&lhs, prec + 1);
13181318
self.s.space();
@@ -2282,7 +2282,7 @@ fn contains_exterior_struct_lit(value: &hir::Expr) -> bool {
22822282
match value.kind {
22832283
hir::ExprKind::Struct(..) => true,
22842284

2285-
hir::ExprKind::Assign(ref lhs, ref rhs) |
2285+
hir::ExprKind::Assign(ref lhs, ref rhs, _) |
22862286
hir::ExprKind::AssignOp(_, ref lhs, ref rhs) |
22872287
hir::ExprKind::Binary(_, ref lhs, ref rhs) => {
22882288
// `X { y: 1 } + X { y: 2 }`

src/librustc_lint/unused.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ impl EarlyLintPass for UnusedParens {
512512
(value, "`return` value", false, Some(left), None)
513513
}
514514

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

src/librustc_mir/hair/cx/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ fn make_mirror_unadjusted<'a, 'tcx>(
274274

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

277-
hir::ExprKind::Assign(ref lhs, ref rhs) => {
277+
hir::ExprKind::Assign(ref lhs, ref rhs, _) => {
278278
ExprKind::Assign {
279279
lhs: lhs.to_ref(),
280280
rhs: rhs.to_ref(),

src/librustc_parse/parser/expr.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,9 @@ impl<'a> Parser<'a> {
276276
let binary = self.mk_binary(source_map::respan(cur_op_span, ast_op), lhs, rhs);
277277
self.mk_expr(span, binary, AttrVec::new())
278278
}
279-
AssocOp::Assign => self.mk_expr(span, ExprKind::Assign(lhs, rhs), AttrVec::new()),
279+
AssocOp::Assign => {
280+
self.mk_expr(span, ExprKind::Assign(lhs, rhs, cur_op_span), AttrVec::new())
281+
}
280282
AssocOp::AssignOp(k) => {
281283
let aop = match k {
282284
token::Plus => BinOpKind::Add,

src/librustc_passes/liveness.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
10961096
span_bug!(expr.span, "continue to unknown label"))
10971097
}
10981098

1099-
hir::ExprKind::Assign(ref l, ref r) => {
1099+
hir::ExprKind::Assign(ref l, ref r, _) => {
11001100
// see comment on places in
11011101
// propagate_through_place_components()
11021102
let succ = self.write_place(&l, succ, ACC_WRITE);
@@ -1389,7 +1389,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Liveness<'a, 'tcx> {
13891389

13901390
fn check_expr<'tcx>(this: &mut Liveness<'_, 'tcx>, expr: &'tcx Expr) {
13911391
match expr.kind {
1392-
hir::ExprKind::Assign(ref l, _) => {
1392+
hir::ExprKind::Assign(ref l, ..) => {
13931393
this.check_place(&l);
13941394
}
13951395

src/librustc_privacy/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> {
11981198
return;
11991199
}
12001200
match expr.kind {
1201-
hir::ExprKind::Assign(.., ref rhs) | hir::ExprKind::Match(ref rhs, ..) => {
1201+
hir::ExprKind::Assign(_, ref rhs, _) | hir::ExprKind::Match(ref rhs, ..) => {
12021202
// Do not report duplicate errors for `x = y` and `match x { ... }`.
12031203
if self.check_expr_pat_type(rhs.hir_id, rhs.span) {
12041204
return;

src/librustc_typeck/check/demand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
484484
String::new()
485485
};
486486
if let Some(hir::Node::Expr(hir::Expr {
487-
kind: hir::ExprKind::Assign(left_expr, _),
487+
kind: hir::ExprKind::Assign(left_expr, ..),
488488
..
489489
})) = self.tcx.hir().find(
490490
self.tcx.hir().get_parent_node(expr.hir_id),

src/librustc_typeck/check/expr.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
232232
ExprKind::Binary(op, ref lhs, ref rhs) => {
233233
self.check_binop(expr, op, lhs, rhs)
234234
}
235+
ExprKind::Assign(ref lhs, ref rhs, ref span) => {
236+
self.check_expr_assign(expr, expected, lhs, rhs, span)
237+
}
235238
ExprKind::AssignOp(op, ref lhs, ref rhs) => {
236239
self.check_binop_assign(expr, op, lhs, rhs)
237240
}
@@ -264,9 +267,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
264267
ExprKind::Ret(ref expr_opt) => {
265268
self.check_expr_return(expr_opt.as_deref(), expr)
266269
}
267-
ExprKind::Assign(ref lhs, ref rhs) => {
268-
self.check_expr_assign(expr, expected, lhs, rhs)
269-
}
270270
ExprKind::Loop(ref body, _, source) => {
271271
self.check_expr_loop(body, source, expected, expr)
272272
}
@@ -805,6 +805,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
805805
expected: Expectation<'tcx>,
806806
lhs: &'tcx hir::Expr,
807807
rhs: &'tcx hir::Expr,
808+
span: &Span,
808809
) -> Ty<'tcx> {
809810
let lhs_ty = self.check_expr_with_needs(&lhs, Needs::MutPlace);
810811
let rhs_ty = self.check_expr_coercable_to_type(&rhs, lhs_ty);
@@ -827,7 +828,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
827828
}
828829
err.emit();
829830
} else {
830-
self.check_lhs_assignable(lhs, "E0070", &expr.span);
831+
self.check_lhs_assignable(lhs, "E0070", span);
831832
}
832833

833834
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
@@ -291,7 +291,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
291291
}
292292
}
293293

294-
hir::ExprKind::Assign(ref lhs, ref rhs) => {
294+
hir::ExprKind::Assign(ref lhs, ref rhs, _) => {
295295
self.mutate_expr(lhs);
296296
self.consume_expr(rhs);
297297
}

src/libsyntax/ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,7 @@ pub enum ExprKind {
12281228
TryBlock(P<Block>),
12291229

12301230
/// An assignment (`a = foo()`).
1231-
Assign(P<Expr>, P<Expr>),
1231+
Assign(P<Expr>, P<Expr>, Span),
12321232
/// An assignment with an operator.
12331233
///
12341234
/// E.g., `a += 1`.

src/libsyntax/mut_visit.rs

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

src/libsyntax/print/pprust.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2077,7 +2077,7 @@ impl<'a> State<'a> {
20772077
self.print_expr_maybe_paren(expr, parser::PREC_POSTFIX);
20782078
self.s.word(".await");
20792079
}
2080-
ast::ExprKind::Assign(ref lhs, ref rhs) => {
2080+
ast::ExprKind::Assign(ref lhs, ref rhs, _) => {
20812081
let prec = AssocOp::Assign.precedence() as i8;
20822082
self.print_expr_maybe_paren(lhs, prec + 1);
20832083
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
@@ -743,9 +743,9 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
743743
visitor.visit_block(body);
744744
}
745745
ExprKind::Await(ref expr) => visitor.visit_expr(expr),
746-
ExprKind::Assign(ref left_hand_expression, ref right_hand_expression) => {
747-
visitor.visit_expr(left_hand_expression);
748-
visitor.visit_expr(right_hand_expression);
746+
ExprKind::Assign(ref lhs, ref rhs, _) => {
747+
visitor.visit_expr(lhs);
748+
visitor.visit_expr(rhs);
749749
}
750750
ExprKind::AssignOp(_, ref left_expression, ref right_expression) => {
751751
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

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0070]: invalid left-hand side of assignment
2-
--> $DIR/issue-26093.rs:3:9
2+
--> $DIR/issue-26093.rs:3:16
33
|
44
LL | $thing = 42;
5-
| ^^^^^^^^^^^
5+
| ^
66
...
77
LL | not_a_place!(99);
88
| -----------------

0 commit comments

Comments
 (0)