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

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 = 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 {

src/librustc/infer/mod.rs

Lines changed: 4 additions & 4 deletions
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
}

src/librustc/infer/opaque_types/mod.rs

Lines changed: 2 additions & 2 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 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, _) => {

src/librustc/middle/mem_categorization.rs

Lines changed: 6 additions & 5 deletions
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),

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/tcx.rs

Lines changed: 1 addition & 1 deletion
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)

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

@@ -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) {

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

0 commit comments

Comments
 (0)