Skip to content

Commit 42014b8

Browse files
Remove opt_item_ident
1 parent 203e6c1 commit 42014b8

File tree

6 files changed

+18
-35
lines changed

6 files changed

+18
-35
lines changed

compiler/rustc_lint/src/lints.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ pub(crate) enum PtrNullChecksDiag<'a> {
600600
label: Span,
601601
},
602602
#[diag(lint_ptr_null_checks_fn_ret)]
603-
FnRet { fn_name: Ident },
603+
FnRet { fn_name: Symbol },
604604
}
605605

606606
// for_loops_over_fallibles.rs

compiler/rustc_lint/src/ptr_nulls.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ fn incorrect_check<'a, 'tcx: 'a>(
4848
if let ExprKind::MethodCall(_, _expr, [], _) = e.kind
4949
&& let Some(def_id) = cx.typeck_results().type_dependent_def_id(e.hir_id)
5050
&& cx.tcx.has_attr(def_id, sym::rustc_never_returns_null_ptr)
51-
&& let Some(fn_name) = cx.tcx.opt_item_ident(def_id)
51+
&& let Some(fn_name) = cx.tcx.opt_item_name(def_id)
5252
{
5353
return Some(PtrNullChecksDiag::FnRet { fn_name });
5454
} else if let ExprKind::Call(path, _args) = e.kind
5555
&& let ExprKind::Path(ref qpath) = path.kind
5656
&& let Some(def_id) = cx.qpath_res(qpath, path.hir_id).opt_def_id()
5757
&& cx.tcx.has_attr(def_id, sym::rustc_never_returns_null_ptr)
58-
&& let Some(fn_name) = cx.tcx.opt_item_ident(def_id)
58+
&& let Some(fn_name) = cx.tcx.opt_item_name(def_id)
5959
{
6060
return Some(PtrNullChecksDiag::FnRet { fn_name });
6161
}

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -999,20 +999,16 @@ impl<'a> CrateMetadataRef<'a> {
999999
self.opt_item_name(item_index).expect("no encoded ident for item")
10001000
}
10011001

1002-
fn opt_item_ident(self, item_index: DefIndex, sess: &Session) -> Option<Ident> {
1003-
let name = self.opt_item_name(item_index)?;
1002+
fn item_ident(self, item_index: DefIndex, sess: &Session) -> Ident {
1003+
let name = self.opt_item_name(item_index).expect("no encoded ident for item");
10041004
let span = self
10051005
.root
10061006
.tables
10071007
.def_ident_span
10081008
.get(self, item_index)
10091009
.unwrap_or_else(|| self.missing("def_ident_span", item_index))
10101010
.decode((self, sess));
1011-
Some(Ident::new(name, span))
1012-
}
1013-
1014-
fn item_ident(self, item_index: DefIndex, sess: &Session) -> Ident {
1015-
self.opt_item_ident(item_index, sess).expect("no encoded ident for item")
1011+
Ident::new(name, span)
10161012
}
10171013

10181014
#[inline]

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,17 +1585,6 @@ impl<'tcx> TyCtxt<'tcx> {
15851585
})
15861586
}
15871587

1588-
/// Look up the name and span of a definition.
1589-
///
1590-
/// See [`item_name`][Self::item_name] for more information.
1591-
pub fn opt_item_ident(self, def_id: DefId) -> Option<Ident> {
1592-
let def = self.opt_item_name(def_id)?;
1593-
let span = self
1594-
.def_ident_span(def_id)
1595-
.unwrap_or_else(|| bug!("missing ident span for {def_id:?}"));
1596-
Some(Ident::new(def, span))
1597-
}
1598-
15991588
pub fn opt_associated_item(self, def_id: DefId) -> Option<AssocItem> {
16001589
if let DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy = self.def_kind(def_id) {
16011590
Some(self.associated_item(def_id))

compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2795,15 +2795,15 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
27952795
let short_item_name = with_forced_trimmed_paths!(tcx.def_path_str(item_def_id));
27962796
let mut multispan = MultiSpan::from(span);
27972797
let sm = tcx.sess.source_map();
2798-
if let Some(ident) = tcx.opt_item_ident(item_def_id) {
2798+
if let Some(ident_span) = tcx.def_ident_span(item_def_id) {
27992799
let same_line =
2800-
match (sm.lookup_line(ident.span.hi()), sm.lookup_line(span.lo())) {
2800+
match (sm.lookup_line(ident_span.hi()), sm.lookup_line(span.lo())) {
28012801
(Ok(l), Ok(r)) => l.line == r.line,
28022802
_ => true,
28032803
};
2804-
if ident.span.is_visible(sm) && !ident.span.overlaps(span) && !same_line {
2804+
if ident_span.is_visible(sm) && !ident_span.overlaps(span) && !same_line {
28052805
multispan.push_span_label(
2806-
ident.span,
2806+
ident_span,
28072807
format!(
28082808
"required by a bound in this {}",
28092809
tcx.def_kind(item_def_id).descr(item_def_id)
@@ -3253,9 +3253,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
32533253
let ty_str = tcx.short_ty_string(ty, long_ty_file);
32543254
let msg = format!("required because it appears within the type `{ty_str}`");
32553255
match ty.kind() {
3256-
ty::Adt(def, _) => match tcx.opt_item_ident(def.did()) {
3257-
Some(ident) => {
3258-
err.span_note(ident.span, msg);
3256+
ty::Adt(def, _) => match tcx.def_ident_span(def.did()) {
3257+
Some(ident_span) => {
3258+
err.span_note(ident_span, msg);
32593259
}
32603260
None => {
32613261
err.note(msg);
@@ -3595,19 +3595,18 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
35953595
`{item_name}` but not on the corresponding trait's {kind}",
35963596
);
35973597
let sp = tcx
3598-
.opt_item_ident(trait_item_def_id)
3599-
.map(|i| i.span)
3598+
.def_ident_span(trait_item_def_id)
36003599
.unwrap_or_else(|| tcx.def_span(trait_item_def_id));
36013600
let mut assoc_span: MultiSpan = sp.into();
36023601
assoc_span.push_span_label(
36033602
sp,
36043603
format!("this trait's {kind} doesn't have the requirement `{predicate}`"),
36053604
);
3606-
if let Some(ident) = tcx
3605+
if let Some(ident_span) = tcx
36073606
.opt_associated_item(trait_item_def_id)
3608-
.and_then(|i| tcx.opt_item_ident(i.container_id(tcx)))
3607+
.and_then(|i| tcx.def_ident_span(i.container_id(tcx)))
36093608
{
3610-
assoc_span.push_span_label(ident.span, "in this trait");
3609+
assoc_span.push_span_label(ident_span, "in this trait");
36113610
}
36123611
err.span_note(assoc_span, msg);
36133612
}

src/tools/clippy/clippy_lints/src/error_impl_error.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ impl<'tcx> LateLintPass<'tcx> for ErrorImplError {
5656
&& let Some(error_def_id) = cx.tcx.get_diagnostic_item(sym::Error)
5757
&& error_def_id == trait_def_id
5858
&& let Some(def_id) = path_res(cx, imp.self_ty).opt_def_id().and_then(DefId::as_local)
59-
&& let Some(ident) = cx.tcx.opt_item_ident(def_id.to_def_id())
60-
&& ident.name == sym::Error
59+
&& let Some(sym::Error) = cx.tcx.opt_item_name(def_id.to_def_id())
6160
&& is_visible_outside_module(cx, def_id) =>
6261
{
6362
span_lint_hir_and_then(

0 commit comments

Comments
 (0)