Rollup merge of #109477 - lcnr:cleanup, r=cjgillot

`HirId` to `LocalDefId` cleanup

revival of the still relevant parts of #109125
This commit is contained in:
Matthias Krüger 2023-03-22 20:08:04 +01:00 committed by GitHub
commit 040001e7c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 12 deletions

View file

@ -1208,7 +1208,7 @@ fn infer_return_ty_for_fn_sig<'tcx>(
fn_sig, fn_sig,
Applicability::MachineApplicable, 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( diag.span_suggestion(
ty.span, ty.span,
"replace with an appropriate return type", "replace with an appropriate return type",
@ -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>( fn suggest_impl_trait<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
ret_ty: Ty<'tcx>, ret_ty: Ty<'tcx>,
span: Span, span: Span,
_hir_id: hir::HirId,
def_id: LocalDefId, def_id: LocalDefId,
) -> Option<String> { ) -> Option<String> {
let format_as_assoc: fn(_, _, _, _, _) -> _ = let format_as_assoc: fn(_, _, _, _, _) -> _ =

View file

@ -165,8 +165,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&self, &self,
ty: Ty<'tcx>, ty: Ty<'tcx>,
) -> Option<(DefIdOrName, Ty<'tcx>, Vec<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(self.body_id, self.param_env, ty)
self.err_ctxt().extract_callable_info(body_hir_id, self.param_env, ty)
} }
pub fn suggest_two_fn_call( pub fn suggest_two_fn_call(

View file

@ -2525,7 +2525,7 @@ impl<'tcx> TyCtxt<'tcx> {
ident ident
} }
// FIXME(vincenzoapalzzo): move the HirId to a LocalDefId // FIXME(vincenzopalazzo): move the HirId to a LocalDefId
pub fn adjust_ident_and_get_scope( pub fn adjust_ident_and_get_scope(
self, self,
mut ident: Ident, mut ident: Ident,

View file

@ -212,7 +212,7 @@ pub trait TypeErrCtxtExt<'tcx> {
fn extract_callable_info( fn extract_callable_info(
&self, &self,
hir_id: HirId, body_id: LocalDefId,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
found: Ty<'tcx>, found: Ty<'tcx>,
) -> Option<(DefIdOrName, Ty<'tcx>, Vec<Ty<'tcx>>)>; ) -> Option<(DefIdOrName, Ty<'tcx>, Vec<Ty<'tcx>>)>;
@ -909,9 +909,8 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
trait_pred.self_ty(), 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( let Some((def_id_or_name, output, inputs)) = self.extract_callable_info(
body_hir_id, obligation.cause.body_id,
obligation.param_env, obligation.param_env,
self_ty, self_ty,
) else { return false; }; ) else { return false; };
@ -1113,10 +1112,9 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
/// Extracts information about a callable type for diagnostics. This is a /// Extracts information about a callable type for diagnostics. This is a
/// heuristic -- it doesn't necessarily mean that a type is always callable, /// heuristic -- it doesn't necessarily mean that a type is always callable,
/// because the callable type must also be well-formed to be called. /// because the callable type must also be well-formed to be called.
// FIXME(vincenzopalazzo): move the HirId to a LocalDefId
fn extract_callable_info( fn extract_callable_info(
&self, &self,
hir_id: HirId, body_id: LocalDefId,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
found: Ty<'tcx>, found: Ty<'tcx>,
) -> Option<(DefIdOrName, Ty<'tcx>, Vec<Ty<'tcx>>)> { ) -> Option<(DefIdOrName, Ty<'tcx>, Vec<Ty<'tcx>>)> {
@ -1168,7 +1166,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
}) })
} }
ty::Param(param) => { ty::Param(param) => {
let generics = self.tcx.generics_of(hir_id.owner.to_def_id()); let generics = self.tcx.generics_of(body_id);
let name = if generics.count() > param.index as usize let name = if generics.count() > param.index as usize
&& let def = generics.param_at(param.index as usize, self.tcx) && let def = generics.param_at(param.index as usize, self.tcx)
&& matches!(def.kind, ty::GenericParamDefKind::Type { .. }) && matches!(def.kind, ty::GenericParamDefKind::Type { .. })