Skip to content

Commit

Permalink
tweak debug output and bless tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aliemjay committed Mar 4, 2023
1 parent 97381d2 commit 427dc18
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 30 deletions.
32 changes: 18 additions & 14 deletions compiler/rustc_borrowck/src/nll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ use rustc_middle::mir::{
BasicBlock, Body, ClosureOutlivesSubject, ClosureRegionRequirements, LocalKind, Location,
Promoted,
};
use rustc_middle::ty::{self, OpaqueHiddenType, Region, RegionVid};
use rustc_middle::ty::{self, OpaqueHiddenType, Region, RegionVid, TyCtxt};
use rustc_span::symbol::sym;
use std::env;
use std::fmt::Debug;
use std::io;
use std::path::PathBuf;
use std::rc::Rc;
Expand Down Expand Up @@ -325,7 +324,7 @@ pub(super) fn dump_mir_results<'tcx>(
infcx: &BorrowckInferCtxt<'_, 'tcx>,
body: &Body<'tcx>,
regioncx: &RegionInferenceContext<'tcx>,
closure_region_requirements: &Option<ClosureRegionRequirements<'_>>,
closure_region_requirements: &Option<ClosureRegionRequirements<'tcx>>,
) {
if !dump_enabled(infcx.tcx, "nll", body.source.def_id()) {
return;
Expand All @@ -340,9 +339,11 @@ pub(super) fn dump_mir_results<'tcx>(

if let Some(closure_region_requirements) = closure_region_requirements {
writeln!(out, "| Free Region Constraints")?;
for_each_region_constraint(closure_region_requirements, &mut |msg| {
writeln!(out, "| {}", msg)
})?;
for_each_region_constraint(
infcx.tcx,
closure_region_requirements,
&mut |msg| writeln!(out, "| {}", msg),
)?;
writeln!(out, "|")?;
}
}
Expand Down Expand Up @@ -375,7 +376,7 @@ pub(super) fn dump_annotation<'tcx>(
infcx: &BorrowckInferCtxt<'_, 'tcx>,
body: &Body<'tcx>,
regioncx: &RegionInferenceContext<'tcx>,
closure_region_requirements: &Option<ClosureRegionRequirements<'_>>,
closure_region_requirements: &Option<ClosureRegionRequirements<'tcx>>,
opaque_type_values: &VecMap<LocalDefId, OpaqueHiddenType<'tcx>>,
errors: &mut crate::error::BorrowckErrors<'tcx>,
) {
Expand Down Expand Up @@ -405,7 +406,7 @@ pub(super) fn dump_annotation<'tcx>(

// Dump the region constraints we are imposing *between* those
// newly created variables.
for_each_region_constraint(closure_region_requirements, &mut |msg| {
for_each_region_constraint(tcx, closure_region_requirements, &mut |msg| {
err.note(msg);
Ok(())
})
Expand All @@ -426,16 +427,19 @@ pub(super) fn dump_annotation<'tcx>(
errors.buffer_non_error_diag(err);
}

fn for_each_region_constraint(
closure_region_requirements: &ClosureRegionRequirements<'_>,
fn for_each_region_constraint<'tcx>(
tcx: TyCtxt<'tcx>,
closure_region_requirements: &ClosureRegionRequirements<'tcx>,
with_msg: &mut dyn FnMut(&str) -> io::Result<()>,
) -> io::Result<()> {
for req in &closure_region_requirements.outlives_requirements {
let subject: &dyn Debug = match &req.subject {
ClosureOutlivesSubject::Region(subject) => subject,
ClosureOutlivesSubject::Ty(ty) => ty,
let subject = match req.subject {
ClosureOutlivesSubject::Region(subject) => format!("{:?}", subject),
ClosureOutlivesSubject::Ty(ty) => {
format!("{:?}", ty.instantiate(tcx, |vid| tcx.mk_re_var(vid)))
}
};
with_msg(&format!("where {:?}: {:?}", subject, req.outlived_free_region,))?;
with_msg(&format!("where {}: {:?}", subject, req.outlived_free_region,))?;
}
Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
(),
]
= note: number of external vids: 4
= note: where <T as Anything<ReEarlyBound(1, 'b)>>::AssocType: '_#3r
= note: where <T as Anything<'_#2r>>::AssocType: '_#3r

note: no external requirements
--> $DIR/projection-one-region-closure.rs:62:1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
(),
]
= note: number of external vids: 4
= note: where <T as Anything<ReEarlyBound(1, 'b)>>::AssocType: '_#3r
= note: where <T as Anything<'_#2r>>::AssocType: '_#3r

note: no external requirements
--> $DIR/projection-one-region-trait-bound-closure.rs:52:1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
]
= note: late-bound region is '_#4r
= note: number of external vids: 5
= note: where <T as Anything<ReEarlyBound(0, 'b), ReEarlyBound(1, 'c)>>::AssocType: '_#3r
= note: where <T as Anything<'_#1r, '_#2r>>::AssocType: '_#3r

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

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

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

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

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

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

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

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

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

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

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

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

0 comments on commit 427dc18

Please sign in to comment.