Skip to content

Rename ClosureKind variants and stop re-exporting them. #31606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/librustc/middle/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ impl LanguageItems {

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

for &(opt_def_id, kind) in &def_id_kinds {
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/middle/mem_categorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,13 +669,13 @@ impl<'t, 'a,'tcx> MemCategorizationContext<'t, 'a, 'tcx> {
// conceptually a `&mut` or `&` reference, so we have to add a
// deref.
let cmt_result = match kind {
ty::FnOnceClosureKind => {
ty::ClosureKind::FnOnce => {
cmt_result
}
ty::FnMutClosureKind => {
ty::ClosureKind::FnMut => {
self.env_deref(id, span, upvar_id, var_mutbl, ty::MutBorrow, cmt_result)
}
ty::FnClosureKind => {
ty::ClosureKind::Fn => {
self.env_deref(id, span, upvar_id, var_mutbl, ty::ImmBorrow, cmt_result)
}
};
Expand Down Expand Up @@ -1633,9 +1633,9 @@ impl fmt::Debug for Upvar {
impl fmt::Display for Upvar {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let kind = match self.kind {
ty::FnClosureKind => "Fn",
ty::FnMutClosureKind => "FnMut",
ty::FnOnceClosureKind => "FnOnce",
ty::ClosureKind::Fn => "Fn",
ty::ClosureKind::FnMut => "FnMut",
ty::ClosureKind::FnOnce => "FnOnce",
};
write!(f, "captured outer variable in an `{}` closure", kind)
}
Expand Down
25 changes: 12 additions & 13 deletions src/librustc/middle/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// except according to those terms.

pub use self::ImplOrTraitItemId::*;
pub use self::ClosureKind::*;
pub use self::Variance::*;
pub use self::DtorKind::*;
pub use self::ImplOrTraitItemContainer::*;
Expand Down Expand Up @@ -1693,19 +1692,19 @@ pub enum ClosureKind {
// Warning: Ordering is significant here! The ordering is chosen
// because the trait Fn is a subtrait of FnMut and so in turn, and
// hence we order it so that Fn < FnMut < FnOnce.
FnClosureKind,
FnMutClosureKind,
FnOnceClosureKind,
Fn,
FnMut,
FnOnce,
}

impl ClosureKind {
pub fn trait_did(&self, cx: &ctxt) -> DefId {
let result = match *self {
FnClosureKind => cx.lang_items.require(FnTraitLangItem),
FnMutClosureKind => {
ClosureKind::Fn => cx.lang_items.require(FnTraitLangItem),
ClosureKind::FnMut => {
cx.lang_items.require(FnMutTraitLangItem)
}
FnOnceClosureKind => {
ClosureKind::FnOnce => {
cx.lang_items.require(FnOnceTraitLangItem)
}
};
Expand All @@ -1719,12 +1718,12 @@ impl ClosureKind {
/// must also implement `other`.
pub fn extends(self, other: ty::ClosureKind) -> bool {
match (self, other) {
(FnClosureKind, FnClosureKind) => true,
(FnClosureKind, FnMutClosureKind) => true,
(FnClosureKind, FnOnceClosureKind) => true,
(FnMutClosureKind, FnMutClosureKind) => true,
(FnMutClosureKind, FnOnceClosureKind) => true,
(FnOnceClosureKind, FnOnceClosureKind) => true,
(ClosureKind::Fn, ClosureKind::Fn) => true,
(ClosureKind::Fn, ClosureKind::FnMut) => true,
(ClosureKind::Fn, ClosureKind::FnOnce) => true,
(ClosureKind::FnMut, ClosureKind::FnMut) => true,
(ClosureKind::FnMut, ClosureKind::FnOnce) => true,
(ClosureKind::FnOnce, ClosureKind::FnOnce) => true,
_ => false,
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_borrowck/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
Categorization::Upvar(mc::Upvar { kind, .. }) => kind,
_ => unreachable!()
};
if kind == ty::FnClosureKind {
if kind == ty::ClosureKind::Fn {
db.span_help(
self.tcx.map.span(upvar_id.closure_expr_id),
"consider changing this closure to take \
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/hair/cx/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ fn convert_var<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>,
let region = cx.tcx.mk_region(region);

let self_expr = match cx.tcx.closure_kind(cx.tcx.map.local_def_id(closure_expr_id)) {
ty::ClosureKind::FnClosureKind => {
ty::ClosureKind::Fn => {
let ref_closure_ty =
cx.tcx.mk_ref(region,
ty::TypeAndMut { ty: closure_ty,
Expand All @@ -698,7 +698,7 @@ fn convert_var<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>,
}
}
}
ty::ClosureKind::FnMutClosureKind => {
ty::ClosureKind::FnMut => {
let ref_closure_ty =
cx.tcx.mk_ref(region,
ty::TypeAndMut { ty: closure_ty,
Expand All @@ -717,7 +717,7 @@ fn convert_var<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>,
}
}
}
ty::ClosureKind::FnOnceClosureKind => {
ty::ClosureKind::FnOnce => {
Expr {
ty: closure_ty,
temp_lifetime: temp_lifetime,
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/mir_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,15 @@ fn closure_self_ty<'a, 'tcx>(tcx: &ty::ctxt<'tcx>,
let region = tcx.mk_region(region);

match tcx.closure_kind(tcx.map.local_def_id(closure_expr_id)) {
ty::ClosureKind::FnClosureKind =>
ty::ClosureKind::Fn =>
tcx.mk_ref(region,
ty::TypeAndMut { ty: closure_ty,
mutbl: hir::MutImmutable }),
ty::ClosureKind::FnMutClosureKind =>
ty::ClosureKind::FnMut =>
tcx.mk_ref(region,
ty::TypeAndMut { ty: closure_ty,
mutbl: hir::MutMutable }),
ty::ClosureKind::FnOnceClosureKind =>
ty::ClosureKind::FnOnce =>
closure_ty
}
}
6 changes: 3 additions & 3 deletions src/librustc_trans/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,13 @@ pub fn self_type_for_closure<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
-> Ty<'tcx> {
let closure_kind = ccx.tcx().closure_kind(closure_id);
match closure_kind {
ty::FnClosureKind => {
ty::ClosureKind::Fn => {
ccx.tcx().mk_imm_ref(ccx.tcx().mk_region(ty::ReStatic), fn_ty)
}
ty::FnMutClosureKind => {
ty::ClosureKind::FnMut => {
ccx.tcx().mk_mut_ref(ccx.tcx().mk_region(ty::ReStatic), fn_ty)
}
ty::FnOnceClosureKind => fn_ty,
ty::ClosureKind::FnOnce => fn_ty,
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_trans/trans/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ pub fn trans_fn_pointer_shim<'a, 'tcx>(

// If this is an impl of `Fn` or `FnMut` trait, the receiver is `&self`.
let is_by_ref = match closure_kind {
ty::FnClosureKind | ty::FnMutClosureKind => true,
ty::FnOnceClosureKind => false,
ty::ClosureKind::Fn | ty::ClosureKind::FnMut => true,
ty::ClosureKind::FnOnce => false,
};
let bare_fn_ty_maybe_ref = if is_by_ref {
tcx.mk_imm_ref(tcx.mk_region(ty::ReStatic), bare_fn_ty)
Expand Down
16 changes: 8 additions & 8 deletions src/librustc_trans/trans/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fn load_closure_environment<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
let closure_ty = node_id_type(bcx, bcx.fcx.id);
let self_type = self_type_for_closure(bcx.ccx(), closure_def_id, closure_ty);
let kind = kind_for_closure(bcx.ccx(), closure_def_id);
let llenv = if kind == ty::FnOnceClosureKind &&
let llenv = if kind == ty::ClosureKind::FnOnce &&
!arg_is_indirect(bcx.ccx(), self_type) {
let datum = rvalue_scratch_datum(bcx,
self_type,
Expand Down Expand Up @@ -85,7 +85,7 @@ fn load_closure_environment<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
let node_id = freevar.def.var_id();
bcx.fcx.llupvars.borrow_mut().insert(node_id, upvar_ptr);

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

match (llfn_closure_kind, trait_closure_kind) {
(ty::FnClosureKind, ty::FnClosureKind) |
(ty::FnMutClosureKind, ty::FnMutClosureKind) |
(ty::FnOnceClosureKind, ty::FnOnceClosureKind) => {
(ty::ClosureKind::Fn, ty::ClosureKind::Fn) |
(ty::ClosureKind::FnMut, ty::ClosureKind::FnMut) |
(ty::ClosureKind::FnOnce, ty::ClosureKind::FnOnce) => {
// No adapter needed.
llfn
}
(ty::FnClosureKind, ty::FnMutClosureKind) => {
(ty::ClosureKind::Fn, ty::ClosureKind::FnMut) => {
// The closure fn `llfn` is a `fn(&self, ...)`. We want a
// `fn(&mut self, ...)`. In fact, at trans time, these are
// basically the same thing, so we can just return llfn.
llfn
}
(ty::FnClosureKind, ty::FnOnceClosureKind) |
(ty::FnMutClosureKind, ty::FnOnceClosureKind) => {
(ty::ClosureKind::Fn, ty::ClosureKind::FnOnce) |
(ty::ClosureKind::FnMut, ty::ClosureKind::FnOnce) => {
// The closure fn `llfn` is a `fn(&self, ...)` or `fn(&mut
// self, ...)`. We want a `fn(self, ...)`. We can produce
// this by doing something like:
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_typeck/check/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,11 +697,11 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
// Check if this is one of the Fn,FnMut,FnOnce traits.
let tcx = self.tcx();
let kind = if Some(trait_def_id) == tcx.lang_items.fn_trait() {
ty::FnClosureKind
ty::ClosureKind::Fn
} else if Some(trait_def_id) == tcx.lang_items.fn_mut_trait() {
ty::FnMutClosureKind
ty::ClosureKind::FnMut
} else if Some(trait_def_id) == tcx.lang_items.fn_once_trait() {
ty::FnOnceClosureKind
ty::ClosureKind::FnOnce
} else {
return Ok(());
};
Expand Down
24 changes: 12 additions & 12 deletions src/librustc_typeck/check/upvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl<'a,'tcx> SeedBorrowKind<'a,'tcx> {
if !self.fcx.inh.tables.borrow().closure_kinds.contains_key(&closure_def_id) {
self.closures_with_inferred_kinds.insert(expr.id);
self.fcx.inh.tables.borrow_mut().closure_kinds
.insert(closure_def_id, ty::FnClosureKind);
.insert(closure_def_id, ty::ClosureKind::Fn);
debug!("check_closure: adding closure_id={:?} to closures_with_inferred_kinds",
closure_def_id);
}
Expand Down Expand Up @@ -301,7 +301,7 @@ impl<'a,'tcx> AdjustBorrowKind<'a,'tcx> {
upvar_id);

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

let upvar_capture_map =
&mut self.fcx.inh.tables.borrow_mut().upvar_capture_map;
Expand All @@ -314,7 +314,7 @@ impl<'a,'tcx> AdjustBorrowKind<'a,'tcx> {
// must still adjust the kind of the closure
// to be a FnOnce closure to permit moves out
// of the environment.
self.adjust_closure_kind(upvar_id.closure_expr_id, ty::FnOnceClosureKind);
self.adjust_closure_kind(upvar_id.closure_expr_id, ty::ClosureKind::FnOnce);
}
mc::NoteNone => {
}
Expand Down Expand Up @@ -418,15 +418,15 @@ impl<'a,'tcx> AdjustBorrowKind<'a,'tcx> {
}

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

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

true
}
Expand Down Expand Up @@ -488,16 +488,16 @@ impl<'a,'tcx> AdjustBorrowKind<'a,'tcx> {
closure_id, existing_kind, new_kind);

match (existing_kind, new_kind) {
(ty::FnClosureKind, ty::FnClosureKind) |
(ty::FnMutClosureKind, ty::FnClosureKind) |
(ty::FnMutClosureKind, ty::FnMutClosureKind) |
(ty::FnOnceClosureKind, _) => {
(ty::ClosureKind::Fn, ty::ClosureKind::Fn) |
(ty::ClosureKind::FnMut, ty::ClosureKind::Fn) |
(ty::ClosureKind::FnMut, ty::ClosureKind::FnMut) |
(ty::ClosureKind::FnOnce, _) => {
// no change needed
}

(ty::FnClosureKind, ty::FnMutClosureKind) |
(ty::FnClosureKind, ty::FnOnceClosureKind) |
(ty::FnMutClosureKind, ty::FnOnceClosureKind) => {
(ty::ClosureKind::Fn, ty::ClosureKind::FnMut) |
(ty::ClosureKind::Fn, ty::ClosureKind::FnOnce) |
(ty::ClosureKind::FnMut, ty::ClosureKind::FnOnce) => {
// new kind is stronger than the old kind
closure_kinds.insert(closure_def_id, new_kind);
}
Expand Down