Skip to content

Commit a9ffe67

Browse files
committed
Auto merge of #31606 - Ms2ger:ClosureKind, r=eddyb
Rename ClosureKind variants and stop re-exporting them.
2 parents 8b7c3f2 + c6474af commit a9ffe67

File tree

11 files changed

+56
-57
lines changed

11 files changed

+56
-57
lines changed

src/librustc/middle/lang_items.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ impl LanguageItems {
120120

121121
pub fn fn_trait_kind(&self, id: DefId) -> Option<ty::ClosureKind> {
122122
let def_id_kinds = [
123-
(self.fn_trait(), ty::FnClosureKind),
124-
(self.fn_mut_trait(), ty::FnMutClosureKind),
125-
(self.fn_once_trait(), ty::FnOnceClosureKind),
123+
(self.fn_trait(), ty::ClosureKind::Fn),
124+
(self.fn_mut_trait(), ty::ClosureKind::FnMut),
125+
(self.fn_once_trait(), ty::ClosureKind::FnOnce),
126126
];
127127

128128
for &(opt_def_id, kind) in &def_id_kinds {

src/librustc/middle/mem_categorization.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -670,13 +670,13 @@ impl<'t, 'a,'tcx> MemCategorizationContext<'t, 'a, 'tcx> {
670670
// conceptually a `&mut` or `&` reference, so we have to add a
671671
// deref.
672672
let cmt_result = match kind {
673-
ty::FnOnceClosureKind => {
673+
ty::ClosureKind::FnOnce => {
674674
cmt_result
675675
}
676-
ty::FnMutClosureKind => {
676+
ty::ClosureKind::FnMut => {
677677
self.env_deref(id, span, upvar_id, var_mutbl, ty::MutBorrow, cmt_result)
678678
}
679-
ty::FnClosureKind => {
679+
ty::ClosureKind::Fn => {
680680
self.env_deref(id, span, upvar_id, var_mutbl, ty::ImmBorrow, cmt_result)
681681
}
682682
};
@@ -1630,9 +1630,9 @@ impl fmt::Debug for Upvar {
16301630
impl fmt::Display for Upvar {
16311631
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
16321632
let kind = match self.kind {
1633-
ty::FnClosureKind => "Fn",
1634-
ty::FnMutClosureKind => "FnMut",
1635-
ty::FnOnceClosureKind => "FnOnce",
1633+
ty::ClosureKind::Fn => "Fn",
1634+
ty::ClosureKind::FnMut => "FnMut",
1635+
ty::ClosureKind::FnOnce => "FnOnce",
16361636
};
16371637
write!(f, "captured outer variable in an `{}` closure", kind)
16381638
}

src/librustc/middle/ty/mod.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
pub use self::ImplOrTraitItemId::*;
12-
pub use self::ClosureKind::*;
1312
pub use self::Variance::*;
1413
pub use self::DtorKind::*;
1514
pub use self::ImplOrTraitItemContainer::*;
@@ -1699,19 +1698,19 @@ pub enum ClosureKind {
16991698
// Warning: Ordering is significant here! The ordering is chosen
17001699
// because the trait Fn is a subtrait of FnMut and so in turn, and
17011700
// hence we order it so that Fn < FnMut < FnOnce.
1702-
FnClosureKind,
1703-
FnMutClosureKind,
1704-
FnOnceClosureKind,
1701+
Fn,
1702+
FnMut,
1703+
FnOnce,
17051704
}
17061705

17071706
impl ClosureKind {
17081707
pub fn trait_did(&self, cx: &TyCtxt) -> DefId {
17091708
let result = match *self {
1710-
FnClosureKind => cx.lang_items.require(FnTraitLangItem),
1711-
FnMutClosureKind => {
1709+
ClosureKind::Fn => cx.lang_items.require(FnTraitLangItem),
1710+
ClosureKind::FnMut => {
17121711
cx.lang_items.require(FnMutTraitLangItem)
17131712
}
1714-
FnOnceClosureKind => {
1713+
ClosureKind::FnOnce => {
17151714
cx.lang_items.require(FnOnceTraitLangItem)
17161715
}
17171716
};
@@ -1725,12 +1724,12 @@ impl ClosureKind {
17251724
/// must also implement `other`.
17261725
pub fn extends(self, other: ty::ClosureKind) -> bool {
17271726
match (self, other) {
1728-
(FnClosureKind, FnClosureKind) => true,
1729-
(FnClosureKind, FnMutClosureKind) => true,
1730-
(FnClosureKind, FnOnceClosureKind) => true,
1731-
(FnMutClosureKind, FnMutClosureKind) => true,
1732-
(FnMutClosureKind, FnOnceClosureKind) => true,
1733-
(FnOnceClosureKind, FnOnceClosureKind) => true,
1727+
(ClosureKind::Fn, ClosureKind::Fn) => true,
1728+
(ClosureKind::Fn, ClosureKind::FnMut) => true,
1729+
(ClosureKind::Fn, ClosureKind::FnOnce) => true,
1730+
(ClosureKind::FnMut, ClosureKind::FnMut) => true,
1731+
(ClosureKind::FnMut, ClosureKind::FnOnce) => true,
1732+
(ClosureKind::FnOnce, ClosureKind::FnOnce) => true,
17341733
_ => false,
17351734
}
17361735
}

src/librustc_borrowck/borrowck/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
10091009
Categorization::Upvar(mc::Upvar { kind, .. }) => kind,
10101010
_ => unreachable!()
10111011
};
1012-
if kind == ty::FnClosureKind {
1012+
if kind == ty::ClosureKind::Fn {
10131013
db.span_help(
10141014
self.tcx.map.span(upvar_id.closure_expr_id),
10151015
"consider changing this closure to take \

src/librustc_mir/hair/cx/expr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ fn convert_var<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>,
725725
let region = cx.tcx.mk_region(region);
726726

727727
let self_expr = match cx.tcx.closure_kind(cx.tcx.map.local_def_id(closure_expr_id)) {
728-
ty::ClosureKind::FnClosureKind => {
728+
ty::ClosureKind::Fn => {
729729
let ref_closure_ty =
730730
cx.tcx.mk_ref(region,
731731
ty::TypeAndMut { ty: closure_ty,
@@ -744,7 +744,7 @@ fn convert_var<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>,
744744
}
745745
}
746746
}
747-
ty::ClosureKind::FnMutClosureKind => {
747+
ty::ClosureKind::FnMut => {
748748
let ref_closure_ty =
749749
cx.tcx.mk_ref(region,
750750
ty::TypeAndMut { ty: closure_ty,
@@ -763,7 +763,7 @@ fn convert_var<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>,
763763
}
764764
}
765765
}
766-
ty::ClosureKind::FnOnceClosureKind => {
766+
ty::ClosureKind::FnOnce => {
767767
Expr {
768768
ty: closure_ty,
769769
temp_lifetime: temp_lifetime,

src/librustc_mir/mir_map.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -252,15 +252,15 @@ fn closure_self_ty<'a, 'tcx>(tcx: &TyCtxt<'tcx>,
252252
let region = tcx.mk_region(region);
253253

254254
match tcx.closure_kind(tcx.map.local_def_id(closure_expr_id)) {
255-
ty::ClosureKind::FnClosureKind =>
255+
ty::ClosureKind::Fn =>
256256
tcx.mk_ref(region,
257257
ty::TypeAndMut { ty: closure_ty,
258258
mutbl: hir::MutImmutable }),
259-
ty::ClosureKind::FnMutClosureKind =>
259+
ty::ClosureKind::FnMut =>
260260
tcx.mk_ref(region,
261261
ty::TypeAndMut { ty: closure_ty,
262262
mutbl: hir::MutMutable }),
263-
ty::ClosureKind::FnOnceClosureKind =>
263+
ty::ClosureKind::FnOnce =>
264264
closure_ty
265265
}
266266
}

src/librustc_trans/trans/base.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,13 @@ pub fn self_type_for_closure<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
216216
-> Ty<'tcx> {
217217
let closure_kind = ccx.tcx().closure_kind(closure_id);
218218
match closure_kind {
219-
ty::FnClosureKind => {
219+
ty::ClosureKind::Fn => {
220220
ccx.tcx().mk_imm_ref(ccx.tcx().mk_region(ty::ReStatic), fn_ty)
221221
}
222-
ty::FnMutClosureKind => {
222+
ty::ClosureKind::FnMut => {
223223
ccx.tcx().mk_mut_ref(ccx.tcx().mk_region(ty::ReStatic), fn_ty)
224224
}
225-
ty::FnOnceClosureKind => fn_ty,
225+
ty::ClosureKind::FnOnce => fn_ty,
226226
}
227227
}
228228

src/librustc_trans/trans/callee.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ pub fn trans_fn_pointer_shim<'a, 'tcx>(
270270

271271
// If this is an impl of `Fn` or `FnMut` trait, the receiver is `&self`.
272272
let is_by_ref = match closure_kind {
273-
ty::FnClosureKind | ty::FnMutClosureKind => true,
274-
ty::FnOnceClosureKind => false,
273+
ty::ClosureKind::Fn | ty::ClosureKind::FnMut => true,
274+
ty::ClosureKind::FnOnce => false,
275275
};
276276
let bare_fn_ty_maybe_ref = if is_by_ref {
277277
tcx.mk_imm_ref(tcx.mk_region(ty::ReStatic), bare_fn_ty)

src/librustc_trans/trans/closure.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fn load_closure_environment<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
4949
let closure_ty = node_id_type(bcx, bcx.fcx.id);
5050
let self_type = self_type_for_closure(bcx.ccx(), closure_def_id, closure_ty);
5151
let kind = kind_for_closure(bcx.ccx(), closure_def_id);
52-
let llenv = if kind == ty::FnOnceClosureKind &&
52+
let llenv = if kind == ty::ClosureKind::FnOnce &&
5353
!arg_is_indirect(bcx.ccx(), self_type) {
5454
let datum = rvalue_scratch_datum(bcx,
5555
self_type,
@@ -85,7 +85,7 @@ fn load_closure_environment<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
8585
let node_id = freevar.def.var_id();
8686
bcx.fcx.llupvars.borrow_mut().insert(node_id, upvar_ptr);
8787

88-
if kind == ty::FnOnceClosureKind && !captured_by_ref {
88+
if kind == ty::ClosureKind::FnOnce && !captured_by_ref {
8989
let hint = bcx.fcx.lldropflag_hints.borrow().hint_datum(upvar_id.var_id);
9090
bcx.fcx.schedule_drop_mem(arg_scope_id,
9191
upvar_ptr,
@@ -300,20 +300,20 @@ fn trans_closure_adapter_shim<'a, 'tcx>(
300300
ccx.tn().val_to_string(llfn));
301301

302302
match (llfn_closure_kind, trait_closure_kind) {
303-
(ty::FnClosureKind, ty::FnClosureKind) |
304-
(ty::FnMutClosureKind, ty::FnMutClosureKind) |
305-
(ty::FnOnceClosureKind, ty::FnOnceClosureKind) => {
303+
(ty::ClosureKind::Fn, ty::ClosureKind::Fn) |
304+
(ty::ClosureKind::FnMut, ty::ClosureKind::FnMut) |
305+
(ty::ClosureKind::FnOnce, ty::ClosureKind::FnOnce) => {
306306
// No adapter needed.
307307
llfn
308308
}
309-
(ty::FnClosureKind, ty::FnMutClosureKind) => {
309+
(ty::ClosureKind::Fn, ty::ClosureKind::FnMut) => {
310310
// The closure fn `llfn` is a `fn(&self, ...)`. We want a
311311
// `fn(&mut self, ...)`. In fact, at trans time, these are
312312
// basically the same thing, so we can just return llfn.
313313
llfn
314314
}
315-
(ty::FnClosureKind, ty::FnOnceClosureKind) |
316-
(ty::FnMutClosureKind, ty::FnOnceClosureKind) => {
315+
(ty::ClosureKind::Fn, ty::ClosureKind::FnOnce) |
316+
(ty::ClosureKind::FnMut, ty::ClosureKind::FnOnce) => {
317317
// The closure fn `llfn` is a `fn(&self, ...)` or `fn(&mut
318318
// self, ...)`. We want a `fn(self, ...)`. We can produce
319319
// this by doing something like:

src/librustc_typeck/check/method/probe.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -697,11 +697,11 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
697697
// Check if this is one of the Fn,FnMut,FnOnce traits.
698698
let tcx = self.tcx();
699699
let kind = if Some(trait_def_id) == tcx.lang_items.fn_trait() {
700-
ty::FnClosureKind
700+
ty::ClosureKind::Fn
701701
} else if Some(trait_def_id) == tcx.lang_items.fn_mut_trait() {
702-
ty::FnMutClosureKind
702+
ty::ClosureKind::FnMut
703703
} else if Some(trait_def_id) == tcx.lang_items.fn_once_trait() {
704-
ty::FnOnceClosureKind
704+
ty::ClosureKind::FnOnce
705705
} else {
706706
return Ok(());
707707
};

src/librustc_typeck/check/upvar.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl<'a,'tcx> SeedBorrowKind<'a,'tcx> {
131131
if !self.fcx.inh.tables.borrow().closure_kinds.contains_key(&closure_def_id) {
132132
self.closures_with_inferred_kinds.insert(expr.id);
133133
self.fcx.inh.tables.borrow_mut().closure_kinds
134-
.insert(closure_def_id, ty::FnClosureKind);
134+
.insert(closure_def_id, ty::ClosureKind::Fn);
135135
debug!("check_closure: adding closure_id={:?} to closures_with_inferred_kinds",
136136
closure_def_id);
137137
}
@@ -301,7 +301,7 @@ impl<'a,'tcx> AdjustBorrowKind<'a,'tcx> {
301301
upvar_id);
302302

303303
// to move out of an upvar, this must be a FnOnce closure
304-
self.adjust_closure_kind(upvar_id.closure_expr_id, ty::FnOnceClosureKind);
304+
self.adjust_closure_kind(upvar_id.closure_expr_id, ty::ClosureKind::FnOnce);
305305

306306
let upvar_capture_map =
307307
&mut self.fcx.inh.tables.borrow_mut().upvar_capture_map;
@@ -314,7 +314,7 @@ impl<'a,'tcx> AdjustBorrowKind<'a,'tcx> {
314314
// must still adjust the kind of the closure
315315
// to be a FnOnce closure to permit moves out
316316
// of the environment.
317-
self.adjust_closure_kind(upvar_id.closure_expr_id, ty::FnOnceClosureKind);
317+
self.adjust_closure_kind(upvar_id.closure_expr_id, ty::ClosureKind::FnOnce);
318318
}
319319
mc::NoteNone => {
320320
}
@@ -418,15 +418,15 @@ impl<'a,'tcx> AdjustBorrowKind<'a,'tcx> {
418418
}
419419

420420
// also need to be in an FnMut closure since this is not an ImmBorrow
421-
self.adjust_closure_kind(upvar_id.closure_expr_id, ty::FnMutClosureKind);
421+
self.adjust_closure_kind(upvar_id.closure_expr_id, ty::ClosureKind::FnMut);
422422

423423
true
424424
}
425425
mc::NoteClosureEnv(upvar_id) => {
426426
// this kind of deref occurs in a `move` closure, or
427427
// for a by-value upvar; in either case, to mutate an
428428
// upvar, we need to be an FnMut closure
429-
self.adjust_closure_kind(upvar_id.closure_expr_id, ty::FnMutClosureKind);
429+
self.adjust_closure_kind(upvar_id.closure_expr_id, ty::ClosureKind::FnMut);
430430

431431
true
432432
}
@@ -488,16 +488,16 @@ impl<'a,'tcx> AdjustBorrowKind<'a,'tcx> {
488488
closure_id, existing_kind, new_kind);
489489

490490
match (existing_kind, new_kind) {
491-
(ty::FnClosureKind, ty::FnClosureKind) |
492-
(ty::FnMutClosureKind, ty::FnClosureKind) |
493-
(ty::FnMutClosureKind, ty::FnMutClosureKind) |
494-
(ty::FnOnceClosureKind, _) => {
491+
(ty::ClosureKind::Fn, ty::ClosureKind::Fn) |
492+
(ty::ClosureKind::FnMut, ty::ClosureKind::Fn) |
493+
(ty::ClosureKind::FnMut, ty::ClosureKind::FnMut) |
494+
(ty::ClosureKind::FnOnce, _) => {
495495
// no change needed
496496
}
497497

498-
(ty::FnClosureKind, ty::FnMutClosureKind) |
499-
(ty::FnClosureKind, ty::FnOnceClosureKind) |
500-
(ty::FnMutClosureKind, ty::FnOnceClosureKind) => {
498+
(ty::ClosureKind::Fn, ty::ClosureKind::FnMut) |
499+
(ty::ClosureKind::Fn, ty::ClosureKind::FnOnce) |
500+
(ty::ClosureKind::FnMut, ty::ClosureKind::FnOnce) => {
501501
// new kind is stronger than the old kind
502502
closure_kinds.insert(closure_def_id, new_kind);
503503
}

0 commit comments

Comments
 (0)