Skip to content

Commit e7ac2ea

Browse files
committed
Deduplicate logic
1 parent 7175da5 commit e7ac2ea

File tree

1 file changed

+8
-14
lines changed
  • compiler/rustc_const_eval/src/check_consts

1 file changed

+8
-14
lines changed

compiler/rustc_const_eval/src/check_consts/check.rs

+8-14
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,12 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
464464
err_span,
465465
);
466466
}
467+
468+
fn crate_inject_span(&self) -> Option<Span> {
469+
self.tcx.hir_crate_items(()).definitions().next().and_then(|id| {
470+
self.tcx.crate_level_attribute_injection_span(self.tcx.local_def_id_to_hir_id(id))
471+
})
472+
}
467473
}
468474

469475
impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
@@ -819,17 +825,11 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
819825
feature,
820826
..
821827
}) => {
822-
let suggestion =
823-
tcx.hir_crate_items(()).definitions().next().and_then(|id| {
824-
tcx.crate_level_attribute_injection_span(
825-
tcx.local_def_id_to_hir_id(id),
826-
)
827-
});
828828
self.check_op(ops::IntrinsicUnstable {
829829
name: intrinsic.name,
830830
feature,
831831
const_stable_indirect: is_const_stable,
832-
suggestion,
832+
suggestion: self.crate_inject_span(),
833833
});
834834
}
835835
Some(ConstStability { level: StabilityLevel::Stable { .. }, .. }) => {
@@ -923,18 +923,12 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
923923
// Even if the feature is enabled, we still need check_op to double-check
924924
// this if the callee is not safe to expose on stable.
925925
if !feature_enabled || !callee_safe_to_expose_on_stable {
926-
let suggestion_span =
927-
tcx.hir_crate_items(()).definitions().next().and_then(|id| {
928-
tcx.crate_level_attribute_injection_span(
929-
tcx.local_def_id_to_hir_id(id),
930-
)
931-
});
932926
self.check_op(ops::FnCallUnstable {
933927
def_id: callee,
934928
feature,
935929
feature_enabled,
936930
safe_to_expose_on_stable: callee_safe_to_expose_on_stable,
937-
suggestion_span,
931+
suggestion_span: self.crate_inject_span(),
938932
});
939933
}
940934
}

0 commit comments

Comments
 (0)