Skip to content

Commit c6474af

Browse files
committed
Rename ClosureKind variants and stop re-exporting them.
1 parent 77f9231 commit c6474af

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
@@ -669,13 +669,13 @@ impl<'t, 'a,'tcx> MemCategorizationContext<'t, 'a, 'tcx> {
669669
// conceptually a `&mut` or `&` reference, so we have to add a
670670
// deref.
671671
let cmt_result = match kind {
672-
ty::FnOnceClosureKind => {
672+
ty::ClosureKind::FnOnce => {
673673
cmt_result
674674
}
675-
ty::FnMutClosureKind => {
675+
ty::ClosureKind::FnMut => {
676676
self.env_deref(id, span, upvar_id, var_mutbl, ty::MutBorrow, cmt_result)
677677
}
678-
ty::FnClosureKind => {
678+
ty::ClosureKind::Fn => {
679679
self.env_deref(id, span, upvar_id, var_mutbl, ty::ImmBorrow, cmt_result)
680680
}
681681
};
@@ -1633,9 +1633,9 @@ impl fmt::Debug for Upvar {
16331633
impl fmt::Display for Upvar {
16341634
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
16351635
let kind = match self.kind {
1636-
ty::FnClosureKind => "Fn",
1637-
ty::FnMutClosureKind => "FnMut",
1638-
ty::FnOnceClosureKind => "FnOnce",
1636+
ty::ClosureKind::Fn => "Fn",
1637+
ty::ClosureKind::FnMut => "FnMut",
1638+
ty::ClosureKind::FnOnce => "FnOnce",
16391639
};
16401640
write!(f, "captured outer variable in an `{}` closure", kind)
16411641
}

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::*;
@@ -1693,19 +1692,19 @@ pub enum ClosureKind {
16931692
// Warning: Ordering is significant here! The ordering is chosen
16941693
// because the trait Fn is a subtrait of FnMut and so in turn, and
16951694
// hence we order it so that Fn < FnMut < FnOnce.
1696-
FnClosureKind,
1697-
FnMutClosureKind,
1698-
FnOnceClosureKind,
1695+
Fn,
1696+
FnMut,
1697+
FnOnce,
16991698
}
17001699

17011700
impl ClosureKind {
17021701
pub fn trait_did(&self, cx: &ctxt) -> DefId {
17031702
let result = match *self {
1704-
FnClosureKind => cx.lang_items.require(FnTraitLangItem),
1705-
FnMutClosureKind => {
1703+
ClosureKind::Fn => cx.lang_items.require(FnTraitLangItem),
1704+
ClosureKind::FnMut => {
17061705
cx.lang_items.require(FnMutTraitLangItem)
17071706
}
1708-
FnOnceClosureKind => {
1707+
ClosureKind::FnOnce => {
17091708
cx.lang_items.require(FnOnceTraitLangItem)
17101709
}
17111710
};
@@ -1719,12 +1718,12 @@ impl ClosureKind {
17191718
/// must also implement `other`.
17201719
pub fn extends(self, other: ty::ClosureKind) -> bool {
17211720
match (self, other) {
1722-
(FnClosureKind, FnClosureKind) => true,
1723-
(FnClosureKind, FnMutClosureKind) => true,
1724-
(FnClosureKind, FnOnceClosureKind) => true,
1725-
(FnMutClosureKind, FnMutClosureKind) => true,
1726-
(FnMutClosureKind, FnOnceClosureKind) => true,
1727-
(FnOnceClosureKind, FnOnceClosureKind) => true,
1721+
(ClosureKind::Fn, ClosureKind::Fn) => true,
1722+
(ClosureKind::Fn, ClosureKind::FnMut) => true,
1723+
(ClosureKind::Fn, ClosureKind::FnOnce) => true,
1724+
(ClosureKind::FnMut, ClosureKind::FnMut) => true,
1725+
(ClosureKind::FnMut, ClosureKind::FnOnce) => true,
1726+
(ClosureKind::FnOnce, ClosureKind::FnOnce) => true,
17281727
_ => false,
17291728
}
17301729
}

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
@@ -679,7 +679,7 @@ fn convert_var<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>,
679679
let region = cx.tcx.mk_region(region);
680680

681681
let self_expr = match cx.tcx.closure_kind(cx.tcx.map.local_def_id(closure_expr_id)) {
682-
ty::ClosureKind::FnClosureKind => {
682+
ty::ClosureKind::Fn => {
683683
let ref_closure_ty =
684684
cx.tcx.mk_ref(region,
685685
ty::TypeAndMut { ty: closure_ty,
@@ -698,7 +698,7 @@ fn convert_var<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>,
698698
}
699699
}
700700
}
701-
ty::ClosureKind::FnMutClosureKind => {
701+
ty::ClosureKind::FnMut => {
702702
let ref_closure_ty =
703703
cx.tcx.mk_ref(region,
704704
ty::TypeAndMut { ty: closure_ty,
@@ -717,7 +717,7 @@ fn convert_var<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>,
717717
}
718718
}
719719
}
720-
ty::ClosureKind::FnOnceClosureKind => {
720+
ty::ClosureKind::FnOnce => {
721721
Expr {
722722
ty: closure_ty,
723723
temp_lifetime: temp_lifetime,

src/librustc_mir/mir_map.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -247,15 +247,15 @@ fn closure_self_ty<'a, 'tcx>(tcx: &ty::ctxt<'tcx>,
247247
let region = tcx.mk_region(region);
248248

249249
match tcx.closure_kind(tcx.map.local_def_id(closure_expr_id)) {
250-
ty::ClosureKind::FnClosureKind =>
250+
ty::ClosureKind::Fn =>
251251
tcx.mk_ref(region,
252252
ty::TypeAndMut { ty: closure_ty,
253253
mutbl: hir::MutImmutable }),
254-
ty::ClosureKind::FnMutClosureKind =>
254+
ty::ClosureKind::FnMut =>
255255
tcx.mk_ref(region,
256256
ty::TypeAndMut { ty: closure_ty,
257257
mutbl: hir::MutMutable }),
258-
ty::ClosureKind::FnOnceClosureKind =>
258+
ty::ClosureKind::FnOnce =>
259259
closure_ty
260260
}
261261
}

src/librustc_trans/trans/base.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,13 @@ pub fn self_type_for_closure<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
218218
-> Ty<'tcx> {
219219
let closure_kind = ccx.tcx().closure_kind(closure_id);
220220
match closure_kind {
221-
ty::FnClosureKind => {
221+
ty::ClosureKind::Fn => {
222222
ccx.tcx().mk_imm_ref(ccx.tcx().mk_region(ty::ReStatic), fn_ty)
223223
}
224-
ty::FnMutClosureKind => {
224+
ty::ClosureKind::FnMut => {
225225
ccx.tcx().mk_mut_ref(ccx.tcx().mk_region(ty::ReStatic), fn_ty)
226226
}
227-
ty::FnOnceClosureKind => fn_ty,
227+
ty::ClosureKind::FnOnce => fn_ty,
228228
}
229229
}
230230

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)