提交 a9ffe67f 编写于 作者: B bors

Auto merge of #31606 - Ms2ger:ClosureKind, r=eddyb

Rename ClosureKind variants and stop re-exporting them.
......@@ -120,9 +120,9 @@ pub fn to_builtin_kind(&self, id: DefId) -> Option<ty::BuiltinBound> {
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 {
......
......@@ -670,13 +670,13 @@ fn cat_upvar(&self,
// 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)
}
};
......@@ -1630,9 +1630,9 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
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)
}
......
......@@ -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::*;
......@@ -1699,19 +1698,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: &TyCtxt) -> 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)
}
};
......@@ -1725,12 +1724,12 @@ pub fn trait_did(&self, cx: &TyCtxt) -> DefId {
/// 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,
}
}
......
......@@ -1009,7 +1009,7 @@ pub fn note_and_explain_bckerr(&self, db: &mut DiagnosticBuilder, err: BckError<
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 \
......
......@@ -725,7 +725,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,
......@@ -744,7 +744,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,
......@@ -763,7 +763,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,
......
......@@ -252,15 +252,15 @@ fn closure_self_ty<'a, 'tcx>(tcx: &TyCtxt<'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
}
}
......@@ -216,13 +216,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,
}
}
......
......@@ -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)
......
......@@ -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,
......@@ -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,
......@@ -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:
......
......@@ -697,11 +697,11 @@ fn assemble_closure_candidates(&mut self,
// 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(());
};
......
......@@ -131,7 +131,7 @@ fn check_closure(&mut self,
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);
}
......@@ -301,7 +301,7 @@ fn adjust_upvar_borrow_kind_for_consume(&self,
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;
......@@ -314,7 +314,7 @@ fn adjust_upvar_borrow_kind_for_consume(&self,
// 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 => {
}
......@@ -418,7 +418,7 @@ fn try_adjust_upvar_deref(&self,
}
// 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
}
......@@ -426,7 +426,7 @@ fn try_adjust_upvar_deref(&self,
// 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
}
......@@ -488,16 +488,16 @@ fn adjust_closure_kind(&self,
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);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册