Merge hir::GeneratorMovability into ast::Movability.
This commit is contained in:
parent
f03cbc313d
commit
5b30da10b6
@ -494,7 +494,7 @@ pub(super) fn make_async_expr(
|
||||
decl,
|
||||
body_id,
|
||||
span,
|
||||
Some(hir::GeneratorMovability::Static)
|
||||
Some(hir::Movability::Static)
|
||||
);
|
||||
let generator = hir::Expr {
|
||||
hir_id: self.lower_node_id(closure_node_id),
|
||||
@ -725,7 +725,7 @@ fn generator_movability_for_fn(
|
||||
fn_decl_span: Span,
|
||||
generator_kind: Option<hir::GeneratorKind>,
|
||||
movability: Movability,
|
||||
) -> Option<hir::GeneratorMovability> {
|
||||
) -> Option<hir::Movability> {
|
||||
match generator_kind {
|
||||
Some(hir::GeneratorKind::Gen) => {
|
||||
if !decl.inputs.is_empty() {
|
||||
@ -736,10 +736,7 @@ fn generator_movability_for_fn(
|
||||
"generators cannot have explicit parameters"
|
||||
);
|
||||
}
|
||||
Some(match movability {
|
||||
Movability::Movable => hir::GeneratorMovability::Movable,
|
||||
Movability::Static => hir::GeneratorMovability::Static,
|
||||
})
|
||||
Some(movability)
|
||||
},
|
||||
Some(hir::GeneratorKind::Async(_)) => {
|
||||
bug!("non-`async` closure body turned `async` during lowering");
|
||||
|
@ -22,7 +22,7 @@
|
||||
use syntax::source_map::Spanned;
|
||||
use syntax::ast::{self, CrateSugar, Ident, Name, NodeId, AsmDialect};
|
||||
use syntax::ast::{Attribute, Label, LitKind, StrStyle, FloatTy, IntTy, UintTy};
|
||||
pub use syntax::ast::{Mutability, Constness, Unsafety};
|
||||
pub use syntax::ast::{Mutability, Constness, Unsafety, Movability};
|
||||
use syntax::attr::{InlineAttr, OptimizeAttr};
|
||||
use syntax::symbol::{Symbol, kw};
|
||||
use syntax::tokenstream::TokenStream;
|
||||
@ -1628,8 +1628,8 @@ pub enum ExprKind {
|
||||
/// The `Span` is the argument block `|...|`.
|
||||
///
|
||||
/// This may also be a generator literal or an `async block` as indicated by the
|
||||
/// `Option<GeneratorMovability>`.
|
||||
Closure(CaptureClause, P<FnDecl>, BodyId, Span, Option<GeneratorMovability>),
|
||||
/// `Option<Movability>`.
|
||||
Closure(CaptureClause, P<FnDecl>, BodyId, Span, Option<Movability>),
|
||||
/// A block (e.g., `'label: { ... }`).
|
||||
Block(P<Block>, Option<Label>),
|
||||
|
||||
@ -1802,17 +1802,6 @@ pub struct Destination {
|
||||
pub target_id: Result<HirId, LoopIdError>,
|
||||
}
|
||||
|
||||
/// Whether a generator contains self-references, causing it to be `!Unpin`.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, HashStable,
|
||||
RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||
pub enum GeneratorMovability {
|
||||
/// May contain self-references, `!Unpin`.
|
||||
Static,
|
||||
|
||||
/// Must not contain self-references, `Unpin`.
|
||||
Movable,
|
||||
}
|
||||
|
||||
/// The yield kind that caused an `ExprKind::Yield`.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug, RustcEncodable, RustcDecodable, HashStable)]
|
||||
pub enum YieldSource {
|
||||
|
@ -168,6 +168,7 @@ fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHas
|
||||
impl_stable_hash_for!(struct ::syntax::ast::Lifetime { id, ident });
|
||||
impl_stable_hash_for!(enum ::syntax::ast::StrStyle { Cooked, Raw(pounds) });
|
||||
impl_stable_hash_for!(enum ::syntax::ast::AttrStyle { Outer, Inner });
|
||||
impl_stable_hash_for!(enum ::syntax::ast::Movability { Static, Movable });
|
||||
|
||||
impl<'a> HashStable<StableHashingContext<'a>> for [ast::Attribute] {
|
||||
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
|
||||
|
@ -2161,7 +2161,7 @@ pub enum AggregateKind<'tcx> {
|
||||
Adt(&'tcx AdtDef, VariantIdx, SubstsRef<'tcx>, Option<UserTypeAnnotationIndex>, Option<usize>),
|
||||
|
||||
Closure(DefId, SubstsRef<'tcx>),
|
||||
Generator(DefId, SubstsRef<'tcx>, hir::GeneratorMovability),
|
||||
Generator(DefId, SubstsRef<'tcx>, hir::Movability),
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)]
|
||||
|
@ -2195,11 +2195,11 @@ fn assemble_candidates_from_auto_impls(
|
||||
if self.tcx().lang_items().unpin_trait() == Some(def_id) =>
|
||||
{
|
||||
match movability {
|
||||
hir::GeneratorMovability::Static => {
|
||||
hir::Movability::Static => {
|
||||
// Immovable generators are never `Unpin`, so
|
||||
// suppress the normal auto-impl candidate for it.
|
||||
}
|
||||
hir::GeneratorMovability::Movable => {
|
||||
hir::Movability::Movable => {
|
||||
// Movable generators are always `Unpin`, so add an
|
||||
// unconditional builtin candidate.
|
||||
candidates.vec.push(BuiltinCandidate {
|
||||
|
@ -2516,7 +2516,7 @@ pub fn mk_closure(self, closure_id: DefId, closure_substs: SubstsRef<'tcx>)
|
||||
pub fn mk_generator(self,
|
||||
id: DefId,
|
||||
generator_substs: SubstsRef<'tcx>,
|
||||
movability: hir::GeneratorMovability)
|
||||
movability: hir::Movability)
|
||||
-> Ty<'tcx> {
|
||||
self.mk_ty(Generator(id, generator_substs, movability))
|
||||
}
|
||||
|
@ -607,10 +607,9 @@ fn pretty_print_type(
|
||||
ty::Generator(did, substs, movability) => {
|
||||
let upvar_tys = substs.as_generator().upvar_tys(did, self.tcx());
|
||||
let witness = substs.as_generator().witness(did, self.tcx());
|
||||
if movability == hir::GeneratorMovability::Movable {
|
||||
p!(write("[generator"));
|
||||
} else {
|
||||
p!(write("[static generator"));
|
||||
match movability {
|
||||
hir::Movability::Movable => p!(write("[generator")),
|
||||
hir::Movability::Static => p!(write("[static generator")),
|
||||
}
|
||||
|
||||
// FIXME(eddyb) should use `def_span`.
|
||||
|
@ -162,7 +162,7 @@ pub enum TyKind<'tcx> {
|
||||
|
||||
/// The anonymous type of a generator. Used to represent the type of
|
||||
/// `|a| yield a`.
|
||||
Generator(DefId, SubstsRef<'tcx>, hir::GeneratorMovability),
|
||||
Generator(DefId, SubstsRef<'tcx>, hir::Movability),
|
||||
|
||||
/// A type representin the types stored inside a generator.
|
||||
/// This should only appear in GeneratorInteriors.
|
||||
|
@ -235,7 +235,7 @@ fn do_mir_borrowck<'a, 'tcx>(
|
||||
|
||||
let movable_generator = match tcx.hir().get(id) {
|
||||
Node::Expr(&hir::Expr {
|
||||
kind: hir::ExprKind::Closure(.., Some(hir::GeneratorMovability::Static)),
|
||||
kind: hir::ExprKind::Closure(.., Some(hir::Movability::Static)),
|
||||
..
|
||||
}) => false,
|
||||
_ => true,
|
||||
|
@ -90,7 +90,7 @@ pub enum DefiningTy<'tcx> {
|
||||
/// The MIR is a generator. The signature is that generators take
|
||||
/// no parameters and return the result of
|
||||
/// `ClosureSubsts::generator_return_ty`.
|
||||
Generator(DefId, SubstsRef<'tcx>, hir::GeneratorMovability),
|
||||
Generator(DefId, SubstsRef<'tcx>, hir::Movability),
|
||||
|
||||
/// The MIR is a fn item with the given `DefId` and substs. The signature
|
||||
/// of the function can be bound then with the `fn_sig` query.
|
||||
|
@ -257,7 +257,7 @@ pub enum ExprKind<'tcx> {
|
||||
closure_id: DefId,
|
||||
substs: UpvarSubsts<'tcx>,
|
||||
upvars: Vec<ExprRef<'tcx>>,
|
||||
movability: Option<hir::GeneratorMovability>,
|
||||
movability: Option<hir::Movability>,
|
||||
},
|
||||
Literal {
|
||||
literal: &'tcx Const<'tcx>,
|
||||
|
@ -1192,7 +1192,7 @@ fn run_pass(&self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut Body<'
|
||||
(substs.upvar_tys(def_id, tcx).collect(),
|
||||
substs.witness(def_id, tcx),
|
||||
substs.discr_ty(tcx),
|
||||
movability == hir::GeneratorMovability::Movable)
|
||||
movability == hir::Movability::Movable)
|
||||
}
|
||||
_ => bug!(),
|
||||
};
|
||||
|
@ -7,7 +7,7 @@
|
||||
use rustc::hir::def_id::DefId;
|
||||
use rustc::hir::map::Map;
|
||||
use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
|
||||
use rustc::hir::{self, Node, Destination, GeneratorMovability};
|
||||
use rustc::hir::{self, Node, Destination, Movability};
|
||||
use syntax::struct_span_err;
|
||||
use syntax_pos::Span;
|
||||
use errors::Applicability;
|
||||
@ -59,7 +59,7 @@ fn visit_expr(&mut self, e: &'hir hir::Expr) {
|
||||
self.with_context(Loop(source), |v| v.visit_block(&b));
|
||||
}
|
||||
hir::ExprKind::Closure(_, ref function_decl, b, span, movability) => {
|
||||
let cx = if let Some(GeneratorMovability::Static) = movability {
|
||||
let cx = if let Some(Movability::Static) = movability {
|
||||
AsyncClosure(span)
|
||||
} else {
|
||||
Closure(span)
|
||||
|
@ -76,6 +76,6 @@
|
||||
tcx.mk_generator(
|
||||
def_id,
|
||||
InternalSubsts::bound_vars_for_item(tcx, def_id),
|
||||
hir::GeneratorMovability::Movable
|
||||
hir::Movability::Movable
|
||||
)
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ pub fn check_expr_closure(
|
||||
_capture: hir::CaptureClause,
|
||||
decl: &'tcx hir::FnDecl,
|
||||
body_id: hir::BodyId,
|
||||
gen: Option<hir::GeneratorMovability>,
|
||||
gen: Option<hir::Movability>,
|
||||
expected: Expectation<'tcx>,
|
||||
) -> Ty<'tcx> {
|
||||
debug!(
|
||||
@ -64,7 +64,7 @@ fn check_closure(
|
||||
opt_kind: Option<ty::ClosureKind>,
|
||||
decl: &'tcx hir::FnDecl,
|
||||
body: &'tcx hir::Body,
|
||||
gen: Option<hir::GeneratorMovability>,
|
||||
gen: Option<hir::Movability>,
|
||||
expected_sig: Option<ExpectedSig<'tcx>>,
|
||||
) -> Ty<'tcx> {
|
||||
debug!(
|
||||
|
@ -1090,7 +1090,7 @@ struct GeneratorTypes<'tcx> {
|
||||
interior: Ty<'tcx>,
|
||||
|
||||
/// Indicates if the generator is movable or static (immovable).
|
||||
movability: hir::GeneratorMovability,
|
||||
movability: hir::Movability,
|
||||
}
|
||||
|
||||
/// Helper used for fns and closures. Does the grungy work of checking a function
|
||||
@ -1106,7 +1106,7 @@ fn check_fn<'a, 'tcx>(
|
||||
decl: &'tcx hir::FnDecl,
|
||||
fn_id: hir::HirId,
|
||||
body: &'tcx hir::Body,
|
||||
can_be_generator: Option<hir::GeneratorMovability>,
|
||||
can_be_generator: Option<hir::Movability>,
|
||||
) -> (FnCtxt<'a, 'tcx>, Option<GeneratorTypes<'tcx>>) {
|
||||
let mut fn_sig = fn_sig.clone();
|
||||
|
||||
|
@ -1339,10 +1339,14 @@ pub enum CaptureBy {
|
||||
Ref,
|
||||
}
|
||||
|
||||
/// The movability of a generator / closure literal.
|
||||
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)]
|
||||
/// The movability of a generator / closure literal:
|
||||
/// whether a generator contains self-references, causing it to be `!Unpin`.
|
||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash,
|
||||
RustcEncodable, RustcDecodable, Debug, Copy)]
|
||||
pub enum Movability {
|
||||
/// May contain self-references, `!Unpin`.
|
||||
Static,
|
||||
/// Must not contain self-references, `Unpin`.
|
||||
Movable,
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user