Skip to content

Commit 321f37a

Browse files
committed
Generalize TyCtxt::item_name.
1 parent da4b36f commit 321f37a

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed

compiler/rustc_hir_analysis/src/check/intrinsic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ fn equate_intrinsic_type<'tcx>(
5959

6060
/// Returns the unsafety of the given intrinsic.
6161
fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -> hir::Safety {
62-
let is_in_list = match tcx.item_name(intrinsic_id.into()) {
62+
let is_in_list = match tcx.item_name(intrinsic_id) {
6363
// When adding a new intrinsic to this list,
6464
// it's usually worth updating that intrinsic's documentation
6565
// to note that it's safe to call, since
@@ -143,7 +143,7 @@ fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -> hi
143143
tcx.def_span(intrinsic_id),
144144
DiagMessage::from(format!(
145145
"intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `{}`",
146-
tcx.item_name(intrinsic_id.into())
146+
tcx.item_name(intrinsic_id)
147147
)
148148
)).emit();
149149
}

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,7 +1593,8 @@ impl<'tcx> TyCtxt<'tcx> {
15931593
}
15941594

15951595
/// Look up the name of a definition across crates. This does not look at HIR.
1596-
pub fn opt_item_name(self, def_id: DefId) -> Option<Symbol> {
1596+
pub fn opt_item_name(self, def_id: impl IntoQueryParam<DefId>) -> Option<Symbol> {
1597+
let def_id = def_id.into_query_param();
15971598
if let Some(cnum) = def_id.as_crate_root() {
15981599
Some(self.crate_name(cnum))
15991600
} else {
@@ -1613,7 +1614,8 @@ impl<'tcx> TyCtxt<'tcx> {
16131614
/// [`opt_item_name`] instead.
16141615
///
16151616
/// [`opt_item_name`]: Self::opt_item_name
1616-
pub fn item_name(self, id: DefId) -> Symbol {
1617+
pub fn item_name(self, id: impl IntoQueryParam<DefId>) -> Symbol {
1618+
let id = id.into_query_param();
16171619
self.opt_item_name(id).unwrap_or_else(|| {
16181620
bug!("item_name: no name for {:?}", self.def_path(id));
16191621
})
@@ -1622,7 +1624,8 @@ impl<'tcx> TyCtxt<'tcx> {
16221624
/// Look up the name and span of a definition.
16231625
///
16241626
/// See [`item_name`][Self::item_name] for more information.
1625-
pub fn opt_item_ident(self, def_id: DefId) -> Option<Ident> {
1627+
pub fn opt_item_ident(self, def_id: impl IntoQueryParam<DefId>) -> Option<Ident> {
1628+
let def_id = def_id.into_query_param();
16261629
let def = self.opt_item_name(def_id)?;
16271630
let span = self
16281631
.def_ident_span(def_id)
@@ -1633,7 +1636,8 @@ impl<'tcx> TyCtxt<'tcx> {
16331636
/// Look up the name and span of a definition.
16341637
///
16351638
/// See [`item_name`][Self::item_name] for more information.
1636-
pub fn item_ident(self, def_id: DefId) -> Ident {
1639+
pub fn item_ident(self, def_id: impl IntoQueryParam<DefId>) -> Ident {
1640+
let def_id = def_id.into_query_param();
16371641
self.opt_item_ident(def_id).unwrap_or_else(|| {
16381642
bug!("item_ident: no name for {:?}", self.def_path(def_id));
16391643
})

compiler/rustc_middle/src/ty/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1681,7 +1681,7 @@ pub fn intrinsic_raw(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ty::Intrinsi
16811681
_ => true,
16821682
};
16831683
Some(ty::IntrinsicDef {
1684-
name: tcx.item_name(def_id.into()),
1684+
name: tcx.item_name(def_id),
16851685
must_be_overridden,
16861686
const_stable: tcx.has_attr(def_id, sym::rustc_intrinsic_const_stable_indirect),
16871687
})

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@ fn find_fallback_pattern_typo<'tcx>(
10831083
&& infcx.can_eq(param_env, ty, cx.tcx.type_of(item.owner_id).instantiate_identity())
10841084
{
10851085
// Look for local consts.
1086-
let item_name = cx.tcx.item_name(item.owner_id.into());
1086+
let item_name = cx.tcx.item_name(item.owner_id);
10871087
let vis = cx.tcx.visibility(item.owner_id);
10881088
if vis.is_accessible_from(parent, cx.tcx) {
10891089
accessible.push(item_name);

compiler/rustc_passes/src/abi_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ fn dump_abi_of_fn_item(tcx: TyCtxt<'_>, item_def_id: LocalDefId, attr: &Attribut
7979
for meta_item in meta_items {
8080
match meta_item.name() {
8181
Some(sym::debug) => {
82-
let fn_name = tcx.item_name(item_def_id.into());
82+
let fn_name = tcx.item_name(item_def_id);
8383
tcx.dcx().emit_err(AbiOf {
8484
span: tcx.def_span(item_def_id),
8585
fn_name,
@@ -135,7 +135,7 @@ fn dump_abi_of_fn_type(tcx: TyCtxt<'_>, item_def_id: LocalDefId, attr: &Attribut
135135
item_def_id,
136136
);
137137

138-
let fn_name = tcx.item_name(item_def_id.into());
138+
let fn_name = tcx.item_name(item_def_id);
139139
tcx.dcx().emit_err(AbiOf { span, fn_name, fn_abi: format!("{:#?}", abi) });
140140
}
141141
Some(sym::assert_eq) => {

0 commit comments

Comments
 (0)