Skip to content

Commit d1cc6e5

Browse files
committed
Use Spanned not semi-traversable Span tuples
1 parent 8da36bd commit d1cc6e5

File tree

90 files changed

+400
-329
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+400
-329
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5301,6 +5301,7 @@ dependencies = [
53015301
"rustc_index",
53025302
"rustc_macros",
53035303
"rustc_serialize",
5304+
"rustc_type_ir",
53045305
"scoped-tls",
53055306
"sha1",
53065307
"sha2",

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
671671
let tcx = self.infcx.tcx;
672672

673673
// Find out if the predicates show that the type is a Fn or FnMut
674-
let find_fn_kind_from_did = |(pred, _): (ty::Predicate<'tcx>, _)| {
675-
if let ty::PredicateKind::Clause(ty::Clause::Trait(pred)) = pred.kind().skip_binder()
674+
let find_fn_kind_from_did = |pred: ty::Spanned<ty::Predicate<'tcx>>| {
675+
if let ty::PredicateKind::Clause(ty::Clause::Trait(pred)) = pred.node.kind().skip_binder()
676676
&& pred.self_ty() == ty
677677
{
678678
if Some(pred.def_id()) == tcx.lang_items().fn_trait() {

compiler/rustc_borrowck/src/diagnostics/move_errors.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
103103
// opt_match_place is None for let [mut] x = ... statements,
104104
// whether or not the right-hand side is a place expression
105105
if let LocalInfo::User(BindingForm::Var(VarBindingForm {
106-
opt_match_place: Some((opt_match_place, match_span)),
106+
opt_match_place:
107+
Some(ty::Spanned { node: opt_match_place, span: match_span }),
107108
binding_mode: _,
108109
opt_ty_info: _,
109110
pat_span: _,

compiler/rustc_borrowck/src/type_check/canonical.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
107107
instantiated_predicates: ty::InstantiatedPredicates<'tcx>,
108108
locations: Locations,
109109
) {
110-
for (predicate, span) in instantiated_predicates {
111-
debug!(?predicate);
112-
let category = ConstraintCategory::Predicate(span);
113-
let predicate = self.normalize_with_category(predicate, locations, category);
110+
for predicate in instantiated_predicates {
111+
debug!(?predicate.node);
112+
let category = ConstraintCategory::Predicate(predicate.span);
113+
let predicate = self.normalize_with_category(predicate.node, locations, category);
114114
self.prove_predicate(predicate, locations, category);
115115
}
116116
}

compiler/rustc_codegen_cranelift/src/common.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,13 +451,13 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
451451
loop {
452452
let scope_data = &self.mir.source_scopes[source_info.scope];
453453

454-
if let Some((callee, callsite_span)) = scope_data.inlined {
454+
if let Some(callee) = scope_data.inlined {
455455
// Stop inside the most nested non-`#[track_caller]` function,
456456
// before ever reaching its caller (which is irrelevant).
457-
if !callee.def.requires_caller_location(self.tcx) {
457+
if !callee.node.def.requires_caller_location(self.tcx) {
458458
return span_to_caller_location(self, source_info.span);
459459
}
460-
source_info.span = callsite_span;
460+
source_info.span = callee.span;
461461
}
462462

463463
// Skip past all of the parents with `inlined: None`.

compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ fn make_mir_scope<'ll, 'tcx>(
8787
let file_metadata = file_metadata(cx, &loc.file);
8888

8989
let dbg_scope = match scope_data.inlined {
90-
Some((callee, _)) => {
90+
Some(callee) => {
9191
// FIXME(eddyb) this would be `self.monomorphize(&callee)`
9292
// if this is moved to `rustc_codegen_ssa::mir::debuginfo`.
9393
let callee = cx.tcx.subst_and_normalize_erasing_regions(
9494
instance.substs,
9595
ty::ParamEnv::reveal_all(),
96-
callee,
96+
callee.node,
9797
);
9898
let callee_fn_abi = cx.fn_abi_of_instance(callee, ty::List::empty());
9999
cx.dbg_scope_fn(callee, callee_fn_abi, None)
@@ -109,11 +109,11 @@ fn make_mir_scope<'ll, 'tcx>(
109109
},
110110
};
111111

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

119119
debug_context.scopes[scope] = DebugScope {

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,13 +1497,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
14971497
loop {
14981498
let scope_data = &self.mir.source_scopes[source_info.scope];
14991499

1500-
if let Some((callee, callsite_span)) = scope_data.inlined {
1500+
if let Some(callee) = scope_data.inlined {
15011501
// Stop inside the most nested non-`#[track_caller]` function,
15021502
// before ever reaching its caller (which is irrelevant).
1503-
if !callee.def.requires_caller_location(tcx) {
1503+
if !callee.node.def.requires_caller_location(tcx) {
15041504
return span_to_caller_location(source_info.span);
15051505
}
1506-
source_info.span = callsite_span;
1506+
source_info.span = callee.span;
15071507
}
15081508

15091509
// Skip past all of the parents with `inlined: None`.

compiler/rustc_const_eval/src/interpret/intrinsics/caller_location.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
4444
loop {
4545
let scope_data = &frame.body.source_scopes[source_info.scope];
4646

47-
if let Some((callee, callsite_span)) = scope_data.inlined {
47+
if let Some(callee) = scope_data.inlined {
4848
// Stop inside the most nested non-`#[track_caller]` function,
4949
// before ever reaching its caller (which is irrelevant).
50-
if !callee.def.requires_caller_location(*self.tcx) {
50+
if !callee.node.def.requires_caller_location(*self.tcx) {
5151
return source_info.span;
5252
}
53-
source_info.span = callsite_span;
53+
source_info.span = callee.span;
5454
}
5555

5656
// Skip past all of the parents with `inlined: None`.

compiler/rustc_hir_analysis/src/astconv/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,20 +1314,20 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
13141314

13151315
let mut trait_bounds = vec![];
13161316
let mut projection_bounds = vec![];
1317-
for (pred, span) in bounds.predicates() {
1318-
let bound_pred = pred.kind();
1317+
for pred in bounds.predicates() {
1318+
let bound_pred = pred.node.kind();
13191319
match bound_pred.skip_binder() {
13201320
ty::PredicateKind::Clause(clause) => match clause {
13211321
ty::Clause::Trait(trait_pred) => {
13221322
assert_eq!(trait_pred.polarity, ty::ImplPolarity::Positive);
13231323
trait_bounds.push((
13241324
bound_pred.rebind(trait_pred.trait_ref),
1325-
span,
1325+
pred.span,
13261326
trait_pred.constness,
13271327
));
13281328
}
13291329
ty::Clause::Projection(proj) => {
1330-
projection_bounds.push((bound_pred.rebind(proj), span));
1330+
projection_bounds.push((bound_pred.rebind(proj), pred.span));
13311331
}
13321332
ty::Clause::TypeOutlives(_) => {
13331333
// Do nothing, we deal with regions separately
@@ -1784,8 +1784,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
17841784
|| {
17851785
traits::transitive_bounds_that_define_assoc_type(
17861786
tcx,
1787-
predicates.iter().filter_map(|(p, _)| {
1788-
Some(p.to_opt_poly_trait_pred()?.map_bound(|t| t.trait_ref))
1787+
predicates.iter().filter_map(|p| {
1788+
Some(p.node.to_opt_poly_trait_pred()?.map_bound(|t| t.trait_ref))
17891789
}),
17901790
assoc_name,
17911791
)

compiler/rustc_hir_analysis/src/bounds.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use rustc_span::Span;
2323
/// include the self type (e.g., `trait_bounds`) but in others we do not
2424
#[derive(Default, PartialEq, Eq, Clone, Debug)]
2525
pub struct Bounds<'tcx> {
26-
pub predicates: Vec<(ty::Predicate<'tcx>, Span)>,
26+
pub predicates: Vec<ty::Spanned<ty::Predicate<'tcx>>>,
2727
}
2828

2929
impl<'tcx> Bounds<'tcx> {
@@ -33,7 +33,7 @@ impl<'tcx> Bounds<'tcx> {
3333
region: ty::PolyTypeOutlivesPredicate<'tcx>,
3434
span: Span,
3535
) {
36-
self.predicates.push((region.to_predicate(tcx), span));
36+
self.predicates.push(ty::Spanned { node: region.to_predicate(tcx), span });
3737
}
3838

3939
pub fn push_trait_bound(
@@ -43,7 +43,10 @@ impl<'tcx> Bounds<'tcx> {
4343
span: Span,
4444
constness: ty::BoundConstness,
4545
) {
46-
self.predicates.push((trait_ref.with_constness(constness).to_predicate(tcx), span));
46+
self.predicates.push(ty::Spanned {
47+
node: trait_ref.with_constness(constness).to_predicate(tcx),
48+
span,
49+
});
4750
}
4851

4952
pub fn push_projection_bound(
@@ -52,17 +55,18 @@ impl<'tcx> Bounds<'tcx> {
5255
projection: ty::PolyProjectionPredicate<'tcx>,
5356
span: Span,
5457
) {
55-
self.predicates.push((projection.to_predicate(tcx), span));
58+
self.predicates.push(ty::Spanned { node: projection.to_predicate(tcx), span });
5659
}
5760

5861
pub fn push_sized(&mut self, tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span) {
5962
let sized_def_id = tcx.require_lang_item(LangItem::Sized, Some(span));
6063
let trait_ref = ty::Binder::dummy(tcx.mk_trait_ref(sized_def_id, [ty]));
6164
// Preferrable to put this obligation first, since we report better errors for sized ambiguity.
62-
self.predicates.insert(0, (trait_ref.without_const().to_predicate(tcx), span));
65+
self.predicates
66+
.insert(0, ty::Spanned { node: trait_ref.without_const().to_predicate(tcx), span });
6367
}
6468

65-
pub fn predicates(&self) -> impl Iterator<Item = (ty::Predicate<'tcx>, Span)> + '_ {
69+
pub fn predicates(&self) -> impl Iterator<Item = ty::Spanned<ty::Predicate<'tcx>>> + '_ {
6670
self.predicates.iter().cloned()
6771
}
6872
}

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ pub(super) fn check_opaque_for_inheriting_lifetimes(
320320
let prohibit_opaque = tcx
321321
.explicit_item_bounds(def_id)
322322
.iter()
323-
.try_for_each(|(predicate, _)| predicate.visit_with(&mut visitor));
323+
.try_for_each(|predicate| predicate.node.visit_with(&mut visitor));
324324

325325
if let Some(ty) = prohibit_opaque.break_value() {
326326
visitor.visit_item(&item);

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ fn compare_method_predicate_entailment<'tcx>(
187187
hybrid_preds.predicates.extend(
188188
trait_m_predicates
189189
.instantiate_own(tcx, trait_to_placeholder_substs)
190-
.map(|(predicate, _)| predicate),
190+
.map(|predicate| predicate.node),
191191
);
192192

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

209209
let impl_m_own_bounds = impl_m_predicates.instantiate_own(tcx, impl_to_placeholder_substs);
210-
for (predicate, span) in impl_m_own_bounds {
210+
for ty::Spanned { node: predicate, span } in impl_m_own_bounds {
211211
let normalize_cause = traits::ObligationCause::misc(span, impl_m_def_id);
212212
let predicate = ocx.normalize(&normalize_cause, param_env, predicate);
213213

@@ -846,7 +846,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ImplTraitInTraitCollector<'_, 'tcx> {
846846
});
847847
self.types.insert(proj.def_id, (infer_ty, proj.substs));
848848
// Recurse into bounds
849-
for (pred, pred_span) in self.interner().bound_explicit_item_bounds(proj.def_id).subst_iter_copied(self.interner(), proj.substs) {
849+
for ty::Spanned { node: pred, span: pred_span } in self.interner().bound_explicit_item_bounds(proj.def_id).subst_iter_copied(self.interner(), proj.substs) {
850850
let pred = pred.fold_with(self);
851851
let pred = self.ocx.normalize(
852852
&ObligationCause::misc(self.span, self.body_id),
@@ -1804,7 +1804,7 @@ fn compare_type_predicate_entailment<'tcx>(
18041804
hybrid_preds.predicates.extend(
18051805
trait_ty_predicates
18061806
.instantiate_own(tcx, trait_to_impl_substs)
1807-
.map(|(predicate, _)| predicate),
1807+
.map(|predicate| predicate.node),
18081808
);
18091809

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

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

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

@@ -2043,9 +2043,14 @@ pub(super) fn check_type_bounds<'tcx>(
20432043
let obligations = tcx
20442044
.bound_explicit_item_bounds(trait_ty.def_id)
20452045
.subst_iter_copied(tcx, rebased_substs)
2046-
.map(|(concrete_ty_bound, span)| {
2047-
debug!("check_type_bounds: concrete_ty_bound = {:?}", concrete_ty_bound);
2048-
traits::Obligation::new(tcx, mk_cause(span), param_env, concrete_ty_bound)
2046+
.map(|concrete_ty_bound| {
2047+
debug!("check_type_bounds: concrete_ty_bound = {:?}", concrete_ty_bound.node);
2048+
traits::Obligation::new(
2049+
tcx,
2050+
mk_cause(concrete_ty_bound.span),
2051+
param_env,
2052+
concrete_ty_bound.node,
2053+
)
20492054
})
20502055
.collect();
20512056
debug!("check_type_bounds: item_bounds={:?}", obligations);

compiler/rustc_hir_analysis/src/check/dropck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
155155
// just to look for all the predicates directly.
156156

157157
assert_eq!(dtor_predicates.parent, None);
158-
for &(predicate, predicate_sp) in dtor_predicates.predicates {
158+
for &ty::Spanned { node: predicate, span: predicate_sp } in dtor_predicates.predicates {
159159
// (We do not need to worry about deep analysis of type
160160
// expressions etc because the Drop impls are already forced
161161
// to take on a structure that is roughly an alpha-renaming of

compiler/rustc_hir_analysis/src/check/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,9 @@ fn bounds_from_generic_predicates<'tcx>(
302302
) -> (String, String) {
303303
let mut types: FxHashMap<Ty<'tcx>, Vec<DefId>> = FxHashMap::default();
304304
let mut projections = vec![];
305-
for (predicate, _) in predicates.predicates {
306-
debug!("predicate {:?}", predicate);
307-
let bound_predicate = predicate.kind();
305+
for predicate in predicates.predicates {
306+
debug!("predicate {:?}", predicate.node);
307+
let bound_predicate = predicate.node.kind();
308308
match bound_predicate.skip_binder() {
309309
ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) => {
310310
let entry = types.entry(trait_predicate.self_ty()).or_default();

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,14 +1134,14 @@ fn check_associated_type_bounds(wfcx: &WfCheckingCtxt<'_, '_>, item: ty::AssocIt
11341134
let bounds = wfcx.tcx().explicit_item_bounds(item.def_id);
11351135

11361136
debug!("check_associated_type_bounds: bounds={:?}", bounds);
1137-
let wf_obligations = bounds.iter().flat_map(|&(bound, bound_span)| {
1138-
let normalized_bound = wfcx.normalize(span, None, bound);
1137+
let wf_obligations = bounds.iter().flat_map(|&bound| {
1138+
let normalized_bound = wfcx.normalize(span, None, bound.node);
11391139
traits::wf::predicate_obligations(
11401140
wfcx.infcx,
11411141
wfcx.param_env,
11421142
wfcx.body_def_id,
11431143
normalized_bound,
1144-
bound_span,
1144+
bound.span,
11451145
)
11461146
});
11471147

@@ -1377,7 +1377,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
13771377
let default_obligations = predicates
13781378
.predicates
13791379
.iter()
1380-
.flat_map(|&(pred, sp)| {
1380+
.flat_map(|&pred| {
13811381
#[derive(Default)]
13821382
struct CountParams {
13831383
params: FxHashSet<u32>,
@@ -1404,18 +1404,18 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
14041404
}
14051405
}
14061406
let mut param_count = CountParams::default();
1407-
let has_region = pred.visit_with(&mut param_count).is_break();
1408-
let substituted_pred = ty::EarlyBinder(pred).subst(tcx, substs);
1407+
let has_region = pred.node.visit_with(&mut param_count).is_break();
1408+
let substituted_pred = ty::EarlyBinder(pred.node).subst(tcx, substs);
14091409
// Don't check non-defaulted params, dependent defaults (including lifetimes)
14101410
// or preds with multiple params.
14111411
if substituted_pred.has_non_region_param() || param_count.params.len() > 1 || has_region
14121412
{
14131413
None
1414-
} else if predicates.predicates.iter().any(|&(p, _)| p == substituted_pred) {
1414+
} else if predicates.predicates.iter().any(|&p| p.node == substituted_pred) {
14151415
// Avoid duplication of predicates that contain no parameters, for example.
14161416
None
14171417
} else {
1418-
Some((substituted_pred, sp))
1418+
Some((substituted_pred, pred.span))
14191419
}
14201420
})
14211421
.map(|(pred, sp)| {
@@ -1443,13 +1443,13 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
14431443

14441444
debug!(?predicates.predicates);
14451445
assert_eq!(predicates.predicates.len(), predicates.spans.len());
1446-
let wf_obligations = predicates.into_iter().flat_map(|(p, sp)| {
1446+
let wf_obligations = predicates.into_iter().flat_map(|p| {
14471447
traits::wf::predicate_obligations(
14481448
infcx,
14491449
wfcx.param_env.without_const(),
14501450
wfcx.body_def_id,
1451-
p,
1452-
sp,
1451+
p.node,
1452+
p.span,
14531453
)
14541454
});
14551455
let obligations: Vec<_> = wf_obligations.chain(default_obligations).collect();
@@ -1566,7 +1566,7 @@ fn check_return_position_impl_trait_in_trait_bounds<'tcx>(
15661566
{
15671567
let span = tcx.def_span(opaque_ty.def_id);
15681568
let bounds = wfcx.tcx().explicit_item_bounds(opaque_ty.def_id);
1569-
let wf_obligations = bounds.iter().flat_map(|&(bound, bound_span)| {
1569+
let wf_obligations = bounds.iter().flat_map(|&ty::Spanned { node: bound, span: bound_span }| {
15701570
let bound = ty::EarlyBinder(bound).subst(tcx, opaque_ty.substs);
15711571
let normalized_bound = wfcx.normalize(span, None, bound);
15721572
traits::wf::predicate_obligations(

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,8 +1448,9 @@ fn predicates_defined_on(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicate
14481448
"predicates_defined_on: inferred_outlives_of({:?}) = {:?}",
14491449
def_id, inferred_outlives,
14501450
);
1451-
let inferred_outlives_iter =
1452-
inferred_outlives.iter().map(|(clause, span)| ((*clause).to_predicate(tcx), *span));
1451+
let inferred_outlives_iter = inferred_outlives
1452+
.iter()
1453+
.map(|(clause, span)| ty::Spanned { node: (*clause).to_predicate(tcx), span: *span });
14531454
if result.predicates.is_empty() {
14541455
result.predicates = tcx.arena.alloc_from_iter(inferred_outlives_iter);
14551456
} else {

0 commit comments

Comments
 (0)