Avoid some def_span query calls

This commit is contained in:
Oli Scherer 2024-04-29 09:48:19 +00:00
parent 90704199fa
commit fea1fe7f01
3 changed files with 12 additions and 15 deletions

View File

@ -24,7 +24,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
let hir_id = tcx.local_def_id_to_hir_id(def_id);
let node = tcx.hir_node(hir_id);
let Node::AnonConst(_) = node else {
let Node::AnonConst(&AnonConst { span, .. }) = node else {
span_bug!(
tcx.def_span(def_id),
"expected anon const in `anon_const_type_of`, got {node:?}"
@ -134,7 +134,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
// I dont think it's possible to reach this but I'm not 100% sure - BoxyUwU
return Ty::new_error_with_message(
tcx,
tcx.def_span(def_id),
span,
"unexpected non-GAT usage of an anon const",
);
}
@ -152,7 +152,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
let Some(type_dependent_def) = tables.type_dependent_def_id(parent_node_id) else {
return Ty::new_error_with_message(
tcx,
tcx.def_span(def_id),
span,
format!("unable to find type-dependent def for {parent_node_id:?}"),
);
};
@ -194,7 +194,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
} else {
return Ty::new_error_with_message(
tcx,
tcx.def_span(def_id),
span,
format!("unable to find const parent for {hir_id} in pat {pat:?}"),
);
}
@ -202,7 +202,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
_ => {
return Ty::new_error_with_message(
tcx,
tcx.def_span(def_id),
span,
format!("unexpected const parent path {parent_node:?}"),
);
}
@ -226,11 +226,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
.map(|idx| (idx, seg))
})
}) else {
return Ty::new_error_with_message(
tcx,
tcx.def_span(def_id),
"no arg matching AnonConst in path",
);
return Ty::new_error_with_message(tcx, span, "no arg matching AnonConst in path");
};
let generics = match tcx.res_generics_def_id(segment.res) {
@ -238,7 +234,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
None => {
return Ty::new_error_with_message(
tcx,
tcx.def_span(def_id),
span,
format!("unexpected anon const res {:?} in path: {:?}", segment.res, path),
);
}
@ -250,7 +246,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
_ => {
return Ty::new_error_with_message(
tcx,
tcx.def_span(def_id),
span,
format!("unexpected const parent in type_of(): {parent_node:?}"),
);
}
@ -278,7 +274,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
} else {
return Ty::new_error_with_message(
tcx,
tcx.def_span(def_id),
span,
format!("const generic parameter not found in {generics:?} at position {arg_idx:?}"),
);
}

View File

@ -885,7 +885,7 @@ impl<'hir> Map<'hir> {
Node::ImplItem(impl_item) => impl_item.span,
Node::Variant(variant) => variant.span,
Node::Field(field) => field.span,
Node::AnonConst(constant) => self.body(constant.body).value.span,
Node::AnonConst(constant) => constant.span,
Node::ConstBlock(constant) => self.body(constant.body).value.span,
Node::Expr(expr) => expr.span,
Node::ExprField(field) => field.span,

View File

@ -566,7 +566,8 @@ fn construct_const<'a, 'tcx>(
span,
..
}) => (*span, ty.span),
Node::AnonConst(_) | Node::ConstBlock(_) => {
Node::AnonConst(ct) => (ct.span, ct.span),
Node::ConstBlock(_) => {
let span = tcx.def_span(def);
(span, span)
}