Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove opt_item_ident #136061

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ pub(crate) enum PtrNullChecksDiag<'a> {
label: Span,
},
#[diag(lint_ptr_null_checks_fn_ret)]
FnRet { fn_name: Ident },
FnRet { fn_name: Symbol },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a function is named async in edition 2018 it should be reported as r#async, but symbols don't carry the "raw-ness" unlike ident.

Are we fine having inaccurate item name in some edge-cases ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh good point

of course we don't have any tests for this lol

}

// for_loops_over_fallibles.rs
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_lint/src/ptr_nulls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ fn incorrect_check<'a, 'tcx: 'a>(
if let ExprKind::MethodCall(_, _expr, [], _) = e.kind
&& let Some(def_id) = cx.typeck_results().type_dependent_def_id(e.hir_id)
&& cx.tcx.has_attr(def_id, sym::rustc_never_returns_null_ptr)
&& let Some(fn_name) = cx.tcx.opt_item_ident(def_id)
&& let Some(fn_name) = cx.tcx.opt_item_name(def_id)
{
return Some(PtrNullChecksDiag::FnRet { fn_name });
} else if let ExprKind::Call(path, _args) = e.kind
&& let ExprKind::Path(ref qpath) = path.kind
&& let Some(def_id) = cx.qpath_res(qpath, path.hir_id).opt_def_id()
&& cx.tcx.has_attr(def_id, sym::rustc_never_returns_null_ptr)
&& let Some(fn_name) = cx.tcx.opt_item_ident(def_id)
&& let Some(fn_name) = cx.tcx.opt_item_name(def_id)
{
return Some(PtrNullChecksDiag::FnRet { fn_name });
}
Expand Down
10 changes: 3 additions & 7 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -999,20 +999,16 @@ impl<'a> CrateMetadataRef<'a> {
self.opt_item_name(item_index).expect("no encoded ident for item")
}

fn opt_item_ident(self, item_index: DefIndex, sess: &Session) -> Option<Ident> {
let name = self.opt_item_name(item_index)?;
fn item_ident(self, item_index: DefIndex, sess: &Session) -> Ident {
let name = self.opt_item_name(item_index).expect("no encoded ident for item");
let span = self
.root
.tables
.def_ident_span
.get(self, item_index)
.unwrap_or_else(|| self.missing("def_ident_span", item_index))
.decode((self, sess));
Some(Ident::new(name, span))
}

fn item_ident(self, item_index: DefIndex, sess: &Session) -> Ident {
self.opt_item_ident(item_index, sess).expect("no encoded ident for item")
Ident::new(name, span)
}

#[inline]
Expand Down
11 changes: 0 additions & 11 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1585,17 +1585,6 @@ 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> {
let def = self.opt_item_name(def_id)?;
let span = self
.def_ident_span(def_id)
.unwrap_or_else(|| bug!("missing ident span for {def_id:?}"));
Some(Ident::new(def, span))
}

pub fn opt_associated_item(self, def_id: DefId) -> Option<AssocItem> {
if let DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy = self.def_kind(def_id) {
Some(self.associated_item(def_id))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2795,15 +2795,15 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
let short_item_name = with_forced_trimmed_paths!(tcx.def_path_str(item_def_id));
let mut multispan = MultiSpan::from(span);
let sm = tcx.sess.source_map();
if let Some(ident) = tcx.opt_item_ident(item_def_id) {
if let Some(ident_span) = tcx.def_ident_span(item_def_id) {
let same_line =
match (sm.lookup_line(ident.span.hi()), sm.lookup_line(span.lo())) {
match (sm.lookup_line(ident_span.hi()), sm.lookup_line(span.lo())) {
(Ok(l), Ok(r)) => l.line == r.line,
_ => true,
};
if ident.span.is_visible(sm) && !ident.span.overlaps(span) && !same_line {
if ident_span.is_visible(sm) && !ident_span.overlaps(span) && !same_line {
multispan.push_span_label(
ident.span,
ident_span,
format!(
"required by a bound in this {}",
tcx.def_kind(item_def_id).descr(item_def_id)
Expand Down Expand Up @@ -3253,9 +3253,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
let ty_str = tcx.short_ty_string(ty, long_ty_file);
let msg = format!("required because it appears within the type `{ty_str}`");
match ty.kind() {
ty::Adt(def, _) => match tcx.opt_item_ident(def.did()) {
Some(ident) => {
err.span_note(ident.span, msg);
ty::Adt(def, _) => match tcx.def_ident_span(def.did()) {
Some(ident_span) => {
err.span_note(ident_span, msg);
}
None => {
err.note(msg);
Expand Down Expand Up @@ -3595,19 +3595,18 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
`{item_name}` but not on the corresponding trait's {kind}",
);
let sp = tcx
.opt_item_ident(trait_item_def_id)
.map(|i| i.span)
.def_ident_span(trait_item_def_id)
.unwrap_or_else(|| tcx.def_span(trait_item_def_id));
let mut assoc_span: MultiSpan = sp.into();
assoc_span.push_span_label(
sp,
format!("this trait's {kind} doesn't have the requirement `{predicate}`"),
);
if let Some(ident) = tcx
if let Some(ident_span) = tcx
.opt_associated_item(trait_item_def_id)
.and_then(|i| tcx.opt_item_ident(i.container_id(tcx)))
.and_then(|i| tcx.def_ident_span(i.container_id(tcx)))
{
assoc_span.push_span_label(ident.span, "in this trait");
assoc_span.push_span_label(ident_span, "in this trait");
}
err.span_note(assoc_span, msg);
}
Expand Down
3 changes: 1 addition & 2 deletions src/tools/clippy/clippy_lints/src/error_impl_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ impl<'tcx> LateLintPass<'tcx> for ErrorImplError {
&& let Some(error_def_id) = cx.tcx.get_diagnostic_item(sym::Error)
&& error_def_id == trait_def_id
&& let Some(def_id) = path_res(cx, imp.self_ty).opt_def_id().and_then(DefId::as_local)
&& let Some(ident) = cx.tcx.opt_item_ident(def_id.to_def_id())
&& ident.name == sym::Error
&& let Some(sym::Error) = cx.tcx.opt_item_name(def_id.to_def_id())
&& is_visible_outside_module(cx, def_id) =>
{
span_lint_hir_and_then(
Expand Down
Loading