Skip to content

Commit 14b85cb

Browse files
committed
Use Spanned not semi-traversable Span tuples
1 parent 561ad7e commit 14b85cb

File tree

100 files changed

+563
-424
lines changed

Some content is hidden

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

100 files changed

+563
-424
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4545,6 +4545,7 @@ dependencies = [
45454545
"rustc_index",
45464546
"rustc_macros",
45474547
"rustc_serialize",
4548+
"rustc_type_ir",
45484549
"scoped-tls",
45494550
"sha1",
45504551
"sha2",

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+3-3
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::Clause<'tcx>, _)| {
675-
if let ty::ClauseKind::Trait(pred) = pred.kind().skip_binder()
674+
let find_fn_kind_from_did = |pred: ty::Spanned<ty::Clause<'tcx>>| {
675+
if let ty::ClauseKind::Trait(pred) = pred.node.kind().skip_binder()
676676
&& pred.self_ty() == ty
677677
{
678678
if Some(pred.def_id()) == tcx.lang_items().fn_trait() {
@@ -698,7 +698,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
698698
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => tcx
699699
.explicit_item_bounds(def_id)
700700
.iter_instantiated_copied(tcx, args)
701-
.find_map(|(clause, span)| find_fn_kind_from_did((clause, span))),
701+
.find_map(find_fn_kind_from_did),
702702
ty::Closure(_, args) => match args.as_closure().kind() {
703703
ty::ClosureKind::Fn => Some(hir::Mutability::Not),
704704
ty::ClosureKind::FnMut => Some(hir::Mutability::Mut),

compiler/rustc_borrowck/src/diagnostics/move_errors.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
130130
// opt_match_place is None for let [mut] x = ... statements,
131131
// whether or not the right-hand side is a place expression
132132
if let LocalInfo::User(BindingForm::Var(VarBindingForm {
133-
opt_match_place: Some((opt_match_place, match_span)),
133+
opt_match_place: Some(opt_match_place),
134134
binding_mode: _,
135135
opt_ty_info: _,
136136
pat_span: _,
@@ -143,8 +143,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
143143
original_path,
144144
*move_from,
145145
local,
146-
opt_match_place,
147-
match_span,
146+
opt_match_place.node,
147+
opt_match_place.span,
148148
stmt_source_info.span,
149149
);
150150
return;

compiler/rustc_borrowck/src/type_check/canonical.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
9999
instantiated_predicates: ty::InstantiatedPredicates<'tcx>,
100100
locations: Locations,
101101
) {
102-
for (predicate, span) in instantiated_predicates {
103-
debug!(?predicate);
104-
let category = ConstraintCategory::Predicate(span);
105-
let predicate = self.normalize_with_category(predicate, locations, category);
102+
for predicate in instantiated_predicates {
103+
debug!(?predicate.node);
104+
let category = ConstraintCategory::Predicate(predicate.span);
105+
let predicate = self.normalize_with_category(predicate.node, locations, category);
106106
self.prove_predicate(predicate, locations, category);
107107
}
108108
}

compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ fn make_mir_scope<'ll, 'tcx>(
9090
let file_metadata = file_metadata(cx, &loc.file);
9191

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

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

126126
debug_context.scopes[scope] = DebugScope {

compiler/rustc_const_eval/src/interpret/eval_context.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1165,9 +1165,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
11651165
// If the stacktrace passes through MIR-inlined source scopes, add them.
11661166
let mir::SourceInfo { mut span, scope } = *frame.body.source_info(loc);
11671167
let mut scope_data = &frame.body.source_scopes[scope];
1168-
while let Some((instance, call_span)) = scope_data.inlined {
1169-
frames.push(FrameInfo { span, instance });
1170-
span = call_span;
1168+
while let Some(instance) = scope_data.inlined {
1169+
frames.push(FrameInfo { span, instance: instance.node });
1170+
span = instance.span;
11711171
scope_data = &frame.body.source_scopes[scope_data.parent_scope.unwrap()];
11721172
}
11731173
span

compiler/rustc_hir_analysis/src/astconv/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
10571057
tcx,
10581058
predicates
10591059
.iter()
1060-
.filter_map(|(p, _)| Some(p.as_trait_clause()?.map_bound(|t| t.trait_ref))),
1060+
.filter_map(|p| Some(p.node.as_trait_clause()?.map_bound(|t| t.trait_ref))),
10611061
assoc_name,
10621062
)
10631063
},

compiler/rustc_hir_analysis/src/astconv/object_safety.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
5757

5858
let mut trait_bounds = vec![];
5959
let mut projection_bounds = vec![];
60-
for (pred, span) in bounds.clauses() {
61-
let bound_pred = pred.kind();
60+
for pred in bounds.clauses() {
61+
let bound_pred = pred.node.kind();
6262
match bound_pred.skip_binder() {
6363
ty::ClauseKind::Trait(trait_pred) => {
6464
assert_eq!(trait_pred.polarity, ty::ImplPolarity::Positive);
65-
trait_bounds.push((bound_pred.rebind(trait_pred.trait_ref), span));
65+
trait_bounds.push((bound_pred.rebind(trait_pred.trait_ref), pred.span));
6666
}
6767
ty::ClauseKind::Projection(proj) => {
68-
projection_bounds.push((bound_pred.rebind(proj), span));
68+
projection_bounds.push((bound_pred.rebind(proj), pred.span));
6969
}
7070
ty::ClauseKind::TypeOutlives(_) => {
7171
// Do nothing, we deal with regions separately

compiler/rustc_hir_analysis/src/bounds.rs

+13-11
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 clauses: Vec<(ty::Clause<'tcx>, Span)>,
26+
pub clauses: Vec<ty::Spanned<ty::Clause<'tcx>>>,
2727
}
2828

2929
impl<'tcx> Bounds<'tcx> {
@@ -33,8 +33,10 @@ impl<'tcx> Bounds<'tcx> {
3333
region: ty::PolyTypeOutlivesPredicate<'tcx>,
3434
span: Span,
3535
) {
36-
self.clauses
37-
.push((region.map_bound(|p| ty::ClauseKind::TypeOutlives(p)).to_predicate(tcx), span));
36+
self.clauses.push(ty::Spanned {
37+
node: region.map_bound(|p| ty::ClauseKind::TypeOutlives(p)).to_predicate(tcx),
38+
span,
39+
});
3840
}
3941

4042
pub fn push_trait_bound(
@@ -72,14 +74,14 @@ impl<'tcx> Bounds<'tcx> {
7274
span: Span,
7375
polarity: ty::ImplPolarity,
7476
) {
75-
self.clauses.push((
76-
trait_ref
77+
self.clauses.push(ty::Spanned {
78+
node: trait_ref
7779
.map_bound(|trait_ref| {
7880
ty::ClauseKind::Trait(ty::TraitPredicate { trait_ref, polarity })
7981
})
8082
.to_predicate(tcx),
8183
span,
82-
));
84+
});
8385
}
8486

8587
pub fn push_projection_bound(
@@ -88,20 +90,20 @@ impl<'tcx> Bounds<'tcx> {
8890
projection: ty::PolyProjectionPredicate<'tcx>,
8991
span: Span,
9092
) {
91-
self.clauses.push((
92-
projection.map_bound(|proj| ty::ClauseKind::Projection(proj)).to_predicate(tcx),
93+
self.clauses.push(ty::Spanned {
94+
node: projection.map_bound(|proj| ty::ClauseKind::Projection(proj)).to_predicate(tcx),
9395
span,
94-
));
96+
});
9597
}
9698

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

104-
pub fn clauses(&self) -> impl Iterator<Item = (ty::Clause<'tcx>, Span)> + '_ {
106+
pub fn clauses(&self) -> impl Iterator<Item = ty::Spanned<ty::Clause<'tcx>>> + '_ {
105107
self.clauses.iter().cloned()
106108
}
107109
}

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+16-11
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ fn compare_method_predicate_entailment<'tcx>(
222222
hybrid_preds.predicates.extend(
223223
trait_m_predicates
224224
.instantiate_own(tcx, trait_to_placeholder_args)
225-
.map(|(predicate, _)| predicate),
225+
.map(|predicate| predicate.node),
226226
);
227227

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

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

@@ -691,7 +691,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
691691
.instantiate_identity(tcx)
692692
.into_iter()
693693
.chain(tcx.predicates_of(trait_m.def_id).instantiate_own(tcx, trait_to_placeholder_args))
694-
.map(|(clause, _)| clause);
694+
.map(|clause| clause.node);
695695
let param_env = ty::ParamEnv::new(tcx.mk_clauses_from_iter(hybrid_preds), Reveal::UserFacing);
696696
let param_env = traits::normalize_param_env_or_error(
697697
tcx,
@@ -1009,7 +1009,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ImplTraitInTraitCollector<'_, 'tcx> {
10091009
});
10101010
self.types.insert(proj.def_id, (infer_ty, proj.args));
10111011
// Recurse into bounds
1012-
for (pred, pred_span) in self
1012+
for ty::Spanned { node: pred, span: pred_span } in self
10131013
.interner()
10141014
.explicit_item_bounds(proj.def_id)
10151015
.iter_instantiated_copied(self.interner(), proj.args)
@@ -1963,7 +1963,7 @@ fn compare_const_predicate_entailment<'tcx>(
19631963
hybrid_preds.predicates.extend(
19641964
trait_ct_predicates
19651965
.instantiate_own(tcx, trait_to_impl_args)
1966-
.map(|(predicate, _)| predicate),
1966+
.map(|predicate| predicate.node),
19671967
);
19681968

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

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

@@ -2098,7 +2098,7 @@ fn compare_type_predicate_entailment<'tcx>(
20982098
hybrid_preds.predicates.extend(
20992099
trait_ty_predicates
21002100
.instantiate_own(tcx, trait_to_impl_args)
2101-
.map(|(predicate, _)| predicate),
2101+
.map(|predicate| predicate.node),
21022102
);
21032103

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

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

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

@@ -2210,9 +2210,14 @@ pub(super) fn check_type_bounds<'tcx>(
22102210
let obligations: Vec<_> = tcx
22112211
.explicit_item_bounds(trait_ty.def_id)
22122212
.iter_instantiated_copied(tcx, rebased_args)
2213-
.map(|(concrete_ty_bound, span)| {
2214-
debug!("check_type_bounds: concrete_ty_bound = {:?}", concrete_ty_bound);
2215-
traits::Obligation::new(tcx, mk_cause(span), param_env, concrete_ty_bound)
2213+
.map(|concrete_ty_bound| {
2214+
debug!("check_type_bounds: concrete_ty_bound = {:?}", concrete_ty_bound.node);
2215+
traits::Obligation::new(
2216+
tcx,
2217+
mk_cause(concrete_ty_bound.span),
2218+
param_env,
2219+
concrete_ty_bound.node,
2220+
)
22162221
})
22172222
.collect();
22182223
debug!("check_type_bounds: item_bounds={:?}", obligations);

compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
123123
.instantiate_identity(tcx)
124124
.into_iter()
125125
.chain(tcx.predicates_of(trait_m.def_id).instantiate_own(tcx, trait_m_to_impl_m_args))
126-
.map(|(clause, _)| clause);
126+
.map(|clause| clause.node);
127127
let param_env = ty::ParamEnv::new(tcx.mk_clauses_from_iter(hybrid_preds), Reveal::UserFacing);
128128
let param_env = normalize_param_env_or_error(tcx, param_env, ObligationCause::dummy());
129129

@@ -193,14 +193,14 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
193193
// too, since we *do not* use the trait solver to prove that the RPITIT's
194194
// bounds are not stronger -- we're doing a simple, syntactic compatibility
195195
// check between bounds. This is strictly forwards compatible, though.
196-
for (clause, span) in impl_bounds {
197-
if !trait_bounds.contains(&clause) {
196+
for clause in impl_bounds {
197+
if !trait_bounds.contains(&clause.node) {
198198
report_mismatched_rpitit_signature(
199199
tcx,
200200
trait_m_sig_with_self_for_diag,
201201
trait_m.def_id,
202202
impl_m.def_id,
203-
Some(span),
203+
Some(clause.span),
204204
);
205205
return;
206206
}
@@ -220,12 +220,12 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitCollector<'tcx> {
220220
&& self.tcx.is_impl_trait_in_trait(proj.def_id)
221221
{
222222
if self.types.insert(proj) {
223-
for (pred, _) in self
223+
for pred in self
224224
.tcx
225225
.explicit_item_bounds(proj.def_id)
226226
.iter_instantiated_copied(self.tcx, proj.args)
227227
{
228-
pred.visit_with(self)?;
228+
pred.node.visit_with(self)?;
229229
}
230230
}
231231
ControlFlow::Continue(())
@@ -267,7 +267,7 @@ fn report_mismatched_rpitit_signature<'tcx>(
267267
let Some(future_output_ty) = tcx
268268
.explicit_item_bounds(future_ty.def_id)
269269
.iter_instantiated_copied(tcx, future_ty.args)
270-
.find_map(|(clause, _)| match clause.kind().no_bound_vars()? {
270+
.find_map(|clause| match clause.node.kind().no_bound_vars()? {
271271
ty::ClauseKind::Projection(proj) => proj.term.ty(),
272272
_ => None,
273273
})

compiler/rustc_hir_analysis/src/check/dropck.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
132132
let param_env =
133133
ty::EarlyBinder::bind(tcx.param_env(adt_def_id)).instantiate(tcx, adt_to_impl_args);
134134

135-
for (pred, span) in tcx.predicates_of(drop_impl_def_id).instantiate_identity(tcx) {
135+
for ty::Spanned { node: pred, span } in
136+
tcx.predicates_of(drop_impl_def_id).instantiate_identity(tcx)
137+
{
136138
let normalize_cause = traits::ObligationCause::misc(span, adt_def_id);
137139
let pred = ocx.normalize(&normalize_cause, param_env, pred);
138140
let cause = traits::ObligationCause::new(span, adt_def_id, traits::DropImpl);

compiler/rustc_hir_analysis/src/check/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -305,13 +305,13 @@ fn default_body_is_unstable(
305305
/// Re-sugar `ty::GenericPredicates` in a way suitable to be used in structured suggestions.
306306
fn bounds_from_generic_predicates<'tcx>(
307307
tcx: TyCtxt<'tcx>,
308-
predicates: impl IntoIterator<Item = (ty::Clause<'tcx>, Span)>,
308+
predicates: impl IntoIterator<Item = ty::Spanned<ty::Clause<'tcx>>>,
309309
) -> (String, String) {
310310
let mut types: FxHashMap<Ty<'tcx>, Vec<DefId>> = FxHashMap::default();
311311
let mut projections = vec![];
312-
for (predicate, _) in predicates {
313-
debug!("predicate {:?}", predicate);
314-
let bound_predicate = predicate.kind();
312+
for predicate in predicates {
313+
debug!("predicate {:?}", predicate.node);
314+
let bound_predicate = predicate.node.kind();
315315
match bound_predicate.skip_binder() {
316316
ty::ClauseKind::Trait(trait_predicate) => {
317317
let entry = types.entry(trait_predicate.self_ty()).or_default();
@@ -382,7 +382,7 @@ fn fn_sig_suggestion<'tcx>(
382382
tcx: TyCtxt<'tcx>,
383383
sig: ty::FnSig<'tcx>,
384384
ident: Ident,
385-
predicates: impl IntoIterator<Item = (ty::Clause<'tcx>, Span)>,
385+
predicates: impl IntoIterator<Item = ty::Spanned<ty::Clause<'tcx>>>,
386386
assoc: ty::AssocItem,
387387
) -> String {
388388
let args = sig
@@ -429,7 +429,7 @@ fn fn_sig_suggestion<'tcx>(
429429
output = if let ty::Alias(_, alias_ty) = *output.kind() {
430430
tcx.explicit_item_bounds(alias_ty.def_id)
431431
.iter_instantiated_copied(tcx, alias_ty.args)
432-
.find_map(|(bound, _)| bound.as_projection_clause()?.no_bound_vars()?.term.ty())
432+
.find_map(|bound| bound.node.as_projection_clause()?.no_bound_vars()?.term.ty())
433433
.unwrap_or_else(|| {
434434
span_bug!(
435435
ident.span,

0 commit comments

Comments
 (0)