Allow LocalDefId as the argument to def_path_str

This commit is contained in:
Oli Scherer 2023-02-16 09:25:11 +00:00
parent e18d1f8d2e
commit 1ce80e210d
18 changed files with 68 additions and 54 deletions

View file

@ -124,7 +124,7 @@ pub fn provide(providers: &mut Providers) {
fn mir_borrowck(tcx: TyCtxt<'_>, def: LocalDefId) -> &BorrowCheckResult<'_> { fn mir_borrowck(tcx: TyCtxt<'_>, def: LocalDefId) -> &BorrowCheckResult<'_> {
let (input_body, promoted) = tcx.mir_promoted(def); let (input_body, promoted) = tcx.mir_promoted(def);
debug!("run query mir_borrowck: {}", tcx.def_path_str(def.to_def_id())); debug!("run query mir_borrowck: {}", tcx.def_path_str(def));
if input_body.borrow().should_skip() { if input_body.borrow().should_skip() {
debug!("Skipping borrowck because of injected body"); debug!("Skipping borrowck because of injected body");

View file

@ -494,7 +494,7 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
debug!( debug!(
"check_item_type(it.def_id={:?}, it.name={})", "check_item_type(it.def_id={:?}, it.name={})",
id.owner_id, id.owner_id,
tcx.def_path_str(id.owner_id.to_def_id()) tcx.def_path_str(id.owner_id)
); );
let _indenter = indenter(); let _indenter = indenter();
match tcx.def_kind(id.owner_id) { match tcx.def_kind(id.owner_id) {

View file

@ -155,7 +155,7 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) {
debug!( debug!(
?item.owner_id, ?item.owner_id,
item.name = ? tcx.def_path_str(def_id.to_def_id()) item.name = ? tcx.def_path_str(def_id)
); );
match item.kind { match item.kind {
@ -251,7 +251,7 @@ fn check_foreign_item(tcx: TyCtxt<'_>, item: &hir::ForeignItem<'_>) {
debug!( debug!(
?item.owner_id, ?item.owner_id,
item.name = ? tcx.def_path_str(def_id.to_def_id()) item.name = ? tcx.def_path_str(def_id)
); );
match item.kind { match item.kind {

View file

@ -22,7 +22,7 @@ fn check_impl(tcx: TyCtxt<'_>, impl_def_id: LocalDefId, trait_ref: ty::TraitRef<
debug!( debug!(
"(checking implementation) adding impl for trait '{:?}', item '{}'", "(checking implementation) adding impl for trait '{:?}', item '{}'",
trait_ref, trait_ref,
tcx.def_path_str(impl_def_id.to_def_id()) tcx.def_path_str(impl_def_id)
); );
// Skip impls where one of the self type is an error type. // Skip impls where one of the self type is an error type.

View file

@ -92,7 +92,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
fn build_constraints_for_item(&mut self, def_id: LocalDefId) { fn build_constraints_for_item(&mut self, def_id: LocalDefId) {
let tcx = self.tcx(); let tcx = self.tcx();
debug!("build_constraints_for_item({})", tcx.def_path_str(def_id.to_def_id())); debug!("build_constraints_for_item({})", tcx.def_path_str(def_id));
// Skip items with no generics - there's nothing to infer in them. // Skip items with no generics - there's nothing to infer in them.
if tcx.generics_of(def_id).count() == 0 { if tcx.generics_of(def_id).count() == 0 {

View file

@ -364,7 +364,7 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for HirId {
#[inline(always)] #[inline(always)]
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String { fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
let HirId { owner, local_id } = *self; let HirId { owner, local_id } = *self;
format!("{}.{}", tcx.def_path_str(owner.to_def_id()), local_id.as_u32()) format!("{}.{}", tcx.def_path_str(owner), local_id.as_u32())
} }
#[inline(always)] #[inline(always)]

View file

@ -1217,7 +1217,7 @@ fn upstream_crates(tcx: TyCtxt<'_>) -> Vec<(StableCrateId, Svh)> {
} }
fn hir_id_to_string(map: Map<'_>, id: HirId) -> String { fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {
let path_str = |def_id: LocalDefId| map.tcx.def_path_str(def_id.to_def_id()); let path_str = |def_id: LocalDefId| map.tcx.def_path_str(def_id);
let span_str = || map.tcx.sess.source_map().span_to_snippet(map.span(id)).unwrap_or_default(); let span_str = || map.tcx.sess.source_map().span_to_snippet(map.span(id)).unwrap_or_default();
let node_str = |prefix| format!("{id} ({prefix} `{}`)", span_str()); let node_str = |prefix| format!("{id} ({prefix} `{}`)", span_str());

View file

@ -83,7 +83,7 @@ rustc_queries! {
/// Avoid calling this query directly. /// Avoid calling this query directly.
query hir_module_items(key: LocalDefId) -> &'tcx rustc_middle::hir::ModuleItems { query hir_module_items(key: LocalDefId) -> &'tcx rustc_middle::hir::ModuleItems {
arena_cache arena_cache
desc { |tcx| "getting HIR module items in `{}`", tcx.def_path_str(key.to_def_id()) } desc { |tcx| "getting HIR module items in `{}`", tcx.def_path_str(key) }
cache_on_disk_if { true } cache_on_disk_if { true }
} }
@ -92,14 +92,14 @@ rustc_queries! {
/// This can be conveniently accessed by methods on `tcx.hir()`. /// This can be conveniently accessed by methods on `tcx.hir()`.
/// Avoid calling this query directly. /// Avoid calling this query directly.
query hir_owner(key: hir::OwnerId) -> Option<crate::hir::Owner<'tcx>> { query hir_owner(key: hir::OwnerId) -> Option<crate::hir::Owner<'tcx>> {
desc { |tcx| "getting HIR owner of `{}`", tcx.def_path_str(key.to_def_id()) } desc { |tcx| "getting HIR owner of `{}`", tcx.def_path_str(key) }
} }
/// Gives access to the HIR ID for the given `LocalDefId` owner `key` if any. /// Gives access to the HIR ID for the given `LocalDefId` owner `key` if any.
/// ///
/// Definitions that were generated with no HIR, would be fed to return `None`. /// Definitions that were generated with no HIR, would be fed to return `None`.
query opt_local_def_id_to_hir_id(key: LocalDefId) -> Option<hir::HirId>{ query opt_local_def_id_to_hir_id(key: LocalDefId) -> Option<hir::HirId>{
desc { |tcx| "getting HIR ID of `{}`", tcx.def_path_str(key.to_def_id()) } desc { |tcx| "getting HIR ID of `{}`", tcx.def_path_str(key) }
feedable feedable
} }
@ -108,7 +108,7 @@ rustc_queries! {
/// This can be conveniently accessed by methods on `tcx.hir()`. /// This can be conveniently accessed by methods on `tcx.hir()`.
/// Avoid calling this query directly. /// Avoid calling this query directly.
query hir_owner_parent(key: hir::OwnerId) -> hir::HirId { query hir_owner_parent(key: hir::OwnerId) -> hir::HirId {
desc { |tcx| "getting HIR parent of `{}`", tcx.def_path_str(key.to_def_id()) } desc { |tcx| "getting HIR parent of `{}`", tcx.def_path_str(key) }
} }
/// Gives access to the HIR nodes and bodies inside the HIR owner `key`. /// Gives access to the HIR nodes and bodies inside the HIR owner `key`.
@ -116,7 +116,7 @@ rustc_queries! {
/// This can be conveniently accessed by methods on `tcx.hir()`. /// This can be conveniently accessed by methods on `tcx.hir()`.
/// Avoid calling this query directly. /// Avoid calling this query directly.
query hir_owner_nodes(key: hir::OwnerId) -> hir::MaybeOwner<&'tcx hir::OwnerNodes<'tcx>> { query hir_owner_nodes(key: hir::OwnerId) -> hir::MaybeOwner<&'tcx hir::OwnerNodes<'tcx>> {
desc { |tcx| "getting HIR owner items in `{}`", tcx.def_path_str(key.to_def_id()) } desc { |tcx| "getting HIR owner items in `{}`", tcx.def_path_str(key) }
} }
/// Gives access to the HIR attributes inside the HIR owner `key`. /// Gives access to the HIR attributes inside the HIR owner `key`.
@ -124,7 +124,7 @@ rustc_queries! {
/// This can be conveniently accessed by methods on `tcx.hir()`. /// This can be conveniently accessed by methods on `tcx.hir()`.
/// Avoid calling this query directly. /// Avoid calling this query directly.
query hir_attrs(key: hir::OwnerId) -> &'tcx hir::AttributeMap<'tcx> { query hir_attrs(key: hir::OwnerId) -> &'tcx hir::AttributeMap<'tcx> {
desc { |tcx| "getting HIR owner attributes in `{}`", tcx.def_path_str(key.to_def_id()) } desc { |tcx| "getting HIR owner attributes in `{}`", tcx.def_path_str(key) }
} }
/// Given the def_id of a const-generic parameter, computes the associated default const /// Given the def_id of a const-generic parameter, computes the associated default const
@ -295,7 +295,7 @@ rustc_queries! {
query shallow_lint_levels_on(key: hir::OwnerId) -> &'tcx rustc_middle::lint::ShallowLintLevelMap { query shallow_lint_levels_on(key: hir::OwnerId) -> &'tcx rustc_middle::lint::ShallowLintLevelMap {
eval_always // fetches `resolutions` eval_always // fetches `resolutions`
arena_cache arena_cache
desc { |tcx| "looking up lint levels for `{}`", tcx.def_path_str(key.to_def_id()) } desc { |tcx| "looking up lint levels for `{}`", tcx.def_path_str(key) }
} }
query lint_expectations(_: ()) -> &'tcx Vec<(LintExpectationId, LintExpectation)> { query lint_expectations(_: ()) -> &'tcx Vec<(LintExpectationId, LintExpectation)> {
@ -305,7 +305,7 @@ rustc_queries! {
query parent_module_from_def_id(key: LocalDefId) -> LocalDefId { query parent_module_from_def_id(key: LocalDefId) -> LocalDefId {
eval_always eval_always
desc { |tcx| "getting the parent module of `{}`", tcx.def_path_str(key.to_def_id()) } desc { |tcx| "getting the parent module of `{}`", tcx.def_path_str(key) }
} }
query expn_that_defined(key: DefId) -> rustc_span::ExpnId { query expn_that_defined(key: DefId) -> rustc_span::ExpnId {
@ -321,7 +321,7 @@ rustc_queries! {
/// Checks whether a type is representable or infinitely sized /// Checks whether a type is representable or infinitely sized
query representability(_: LocalDefId) -> rustc_middle::ty::Representability { query representability(_: LocalDefId) -> rustc_middle::ty::Representability {
desc { "checking if `{}` is representable", tcx.def_path_str(key.to_def_id()) } desc { "checking if `{}` is representable", tcx.def_path_str(key) }
// infinitely sized types will cause a cycle // infinitely sized types will cause a cycle
cycle_delay_bug cycle_delay_bug
// we don't want recursive representability calls to be forced with // we don't want recursive representability calls to be forced with
@ -349,21 +349,21 @@ rustc_queries! {
query thir_body(key: LocalDefId) -> Result<(&'tcx Steal<thir::Thir<'tcx>>, thir::ExprId), ErrorGuaranteed> { query thir_body(key: LocalDefId) -> Result<(&'tcx Steal<thir::Thir<'tcx>>, thir::ExprId), ErrorGuaranteed> {
// Perf tests revealed that hashing THIR is inefficient (see #85729). // Perf tests revealed that hashing THIR is inefficient (see #85729).
no_hash no_hash
desc { |tcx| "building THIR for `{}`", tcx.def_path_str(key.to_def_id()) } desc { |tcx| "building THIR for `{}`", tcx.def_path_str(key) }
} }
/// Create a THIR tree for debugging. /// Create a THIR tree for debugging.
query thir_tree(key: LocalDefId) -> &'tcx String { query thir_tree(key: LocalDefId) -> &'tcx String {
no_hash no_hash
arena_cache arena_cache
desc { |tcx| "constructing THIR tree for `{}`", tcx.def_path_str(key.to_def_id()) } desc { |tcx| "constructing THIR tree for `{}`", tcx.def_path_str(key) }
} }
/// Create a list-like THIR representation for debugging. /// Create a list-like THIR representation for debugging.
query thir_flat(key: LocalDefId) -> &'tcx String { query thir_flat(key: LocalDefId) -> &'tcx String {
no_hash no_hash
arena_cache arena_cache
desc { |tcx| "constructing flat THIR representation for `{}`", tcx.def_path_str(key.to_def_id()) } desc { |tcx| "constructing flat THIR representation for `{}`", tcx.def_path_str(key) }
} }
/// Set of all the `DefId`s in this crate that have MIR associated with /// Set of all the `DefId`s in this crate that have MIR associated with
@ -386,7 +386,7 @@ rustc_queries! {
/// Fetch the MIR for a given `DefId` right after it's built - this includes /// Fetch the MIR for a given `DefId` right after it's built - this includes
/// unreachable code. /// unreachable code.
query mir_built(key: LocalDefId) -> &'tcx Steal<mir::Body<'tcx>> { query mir_built(key: LocalDefId) -> &'tcx Steal<mir::Body<'tcx>> {
desc { |tcx| "building MIR for `{}`", tcx.def_path_str(key.to_def_id()) } desc { |tcx| "building MIR for `{}`", tcx.def_path_str(key) }
} }
/// Fetch the MIR for a given `DefId` up till the point where it is /// Fetch the MIR for a given `DefId` up till the point where it is
@ -394,7 +394,7 @@ rustc_queries! {
/// ///
/// See the README for the `mir` module for details. /// See the README for the `mir` module for details.
query mir_const(key: LocalDefId) -> &'tcx Steal<mir::Body<'tcx>> { query mir_const(key: LocalDefId) -> &'tcx Steal<mir::Body<'tcx>> {
desc { |tcx| "preparing `{}` for borrow checking", tcx.def_path_str(key.to_def_id()) } desc { |tcx| "preparing `{}` for borrow checking", tcx.def_path_str(key) }
no_hash no_hash
} }
@ -410,7 +410,7 @@ rustc_queries! {
query mir_drops_elaborated_and_const_checked(key: LocalDefId) -> &'tcx Steal<mir::Body<'tcx>> { query mir_drops_elaborated_and_const_checked(key: LocalDefId) -> &'tcx Steal<mir::Body<'tcx>> {
no_hash no_hash
desc { |tcx| "elaborating drops for `{}`", tcx.def_path_str(key.to_def_id()) } desc { |tcx| "elaborating drops for `{}`", tcx.def_path_str(key) }
} }
query mir_for_ctfe( query mir_for_ctfe(
@ -426,13 +426,13 @@ rustc_queries! {
&'tcx Steal<IndexVec<mir::Promoted, mir::Body<'tcx>>> &'tcx Steal<IndexVec<mir::Promoted, mir::Body<'tcx>>>
) { ) {
no_hash no_hash
desc { |tcx| "promoting constants in MIR for `{}`", tcx.def_path_str(key.to_def_id()) } desc { |tcx| "promoting constants in MIR for `{}`", tcx.def_path_str(key) }
} }
query closure_typeinfo(key: LocalDefId) -> ty::ClosureTypeInfo<'tcx> { query closure_typeinfo(key: LocalDefId) -> ty::ClosureTypeInfo<'tcx> {
desc { desc {
|tcx| "finding symbols for captures of closure `{}`", |tcx| "finding symbols for captures of closure `{}`",
tcx.def_path_str(key.to_def_id()) tcx.def_path_str(key)
} }
} }
@ -444,7 +444,7 @@ rustc_queries! {
} }
query check_generator_obligations(key: LocalDefId) { query check_generator_obligations(key: LocalDefId) {
desc { |tcx| "verify auto trait bounds for generator interior type `{}`", tcx.def_path_str(key.to_def_id()) } desc { |tcx| "verify auto trait bounds for generator interior type `{}`", tcx.def_path_str(key) }
} }
/// MIR after our optimization passes have run. This is MIR that is ready /// MIR after our optimization passes have run. This is MIR that is ready
@ -526,7 +526,7 @@ rustc_queries! {
/// `explicit_predicates_of` and `explicit_item_bounds` will then take /// `explicit_predicates_of` and `explicit_item_bounds` will then take
/// the appropriate subsets of the predicates here. /// the appropriate subsets of the predicates here.
query trait_explicit_predicates_and_bounds(key: LocalDefId) -> ty::GenericPredicates<'tcx> { query trait_explicit_predicates_and_bounds(key: LocalDefId) -> ty::GenericPredicates<'tcx> {
desc { |tcx| "computing explicit predicates of trait `{}`", tcx.def_path_str(key.to_def_id()) } desc { |tcx| "computing explicit predicates of trait `{}`", tcx.def_path_str(key) }
} }
/// Returns the predicates written explicitly by the user. /// Returns the predicates written explicitly by the user.
@ -768,14 +768,14 @@ rustc_queries! {
/// The result of unsafety-checking this `LocalDefId`. /// The result of unsafety-checking this `LocalDefId`.
query unsafety_check_result(key: LocalDefId) -> &'tcx mir::UnsafetyCheckResult { query unsafety_check_result(key: LocalDefId) -> &'tcx mir::UnsafetyCheckResult {
desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) } desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key) }
cache_on_disk_if { true } cache_on_disk_if { true }
} }
/// Unsafety-check this `LocalDefId` with THIR unsafeck. This should be /// Unsafety-check this `LocalDefId` with THIR unsafeck. This should be
/// used with `-Zthir-unsafeck`. /// used with `-Zthir-unsafeck`.
query thir_check_unsafety(key: LocalDefId) { query thir_check_unsafety(key: LocalDefId) {
desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) } desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key) }
cache_on_disk_if { true } cache_on_disk_if { true }
} }
@ -872,16 +872,16 @@ rustc_queries! {
} }
query typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> { query typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) } desc { |tcx| "type-checking `{}`", tcx.def_path_str(key) }
cache_on_disk_if { true } cache_on_disk_if { true }
} }
query diagnostic_only_typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> { query diagnostic_only_typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) } desc { |tcx| "type-checking `{}`", tcx.def_path_str(key) }
cache_on_disk_if { true } cache_on_disk_if { true }
} }
query used_trait_imports(key: LocalDefId) -> &'tcx UnordSet<LocalDefId> { query used_trait_imports(key: LocalDefId) -> &'tcx UnordSet<LocalDefId> {
desc { |tcx| "finding used_trait_imports `{}`", tcx.def_path_str(key.to_def_id()) } desc { |tcx| "finding used_trait_imports `{}`", tcx.def_path_str(key) }
cache_on_disk_if { true } cache_on_disk_if { true }
} }
@ -896,7 +896,7 @@ rustc_queries! {
/// Borrow-checks the function body. If this is a closure, returns /// Borrow-checks the function body. If this is a closure, returns
/// additional requirements that the closure's creator must verify. /// additional requirements that the closure's creator must verify.
query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> { query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> {
desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.to_def_id()) } desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key) }
cache_on_disk_if(tcx) { tcx.is_typeck_child(key.to_def_id()) } cache_on_disk_if(tcx) { tcx.is_typeck_child(key.to_def_id()) }
} }
@ -918,7 +918,7 @@ rustc_queries! {
query orphan_check_impl(key: LocalDefId) -> Result<(), ErrorGuaranteed> { query orphan_check_impl(key: LocalDefId) -> Result<(), ErrorGuaranteed> {
desc { |tcx| desc { |tcx|
"checking whether impl `{}` follows the orphan rules", "checking whether impl `{}` follows the orphan rules",
tcx.def_path_str(key.to_def_id()), tcx.def_path_str(key),
} }
} }
@ -930,7 +930,7 @@ rustc_queries! {
desc { |tcx| desc { |tcx|
"computing if `{}` (transitively) calls `{}`", "computing if `{}` (transitively) calls `{}`",
key.0, key.0,
tcx.def_path_str(key.1.to_def_id()), tcx.def_path_str(key.1),
} }
} }
@ -1368,7 +1368,7 @@ rustc_queries! {
separate_provide_extern separate_provide_extern
} }
query has_ffi_unwind_calls(key: LocalDefId) -> bool { query has_ffi_unwind_calls(key: LocalDefId) -> bool {
desc { |tcx| "checking if `{}` contains FFI-unwind calls", tcx.def_path_str(key.to_def_id()) } desc { |tcx| "checking if `{}` contains FFI-unwind calls", tcx.def_path_str(key) }
cache_on_disk_if { true } cache_on_disk_if { true }
} }
query required_panic_strategy(_: CrateNum) -> Option<PanicStrategy> { query required_panic_strategy(_: CrateNum) -> Option<PanicStrategy> {
@ -1414,7 +1414,7 @@ rustc_queries! {
} }
query check_well_formed(key: hir::OwnerId) -> () { query check_well_formed(key: hir::OwnerId) -> () {
desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) } desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key) }
} }
// The `DefId`s of all non-generic functions and statics in the given crate // The `DefId`s of all non-generic functions and statics in the given crate
@ -1443,7 +1443,7 @@ rustc_queries! {
query is_unreachable_local_definition(def_id: LocalDefId) -> bool { query is_unreachable_local_definition(def_id: LocalDefId) -> bool {
desc { |tcx| desc { |tcx|
"checking whether `{}` is reachable from outside the crate", "checking whether `{}` is reachable from outside the crate",
tcx.def_path_str(def_id.to_def_id()), tcx.def_path_str(def_id),
} }
} }
@ -1637,7 +1637,7 @@ rustc_queries! {
separate_provide_extern separate_provide_extern
} }
query extern_mod_stmt_cnum(def_id: LocalDefId) -> Option<CrateNum> { query extern_mod_stmt_cnum(def_id: LocalDefId) -> Option<CrateNum> {
desc { |tcx| "computing crate imported by `{}`", tcx.def_path_str(def_id.to_def_id()) } desc { |tcx| "computing crate imported by `{}`", tcx.def_path_str(def_id) }
} }
query lib_features(_: ()) -> &'tcx LibFeatures { query lib_features(_: ()) -> &'tcx LibFeatures {
@ -1741,7 +1741,7 @@ rustc_queries! {
desc { "fetching potentially unused trait imports" } desc { "fetching potentially unused trait imports" }
} }
query names_imported_by_glob_use(def_id: LocalDefId) -> &'tcx UnordSet<Symbol> { query names_imported_by_glob_use(def_id: LocalDefId) -> &'tcx UnordSet<Symbol> {
desc { |tcx| "finding names imported by glob use for `{}`", tcx.def_path_str(def_id.to_def_id()) } desc { |tcx| "finding names imported by glob use for `{}`", tcx.def_path_str(def_id) }
} }
query stability_index(_: ()) -> &'tcx stability::Index { query stability_index(_: ()) -> &'tcx stability::Index {
@ -2064,7 +2064,7 @@ rustc_queries! {
query compare_impl_const( query compare_impl_const(
key: (LocalDefId, DefId) key: (LocalDefId, DefId)
) -> Result<(), ErrorGuaranteed> { ) -> Result<(), ErrorGuaranteed> {
desc { |tcx| "checking assoc const `{}` has the same type as trait item", tcx.def_path_str(key.0.to_def_id()) } desc { |tcx| "checking assoc const `{}` has the same type as trait item", tcx.def_path_str(key.0) }
} }
query deduced_param_attrs(def_id: DefId) -> &'tcx [ty::DeducedParamAttrs] { query deduced_param_attrs(def_id: DefId) -> &'tcx [ty::DeducedParamAttrs] {

View file

@ -80,6 +80,8 @@ use std::iter;
use std::mem; use std::mem;
use std::ops::{Bound, Deref}; use std::ops::{Bound, Deref};
use super::query::IntoQueryParam;
const TINY_CONST_EVAL_LIMIT: Limit = Limit(20); const TINY_CONST_EVAL_LIMIT: Limit = Limit(20);
pub trait OnDiskCache<'tcx>: rustc_data_structures::sync::Sync { pub trait OnDiskCache<'tcx>: rustc_data_structures::sync::Sync {
@ -822,7 +824,8 @@ impl<'tcx> TyCtxt<'tcx> {
self.features_query(()) self.features_query(())
} }
pub fn def_key(self, id: DefId) -> rustc_hir::definitions::DefKey { pub fn def_key(self, id: impl IntoQueryParam<DefId>) -> rustc_hir::definitions::DefKey {
let id = id.into_query_param();
// Accessing the DefKey is ok, since it is part of DefPathHash. // Accessing the DefKey is ok, since it is part of DefPathHash.
if let Some(id) = id.as_local() { if let Some(id) = id.as_local() {
self.definitions_untracked().def_key(id) self.definitions_untracked().def_key(id)

View file

@ -327,6 +327,6 @@ pub fn describe_as_module(def_id: LocalDefId, tcx: TyCtxt<'_>) -> String {
if def_id.is_top_level_module() { if def_id.is_top_level_module() {
"top-level module".to_string() "top-level module".to_string()
} else { } else {
format!("module `{}`", tcx.def_path_str(def_id.to_def_id())) format!("module `{}`", tcx.def_path_str(def_id))
} }
} }

View file

@ -1,4 +1,5 @@
use crate::mir::interpret::{AllocRange, GlobalAlloc, Pointer, Provenance, Scalar}; use crate::mir::interpret::{AllocRange, GlobalAlloc, Pointer, Provenance, Scalar};
use crate::ty::query::IntoQueryParam;
use crate::ty::{ use crate::ty::{
self, ConstInt, ParamConst, ScalarInt, Term, TermKind, Ty, TyCtxt, TypeFoldable, self, ConstInt, ParamConst, ScalarInt, Term, TermKind, Ty, TyCtxt, TypeFoldable,
TypeSuperFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeSuperFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitableExt,
@ -1787,17 +1788,27 @@ fn guess_def_namespace(tcx: TyCtxt<'_>, def_id: DefId) -> Namespace {
impl<'t> TyCtxt<'t> { impl<'t> TyCtxt<'t> {
/// Returns a string identifying this `DefId`. This string is /// Returns a string identifying this `DefId`. This string is
/// suitable for user output. /// suitable for user output.
pub fn def_path_str(self, def_id: DefId) -> String { pub fn def_path_str(self, def_id: impl IntoQueryParam<DefId>) -> String {
self.def_path_str_with_substs(def_id, &[]) self.def_path_str_with_substs(def_id, &[])
} }
pub fn def_path_str_with_substs(self, def_id: DefId, substs: &'t [GenericArg<'t>]) -> String { pub fn def_path_str_with_substs(
self,
def_id: impl IntoQueryParam<DefId>,
substs: &'t [GenericArg<'t>],
) -> String {
let def_id = def_id.into_query_param();
let ns = guess_def_namespace(self, def_id); let ns = guess_def_namespace(self, def_id);
debug!("def_path_str: def_id={:?}, ns={:?}", def_id, ns); debug!("def_path_str: def_id={:?}, ns={:?}", def_id, ns);
FmtPrinter::new(self, ns).print_def_path(def_id, substs).unwrap().into_buffer() FmtPrinter::new(self, ns).print_def_path(def_id, substs).unwrap().into_buffer()
} }
pub fn value_path_str_with_substs(self, def_id: DefId, substs: &'t [GenericArg<'t>]) -> String { pub fn value_path_str_with_substs(
self,
def_id: impl IntoQueryParam<DefId>,
substs: &'t [GenericArg<'t>],
) -> String {
let def_id = def_id.into_query_param();
let ns = guess_def_namespace(self, def_id); let ns = guess_def_namespace(self, def_id);
debug!("value_path_str: def_id={:?}, ns={:?}", def_id, ns); debug!("value_path_str: def_id={:?}, ns={:?}", def_id, ns);
FmtPrinter::new(self, ns).print_value_path(def_id, substs).unwrap().into_buffer() FmtPrinter::new(self, ns).print_value_path(def_id, substs).unwrap().into_buffer()

View file

@ -587,7 +587,7 @@ mod sealed {
} }
} }
use sealed::IntoQueryParam; pub use sealed::IntoQueryParam;
impl<'tcx> TyCtxt<'tcx> { impl<'tcx> TyCtxt<'tcx> {
pub fn def_kind(self, def_id: impl IntoQueryParam<DefId>) -> DefKind { pub fn def_kind(self, def_id: impl IntoQueryParam<DefId>) -> DefKind {

View file

@ -158,8 +158,8 @@ pub fn recursive_type_error(
} }
let items_list = { let items_list = {
let mut s = String::new(); let mut s = String::new();
for (i, (item_id, _)) in item_and_field_ids.iter().enumerate() { for (i, &(item_id, _)) in item_and_field_ids.iter().enumerate() {
let path = tcx.def_path_str(item_id.to_def_id()); let path = tcx.def_path_str(item_id);
write!(&mut s, "`{path}`").unwrap(); write!(&mut s, "`{path}`").unwrap();
if i == (ITEM_LIMIT - 1) && cycle_len > ITEM_LIMIT { if i == (ITEM_LIMIT - 1) && cycle_len > ITEM_LIMIT {
write!(&mut s, " and {} more", cycle_len - 5).unwrap(); write!(&mut s, " and {} more", cycle_len - 5).unwrap();

View file

@ -13,7 +13,7 @@ pub(crate) fn mir_callgraph_reachable<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
(root, target): (ty::Instance<'tcx>, LocalDefId), (root, target): (ty::Instance<'tcx>, LocalDefId),
) -> bool { ) -> bool {
trace!(%root, target = %tcx.def_path_str(target.to_def_id())); trace!(%root, target = %tcx.def_path_str(target));
let param_env = tcx.param_env_reveal_all_normalized(target); let param_env = tcx.param_env_reveal_all_normalized(target);
assert_ne!( assert_ne!(
root.def_id().expect_local(), root.def_id().expect_local(),

View file

@ -1230,7 +1230,7 @@ impl<'v> RootCollector<'_, 'v> {
DefKind::GlobalAsm => { DefKind::GlobalAsm => {
debug!( debug!(
"RootCollector: ItemKind::GlobalAsm({})", "RootCollector: ItemKind::GlobalAsm({})",
self.tcx.def_path_str(id.owner_id.to_def_id()) self.tcx.def_path_str(id.owner_id)
); );
self.output.push(dummy_spanned(MonoItem::GlobalAsm(id))); self.output.push(dummy_spanned(MonoItem::GlobalAsm(id)));
} }

View file

@ -83,7 +83,7 @@ impl SymbolNamesTest<'_> {
tcx.sess.emit_err(TestOutput { tcx.sess.emit_err(TestOutput {
span: attr.span, span: attr.span,
kind: Kind::DefPath, kind: Kind::DefPath,
content: with_no_trimmed_paths!(tcx.def_path_str(def_id.to_def_id())), content: with_no_trimmed_paths!(tcx.def_path_str(def_id)),
}); });
} }
} }

View file

@ -61,7 +61,7 @@ impl<'tcx> LateLintPass<'tcx> for DefaultUnionRepresentation {
None, None,
&format!( &format!(
"consider annotating `{}` with `#[repr(C)]` to explicitly specify memory layout", "consider annotating `{}` with `#[repr(C)]` to explicitly specify memory layout",
cx.tcx.def_path_str(item.owner_id.to_def_id()) cx.tcx.def_path_str(item.owner_id)
), ),
); );
} }

View file

@ -46,7 +46,7 @@ impl<'tcx> LateLintPass<'tcx> for TrailingEmptyArray {
None, None,
&format!( &format!(
"consider annotating `{}` with `#[repr(C)]` or another `repr` attribute", "consider annotating `{}` with `#[repr(C)]` or another `repr` attribute",
cx.tcx.def_path_str(item.owner_id.to_def_id()) cx.tcx.def_path_str(item.owner_id)
), ),
); );
} }