Rollup merge of #142012 - oli-obk:no-optional-spans, r=fee1-dead
Replace some `Option<Span>` with `Span` and use DUMMY_SP instead of None Turns out many locations actually have a span available that we could use, so I used it
This commit is contained in:
@@ -73,7 +73,7 @@ use rustc_middle::ty::{
|
||||
TypeVisitableExt,
|
||||
};
|
||||
use rustc_span::def_id::LOCAL_CRATE;
|
||||
use rustc_span::{BytePos, DesugaringKind, Pos, Span, sym};
|
||||
use rustc_span::{BytePos, DUMMY_SP, DesugaringKind, Pos, Span, sym};
|
||||
use tracing::{debug, instrument};
|
||||
|
||||
use crate::error_reporting::TypeErrCtxt;
|
||||
@@ -194,7 +194,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||
_ => return None,
|
||||
};
|
||||
|
||||
let future_trait = self.tcx.require_lang_item(LangItem::Future, None);
|
||||
let future_trait = self.tcx.require_lang_item(LangItem::Future, DUMMY_SP);
|
||||
let item_def_id = self.tcx.associated_item_def_ids(future_trait)[0];
|
||||
|
||||
self.tcx
|
||||
|
||||
@@ -6,7 +6,7 @@ use rustc_hir::def::DefKind;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::{LangItem, lang_items};
|
||||
use rustc_middle::ty::{AssocItemContainer, GenericArgsRef, Instance, Ty, TyCtxt, TypingEnv};
|
||||
use rustc_span::{DesugaringKind, Ident, Span, sym};
|
||||
use rustc_span::{DUMMY_SP, DesugaringKind, Ident, Span, sym};
|
||||
use tracing::debug;
|
||||
|
||||
use crate::traits::specialization_graph;
|
||||
@@ -31,9 +31,9 @@ impl CallDesugaringKind {
|
||||
pub fn trait_def_id(self, tcx: TyCtxt<'_>) -> DefId {
|
||||
match self {
|
||||
Self::ForLoopIntoIter => tcx.get_diagnostic_item(sym::IntoIterator).unwrap(),
|
||||
Self::ForLoopNext => tcx.require_lang_item(LangItem::Iterator, None),
|
||||
Self::ForLoopNext => tcx.require_lang_item(LangItem::Iterator, DUMMY_SP),
|
||||
Self::QuestionBranch | Self::TryBlockFromOutput => {
|
||||
tcx.require_lang_item(LangItem::Try, None)
|
||||
tcx.require_lang_item(LangItem::Try, DUMMY_SP)
|
||||
}
|
||||
Self::QuestionFromResidual => tcx.get_diagnostic_item(sym::FromResidual).unwrap(),
|
||||
Self::Await => tcx.get_diagnostic_item(sym::IntoFuture).unwrap(),
|
||||
|
||||
@@ -955,7 +955,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||
return false;
|
||||
};
|
||||
|
||||
let clone_trait = self.tcx.require_lang_item(LangItem::Clone, None);
|
||||
let clone_trait = self.tcx.require_lang_item(LangItem::Clone, obligation.cause.span);
|
||||
let has_clone = |ty| {
|
||||
self.type_implements_trait(clone_trait, [ty], obligation.param_env)
|
||||
.must_apply_modulo_regions()
|
||||
@@ -3625,7 +3625,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||
span: Span,
|
||||
) {
|
||||
let future_trait = self.tcx.require_lang_item(LangItem::Future, None);
|
||||
let future_trait = self.tcx.require_lang_item(LangItem::Future, span);
|
||||
|
||||
let self_ty = self.resolve_vars_if_possible(trait_pred.self_ty());
|
||||
let impls_future = self.type_implements_trait(
|
||||
@@ -4141,7 +4141,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||
let pred = ty::Binder::dummy(ty::TraitPredicate {
|
||||
trait_ref: ty::TraitRef::new(
|
||||
tcx,
|
||||
tcx.require_lang_item(LangItem::Clone, Some(span)),
|
||||
tcx.require_lang_item(LangItem::Clone, span),
|
||||
[*ty],
|
||||
),
|
||||
polarity: ty::PredicatePolarity::Positive,
|
||||
|
||||
@@ -38,7 +38,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||
return self.tcx.type_is_copy_modulo_regions(self.typing_env(param_env), ty);
|
||||
}
|
||||
|
||||
let copy_def_id = self.tcx.require_lang_item(LangItem::Copy, None);
|
||||
let copy_def_id = self.tcx.require_lang_item(LangItem::Copy, DUMMY_SP);
|
||||
|
||||
// This can get called from typeck (by euv), and `moves_by_default`
|
||||
// rightly refuses to work with inference variables, but
|
||||
@@ -49,7 +49,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||
|
||||
fn type_is_clone_modulo_regions(&self, param_env: ty::ParamEnv<'tcx>, ty: Ty<'tcx>) -> bool {
|
||||
let ty = self.resolve_vars_if_possible(ty);
|
||||
let clone_def_id = self.tcx.require_lang_item(LangItem::Clone, None);
|
||||
let clone_def_id = self.tcx.require_lang_item(LangItem::Clone, DUMMY_SP);
|
||||
traits::type_known_to_meet_bound_modulo_regions(self, param_env, ty, clone_def_id)
|
||||
}
|
||||
|
||||
@@ -59,12 +59,12 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||
ty: Ty<'tcx>,
|
||||
) -> bool {
|
||||
let ty = self.resolve_vars_if_possible(ty);
|
||||
let use_cloned_def_id = self.tcx.require_lang_item(LangItem::UseCloned, None);
|
||||
let use_cloned_def_id = self.tcx.require_lang_item(LangItem::UseCloned, DUMMY_SP);
|
||||
traits::type_known_to_meet_bound_modulo_regions(self, param_env, ty, use_cloned_def_id)
|
||||
}
|
||||
|
||||
fn type_is_sized_modulo_regions(&self, param_env: ty::ParamEnv<'tcx>, ty: Ty<'tcx>) -> bool {
|
||||
let lang_item = self.tcx.require_lang_item(LangItem::Sized, None);
|
||||
let lang_item = self.tcx.require_lang_item(LangItem::Sized, DUMMY_SP);
|
||||
traits::type_known_to_meet_bound_modulo_regions(self, param_env, ty, lang_item)
|
||||
}
|
||||
|
||||
|
||||
@@ -248,7 +248,7 @@ fn evaluate_host_effect_for_destruct_goal<'tcx>(
|
||||
obligation: &HostEffectObligation<'tcx>,
|
||||
) -> Result<ThinVec<PredicateObligation<'tcx>>, EvaluationFailure> {
|
||||
let tcx = selcx.tcx();
|
||||
let destruct_def_id = tcx.require_lang_item(LangItem::Destruct, None);
|
||||
let destruct_def_id = tcx.require_lang_item(LangItem::Destruct, obligation.cause.span);
|
||||
let self_ty = obligation.predicate.self_ty();
|
||||
|
||||
let const_conditions = match *self_ty.kind() {
|
||||
@@ -267,7 +267,7 @@ fn evaluate_host_effect_for_destruct_goal<'tcx>(
|
||||
Some(hir::Constness::NotConst) => return Err(EvaluationFailure::NoSolution),
|
||||
// `Drop` impl exists, and it's const. Require `Ty: ~const Drop` to hold.
|
||||
Some(hir::Constness::Const) => {
|
||||
let drop_def_id = tcx.require_lang_item(LangItem::Drop, None);
|
||||
let drop_def_id = tcx.require_lang_item(LangItem::Drop, obligation.cause.span);
|
||||
let drop_trait_ref = ty::TraitRef::new(tcx, drop_def_id, [self_ty]);
|
||||
const_conditions.push(drop_trait_ref);
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ pub fn type_allowed_to_implement_const_param_ty<'tcx>(
|
||||
parent_cause.clone(),
|
||||
param_env,
|
||||
inner_ty,
|
||||
tcx.require_lang_item(lang_item, Some(parent_cause.span)),
|
||||
tcx.require_lang_item(lang_item, parent_cause.span),
|
||||
);
|
||||
|
||||
let errors = ocx.select_all_or_error();
|
||||
@@ -193,7 +193,7 @@ pub fn all_fields_implement_trait<'tcx>(
|
||||
parent_cause: ObligationCause<'tcx>,
|
||||
lang_item: LangItem,
|
||||
) -> Result<(), Vec<(&'tcx ty::FieldDef, Ty<'tcx>, InfringingFieldsReason<'tcx>)>> {
|
||||
let trait_def_id = tcx.require_lang_item(lang_item, Some(parent_cause.span));
|
||||
let trait_def_id = tcx.require_lang_item(lang_item, parent_cause.span);
|
||||
|
||||
let mut infringing = Vec::new();
|
||||
for variant in adt.variants() {
|
||||
|
||||
@@ -1117,7 +1117,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
|
||||
selcx.tcx(),
|
||||
selcx.tcx().require_lang_item(
|
||||
LangItem::Sized,
|
||||
Some(obligation.cause.span),
|
||||
obligation.cause.span,
|
||||
),
|
||||
[self_ty],
|
||||
),
|
||||
@@ -1317,7 +1317,7 @@ fn confirm_coroutine_candidate<'cx, 'tcx>(
|
||||
|
||||
let tcx = selcx.tcx();
|
||||
|
||||
let coroutine_def_id = tcx.require_lang_item(LangItem::Coroutine, None);
|
||||
let coroutine_def_id = tcx.require_lang_item(LangItem::Coroutine, obligation.cause.span);
|
||||
|
||||
let (trait_ref, yield_ty, return_ty) = super::util::coroutine_trait_ref_and_outputs(
|
||||
tcx,
|
||||
@@ -1375,7 +1375,7 @@ fn confirm_future_candidate<'cx, 'tcx>(
|
||||
debug!(?obligation, ?coroutine_sig, ?obligations, "confirm_future_candidate");
|
||||
|
||||
let tcx = selcx.tcx();
|
||||
let fut_def_id = tcx.require_lang_item(LangItem::Future, None);
|
||||
let fut_def_id = tcx.require_lang_item(LangItem::Future, obligation.cause.span);
|
||||
|
||||
let (trait_ref, return_ty) = super::util::future_trait_ref_and_outputs(
|
||||
tcx,
|
||||
@@ -1421,7 +1421,7 @@ fn confirm_iterator_candidate<'cx, 'tcx>(
|
||||
debug!(?obligation, ?gen_sig, ?obligations, "confirm_iterator_candidate");
|
||||
|
||||
let tcx = selcx.tcx();
|
||||
let iter_def_id = tcx.require_lang_item(LangItem::Iterator, None);
|
||||
let iter_def_id = tcx.require_lang_item(LangItem::Iterator, obligation.cause.span);
|
||||
|
||||
let (trait_ref, yield_ty) = super::util::iterator_trait_ref_and_outputs(
|
||||
tcx,
|
||||
@@ -1467,7 +1467,7 @@ fn confirm_async_iterator_candidate<'cx, 'tcx>(
|
||||
debug!(?obligation, ?gen_sig, ?obligations, "confirm_async_iterator_candidate");
|
||||
|
||||
let tcx = selcx.tcx();
|
||||
let iter_def_id = tcx.require_lang_item(LangItem::AsyncIterator, None);
|
||||
let iter_def_id = tcx.require_lang_item(LangItem::AsyncIterator, obligation.cause.span);
|
||||
|
||||
let (trait_ref, yield_ty) = super::util::async_iterator_trait_ref_and_outputs(
|
||||
tcx,
|
||||
@@ -1511,12 +1511,13 @@ fn confirm_builtin_candidate<'cx, 'tcx>(
|
||||
let trait_def_id = tcx.trait_of_item(item_def_id).unwrap();
|
||||
let args = tcx.mk_args(&[self_ty.into()]);
|
||||
let (term, obligations) = if tcx.is_lang_item(trait_def_id, LangItem::DiscriminantKind) {
|
||||
let discriminant_def_id = tcx.require_lang_item(LangItem::Discriminant, None);
|
||||
let discriminant_def_id =
|
||||
tcx.require_lang_item(LangItem::Discriminant, obligation.cause.span);
|
||||
assert_eq!(discriminant_def_id, item_def_id);
|
||||
|
||||
(self_ty.discriminant_ty(tcx).into(), PredicateObligations::new())
|
||||
} else if tcx.is_lang_item(trait_def_id, LangItem::PointeeTrait) {
|
||||
let metadata_def_id = tcx.require_lang_item(LangItem::Metadata, None);
|
||||
let metadata_def_id = tcx.require_lang_item(LangItem::Metadata, obligation.cause.span);
|
||||
assert_eq!(metadata_def_id, item_def_id);
|
||||
|
||||
let mut obligations = PredicateObligations::new();
|
||||
@@ -1538,7 +1539,7 @@ fn confirm_builtin_candidate<'cx, 'tcx>(
|
||||
// exist. Instead, `Pointee<Metadata = ()>` should be a supertrait of `Sized`.
|
||||
let sized_predicate = ty::TraitRef::new(
|
||||
tcx,
|
||||
tcx.require_lang_item(LangItem::Sized, Some(obligation.cause.span)),
|
||||
tcx.require_lang_item(LangItem::Sized, obligation.cause.span),
|
||||
[self_ty],
|
||||
);
|
||||
obligations.push(obligation.with(tcx, sized_predicate));
|
||||
@@ -1620,7 +1621,7 @@ fn confirm_closure_candidate<'cx, 'tcx>(
|
||||
)
|
||||
} else {
|
||||
let upvars_projection_def_id =
|
||||
tcx.require_lang_item(LangItem::AsyncFnKindUpvars, None);
|
||||
tcx.require_lang_item(LangItem::AsyncFnKindUpvars, obligation.cause.span);
|
||||
let tupled_upvars_ty = Ty::new_projection(
|
||||
tcx,
|
||||
upvars_projection_def_id,
|
||||
@@ -1681,8 +1682,9 @@ fn confirm_callable_candidate<'cx, 'tcx>(
|
||||
|
||||
debug!(?obligation, ?fn_sig, "confirm_callable_candidate");
|
||||
|
||||
let fn_once_def_id = tcx.require_lang_item(LangItem::FnOnce, None);
|
||||
let fn_once_output_def_id = tcx.require_lang_item(LangItem::FnOnceOutput, None);
|
||||
let fn_once_def_id = tcx.require_lang_item(LangItem::FnOnce, obligation.cause.span);
|
||||
let fn_once_output_def_id =
|
||||
tcx.require_lang_item(LangItem::FnOnceOutput, obligation.cause.span);
|
||||
|
||||
let predicate = super::util::closure_trait_ref_and_return_type(
|
||||
tcx,
|
||||
@@ -1740,8 +1742,8 @@ fn confirm_async_closure_candidate<'cx, 'tcx>(
|
||||
args.coroutine_captures_by_ref_ty(),
|
||||
)
|
||||
} else {
|
||||
let upvars_projection_def_id =
|
||||
tcx.require_lang_item(LangItem::AsyncFnKindUpvars, None);
|
||||
let upvars_projection_def_id = tcx
|
||||
.require_lang_item(LangItem::AsyncFnKindUpvars, obligation.cause.span);
|
||||
// When we don't know the closure kind (and therefore also the closure's upvars,
|
||||
// which are computed at the same time), we must delay the computation of the
|
||||
// generator's upvars. We do this using the `AsyncFnKindHelper`, which as a trait
|
||||
@@ -1798,7 +1800,8 @@ fn confirm_async_closure_candidate<'cx, 'tcx>(
|
||||
let term = match item_name {
|
||||
sym::CallOnceFuture | sym::CallRefFuture => sig.output(),
|
||||
sym::Output => {
|
||||
let future_output_def_id = tcx.require_lang_item(LangItem::FutureOutput, None);
|
||||
let future_output_def_id =
|
||||
tcx.require_lang_item(LangItem::FutureOutput, obligation.cause.span);
|
||||
Ty::new_projection(tcx, future_output_def_id, [sig.output()])
|
||||
}
|
||||
name => bug!("no such associated type: {name}"),
|
||||
@@ -1831,7 +1834,8 @@ fn confirm_async_closure_candidate<'cx, 'tcx>(
|
||||
let term = match item_name {
|
||||
sym::CallOnceFuture | sym::CallRefFuture => sig.output(),
|
||||
sym::Output => {
|
||||
let future_output_def_id = tcx.require_lang_item(LangItem::FutureOutput, None);
|
||||
let future_output_def_id =
|
||||
tcx.require_lang_item(LangItem::FutureOutput, obligation.cause.span);
|
||||
Ty::new_projection(tcx, future_output_def_id, [sig.output()])
|
||||
}
|
||||
name => bug!("no such associated type: {name}"),
|
||||
|
||||
@@ -318,7 +318,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
let make_freeze_obl = |ty| {
|
||||
let trait_ref = ty::TraitRef::new(
|
||||
tcx,
|
||||
tcx.require_lang_item(LangItem::Freeze, None),
|
||||
tcx.require_lang_item(LangItem::Freeze, obligation.cause.span),
|
||||
[ty::GenericArg::from(ty)],
|
||||
);
|
||||
Obligation::with_depth(
|
||||
@@ -657,7 +657,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
);
|
||||
let tr = ty::TraitRef::new(
|
||||
self.tcx(),
|
||||
self.tcx().require_lang_item(LangItem::Sized, Some(cause.span)),
|
||||
self.tcx().require_lang_item(LangItem::Sized, cause.span),
|
||||
[output_ty],
|
||||
);
|
||||
nested.push(Obligation::new(self.infcx.tcx, cause, obligation.param_env, tr));
|
||||
@@ -877,14 +877,16 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
});
|
||||
|
||||
// We must additionally check that the return type impls `Future + Sized`.
|
||||
let future_trait_def_id = tcx.require_lang_item(LangItem::Future, None);
|
||||
let future_trait_def_id =
|
||||
tcx.require_lang_item(LangItem::Future, obligation.cause.span);
|
||||
nested.push(obligation.with(
|
||||
tcx,
|
||||
sig.output().map_bound(|output_ty| {
|
||||
ty::TraitRef::new(tcx, future_trait_def_id, [output_ty])
|
||||
}),
|
||||
));
|
||||
let sized_trait_def_id = tcx.require_lang_item(LangItem::Sized, None);
|
||||
let sized_trait_def_id =
|
||||
tcx.require_lang_item(LangItem::Sized, obligation.cause.span);
|
||||
nested.push(obligation.with(
|
||||
tcx,
|
||||
sig.output().map_bound(|output_ty| {
|
||||
@@ -906,13 +908,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
});
|
||||
|
||||
// We must additionally check that the return type impls `Future + Sized`.
|
||||
let future_trait_def_id = tcx.require_lang_item(LangItem::Future, None);
|
||||
let future_trait_def_id =
|
||||
tcx.require_lang_item(LangItem::Future, obligation.cause.span);
|
||||
let placeholder_output_ty = self.infcx.enter_forall_and_leak_universe(sig.output());
|
||||
nested.push(obligation.with(
|
||||
tcx,
|
||||
ty::TraitRef::new(tcx, future_trait_def_id, [placeholder_output_ty]),
|
||||
));
|
||||
let sized_trait_def_id = tcx.require_lang_item(LangItem::Sized, None);
|
||||
let sized_trait_def_id =
|
||||
tcx.require_lang_item(LangItem::Sized, obligation.cause.span);
|
||||
nested.push(obligation.with(
|
||||
tcx,
|
||||
sig.output().map_bound(|output_ty| {
|
||||
@@ -946,10 +950,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
obligation.param_env,
|
||||
ty::TraitRef::new(
|
||||
self.tcx(),
|
||||
self.tcx().require_lang_item(
|
||||
LangItem::AsyncFnKindHelper,
|
||||
Some(obligation.cause.span),
|
||||
),
|
||||
self.tcx()
|
||||
.require_lang_item(LangItem::AsyncFnKindHelper, obligation.cause.span),
|
||||
[kind_ty, Ty::from_closure_kind(self.tcx(), goal_kind)],
|
||||
),
|
||||
));
|
||||
@@ -1165,7 +1167,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
// We can only make objects from sized types.
|
||||
let tr = ty::TraitRef::new(
|
||||
tcx,
|
||||
tcx.require_lang_item(LangItem::Sized, Some(obligation.cause.span)),
|
||||
tcx.require_lang_item(LangItem::Sized, obligation.cause.span),
|
||||
[source],
|
||||
);
|
||||
nested.push(predicate_to_obligation(tr.upcast(tcx)));
|
||||
@@ -1359,7 +1361,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
self_ty.map_bound(|ty| {
|
||||
ty::TraitRef::new(
|
||||
tcx,
|
||||
tcx.require_lang_item(LangItem::Copy, Some(obligation.cause.span)),
|
||||
tcx.require_lang_item(LangItem::Copy, obligation.cause.span),
|
||||
[ty],
|
||||
)
|
||||
}),
|
||||
@@ -1411,7 +1413,7 @@ fn pointer_like_goal_for_rpitit<'tcx>(
|
||||
ty::Binder::bind_with_vars(
|
||||
ty::TraitRef::new(
|
||||
tcx,
|
||||
tcx.require_lang_item(LangItem::PointerLike, Some(cause.span)),
|
||||
tcx.require_lang_item(LangItem::PointerLike, cause.span),
|
||||
[Ty::new_projection_from_args(tcx, rpitit_item, args)],
|
||||
),
|
||||
tcx.mk_bound_variable_kinds(&bound_vars),
|
||||
|
||||
@@ -541,7 +541,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
||||
let cause = self.cause(cause);
|
||||
let trait_ref = ty::TraitRef::new(
|
||||
self.tcx(),
|
||||
self.tcx().require_lang_item(LangItem::Sized, Some(cause.span)),
|
||||
self.tcx().require_lang_item(LangItem::Sized, cause.span),
|
||||
[subty],
|
||||
);
|
||||
self.out.push(traits::Obligation::with_depth(
|
||||
@@ -895,7 +895,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
|
||||
self.tcx(),
|
||||
self.tcx().require_lang_item(
|
||||
LangItem::BikeshedGuaranteedNoDrop,
|
||||
Some(self.span),
|
||||
self.span,
|
||||
),
|
||||
[ty],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user