Skip to content

Commit 9b91bef

Browse files
committed
generate ClosureSubsts from SubstsRef
1 parent 1f8e1d8 commit 9b91bef

File tree

45 files changed

+139
-216
lines changed

Some content is hidden

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

45 files changed

+139
-216
lines changed

Diff for: src/librustc/infer/error_reporting/need_type_info.rs

+2-2
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 = ty::ClosureSubsts::from_ref(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 {

Diff for: src/librustc/infer/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1481,9 +1481,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14811481
pub fn closure_kind(
14821482
&self,
14831483
closure_def_id: DefId,
1484-
closure_substs: ty::ClosureSubsts<'tcx>,
1484+
closure_substs: SubstsRef<'tcx>,
14851485
) -> Option<ty::ClosureKind> {
1486-
let closure_kind_ty = closure_substs.closure_kind_ty(closure_def_id, self.tcx);
1486+
let closure_kind_ty = closure_substs.as_closure().kind_ty(closure_def_id, self.tcx);
14871487
let closure_kind_ty = self.shallow_resolve(closure_kind_ty);
14881488
closure_kind_ty.to_opt_closure_kind()
14891489
}
@@ -1495,9 +1495,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14951495
pub fn closure_sig(
14961496
&self,
14971497
def_id: DefId,
1498-
substs: ty::ClosureSubsts<'tcx>,
1498+
substs: SubstsRef<'tcx>,
14991499
) -> ty::PolyFnSig<'tcx> {
1500-
let closure_sig_ty = substs.closure_sig_ty(def_id, self.tcx);
1500+
let closure_sig_ty = substs.as_closure().sig_ty(def_id, self.tcx);
15011501
let closure_sig_ty = self.shallow_resolve(closure_sig_ty);
15021502
closure_sig_ty.fn_sig(self.tcx)
15031503
}

Diff for: src/librustc/infer/opaque_types/mod.rs

+2-2
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 ty::ClosureSubsts::from_ref(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, _) => {

Diff for: src/librustc/middle/mem_categorization.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -740,17 +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,
749-
ty::ClosureSubsts::from_ref(closure_substs))
750-
.unwrap_or(ty::ClosureKind::LATTICE_BOTTOM),
748+
infcx.closure_kind(
749+
closure_def_id,
750+
substs
751+
).unwrap_or(ty::ClosureKind::LATTICE_BOTTOM),
751752

752753
None =>
753-
closure_substs.closure_kind(closure_def_id, self.tcx),
754+
substs.as_closure().kind(closure_def_id, self.tcx),
754755
}
755756
}
756757
_ => span_bug!(span, "unexpected type for fn in mem_categorization: {:?}", ty),

Diff for: src/librustc/mir/mod.rs

+2-2
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

Diff for: src/librustc/mir/tcx.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ impl<'tcx> Rvalue<'tcx> {
218218
tcx.type_of(def.did).subst(tcx, substs)
219219
}
220220
AggregateKind::Closure(did, substs) => {
221-
tcx.mk_closure(did, &substs.substs)
221+
tcx.mk_closure(did, substs)
222222
}
223223
AggregateKind::Generator(did, substs, movability) => {
224224
tcx.mk_generator(did, substs, movability)

Diff for: src/librustc/mir/visit.rs

+2-12
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

@@ -221,12 +221,6 @@ macro_rules! make_mir_visitor {
221221
self.super_substs(substs);
222222
}
223223

224-
fn visit_closure_substs(&mut self,
225-
substs: & $($mutability)? ClosureSubsts<'tcx>,
226-
_: Location) {
227-
self.super_closure_substs(substs);
228-
}
229-
230224
fn visit_generator_substs(&mut self,
231225
substs: & $($mutability)? GeneratorSubsts<'tcx>,
232226
_: Location) {
@@ -618,7 +612,7 @@ macro_rules! make_mir_visitor {
618612
_,
619613
closure_substs
620614
) => {
621-
self.visit_closure_substs(closure_substs, location);
615+
self.visit_substs(closure_substs, location);
622616
}
623617
AggregateKind::Generator(
624618
_,
@@ -838,10 +832,6 @@ macro_rules! make_mir_visitor {
838832
_substs: & $($mutability)? GeneratorSubsts<'tcx>) {
839833
}
840834

841-
fn super_closure_substs(&mut self,
842-
_substs: & $($mutability)? ClosureSubsts<'tcx>) {
843-
}
844-
845835
// Convenience methods
846836

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

Diff for: src/librustc/traits/mod.rs

+1-1
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>

Diff for: src/librustc/traits/project.rs

+2-1
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,

Diff for: src/librustc/traits/query/dropck_outlives.rs

+1
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

Diff for: src/librustc/traits/select.rs

+15-9
Original file line numberDiff line numberDiff line change
@@ -2051,8 +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,
2055-
ty::ClosureSubsts::from_ref(closure_substs)) {
2054+
match self.infcx.closure_kind(
2055+
closure_def_id,
2056+
closure_substs
2057+
) {
20562058
Some(closure_kind) => {
20572059
debug!(
20582060
"assemble_unboxed_candidates: closure_kind = {:?}",
@@ -2670,7 +2672,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
26702672
ty::Closure(def_id, substs) => {
26712673
// (*) binder moved here
26722674
Where(ty::Binder::bind(
2673-
substs.upvar_tys(def_id, self.tcx()).collect(),
2675+
substs.as_closure().upvar_tys(def_id, self.tcx()).collect(),
26742676
))
26752677
}
26762678

@@ -2754,7 +2756,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
27542756
tys.iter().map(|k| k.expect_ty()).collect()
27552757
}
27562758

2757-
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(),
27582762

27592763
ty::Generator(def_id, ref substs, _) => {
27602764
let witness = substs.witness(def_id, self.tcx());
@@ -3376,14 +3380,17 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
33763380
obligations.push(Obligation::new(
33773381
obligation.cause.clone(),
33783382
obligation.param_env,
3379-
ty::Predicate::ClosureKind(closure_def_id,
3380-
ty::ClosureSubsts::from_ref(substs.clone()), kind),
3383+
ty::Predicate::ClosureKind(
3384+
closure_def_id,
3385+
substs,
3386+
kind
3387+
),
33813388
));
33823389
}
33833390

33843391
Ok(VtableClosureData {
33853392
closure_def_id,
3386-
substs: ty::ClosureSubsts::from_ref(substs),
3393+
substs: substs,
33873394
nested: obligations,
33883395
})
33893396
}
@@ -3878,8 +3885,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
38783885
"closure_trait_ref_unnormalized(obligation={:?}, closure_def_id={:?}, substs={:?})",
38793886
obligation, closure_def_id, substs,
38803887
);
3881-
let closure_type = self.infcx.closure_sig(closure_def_id,
3882-
ty::ClosureSubsts::from_ref(substs));
3888+
let closure_type = self.infcx.closure_sig(closure_def_id, substs);
38833889

38843890
debug!(
38853891
"closure_trait_ref_unnormalized: closure_type = {:?}",

Diff for: src/librustc/ty/instance.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl<'tcx> Instance<'tcx> {
5959
// Shims currently have type FnPtr. Not sure this should remain.
6060
ty::FnPtr(_) => ty.fn_sig(tcx),
6161
ty::Closure(def_id, substs) => {
62-
let sig = substs.closure_sig(def_id, tcx);
62+
let sig = substs.as_closure().sig(def_id, tcx);
6363

6464
let env_ty = tcx.closure_env_ty(def_id, substs).unwrap();
6565
sig.map_bound(|sig| tcx.mk_fn_sig(
@@ -315,14 +315,14 @@ impl<'tcx> Instance<'tcx> {
315315
pub fn resolve_closure(
316316
tcx: TyCtxt<'tcx>,
317317
def_id: DefId,
318-
substs: ty::ClosureSubsts<'tcx>,
318+
substs: ty::SubstsRef<'tcx>,
319319
requested_kind: ty::ClosureKind,
320320
) -> Instance<'tcx> {
321-
let actual_kind = substs.closure_kind(def_id, tcx);
321+
let actual_kind = substs.as_closure().kind(def_id, tcx);
322322

323323
match needs_fn_once_adapter_shim(actual_kind, requested_kind) {
324-
Ok(true) => Instance::fn_once_adapter_instance(tcx, def_id, substs.substs),
325-
_ => Instance::new(def_id, substs.substs)
324+
Ok(true) => Instance::fn_once_adapter_instance(tcx, def_id, substs),
325+
_ => Instance::new(def_id, substs)
326326
}
327327
}
328328

@@ -348,7 +348,7 @@ impl<'tcx> Instance<'tcx> {
348348

349349
let self_ty = tcx.mk_closure(closure_did, substs);
350350

351-
let sig = substs.closure_sig(closure_did, tcx);
351+
let sig = substs.as_closure().sig(closure_did, tcx);
352352
let sig = tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
353353
assert_eq!(sig.inputs().len(), 1);
354354
let substs = tcx.mk_substs_trait(self_ty, &[sig.inputs()[0].into()]);

Diff for: src/librustc/ty/layout.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
674674
ty::Generator(def_id, substs, _) => self.generator_layout(ty, def_id, &substs)?,
675675

676676
ty::Closure(def_id, ref substs) => {
677-
let tys = substs.upvar_tys(def_id, tcx);
677+
let tys = substs.as_closure().upvar_tys(def_id, tcx);
678678
univariant(&tys.map(|ty| self.layout_of(ty)).collect::<Result<Vec<_>, _>>()?,
679679
&ReprOptions::default(),
680680
StructKind::AlwaysSized)?
@@ -2147,7 +2147,7 @@ where
21472147

21482148
// Tuples, generators and closures.
21492149
ty::Closure(def_id, ref substs) => {
2150-
substs.upvar_tys(def_id, tcx).nth(i).unwrap()
2150+
substs.as_closure().upvar_tys(def_id, tcx).nth(i).unwrap()
21512151
}
21522152

21532153
ty::Generator(def_id, ref substs, _) => {

Diff for: src/librustc/ty/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ pub enum Predicate<'tcx> {
11101110
/// No direct syntax. May be thought of as `where T: FnFoo<...>`
11111111
/// for some substitutions `...` and `T` being a closure type.
11121112
/// Satisfied (or refuted) once we know the closure's kind.
1113-
ClosureKind(DefId, ClosureSubsts<'tcx>, ClosureKind),
1113+
ClosureKind(DefId, SubstsRef<'tcx>, ClosureKind),
11141114

11151115
/// `T1 <: T2`
11161116
Subtype(PolySubtypePredicate<'tcx>),
@@ -1457,7 +1457,7 @@ impl<'tcx> Predicate<'tcx> {
14571457
WalkTysIter::None
14581458
}
14591459
ty::Predicate::ClosureKind(_closure_def_id, closure_substs, _kind) => {
1460-
WalkTysIter::Types(closure_substs.substs.types())
1460+
WalkTysIter::Types(closure_substs.types())
14611461
}
14621462
ty::Predicate::ConstEvaluatable(_, substs) => {
14631463
WalkTysIter::Types(substs.types())

Diff for: src/librustc/ty/outlives.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<'tcx> TyCtxt<'tcx> {
6262
// projection).
6363
match ty.kind {
6464
ty::Closure(def_id, ref substs) => {
65-
for upvar_ty in substs.upvar_tys(def_id, *self) {
65+
for upvar_ty in substs.as_closure().upvar_tys(def_id, *self) {
6666
self.compute_components(upvar_ty, out);
6767
}
6868
}

Diff for: src/librustc/ty/print/obsolete.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,8 @@ impl DefPathBasedNames<'tcx> {
154154
self.push_type_name(sig.output(), output, debug);
155155
}
156156
}
157-
ty::Generator(def_id, GeneratorSubsts { ref substs }, _) => {
158-
self.push_def_path(def_id, output);
159-
let generics = self.tcx.generics_of(self.tcx.closure_base_def_id(def_id));
160-
let substs = substs.truncate_to(self.tcx, generics);
161-
self.push_generic_params(substs, iter::empty(), output, debug);
162-
}
163-
ty::Closure(def_id, substs) => {
157+
ty::Generator(def_id, GeneratorSubsts { substs }, _)
158+
| ty::Closure(def_id, substs) => {
164159
self.push_def_path(def_id, output);
165160
let generics = self.tcx.generics_of(self.tcx.closure_base_def_id(def_id));
166161
let substs = substs.truncate_to(self.tcx, generics);

Diff for: src/librustc/ty/print/pretty.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ pub trait PrettyPrinter<'tcx>:
649649
p!(in_binder(&types));
650650
}
651651
ty::Closure(did, substs) => {
652-
let upvar_tys = substs.upvar_tys(did, self.tcx());
652+
let upvar_tys = substs.as_closure().upvar_tys(did, self.tcx());
653653
p!(write("[closure"));
654654

655655
// FIXME(eddyb) should use `def_span`.
@@ -689,8 +689,8 @@ pub trait PrettyPrinter<'tcx>:
689689
if self.tcx().sess.verbose() {
690690
p!(write(
691691
" closure_kind_ty={:?} closure_sig_ty={:?}",
692-
substs.closure_kind_ty(did, self.tcx()),
693-
substs.closure_sig_ty(did, self.tcx())
692+
substs.as_closure().kind(did, self.tcx()),
693+
substs.as_closure().sig_ty(did, self.tcx())
694694
));
695695
}
696696

0 commit comments

Comments
 (0)