Skip to content

Commit 5b30da1

Browse files
committed
Merge hir::GeneratorMovability into ast::Movability.
1 parent f03cbc3 commit 5b30da1

File tree

17 files changed

+32
-42
lines changed

17 files changed

+32
-42
lines changed

src/librustc/hir/lowering/expr.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ impl LoweringContext<'_> {
494494
decl,
495495
body_id,
496496
span,
497-
Some(hir::GeneratorMovability::Static)
497+
Some(hir::Movability::Static)
498498
);
499499
let generator = hir::Expr {
500500
hir_id: self.lower_node_id(closure_node_id),
@@ -725,7 +725,7 @@ impl LoweringContext<'_> {
725725
fn_decl_span: Span,
726726
generator_kind: Option<hir::GeneratorKind>,
727727
movability: Movability,
728-
) -> Option<hir::GeneratorMovability> {
728+
) -> Option<hir::Movability> {
729729
match generator_kind {
730730
Some(hir::GeneratorKind::Gen) => {
731731
if !decl.inputs.is_empty() {
@@ -736,10 +736,7 @@ impl LoweringContext<'_> {
736736
"generators cannot have explicit parameters"
737737
);
738738
}
739-
Some(match movability {
740-
Movability::Movable => hir::GeneratorMovability::Movable,
741-
Movability::Static => hir::GeneratorMovability::Static,
742-
})
739+
Some(movability)
743740
},
744741
Some(hir::GeneratorKind::Async(_)) => {
745742
bug!("non-`async` closure body turned `async` during lowering");

src/librustc/hir/mod.rs

+3-14
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use syntax_pos::{Span, DUMMY_SP, MultiSpan};
2222
use syntax::source_map::Spanned;
2323
use syntax::ast::{self, CrateSugar, Ident, Name, NodeId, AsmDialect};
2424
use syntax::ast::{Attribute, Label, LitKind, StrStyle, FloatTy, IntTy, UintTy};
25-
pub use syntax::ast::{Mutability, Constness, Unsafety};
25+
pub use syntax::ast::{Mutability, Constness, Unsafety, Movability};
2626
use syntax::attr::{InlineAttr, OptimizeAttr};
2727
use syntax::symbol::{Symbol, kw};
2828
use syntax::tokenstream::TokenStream;
@@ -1628,8 +1628,8 @@ pub enum ExprKind {
16281628
/// The `Span` is the argument block `|...|`.
16291629
///
16301630
/// This may also be a generator literal or an `async block` as indicated by the
1631-
/// `Option<GeneratorMovability>`.
1632-
Closure(CaptureClause, P<FnDecl>, BodyId, Span, Option<GeneratorMovability>),
1631+
/// `Option<Movability>`.
1632+
Closure(CaptureClause, P<FnDecl>, BodyId, Span, Option<Movability>),
16331633
/// A block (e.g., `'label: { ... }`).
16341634
Block(P<Block>, Option<Label>),
16351635

@@ -1802,17 +1802,6 @@ pub struct Destination {
18021802
pub target_id: Result<HirId, LoopIdError>,
18031803
}
18041804

1805-
/// Whether a generator contains self-references, causing it to be `!Unpin`.
1806-
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, HashStable,
1807-
RustcEncodable, RustcDecodable, Hash, Debug)]
1808-
pub enum GeneratorMovability {
1809-
/// May contain self-references, `!Unpin`.
1810-
Static,
1811-
1812-
/// Must not contain self-references, `Unpin`.
1813-
Movable,
1814-
}
1815-
18161805
/// The yield kind that caused an `ExprKind::Yield`.
18171806
#[derive(Copy, Clone, PartialEq, Eq, Debug, RustcEncodable, RustcDecodable, HashStable)]
18181807
pub enum YieldSource {

src/librustc/ich/impls_syntax.rs

+1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ impl_stable_hash_for!(enum ::syntax::ast::Defaultness { Default, Final });
168168
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 });
171+
impl_stable_hash_for!(enum ::syntax::ast::Movability { Static, Movable });
171172

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

src/librustc/mir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2161,7 +2161,7 @@ pub enum AggregateKind<'tcx> {
21612161
Adt(&'tcx AdtDef, VariantIdx, SubstsRef<'tcx>, Option<UserTypeAnnotationIndex>, Option<usize>),
21622162

21632163
Closure(DefId, SubstsRef<'tcx>),
2164-
Generator(DefId, SubstsRef<'tcx>, hir::GeneratorMovability),
2164+
Generator(DefId, SubstsRef<'tcx>, hir::Movability),
21652165
}
21662166

21672167
#[derive(Copy, Clone, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)]

src/librustc/traits/select.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2195,11 +2195,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
21952195
if self.tcx().lang_items().unpin_trait() == Some(def_id) =>
21962196
{
21972197
match movability {
2198-
hir::GeneratorMovability::Static => {
2198+
hir::Movability::Static => {
21992199
// Immovable generators are never `Unpin`, so
22002200
// suppress the normal auto-impl candidate for it.
22012201
}
2202-
hir::GeneratorMovability::Movable => {
2202+
hir::Movability::Movable => {
22032203
// Movable generators are always `Unpin`, so add an
22042204
// unconditional builtin candidate.
22052205
candidates.vec.push(BuiltinCandidate {

src/librustc/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2516,7 +2516,7 @@ impl<'tcx> TyCtxt<'tcx> {
25162516
pub fn mk_generator(self,
25172517
id: DefId,
25182518
generator_substs: SubstsRef<'tcx>,
2519-
movability: hir::GeneratorMovability)
2519+
movability: hir::Movability)
25202520
-> Ty<'tcx> {
25212521
self.mk_ty(Generator(id, generator_substs, movability))
25222522
}

src/librustc/ty/print/pretty.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -607,10 +607,9 @@ pub trait PrettyPrinter<'tcx>:
607607
ty::Generator(did, substs, movability) => {
608608
let upvar_tys = substs.as_generator().upvar_tys(did, self.tcx());
609609
let witness = substs.as_generator().witness(did, self.tcx());
610-
if movability == hir::GeneratorMovability::Movable {
611-
p!(write("[generator"));
612-
} else {
613-
p!(write("[static generator"));
610+
match movability {
611+
hir::Movability::Movable => p!(write("[generator")),
612+
hir::Movability::Static => p!(write("[static generator")),
614613
}
615614

616615
// FIXME(eddyb) should use `def_span`.

src/librustc/ty/sty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ pub enum TyKind<'tcx> {
162162

163163
/// The anonymous type of a generator. Used to represent the type of
164164
/// `|a| yield a`.
165-
Generator(DefId, SubstsRef<'tcx>, hir::GeneratorMovability),
165+
Generator(DefId, SubstsRef<'tcx>, hir::Movability),
166166

167167
/// A type representin the types stored inside a generator.
168168
/// This should only appear in GeneratorInteriors.

src/librustc_mir/borrow_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ fn do_mir_borrowck<'a, 'tcx>(
235235

236236
let movable_generator = match tcx.hir().get(id) {
237237
Node::Expr(&hir::Expr {
238-
kind: hir::ExprKind::Closure(.., Some(hir::GeneratorMovability::Static)),
238+
kind: hir::ExprKind::Closure(.., Some(hir::Movability::Static)),
239239
..
240240
}) => false,
241241
_ => true,

src/librustc_mir/borrow_check/nll/universal_regions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pub enum DefiningTy<'tcx> {
9090
/// The MIR is a generator. The signature is that generators take
9191
/// no parameters and return the result of
9292
/// `ClosureSubsts::generator_return_ty`.
93-
Generator(DefId, SubstsRef<'tcx>, hir::GeneratorMovability),
93+
Generator(DefId, SubstsRef<'tcx>, hir::Movability),
9494

9595
/// The MIR is a fn item with the given `DefId` and substs. The signature
9696
/// of the function can be bound then with the `fn_sig` query.

src/librustc_mir/hair/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ pub enum ExprKind<'tcx> {
257257
closure_id: DefId,
258258
substs: UpvarSubsts<'tcx>,
259259
upvars: Vec<ExprRef<'tcx>>,
260-
movability: Option<hir::GeneratorMovability>,
260+
movability: Option<hir::Movability>,
261261
},
262262
Literal {
263263
literal: &'tcx Const<'tcx>,

src/librustc_mir/transform/generator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
11921192
(substs.upvar_tys(def_id, tcx).collect(),
11931193
substs.witness(def_id, tcx),
11941194
substs.discr_ty(tcx),
1195-
movability == hir::GeneratorMovability::Movable)
1195+
movability == hir::Movability::Movable)
11961196
}
11971197
_ => bug!(),
11981198
};

src/librustc_passes/loops.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc::ty::TyCtxt;
77
use rustc::hir::def_id::DefId;
88
use rustc::hir::map::Map;
99
use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
10-
use rustc::hir::{self, Node, Destination, GeneratorMovability};
10+
use rustc::hir::{self, Node, Destination, Movability};
1111
use syntax::struct_span_err;
1212
use syntax_pos::Span;
1313
use errors::Applicability;
@@ -59,7 +59,7 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
5959
self.with_context(Loop(source), |v| v.visit_block(&b));
6060
}
6161
hir::ExprKind::Closure(_, ref function_decl, b, span, movability) => {
62-
let cx = if let Some(GeneratorMovability::Static) = movability {
62+
let cx = if let Some(Movability::Static) = movability {
6363
AsyncClosure(span)
6464
} else {
6565
Closure(span)

src/librustc_traits/generic_types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,6 @@ crate fn generator(tcx: TyCtxt<'tcx>, def_id: DefId) -> Ty<'tcx> {
7676
tcx.mk_generator(
7777
def_id,
7878
InternalSubsts::bound_vars_for_item(tcx, def_id),
79-
hir::GeneratorMovability::Movable
79+
hir::Movability::Movable
8080
)
8181
}

src/librustc_typeck/check/closure.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3939
_capture: hir::CaptureClause,
4040
decl: &'tcx hir::FnDecl,
4141
body_id: hir::BodyId,
42-
gen: Option<hir::GeneratorMovability>,
42+
gen: Option<hir::Movability>,
4343
expected: Expectation<'tcx>,
4444
) -> Ty<'tcx> {
4545
debug!(
@@ -64,7 +64,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
6464
opt_kind: Option<ty::ClosureKind>,
6565
decl: &'tcx hir::FnDecl,
6666
body: &'tcx hir::Body,
67-
gen: Option<hir::GeneratorMovability>,
67+
gen: Option<hir::Movability>,
6868
expected_sig: Option<ExpectedSig<'tcx>>,
6969
) -> Ty<'tcx> {
7070
debug!(

src/librustc_typeck/check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,7 @@ struct GeneratorTypes<'tcx> {
10901090
interior: Ty<'tcx>,
10911091

10921092
/// Indicates if the generator is movable or static (immovable).
1093-
movability: hir::GeneratorMovability,
1093+
movability: hir::Movability,
10941094
}
10951095

10961096
/// Helper used for fns and closures. Does the grungy work of checking a function
@@ -1106,7 +1106,7 @@ fn check_fn<'a, 'tcx>(
11061106
decl: &'tcx hir::FnDecl,
11071107
fn_id: hir::HirId,
11081108
body: &'tcx hir::Body,
1109-
can_be_generator: Option<hir::GeneratorMovability>,
1109+
can_be_generator: Option<hir::Movability>,
11101110
) -> (FnCtxt<'a, 'tcx>, Option<GeneratorTypes<'tcx>>) {
11111111
let mut fn_sig = fn_sig.clone();
11121112

src/libsyntax/ast.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1339,10 +1339,14 @@ pub enum CaptureBy {
13391339
Ref,
13401340
}
13411341

1342-
/// The movability of a generator / closure literal.
1343-
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)]
1342+
/// The movability of a generator / closure literal:
1343+
/// whether a generator contains self-references, causing it to be `!Unpin`.
1344+
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash,
1345+
RustcEncodable, RustcDecodable, Debug, Copy)]
13441346
pub enum Movability {
1347+
/// May contain self-references, `!Unpin`.
13451348
Static,
1349+
/// Must not contain self-references, `Unpin`.
13461350
Movable,
13471351
}
13481352

0 commit comments

Comments
 (0)