Skip to content

Commit fe87042

Browse files
Do not set up wrong span for adjustments
1 parent 05b82e5 commit fe87042

File tree

159 files changed

+364
-433
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

159 files changed

+364
-433
lines changed

Diff for: compiler/rustc_mir_build/src/thir/cx/expr.rs

+1-18
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,14 @@ impl<'tcx> Cx<'tcx> {
4141

4242
let mut expr = self.make_mirror_unadjusted(hir_expr);
4343

44-
let adjustment_span = match self.adjustment_span {
45-
Some((hir_id, span)) if hir_id == hir_expr.hir_id => Some(span),
46-
_ => None,
47-
};
48-
4944
trace!(?expr.ty);
5045

5146
// Now apply adjustments, if any.
5247
if self.apply_adjustments {
5348
for adjustment in self.typeck_results.expr_adjustments(hir_expr) {
5449
trace!(?expr, ?adjustment);
5550
let span = expr.span;
56-
expr = self.apply_adjustment(
57-
hir_expr,
58-
expr,
59-
adjustment,
60-
adjustment_span.unwrap_or(span),
61-
);
51+
expr = self.apply_adjustment(hir_expr, expr, adjustment, span);
6252
}
6353
}
6454

@@ -274,7 +264,6 @@ impl<'tcx> Cx<'tcx> {
274264
fn make_mirror_unadjusted(&mut self, expr: &'tcx hir::Expr<'tcx>) -> Expr<'tcx> {
275265
let tcx = self.tcx;
276266
let expr_ty = self.typeck_results().expr_ty(expr);
277-
let expr_span = expr.span;
278267
let temp_lifetime =
279268
self.rvalue_scopes.temporary_scope(self.region_scope_tree, expr.hir_id.local_id);
280269

@@ -283,17 +272,11 @@ impl<'tcx> Cx<'tcx> {
283272
hir::ExprKind::MethodCall(segment, receiver, ref args, fn_span) => {
284273
// Rewrite a.b(c) into UFCS form like Trait::b(a, c)
285274
let expr = self.method_callee(expr, segment.ident.span, None);
286-
// When we apply adjustments to the receiver, use the span of
287-
// the overall method call for better diagnostics. args[0]
288-
// is guaranteed to exist, since a method call always has a receiver.
289-
let old_adjustment_span =
290-
self.adjustment_span.replace((receiver.hir_id, expr_span));
291275
info!("Using method span: {:?}", expr.span);
292276
let args = std::iter::once(receiver)
293277
.chain(args.iter())
294278
.map(|expr| self.mirror_expr(expr))
295279
.collect();
296-
self.adjustment_span = old_adjustment_span;
297280
ExprKind::Call {
298281
ty: expr.ty,
299282
fun: self.thir.exprs.push(expr),

Diff for: compiler/rustc_mir_build/src/thir/cx/mod.rs

-10
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use rustc_hir::Node;
1616
use rustc_middle::middle::region;
1717
use rustc_middle::thir::*;
1818
use rustc_middle::ty::{self, RvalueScopes, Ty, TyCtxt};
19-
use rustc_span::Span;
2019

2120
pub(crate) fn thir_body(
2221
tcx: TyCtxt<'_>,
@@ -62,14 +61,6 @@ struct Cx<'tcx> {
6261
typeck_results: &'tcx ty::TypeckResults<'tcx>,
6362
rvalue_scopes: &'tcx RvalueScopes,
6463

65-
/// When applying adjustments to the expression
66-
/// with the given `HirId`, use the given `Span`,
67-
/// instead of the usual span. This is used to
68-
/// assign the span of an overall method call
69-
/// (e.g. `my_val.foo()`) to the adjustment expressions
70-
/// for the receiver.
71-
adjustment_span: Option<(HirId, Span)>,
72-
7364
/// False to indicate that adjustments should not be applied. Only used for `custom_mir`
7465
apply_adjustments: bool,
7566

@@ -110,7 +101,6 @@ impl<'tcx> Cx<'tcx> {
110101
typeck_results,
111102
rvalue_scopes: &typeck_results.rvalue_scopes,
112103
body_owner: def.to_def_id(),
113-
adjustment_span: None,
114104
apply_adjustments: hir
115105
.attrs(hir_id)
116106
.iter()

Diff for: src/tools/miri/tests/fail/box-cell-alias.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: Undefined Behavior: trying to retag from <TAG> for SharedReadWrite permis
22
--> $DIR/box-cell-alias.rs:LL:CC
33
|
44
LL | unsafe { (*ptr).set(20) };
5-
| ^^^^^^^^^^^^^^
5+
| ^^^^^^
66
| |
77
| trying to retag from <TAG> for SharedReadWrite permission at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
88
| this error occurs as part of retag at ALLOC[0x0..0x1]

Diff for: src/tools/miri/tests/fail/stacked_borrows/illegal_read7.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: Undefined Behavior: trying to retag from <TAG> for SharedReadWrite permis
22
--> $DIR/illegal_read7.rs:LL:CC
33
|
44
LL | let _val = *x.get_mut();
5-
| ^^^^^^^^^^^
5+
| ^
66
| |
77
| trying to retag from <TAG> for SharedReadWrite permission at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
88
| this error occurs as part of two-phase retag at ALLOC[0x0..0x4]

Diff for: src/tools/miri/tests/fail/stacked_borrows/interior_mut1.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: Undefined Behavior: trying to retag from <TAG> for SharedReadWrite permis
22
--> $DIR/interior_mut1.rs:LL:CC
33
|
44
LL | let _val = *inner_shr.get();
5-
| ^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^
66
| |
77
| trying to retag from <TAG> for SharedReadWrite permission at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
88
| this error occurs as part of retag at ALLOC[0x0..0x4]

Diff for: src/tools/miri/tests/fail/stacked_borrows/interior_mut2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: Undefined Behavior: trying to retag from <TAG> for SharedReadWrite permis
22
--> $DIR/interior_mut2.rs:LL:CC
33
|
44
LL | let _val = *inner_shr.get();
5-
| ^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^
66
| |
77
| trying to retag from <TAG> for SharedReadWrite permission at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
88
| this error occurs as part of retag at ALLOC[0x0..0x4]

Diff for: src/tools/miri/tests/fail/stacked_borrows/shared_rw_borrows_are_weak1.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: Undefined Behavior: trying to retag from <TAG> for SharedReadWrite permis
22
--> $DIR/shared_rw_borrows_are_weak1.rs:LL:CC
33
|
44
LL | y.get_mut();
5-
| ^^^^^^^^^^^
5+
| ^
66
| |
77
| trying to retag from <TAG> for SharedReadWrite permission at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
88
| this error occurs as part of two-phase retag at ALLOC[0x0..0x4]

Diff for: src/tools/miri/tests/fail/tree_borrows/fnentry_invalidation.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ help: the accessed tag <TAG> later transitioned to Frozen due to a reborrow (act
2121
--> $DIR/fnentry_invalidation.rs:LL:CC
2222
|
2323
LL | x.do_bad();
24-
| ^^^^^^^^^^
24+
| ^
2525
= help: this transition corresponds to a loss of write permissions
2626
= note: BACKTRACE (of the first span):
2727
= note: inside `main` at $DIR/fnentry_invalidation.rs:LL:CC

Diff for: src/tools/miri/tests/fail/tree_borrows/write-during-2phase.stderr

+2-9
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,8 @@ LL | fn add(&mut self, n: u64) -> u64 {
99
help: the accessed tag <TAG> was created here, in the initial state Reserved
1010
--> $DIR/write-during-2phase.rs:LL:CC
1111
|
12-
LL | let _res = f.add(unsafe {
13-
| ________________^
14-
LL | | let n = f.0;
15-
LL | | // This is the access at fault, but it's not immediately apparent because
16-
LL | | // the reference that got invalidated is not under a Protector.
17-
LL | | *inner = 42;
18-
LL | | n
19-
LL | | });
20-
| |______^
12+
LL | let _res = f.add(unsafe {
13+
| ^
2114
help: the accessed tag <TAG> later transitioned to Disabled due to a foreign write access at offsets [0x0..0x8]
2215
--> $DIR/write-during-2phase.rs:LL:CC
2316
|

Diff for: tests/ui/array-slice-vec/vec-mut-iter-borrow.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | for x in &mut xs {
77
| first mutable borrow occurs here
88
| first borrow later used here
99
LL | xs.push(1)
10-
| ^^^^^^^^^^ second mutable borrow occurs here
10+
| ^^ second mutable borrow occurs here
1111

1212
error: aborting due to previous error
1313

Diff for: tests/ui/async-await/issue-61452.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
22
--> $DIR/issue-61452.rs:4:5
33
|
44
LL | x.take();
5-
| ^^^^^^^^ cannot borrow as mutable
5+
| ^ cannot borrow as mutable
66
|
77
help: consider changing this to be mutable
88
|

Diff for: tests/ui/async-await/issues/issue-61187.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0596]: cannot borrow `data` as mutable, as it is not declared as mutable
22
--> $DIR/issue-61187.rs:6:5
33
|
44
LL | data.reverse();
5-
| ^^^^^^^^^^^^^^ cannot borrow as mutable
5+
| ^^^^ cannot borrow as mutable
66
|
77
help: consider changing this to be mutable
88
|

Diff for: tests/ui/binop/binop-move-semantics.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ LL | x
2727
| - value moved here
2828
LL | +
2929
LL | x.clone();
30-
| ^^^^^^^^^ value borrowed here after move
30+
| ^ value borrowed here after move
3131
|
3232
help: consider cloning the value if the performance cost is acceptable
3333
|

Diff for: tests/ui/borrowck/borrow-tuple-fields.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LL | let y = x;
99
| ^ move out of `x` occurs here
1010
LL |
1111
LL | r.use_ref();
12-
| ----------- borrow later used here
12+
| - borrow later used here
1313

1414
error[E0502]: cannot borrow `x.0` as mutable because it is also borrowed as immutable
1515
--> $DIR/borrow-tuple-fields.rs:18:13
@@ -19,7 +19,7 @@ LL | let a = &x.0;
1919
LL | let b = &mut x.0;
2020
| ^^^^^^^^ mutable borrow occurs here
2121
LL | a.use_ref();
22-
| ----------- immutable borrow later used here
22+
| - immutable borrow later used here
2323

2424
error[E0499]: cannot borrow `x.0` as mutable more than once at a time
2525
--> $DIR/borrow-tuple-fields.rs:23:13
@@ -29,7 +29,7 @@ LL | let a = &mut x.0;
2929
LL | let b = &mut x.0;
3030
| ^^^^^^^^ second mutable borrow occurs here
3131
LL | a.use_ref();
32-
| ----------- first borrow later used here
32+
| - first borrow later used here
3333

3434
error[E0505]: cannot move out of `x` because it is borrowed
3535
--> $DIR/borrow-tuple-fields.rs:28:13
@@ -41,7 +41,7 @@ LL | let r = &x.0;
4141
LL | let y = x;
4242
| ^ move out of `x` occurs here
4343
LL | r.use_ref();
44-
| ----------- borrow later used here
44+
| - borrow later used here
4545

4646
error[E0502]: cannot borrow `x.0` as mutable because it is also borrowed as immutable
4747
--> $DIR/borrow-tuple-fields.rs:33:13
@@ -51,7 +51,7 @@ LL | let a = &x.0;
5151
LL | let b = &mut x.0;
5252
| ^^^^^^^^ mutable borrow occurs here
5353
LL | a.use_ref();
54-
| ----------- immutable borrow later used here
54+
| - immutable borrow later used here
5555

5656
error[E0499]: cannot borrow `x.0` as mutable more than once at a time
5757
--> $DIR/borrow-tuple-fields.rs:38:13
@@ -61,7 +61,7 @@ LL | let a = &mut x.0;
6161
LL | let b = &mut x.0;
6262
| ^^^^^^^^ second mutable borrow occurs here
6363
LL | a.use_mut();
64-
| ----------- first borrow later used here
64+
| - first borrow later used here
6565

6666
error: aborting due to 6 previous errors
6767

Diff for: tests/ui/borrowck/borrowck-argument.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0596]: cannot borrow `arg` as mutable, as it is not declared as mutable
22
--> $DIR/borrowck-argument.rs:10:5
33
|
44
LL | arg.mutate();
5-
| ^^^^^^^^^^^^ cannot borrow as mutable
5+
| ^^^ cannot borrow as mutable
66
|
77
help: consider changing this to be mutable
88
|
@@ -13,7 +13,7 @@ error[E0596]: cannot borrow `arg` as mutable, as it is not declared as mutable
1313
--> $DIR/borrowck-argument.rs:15:9
1414
|
1515
LL | arg.mutate();
16-
| ^^^^^^^^^^^^ cannot borrow as mutable
16+
| ^^^ cannot borrow as mutable
1717
|
1818
help: consider changing this to be mutable
1919
|
@@ -24,7 +24,7 @@ error[E0596]: cannot borrow `arg` as mutable, as it is not declared as mutable
2424
--> $DIR/borrowck-argument.rs:21:9
2525
|
2626
LL | arg.mutate();
27-
| ^^^^^^^^^^^^ cannot borrow as mutable
27+
| ^^^ cannot borrow as mutable
2828
|
2929
help: consider changing this to be mutable
3030
|
@@ -35,7 +35,7 @@ error[E0596]: cannot borrow `arg` as mutable, as it is not declared as mutable
3535
--> $DIR/borrowck-argument.rs:32:17
3636
|
3737
LL | (|arg: S| { arg.mutate() })(s);
38-
| ^^^^^^^^^^^^ cannot borrow as mutable
38+
| ^^^ cannot borrow as mutable
3939
|
4040
help: consider changing this to be mutable
4141
|

Diff for: tests/ui/borrowck/borrowck-auto-mut-ref-to-immut-var.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
22
--> $DIR/borrowck-auto-mut-ref-to-immut-var.rs:15:5
33
|
44
LL | x.printme();
5-
| ^^^^^^^^^^^ cannot borrow as mutable
5+
| ^ cannot borrow as mutable
66
|
77
help: consider changing this to be mutable
88
|

Diff for: tests/ui/borrowck/borrowck-borrow-immut-deref-of-box-as-mut.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0596]: cannot borrow `*a` as mutable, as `a` is not declared as mutable
22
--> $DIR/borrowck-borrow-immut-deref-of-box-as-mut.rs:12:5
33
|
44
LL | a.foo();
5-
| ^^^^^^^ cannot borrow as mutable
5+
| ^ cannot borrow as mutable
66
|
77
help: consider changing this to be mutable
88
|

Diff for: tests/ui/borrowck/borrowck-borrow-mut-object-twice.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ error[E0499]: cannot borrow `*x` as mutable more than once at a time
22
--> $DIR/borrowck-borrow-mut-object-twice.rs:13:5
33
|
44
LL | let y = x.f1();
5-
| ------ first mutable borrow occurs here
5+
| - first mutable borrow occurs here
66
LL | x.f2();
7-
| ^^^^^^ second mutable borrow occurs here
7+
| ^ second mutable borrow occurs here
88
LL | y.use_ref();
9-
| ----------- first borrow later used here
9+
| - first borrow later used here
1010

1111
error: aborting due to previous error
1212

Diff for: tests/ui/borrowck/borrowck-borrow-overloaded-auto-deref.stderr

+7-7
Original file line numberDiff line numberDiff line change
@@ -58,55 +58,55 @@ error[E0596]: cannot borrow data in an `Rc` as mutable
5858
--> $DIR/borrowck-borrow-overloaded-auto-deref.rs:72:5
5959
|
6060
LL | x.set(0, 0);
61-
| ^^^^^^^^^^^ cannot borrow as mutable
61+
| ^ cannot borrow as mutable
6262
|
6363
= help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Rc<Point>`
6464

6565
error[E0596]: cannot borrow data in an `Rc` as mutable
6666
--> $DIR/borrowck-borrow-overloaded-auto-deref.rs:76:5
6767
|
6868
LL | x.set(0, 0);
69-
| ^^^^^^^^^^^ cannot borrow as mutable
69+
| ^ cannot borrow as mutable
7070
|
7171
= help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Rc<Point>`
7272

7373
error[E0596]: cannot borrow data in an `Rc` as mutable
7474
--> $DIR/borrowck-borrow-overloaded-auto-deref.rs:84:5
7575
|
7676
LL | x.y_mut()
77-
| ^^^^^^^^^ cannot borrow as mutable
77+
| ^ cannot borrow as mutable
7878
|
7979
= help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Rc<Point>`
8080

8181
error[E0596]: cannot borrow data in an `Rc` as mutable
8282
--> $DIR/borrowck-borrow-overloaded-auto-deref.rs:88:5
8383
|
8484
LL | x.y_mut()
85-
| ^^^^^^^^^ cannot borrow as mutable
85+
| ^ cannot borrow as mutable
8686
|
8787
= help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Rc<Point>`
8888

8989
error[E0596]: cannot borrow data in an `Rc` as mutable
9090
--> $DIR/borrowck-borrow-overloaded-auto-deref.rs:92:6
9191
|
9292
LL | *x.y_mut() = 3;
93-
| ^^^^^^^^^ cannot borrow as mutable
93+
| ^ cannot borrow as mutable
9494
|
9595
= help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Rc<Point>`
9696

9797
error[E0596]: cannot borrow data in an `Rc` as mutable
9898
--> $DIR/borrowck-borrow-overloaded-auto-deref.rs:96:6
9999
|
100100
LL | *x.y_mut() = 3;
101-
| ^^^^^^^^^ cannot borrow as mutable
101+
| ^ cannot borrow as mutable
102102
|
103103
= help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Rc<Point>`
104104

105105
error[E0596]: cannot borrow data in an `Rc` as mutable
106106
--> $DIR/borrowck-borrow-overloaded-auto-deref.rs:100:6
107107
|
108108
LL | *x.y_mut() = 3;
109-
| ^^^^^^^^^ cannot borrow as mutable
109+
| ^ cannot borrow as mutable
110110
|
111111
= help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Rc<Point>`
112112

Diff for: tests/ui/borrowck/borrowck-borrowed-uniq-rvalue.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | buggy_map.insert(42, &*Box::new(1));
77
| creates a temporary value which is freed while still in use
88
...
99
LL | buggy_map.insert(43, &*tmp);
10-
| --------------------------- borrow later used here
10+
| --------- borrow later used here
1111
|
1212
help: consider using a `let` binding to create a longer lived value
1313
|

Diff for: tests/ui/borrowck/borrowck-closures-unique-imm.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | let p = &this.x;
66
LL | &mut this.x;
77
| ^^^^^^^^^^^ mutable borrow occurs here
88
LL | p.use_ref();
9-
| ----------- immutable borrow later used here
9+
| - immutable borrow later used here
1010

1111
error: aborting due to previous error
1212

0 commit comments

Comments
 (0)