Avoid some def_span
query calls
This commit is contained in:
parent
90704199fa
commit
fea1fe7f01
3 changed files with 12 additions and 15 deletions
|
@ -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 hir_id = tcx.local_def_id_to_hir_id(def_id);
|
||||||
|
|
||||||
let node = tcx.hir_node(hir_id);
|
let node = tcx.hir_node(hir_id);
|
||||||
let Node::AnonConst(_) = node else {
|
let Node::AnonConst(&AnonConst { span, .. }) = node else {
|
||||||
span_bug!(
|
span_bug!(
|
||||||
tcx.def_span(def_id),
|
tcx.def_span(def_id),
|
||||||
"expected anon const in `anon_const_type_of`, got {node:?}"
|
"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
|
// I dont think it's possible to reach this but I'm not 100% sure - BoxyUwU
|
||||||
return Ty::new_error_with_message(
|
return Ty::new_error_with_message(
|
||||||
tcx,
|
tcx,
|
||||||
tcx.def_span(def_id),
|
span,
|
||||||
"unexpected non-GAT usage of an anon const",
|
"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 {
|
let Some(type_dependent_def) = tables.type_dependent_def_id(parent_node_id) else {
|
||||||
return Ty::new_error_with_message(
|
return Ty::new_error_with_message(
|
||||||
tcx,
|
tcx,
|
||||||
tcx.def_span(def_id),
|
span,
|
||||||
format!("unable to find type-dependent def for {parent_node_id:?}"),
|
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 {
|
} else {
|
||||||
return Ty::new_error_with_message(
|
return Ty::new_error_with_message(
|
||||||
tcx,
|
tcx,
|
||||||
tcx.def_span(def_id),
|
span,
|
||||||
format!("unable to find const parent for {hir_id} in pat {pat:?}"),
|
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(
|
return Ty::new_error_with_message(
|
||||||
tcx,
|
tcx,
|
||||||
tcx.def_span(def_id),
|
span,
|
||||||
format!("unexpected const parent path {parent_node:?}"),
|
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))
|
.map(|idx| (idx, seg))
|
||||||
})
|
})
|
||||||
}) else {
|
}) else {
|
||||||
return Ty::new_error_with_message(
|
return Ty::new_error_with_message(tcx, span, "no arg matching AnonConst in path");
|
||||||
tcx,
|
|
||||||
tcx.def_span(def_id),
|
|
||||||
"no arg matching AnonConst in path",
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let generics = match tcx.res_generics_def_id(segment.res) {
|
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 => {
|
None => {
|
||||||
return Ty::new_error_with_message(
|
return Ty::new_error_with_message(
|
||||||
tcx,
|
tcx,
|
||||||
tcx.def_span(def_id),
|
span,
|
||||||
format!("unexpected anon const res {:?} in path: {:?}", segment.res, path),
|
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(
|
return Ty::new_error_with_message(
|
||||||
tcx,
|
tcx,
|
||||||
tcx.def_span(def_id),
|
span,
|
||||||
format!("unexpected const parent in type_of(): {parent_node:?}"),
|
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 {
|
} else {
|
||||||
return Ty::new_error_with_message(
|
return Ty::new_error_with_message(
|
||||||
tcx,
|
tcx,
|
||||||
tcx.def_span(def_id),
|
span,
|
||||||
format!("const generic parameter not found in {generics:?} at position {arg_idx:?}"),
|
format!("const generic parameter not found in {generics:?} at position {arg_idx:?}"),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -885,7 +885,7 @@ impl<'hir> Map<'hir> {
|
||||||
Node::ImplItem(impl_item) => impl_item.span,
|
Node::ImplItem(impl_item) => impl_item.span,
|
||||||
Node::Variant(variant) => variant.span,
|
Node::Variant(variant) => variant.span,
|
||||||
Node::Field(field) => field.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::ConstBlock(constant) => self.body(constant.body).value.span,
|
||||||
Node::Expr(expr) => expr.span,
|
Node::Expr(expr) => expr.span,
|
||||||
Node::ExprField(field) => field.span,
|
Node::ExprField(field) => field.span,
|
||||||
|
|
|
@ -566,7 +566,8 @@ fn construct_const<'a, 'tcx>(
|
||||||
span,
|
span,
|
||||||
..
|
..
|
||||||
}) => (*span, ty.span),
|
}) => (*span, ty.span),
|
||||||
Node::AnonConst(_) | Node::ConstBlock(_) => {
|
Node::AnonConst(ct) => (ct.span, ct.span),
|
||||||
|
Node::ConstBlock(_) => {
|
||||||
let span = tcx.def_span(def);
|
let span = tcx.def_span(def);
|
||||||
(span, span)
|
(span, span)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue