Skip to content

Commit 17e1f23

Browse files
authored
Rollup merge of rust-lang#64817 - csmoe:closure, r=nikomatsakis
Replace ClosureSubsts with SubstsRef Addresses rust-lang#42340 part 3 rust-lang#59312 might benefit from this clean up. r? @nikomatsakis
2 parents 314fbf4 + 9b91bef commit 17e1f23

File tree

51 files changed

+151
-142
lines changed

Some content is hidden

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

51 files changed

+151
-142
lines changed

src/librustc/infer/error_reporting/need_type_info.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
220220

221221
let ty_msg = match local_visitor.found_ty {
222222
Some(ty::TyS { kind: ty::Closure(def_id, substs), .. }) => {
223-
let fn_sig = substs.closure_sig(*def_id, self.tcx);
223+
let fn_sig = substs.as_closure().sig(*def_id, self.tcx);
224224
let args = closure_args(&fn_sig);
225225
let ret = fn_sig.output().skip_binder().to_string();
226226
format!(" for the closure `fn({}) -> {}`", args, ret)
@@ -255,7 +255,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
255255

256256
let suffix = match local_visitor.found_ty {
257257
Some(ty::TyS { kind: ty::Closure(def_id, substs), .. }) => {
258-
let fn_sig = substs.closure_sig(*def_id, self.tcx);
258+
let fn_sig = substs.as_closure().sig(*def_id, self.tcx);
259259
let ret = fn_sig.output().skip_binder().to_string();
260260

261261
if let Some(ExprKind::Closure(_, decl, body_id, ..)) = local_visitor.found_closure {

src/librustc/infer/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,9 +1504,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
15041504
pub fn closure_kind(
15051505
&self,
15061506
closure_def_id: DefId,
1507-
closure_substs: ty::ClosureSubsts<'tcx>,
1507+
closure_substs: SubstsRef<'tcx>,
15081508
) -> Option<ty::ClosureKind> {
1509-
let closure_kind_ty = closure_substs.closure_kind_ty(closure_def_id, self.tcx);
1509+
let closure_kind_ty = closure_substs.as_closure().kind_ty(closure_def_id, self.tcx);
15101510
let closure_kind_ty = self.shallow_resolve(closure_kind_ty);
15111511
closure_kind_ty.to_opt_closure_kind()
15121512
}
@@ -1518,9 +1518,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
15181518
pub fn closure_sig(
15191519
&self,
15201520
def_id: DefId,
1521-
substs: ty::ClosureSubsts<'tcx>,
1521+
substs: SubstsRef<'tcx>,
15221522
) -> ty::PolyFnSig<'tcx> {
1523-
let closure_sig_ty = substs.closure_sig_ty(def_id, self.tcx);
1523+
let closure_sig_ty = substs.as_closure().sig_ty(def_id, self.tcx);
15241524
let closure_sig_ty = self.shallow_resolve(closure_sig_ty);
15251525
closure_sig_ty.fn_sig(self.tcx)
15261526
}

src/librustc/infer/opaque_types/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -722,11 +722,11 @@ where
722722
ty::Closure(def_id, ref substs) => {
723723
// Skip lifetime parameters of the enclosing item(s)
724724

725-
for upvar_ty in substs.upvar_tys(def_id, self.tcx) {
725+
for upvar_ty in substs.as_closure().upvar_tys(def_id, self.tcx) {
726726
upvar_ty.visit_with(self);
727727
}
728728

729-
substs.closure_sig_ty(def_id, self.tcx).visit_with(self);
729+
substs.as_closure().sig_ty(def_id, self.tcx).visit_with(self);
730730
}
731731

732732
ty::Generator(def_id, ref substs, _) => {
@@ -886,7 +886,7 @@ impl TypeFolder<'tcx> for ReverseMapper<'tcx> {
886886

887887
let generics = self.tcx.generics_of(def_id);
888888
let substs =
889-
self.tcx.mk_substs(substs.substs.iter().enumerate().map(|(index, &kind)| {
889+
self.tcx.mk_substs(substs.iter().enumerate().map(|(index, &kind)| {
890890
if index < generics.parent_count {
891891
// Accommodate missing regions in the parent kinds...
892892
self.fold_kind_mapping_missing_regions_to_empty(kind)
@@ -896,7 +896,7 @@ impl TypeFolder<'tcx> for ReverseMapper<'tcx> {
896896
}
897897
}));
898898

899-
self.tcx.mk_closure(def_id, ty::ClosureSubsts { substs })
899+
self.tcx.mk_closure(def_id, substs)
900900
}
901901

902902
ty::Generator(def_id, substs, movability) => {

src/librustc/middle/mem_categorization.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -740,16 +740,18 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
740740
let ty = self.node_ty(fn_hir_id)?;
741741
let kind = match ty.kind {
742742
ty::Generator(..) => ty::ClosureKind::FnOnce,
743-
ty::Closure(closure_def_id, closure_substs) => {
743+
ty::Closure(closure_def_id, substs) => {
744744
match self.infcx {
745745
// During upvar inference we may not know the
746746
// closure kind, just use the LATTICE_BOTTOM value.
747747
Some(infcx) =>
748-
infcx.closure_kind(closure_def_id, closure_substs)
749-
.unwrap_or(ty::ClosureKind::LATTICE_BOTTOM),
748+
infcx.closure_kind(
749+
closure_def_id,
750+
substs
751+
).unwrap_or(ty::ClosureKind::LATTICE_BOTTOM),
750752

751753
None =>
752-
closure_substs.closure_kind(closure_def_id, self.tcx),
754+
substs.as_closure().kind(closure_def_id, self.tcx),
753755
}
754756
}
755757
_ => span_bug!(span, "unexpected type for fn in mem_categorization: {:?}", ty),

src/librustc/mir/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::ty::layout::VariantIdx;
1515
use crate::ty::print::{FmtPrinter, Printer};
1616
use crate::ty::subst::{Subst, SubstsRef};
1717
use crate::ty::{
18-
self, AdtDef, CanonicalUserTypeAnnotations, ClosureSubsts, GeneratorSubsts, Region, Ty, TyCtxt,
18+
self, AdtDef, CanonicalUserTypeAnnotations, GeneratorSubsts, Region, Ty, TyCtxt,
1919
UserTypeAnnotationIndex,
2020
};
2121

@@ -2188,7 +2188,7 @@ pub enum AggregateKind<'tcx> {
21882188
/// active field index would identity the field `c`
21892189
Adt(&'tcx AdtDef, VariantIdx, SubstsRef<'tcx>, Option<UserTypeAnnotationIndex>, Option<usize>),
21902190

2191-
Closure(DefId, ClosureSubsts<'tcx>),
2191+
Closure(DefId, SubstsRef<'tcx>),
21922192
Generator(DefId, GeneratorSubsts<'tcx>, hir::GeneratorMovability),
21932193
}
21942194

src/librustc/mir/visit.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::ty::subst::SubstsRef;
2-
use crate::ty::{CanonicalUserTypeAnnotation, ClosureSubsts, GeneratorSubsts, Ty};
2+
use crate::ty::{CanonicalUserTypeAnnotation, GeneratorSubsts, Ty};
33
use crate::mir::*;
44
use syntax_pos::Span;
55

@@ -230,12 +230,6 @@ macro_rules! make_mir_visitor {
230230
self.super_substs(substs);
231231
}
232232

233-
fn visit_closure_substs(&mut self,
234-
substs: & $($mutability)? ClosureSubsts<'tcx>,
235-
_: Location) {
236-
self.super_closure_substs(substs);
237-
}
238-
239233
fn visit_generator_substs(&mut self,
240234
substs: & $($mutability)? GeneratorSubsts<'tcx>,
241235
_: Location) {
@@ -627,7 +621,7 @@ macro_rules! make_mir_visitor {
627621
_,
628622
closure_substs
629623
) => {
630-
self.visit_closure_substs(closure_substs, location);
624+
self.visit_substs(closure_substs, location);
631625
}
632626
AggregateKind::Generator(
633627
_,
@@ -856,10 +850,6 @@ macro_rules! make_mir_visitor {
856850
_substs: & $($mutability)? GeneratorSubsts<'tcx>) {
857851
}
858852

859-
fn super_closure_substs(&mut self,
860-
_substs: & $($mutability)? ClosureSubsts<'tcx>) {
861-
}
862-
863853
// Convenience methods
864854

865855
fn visit_location(&mut self, body: & $($mutability)? Body<'tcx>, location: Location) {

src/librustc/traits/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ pub struct VtableGeneratorData<'tcx, N> {
619619
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)]
620620
pub struct VtableClosureData<'tcx, N> {
621621
pub closure_def_id: DefId,
622-
pub substs: ty::ClosureSubsts<'tcx>,
622+
pub substs: SubstsRef<'tcx>,
623623
/// Nested obligations. This can be non-empty if the closure
624624
/// signature contains associated types.
625625
pub nested: Vec<N>

src/librustc/traits/project.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,8 @@ fn confirm_closure_candidate<'cx, 'tcx>(
13341334
) -> Progress<'tcx> {
13351335
let tcx = selcx.tcx();
13361336
let infcx = selcx.infcx();
1337-
let closure_sig_ty = vtable.substs.closure_sig_ty(vtable.closure_def_id, tcx);
1337+
let closure_sig_ty = vtable.substs
1338+
.as_closure().sig_ty(vtable.closure_def_id, tcx);
13381339
let closure_sig = infcx.shallow_resolve(closure_sig_ty).fn_sig(tcx);
13391340
let Normalized {
13401341
value: closure_sig,

src/librustc/traits/query/dropck_outlives.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
213213
// check if *any* of those are trivial.
214214
ty::Tuple(ref tys) => tys.iter().all(|t| trivial_dropck_outlives(tcx, t.expect_ty())),
215215
ty::Closure(def_id, ref substs) => substs
216+
.as_closure()
216217
.upvar_tys(def_id, tcx)
217218
.all(|t| trivial_dropck_outlives(tcx, t)),
218219

src/librustc/traits/select.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2051,7 +2051,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
20512051
"assemble_unboxed_candidates: kind={:?} obligation={:?}",
20522052
kind, obligation
20532053
);
2054-
match self.infcx.closure_kind(closure_def_id, closure_substs) {
2054+
match self.infcx.closure_kind(
2055+
closure_def_id,
2056+
closure_substs
2057+
) {
20552058
Some(closure_kind) => {
20562059
debug!(
20572060
"assemble_unboxed_candidates: closure_kind = {:?}",
@@ -2669,7 +2672,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
26692672
ty::Closure(def_id, substs) => {
26702673
// (*) binder moved here
26712674
Where(ty::Binder::bind(
2672-
substs.upvar_tys(def_id, self.tcx()).collect(),
2675+
substs.as_closure().upvar_tys(def_id, self.tcx()).collect(),
26732676
))
26742677
}
26752678

@@ -2753,7 +2756,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
27532756
tys.iter().map(|k| k.expect_ty()).collect()
27542757
}
27552758

2756-
ty::Closure(def_id, ref substs) => substs.upvar_tys(def_id, self.tcx()).collect(),
2759+
ty::Closure(def_id, ref substs) => substs.as_closure()
2760+
.upvar_tys(def_id, self.tcx())
2761+
.collect(),
27572762

27582763
ty::Generator(def_id, ref substs, _) => {
27592764
let witness = substs.witness(def_id, self.tcx());
@@ -3370,17 +3375,22 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
33703375
)?);
33713376

33723377
// FIXME: chalk
3378+
33733379
if !self.tcx().sess.opts.debugging_opts.chalk {
33743380
obligations.push(Obligation::new(
33753381
obligation.cause.clone(),
33763382
obligation.param_env,
3377-
ty::Predicate::ClosureKind(closure_def_id, substs, kind),
3383+
ty::Predicate::ClosureKind(
3384+
closure_def_id,
3385+
substs,
3386+
kind
3387+
),
33783388
));
33793389
}
33803390

33813391
Ok(VtableClosureData {
33823392
closure_def_id,
3383-
substs: substs.clone(),
3393+
substs: substs,
33843394
nested: obligations,
33853395
})
33863396
}
@@ -3869,7 +3879,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
38693879
&mut self,
38703880
obligation: &TraitObligation<'tcx>,
38713881
closure_def_id: DefId,
3872-
substs: ty::ClosureSubsts<'tcx>,
3882+
substs: SubstsRef<'tcx>,
38733883
) -> ty::PolyTraitRef<'tcx> {
38743884
debug!(
38753885
"closure_trait_ref_unnormalized(obligation={:?}, closure_def_id={:?}, substs={:?})",

0 commit comments

Comments
 (0)