Skip to content

Commit c50e57f

Browse files
committedNov 13, 2020
Log closure as well
1 parent d0fac05 commit c50e57f

27 files changed

+727
-219
lines changed
 

‎compiler/rustc_typeck/src/check/upvar.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
166166
"For closure={:?}, capture_information={:#?}",
167167
closure_def_id, delegate.capture_information
168168
);
169-
self.log_closure_capture_info(closure_def_id, &delegate.capture_information, span);
169+
self.log_capture_analysis_first_pass(closure_def_id, &delegate.capture_information, span);
170170

171171
if let Some(closure_substs) = infer_kind {
172172
// Unify the (as yet unbound) type variable in the closure
@@ -499,20 +499,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
499499
self.tcx.has_attr(closure_def_id, sym::rustc_capture_analysis)
500500
}
501501

502-
fn log_closure_capture_info(
502+
fn log_capture_analysis_first_pass(
503503
&self,
504504
closure_def_id: rustc_hir::def_id::DefId,
505505
capture_information: &FxIndexMap<Place<'tcx>, ty::CaptureInfo<'tcx>>,
506506
closure_span: Span,
507507
) {
508508
if self.should_log_capture_analysis(closure_def_id) {
509+
let mut diag =
510+
self.tcx.sess.struct_span_err(closure_span, "First Pass analysis includes:");
509511
for (place, capture_info) in capture_information {
510512
let capture_str = construct_capture_info_string(self.tcx, place, capture_info);
511513
let output_str = format!("Capturing {}", capture_str);
512514

513515
let span = capture_info.expr_id.map_or(closure_span, |e| self.tcx.hir().span(e));
514-
self.tcx.sess.span_err(span, &output_str);
516+
diag.span_note(span, &output_str);
515517
}
518+
diag.emit();
516519
}
517520
}
518521

@@ -521,6 +524,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
521524
if let Some(min_captures) =
522525
self.typeck_results.borrow().closure_min_captures.get(&closure_def_id)
523526
{
527+
let mut diag =
528+
self.tcx.sess.struct_span_err(closure_span, "Min Capture analysis includes:");
529+
524530
for (_, min_captures_for_var) in min_captures {
525531
for capture in min_captures_for_var {
526532
let place = &capture.place;
@@ -532,9 +538,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
532538

533539
let span =
534540
capture_info.expr_id.map_or(closure_span, |e| self.tcx.hir().span(e));
535-
self.tcx.sess.span_err(span, &output_str);
541+
diag.span_note(span, &output_str);
536542
}
537543
}
544+
diag.emit();
538545
}
539546
}
540547
}

‎src/test/ui/closures/2229_closure_analysis/arrays-completely-captured.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#![feature(capture_disjoint_fields)]
2-
//~^ WARNING the feature `capture_disjoint_fields` is incomplete
2+
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
3+
//~| `#[warn(incomplete_features)]` on by default
4+
//~| see issue #53488 <https://github.com/rust-lang/rust/issues/53488>
35
#![feature(rustc_attrs)]
46

57
// Ensure that capture analysis results in arrays being completely captured.
@@ -8,10 +10,13 @@ fn main() {
810

911
let mut c = #[rustc_capture_analysis]
1012
//~^ ERROR: attributes on expressions are experimental
13+
//~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
1114
|| {
15+
//~^ ERROR: First Pass analysis includes:
16+
//~| ERROR: Min Capture analysis includes:
1217
m[0] += 10;
13-
//~^ ERROR: Capturing m[] -> MutBorrow
14-
//~| ERROR: Min Capture m[] -> MutBorrow
18+
//~^ NOTE: Capturing m[] -> MutBorrow
19+
//~| NOTE: Min Capture m[] -> MutBorrow
1520
m[1] += 40;
1621
};
1722

‎src/test/ui/closures/2229_closure_analysis/arrays-completely-captured.stderr

+29-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0658]: attributes on expressions are experimental
2-
--> $DIR/arrays-completely-captured.rs:9:17
2+
--> $DIR/arrays-completely-captured.rs:11:17
33
|
44
LL | let mut c = #[rustc_capture_analysis]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -16,14 +16,38 @@ LL | #![feature(capture_disjoint_fields)]
1616
= note: `#[warn(incomplete_features)]` on by default
1717
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
1818

19-
error: Capturing m[] -> MutBorrow
20-
--> $DIR/arrays-completely-captured.rs:12:9
19+
error: First Pass analysis includes:
20+
--> $DIR/arrays-completely-captured.rs:14:5
21+
|
22+
LL | / || {
23+
LL | |
24+
LL | |
25+
LL | | m[0] += 10;
26+
... |
27+
LL | | m[1] += 40;
28+
LL | | };
29+
| |_____^
30+
|
31+
note: Capturing m[] -> MutBorrow
32+
--> $DIR/arrays-completely-captured.rs:17:9
2133
|
2234
LL | m[0] += 10;
2335
| ^
2436

25-
error: Min Capture m[] -> MutBorrow
26-
--> $DIR/arrays-completely-captured.rs:12:9
37+
error: Min Capture analysis includes:
38+
--> $DIR/arrays-completely-captured.rs:14:5
39+
|
40+
LL | / || {
41+
LL | |
42+
LL | |
43+
LL | | m[0] += 10;
44+
... |
45+
LL | | m[1] += 40;
46+
LL | | };
47+
| |_____^
48+
|
49+
note: Min Capture m[] -> MutBorrow
50+
--> $DIR/arrays-completely-captured.rs:17:9
2751
|
2852
LL | m[0] += 10;
2953
| ^

‎src/test/ui/closures/2229_closure_analysis/capture-disjoint-field-struct.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// FIXME(arora-aman) add run-pass once 2229 is implemented
22

33
#![feature(capture_disjoint_fields)]
4-
//~^ WARNING the feature `capture_disjoint_fields` is incomplete
4+
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
5+
//~| NOTE: `#[warn(incomplete_features)]` on by default
6+
//~| NOTE: see issue #53488 <https://github.com/rust-lang/rust/issues/53488>
57
#![feature(rustc_attrs)]
68

79
struct Point {
@@ -14,10 +16,13 @@ fn main() {
1416

1517
let c = #[rustc_capture_analysis]
1618
//~^ ERROR: attributes on expressions are experimental
19+
//~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
1720
|| {
21+
//~^ First Pass analysis includes:
22+
//~| Min Capture analysis includes:
1823
println!("{}", p.x);
19-
//~^ ERROR: Capturing p[(0, 0)] -> ImmBorrow
20-
//~| ERROR: Min Capture p[(0, 0)] -> ImmBorrow
24+
//~^ NOTE: Capturing p[(0, 0)] -> ImmBorrow
25+
//~| NOTE: Min Capture p[(0, 0)] -> ImmBorrow
2126
};
2227

2328
// `c` should only capture `p.x`, therefore mutating `p.y` is allowed.

‎src/test/ui/closures/2229_closure_analysis/capture-disjoint-field-struct.stderr

+29-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0658]: attributes on expressions are experimental
2-
--> $DIR/capture-disjoint-field-struct.rs:15:13
2+
--> $DIR/capture-disjoint-field-struct.rs:17:13
33
|
44
LL | let c = #[rustc_capture_analysis]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -16,14 +16,38 @@ LL | #![feature(capture_disjoint_fields)]
1616
= note: `#[warn(incomplete_features)]` on by default
1717
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
1818

19-
error: Capturing p[(0, 0)] -> ImmBorrow
20-
--> $DIR/capture-disjoint-field-struct.rs:18:24
19+
error: First Pass analysis includes:
20+
--> $DIR/capture-disjoint-field-struct.rs:20:5
21+
|
22+
LL | / || {
23+
LL | |
24+
LL | |
25+
LL | | println!("{}", p.x);
26+
LL | |
27+
LL | |
28+
LL | | };
29+
| |_____^
30+
|
31+
note: Capturing p[(0, 0)] -> ImmBorrow
32+
--> $DIR/capture-disjoint-field-struct.rs:23:24
2133
|
2234
LL | println!("{}", p.x);
2335
| ^^^
2436

25-
error: Min Capture p[(0, 0)] -> ImmBorrow
26-
--> $DIR/capture-disjoint-field-struct.rs:18:24
37+
error: Min Capture analysis includes:
38+
--> $DIR/capture-disjoint-field-struct.rs:20:5
39+
|
40+
LL | / || {
41+
LL | |
42+
LL | |
43+
LL | | println!("{}", p.x);
44+
LL | |
45+
LL | |
46+
LL | | };
47+
| |_____^
48+
|
49+
note: Min Capture p[(0, 0)] -> ImmBorrow
50+
--> $DIR/capture-disjoint-field-struct.rs:23:24
2751
|
2852
LL | println!("{}", p.x);
2953
| ^^^

‎src/test/ui/closures/2229_closure_analysis/capture-disjoint-field-tuple.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
// FIXME(arora-aman) add run-pass once 2229 is implemented
22

33
#![feature(capture_disjoint_fields)]
4-
//~^ WARNING the feature `capture_disjoint_fields` is incomplete
4+
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
5+
//~| NOTE: `#[warn(incomplete_features)]` on by default
6+
//~| NOTE: see issue #53488 <https://github.com/rust-lang/rust/issues/53488>
57
#![feature(rustc_attrs)]
68

79
fn main() {
810
let mut t = (10, 10);
911

1012
let c = #[rustc_capture_analysis]
1113
//~^ ERROR: attributes on expressions are experimental
14+
//~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
1215
|| {
16+
//~^ First Pass analysis includes:
17+
//~| Min Capture analysis includes:
1318
println!("{}", t.0);
14-
//~^ ERROR: Capturing t[(0, 0)] -> ImmBorrow
15-
//~| ERROR: Min Capture t[(0, 0)] -> ImmBorrow
19+
//~^ NOTE: Capturing t[(0, 0)] -> ImmBorrow
20+
//~| NOTE: Min Capture t[(0, 0)] -> ImmBorrow
1621
};
1722

1823
// `c` only captures t.0, therefore mutating t.1 is allowed.

‎src/test/ui/closures/2229_closure_analysis/capture-disjoint-field-tuple.stderr

+29-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0658]: attributes on expressions are experimental
2-
--> $DIR/capture-disjoint-field-tuple.rs:10:13
2+
--> $DIR/capture-disjoint-field-tuple.rs:12:13
33
|
44
LL | let c = #[rustc_capture_analysis]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -16,14 +16,38 @@ LL | #![feature(capture_disjoint_fields)]
1616
= note: `#[warn(incomplete_features)]` on by default
1717
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
1818

19-
error: Capturing t[(0, 0)] -> ImmBorrow
20-
--> $DIR/capture-disjoint-field-tuple.rs:13:24
19+
error: First Pass analysis includes:
20+
--> $DIR/capture-disjoint-field-tuple.rs:15:5
21+
|
22+
LL | / || {
23+
LL | |
24+
LL | |
25+
LL | | println!("{}", t.0);
26+
LL | |
27+
LL | |
28+
LL | | };
29+
| |_____^
30+
|
31+
note: Capturing t[(0, 0)] -> ImmBorrow
32+
--> $DIR/capture-disjoint-field-tuple.rs:18:24
2133
|
2234
LL | println!("{}", t.0);
2335
| ^^^
2436

25-
error: Min Capture t[(0, 0)] -> ImmBorrow
26-
--> $DIR/capture-disjoint-field-tuple.rs:13:24
37+
error: Min Capture analysis includes:
38+
--> $DIR/capture-disjoint-field-tuple.rs:15:5
39+
|
40+
LL | / || {
41+
LL | |
42+
LL | |
43+
LL | | println!("{}", t.0);
44+
LL | |
45+
LL | |
46+
LL | | };
47+
| |_____^
48+
|
49+
note: Min Capture t[(0, 0)] -> ImmBorrow
50+
--> $DIR/capture-disjoint-field-tuple.rs:18:24
2751
|
2852
LL | println!("{}", t.0);
2953
| ^^^

‎src/test/ui/closures/2229_closure_analysis/capture-enums.rs

+18-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#![feature(capture_disjoint_fields)]
2-
//~^ WARNING the feature `capture_disjoint_fields` is incomplete
2+
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
3+
//~| NOTE: `#[warn(incomplete_features)]` on by default
4+
//~| NOTE: see issue #53488 <https://github.com/rust-lang/rust/issues/53488>
35
#![feature(rustc_attrs)]
46

57
enum Info {
@@ -15,18 +17,21 @@ fn multi_variant_enum() {
1517

1618
let c = #[rustc_capture_analysis]
1719
//~^ ERROR: attributes on expressions are experimental
20+
//~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
1821
|| {
22+
//~^ First Pass analysis includes:
23+
//~| Min Capture analysis includes:
1924
if let Info::Point(_, _, str) = point {
20-
//~^ Capturing point[] -> ImmBorrow
21-
//~| Capturing point[(2, 0)] -> ByValue
22-
//~| Min Capture point[] -> ByValue
25+
//~^ NOTE: Capturing point[] -> ImmBorrow
26+
//~| NOTE: Capturing point[(2, 0)] -> ByValue
27+
//~| NOTE: Min Capture point[] -> ByValue
2328
println!("{}", str);
2429
}
2530

2631
if let Info::Meta(_, v) = meta {
27-
//~^ Capturing meta[] -> ImmBorrow
28-
//~| Capturing meta[(1, 1)] -> ByValue
29-
//~| Min Capture meta[] -> ByValue
32+
//~^ NOTE: Capturing meta[] -> ImmBorrow
33+
//~| NOTE: Capturing meta[(1, 1)] -> ByValue
34+
//~| NOTE: Min Capture meta[] -> ByValue
3035
println!("{:?}", v);
3136
}
3237
};
@@ -43,10 +48,13 @@ fn single_variant_enum() {
4348

4449
let c = #[rustc_capture_analysis]
4550
//~^ ERROR: attributes on expressions are experimental
51+
//~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
4652
|| {
47-
let SingleVariant::Point(_, _, str) = point;
48-
//~^ Capturing point[(2, 0)] -> ByValue
49-
//~| Min Capture point[(2, 0)] -> ByValue
53+
//~^ First Pass analysis includes:
54+
//~| Min Capture analysis includes:
55+
let SingleVariant::Point(_, _, str) = point;
56+
//~^ NOTE: Capturing point[(2, 0)] -> ByValue
57+
//~| NOTE: Min Capture point[(2, 0)] -> ByValue
5058
println!("{}", str);
5159
};
5260

0 commit comments

Comments
 (0)
Please sign in to comment.