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

HirId to LocalDefId cleanup #109477

Merged
merged 2 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 1 addition & 3 deletions compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1208,7 +1208,7 @@ fn infer_return_ty_for_fn_sig<'tcx>(
fn_sig,
Applicability::MachineApplicable,
);
} else if let Some(sugg) = suggest_impl_trait(tcx, ret_ty, ty.span, hir_id, def_id) {
} else if let Some(sugg) = suggest_impl_trait(tcx, ret_ty, ty.span, def_id) {
diag.span_suggestion(
ty.span,
"replace with an appropriate return type",
Expand Down Expand Up @@ -1240,12 +1240,10 @@ fn infer_return_ty_for_fn_sig<'tcx>(
}
}

// FIXME(vincenzopalazzo): remove the hir item when the refactoring is stable
fn suggest_impl_trait<'tcx>(
tcx: TyCtxt<'tcx>,
ret_ty: Ty<'tcx>,
span: Span,
_hir_id: hir::HirId,
def_id: LocalDefId,
) -> Option<String> {
let format_as_assoc: fn(_, _, _, _, _) -> _ =
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&self,
ty: Ty<'tcx>,
) -> Option<(DefIdOrName, Ty<'tcx>, Vec<Ty<'tcx>>)> {
let body_hir_id = self.tcx.hir().local_def_id_to_hir_id(self.body_id);
self.err_ctxt().extract_callable_info(body_hir_id, self.param_env, ty)
self.err_ctxt().extract_callable_info(self.body_id, self.param_env, ty)
}

pub fn suggest_two_fn_call(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2525,7 +2525,7 @@ impl<'tcx> TyCtxt<'tcx> {
ident
}

// FIXME(vincenzoapalzzo): move the HirId to a LocalDefId
// FIXME(vincenzopalazzo): move the HirId to a LocalDefId
pub fn adjust_ident_and_get_scope(
self,
mut ident: Ident,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ pub trait TypeErrCtxtExt<'tcx> {

fn extract_callable_info(
&self,
hir_id: HirId,
hir_id: LocalDefId,
lcnr marked this conversation as resolved.
Show resolved Hide resolved
param_env: ty::ParamEnv<'tcx>,
found: Ty<'tcx>,
) -> Option<(DefIdOrName, Ty<'tcx>, Vec<Ty<'tcx>>)>;
Expand Down Expand Up @@ -909,9 +909,8 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
trait_pred.self_ty(),
);

let body_hir_id = self.tcx.hir().local_def_id_to_hir_id(obligation.cause.body_id);
let Some((def_id_or_name, output, inputs)) = self.extract_callable_info(
body_hir_id,
obligation.cause.body_id,
obligation.param_env,
self_ty,
) else { return false; };
Expand Down Expand Up @@ -1116,7 +1115,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
// FIXME(vincenzopalazzo): move the HirId to a LocalDefId
lcnr marked this conversation as resolved.
Show resolved Hide resolved
fn extract_callable_info(
&self,
hir_id: HirId,
body_id: LocalDefId,
param_env: ty::ParamEnv<'tcx>,
found: Ty<'tcx>,
) -> Option<(DefIdOrName, Ty<'tcx>, Vec<Ty<'tcx>>)> {
Expand Down Expand Up @@ -1168,7 +1167,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
})
}
ty::Param(param) => {
let generics = self.tcx.generics_of(hir_id.owner.to_def_id());
let generics = self.tcx.generics_of(body_id);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not exactly equivalent for closures, but the difference doesn't matter.
r=me once CI passes

let name = if generics.count() > param.index as usize
&& let def = generics.param_at(param.index as usize, self.tcx)
&& matches!(def.kind, ty::GenericParamDefKind::Type { .. })
Expand Down