Skip to content

Commit 4aabb46

Browse files
committed
Avoid various uses of Option<Span> in favor of using DUMMY_SP in the few cases that used None
1 parent f24f055 commit 4aabb46

File tree

28 files changed

+57
-64
lines changed

28 files changed

+57
-64
lines changed

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 constants before codegen began, so if we got here there
2525
// 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 not captured by required_consts")
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
@@ -796,7 +796,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
796796
for &const_ in &body.required_consts {
797797
let c = self
798798
.instantiate_from_current_frame_and_normalize_erasing_regions(const_.const_)?;
799-
c.eval(*self.tcx, self.param_env, Some(const_.span)).map_err(|err| {
799+
c.eval(*self.tcx, self.param_env, const_.span).map_err(|err| {
800800
err.emit_note(*self.tcx);
801801
err
802802
})?;
@@ -1144,7 +1144,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
11441144
pub fn eval_mir_constant(
11451145
&self,
11461146
val: &mir::Const<'tcx>,
1147-
span: Option<Span>,
1147+
span: Span,
11481148
layout: Option<TyAndLayout<'tcx>>,
11491149
) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> {
11501150
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
@@ -544,15 +544,15 @@ pub trait Machine<'mir, 'tcx: 'mir>: Sized {
544544
fn eval_mir_constant<F>(
545545
ecx: &InterpCx<'mir, 'tcx, Self>,
546546
val: mir::Const<'tcx>,
547-
span: Option<Span>,
547+
span: Span,
548548
layout: Option<TyAndLayout<'tcx>>,
549549
eval: F,
550550
) -> InterpResult<'tcx, OpTy<'tcx, Self::Provenance>>
551551
where
552552
F: Fn(
553553
&InterpCx<'mir, 'tcx, Self>,
554554
mir::Const<'tcx>,
555-
Option<Span>,
555+
Span,
556556
Option<TyAndLayout<'tcx>>,
557557
) -> InterpResult<'tcx, OpTy<'tcx, Self::Provenance>>,
558558
{

compiler/rustc_const_eval/src/interpret/operand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
740740
// * During ConstProp, with `TooGeneric` or since the `required_consts` were not all
741741
// checked yet.
742742
// * During CTFE, since promoteds in `const`/`static` initializer bodies can fail.
743-
self.eval_mir_constant(&c, Some(constant.span), layout)?
743+
self.eval_mir_constant(&c, constant.span, layout)?
744744
}
745745
};
746746
trace!("{:?}: {:?}", mir_op, op);

compiler/rustc_hir_typeck/src/pat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2169,7 +2169,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
21692169
len: ty::Const<'tcx>,
21702170
min_len: u64,
21712171
) -> (Option<Ty<'tcx>>, Ty<'tcx>) {
2172-
let len = match len.eval(self.tcx, self.param_env, None) {
2172+
let len = match len.eval(self.tcx, self.param_env, span) {
21732173
Ok(val) => val
21742174
.try_to_scalar()
21752175
.and_then(|scalar| scalar.try_to_int().ok())

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,7 +1475,7 @@ impl<'tcx> InferCtxt<'tcx> {
14751475
param_env: ty::ParamEnv<'tcx>,
14761476
unevaluated: ty::UnevaluatedConst<'tcx>,
14771477
ty: Ty<'tcx>,
1478-
span: Option<Span>,
1478+
span: Span,
14791479
) -> Result<ty::Const<'tcx>, ErrorHandled> {
14801480
match self.const_eval_resolve(param_env, unevaluated, span) {
14811481
Ok(Some(val)) => Ok(ty::Const::new_value(self.tcx, val, ty)),
@@ -1509,7 +1509,7 @@ impl<'tcx> InferCtxt<'tcx> {
15091509
&self,
15101510
mut param_env: ty::ParamEnv<'tcx>,
15111511
unevaluated: ty::UnevaluatedConst<'tcx>,
1512-
span: Option<Span>,
1512+
span: Span,
15131513
) -> EvalToValTreeResult<'tcx> {
15141514
let mut args = self.resolve_vars_if_possible(unevaluated.args);
15151515
debug!(?args);
@@ -1521,12 +1521,9 @@ impl<'tcx> InferCtxt<'tcx> {
15211521
if let Some(ct) = tcx.thir_abstract_const(unevaluated.def)? {
15221522
let ct = tcx.expand_abstract_consts(ct.instantiate(tcx, args));
15231523
if let Err(e) = ct.error_reported() {
1524-
return Err(ErrorHandled::Reported(
1525-
e.into(),
1526-
span.unwrap_or(rustc_span::DUMMY_SP),
1527-
));
1524+
return Err(ErrorHandled::Reported(e.into(), span));
15281525
} else if ct.has_non_region_infer() || ct.has_non_region_param() {
1529-
return Err(ErrorHandled::TooGeneric(span.unwrap_or(rustc_span::DUMMY_SP)));
1526+
return Err(ErrorHandled::TooGeneric(span));
15301527
} else {
15311528
args = replace_param_and_infer_args_with_placeholder(tcx, args);
15321529
}

0 commit comments

Comments
 (0)