Skip to content

Commit c8e8d6b

Browse files
committed
Generalize TyCtxt::item_name.
1 parent bdb9661 commit c8e8d6b

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
@@ -1589,7 +1589,8 @@ impl<'tcx> TyCtxt<'tcx> {
15891589
}
15901590

15911591
/// Look up the name of a definition across crates. This does not look at HIR.
1592-
pub fn opt_item_name(self, def_id: DefId) -> Option<Symbol> {
1592+
pub fn opt_item_name(self, def_id: impl IntoQueryParam<DefId>) -> Option<Symbol> {
1593+
let def_id = def_id.into_query_param();
15931594
if let Some(cnum) = def_id.as_crate_root() {
15941595
Some(self.crate_name(cnum))
15951596
} else {
@@ -1609,7 +1610,8 @@ impl<'tcx> TyCtxt<'tcx> {
16091610
/// [`opt_item_name`] instead.
16101611
///
16111612
/// [`opt_item_name`]: Self::opt_item_name
1612-
pub fn item_name(self, id: DefId) -> Symbol {
1613+
pub fn item_name(self, id: impl IntoQueryParam<DefId>) -> Symbol {
1614+
let id = id.into_query_param();
16131615
self.opt_item_name(id).unwrap_or_else(|| {
16141616
bug!("item_name: no name for {:?}", self.def_path(id));
16151617
})
@@ -1618,7 +1620,8 @@ impl<'tcx> TyCtxt<'tcx> {
16181620
/// Look up the name and span of a definition.
16191621
///
16201622
/// See [`item_name`][Self::item_name] for more information.
1621-
pub fn opt_item_ident(self, def_id: DefId) -> Option<Ident> {
1623+
pub fn opt_item_ident(self, def_id: impl IntoQueryParam<DefId>) -> Option<Ident> {
1624+
let def_id = def_id.into_query_param();
16221625
let def = self.opt_item_name(def_id)?;
16231626
let span = self
16241627
.def_ident_span(def_id)
@@ -1629,7 +1632,8 @@ impl<'tcx> TyCtxt<'tcx> {
16291632
/// Look up the name and span of a definition.
16301633
///
16311634
/// See [`item_name`][Self::item_name] for more information.
1632-
pub fn item_ident(self, def_id: DefId) -> Ident {
1635+
pub fn item_ident(self, def_id: impl IntoQueryParam<DefId>) -> Ident {
1636+
let def_id = def_id.into_query_param();
16331637
self.opt_item_ident(def_id).unwrap_or_else(|| {
16341638
bug!("item_ident: no name for {:?}", self.def_path(def_id));
16351639
})

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)