Skip to content

Commit 1dc6b91

Browse files
committed
rustc_resolve: use structured fields in traces
1 parent efc2576 commit 1dc6b91

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use rustc_span::hygiene::MacroKind;
3030
use rustc_span::source_map::SourceMap;
3131
use rustc_span::{BytePos, Ident, Span, Symbol, SyntaxContext, kw, sym};
3232
use thin_vec::{ThinVec, thin_vec};
33-
use tracing::debug;
33+
use tracing::{debug, instrument};
3434

3535
use crate::errors::{
3636
self, AddedMacroUse, ChangeImportBinding, ChangeImportBindingSuggestion, ConsiderAddingADerive,
@@ -2235,13 +2235,14 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
22352235
}
22362236

22372237
/// Adds suggestions for a path that cannot be resolved.
2238+
#[instrument(skip(self, parent_scope))]
22382239
pub(crate) fn make_path_suggestion(
22392240
&mut self,
22402241
span: Span,
22412242
mut path: Vec<Segment>,
22422243
parent_scope: &ParentScope<'ra>,
22432244
) -> Option<(Vec<Segment>, Option<String>)> {
2244-
debug!("make_path_suggestion: span={:?} path={:?}", span, path);
2245+
debug!("entered");
22452246

22462247
match (path.get(0), path.get(1)) {
22472248
// `{{root}}::ident::...` on both editions.
@@ -2271,6 +2272,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
22712272
/// LL | use foo::Bar;
22722273
/// | ^^^ did you mean `self::foo`?
22732274
/// ```
2275+
#[instrument(skip(self, parent_scope))]
22742276
fn make_missing_self_suggestion(
22752277
&mut self,
22762278
mut path: Vec<Segment>,
@@ -2279,7 +2281,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
22792281
// Replace first ident with `self` and check if that is valid.
22802282
path[0].ident.name = kw::SelfLower;
22812283
let result = self.maybe_resolve_path(&path, None, parent_scope, None);
2282-
debug!("make_missing_self_suggestion: path={:?} result={:?}", path, result);
2284+
debug!(?result);
22832285
if let PathResult::Module(..) = result { Some((path, None)) } else { None }
22842286
}
22852287

@@ -2290,6 +2292,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
22902292
/// LL | use foo::Bar;
22912293
/// | ^^^ did you mean `crate::foo`?
22922294
/// ```
2295+
#[instrument(skip(self, parent_scope))]
22932296
fn make_missing_crate_suggestion(
22942297
&mut self,
22952298
mut path: Vec<Segment>,
@@ -2298,7 +2301,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
22982301
// Replace first ident with `crate` and check if that is valid.
22992302
path[0].ident.name = kw::Crate;
23002303
let result = self.maybe_resolve_path(&path, None, parent_scope, None);
2301-
debug!("make_missing_crate_suggestion: path={:?} result={:?}", path, result);
2304+
debug!(?result);
23022305
if let PathResult::Module(..) = result {
23032306
Some((
23042307
path,
@@ -2321,6 +2324,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
23212324
/// LL | use foo::Bar;
23222325
/// | ^^^ did you mean `super::foo`?
23232326
/// ```
2327+
#[instrument(skip(self, parent_scope))]
23242328
fn make_missing_super_suggestion(
23252329
&mut self,
23262330
mut path: Vec<Segment>,
@@ -2329,7 +2333,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
23292333
// Replace first ident with `crate` and check if that is valid.
23302334
path[0].ident.name = kw::Super;
23312335
let result = self.maybe_resolve_path(&path, None, parent_scope, None);
2332-
debug!("make_missing_super_suggestion: path={:?} result={:?}", path, result);
2336+
debug!(?result);
23332337
if let PathResult::Module(..) = result { Some((path, None)) } else { None }
23342338
}
23352339

@@ -2343,6 +2347,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
23432347
///
23442348
/// Used when importing a submodule of an external crate but missing that crate's
23452349
/// name as the first part of path.
2350+
#[instrument(skip(self, parent_scope))]
23462351
fn make_external_crate_suggestion(
23472352
&mut self,
23482353
mut path: Vec<Segment>,
@@ -2363,10 +2368,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
23632368
// Replace first ident with a crate name and check if that is valid.
23642369
path[0].ident.name = name;
23652370
let result = self.maybe_resolve_path(&path, None, parent_scope, None);
2366-
debug!(
2367-
"make_external_crate_suggestion: name={:?} path={:?} result={:?}",
2368-
name, path, result
2369-
);
2371+
debug!(?name, ?result);
23702372
if let PathResult::Module(..) = result {
23712373
return Some((path, None));
23722374
}
@@ -2433,10 +2435,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
24332435
import.span,
24342436
import.use_span,
24352437
);
2436-
debug!(
2437-
"check_for_module_export_macro: found_closing_brace={:?} binding_span={:?}",
2438-
found_closing_brace, binding_span
2439-
);
2438+
debug!(found_closing_brace, ?binding_span);
24402439

24412440
let mut removal_span = binding_span;
24422441
if found_closing_brace {
@@ -2450,11 +2449,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
24502449
if let Some(previous_span) =
24512450
extend_span_to_previous_binding(self.tcx.sess, binding_span)
24522451
{
2453-
debug!("check_for_module_export_macro: previous_span={:?}", previous_span);
2452+
debug!(?previous_span);
24542453
removal_span = removal_span.with_lo(previous_span.lo());
24552454
}
24562455
}
2457-
debug!("check_for_module_export_macro: removal_span={:?}", removal_span);
2456+
debug!(?removal_span);
24582457

24592458
// Remove the `removal_span`.
24602459
corrections.push((removal_span, "".to_string()));
@@ -2470,10 +2469,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
24702469
module_name,
24712470
import.use_span,
24722471
);
2473-
debug!(
2474-
"check_for_module_export_macro: has_nested={:?} after_crate_name={:?}",
2475-
has_nested, after_crate_name
2476-
);
2472+
debug!(has_nested, ?after_crate_name);
24772473

24782474
let source_map = self.tcx.sess.source_map();
24792475

@@ -2677,15 +2673,13 @@ fn extend_span_to_previous_binding(sess: &Session, binding_span: Span) -> Option
26772673
/// use foo::{a, b::{c, d}};
26782674
/// // ^^^^^^^^^^^^^^^ -- true
26792675
/// ```
2676+
#[instrument(skip(sess))]
26802677
fn find_span_immediately_after_crate_name(
26812678
sess: &Session,
26822679
module_name: Symbol,
26832680
use_span: Span,
26842681
) -> (bool, Span) {
2685-
debug!(
2686-
"find_span_immediately_after_crate_name: module_name={:?} use_span={:?}",
2687-
module_name, use_span
2688-
);
2682+
debug!("entered");
26892683
let source_map = sess.source_map();
26902684

26912685
// Using `use issue_59764::foo::{baz, makro};` as an example throughout..

0 commit comments

Comments
 (0)