Skip to content

Commit 908504e

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

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

Diff for: compiler/rustc_hir_typeck/src/expr_use_visitor.rs

+10-19
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
}
@@ -948,14 +941,13 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
948941
}
949942

950943
/// The core driver for walking a pattern
944+
#[instrument(skip(self), level = "debug")]
951945
fn walk_pat(
952946
&self,
953947
discr_place: &PlaceWithHirId<'tcx>,
954948
pat: &hir::Pat<'_>,
955949
has_guard: bool,
956950
) -> Result<(), Cx::Error> {
957-
debug!("walk_pat(discr_place={:?}, pat={:?}, has_guard={:?})", discr_place, pat, has_guard);
958-
959951
let tcx = self.cx.tcx();
960952
self.cat_pattern(discr_place.clone(), pat, &mut |place, pat| {
961953
match pat.kind {
@@ -1048,6 +1040,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
10481040
///
10491041
/// - When reporting the Place back to the Delegate, ensure that the UpvarId uses the enclosing
10501042
/// closure as the DefId.
1043+
#[instrument(skip(self), level = "debug")]
10511044
fn walk_captures(&self, closure_expr: &hir::Closure<'_>) -> Result<(), Cx::Error> {
10521045
fn upvar_is_local_variable(
10531046
upvars: Option<&FxIndexMap<HirId, hir::Upvar>>,
@@ -1057,8 +1050,6 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
10571050
upvars.map(|upvars| !upvars.contains_key(&upvar_id)).unwrap_or(body_owner_is_closure)
10581051
}
10591052

1060-
debug!("walk_captures({:?})", closure_expr);
1061-
10621053
let tcx = self.cx.tcx();
10631054
let closure_def_id = closure_expr.def_id;
10641055
// For purposes of this function, coroutine and closures are equivalent.

0 commit comments

Comments
 (0)