Skip to content

Commit 4b7bf58

Browse files
committed
ExprUseVisitor: use tracing::instrument as appropriate
Replace debug! calls that output a worse version of what #[instrument] does.
1 parent 06e8a1d commit 4b7bf58

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

compiler/rustc_hir_typeck/src/expr_use_visitor.rs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use rustc_middle::ty::{
2828
use rustc_middle::{bug, span_bug};
2929
use rustc_span::{ErrorGuaranteed, Span};
3030
use rustc_trait_selection::infer::InferCtxtExt;
31-
use tracing::{debug, trace};
31+
use tracing::{debug, instrument, trace};
3232

3333
use crate::fn_ctxt::FnCtxt;
3434

@@ -320,19 +320,17 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
320320
Ok(())
321321
}
322322

323+
#[instrument(skip(self), level = "debug")]
323324
fn consume_or_copy(&self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: HirId) {
324-
debug!("delegate_consume(place_with_id={:?})", place_with_id);
325-
326325
if self.cx.type_is_copy_modulo_regions(place_with_id.place.ty()) {
327326
self.delegate.borrow_mut().copy(place_with_id, diag_expr_id);
328327
} else {
329328
self.delegate.borrow_mut().consume(place_with_id, diag_expr_id);
330329
}
331330
}
332331

332+
#[instrument(skip(self), level = "debug")]
333333
pub fn consume_clone_or_copy(&self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: HirId) {
334-
debug!("delegate_consume_or_clone(place_with_id={:?})", place_with_id);
335-
336334
// `x.use` will do one of the following
337335
// * if it implements `Copy`, it will be a copy
338336
// * if it implements `UseCloned`, it will be a call to `clone`
@@ -357,18 +355,16 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
357355
}
358356

359357
// FIXME: It's suspicious that this is public; clippy should probably use `walk_expr`.
358+
#[instrument(skip(self), level = "debug")]
360359
pub fn consume_expr(&self, expr: &hir::Expr<'_>) -> Result<(), Cx::Error> {
361-
debug!("consume_expr(expr={:?})", expr);
362-
363360
let place_with_id = self.cat_expr(expr)?;
364361
self.consume_or_copy(&place_with_id, place_with_id.hir_id);
365362
self.walk_expr(expr)?;
366363
Ok(())
367364
}
368365

366+
#[instrument(skip(self), level = "debug")]
369367
pub fn consume_or_clone_expr(&self, expr: &hir::Expr<'_>) -> Result<(), Cx::Error> {
370-
debug!("consume_or_clone_expr(expr={:?})", expr);
371-
372368
let place_with_id = self.cat_expr(expr)?;
373369
self.consume_clone_or_copy(&place_with_id, place_with_id.hir_id);
374370
self.walk_expr(expr)?;
@@ -382,17 +378,15 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
382378
Ok(())
383379
}
384380

381+
#[instrument(skip(self), level = "debug")]
385382
fn borrow_expr(&self, expr: &hir::Expr<'_>, bk: ty::BorrowKind) -> Result<(), Cx::Error> {
386-
debug!("borrow_expr(expr={:?}, bk={:?})", expr, bk);
387-
388383
let place_with_id = self.cat_expr(expr)?;
389384
self.delegate.borrow_mut().borrow(&place_with_id, place_with_id.hir_id, bk);
390385
self.walk_expr(expr)
391386
}
392387

388+
#[instrument(skip(self), level = "debug")]
393389
pub fn walk_expr(&self, expr: &hir::Expr<'_>) -> Result<(), Cx::Error> {
394-
debug!("walk_expr(expr={:?})", expr);
395-
396390
self.walk_adjustment(expr)?;
397391

398392
match expr.kind {
@@ -739,9 +733,8 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
739733

740734
/// Indicates that the value of `blk` will be consumed, meaning either copied or moved
741735
/// depending on its type.
736+
#[instrument(skip(self), level = "debug")]
742737
fn walk_block(&self, blk: &hir::Block<'_>) -> Result<(), Cx::Error> {
743-
debug!("walk_block(blk.hir_id={})", blk.hir_id);
744-
745738
for stmt in blk.stmts {
746739
self.walk_stmt(stmt)?;
747740
}
@@ -963,14 +956,13 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
963956
///
964957
/// Do note that discrepancies like these do still create weird language
965958
/// semantics, and should be avoided if possible.
959+
#[instrument(skip(self), level = "debug")]
966960
fn walk_pat(
967961
&self,
968962
discr_place: &PlaceWithHirId<'tcx>,
969963
pat: &hir::Pat<'_>,
970964
has_guard: bool,
971965
) -> Result<(), Cx::Error> {
972-
debug!("walk_pat(discr_place={:?}, pat={:?}, has_guard={:?})", discr_place, pat, has_guard);
973-
974966
let tcx = self.cx.tcx();
975967
self.cat_pattern(discr_place.clone(), pat, &mut |place, pat| {
976968
debug!("walk_pat: pat.kind={:?}", pat.kind);
@@ -1121,6 +1113,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
11211113
///
11221114
/// - When reporting the Place back to the Delegate, ensure that the UpvarId uses the enclosing
11231115
/// closure as the DefId.
1116+
#[instrument(skip(self), level = "debug")]
11241117
fn walk_captures(&self, closure_expr: &hir::Closure<'_>) -> Result<(), Cx::Error> {
11251118
fn upvar_is_local_variable(
11261119
upvars: Option<&FxIndexMap<HirId, hir::Upvar>>,
@@ -1130,8 +1123,6 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
11301123
upvars.map(|upvars| !upvars.contains_key(&upvar_id)).unwrap_or(body_owner_is_closure)
11311124
}
11321125

1133-
debug!("walk_captures({:?})", closure_expr);
1134-
11351126
let tcx = self.cx.tcx();
11361127
let closure_def_id = closure_expr.def_id;
11371128
// For purposes of this function, coroutine and closures are equivalent.

0 commit comments

Comments
 (0)