Skip to content

Commit 7eb7b23

Browse files
committed
move describe_as_module to where it's used
1 parent e0e9ff0 commit 7eb7b23

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

src/librustc/hir/def_id.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::ty::{self, TyCtxt};
1+
use crate::ty;
22
use rustc_index::vec::Idx;
33
use std::fmt;
44
use std::u32;
@@ -145,12 +145,8 @@ impl DefId {
145145
LocalDefId::from_def_id(self)
146146
}
147147

148-
pub fn describe_as_module(&self, tcx: TyCtxt<'_>) -> String {
149-
if self.is_local() && self.index == CRATE_DEF_INDEX {
150-
format!("top-level module")
151-
} else {
152-
format!("module `{}`", tcx.def_path_str(*self))
153-
}
148+
pub fn is_top_level_module(self) -> bool {
149+
self.is_local() && self.index == CRATE_DEF_INDEX
154150
}
155151
}
156152

src/librustc/query/mod.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ use crate::ty::{self, ParamEnvAnd, Ty, TyCtxt};
1616
use rustc_span::symbol::Symbol;
1717
use std::borrow::Cow;
1818

19+
fn describe_as_module(def_id: DefId, tcx: TyCtxt<'_>) -> String {
20+
if def_id.is_top_level_module() {
21+
format!("top-level module")
22+
} else {
23+
format!("module `{}`", tcx.def_path_str(def_id))
24+
}
25+
}
26+
1927
// Each of these queries corresponds to a function pointer field in the
2028
// `Providers` struct for requesting a value of that type, and a method
2129
// on `tcx: TyCtxt` (and `tcx.at(span)`) for doing that request in a way
@@ -332,50 +340,50 @@ rustc_queries! {
332340

333341
Other {
334342
query lint_mod(key: DefId) -> () {
335-
desc { |tcx| "linting {}", key.describe_as_module(tcx) }
343+
desc { |tcx| "linting {}", describe_as_module(key, tcx) }
336344
}
337345

338346
/// Checks the attributes in the module.
339347
query check_mod_attrs(key: DefId) -> () {
340-
desc { |tcx| "checking attributes in {}", key.describe_as_module(tcx) }
348+
desc { |tcx| "checking attributes in {}", describe_as_module(key, tcx) }
341349
}
342350

343351
query check_mod_unstable_api_usage(key: DefId) -> () {
344-
desc { |tcx| "checking for unstable API usage in {}", key.describe_as_module(tcx) }
352+
desc { |tcx| "checking for unstable API usage in {}", describe_as_module(key, tcx) }
345353
}
346354

347355
/// Checks the const bodies in the module for illegal operations (e.g. `if` or `loop`).
348356
query check_mod_const_bodies(key: DefId) -> () {
349-
desc { |tcx| "checking consts in {}", key.describe_as_module(tcx) }
357+
desc { |tcx| "checking consts in {}", describe_as_module(key, tcx) }
350358
}
351359

352360
/// Checks the loops in the module.
353361
query check_mod_loops(key: DefId) -> () {
354-
desc { |tcx| "checking loops in {}", key.describe_as_module(tcx) }
362+
desc { |tcx| "checking loops in {}", describe_as_module(key, tcx) }
355363
}
356364

357365
query check_mod_item_types(key: DefId) -> () {
358-
desc { |tcx| "checking item types in {}", key.describe_as_module(tcx) }
366+
desc { |tcx| "checking item types in {}", describe_as_module(key, tcx) }
359367
}
360368

361369
query check_mod_privacy(key: DefId) -> () {
362-
desc { |tcx| "checking privacy in {}", key.describe_as_module(tcx) }
370+
desc { |tcx| "checking privacy in {}", describe_as_module(key, tcx) }
363371
}
364372

365373
query check_mod_intrinsics(key: DefId) -> () {
366-
desc { |tcx| "checking intrinsics in {}", key.describe_as_module(tcx) }
374+
desc { |tcx| "checking intrinsics in {}", describe_as_module(key, tcx) }
367375
}
368376

369377
query check_mod_liveness(key: DefId) -> () {
370-
desc { |tcx| "checking liveness of variables in {}", key.describe_as_module(tcx) }
378+
desc { |tcx| "checking liveness of variables in {}", describe_as_module(key, tcx) }
371379
}
372380

373381
query check_mod_impl_wf(key: DefId) -> () {
374-
desc { |tcx| "checking that impls are well-formed in {}", key.describe_as_module(tcx) }
382+
desc { |tcx| "checking that impls are well-formed in {}", describe_as_module(key, tcx) }
375383
}
376384

377385
query collect_mod_item_types(key: DefId) -> () {
378-
desc { |tcx| "collecting item types in {}", key.describe_as_module(tcx) }
386+
desc { |tcx| "collecting item types in {}", describe_as_module(key, tcx) }
379387
}
380388

381389
/// Caches `CoerceUnsized` kinds for impls on custom types.

0 commit comments

Comments
 (0)