Skip to content

Commit cb233f5

Browse files
committed
Merge hir::CaptureClause into ast::CaptureBy.
1 parent 5b30da1 commit cb233f5

File tree

6 files changed

+12
-27
lines changed

6 files changed

+12
-27
lines changed

src/librustc/hir/lowering/expr.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,6 @@ impl LoweringContext<'_> {
473473
async_gen_kind: hir::AsyncGeneratorKind,
474474
body: impl FnOnce(&mut LoweringContext<'_>) -> hir::Expr,
475475
) -> hir::ExprKind {
476-
let capture_clause = self.lower_capture_clause(capture_clause);
477476
let output = match ret_ty {
478477
Some(ty) => FunctionRetTy::Ty(ty),
479478
None => FunctionRetTy::Default(span),
@@ -700,7 +699,6 @@ impl LoweringContext<'_> {
700699
generator_kind,
701700
movability,
702701
);
703-
let capture_clause = this.lower_capture_clause(capture_clause);
704702
this.current_item = prev;
705703
hir::ExprKind::Closure(
706704
capture_clause,
@@ -712,13 +710,6 @@ impl LoweringContext<'_> {
712710
})
713711
}
714712

715-
fn lower_capture_clause(&mut self, c: CaptureBy) -> hir::CaptureClause {
716-
match c {
717-
CaptureBy::Value => hir::CaptureByValue,
718-
CaptureBy::Ref => hir::CaptureByRef,
719-
}
720-
}
721-
722713
fn generator_movability_for_fn(
723714
&mut self,
724715
decl: &FnDecl,
@@ -807,7 +798,7 @@ impl LoweringContext<'_> {
807798
this.expr(fn_decl_span, async_body, ThinVec::new())
808799
});
809800
hir::ExprKind::Closure(
810-
this.lower_capture_clause(capture_clause),
801+
capture_clause,
811802
fn_decl,
812803
body_id,
813804
fn_decl_span,

src/librustc/hir/mod.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//! [rustc guide]: https://rust-lang.github.io/rustc-guide/hir.html
44
55
pub use self::BlockCheckMode::*;
6-
pub use self::CaptureClause::*;
76
pub use self::FunctionRetTy::*;
87
pub use self::PrimTy::*;
98
pub use self::UnOp::*;
@@ -22,7 +21,7 @@ use syntax_pos::{Span, DUMMY_SP, MultiSpan};
2221
use syntax::source_map::Spanned;
2322
use syntax::ast::{self, CrateSugar, Ident, Name, NodeId, AsmDialect};
2423
use syntax::ast::{Attribute, Label, LitKind, StrStyle, FloatTy, IntTy, UintTy};
25-
pub use syntax::ast::{Mutability, Constness, Unsafety, Movability};
24+
pub use syntax::ast::{Mutability, Constness, Unsafety, Movability, CaptureBy};
2625
use syntax::attr::{InlineAttr, OptimizeAttr};
2726
use syntax::symbol::{Symbol, kw};
2827
use syntax::tokenstream::TokenStream;
@@ -1629,7 +1628,7 @@ pub enum ExprKind {
16291628
///
16301629
/// This may also be a generator literal or an `async block` as indicated by the
16311630
/// `Option<Movability>`.
1632-
Closure(CaptureClause, P<FnDecl>, BodyId, Span, Option<Movability>),
1631+
Closure(CaptureBy, P<FnDecl>, BodyId, Span, Option<Movability>),
16331632
/// A block (e.g., `'label: { ... }`).
16341633
Block(P<Block>, Option<Label>),
16351634

@@ -1820,12 +1819,6 @@ impl fmt::Display for YieldSource {
18201819
}
18211820
}
18221821

1823-
#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)]
1824-
pub enum CaptureClause {
1825-
CaptureByValue,
1826-
CaptureByRef,
1827-
}
1828-
18291822
// N.B., if you change this, you'll probably want to change the corresponding
18301823
// type structure in middle/ty.rs as well.
18311824
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
@@ -2620,7 +2613,7 @@ pub struct Upvar {
26202613
pub span: Span
26212614
}
26222615

2623-
pub type CaptureModeMap = NodeMap<CaptureClause>;
2616+
pub type CaptureModeMap = NodeMap<CaptureBy>;
26242617

26252618
// The TraitCandidate's import_ids is empty if the trait is defined in the same module, and
26262619
// has length > 0 if the trait is found through an chain of imports, starting with the

src/librustc/hir/print.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1909,10 +1909,10 @@ impl<'a> State<'a> {
19091909
}
19101910
}
19111911

1912-
pub fn print_capture_clause(&mut self, capture_clause: hir::CaptureClause) {
1912+
pub fn print_capture_clause(&mut self, capture_clause: hir::CaptureBy) {
19131913
match capture_clause {
1914-
hir::CaptureByValue => self.word_space("move"),
1915-
hir::CaptureByRef => {},
1914+
hir::CaptureBy::Value => self.word_space("move"),
1915+
hir::CaptureBy::Ref => {},
19161916
}
19171917
}
19181918

src/librustc/ich/impls_syntax.rs

+1
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ impl_stable_hash_for!(struct ::syntax::ast::Lifetime { id, ident });
169169
impl_stable_hash_for!(enum ::syntax::ast::StrStyle { Cooked, Raw(pounds) });
170170
impl_stable_hash_for!(enum ::syntax::ast::AttrStyle { Outer, Inner });
171171
impl_stable_hash_for!(enum ::syntax::ast::Movability { Static, Movable });
172+
impl_stable_hash_for!(enum ::syntax::ast::CaptureBy { Value, Ref });
172173

173174
impl<'a> HashStable<StableHashingContext<'a>> for [ast::Attribute] {
174175
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {

src/librustc_typeck/check/closure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3636
pub fn check_expr_closure(
3737
&self,
3838
expr: &hir::Expr,
39-
_capture: hir::CaptureClause,
39+
_capture: hir::CaptureBy,
4040
decl: &'tcx hir::FnDecl,
4141
body_id: hir::BodyId,
4242
gen: Option<hir::Movability>,

src/librustc_typeck/check/upvar.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
8181
closure_hir_id: hir::HirId,
8282
span: Span,
8383
body: &hir::Body,
84-
capture_clause: hir::CaptureClause,
84+
capture_clause: hir::CaptureBy,
8585
) {
8686
/*!
8787
* Analysis starting point.
@@ -141,8 +141,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
141141
upvar_list.insert(var_hir_id, upvar_id);
142142

143143
let capture_kind = match capture_clause {
144-
hir::CaptureByValue => ty::UpvarCapture::ByValue,
145-
hir::CaptureByRef => {
144+
hir::CaptureBy::Value => ty::UpvarCapture::ByValue,
145+
hir::CaptureBy::Ref => {
146146
let origin = UpvarRegion(upvar_id, span);
147147
let upvar_region = self.next_region_var(origin);
148148
let upvar_borrow = ty::UpvarBorrow {

0 commit comments

Comments
 (0)