Skip to content

Commit 6aca2ab

Browse files
authored
Rollup merge of rust-lang#122480 - oli-obk:const-eval-span-no-opt, r=RalfJung
Avoid various uses of `Option<Span>` in favor of using `DUMMY_SP` in the few cases that used `None` based on rust-lang#122471 `DUMMY_SP` is already the sentinel value we have that says "no span". We don't need to wrap these `Span`s in a separate `Option`.
2 parents 6e1b2b1 + adda9da commit 6aca2ab

File tree

34 files changed

+70
-75
lines changed

34 files changed

+70
-75
lines changed

compiler/rustc_codegen_cranelift/src/constant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub(crate) fn eval_mir_constant<'tcx>(
7474
let cv = fx.monomorphize(constant.const_);
7575
// This cannot fail because we checked all required_consts in advance.
7676
let val = cv
77-
.eval(fx.tcx, ty::ParamEnv::reveal_all(), Some(constant.span))
77+
.eval(fx.tcx, ty::ParamEnv::reveal_all(), constant.span)
7878
.expect("erroneous constant missed by mono item collection");
7979
(val, cv.ty())
8080
}

compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,8 +728,10 @@ fn codegen_regular_intrinsic_call<'tcx>(
728728
| sym::variant_count => {
729729
intrinsic_args!(fx, args => (); intrinsic);
730730

731-
let const_val =
732-
fx.tcx.const_eval_instance(ParamEnv::reveal_all(), instance, None).unwrap();
731+
let const_val = fx
732+
.tcx
733+
.const_eval_instance(ParamEnv::reveal_all(), instance, source_info.span)
734+
.unwrap();
733735
let val = crate::constant::codegen_const_value(fx, const_val, ret.layout().ty);
734736
ret.write_cvalue(fx, val);
735737
}

compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
131131

132132
let idx = generic_args[2]
133133
.expect_const()
134-
.eval(fx.tcx, ty::ParamEnv::reveal_all(), Some(span))
134+
.eval(fx.tcx, ty::ParamEnv::reveal_all(), span)
135135
.unwrap()
136136
.unwrap_branch();
137137

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
11291129
if name == sym::simd_shuffle_generic {
11301130
let idx = fn_args[2]
11311131
.expect_const()
1132-
.eval(tcx, ty::ParamEnv::reveal_all(), Some(span))
1132+
.eval(tcx, ty::ParamEnv::reveal_all(), span)
11331133
.unwrap()
11341134
.unwrap_branch();
11351135
let n = idx.len() as u64;

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use rustc_hir::{CoroutineDesugaring, CoroutineKind, CoroutineSource, Mutability}
1919
use rustc_middle::ty::layout::{IntegerExt, TyAndLayout};
2020
use rustc_middle::ty::{self, ExistentialProjection, ParamEnv, Ty, TyCtxt};
2121
use rustc_middle::ty::{GenericArgKind, GenericArgsRef};
22+
use rustc_span::DUMMY_SP;
2223
use rustc_target::abi::Integer;
2324
use smallvec::SmallVec;
2425

@@ -704,7 +705,7 @@ fn push_const_param<'tcx>(tcx: TyCtxt<'tcx>, ct: ty::Const<'tcx>, output: &mut S
704705
// avoiding collisions and will make the emitted type names shorter.
705706
let hash_short = tcx.with_stable_hashing_context(|mut hcx| {
706707
let mut hasher = StableHasher::new();
707-
let ct = ct.eval(tcx, ty::ParamEnv::reveal_all(), None).unwrap();
708+
let ct = ct.eval(tcx, ty::ParamEnv::reveal_all(), DUMMY_SP).unwrap();
708709
hcx.while_hashing_spans(false, |hcx| ct.hash_stable(hcx, &mut hasher));
709710
hasher.finish::<Hash64>()
710711
});

compiler/rustc_codegen_ssa/src/mir/constant.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
2424
// `MirUsedCollector` visited all required_consts before codegen began, so if we got here
2525
// there can be no more constants that fail to evaluate.
2626
self.monomorphize(constant.const_)
27-
.eval(self.cx.tcx(), ty::ParamEnv::reveal_all(), Some(constant.span))
27+
.eval(self.cx.tcx(), ty::ParamEnv::reveal_all(), constant.span)
2828
.expect("erroneous constant missed by mono item collection")
2929
}
3030

@@ -56,11 +56,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
5656
other => span_bug!(constant.span, "{other:#?}"),
5757
};
5858
let uv = self.monomorphize(uv);
59-
self.cx.tcx().const_eval_resolve_for_typeck(
60-
ty::ParamEnv::reveal_all(),
61-
uv,
62-
Some(constant.span),
63-
)
59+
self.cx.tcx().const_eval_resolve_for_typeck(ty::ParamEnv::reveal_all(), uv, constant.span)
6460
}
6561

6662
/// process constant containing SIMD shuffle indices

compiler/rustc_codegen_ssa/src/mir/intrinsic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
130130
| sym::variant_count => {
131131
let value = bx
132132
.tcx()
133-
.const_eval_instance(ty::ParamEnv::reveal_all(), instance, None)
133+
.const_eval_instance(ty::ParamEnv::reveal_all(), instance, span)
134134
.unwrap();
135135
OperandRef::from_const(bx, value, ret_ty).immediate_or_packed_pair(bx)
136136
}

compiler/rustc_const_eval/src/interpret/eval_context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
826826
for &const_ in &body.required_consts {
827827
let c = self
828828
.instantiate_from_current_frame_and_normalize_erasing_regions(const_.const_)?;
829-
c.eval(*self.tcx, self.param_env, Some(const_.span)).map_err(|err| {
829+
c.eval(*self.tcx, self.param_env, const_.span).map_err(|err| {
830830
err.emit_note(*self.tcx);
831831
err
832832
})?;
@@ -1174,7 +1174,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
11741174
pub fn eval_mir_constant(
11751175
&self,
11761176
val: &mir::Const<'tcx>,
1177-
span: Option<Span>,
1177+
span: Span,
11781178
layout: Option<TyAndLayout<'tcx>>,
11791179
) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> {
11801180
M::eval_mir_constant(self, *val, span, layout, |ecx, val, span, layout| {

compiler/rustc_const_eval/src/interpret/intrinsics.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
153153
sym::type_name => Ty::new_static_str(self.tcx.tcx),
154154
_ => bug!(),
155155
};
156-
let val = self.ctfe_query(|tcx| {
157-
tcx.const_eval_global_id(self.param_env, gid, Some(tcx.span))
158-
})?;
156+
let val =
157+
self.ctfe_query(|tcx| tcx.const_eval_global_id(self.param_env, gid, tcx.span))?;
159158
let val = self.const_val_to_op(val, ty, Some(dest.layout))?;
160159
self.copy_op(&val, dest)?;
161160
}

compiler/rustc_const_eval/src/interpret/machine.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,15 +525,15 @@ pub trait Machine<'mir, 'tcx: 'mir>: Sized {
525525
fn eval_mir_constant<F>(
526526
ecx: &InterpCx<'mir, 'tcx, Self>,
527527
val: mir::Const<'tcx>,
528-
span: Option<Span>,
528+
span: Span,
529529
layout: Option<TyAndLayout<'tcx>>,
530530
eval: F,
531531
) -> InterpResult<'tcx, OpTy<'tcx, Self::Provenance>>
532532
where
533533
F: Fn(
534534
&InterpCx<'mir, 'tcx, Self>,
535535
mir::Const<'tcx>,
536-
Option<Span>,
536+
Span,
537537
Option<TyAndLayout<'tcx>>,
538538
) -> InterpResult<'tcx, OpTy<'tcx, Self::Provenance>>,
539539
{

0 commit comments

Comments
 (0)