Skip to content

Commit f074530

Browse files
committed
Auto merge of #112945 - compiler-errors:tighten-span-of-adjustment-error, r=oli-obk
(re-)tighten sourceinfo span of adjustments in MIR Diagnostics rely on the spans of MIR statements being (approximately) correct in order to give suggestions relative to that span (i.e. `shrink_to_hi` and `shrink_to_lo`). I discovered that we're *intentionally* lowering THIR exprs with their parent expr's span if they come from adjustments that are due to a parent expression. While I understand why that may be desirable to demonstrate the relationship of an adjustment and the expression that requires it, it leads to 1. very verbose borrowck output 2. incorrect spans for suggestions Some diagnostics get around that by giving suggestions relative to other spans we've collected during MIR lowering, such as the span of the method's identifier (e.g. `name` in `.name()`), but this doesn't work too well when things come from desugaring. I assume it also has lead to numerous tweaks and complications to diagnostics code down the road, which this PR doesn't necessarily aim to fix but may open the gates to fixing later... The last three commits are simplifications due to the fact that we can assume that the move span actually points to what is being moved (and a test). This regressed in #89110, which was debated somewhat in #90286. cc `@Aaron1011` who originally made this change. r? diagnostics Fixes #113547 Fixes #111016
2 parents 0a0ebe2 + 6779ead commit f074530

7 files changed

+8
-15
lines changed

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]

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]

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]

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]

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]

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

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
|

0 commit comments

Comments
 (0)