Skip to content

Commit 7b84298

Browse files
authored
Rollup merge of rust-lang#101146 - jackh726:borrowck-logging, r=compiler-errors
Various changes to logging of borrowck-related code Cleanups found when doing other changes r? `@compiler-errors`
2 parents 3094cc1 + 8033c3c commit 7b84298

File tree

13 files changed

+41
-84
lines changed

13 files changed

+41
-84
lines changed

compiler/rustc_borrowck/src/constraints/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ impl<'tcx> fmt::Debug for OutlivesConstraint<'tcx> {
105105
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
106106
write!(
107107
formatter,
108-
"({:?}: {:?}) due to {:?} ({:?})",
109-
self.sup, self.sub, self.locations, self.variance_info
108+
"({:?}: {:?}) due to {:?} ({:?}) ({:?})",
109+
self.sup, self.sub, self.locations, self.variance_info, self.category,
110110
)
111111
}
112112
}

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+4-18
Original file line numberDiff line numberDiff line change
@@ -1119,20 +1119,14 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11191119
/// short a lifetime. (But sometimes it is more useful to report
11201120
/// it as a more direct conflict between the execution of a
11211121
/// `Drop::drop` with an aliasing borrow.)
1122+
#[instrument(level = "debug", skip(self))]
11221123
pub(crate) fn report_borrowed_value_does_not_live_long_enough(
11231124
&mut self,
11241125
location: Location,
11251126
borrow: &BorrowData<'tcx>,
11261127
place_span: (Place<'tcx>, Span),
11271128
kind: Option<WriteKind>,
11281129
) {
1129-
debug!(
1130-
"report_borrowed_value_does_not_live_long_enough(\
1131-
{:?}, {:?}, {:?}, {:?}\
1132-
)",
1133-
location, borrow, place_span, kind
1134-
);
1135-
11361130
let drop_span = place_span.1;
11371131
let root_place =
11381132
self.prefixes(borrow.borrowed_place.as_ref(), PrefixSet::All).last().unwrap();
@@ -1189,10 +1183,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11891183
let kind_place = kind.filter(|_| place_desc.is_some()).map(|k| (k, place_span.0));
11901184
let explanation = self.explain_why_borrow_contains_point(location, &borrow, kind_place);
11911185

1192-
debug!(
1193-
"report_borrowed_value_does_not_live_long_enough(place_desc: {:?}, explanation: {:?})",
1194-
place_desc, explanation
1195-
);
1186+
debug!(?place_desc, ?explanation);
1187+
11961188
let err = match (place_desc, explanation) {
11971189
// If the outlives constraint comes from inside the closure,
11981190
// for example:
@@ -1464,6 +1456,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
14641456
err
14651457
}
14661458

1459+
#[instrument(level = "debug", skip(self))]
14671460
fn report_temporary_value_does_not_live_long_enough(
14681461
&mut self,
14691462
location: Location,
@@ -1473,13 +1466,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
14731466
proper_span: Span,
14741467
explanation: BorrowExplanation<'tcx>,
14751468
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
1476-
debug!(
1477-
"report_temporary_value_does_not_live_long_enough(\
1478-
{:?}, {:?}, {:?}, {:?}\
1479-
)",
1480-
location, borrow, drop_span, proper_span
1481-
);
1482-
14831469
if let BorrowExplanation::MustBeValidFor { category, span, from_closure: false, .. } =
14841470
explanation
14851471
{

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

+5-15
Original file line numberDiff line numberDiff line change
@@ -336,26 +336,22 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
336336
/// - second half is the place being accessed
337337
///
338338
/// [d]: https://rust-lang.github.io/rfcs/2094-nll.html#leveraging-intuition-framing-errors-in-terms-of-points
339+
#[instrument(level = "debug", skip(self))]
339340
pub(crate) fn explain_why_borrow_contains_point(
340341
&self,
341342
location: Location,
342343
borrow: &BorrowData<'tcx>,
343344
kind_place: Option<(WriteKind, Place<'tcx>)>,
344345
) -> BorrowExplanation<'tcx> {
345-
debug!(
346-
"explain_why_borrow_contains_point(location={:?}, borrow={:?}, kind_place={:?})",
347-
location, borrow, kind_place
348-
);
349-
350346
let regioncx = &self.regioncx;
351347
let body: &Body<'_> = &self.body;
352348
let tcx = self.infcx.tcx;
353349

354350
let borrow_region_vid = borrow.region;
355-
debug!("explain_why_borrow_contains_point: borrow_region_vid={:?}", borrow_region_vid);
351+
debug!(?borrow_region_vid);
356352

357353
let region_sub = self.regioncx.find_sub_region_live_at(borrow_region_vid, location);
358-
debug!("explain_why_borrow_contains_point: region_sub={:?}", region_sub);
354+
debug!(?region_sub);
359355

360356
match find_use::find(body, regioncx, tcx, region_sub, location) {
361357
Some(Cause::LiveVar(local, location)) => {
@@ -408,17 +404,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
408404
opt_place_desc,
409405
}
410406
} else {
411-
debug!(
412-
"explain_why_borrow_contains_point: \
413-
Could not generate a region name"
414-
);
407+
debug!("Could not generate a region name");
415408
BorrowExplanation::Unexplained
416409
}
417410
} else {
418-
debug!(
419-
"explain_why_borrow_contains_point: \
420-
Could not generate an error region vid"
421-
);
411+
debug!("Could not generate an error region vid");
422412
BorrowExplanation::Unexplained
423413
}
424414
}

compiler/rustc_borrowck/src/lib.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
975975
}
976976
}
977977

978+
#[instrument(level = "debug", skip(self, flow_state))]
978979
fn check_access_for_conflict(
979980
&mut self,
980981
location: Location,
@@ -983,11 +984,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
983984
rw: ReadOrWrite,
984985
flow_state: &Flows<'cx, 'tcx>,
985986
) -> bool {
986-
debug!(
987-
"check_access_for_conflict(location={:?}, place_span={:?}, sd={:?}, rw={:?})",
988-
location, place_span, sd, rw,
989-
);
990-
991987
let mut error_reported = false;
992988
let tcx = self.infcx.tcx;
993989
let body = self.body;
@@ -1451,13 +1447,13 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
14511447

14521448
/// Checks whether a borrow of this place is invalidated when the function
14531449
/// exits
1450+
#[instrument(level = "debug", skip(self))]
14541451
fn check_for_invalidation_at_exit(
14551452
&mut self,
14561453
location: Location,
14571454
borrow: &BorrowData<'tcx>,
14581455
span: Span,
14591456
) {
1460-
debug!("check_for_invalidation_at_exit({:?})", borrow);
14611457
let place = borrow.borrowed_place;
14621458
let mut root_place = PlaceRef { local: place.local, projection: &[] };
14631459

compiler/rustc_borrowck/src/places_conflict.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub(crate) fn places_conflict<'tcx>(
4444
/// access depth. The `bias` parameter is used to determine how the unknowable (comparing runtime
4545
/// array indices, for example) should be interpreted - this depends on what the caller wants in
4646
/// order to make the conservative choice and preserve soundness.
47+
#[instrument(level = "debug", skip(tcx, body))]
4748
pub(super) fn borrow_conflicts_with_place<'tcx>(
4849
tcx: TyCtxt<'tcx>,
4950
body: &Body<'tcx>,
@@ -53,11 +54,6 @@ pub(super) fn borrow_conflicts_with_place<'tcx>(
5354
access: AccessDepth,
5455
bias: PlaceConflictBias,
5556
) -> bool {
56-
debug!(
57-
"borrow_conflicts_with_place({:?}, {:?}, {:?}, {:?})",
58-
borrow_place, access_place, access, bias,
59-
);
60-
6157
// This Local/Local case is handled by the more general code below, but
6258
// it's so common that it's a speed win to check for it first.
6359
if let Some(l1) = borrow_place.as_local() && let Some(l2) = access_place.as_local() {
@@ -140,10 +136,9 @@ fn place_components_conflict<'tcx>(
140136
for (i, (borrow_c, &access_c)) in
141137
iter::zip(borrow_place.projection, access_place.projection).enumerate()
142138
{
143-
debug!("borrow_conflicts_with_place: borrow_c = {:?}", borrow_c);
144-
let borrow_proj_base = &borrow_place.projection[..i];
139+
debug!(?borrow_c, ?access_c);
145140

146-
debug!("borrow_conflicts_with_place: access_c = {:?}", access_c);
141+
let borrow_proj_base = &borrow_place.projection[..i];
147142

148143
// Borrow and access path both have more components.
149144
//
@@ -180,7 +175,7 @@ fn place_components_conflict<'tcx>(
180175
// idea, at least for now, so just give up and
181176
// report a conflict. This is unsafe code anyway so
182177
// the user could always use raw pointers.
183-
debug!("borrow_conflicts_with_place: arbitrary -> conflict");
178+
debug!("arbitrary -> conflict");
184179
return true;
185180
}
186181
Overlap::EqualOrDisjoint => {
@@ -189,7 +184,7 @@ fn place_components_conflict<'tcx>(
189184
Overlap::Disjoint => {
190185
// We have proven the borrow disjoint - further
191186
// projections will remain disjoint.
192-
debug!("borrow_conflicts_with_place: disjoint");
187+
debug!("disjoint");
193188
return false;
194189
}
195190
}

compiler/rustc_borrowck/src/region_infer/mod.rs

+9-15
Original file line numberDiff line numberDiff line change
@@ -1167,8 +1167,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
11671167
/// Therefore, this method should only be used in diagnostic code,
11681168
/// where displaying *some* named universal region is better than
11691169
/// falling back to 'static.
1170+
#[instrument(level = "debug", skip(self))]
11701171
pub(crate) fn approx_universal_upper_bound(&self, r: RegionVid) -> RegionVid {
1171-
debug!("approx_universal_upper_bound(r={:?}={})", r, self.region_value_str(r));
1172+
debug!("{}", self.region_value_str(r));
11721173

11731174
// Find the smallest universal region that contains all other
11741175
// universal regions within `region`.
@@ -1177,7 +1178,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
11771178
let static_r = self.universal_regions.fr_static;
11781179
for ur in self.scc_values.universal_regions_outlived_by(r_scc) {
11791180
let new_lub = self.universal_region_relations.postdom_upper_bound(lub, ur);
1180-
debug!("approx_universal_upper_bound: ur={:?} lub={:?} new_lub={:?}", ur, lub, new_lub);
1181+
debug!(?ur, ?lub, ?new_lub);
11811182
// The upper bound of two non-static regions is static: this
11821183
// means we know nothing about the relationship between these
11831184
// two regions. Pick a 'better' one to use when constructing
@@ -1201,7 +1202,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
12011202
}
12021203
}
12031204

1204-
debug!("approx_universal_upper_bound: r={:?} lub={:?}", r, lub);
1205+
debug!(?r, ?lub);
12051206

12061207
lub
12071208
}
@@ -2048,23 +2049,19 @@ impl<'tcx> RegionInferenceContext<'tcx> {
20482049
/// creating a constraint path that forces `R` to outlive
20492050
/// `from_region`, and then finding the best choices within that
20502051
/// path to blame.
2052+
#[instrument(level = "debug", skip(self, target_test))]
20512053
pub(crate) fn best_blame_constraint(
20522054
&self,
20532055
body: &Body<'tcx>,
20542056
from_region: RegionVid,
20552057
from_region_origin: NllRegionVariableOrigin,
20562058
target_test: impl Fn(RegionVid) -> bool,
20572059
) -> BlameConstraint<'tcx> {
2058-
debug!(
2059-
"best_blame_constraint(from_region={:?}, from_region_origin={:?})",
2060-
from_region, from_region_origin
2061-
);
2062-
20632060
// Find all paths
20642061
let (path, target_region) =
20652062
self.find_constraint_paths_between_regions(from_region, target_test).unwrap();
20662063
debug!(
2067-
"best_blame_constraint: path={:#?}",
2064+
"path={:#?}",
20682065
path.iter()
20692066
.map(|c| format!(
20702067
"{:?} ({:?}: {:?})",
@@ -2116,7 +2113,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
21162113
}
21172114
})
21182115
.collect();
2119-
debug!("best_blame_constraint: categorized_path={:#?}", categorized_path);
2116+
debug!("categorized_path={:#?}", categorized_path);
21202117

21212118
// To find the best span to cite, we first try to look for the
21222119
// final constraint that is interesting and where the `sup` is
@@ -2214,10 +2211,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
22142211
let best_choice =
22152212
if blame_source { range.rev().find(find_region) } else { range.find(find_region) };
22162213

2217-
debug!(
2218-
"best_blame_constraint: best_choice={:?} blame_source={}",
2219-
best_choice, blame_source
2220-
);
2214+
debug!(?best_choice, ?blame_source);
22212215

22222216
if let Some(i) = best_choice {
22232217
if let Some(next) = categorized_path.get(i + 1) {
@@ -2254,7 +2248,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
22542248
// appears to be the most interesting point to report to the
22552249
// user via an even more ad-hoc guess.
22562250
categorized_path.sort_by(|p0, p1| p0.category.cmp(&p1.category));
2257-
debug!("best_blame_constraint: sorted_path={:#?}", categorized_path);
2251+
debug!("sorted_path={:#?}", categorized_path);
22582252

22592253
categorized_path.remove(0)
22602254
}

compiler/rustc_borrowck/src/type_check/canonical.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
2424
/// **Any `rustc_infer::infer` operations that might generate region
2525
/// constraints should occur within this method so that those
2626
/// constraints can be properly localized!**
27-
#[instrument(skip(self, category, op), level = "trace")]
27+
#[instrument(skip(self, op), level = "trace")]
2828
pub(super) fn fully_perform_op<R, Op>(
2929
&mut self,
3030
locations: Locations,

compiler/rustc_borrowck/src/type_check/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
10431043
let CanonicalUserTypeAnnotation { span, ref user_ty, inferred_ty } = *user_annotation;
10441044
let inferred_ty = self.normalize(inferred_ty, Locations::All(span));
10451045
let annotation = self.instantiate_canonical_with_fresh_inference_vars(span, user_ty);
1046+
debug!(?annotation);
10461047
match annotation {
10471048
UserType::Ty(mut ty) => {
10481049
ty = self.normalize(ty, Locations::All(span));

compiler/rustc_infer/src/infer/canonical/canonicalizer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
372372
debug!(
373373
"canonical: region var found with vid {:?}, \
374374
opportunistically resolved to {:?}",
375-
vid, r
375+
vid, resolved_vid
376376
);
377377
let r = self.tcx.reuse_or_mk_region(r, ty::ReVar(resolved_vid));
378378
self.canonicalize_mode.canonicalize_free_region(self, r)

compiler/rustc_infer/src/infer/canonical/query_response.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
6363
Canonical<'tcx, QueryResponse<'tcx, T>>: ArenaAllocatable<'tcx>,
6464
{
6565
let query_response = self.make_query_response(inference_vars, answer, fulfill_cx)?;
66+
debug!("query_response = {:#?}", query_response);
6667
let canonical_result = self.canonicalize_response(query_response);
67-
6868
debug!("canonical_result = {:#?}", canonical_result);
6969

7070
Ok(self.tcx.arena.alloc(canonical_result))
@@ -125,13 +125,15 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
125125
debug!("ambig_errors = {:#?}", ambig_errors);
126126

127127
let region_obligations = self.take_registered_region_obligations();
128+
debug!(?region_obligations);
128129
let region_constraints = self.with_region_constraints(|region_constraints| {
129130
make_query_region_constraints(
130131
tcx,
131132
region_obligations.iter().map(|r_o| (r_o.sup_type, r_o.sub_region)),
132133
region_constraints,
133134
)
134135
});
136+
debug!(?region_constraints);
135137

136138
let certainty =
137139
if ambig_errors.is_empty() { Certainty::Proven } else { Certainty::Ambiguous };
@@ -632,6 +634,8 @@ pub fn make_query_region_constraints<'tcx>(
632634
assert!(verifys.is_empty());
633635
assert!(givens.is_empty());
634636

637+
debug!(?constraints);
638+
635639
let outlives: Vec<_> = constraints
636640
.iter()
637641
.map(|(k, _)| match *k {

compiler/rustc_infer/src/infer/mod.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ pub enum FixupError<'tcx> {
504504
}
505505

506506
/// See the `region_obligations` field for more information.
507-
#[derive(Clone)]
507+
#[derive(Clone, Debug)]
508508
pub struct RegionObligation<'tcx> {
509509
pub sub_region: ty::Region<'tcx>,
510510
pub sup_type: Ty<'tcx>,
@@ -2027,16 +2027,6 @@ impl RegionVariableOrigin {
20272027
}
20282028
}
20292029

2030-
impl<'tcx> fmt::Debug for RegionObligation<'tcx> {
2031-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2032-
write!(
2033-
f,
2034-
"RegionObligation(sub_region={:?}, sup_type={:?})",
2035-
self.sub_region, self.sup_type
2036-
)
2037-
}
2038-
}
2039-
20402030
/// Replaces substs that reference param or infer variables with suitable
20412031
/// placeholders. This function is meant to remove these param and infer
20422032
/// substs when they're not actually needed to evaluate a constant.

compiler/rustc_infer/src/infer/outlives/obligations.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
9292
sub_region: Region<'tcx>,
9393
cause: &ObligationCause<'tcx>,
9494
) {
95+
debug!(?sup_type, ?sub_region, ?cause);
9596
let origin = SubregionOrigin::from_obligation_cause(cause, || {
9697
infer::RelateParamBound(
9798
cause.span,
@@ -248,14 +249,13 @@ where
248249
/// - `origin`, the reason we need this constraint
249250
/// - `ty`, the type `T`
250251
/// - `region`, the region `'a`
252+
#[instrument(level = "debug", skip(self))]
251253
pub fn type_must_outlive(
252254
&mut self,
253255
origin: infer::SubregionOrigin<'tcx>,
254256
ty: Ty<'tcx>,
255257
region: ty::Region<'tcx>,
256258
) {
257-
debug!("type_must_outlive(ty={:?}, region={:?}, origin={:?})", ty, region, origin);
258-
259259
assert!(!ty.has_escaping_bound_vars());
260260

261261
let mut components = smallvec![];

0 commit comments

Comments
 (0)