Skip to content

Commit 36bc094

Browse files
committed
Generalize TyCtxt::item_name.
1 parent 277b0ec commit 36bc094

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
@@ -144,7 +144,7 @@ fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -> hi
144144
tcx.def_span(intrinsic_id),
145145
DiagMessage::from(format!(
146146
"intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `{}`",
147-
tcx.item_name(intrinsic_id.into())
147+
tcx.item_name(intrinsic_id)
148148
)
149149
)).emit();
150150
}

compiler/rustc_middle/src/ty/mod.rs

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

15921592
/// Look up the name of a definition across crates. This does not look at HIR.
1593-
pub fn opt_item_name(self, def_id: DefId) -> Option<Symbol> {
1593+
pub fn opt_item_name(self, def_id: impl IntoQueryParam<DefId>) -> Option<Symbol> {
1594+
let def_id = def_id.into_query_param();
15941595
if let Some(cnum) = def_id.as_crate_root() {
15951596
Some(self.crate_name(cnum))
15961597
} else {
@@ -1610,7 +1611,8 @@ impl<'tcx> TyCtxt<'tcx> {
16101611
/// [`opt_item_name`] instead.
16111612
///
16121613
/// [`opt_item_name`]: Self::opt_item_name
1613-
pub fn item_name(self, id: DefId) -> Symbol {
1614+
pub fn item_name(self, id: impl IntoQueryParam<DefId>) -> Symbol {
1615+
let id = id.into_query_param();
16141616
self.opt_item_name(id).unwrap_or_else(|| {
16151617
bug!("item_name: no name for {:?}", self.def_path(id));
16161618
})
@@ -1619,7 +1621,8 @@ impl<'tcx> TyCtxt<'tcx> {
16191621
/// Look up the name and span of a definition.
16201622
///
16211623
/// See [`item_name`][Self::item_name] for more information.
1622-
pub fn opt_item_ident(self, def_id: DefId) -> Option<Ident> {
1624+
pub fn opt_item_ident(self, def_id: impl IntoQueryParam<DefId>) -> Option<Ident> {
1625+
let def_id = def_id.into_query_param();
16231626
let def = self.opt_item_name(def_id)?;
16241627
let span = self
16251628
.def_ident_span(def_id)
@@ -1630,7 +1633,8 @@ impl<'tcx> TyCtxt<'tcx> {
16301633
/// Look up the name and span of a definition.
16311634
///
16321635
/// See [`item_name`][Self::item_name] for more information.
1633-
pub fn item_ident(self, def_id: DefId) -> Ident {
1636+
pub fn item_ident(self, def_id: impl IntoQueryParam<DefId>) -> Ident {
1637+
let def_id = def_id.into_query_param();
16341638
self.opt_item_ident(def_id).unwrap_or_else(|| {
16351639
bug!("item_ident: no name for {:?}", self.def_path(def_id));
16361640
})

compiler/rustc_middle/src/ty/util.rs

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ fn find_fallback_pattern_typo<'tcx>(
10841084
&& infcx.can_eq(param_env, ty, cx.tcx.type_of(item.owner_id).instantiate_identity())
10851085
{
10861086
// Look for local consts.
1087-
let item_name = cx.tcx.item_name(item.owner_id.into());
1087+
let item_name = cx.tcx.item_name(item.owner_id);
10881088
let vis = cx.tcx.visibility(item.owner_id);
10891089
if vis.is_accessible_from(parent, cx.tcx) {
10901090
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)