Skip to content

Commit fea1fe7

Browse files
committed
Avoid some def_span query calls
1 parent 9070419 commit fea1fe7

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

compiler/rustc_hir_analysis/src/collect/type_of.rs

+9-13
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
2424
let hir_id = tcx.local_def_id_to_hir_id(def_id);
2525

2626
let node = tcx.hir_node(hir_id);
27-
let Node::AnonConst(_) = node else {
27+
let Node::AnonConst(&AnonConst { span, .. }) = node else {
2828
span_bug!(
2929
tcx.def_span(def_id),
3030
"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> {
134134
// I dont think it's possible to reach this but I'm not 100% sure - BoxyUwU
135135
return Ty::new_error_with_message(
136136
tcx,
137-
tcx.def_span(def_id),
137+
span,
138138
"unexpected non-GAT usage of an anon const",
139139
);
140140
}
@@ -152,7 +152,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
152152
let Some(type_dependent_def) = tables.type_dependent_def_id(parent_node_id) else {
153153
return Ty::new_error_with_message(
154154
tcx,
155-
tcx.def_span(def_id),
155+
span,
156156
format!("unable to find type-dependent def for {parent_node_id:?}"),
157157
);
158158
};
@@ -194,15 +194,15 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
194194
} else {
195195
return Ty::new_error_with_message(
196196
tcx,
197-
tcx.def_span(def_id),
197+
span,
198198
format!("unable to find const parent for {hir_id} in pat {pat:?}"),
199199
);
200200
}
201201
}
202202
_ => {
203203
return Ty::new_error_with_message(
204204
tcx,
205-
tcx.def_span(def_id),
205+
span,
206206
format!("unexpected const parent path {parent_node:?}"),
207207
);
208208
}
@@ -226,19 +226,15 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
226226
.map(|idx| (idx, seg))
227227
})
228228
}) else {
229-
return Ty::new_error_with_message(
230-
tcx,
231-
tcx.def_span(def_id),
232-
"no arg matching AnonConst in path",
233-
);
229+
return Ty::new_error_with_message(tcx, span, "no arg matching AnonConst in path");
234230
};
235231

236232
let generics = match tcx.res_generics_def_id(segment.res) {
237233
Some(def_id) => tcx.generics_of(def_id),
238234
None => {
239235
return Ty::new_error_with_message(
240236
tcx,
241-
tcx.def_span(def_id),
237+
span,
242238
format!("unexpected anon const res {:?} in path: {:?}", segment.res, path),
243239
);
244240
}
@@ -250,7 +246,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
250246
_ => {
251247
return Ty::new_error_with_message(
252248
tcx,
253-
tcx.def_span(def_id),
249+
span,
254250
format!("unexpected const parent in type_of(): {parent_node:?}"),
255251
);
256252
}
@@ -278,7 +274,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
278274
} else {
279275
return Ty::new_error_with_message(
280276
tcx,
281-
tcx.def_span(def_id),
277+
span,
282278
format!("const generic parameter not found in {generics:?} at position {arg_idx:?}"),
283279
);
284280
}

compiler/rustc_middle/src/hir/map/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ impl<'hir> Map<'hir> {
885885
Node::ImplItem(impl_item) => impl_item.span,
886886
Node::Variant(variant) => variant.span,
887887
Node::Field(field) => field.span,
888-
Node::AnonConst(constant) => self.body(constant.body).value.span,
888+
Node::AnonConst(constant) => constant.span,
889889
Node::ConstBlock(constant) => self.body(constant.body).value.span,
890890
Node::Expr(expr) => expr.span,
891891
Node::ExprField(field) => field.span,

compiler/rustc_mir_build/src/build/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,8 @@ fn construct_const<'a, 'tcx>(
566566
span,
567567
..
568568
}) => (*span, ty.span),
569-
Node::AnonConst(_) | Node::ConstBlock(_) => {
569+
Node::AnonConst(ct) => (ct.span, ct.span),
570+
Node::ConstBlock(_) => {
570571
let span = tcx.def_span(def);
571572
(span, span)
572573
}

0 commit comments

Comments
 (0)