Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

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

compiler/rustc_mir_build/src/thir/cx/expr.rs

Lines changed: 1 addition & 18 deletions
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),

compiler/rustc_mir_build/src/thir/cx/mod.rs

Lines changed: 0 additions & 10 deletions
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()

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

Lines changed: 1 addition & 1 deletion
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]

src/tools/miri/tests/fail/stacked_borrows/illegal_read7.stderr

Lines changed: 1 addition & 1 deletion
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]

src/tools/miri/tests/fail/stacked_borrows/interior_mut1.stderr

Lines changed: 1 addition & 1 deletion
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]

src/tools/miri/tests/fail/stacked_borrows/interior_mut2.stderr

Lines changed: 1 addition & 1 deletion
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]

src/tools/miri/tests/fail/stacked_borrows/shared_rw_borrows_are_weak1.stderr

Lines changed: 1 addition & 1 deletion
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]

src/tools/miri/tests/fail/tree_borrows/fnentry_invalidation.stderr

Lines changed: 1 addition & 1 deletion
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

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

Lines changed: 2 additions & 9 deletions
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
|

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

Lines changed: 1 addition & 1 deletion
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

0 commit comments

Comments
 (0)