diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2025-07-03 09:09:26 +0000 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2025-07-13 13:50:00 +0000 |
| commit | 36bc0948e0a67f5aeb2a1d997acf4cd94d948fa9 (patch) | |
| tree | 3b7603b8c6484721867b6d16392144c0d4941240 /compiler/rustc_middle/src/ty/mod.rs | |
| parent | 277b0ecf3493a89818a4008afbb36ae4e77c1024 (diff) | |
| download | rust-36bc0948e0a67f5aeb2a1d997acf4cd94d948fa9.tar.gz rust-36bc0948e0a67f5aeb2a1d997acf4cd94d948fa9.zip | |
Generalize TyCtxt::item_name.
Diffstat (limited to 'compiler/rustc_middle/src/ty/mod.rs')
| -rw-r--r-- | compiler/rustc_middle/src/ty/mod.rs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 0177a95498b..9df44bbc15e 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -1590,7 +1590,8 @@ impl<'tcx> TyCtxt<'tcx> { } /// Look up the name of a definition across crates. This does not look at HIR. - pub fn opt_item_name(self, def_id: DefId) -> Option<Symbol> { + pub fn opt_item_name(self, def_id: impl IntoQueryParam<DefId>) -> Option<Symbol> { + let def_id = def_id.into_query_param(); if let Some(cnum) = def_id.as_crate_root() { Some(self.crate_name(cnum)) } else { @@ -1610,7 +1611,8 @@ impl<'tcx> TyCtxt<'tcx> { /// [`opt_item_name`] instead. /// /// [`opt_item_name`]: Self::opt_item_name - pub fn item_name(self, id: DefId) -> Symbol { + pub fn item_name(self, id: impl IntoQueryParam<DefId>) -> Symbol { + let id = id.into_query_param(); self.opt_item_name(id).unwrap_or_else(|| { bug!("item_name: no name for {:?}", self.def_path(id)); }) @@ -1619,7 +1621,8 @@ impl<'tcx> TyCtxt<'tcx> { /// Look up the name and span of a definition. /// /// See [`item_name`][Self::item_name] for more information. - pub fn opt_item_ident(self, def_id: DefId) -> Option<Ident> { + pub fn opt_item_ident(self, def_id: impl IntoQueryParam<DefId>) -> Option<Ident> { + let def_id = def_id.into_query_param(); let def = self.opt_item_name(def_id)?; let span = self .def_ident_span(def_id) @@ -1630,7 +1633,8 @@ impl<'tcx> TyCtxt<'tcx> { /// Look up the name and span of a definition. /// /// See [`item_name`][Self::item_name] for more information. - pub fn item_ident(self, def_id: DefId) -> Ident { + pub fn item_ident(self, def_id: impl IntoQueryParam<DefId>) -> Ident { + let def_id = def_id.into_query_param(); self.opt_item_ident(def_id).unwrap_or_else(|| { bug!("item_ident: no name for {:?}", self.def_path(def_id)); }) |
