Skip to content

Replace some Option<Span> with Span and use DUMMY_SP instead of None #142012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
span: Span,
args: Option<&'hir hir::GenericArgs<'hir>>,
) -> &'hir hir::Path<'hir> {
let def_id = self.tcx.require_lang_item(lang_item, Some(span));
let def_id = self.tcx.require_lang_item(lang_item, span);
let def_kind = self.tcx.def_kind(def_id);
let res = Res::Def(def_kind, def_id);
self.arena.alloc(hir::Path {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
// something that already has `Fn`-like bounds (or is a closure), so we can't
// restrict anyways.
} else {
let copy_did = self.infcx.tcx.require_lang_item(LangItem::Copy, Some(span));
let copy_did = self.infcx.tcx.require_lang_item(LangItem::Copy, span);
self.suggest_adding_bounds(&mut err, ty, copy_did, span);
}

Expand Down Expand Up @@ -1915,7 +1915,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {

let local_ty = self.body.local_decls[place.local].ty;
let typeck_results = tcx.typeck(self.mir_def_id());
let clone = tcx.require_lang_item(LangItem::Clone, Some(body.span));
let clone = tcx.require_lang_item(LangItem::Clone, body.span);
for expr in expr_finder.clones {
if let hir::ExprKind::MethodCall(_, rcvr, _, span) = expr.kind
&& let Some(rcvr_ty) = typeck_results.node_type_opt(rcvr.hir_id)
Expand Down
22 changes: 8 additions & 14 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
if !self.unsized_feature_enabled() {
let trait_ref = ty::TraitRef::new(
tcx,
tcx.require_lang_item(LangItem::Sized, Some(self.last_span)),
tcx.require_lang_item(LangItem::Sized, self.last_span),
[place_ty],
);
self.prove_trait_ref(
Expand Down Expand Up @@ -1010,7 +1010,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
let ty = place.ty(self.body, tcx).ty;
let trait_ref = ty::TraitRef::new(
tcx,
tcx.require_lang_item(LangItem::Copy, Some(span)),
tcx.require_lang_item(LangItem::Copy, span),
[ty],
);

Expand All @@ -1025,11 +1025,8 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
}

&Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, ty) => {
let trait_ref = ty::TraitRef::new(
tcx,
tcx.require_lang_item(LangItem::Sized, Some(span)),
[ty],
);
let trait_ref =
ty::TraitRef::new(tcx, tcx.require_lang_item(LangItem::Sized, span), [ty]);

self.prove_trait_ref(
trait_ref,
Expand All @@ -1041,11 +1038,8 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
&Rvalue::NullaryOp(NullOp::UbChecks, _) => {}

Rvalue::ShallowInitBox(_operand, ty) => {
let trait_ref = ty::TraitRef::new(
tcx,
tcx.require_lang_item(LangItem::Sized, Some(span)),
[*ty],
);
let trait_ref =
ty::TraitRef::new(tcx, tcx.require_lang_item(LangItem::Sized, span), [*ty]);

self.prove_trait_ref(
trait_ref,
Expand Down Expand Up @@ -1222,7 +1216,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
let &ty = ty;
let trait_ref = ty::TraitRef::new(
tcx,
tcx.require_lang_item(LangItem::CoerceUnsized, Some(span)),
tcx.require_lang_item(LangItem::CoerceUnsized, span),
[op.ty(self.body, tcx), ty],
);

Expand Down Expand Up @@ -1811,7 +1805,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
if let PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) = context {
let trait_ref = ty::TraitRef::new(
tcx,
tcx.require_lang_item(LangItem::Copy, Some(self.last_span)),
tcx.require_lang_item(LangItem::Copy, self.last_span),
[place_ty.ty],
);

Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_borrowck/src/universal_regions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,10 +544,10 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
// (as it's created inside the body itself, not passed in from outside).
if let DefiningTy::FnDef(def_id, _) = defining_ty {
if self.infcx.tcx.fn_sig(def_id).skip_binder().c_variadic() {
let va_list_did = self.infcx.tcx.require_lang_item(
LangItem::VaList,
Some(self.infcx.tcx.def_span(self.mir_def)),
);
let va_list_did = self
.infcx
.tcx
.require_lang_item(LangItem::VaList, self.infcx.tcx.def_span(self.mir_def));

let reg_vid = self
.infcx
Expand Down
16 changes: 8 additions & 8 deletions compiler/rustc_codegen_cranelift/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
rustc_hir::LangItem::PanicBoundsCheck,
&[index, len, location],
*unwind,
Some(source_info.span),
source_info.span,
);
}
AssertKind::MisalignedPointerDereference { ref required, ref found } => {
Expand All @@ -393,7 +393,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
rustc_hir::LangItem::PanicMisalignedPointerDereference,
&[required, found, location],
*unwind,
Some(source_info.span),
source_info.span,
);
}
AssertKind::NullPointerDereference => {
Expand All @@ -404,7 +404,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
rustc_hir::LangItem::PanicNullPointerDereference,
&[location],
*unwind,
Some(source_info.span),
source_info.span,
)
}
_ => {
Expand All @@ -415,7 +415,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
msg.panic_function(),
&[location],
*unwind,
Some(source_info.span),
source_info.span,
);
}
}
Expand Down Expand Up @@ -531,7 +531,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
);
}
TerminatorKind::UnwindTerminate(reason) => {
codegen_unwind_terminate(fx, Some(source_info.span), *reason);
codegen_unwind_terminate(fx, source_info.span, *reason);
}
TerminatorKind::UnwindResume => {
// FIXME implement unwinding
Expand Down Expand Up @@ -1074,7 +1074,7 @@ pub(crate) fn codegen_operand<'tcx>(
pub(crate) fn codegen_panic_nounwind<'tcx>(
fx: &mut FunctionCx<'_, '_, 'tcx>,
msg_str: &str,
span: Option<Span>,
span: Span,
) {
let msg_ptr = fx.anonymous_str(msg_str);
let msg_len = fx.bcx.ins().iconst(fx.pointer_type, i64::try_from(msg_str.len()).unwrap());
Expand All @@ -1091,7 +1091,7 @@ pub(crate) fn codegen_panic_nounwind<'tcx>(

pub(crate) fn codegen_unwind_terminate<'tcx>(
fx: &mut FunctionCx<'_, '_, 'tcx>,
span: Option<Span>,
span: Span,
reason: UnwindTerminateReason,
) {
codegen_panic_inner(fx, reason.lang_item(), &[], UnwindAction::Unreachable, span);
Expand All @@ -1102,7 +1102,7 @@ fn codegen_panic_inner<'tcx>(
lang_item: rustc_hir::LangItem,
args: &[Value],
_unwind: UnwindAction,
span: Option<Span>,
span: Span,
) {
fx.bcx.set_cold_block(fx.bcx.current_block().unwrap());

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/intrinsics/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub(crate) fn codegen_llvm_intrinsic_call<'tcx>(
See https://github.com/rust-lang/rustc_codegen_cranelift/issues/171\n\
Please open an issue at https://github.com/rust-lang/rustc_codegen_cranelift/issues"
);
crate::base::codegen_panic_nounwind(fx, &msg, None);
crate::base::codegen_panic_nounwind(fx, &msg, span);
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ pub(super) fn codegen_aarch64_llvm_intrinsic_call<'tcx>(
See https://github.com/rust-lang/rustc_codegen_cranelift/issues/171\n\
Please open an issue at https://github.com/rust-lang/rustc_codegen_cranelift/issues"
);
crate::base::codegen_panic_nounwind(fx, &msg, None);
crate::base::codegen_panic_nounwind(fx, &msg, fx.mir.span);
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,7 @@ pub(super) fn codegen_x86_llvm_intrinsic_call<'tcx>(
See https://github.com/rust-lang/rustc_codegen_cranelift/issues/171\n\
Please open an issue at https://github.com/rust-lang/rustc_codegen_cranelift/issues"
);
crate::base::codegen_panic_nounwind(fx, &msg, None);
crate::base::codegen_panic_nounwind(fx, &msg, span);
return;
}
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
}
})
});
crate::base::codegen_panic_nounwind(fx, &msg_str, Some(source_info.span));
crate::base::codegen_panic_nounwind(fx, &msg_str, source_info.span);
return Ok(());
}
}
Expand Down Expand Up @@ -884,7 +884,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
crate::base::codegen_panic_nounwind(
fx,
"128bit atomics not yet supported",
None,
source_info.span,
);
return Ok(());
} else {
Expand Down Expand Up @@ -919,7 +919,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
crate::base::codegen_panic_nounwind(
fx,
"128bit atomics not yet supported",
None,
source_info.span,
);
return Ok(());
} else {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_cranelift/src/main_shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub(crate) fn maybe_create_entry_wrapper(
let call_inst = bcx.ins().call(main_func_ref, &[]);
let call_results = bcx.func.dfg.inst_results(call_inst).to_owned();

let termination_trait = tcx.require_lang_item(LangItem::Termination, None);
let termination_trait = tcx.require_lang_item(LangItem::Termination, DUMMY_SP);
let report = tcx
.associated_items(termination_trait)
.find_by_ident_and_kind(
Expand Down Expand Up @@ -136,7 +136,7 @@ pub(crate) fn maybe_create_entry_wrapper(
}
} else {
// Regular main fn invoked via start lang item.
let start_def_id = tcx.require_lang_item(LangItem::Start, None);
let start_def_id = tcx.require_lang_item(LangItem::Start, DUMMY_SP);
let start_instance = Instance::expect_resolve(
tcx,
ty::TypingEnv::fully_monomorphized(),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn codegen_three_way_compare<'tcx>(
let gt = fx.bcx.ins().icmp(gt_cc, lhs, rhs);
let lt = fx.bcx.ins().icmp(lt_cc, lhs, rhs);
let val = fx.bcx.ins().isub(gt, lt);
CValue::by_val(val, fx.layout_of(fx.tcx.ty_ordering_enum(Some(fx.mir.span))))
CValue::by_val(val, fx.layout_of(fx.tcx.ty_ordering_enum(fx.mir.span)))
}

fn codegen_compare_bin_op<'tcx>(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/unsize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ pub(crate) fn size_and_align_of<'tcx>(
})
});

codegen_panic_nounwind(fx, &msg_str, None);
codegen_panic_nounwind(fx, &msg_str, fx.mir.span);

fx.bcx.switch_to_block(next_block);

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(

let EntryFnType::Main { sigpipe } = entry_type;
let (start_fn, start_ty, args, instance) = {
let start_def_id = cx.tcx().require_lang_item(LangItem::Start, None);
let start_def_id = cx.tcx().require_lang_item(LangItem::Start, DUMMY_SP);
let start_instance = ty::Instance::expect_resolve(
cx.tcx(),
cx.typing_env(),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ mod temp_stable_hash_impls {

pub(crate) fn build_langcall<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
bx: &Bx,
span: Option<Span>,
span: Span,
li: LangItem,
) -> (Bx::FnAbiOfResult, Bx::Value, Instance<'tcx>) {
let tcx = bx.tcx();
Expand Down
9 changes: 5 additions & 4 deletions compiler/rustc_codegen_ssa/src/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
}
};

let (fn_abi, llfn, instance) = common::build_langcall(bx, Some(span), lang_item);
let (fn_abi, llfn, instance) = common::build_langcall(bx, span, lang_item);

// Codegen the actual panic invoke/call.
let merging_succ =
Expand All @@ -803,7 +803,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
self.set_debug_loc(bx, terminator.source_info);

// Obtain the panic entry point.
let (fn_abi, llfn, instance) = common::build_langcall(bx, Some(span), reason.lang_item());
let (fn_abi, llfn, instance) = common::build_langcall(bx, span, reason.lang_item());

// Codegen the actual panic invoke/call.
let merging_succ = helper.do_call(
Expand Down Expand Up @@ -871,7 +871,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {

// Obtain the panic entry point.
let (fn_abi, llfn, instance) =
common::build_langcall(bx, Some(source_info.span), LangItem::PanicNounwind);
common::build_langcall(bx, source_info.span, LangItem::PanicNounwind);

// Codegen the actual panic invoke/call.
Some(helper.do_call(
Expand Down Expand Up @@ -1830,7 +1830,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {

self.set_debug_loc(&mut bx, mir::SourceInfo::outermost(self.mir.span));

let (fn_abi, fn_ptr, instance) = common::build_langcall(&bx, None, reason.lang_item());
let (fn_abi, fn_ptr, instance) =
common::build_langcall(&bx, self.mir.span, reason.lang_item());
if is_call_from_compiler_builtins_to_upstream_monomorphization(bx.tcx(), instance) {
bx.abort();
} else {
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_codegen_ssa/src/size_of_val.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use rustc_hir::LangItem;
use rustc_middle::bug;
use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
use rustc_middle::ty::{self, Ty};
use rustc_span::DUMMY_SP;
use tracing::{debug, trace};

use crate::common::IntPredicate;
Expand Down Expand Up @@ -62,7 +63,7 @@ pub fn size_and_align_of_dst<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(

// Obtain the panic entry point.
let (fn_abi, llfn, _instance) =
common::build_langcall(bx, None, LangItem::PanicNounwind);
common::build_langcall(bx, DUMMY_SP, LangItem::PanicNounwind);

// Generate the call. Cannot use `do_call` since we don't have a MIR terminator so we
// can't create a `TerminationCodegenHelper`. (But we are in good company, this code is
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_const_eval/src/check_consts/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,7 @@ fn build_error_for_const_call<'tcx>(
non_or_conditionally,
});

note_trait_if_possible(
&mut err,
self_ty,
tcx.require_lang_item(LangItem::Deref, Some(span)),
);
note_trait_if_possible(&mut err, self_ty, tcx.require_lang_item(LangItem::Deref, span));
err
}
_ if tcx.opt_parent(callee) == tcx.get_diagnostic_item(sym::FmtArgumentsNew) => {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_const_eval/src/check_consts/qualifs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl Qualif for HasMutInterior {
// requires borrowck, which in turn will invoke mir_const_qualifs again, causing a cycle error.
// Instead we invoke an obligation context manually, and provide the opaque type inference settings
// that allow the trait solver to just error out instead of cycling.
let freeze_def_id = cx.tcx.require_lang_item(LangItem::Freeze, Some(cx.body.span));
let freeze_def_id = cx.tcx.require_lang_item(LangItem::Freeze, cx.body.span);
// FIXME(#132279): Once we've got a typing mode which reveals opaque types using the HIR
// typeck results without causing query cycles, we should use this here instead of defining
// opaque types.
Expand Down Expand Up @@ -180,7 +180,7 @@ impl Qualif for NeedsNonConstDrop {
// that the components of this type are also `~const Destruct`. This
// amounts to verifying that there are no values in this ADT that may have
// a non-const drop.
let destruct_def_id = cx.tcx.require_lang_item(LangItem::Destruct, Some(cx.body.span));
let destruct_def_id = cx.tcx.require_lang_item(LangItem::Destruct, cx.body.span);
let (infcx, param_env) = cx.tcx.infer_ctxt().build_with_typing_env(cx.typing_env);
let ocx = ObligationCtxt::new(&infcx);
ocx.register_obligation(Obligation::new(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/const_eval/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ impl<'tcx> CompileTimeInterpCx<'tcx> {
return Err(ConstEvalErrKind::Panic { msg, file, line, col }).into();
} else if self.tcx.is_lang_item(def_id, LangItem::PanicFmt) {
// For panic_fmt, call const_panic_fmt instead.
let const_def_id = self.tcx.require_lang_item(LangItem::ConstPanicFmt, None);
let const_def_id = self.tcx.require_lang_item(LangItem::ConstPanicFmt, self.tcx.span);
let new_instance = ty::Instance::expect_resolve(
*self.tcx,
self.typing_env(),
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_const_eval/src/interpret/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use rustc_middle::ty::layout::{HasTyCtxt, HasTypingEnv, LayoutOf, TyAndLayout};
use rustc_middle::ty::print::{FmtPrinter, PrettyPrinter};
use rustc_middle::ty::{ConstInt, ScalarInt, Ty, TyCtxt};
use rustc_middle::{bug, mir, span_bug, ty};
use rustc_span::DUMMY_SP;
use tracing::trace;

use super::{
Expand Down Expand Up @@ -307,7 +308,7 @@ impl<'tcx, Prov: Provenance> ImmTy<'tcx, Prov> {
#[inline]
pub fn from_ordering(c: std::cmp::Ordering, tcx: TyCtxt<'tcx>) -> Self {
// Can use any typing env, since `Ordering` is always monomorphic.
let ty = tcx.ty_ordering_enum(None);
let ty = tcx.ty_ordering_enum(DUMMY_SP);
let layout =
tcx.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(ty)).unwrap();
Self::from_scalar(Scalar::Int(c.into()), layout)
Expand Down
Loading
Loading