Skip to content

Commit 427dc18

Browse files
committed
tweak debug output and bless tests
1 parent 97381d2 commit 427dc18

File tree

4 files changed

+34
-30
lines changed

4 files changed

+34
-30
lines changed

compiler/rustc_borrowck/src/nll.rs

+18-14
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ use rustc_middle::mir::{
1010
BasicBlock, Body, ClosureOutlivesSubject, ClosureRegionRequirements, LocalKind, Location,
1111
Promoted,
1212
};
13-
use rustc_middle::ty::{self, OpaqueHiddenType, Region, RegionVid};
13+
use rustc_middle::ty::{self, OpaqueHiddenType, Region, RegionVid, TyCtxt};
1414
use rustc_span::symbol::sym;
1515
use std::env;
16-
use std::fmt::Debug;
1716
use std::io;
1817
use std::path::PathBuf;
1918
use std::rc::Rc;
@@ -325,7 +324,7 @@ pub(super) fn dump_mir_results<'tcx>(
325324
infcx: &BorrowckInferCtxt<'_, 'tcx>,
326325
body: &Body<'tcx>,
327326
regioncx: &RegionInferenceContext<'tcx>,
328-
closure_region_requirements: &Option<ClosureRegionRequirements<'_>>,
327+
closure_region_requirements: &Option<ClosureRegionRequirements<'tcx>>,
329328
) {
330329
if !dump_enabled(infcx.tcx, "nll", body.source.def_id()) {
331330
return;
@@ -340,9 +339,11 @@ pub(super) fn dump_mir_results<'tcx>(
340339

341340
if let Some(closure_region_requirements) = closure_region_requirements {
342341
writeln!(out, "| Free Region Constraints")?;
343-
for_each_region_constraint(closure_region_requirements, &mut |msg| {
344-
writeln!(out, "| {}", msg)
345-
})?;
342+
for_each_region_constraint(
343+
infcx.tcx,
344+
closure_region_requirements,
345+
&mut |msg| writeln!(out, "| {}", msg),
346+
)?;
346347
writeln!(out, "|")?;
347348
}
348349
}
@@ -375,7 +376,7 @@ pub(super) fn dump_annotation<'tcx>(
375376
infcx: &BorrowckInferCtxt<'_, 'tcx>,
376377
body: &Body<'tcx>,
377378
regioncx: &RegionInferenceContext<'tcx>,
378-
closure_region_requirements: &Option<ClosureRegionRequirements<'_>>,
379+
closure_region_requirements: &Option<ClosureRegionRequirements<'tcx>>,
379380
opaque_type_values: &VecMap<LocalDefId, OpaqueHiddenType<'tcx>>,
380381
errors: &mut crate::error::BorrowckErrors<'tcx>,
381382
) {
@@ -405,7 +406,7 @@ pub(super) fn dump_annotation<'tcx>(
405406

406407
// Dump the region constraints we are imposing *between* those
407408
// newly created variables.
408-
for_each_region_constraint(closure_region_requirements, &mut |msg| {
409+
for_each_region_constraint(tcx, closure_region_requirements, &mut |msg| {
409410
err.note(msg);
410411
Ok(())
411412
})
@@ -426,16 +427,19 @@ pub(super) fn dump_annotation<'tcx>(
426427
errors.buffer_non_error_diag(err);
427428
}
428429

429-
fn for_each_region_constraint(
430-
closure_region_requirements: &ClosureRegionRequirements<'_>,
430+
fn for_each_region_constraint<'tcx>(
431+
tcx: TyCtxt<'tcx>,
432+
closure_region_requirements: &ClosureRegionRequirements<'tcx>,
431433
with_msg: &mut dyn FnMut(&str) -> io::Result<()>,
432434
) -> io::Result<()> {
433435
for req in &closure_region_requirements.outlives_requirements {
434-
let subject: &dyn Debug = match &req.subject {
435-
ClosureOutlivesSubject::Region(subject) => subject,
436-
ClosureOutlivesSubject::Ty(ty) => ty,
436+
let subject = match req.subject {
437+
ClosureOutlivesSubject::Region(subject) => format!("{:?}", subject),
438+
ClosureOutlivesSubject::Ty(ty) => {
439+
format!("{:?}", ty.instantiate(tcx, |vid| tcx.mk_re_var(vid)))
440+
}
437441
};
438-
with_msg(&format!("where {:?}: {:?}", subject, req.outlived_free_region,))?;
442+
with_msg(&format!("where {}: {:?}", subject, req.outlived_free_region,))?;
439443
}
440444
Ok(())
441445
}

tests/ui/nll/ty-outlives/projection-one-region-closure.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
110110
(),
111111
]
112112
= note: number of external vids: 4
113-
= note: where <T as Anything<ReEarlyBound(1, 'b)>>::AssocType: '_#3r
113+
= note: where <T as Anything<'_#2r>>::AssocType: '_#3r
114114

115115
note: no external requirements
116116
--> $DIR/projection-one-region-closure.rs:62:1

tests/ui/nll/ty-outlives/projection-one-region-trait-bound-closure.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
8686
(),
8787
]
8888
= note: number of external vids: 4
89-
= note: where <T as Anything<ReEarlyBound(1, 'b)>>::AssocType: '_#3r
89+
= note: where <T as Anything<'_#2r>>::AssocType: '_#3r
9090

9191
note: no external requirements
9292
--> $DIR/projection-one-region-trait-bound-closure.rs:52:1

tests/ui/nll/ty-outlives/projection-two-region-trait-bound-closure.stderr

+14-14
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
1111
]
1212
= note: late-bound region is '_#4r
1313
= note: number of external vids: 5
14-
= note: where <T as Anything<ReEarlyBound(0, 'b), ReEarlyBound(1, 'c)>>::AssocType: '_#3r
14+
= note: where <T as Anything<'_#1r, '_#2r>>::AssocType: '_#3r
1515

1616
note: no external requirements
1717
--> $DIR/projection-two-region-trait-bound-closure.rs:34:1
@@ -23,14 +23,14 @@ LL | | T: Anything<'b, 'c>,
2323
|
2424
= note: defining type: no_relationships_late::<'_#1r, '_#2r, T>
2525

26-
error[E0309]: the associated type `<T as Anything<ReEarlyBound(0, 'b), ReEarlyBound(1, 'c)>>::AssocType` may not live long enough
26+
error[E0309]: the associated type `<T as Anything<'_#5r, '_#6r>>::AssocType` may not live long enough
2727
--> $DIR/projection-two-region-trait-bound-closure.rs:38:39
2828
|
2929
LL | with_signature(cell, t, |cell, t| require(cell, t));
3030
| ^^^^^^^^^^^^^^^^
3131
|
32-
= help: consider adding an explicit lifetime bound `<T as Anything<ReEarlyBound(0, 'b), ReEarlyBound(1, 'c)>>::AssocType: 'a`...
33-
= note: ...so that the type `<T as Anything<ReEarlyBound(0, 'b), ReEarlyBound(1, 'c)>>::AssocType` will meet its required lifetime bounds
32+
= help: consider adding an explicit lifetime bound `<T as Anything<'_#5r, '_#6r>>::AssocType: 'a`...
33+
= note: ...so that the type `<T as Anything<'_#5r, '_#6r>>::AssocType` will meet its required lifetime bounds
3434

3535
note: external requirements
3636
--> $DIR/projection-two-region-trait-bound-closure.rs:48:29
@@ -44,7 +44,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
4444
(),
4545
]
4646
= note: number of external vids: 5
47-
= note: where <T as Anything<ReEarlyBound(1, 'b), ReEarlyBound(2, 'c)>>::AssocType: '_#4r
47+
= note: where <T as Anything<'_#2r, '_#3r>>::AssocType: '_#4r
4848

4949
note: no external requirements
5050
--> $DIR/projection-two-region-trait-bound-closure.rs:43:1
@@ -57,14 +57,14 @@ LL | | 'a: 'a,
5757
|
5858
= note: defining type: no_relationships_early::<'_#1r, '_#2r, '_#3r, T>
5959

60-
error[E0309]: the associated type `<T as Anything<ReEarlyBound(1, 'b), ReEarlyBound(2, 'c)>>::AssocType` may not live long enough
60+
error[E0309]: the associated type `<T as Anything<'_#6r, '_#7r>>::AssocType` may not live long enough
6161
--> $DIR/projection-two-region-trait-bound-closure.rs:48:39
6262
|
6363
LL | with_signature(cell, t, |cell, t| require(cell, t));
6464
| ^^^^^^^^^^^^^^^^
6565
|
66-
= help: consider adding an explicit lifetime bound `<T as Anything<ReEarlyBound(1, 'b), ReEarlyBound(2, 'c)>>::AssocType: 'a`...
67-
= note: ...so that the type `<T as Anything<ReEarlyBound(1, 'b), ReEarlyBound(2, 'c)>>::AssocType` will meet its required lifetime bounds
66+
= help: consider adding an explicit lifetime bound `<T as Anything<'_#6r, '_#7r>>::AssocType: 'a`...
67+
= note: ...so that the type `<T as Anything<'_#6r, '_#7r>>::AssocType` will meet its required lifetime bounds
6868

6969
note: external requirements
7070
--> $DIR/projection-two-region-trait-bound-closure.rs:61:29
@@ -78,7 +78,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
7878
(),
7979
]
8080
= note: number of external vids: 5
81-
= note: where <T as Anything<ReEarlyBound(1, 'b), ReEarlyBound(2, 'c)>>::AssocType: '_#4r
81+
= note: where <T as Anything<'_#2r, '_#3r>>::AssocType: '_#4r
8282

8383
note: no external requirements
8484
--> $DIR/projection-two-region-trait-bound-closure.rs:53:1
@@ -103,7 +103,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
103103
(),
104104
]
105105
= note: number of external vids: 5
106-
= note: where <T as Anything<ReEarlyBound(1, 'b), ReEarlyBound(2, 'c)>>::AssocType: '_#4r
106+
= note: where <T as Anything<'_#2r, '_#3r>>::AssocType: '_#4r
107107

108108
note: no external requirements
109109
--> $DIR/projection-two-region-trait-bound-closure.rs:65:1
@@ -128,7 +128,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
128128
(),
129129
]
130130
= note: number of external vids: 5
131-
= note: where <T as Anything<ReEarlyBound(1, 'b), ReEarlyBound(2, 'c)>>::AssocType: '_#4r
131+
= note: where <T as Anything<'_#2r, '_#3r>>::AssocType: '_#4r
132132

133133
note: no external requirements
134134
--> $DIR/projection-two-region-trait-bound-closure.rs:74:1
@@ -154,7 +154,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
154154
]
155155
= note: late-bound region is '_#3r
156156
= note: number of external vids: 4
157-
= note: where <T as Anything<ReEarlyBound(0, 'b), ReEarlyBound(0, 'b)>>::AssocType: '_#2r
157+
= note: where <T as Anything<'_#1r, '_#1r>>::AssocType: '_#2r
158158

159159
note: no external requirements
160160
--> $DIR/projection-two-region-trait-bound-closure.rs:83:1
@@ -194,7 +194,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
194194
(),
195195
]
196196
= note: number of external vids: 4
197-
= note: where <T as Anything<ReEarlyBound(1, 'b), ReEarlyBound(1, 'b)>>::AssocType: '_#3r
197+
= note: where <T as Anything<'_#2r, '_#2r>>::AssocType: '_#3r
198198

199199
note: no external requirements
200200
--> $DIR/projection-two-region-trait-bound-closure.rs:92:1
@@ -219,7 +219,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
219219
(),
220220
]
221221
= note: number of external vids: 3
222-
= note: where <T as Anything<ReEarlyBound(0, 'a), ReEarlyBound(0, 'a)>>::AssocType: '_#2r
222+
= note: where <T as Anything<'_#1r, '_#1r>>::AssocType: '_#2r
223223

224224
note: no external requirements
225225
--> $DIR/projection-two-region-trait-bound-closure.rs:101:1

0 commit comments

Comments
 (0)