Skip to content

Commit 95a7073

Browse files
authored
Unrolled build for rust-lang#135676
Rollup merge of rust-lang#135676 - yotamofek:resolve-cleanups, r=BoxyUwU rustc_resolve: use structured fields in traces I think this crate was written before `tracing` was adopted, and was manually writing fields into trace logs instead of using structured fields. I kept function names in the trace messages even though I added `#[instrument]` invocations so that the events will be in named spans, wasn't sure if spans are always printed.
2 parents 6a64e3b + 539b4d8 commit 95a7073

File tree

1 file changed

+15
-24
lines changed

1 file changed

+15
-24
lines changed

compiler/rustc_resolve/src/diagnostics.rs

+15-24
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,14 +2235,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
22352235
}
22362236

22372237
/// Adds suggestions for a path that cannot be resolved.
2238+
#[instrument(level = "debug", 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-
22462245
match (path.get(0), path.get(1)) {
22472246
// `{{root}}::ident::...` on both editions.
22482247
// On 2015 `{{root}}` is usually added implicitly.
@@ -2271,6 +2270,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
22712270
/// LL | use foo::Bar;
22722271
/// | ^^^ did you mean `self::foo`?
22732272
/// ```
2273+
#[instrument(level = "debug", skip(self, parent_scope))]
22742274
fn make_missing_self_suggestion(
22752275
&mut self,
22762276
mut path: Vec<Segment>,
@@ -2279,7 +2279,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
22792279
// Replace first ident with `self` and check if that is valid.
22802280
path[0].ident.name = kw::SelfLower;
22812281
let result = self.maybe_resolve_path(&path, None, parent_scope, None);
2282-
debug!("make_missing_self_suggestion: path={:?} result={:?}", path, result);
2282+
debug!(?path, ?result);
22832283
if let PathResult::Module(..) = result { Some((path, None)) } else { None }
22842284
}
22852285

@@ -2290,6 +2290,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
22902290
/// LL | use foo::Bar;
22912291
/// | ^^^ did you mean `crate::foo`?
22922292
/// ```
2293+
#[instrument(level = "debug", skip(self, parent_scope))]
22932294
fn make_missing_crate_suggestion(
22942295
&mut self,
22952296
mut path: Vec<Segment>,
@@ -2298,7 +2299,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
22982299
// Replace first ident with `crate` and check if that is valid.
22992300
path[0].ident.name = kw::Crate;
23002301
let result = self.maybe_resolve_path(&path, None, parent_scope, None);
2301-
debug!("make_missing_crate_suggestion: path={:?} result={:?}", path, result);
2302+
debug!(?path, ?result);
23022303
if let PathResult::Module(..) = result {
23032304
Some((
23042305
path,
@@ -2321,6 +2322,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
23212322
/// LL | use foo::Bar;
23222323
/// | ^^^ did you mean `super::foo`?
23232324
/// ```
2325+
#[instrument(level = "debug", skip(self, parent_scope))]
23242326
fn make_missing_super_suggestion(
23252327
&mut self,
23262328
mut path: Vec<Segment>,
@@ -2329,7 +2331,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
23292331
// Replace first ident with `crate` and check if that is valid.
23302332
path[0].ident.name = kw::Super;
23312333
let result = self.maybe_resolve_path(&path, None, parent_scope, None);
2332-
debug!("make_missing_super_suggestion: path={:?} result={:?}", path, result);
2334+
debug!(?path, ?result);
23332335
if let PathResult::Module(..) = result { Some((path, None)) } else { None }
23342336
}
23352337

@@ -2343,6 +2345,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
23432345
///
23442346
/// Used when importing a submodule of an external crate but missing that crate's
23452347
/// name as the first part of path.
2348+
#[instrument(level = "debug", skip(self, parent_scope))]
23462349
fn make_external_crate_suggestion(
23472350
&mut self,
23482351
mut path: Vec<Segment>,
@@ -2363,10 +2366,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
23632366
// Replace first ident with a crate name and check if that is valid.
23642367
path[0].ident.name = name;
23652368
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-
);
2369+
debug!(?path, ?name, ?result);
23702370
if let PathResult::Module(..) = result {
23712371
return Some((path, None));
23722372
}
@@ -2433,10 +2433,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
24332433
import.span,
24342434
import.use_span,
24352435
);
2436-
debug!(
2437-
"check_for_module_export_macro: found_closing_brace={:?} binding_span={:?}",
2438-
found_closing_brace, binding_span
2439-
);
2436+
debug!(found_closing_brace, ?binding_span);
24402437

24412438
let mut removal_span = binding_span;
24422439
if found_closing_brace {
@@ -2450,11 +2447,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
24502447
if let Some(previous_span) =
24512448
extend_span_to_previous_binding(self.tcx.sess, binding_span)
24522449
{
2453-
debug!("check_for_module_export_macro: previous_span={:?}", previous_span);
2450+
debug!(?previous_span);
24542451
removal_span = removal_span.with_lo(previous_span.lo());
24552452
}
24562453
}
2457-
debug!("check_for_module_export_macro: removal_span={:?}", removal_span);
2454+
debug!(?removal_span);
24582455

24592456
// Remove the `removal_span`.
24602457
corrections.push((removal_span, "".to_string()));
@@ -2470,10 +2467,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
24702467
module_name,
24712468
import.use_span,
24722469
);
2473-
debug!(
2474-
"check_for_module_export_macro: has_nested={:?} after_crate_name={:?}",
2475-
has_nested, after_crate_name
2476-
);
2470+
debug!(has_nested, ?after_crate_name);
24772471

24782472
let source_map = self.tcx.sess.source_map();
24792473

@@ -2677,15 +2671,12 @@ fn extend_span_to_previous_binding(sess: &Session, binding_span: Span) -> Option
26772671
/// use foo::{a, b::{c, d}};
26782672
/// // ^^^^^^^^^^^^^^^ -- true
26792673
/// ```
2674+
#[instrument(level = "debug", skip(sess))]
26802675
fn find_span_immediately_after_crate_name(
26812676
sess: &Session,
26822677
module_name: Symbol,
26832678
use_span: Span,
26842679
) -> (bool, Span) {
2685-
debug!(
2686-
"find_span_immediately_after_crate_name: module_name={:?} use_span={:?}",
2687-
module_name, use_span
2688-
);
26892680
let source_map = sess.source_map();
26902681

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

0 commit comments

Comments
 (0)