Skip to content

Commit 2d29c44

Browse files
authored
Rollup merge of rust-lang#52904 - pnkfelix:issue-51167-sort-by-span, r=petrochenkov
NLL: sort diagnostics by span Sorting the output diagnostics by span is a long planned revision to the NLL diagnostics that we hope will yield a less surprising user experience in some case. Once we got them buffered, it was trivial to implement. (The hard part is skimming the resulting changes to the diagnostics to make sure nothing broke... Note that I largely rubber-stamped the `#[rustc_regions]` output change.) Fix rust-lang#51167
2 parents a8ed603 + 779792f commit 2d29c44

27 files changed

+353
-351
lines changed

src/librustc_mir/borrow_check/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,8 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
331331
}
332332

333333
if mbcx.errors_buffer.len() > 0 {
334+
mbcx.errors_buffer.sort_by_key(|diag| diag.span.primary_span());
335+
334336
if tcx.migrate_borrowck() {
335337
match tcx.borrowck(def_id).signalled_any_error {
336338
SignalledError::NoErrorsSeen => {

src/test/ui/borrowck/issue-41962.stderr

+17-17
Original file line numberDiff line numberDiff line change
@@ -17,41 +17,41 @@ LL | if let Some(thing) = maybe {
1717
= note: move occurs because the value has type `std::vec::Vec<bool>`, which does not implement the `Copy` trait
1818

1919
error[E0382]: use of moved value: `maybe` (Mir)
20-
--> $DIR/issue-41962.rs:17:30
20+
--> $DIR/issue-41962.rs:17:16
2121
|
2222
LL | if let Some(thing) = maybe {
23-
| ----- ^^^^^ value used here after move
24-
| |
25-
| value moved here
23+
| ^^^^^-----^
24+
| | |
25+
| | value moved here
26+
| value used here after move
2627
|
2728
= note: move occurs because value has type `std::vec::Vec<bool>`, which does not implement the `Copy` trait
2829

29-
error[E0382]: borrow of moved value: `maybe` (Mir)
30-
--> $DIR/issue-41962.rs:17:30
30+
error[E0382]: use of moved value (Mir)
31+
--> $DIR/issue-41962.rs:17:21
3132
|
3233
LL | if let Some(thing) = maybe {
33-
| ----- ^^^^^ value borrowed here after move
34-
| |
35-
| value moved here
34+
| ^^^^^ value moved here in previous iteration of loop
3635
|
3736
= note: move occurs because value has type `std::vec::Vec<bool>`, which does not implement the `Copy` trait
3837

3938
error[E0382]: use of moved value: `maybe` (Mir)
40-
--> $DIR/issue-41962.rs:17:16
39+
--> $DIR/issue-41962.rs:17:30
4140
|
4241
LL | if let Some(thing) = maybe {
43-
| ^^^^^-----^
44-
| | |
45-
| | value moved here
46-
| value used here after move
42+
| ----- ^^^^^ value used here after move
43+
| |
44+
| value moved here
4745
|
4846
= note: move occurs because value has type `std::vec::Vec<bool>`, which does not implement the `Copy` trait
4947

50-
error[E0382]: use of moved value (Mir)
51-
--> $DIR/issue-41962.rs:17:21
48+
error[E0382]: borrow of moved value: `maybe` (Mir)
49+
--> $DIR/issue-41962.rs:17:30
5250
|
5351
LL | if let Some(thing) = maybe {
54-
| ^^^^^ value moved here in previous iteration of loop
52+
| ----- ^^^^^ value borrowed here after move
53+
| |
54+
| value moved here
5555
|
5656
= note: move occurs because value has type `std::vec::Vec<bool>`, which does not implement the `Copy` trait
5757

src/test/ui/borrowck/two-phase-multi-mut.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
error[E0499]: cannot borrow `foo` as mutable more than once at a time
2-
--> $DIR/two-phase-multi-mut.rs:23:16
2+
--> $DIR/two-phase-multi-mut.rs:23:5
33
|
44
LL | foo.method(&mut foo);
5-
| -----------^^^^^^^^-
5+
| ^^^^^^^^^^^--------^
66
| | |
7-
| | second mutable borrow occurs here
8-
| first mutable borrow occurs here
7+
| | first mutable borrow occurs here
8+
| second mutable borrow occurs here
99
| borrow later used here
1010

1111
error[E0499]: cannot borrow `foo` as mutable more than once at a time
12-
--> $DIR/two-phase-multi-mut.rs:23:5
12+
--> $DIR/two-phase-multi-mut.rs:23:16
1313
|
1414
LL | foo.method(&mut foo);
15-
| ^^^^^^^^^^^--------^
15+
| -----------^^^^^^^^-
1616
| | |
17-
| | first mutable borrow occurs here
18-
| second mutable borrow occurs here
17+
| | second mutable borrow occurs here
18+
| first mutable borrow occurs here
1919
| borrow later used here
2020

2121
error: aborting due to 2 previous errors

src/test/ui/hygiene/fields-move.nll.stderr

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
error[E0382]: use of moved value: `foo.x`
2-
--> $DIR/fields-move.rs:38:42
2+
--> $DIR/fields-move.rs:28:9
33
|
44
LL | $foo.x
55
| ------ value moved here
66
...
7+
LL | $foo.x //~ ERROR use of moved value: `foo.x`
8+
| ^^^^^^ value used here after move
9+
...
710
LL | assert_two_copies(copy_modern!(foo), foo.x); //~ ERROR use of moved value: `foo.x`
8-
| ^^^^^ value used here after move
11+
| ----- value moved here
12+
LL | assert_two_copies(copy_legacy!(foo), foo.x); //~ ERROR use of moved value: `foo.x`
13+
| ----------------- in this macro invocation
914
|
1015
= note: move occurs because `foo.x` has type `NonCopy`, which does not implement the `Copy` trait
1116

1217
error[E0382]: use of moved value: `foo.x`
13-
--> $DIR/fields-move.rs:28:9
18+
--> $DIR/fields-move.rs:38:42
1419
|
1520
LL | $foo.x
1621
| ------ value moved here
1722
...
18-
LL | $foo.x //~ ERROR use of moved value: `foo.x`
19-
| ^^^^^^ value used here after move
20-
...
2123
LL | assert_two_copies(copy_modern!(foo), foo.x); //~ ERROR use of moved value: `foo.x`
22-
| ----- value moved here
23-
LL | assert_two_copies(copy_legacy!(foo), foo.x); //~ ERROR use of moved value: `foo.x`
24-
| ----------------- in this macro invocation
24+
| ^^^^^ value used here after move
2525
|
2626
= note: move occurs because `foo.x` has type `NonCopy`, which does not implement the `Copy` trait
2727

src/test/ui/issue-27592.nll.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
error[E0597]: borrowed value does not live long enough
2-
--> $DIR/issue-27592.rs:26:33
3-
|
4-
LL | write(|| format_args!("{}", String::from("Hello world")));
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^- temporary value only lives until here
6-
| |
7-
| temporary value does not live long enough
8-
91
error[E0597]: borrowed value does not live long enough
102
--> $DIR/issue-27592.rs:26:27
113
|
@@ -14,6 +6,14 @@ LL | write(|| format_args!("{}", String::from("Hello world")));
146
| |
157
| temporary value does not live long enough
168

9+
error[E0597]: borrowed value does not live long enough
10+
--> $DIR/issue-27592.rs:26:33
11+
|
12+
LL | write(|| format_args!("{}", String::from("Hello world")));
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^- temporary value only lives until here
14+
| |
15+
| temporary value does not live long enough
16+
1717
error: aborting due to 2 previous errors
1818

1919
For more information about this error, try `rustc --explain E0597`.

src/test/ui/nll/closure-requirements/escape-argument-callee.stderr

+9-9
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,6 @@ warning: not reporting region error due to nll
44
LL | let mut closure = expect_sig(|p, y| *p = y);
55
| ^
66

7-
error: unsatisfied lifetime constraints
8-
--> $DIR/escape-argument-callee.rs:36:45
9-
|
10-
LL | let mut closure = expect_sig(|p, y| *p = y);
11-
| - - ^^^^^^ requires that `'1` must outlive `'2`
12-
| | |
13-
| | has type `&'1 i32`
14-
| has type `&mut &'2 i32`
15-
167
note: No external requirements
178
--> $DIR/escape-argument-callee.rs:36:38
189
|
@@ -24,6 +15,15 @@ LL | let mut closure = expect_sig(|p, y| *p = y);
2415
for<'r, 's, 't0> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) mut &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) i32, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't0)) i32))
2516
]
2617

18+
error: unsatisfied lifetime constraints
19+
--> $DIR/escape-argument-callee.rs:36:45
20+
|
21+
LL | let mut closure = expect_sig(|p, y| *p = y);
22+
| - - ^^^^^^ requires that `'1` must outlive `'2`
23+
| | |
24+
| | has type `&'1 i32`
25+
| has type `&mut &'2 i32`
26+
2727
note: No external requirements
2828
--> $DIR/escape-argument-callee.rs:30:1
2929
|

src/test/ui/nll/closure-requirements/propagate-approximated-fail-no-postdom.stderr

+11-11
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,6 @@ warning: not reporting region error due to nll
44
LL | let p = x.get();
55
| ^^^^^^^
66

7-
error: unsatisfied lifetime constraints
8-
--> $DIR/propagate-approximated-fail-no-postdom.rs:57:13
9-
|
10-
LL | |_outlives1, _outlives2, _outlives3, x, y| {
11-
| ---------- ---------- has type `std::cell::Cell<&'2 &u32>`
12-
| |
13-
| has type `std::cell::Cell<&&'1 u32>`
14-
...
15-
LL | demand_y(x, y, p) //~ ERROR
16-
| ^^^^^^^^^^^^^^^^^ argument requires that `'1` must outlive `'2`
17-
187
note: No external requirements
198
--> $DIR/propagate-approximated-fail-no-postdom.rs:53:9
209
|
@@ -31,6 +20,17 @@ LL | | },
3120
for<'r, 's> extern "rust-call" fn((std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) u32>, std::cell::Cell<&'_#2r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) &'_#3r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) u32>))
3221
]
3322

23+
error: unsatisfied lifetime constraints
24+
--> $DIR/propagate-approximated-fail-no-postdom.rs:57:13
25+
|
26+
LL | |_outlives1, _outlives2, _outlives3, x, y| {
27+
| ---------- ---------- has type `std::cell::Cell<&'2 &u32>`
28+
| |
29+
| has type `std::cell::Cell<&&'1 u32>`
30+
...
31+
LL | demand_y(x, y, p) //~ ERROR
32+
| ^^^^^^^^^^^^^^^^^ argument requires that `'1` must outlive `'2`
33+
3434
note: No external requirements
3535
--> $DIR/propagate-approximated-fail-no-postdom.rs:48:1
3636
|

src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr

+11-11
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,6 @@ warning: not reporting region error due to nll
44
LL | foo(cell, |cell_a, cell_x| {
55
| ^^^
66

7-
error: borrowed data escapes outside of closure
8-
--> $DIR/propagate-approximated-shorter-to-static-comparing-against-free.rs:33:9
9-
|
10-
LL | foo(cell, |cell_a, cell_x| {
11-
| ------ ------ `cell_x` is a reference that is only valid in the closure body
12-
| |
13-
| `cell_a` is declared here, outside of the closure body
14-
LL | //~^ WARNING not reporting region error due to nll
15-
LL | cell_a.set(cell_x.get()); // forces 'x: 'a, error in closure
16-
| ^^^^^^^^^^^^^^^^^^^^^^^^ `cell_x` escapes the closure body here
17-
187
note: No external requirements
198
--> $DIR/propagate-approximated-shorter-to-static-comparing-against-free.rs:31:15
209
|
@@ -31,6 +20,17 @@ LL | | })
3120
for<'r> extern "rust-call" fn((std::cell::Cell<&'_#1r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) u32>))
3221
]
3322

23+
error: borrowed data escapes outside of closure
24+
--> $DIR/propagate-approximated-shorter-to-static-comparing-against-free.rs:33:9
25+
|
26+
LL | foo(cell, |cell_a, cell_x| {
27+
| ------ ------ `cell_x` is a reference that is only valid in the closure body
28+
| |
29+
| `cell_a` is declared here, outside of the closure body
30+
LL | //~^ WARNING not reporting region error due to nll
31+
LL | cell_a.set(cell_x.get()); // forces 'x: 'a, error in closure
32+
| ^^^^^^^^^^^^^^^^^^^^^^^^ `cell_x` escapes the closure body here
33+
3434
note: No external requirements
3535
--> $DIR/propagate-approximated-shorter-to-static-comparing-against-free.rs:28:1
3636
|

src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr

+13-13
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,6 @@ LL | | });
2323
= note: number of external vids: 4
2424
= note: where '_#1r: '_#0r
2525

26-
error: borrowed data escapes outside of function
27-
--> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:45:5
28-
|
29-
LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
30-
| ------ `cell_a` is a reference that is only valid in the function body
31-
LL | / establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
32-
LL | | //~^ ERROR
33-
LL | |
34-
LL | | // Only works if 'x: 'y:
35-
LL | | demand_y(x, y, x.get()) //~ WARNING not reporting region error due to nll
36-
LL | | });
37-
| |______^ `cell_a` escapes the function body here
38-
3926
note: No external requirements
4027
--> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:44:1
4128
|
@@ -50,5 +37,18 @@ LL | | }
5037
|
5138
= note: defining type: DefId(0/0:6 ~ propagate_approximated_shorter_to_static_no_bound[317d]::supply[0]) with substs []
5239

40+
error: borrowed data escapes outside of function
41+
--> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:45:5
42+
|
43+
LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
44+
| ------ `cell_a` is a reference that is only valid in the function body
45+
LL | / establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
46+
LL | | //~^ ERROR
47+
LL | |
48+
LL | | // Only works if 'x: 'y:
49+
LL | | demand_y(x, y, x.get()) //~ WARNING not reporting region error due to nll
50+
LL | | });
51+
| |______^ `cell_a` escapes the function body here
52+
5353
error: aborting due to previous error
5454

src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr

+13-13
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,6 @@ LL | | });
2323
= note: number of external vids: 5
2424
= note: where '_#1r: '_#0r
2525

26-
error: borrowed data escapes outside of function
27-
--> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:48:5
28-
|
29-
LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
30-
| ------ `cell_a` is a reference that is only valid in the function body
31-
LL | / establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
32-
LL | | //~^ ERROR
33-
LL | | // Only works if 'x: 'y:
34-
LL | | demand_y(x, y, x.get())
35-
LL | | //~^ WARNING not reporting region error due to nll
36-
LL | | });
37-
| |______^ `cell_a` escapes the function body here
38-
3926
note: No external requirements
4027
--> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:47:1
4128
|
@@ -50,5 +37,18 @@ LL | | }
5037
|
5138
= note: defining type: DefId(0/0:6 ~ propagate_approximated_shorter_to_static_wrong_bound[317d]::supply[0]) with substs []
5239

40+
error: borrowed data escapes outside of function
41+
--> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:48:5
42+
|
43+
LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
44+
| ------ `cell_a` is a reference that is only valid in the function body
45+
LL | / establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
46+
LL | | //~^ ERROR
47+
LL | | // Only works if 'x: 'y:
48+
LL | | demand_y(x, y, x.get())
49+
LL | | //~^ WARNING not reporting region error due to nll
50+
LL | | });
51+
| |______^ `cell_a` escapes the function body here
52+
5353
error: aborting due to previous error
5454

src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-no-bounds.stderr

+11-11
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,6 @@ warning: not reporting region error due to nll
44
LL | demand_y(x, y, x.get())
55
| ^^^^^^^^^^^^^^^^^^^^^^^
66

7-
error: unsatisfied lifetime constraints
8-
--> $DIR/propagate-fail-to-approximate-longer-no-bounds.rs:47:9
9-
|
10-
LL | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
11-
| --------- - has type `&std::cell::Cell<&'1 u32>`
12-
| |
13-
| has type `&std::cell::Cell<&'2 &u32>`
14-
LL | // Only works if 'x: 'y:
15-
LL | demand_y(x, y, x.get())
16-
| ^^^^^^^^^^^^^^^^^^^^^^^ argument requires that `'1` must outlive `'2`
17-
187
note: No external requirements
198
--> $DIR/propagate-fail-to-approximate-longer-no-bounds.rs:45:47
209
|
@@ -32,6 +21,17 @@ LL | | });
3221
for<'r, 's, 't0, 't1, 't2> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) &'_#1r u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't0)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't1)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't2)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) u32>))
3322
]
3423

24+
error: unsatisfied lifetime constraints
25+
--> $DIR/propagate-fail-to-approximate-longer-no-bounds.rs:47:9
26+
|
27+
LL | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
28+
| --------- - has type `&std::cell::Cell<&'1 u32>`
29+
| |
30+
| has type `&std::cell::Cell<&'2 &u32>`
31+
LL | // Only works if 'x: 'y:
32+
LL | demand_y(x, y, x.get())
33+
| ^^^^^^^^^^^^^^^^^^^^^^^ argument requires that `'1` must outlive `'2`
34+
3535
note: No external requirements
3636
--> $DIR/propagate-fail-to-approximate-longer-no-bounds.rs:44:1
3737
|

0 commit comments

Comments
 (0)