Skip to content

Commit

Permalink
Use Spanned not semi-traversable Span tuples
Browse files Browse the repository at this point in the history
  • Loading branch information
eggyal committed Nov 9, 2023
1 parent f3e8b6a commit c5e9447
Show file tree
Hide file tree
Showing 100 changed files with 563 additions and 424 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4532,6 +4532,7 @@ dependencies = [
"rustc_index",
"rustc_macros",
"rustc_serialize",
"rustc_type_ir",
"scoped-tls",
"sha1",
"sha2",
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,8 +671,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let tcx = self.infcx.tcx;

// Find out if the predicates show that the type is a Fn or FnMut
let find_fn_kind_from_did = |(pred, _): (ty::Clause<'tcx>, _)| {
if let ty::ClauseKind::Trait(pred) = pred.kind().skip_binder()
let find_fn_kind_from_did = |pred: ty::Spanned<ty::Clause<'tcx>>| {
if let ty::ClauseKind::Trait(pred) = pred.node.kind().skip_binder()
&& pred.self_ty() == ty
{
if Some(pred.def_id()) == tcx.lang_items().fn_trait() {
Expand All @@ -698,7 +698,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => tcx
.explicit_item_bounds(def_id)
.iter_instantiated_copied(tcx, args)
.find_map(|(clause, span)| find_fn_kind_from_did((clause, span))),
.find_map(find_fn_kind_from_did),
ty::Closure(_, args) => match args.as_closure().kind() {
ty::ClosureKind::Fn => Some(hir::Mutability::Not),
ty::ClosureKind::FnMut => Some(hir::Mutability::Mut),
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_borrowck/src/diagnostics/move_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
// opt_match_place is None for let [mut] x = ... statements,
// whether or not the right-hand side is a place expression
if let LocalInfo::User(BindingForm::Var(VarBindingForm {
opt_match_place: Some((opt_match_place, match_span)),
opt_match_place: Some(opt_match_place),
binding_mode: _,
opt_ty_info: _,
pat_span: _,
Expand All @@ -143,8 +143,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
original_path,
*move_from,
local,
opt_match_place,
match_span,
opt_match_place.node,
opt_match_place.span,
stmt_source_info.span,
);
return;
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_borrowck/src/type_check/canonical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
instantiated_predicates: ty::InstantiatedPredicates<'tcx>,
locations: Locations,
) {
for (predicate, span) in instantiated_predicates {
debug!(?predicate);
let category = ConstraintCategory::Predicate(span);
let predicate = self.normalize_with_category(predicate, locations, category);
for predicate in instantiated_predicates {
debug!(?predicate.node);
let category = ConstraintCategory::Predicate(predicate.span);
let predicate = self.normalize_with_category(predicate.node, locations, category);
self.prove_predicate(predicate, locations, category);
}
}
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ fn make_mir_scope<'ll, 'tcx>(
let file_metadata = file_metadata(cx, &loc.file);

let parent_dbg_scope = match scope_data.inlined {
Some((callee, _)) => {
Some(callee) => {
// FIXME(eddyb) this would be `self.monomorphize(&callee)`
// if this is moved to `rustc_codegen_ssa::mir::debuginfo`.
let callee = cx.tcx.instantiate_and_normalize_erasing_regions(
instance.args,
ty::ParamEnv::reveal_all(),
ty::EarlyBinder::bind(callee),
ty::EarlyBinder::bind(callee.node),
);
debug_context.inlined_function_scopes.entry(callee).or_insert_with(|| {
let callee_fn_abi = cx.fn_abi_of_instance(callee, ty::List::empty());
Expand All @@ -116,11 +116,11 @@ fn make_mir_scope<'ll, 'tcx>(
)
};

let inlined_at = scope_data.inlined.map(|(_, callsite_span)| {
let inlined_at = scope_data.inlined.map(|callee| {
// FIXME(eddyb) this doesn't account for the macro-related
// `Span` fixups that `rustc_codegen_ssa::mir::debuginfo` does.
let callsite_scope = parent_scope.adjust_dbg_scope_for_span(cx, callsite_span);
cx.dbg_loc(callsite_scope, parent_scope.inlined_at, callsite_span)
let callsite_scope = parent_scope.adjust_dbg_scope_for_span(cx, callee.span);
cx.dbg_loc(callsite_scope, parent_scope.inlined_at, callee.span)
});

debug_context.scopes[scope] = DebugScope {
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_const_eval/src/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1165,9 +1165,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
// If the stacktrace passes through MIR-inlined source scopes, add them.
let mir::SourceInfo { mut span, scope } = *frame.body.source_info(loc);
let mut scope_data = &frame.body.source_scopes[scope];
while let Some((instance, call_span)) = scope_data.inlined {
frames.push(FrameInfo { span, instance });
span = call_span;
while let Some(instance) = scope_data.inlined {
frames.push(FrameInfo { span, instance: instance.node });
span = instance.span;
scope_data = &frame.body.source_scopes[scope_data.parent_scope.unwrap()];
}
span
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
tcx,
predicates
.iter()
.filter_map(|(p, _)| Some(p.as_trait_clause()?.map_bound(|t| t.trait_ref))),
.filter_map(|p| Some(p.node.as_trait_clause()?.map_bound(|t| t.trait_ref))),
assoc_name,
)
},
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_hir_analysis/src/astconv/object_safety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {

let mut trait_bounds = vec![];
let mut projection_bounds = vec![];
for (pred, span) in bounds.clauses() {
let bound_pred = pred.kind();
for pred in bounds.clauses() {
let bound_pred = pred.node.kind();
match bound_pred.skip_binder() {
ty::ClauseKind::Trait(trait_pred) => {
assert_eq!(trait_pred.polarity, ty::ImplPolarity::Positive);
trait_bounds.push((bound_pred.rebind(trait_pred.trait_ref), span));
trait_bounds.push((bound_pred.rebind(trait_pred.trait_ref), pred.span));
}
ty::ClauseKind::Projection(proj) => {
projection_bounds.push((bound_pred.rebind(proj), span));
projection_bounds.push((bound_pred.rebind(proj), pred.span));
}
ty::ClauseKind::TypeOutlives(_) => {
// Do nothing, we deal with regions separately
Expand Down
24 changes: 13 additions & 11 deletions compiler/rustc_hir_analysis/src/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use rustc_span::Span;
/// include the self type (e.g., `trait_bounds`) but in others we do not
#[derive(Default, PartialEq, Eq, Clone, Debug)]
pub struct Bounds<'tcx> {
pub clauses: Vec<(ty::Clause<'tcx>, Span)>,
pub clauses: Vec<ty::Spanned<ty::Clause<'tcx>>>,
}

impl<'tcx> Bounds<'tcx> {
Expand All @@ -33,8 +33,10 @@ impl<'tcx> Bounds<'tcx> {
region: ty::PolyTypeOutlivesPredicate<'tcx>,
span: Span,
) {
self.clauses
.push((region.map_bound(|p| ty::ClauseKind::TypeOutlives(p)).to_predicate(tcx), span));
self.clauses.push(ty::Spanned {
node: region.map_bound(|p| ty::ClauseKind::TypeOutlives(p)).to_predicate(tcx),
span,
});
}

pub fn push_trait_bound(
Expand Down Expand Up @@ -72,14 +74,14 @@ impl<'tcx> Bounds<'tcx> {
span: Span,
polarity: ty::ImplPolarity,
) {
self.clauses.push((
trait_ref
self.clauses.push(ty::Spanned {
node: trait_ref
.map_bound(|trait_ref| {
ty::ClauseKind::Trait(ty::TraitPredicate { trait_ref, polarity })
})
.to_predicate(tcx),
span,
));
});
}

pub fn push_projection_bound(
Expand All @@ -88,20 +90,20 @@ impl<'tcx> Bounds<'tcx> {
projection: ty::PolyProjectionPredicate<'tcx>,
span: Span,
) {
self.clauses.push((
projection.map_bound(|proj| ty::ClauseKind::Projection(proj)).to_predicate(tcx),
self.clauses.push(ty::Spanned {
node: projection.map_bound(|proj| ty::ClauseKind::Projection(proj)).to_predicate(tcx),
span,
));
});
}

pub fn push_sized(&mut self, tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span) {
let sized_def_id = tcx.require_lang_item(LangItem::Sized, Some(span));
let trait_ref = ty::TraitRef::new(tcx, sized_def_id, [ty]);
// Preferable to put this obligation first, since we report better errors for sized ambiguity.
self.clauses.insert(0, (trait_ref.to_predicate(tcx), span));
self.clauses.insert(0, ty::Spanned { node: trait_ref.to_predicate(tcx), span });
}

pub fn clauses(&self) -> impl Iterator<Item = (ty::Clause<'tcx>, Span)> + '_ {
pub fn clauses(&self) -> impl Iterator<Item = ty::Spanned<ty::Clause<'tcx>>> + '_ {
self.clauses.iter().cloned()
}
}
27 changes: 16 additions & 11 deletions compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ fn compare_method_predicate_entailment<'tcx>(
hybrid_preds.predicates.extend(
trait_m_predicates
.instantiate_own(tcx, trait_to_placeholder_args)
.map(|(predicate, _)| predicate),
.map(|predicate| predicate.node),
);

// Construct trait parameter environment and then shift it into the placeholder viewpoint.
Expand All @@ -238,7 +238,7 @@ fn compare_method_predicate_entailment<'tcx>(
debug!("compare_impl_method: caller_bounds={:?}", param_env.caller_bounds());

let impl_m_own_bounds = impl_m_predicates.instantiate_own(tcx, impl_to_placeholder_args);
for (predicate, span) in impl_m_own_bounds {
for ty::Spanned { node: predicate, span } in impl_m_own_bounds {
let normalize_cause = traits::ObligationCause::misc(span, impl_m_def_id);
let predicate = ocx.normalize(&normalize_cause, param_env, predicate);

Expand Down Expand Up @@ -691,7 +691,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
.instantiate_identity(tcx)
.into_iter()
.chain(tcx.predicates_of(trait_m.def_id).instantiate_own(tcx, trait_to_placeholder_args))
.map(|(clause, _)| clause);
.map(|clause| clause.node);
let param_env = ty::ParamEnv::new(tcx.mk_clauses_from_iter(hybrid_preds), Reveal::UserFacing);
let param_env = traits::normalize_param_env_or_error(
tcx,
Expand Down Expand Up @@ -1009,7 +1009,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ImplTraitInTraitCollector<'_, 'tcx> {
});
self.types.insert(proj.def_id, (infer_ty, proj.args));
// Recurse into bounds
for (pred, pred_span) in self
for ty::Spanned { node: pred, span: pred_span } in self
.interner()
.explicit_item_bounds(proj.def_id)
.iter_instantiated_copied(self.interner(), proj.args)
Expand Down Expand Up @@ -1963,7 +1963,7 @@ fn compare_const_predicate_entailment<'tcx>(
hybrid_preds.predicates.extend(
trait_ct_predicates
.instantiate_own(tcx, trait_to_impl_args)
.map(|(predicate, _)| predicate),
.map(|predicate| predicate.node),
);

let param_env = ty::ParamEnv::new(tcx.mk_clauses(&hybrid_preds.predicates), Reveal::UserFacing);
Expand All @@ -1977,7 +1977,7 @@ fn compare_const_predicate_entailment<'tcx>(
let ocx = ObligationCtxt::new(&infcx);

let impl_ct_own_bounds = impl_ct_predicates.instantiate_own(tcx, impl_args);
for (predicate, span) in impl_ct_own_bounds {
for ty::Spanned { node: predicate, span } in impl_ct_own_bounds {
let cause = ObligationCause::misc(span, impl_ct_def_id);
let predicate = ocx.normalize(&cause, param_env, predicate);

Expand Down Expand Up @@ -2098,7 +2098,7 @@ fn compare_type_predicate_entailment<'tcx>(
hybrid_preds.predicates.extend(
trait_ty_predicates
.instantiate_own(tcx, trait_to_impl_args)
.map(|(predicate, _)| predicate),
.map(|predicate| predicate.node),
);

debug!("compare_type_predicate_entailment: bounds={:?}", hybrid_preds);
Expand All @@ -2112,7 +2112,7 @@ fn compare_type_predicate_entailment<'tcx>(

debug!("compare_type_predicate_entailment: caller_bounds={:?}", param_env.caller_bounds());

for (predicate, span) in impl_ty_own_bounds {
for ty::Spanned { node: predicate, span } in impl_ty_own_bounds {
let cause = ObligationCause::misc(span, impl_ty_def_id);
let predicate = ocx.normalize(&cause, param_env, predicate);

Expand Down Expand Up @@ -2210,9 +2210,14 @@ pub(super) fn check_type_bounds<'tcx>(
let obligations: Vec<_> = tcx
.explicit_item_bounds(trait_ty.def_id)
.iter_instantiated_copied(tcx, rebased_args)
.map(|(concrete_ty_bound, span)| {
debug!("check_type_bounds: concrete_ty_bound = {:?}", concrete_ty_bound);
traits::Obligation::new(tcx, mk_cause(span), param_env, concrete_ty_bound)
.map(|concrete_ty_bound| {
debug!("check_type_bounds: concrete_ty_bound = {:?}", concrete_ty_bound.node);
traits::Obligation::new(
tcx,
mk_cause(concrete_ty_bound.span),
param_env,
concrete_ty_bound.node,
)
})
.collect();
debug!("check_type_bounds: item_bounds={:?}", obligations);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
.instantiate_identity(tcx)
.into_iter()
.chain(tcx.predicates_of(trait_m.def_id).instantiate_own(tcx, trait_m_to_impl_m_args))
.map(|(clause, _)| clause);
.map(|clause| clause.node);
let param_env = ty::ParamEnv::new(tcx.mk_clauses_from_iter(hybrid_preds), Reveal::UserFacing);
let param_env = normalize_param_env_or_error(tcx, param_env, ObligationCause::dummy());

Expand Down Expand Up @@ -193,14 +193,14 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
// too, since we *do not* use the trait solver to prove that the RPITIT's
// bounds are not stronger -- we're doing a simple, syntactic compatibility
// check between bounds. This is strictly forwards compatible, though.
for (clause, span) in impl_bounds {
if !trait_bounds.contains(&clause) {
for clause in impl_bounds {
if !trait_bounds.contains(&clause.node) {
report_mismatched_rpitit_signature(
tcx,
trait_m_sig_with_self_for_diag,
trait_m.def_id,
impl_m.def_id,
Some(span),
Some(clause.span),
);
return;
}
Expand All @@ -220,12 +220,12 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitCollector<'tcx> {
&& self.tcx.is_impl_trait_in_trait(proj.def_id)
{
if self.types.insert(proj) {
for (pred, _) in self
for pred in self
.tcx
.explicit_item_bounds(proj.def_id)
.iter_instantiated_copied(self.tcx, proj.args)
{
pred.visit_with(self)?;
pred.node.visit_with(self)?;
}
}
ControlFlow::Continue(())
Expand Down Expand Up @@ -267,7 +267,7 @@ fn report_mismatched_rpitit_signature<'tcx>(
let Some(future_output_ty) = tcx
.explicit_item_bounds(future_ty.def_id)
.iter_instantiated_copied(tcx, future_ty.args)
.find_map(|(clause, _)| match clause.kind().no_bound_vars()? {
.find_map(|clause| match clause.node.kind().no_bound_vars()? {
ty::ClauseKind::Projection(proj) => proj.term.ty(),
_ => None,
})
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_hir_analysis/src/check/dropck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
let param_env =
ty::EarlyBinder::bind(tcx.param_env(adt_def_id)).instantiate(tcx, adt_to_impl_args);

for (pred, span) in tcx.predicates_of(drop_impl_def_id).instantiate_identity(tcx) {
for ty::Spanned { node: pred, span } in
tcx.predicates_of(drop_impl_def_id).instantiate_identity(tcx)
{
let normalize_cause = traits::ObligationCause::misc(span, adt_def_id);
let pred = ocx.normalize(&normalize_cause, param_env, pred);
let cause = traits::ObligationCause::new(span, adt_def_id, traits::DropImpl);
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_hir_analysis/src/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,13 @@ fn default_body_is_unstable(
/// Re-sugar `ty::GenericPredicates` in a way suitable to be used in structured suggestions.
fn bounds_from_generic_predicates<'tcx>(
tcx: TyCtxt<'tcx>,
predicates: impl IntoIterator<Item = (ty::Clause<'tcx>, Span)>,
predicates: impl IntoIterator<Item = ty::Spanned<ty::Clause<'tcx>>>,
) -> (String, String) {
let mut types: FxHashMap<Ty<'tcx>, Vec<DefId>> = FxHashMap::default();
let mut projections = vec![];
for (predicate, _) in predicates {
debug!("predicate {:?}", predicate);
let bound_predicate = predicate.kind();
for predicate in predicates {
debug!("predicate {:?}", predicate.node);
let bound_predicate = predicate.node.kind();
match bound_predicate.skip_binder() {
ty::ClauseKind::Trait(trait_predicate) => {
let entry = types.entry(trait_predicate.self_ty()).or_default();
Expand Down Expand Up @@ -382,7 +382,7 @@ fn fn_sig_suggestion<'tcx>(
tcx: TyCtxt<'tcx>,
sig: ty::FnSig<'tcx>,
ident: Ident,
predicates: impl IntoIterator<Item = (ty::Clause<'tcx>, Span)>,
predicates: impl IntoIterator<Item = ty::Spanned<ty::Clause<'tcx>>>,
assoc: ty::AssocItem,
) -> String {
let args = sig
Expand Down Expand Up @@ -429,7 +429,7 @@ fn fn_sig_suggestion<'tcx>(
output = if let ty::Alias(_, alias_ty) = *output.kind() {
tcx.explicit_item_bounds(alias_ty.def_id)
.iter_instantiated_copied(tcx, alias_ty.args)
.find_map(|(bound, _)| bound.as_projection_clause()?.no_bound_vars()?.term.ty())
.find_map(|bound| bound.node.as_projection_clause()?.no_bound_vars()?.term.ty())
.unwrap_or_else(|| {
span_bug!(
ident.span,
Expand Down
Loading

0 comments on commit c5e9447

Please sign in to comment.