Fix tidy warnings
This commit is contained in:
parent
d861982ca6
commit
17c749f3ee
29 changed files with 122 additions and 75 deletions
|
@ -33,6 +33,6 @@ pub trait Generator<Arg = ()> {
|
||||||
/// The type of value this generator returns.
|
/// The type of value this generator returns.
|
||||||
type Return;
|
type Return;
|
||||||
|
|
||||||
/// This resumes the execution of the generator.
|
/// This resumes the execution of the generator.
|
||||||
fn resume(&mut self, arg: Arg) -> State<Self::Yield, Self::Return>;
|
fn resume(&mut self, arg: Arg) -> State<Self::Yield, Self::Return>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2109,7 +2109,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
ExprKind::ImplArg => {
|
ExprKind::ImplArg => {
|
||||||
hir::ExprImplArg(self.impl_arg_id())
|
hir::ExprImplArg(self.impl_arg_id())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Desugar ExprIfLet
|
// Desugar ExprIfLet
|
||||||
// From: `if let <pat> = <sub_expr> <body> [<else_opt>]`
|
// From: `if let <pat> = <sub_expr> <body> [<else_opt>]`
|
||||||
ExprKind::IfLet(ref pat, ref sub_expr, ref body, ref else_opt) => {
|
ExprKind::IfLet(ref pat, ref sub_expr, ref body, ref else_opt) => {
|
||||||
|
|
|
@ -1317,7 +1317,7 @@ impl<'a> State<'a> {
|
||||||
self.head("gen")?;
|
self.head("gen")?;
|
||||||
space(&mut self.s)?;
|
space(&mut self.s)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.print_capture_clause(capture_clause)?;
|
self.print_capture_clause(capture_clause)?;
|
||||||
|
|
||||||
self.print_closure_args(&decl, body)?;
|
self.print_closure_args(&decl, body)?;
|
||||||
|
|
|
@ -146,7 +146,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if local_visitor.found_impl_arg {
|
if local_visitor.found_impl_arg {
|
||||||
labels.push((DUMMY_SP, format!("consider giving a type to the implicit generator argument")));
|
labels.push((DUMMY_SP, format!("consider giving a type to the \
|
||||||
|
implicit generator argument")));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut err = struct_span_err!(self.tcx.sess,
|
let mut err = struct_span_err!(self.tcx.sess,
|
||||||
|
|
|
@ -1075,7 +1075,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RegionResolutionVisitor<'a, 'tcx> {
|
||||||
if let Some(ref impl_arg) = body.impl_arg {
|
if let Some(ref impl_arg) = body.impl_arg {
|
||||||
record_var_lifetime(self, impl_arg.id, impl_arg.span);
|
record_var_lifetime(self, impl_arg.id, impl_arg.span);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The body of the every fn is a root scope.
|
// The body of the every fn is a root scope.
|
||||||
self.cx.parent = self.cx.var_parent;
|
self.cx.parent = self.cx.var_parent;
|
||||||
self.visit_expr(&body.value);
|
self.visit_expr(&body.value);
|
||||||
|
@ -1161,12 +1161,13 @@ impl<'tcx> Visitor<'tcx> for YieldFinder {
|
||||||
if let hir::ExprSuspend(..) = expr.node {
|
if let hir::ExprSuspend(..) = expr.node {
|
||||||
self.0 = true;
|
self.0 = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
intravisit::walk_expr(self, expr);
|
intravisit::walk_expr(self, expr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn extent_has_yield<'a, 'gcx: 'a+'tcx, 'tcx: 'a>(tcx: TyCtxt<'a, 'gcx, 'tcx>, extent: CodeExtent) -> bool {
|
pub fn extent_has_yield<'a, 'gcx: 'a+'tcx, 'tcx: 'a>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||||
|
extent: CodeExtent) -> bool {
|
||||||
let mut finder = YieldFinder(false);
|
let mut finder = YieldFinder(false);
|
||||||
|
|
||||||
match extent {
|
match extent {
|
||||||
|
@ -1181,7 +1182,7 @@ pub fn extent_has_yield<'a, 'gcx: 'a+'tcx, 'tcx: 'a>(tcx: TyCtxt<'a, 'gcx, 'tcx>
|
||||||
}
|
}
|
||||||
Node::NodeExpr(expr) => intravisit::walk_expr(&mut finder, expr),
|
Node::NodeExpr(expr) => intravisit::walk_expr(&mut finder, expr),
|
||||||
Node::NodeStmt(stmt) => intravisit::walk_stmt(&mut finder, stmt),
|
Node::NodeStmt(stmt) => intravisit::walk_stmt(&mut finder, stmt),
|
||||||
Node::NodeBlock(block) => intravisit::walk_block(&mut finder, block),
|
Node::NodeBlock(block) => intravisit::walk_block(&mut finder, block),
|
||||||
_ => bug!(),
|
_ => bug!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1355,7 +1355,8 @@ impl<'tcx> Debug for Rvalue<'tcx> {
|
||||||
}
|
}
|
||||||
struct_fmt.field("$state", &lvs[freevars.len()]);
|
struct_fmt.field("$state", &lvs[freevars.len()]);
|
||||||
for i in (freevars.len() + 1)..lvs.len() {
|
for i in (freevars.len() + 1)..lvs.len() {
|
||||||
struct_fmt.field(&format!("${}", i - freevars.len() - 1), &lvs[i]);
|
struct_fmt.field(&format!("${}", i - freevars.len() - 1),
|
||||||
|
&lvs[i]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -204,7 +204,10 @@ impl<'tcx> Rvalue<'tcx> {
|
||||||
}
|
}
|
||||||
AggregateKind::Generator(did, substs) => {
|
AggregateKind::Generator(did, substs) => {
|
||||||
let node_id = tcx.hir.as_local_node_id(did).unwrap();
|
let node_id = tcx.hir.as_local_node_id(did).unwrap();
|
||||||
let interior = *tcx.typeck_tables_of(did).generator_interiors.get(&node_id).unwrap();
|
let interior = *tcx.typeck_tables_of(did)
|
||||||
|
.generator_interiors
|
||||||
|
.get(&node_id)
|
||||||
|
.unwrap();
|
||||||
tcx.mk_generator(did, substs, interior.subst(tcx, substs.substs))
|
tcx.mk_generator(did, substs, interior.subst(tcx, substs.substs))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -399,7 +399,7 @@ macro_rules! make_mir_visitor {
|
||||||
}
|
}
|
||||||
|
|
||||||
TerminatorKind::Resume |
|
TerminatorKind::Resume |
|
||||||
TerminatorKind::Return |
|
TerminatorKind::Return |
|
||||||
TerminatorKind::GeneratorDrop |
|
TerminatorKind::GeneratorDrop |
|
||||||
TerminatorKind::Unreachable => {
|
TerminatorKind::Unreachable => {
|
||||||
}
|
}
|
||||||
|
|
|
@ -2583,7 +2583,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
|
||||||
value: trait_ref,
|
value: trait_ref,
|
||||||
obligations
|
obligations
|
||||||
} = self.generator_trait_ref(obligation, closure_def_id, substs);
|
} = self.generator_trait_ref(obligation, closure_def_id, substs);
|
||||||
|
|
||||||
debug!("confirm_generator_candidate(closure_def_id={:?}, trait_ref={:?}, obligations={:?})",
|
debug!("confirm_generator_candidate(closure_def_id={:?}, trait_ref={:?}, obligations={:?})",
|
||||||
closure_def_id,
|
closure_def_id,
|
||||||
trait_ref,
|
trait_ref,
|
||||||
|
|
|
@ -525,7 +525,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||||
};
|
};
|
||||||
ty::Binder((trait_ref, sig.skip_binder().suspend_ty, sig.skip_binder().return_ty))
|
ty::Binder((trait_ref, sig.skip_binder().suspend_ty, sig.skip_binder().return_ty))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn impl_is_default(self, node_item_def_id: DefId) -> bool {
|
pub fn impl_is_default(self, node_item_def_id: DefId) -> bool {
|
||||||
match self.hir.as_local_node_id(node_item_def_id) {
|
match self.hir.as_local_node_id(node_item_def_id) {
|
||||||
Some(node_id) => {
|
Some(node_id) => {
|
||||||
|
|
|
@ -1401,7 +1401,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||||
self.mk_ty(TyClosure(closure_id, closure_substs))
|
self.mk_ty(TyClosure(closure_id, closure_substs))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mk_generator(self,
|
pub fn mk_generator(self,
|
||||||
id: DefId,
|
id: DefId,
|
||||||
closure_substs: ClosureSubsts<'tcx>,
|
closure_substs: ClosureSubsts<'tcx>,
|
||||||
interior: GeneratorInterior<'tcx>)
|
interior: GeneratorInterior<'tcx>)
|
||||||
|
|
|
@ -541,7 +541,9 @@ macro_rules! define_maps {
|
||||||
impl<$tcx> Query<$tcx> {
|
impl<$tcx> Query<$tcx> {
|
||||||
pub fn describe(&self, tcx: TyCtxt) -> String {
|
pub fn describe(&self, tcx: TyCtxt) -> String {
|
||||||
let (r, name) = match *self {
|
let (r, name) = match *self {
|
||||||
$(Query::$name(key) => (queries::$name::describe(tcx, key), stringify!($name))),*
|
$(Query::$name(key) => {
|
||||||
|
(queries::$name::describe(tcx, key), stringify!($name))
|
||||||
|
})*
|
||||||
};
|
};
|
||||||
if tcx.sess.verbose() {
|
if tcx.sess.verbose() {
|
||||||
format!("{} [{}]", r, name)
|
format!("{} [{}]", r, name)
|
||||||
|
|
|
@ -304,13 +304,14 @@ impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::AutoBorrow<'a> {
|
||||||
impl<'a, 'tcx> Lift<'tcx> for ty::GenSig<'a> {
|
impl<'a, 'tcx> Lift<'tcx> for ty::GenSig<'a> {
|
||||||
type Lifted = ty::GenSig<'tcx>;
|
type Lifted = ty::GenSig<'tcx>;
|
||||||
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
||||||
tcx.lift(&(self.impl_arg_ty, self.suspend_ty, self.return_ty)).map(|(impl_arg_ty, suspend_ty, return_ty)| {
|
tcx.lift(&(self.impl_arg_ty, self.suspend_ty, self.return_ty))
|
||||||
ty::GenSig {
|
.map(|(impl_arg_ty, suspend_ty, return_ty)| {
|
||||||
impl_arg_ty,
|
ty::GenSig {
|
||||||
suspend_ty,
|
impl_arg_ty,
|
||||||
return_ty,
|
suspend_ty,
|
||||||
}
|
return_ty,
|
||||||
})
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -572,7 +573,9 @@ impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
|
||||||
ty::TyRef(ref r, tm) => {
|
ty::TyRef(ref r, tm) => {
|
||||||
ty::TyRef(r.fold_with(folder), tm.fold_with(folder))
|
ty::TyRef(r.fold_with(folder), tm.fold_with(folder))
|
||||||
}
|
}
|
||||||
ty::TyGenerator(did, substs, interior) => ty::TyGenerator(did, substs.fold_with(folder), interior.fold_with(folder)),
|
ty::TyGenerator(did, substs, interior) => {
|
||||||
|
ty::TyGenerator(did, substs.fold_with(folder), interior.fold_with(folder))
|
||||||
|
}
|
||||||
ty::TyClosure(did, substs) => ty::TyClosure(did, substs.fold_with(folder)),
|
ty::TyClosure(did, substs) => ty::TyClosure(did, substs.fold_with(folder)),
|
||||||
ty::TyProjection(ref data) => ty::TyProjection(data.fold_with(folder)),
|
ty::TyProjection(ref data) => ty::TyProjection(data.fold_with(folder)),
|
||||||
ty::TyAnon(did, substs) => ty::TyAnon(did, substs.fold_with(folder)),
|
ty::TyAnon(did, substs) => ty::TyAnon(did, substs.fold_with(folder)),
|
||||||
|
@ -604,7 +607,9 @@ impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
|
||||||
ty::TyFnDef(_, substs) => substs.visit_with(visitor),
|
ty::TyFnDef(_, substs) => substs.visit_with(visitor),
|
||||||
ty::TyFnPtr(ref f) => f.visit_with(visitor),
|
ty::TyFnPtr(ref f) => f.visit_with(visitor),
|
||||||
ty::TyRef(r, ref tm) => r.visit_with(visitor) || tm.visit_with(visitor),
|
ty::TyRef(r, ref tm) => r.visit_with(visitor) || tm.visit_with(visitor),
|
||||||
ty::TyGenerator(_did, ref substs, ref interior) => substs.visit_with(visitor) || interior.visit_with(visitor),
|
ty::TyGenerator(_did, ref substs, ref interior) => {
|
||||||
|
substs.visit_with(visitor) || interior.visit_with(visitor)
|
||||||
|
}
|
||||||
ty::TyClosure(_did, ref substs) => substs.visit_with(visitor),
|
ty::TyClosure(_did, ref substs) => substs.visit_with(visitor),
|
||||||
ty::TyProjection(ref data) => data.visit_with(visitor),
|
ty::TyProjection(ref data) => data.visit_with(visitor),
|
||||||
ty::TyAnon(_, ref substs) => substs.visit_with(visitor),
|
ty::TyAnon(_, ref substs) => substs.visit_with(visitor),
|
||||||
|
|
|
@ -144,7 +144,7 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for GatherLoanCtxt<'a, 'tcx> {
|
||||||
},
|
},
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
|
|
||||||
if borrows_impl_arg {
|
if borrows_impl_arg {
|
||||||
span_err!(self.bccx.tcx.sess,
|
span_err!(self.bccx.tcx.sess,
|
||||||
borrow_span,
|
borrow_span,
|
||||||
|
|
|
@ -118,14 +118,14 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'t
|
||||||
});
|
});
|
||||||
|
|
||||||
let arguments = implicit_argument.into_iter().chain(explicit_arguments);
|
let arguments = implicit_argument.into_iter().chain(explicit_arguments);
|
||||||
|
|
||||||
let (suspend_ty, impl_arg_ty, return_ty) = if body.is_generator() {
|
let (suspend_ty, impl_arg_ty, return_ty) = if body.is_generator() {
|
||||||
let gen_sig = cx.tables().generator_sigs[&id].clone().unwrap();
|
let gen_sig = cx.tables().generator_sigs[&id].clone().unwrap();
|
||||||
(Some(gen_sig.suspend_ty), Some(gen_sig.impl_arg_ty), gen_sig.return_ty)
|
(Some(gen_sig.suspend_ty), Some(gen_sig.impl_arg_ty), gen_sig.return_ty)
|
||||||
} else {
|
} else {
|
||||||
(None, None, fn_sig.output())
|
(None, None, fn_sig.output())
|
||||||
};
|
};
|
||||||
|
|
||||||
build::construct_fn(cx, id, arguments, abi, return_ty, suspend_ty, impl_arg_ty, body)
|
build::construct_fn(cx, id, arguments, abi, return_ty, suspend_ty, impl_arg_ty, body)
|
||||||
} else {
|
} else {
|
||||||
build::construct_const(cx, body_id)
|
build::construct_const(cx, body_id)
|
||||||
|
|
|
@ -502,7 +502,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
||||||
block,
|
block,
|
||||||
self.arg_count,
|
self.arg_count,
|
||||||
true));
|
true));
|
||||||
|
|
||||||
// End all regions for scopes out of which we are breaking.
|
// End all regions for scopes out of which we are breaking.
|
||||||
self.cfg.push_end_region(block, src_info, scope.extent);
|
self.cfg.push_end_region(block, src_info, scope.extent);
|
||||||
|
|
||||||
|
@ -513,7 +513,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
||||||
block = next;
|
block = next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.cfg.terminate(block, src_info, TerminatorKind::GeneratorDrop);
|
self.cfg.terminate(block, src_info, TerminatorKind::GeneratorDrop);
|
||||||
|
|
||||||
Some(result)
|
Some(result)
|
||||||
|
@ -778,7 +778,13 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
||||||
};
|
};
|
||||||
|
|
||||||
for scope in scopes.iter_mut() {
|
for scope in scopes.iter_mut() {
|
||||||
target = build_diverge_scope(hir.tcx(), cfg, &unit_temp, span, scope, target, generator_drop);
|
target = build_diverge_scope(hir.tcx(),
|
||||||
|
cfg,
|
||||||
|
&unit_temp,
|
||||||
|
span,
|
||||||
|
scope,
|
||||||
|
target,
|
||||||
|
generator_drop);
|
||||||
}
|
}
|
||||||
Some(target)
|
Some(target)
|
||||||
}
|
}
|
||||||
|
@ -858,7 +864,7 @@ fn build_scope_drops<'tcx>(cfg: &mut CFG<'tcx>,
|
||||||
arg_count: usize,
|
arg_count: usize,
|
||||||
generator_drop: bool)
|
generator_drop: bool)
|
||||||
-> BlockAnd<()> {
|
-> BlockAnd<()> {
|
||||||
|
|
||||||
let mut iter = scope.drops(generator_drop).iter().rev().peekable();
|
let mut iter = scope.drops(generator_drop).iter().rev().peekable();
|
||||||
while let Some(drop_data) = iter.next() {
|
while let Some(drop_data) = iter.next() {
|
||||||
let source_info = scope.source_info(drop_data.span);
|
let source_info = scope.source_info(drop_data.span);
|
||||||
|
|
|
@ -327,7 +327,8 @@ fn locals_live_across_suspend_points<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The implicit argument is defined after each suspend point so it can never be live in a suspend point.
|
// The implicit argument is defined after each suspend point so it can never
|
||||||
|
// be live in a suspend point.
|
||||||
set.remove(&Local::new(2));
|
set.remove(&Local::new(2));
|
||||||
|
|
||||||
// The generator argument is ignored
|
// The generator argument is ignored
|
||||||
|
@ -340,7 +341,9 @@ fn compute_layout<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
source: MirSource,
|
source: MirSource,
|
||||||
interior: GeneratorInterior<'tcx>,
|
interior: GeneratorInterior<'tcx>,
|
||||||
mir: &mut Mir<'tcx>) -> (HashMap<Local, (Ty<'tcx>, usize)>, GeneratorLayout<'tcx>) {
|
mir: &mut Mir<'tcx>)
|
||||||
|
-> (HashMap<Local, (Ty<'tcx>, usize)>, GeneratorLayout<'tcx>)
|
||||||
|
{
|
||||||
let source_info = SourceInfo {
|
let source_info = SourceInfo {
|
||||||
span: mir.span,
|
span: mir.span,
|
||||||
scope: ARGUMENT_VISIBILITY_SCOPE,
|
scope: ARGUMENT_VISIBILITY_SCOPE,
|
||||||
|
@ -349,7 +352,7 @@ fn compute_layout<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
let mut live_locals = locals_live_across_suspend_points(tcx, mir, source);
|
let mut live_locals = locals_live_across_suspend_points(tcx, mir, source);
|
||||||
|
|
||||||
let allowed = tcx.erase_regions(&interior.as_slice());
|
let allowed = tcx.erase_regions(&interior.as_slice());
|
||||||
|
|
||||||
for (local, decl) in mir.local_decls.iter_enumerated() {
|
for (local, decl) in mir.local_decls.iter_enumerated() {
|
||||||
if !live_locals.contains(&local) {
|
if !live_locals.contains(&local) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -363,7 +366,10 @@ fn compute_layout<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
let upvar_len = mir.upvar_decls.len();
|
let upvar_len = mir.upvar_decls.len();
|
||||||
let live_decls : Vec<_> = mir.local_decls.iter_enumerated_mut().filter(|&(local, _)| live_locals.contains(&local)).collect();
|
let live_decls : Vec<_> = mir.local_decls
|
||||||
|
.iter_enumerated_mut()
|
||||||
|
.filter(|&(local, _)| live_locals.contains(&local))
|
||||||
|
.collect();
|
||||||
|
|
||||||
let mut remap = HashMap::new();
|
let mut remap = HashMap::new();
|
||||||
let unit = tcx.mk_nil();
|
let unit = tcx.mk_nil();
|
||||||
|
@ -383,7 +389,7 @@ fn compute_layout<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
let layout = GeneratorLayout {
|
let layout = GeneratorLayout {
|
||||||
fields: vars
|
fields: vars
|
||||||
};
|
};
|
||||||
|
|
||||||
(remap, layout)
|
(remap, layout)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -421,7 +427,7 @@ fn elaborate_generator_drops<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
_ => continue,
|
_ => continue,
|
||||||
};
|
};
|
||||||
let unwind = if let Some(unwind) = unwind {
|
let unwind = if let Some(unwind) = unwind {
|
||||||
Unwind::To(unwind)
|
Unwind::To(unwind)
|
||||||
} else {
|
} else {
|
||||||
Unwind::InCleanup
|
Unwind::InCleanup
|
||||||
};
|
};
|
||||||
|
@ -503,7 +509,7 @@ fn generate_drop<'a, 'tcx>(
|
||||||
// Remove the implicit argument
|
// Remove the implicit argument
|
||||||
mir.arg_count = 1;
|
mir.arg_count = 1;
|
||||||
mir.local_decls.raw.pop();
|
mir.local_decls.raw.pop();
|
||||||
|
|
||||||
// Replace the return variable
|
// Replace the return variable
|
||||||
let source_info = SourceInfo {
|
let source_info = SourceInfo {
|
||||||
span: mir.span,
|
span: mir.span,
|
||||||
|
@ -524,7 +530,7 @@ fn generate_drop<'a, 'tcx>(
|
||||||
mutability: Mutability::Mut,
|
mutability: Mutability::Mut,
|
||||||
ty: tcx.mk_ptr(ty::TypeAndMut {
|
ty: tcx.mk_ptr(ty::TypeAndMut {
|
||||||
ty: gen_ty,
|
ty: gen_ty,
|
||||||
mutbl: hir::Mutability::MutMutable,
|
mutbl: hir::Mutability::MutMutable,
|
||||||
}),
|
}),
|
||||||
name: None,
|
name: None,
|
||||||
source_info,
|
source_info,
|
||||||
|
@ -650,7 +656,10 @@ fn generate_resume<'a, 'tcx>(
|
||||||
values: Cow::from(transform.bb_targets.values().map(|&i| {
|
values: Cow::from(transform.bb_targets.values().map(|&i| {
|
||||||
ConstInt::U32(i)
|
ConstInt::U32(i)
|
||||||
}).collect::<Vec<_>>()),
|
}).collect::<Vec<_>>()),
|
||||||
targets: transform.bb_targets.keys().map(|&(k, _)| k).chain(once(transform.return_block)).collect(),
|
targets: transform.bb_targets.keys()
|
||||||
|
.map(|&(k, _)| k)
|
||||||
|
.chain(once(transform.return_block))
|
||||||
|
.collect(),
|
||||||
};
|
};
|
||||||
|
|
||||||
insert_entry_point(mir, BasicBlockData {
|
insert_entry_point(mir, BasicBlockData {
|
||||||
|
@ -661,7 +670,7 @@ fn generate_resume<'a, 'tcx>(
|
||||||
}),
|
}),
|
||||||
is_cleanup: false,
|
is_cleanup: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Make sure we remove dead blocks to remove
|
// Make sure we remove dead blocks to remove
|
||||||
// unrelated code from the drop part of the function
|
// unrelated code from the drop part of the function
|
||||||
simplify::remove_dead_blocks(mir);
|
simplify::remove_dead_blocks(mir);
|
||||||
|
|
|
@ -34,7 +34,10 @@ fn mirbug(tcx: TyCtxt, span: Span, msg: &str) {
|
||||||
macro_rules! span_mirbug {
|
macro_rules! span_mirbug {
|
||||||
($context:expr, $elem:expr, $($message:tt)*) => ({
|
($context:expr, $elem:expr, $($message:tt)*) => ({
|
||||||
mirbug($context.tcx(), $context.last_span,
|
mirbug($context.tcx(), $context.last_span,
|
||||||
&format!("broken MIR in {:?} ({:?}): {}", $context.body_id, $elem, format!($($message)*)))
|
&format!("broken MIR in {:?} ({:?}): {}",
|
||||||
|
$context.body_id,
|
||||||
|
$elem,
|
||||||
|
format_args!($($message)*)))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,8 @@
|
||||||
|
|
||||||
//! Liveness analysis.
|
//! Liveness analysis.
|
||||||
|
|
||||||
// FIXME: Make sure this analysis uses proper MIR semantics. Also find out what the MIR semantics are.
|
// FIXME: Make sure this analysis uses proper MIR semantics. Also find out what
|
||||||
|
// the MIR semantics are.
|
||||||
|
|
||||||
use rustc::mir::*;
|
use rustc::mir::*;
|
||||||
use rustc::mir::visit::{LvalueContext, Visitor};
|
use rustc::mir::visit::{LvalueContext, Visitor};
|
||||||
|
@ -188,7 +189,10 @@ pub fn write_mir_fn<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
write_mir_intro(tcx, src, mir, w)?;
|
write_mir_intro(tcx, src, mir, w)?;
|
||||||
for block in mir.basic_blocks().indices() {
|
for block in mir.basic_blocks().indices() {
|
||||||
let print = |w: &mut Write, prefix, result: &IndexVec<BasicBlock, LocalSet>| {
|
let print = |w: &mut Write, prefix, result: &IndexVec<BasicBlock, LocalSet>| {
|
||||||
let live: Vec<String> = mir.local_decls.indices().filter(|i| result[block].contains(i)).map(|i| format!("{:?}", i)).collect();
|
let live: Vec<String> = mir.local_decls.indices()
|
||||||
|
.filter(|i| result[block].contains(i))
|
||||||
|
.map(|i| format!("{:?}", i))
|
||||||
|
.collect();
|
||||||
writeln!(w, "{} {{{}}}", prefix, live.join(", "))
|
writeln!(w, "{} {{{}}}", prefix, live.join(", "))
|
||||||
};
|
};
|
||||||
print(w, " ", &result.ins)?;
|
print(w, " ", &result.ins)?;
|
||||||
|
|
|
@ -171,8 +171,12 @@ impl<'a, 'tcx> mir_visit::Visitor<'tcx> for StatCollector<'a, 'tcx> {
|
||||||
self.record(match *msg {
|
self.record(match *msg {
|
||||||
AssertMessage::BoundsCheck { .. } => "AssertMessage::BoundsCheck",
|
AssertMessage::BoundsCheck { .. } => "AssertMessage::BoundsCheck",
|
||||||
AssertMessage::Math(..) => "AssertMessage::Math",
|
AssertMessage::Math(..) => "AssertMessage::Math",
|
||||||
AssertMessage::GeneratorResumedAfterReturn => "AssertMessage::GeneratorResumedAfterReturn",
|
AssertMessage::GeneratorResumedAfterReturn => {
|
||||||
AssertMessage::GeneratorResumedAfterPanic => "AssertMessage::GeneratorResumedAfterPanic",
|
"AssertMessage::GeneratorResumedAfterReturn"
|
||||||
|
}
|
||||||
|
AssertMessage::GeneratorResumedAfterPanic => {
|
||||||
|
"AssertMessage::GeneratorResumedAfterPanic"
|
||||||
|
}
|
||||||
}, msg);
|
}, msg);
|
||||||
self.super_assert_message(msg, location);
|
self.super_assert_message(msg, location);
|
||||||
}
|
}
|
||||||
|
|
|
@ -323,7 +323,7 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> {
|
||||||
ErrKind::Math(err.clone())
|
ErrKind::Math(err.clone())
|
||||||
}
|
}
|
||||||
mir::AssertMessage::GeneratorResumedAfterReturn |
|
mir::AssertMessage::GeneratorResumedAfterReturn |
|
||||||
mir::AssertMessage::GeneratorResumedAfterPanic =>
|
mir::AssertMessage::GeneratorResumedAfterPanic =>
|
||||||
span_bug!(span, "{:?} should not appear in constants?", msg),
|
span_bug!(span, "{:?} should not appear in constants?", msg),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -528,7 +528,7 @@ fn arg_local_refs<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
|
||||||
ty::TyRef(_, mt) | ty::TyRawPtr(mt) => (mt.ty, true),
|
ty::TyRef(_, mt) | ty::TyRawPtr(mt) => (mt.ty, true),
|
||||||
_ => (arg_ty, false)
|
_ => (arg_ty, false)
|
||||||
};
|
};
|
||||||
|
|
||||||
let upvar_tys = match closure_ty.sty {
|
let upvar_tys = match closure_ty.sty {
|
||||||
ty::TyClosure(def_id, substs) |
|
ty::TyClosure(def_id, substs) |
|
||||||
ty::TyGenerator(def_id, substs, _) => substs.upvar_tys(def_id, tcx),
|
ty::TyGenerator(def_id, substs, _) => substs.upvar_tys(def_id, tcx),
|
||||||
|
|
|
@ -33,7 +33,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
expr,
|
expr,
|
||||||
expected);
|
expected);
|
||||||
// FIXME: See if expected_kind here can impact generators
|
// FIXME: See if expected_kind here can impact generators
|
||||||
|
|
||||||
// It's always helpful for inference if we know the kind of
|
// It's always helpful for inference if we know the kind of
|
||||||
// closure sooner rather than later, so first examine the expected
|
// closure sooner rather than later, so first examine the expected
|
||||||
// type, and see if can glean a closure kind from there.
|
// type, and see if can glean a closure kind from there.
|
||||||
|
|
|
@ -31,10 +31,13 @@ impl<'a, 'gcx, 'tcx> InteriorVisitor<'a, 'gcx, 'tcx> {
|
||||||
if self.fcx.tcx.sess.verbose() {
|
if self.fcx.tcx.sess.verbose() {
|
||||||
if let Some(s) = scope {
|
if let Some(s) = scope {
|
||||||
self.fcx.tcx.sess.span_warn(s.span(&self.fcx.tcx.hir).unwrap_or(DUMMY_SP),
|
self.fcx.tcx.sess.span_warn(s.span(&self.fcx.tcx.hir).unwrap_or(DUMMY_SP),
|
||||||
&format!("type in generator with scope = {:?}, type = {:?}", scope, self.fcx.resolve_type_vars_if_possible(&ty)));
|
&format!("type in generator with scope = {:?}, type = {:?}",
|
||||||
|
scope,
|
||||||
|
self.fcx.resolve_type_vars_if_possible(&ty)));
|
||||||
} else {
|
} else {
|
||||||
self.fcx.tcx.sess.span_warn(DUMMY_SP,
|
self.fcx.tcx.sess.span_warn(DUMMY_SP,
|
||||||
&format!("type in generator WITHOUT scope, type = {:?}", self.fcx.resolve_type_vars_if_possible(&ty)));
|
&format!("type in generator WITHOUT scope, type = {:?}",
|
||||||
|
self.fcx.resolve_type_vars_if_possible(&ty)));
|
||||||
}
|
}
|
||||||
if let Some(e) = expr {
|
if let Some(e) = expr {
|
||||||
self.fcx.tcx.sess.span_warn(e.span,
|
self.fcx.tcx.sess.span_warn(e.span,
|
||||||
|
@ -51,7 +54,10 @@ impl<'a, 'gcx, 'tcx> InteriorVisitor<'a, 'gcx, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_interior<'a, 'gcx, 'tcx>(fcx: &'a FnCtxt<'a, 'gcx, 'tcx>, def_id: DefId, body_id: hir::BodyId, witness: Ty<'tcx>) {
|
pub fn find_interior<'a, 'gcx, 'tcx>(fcx: &'a FnCtxt<'a, 'gcx, 'tcx>,
|
||||||
|
def_id: DefId,
|
||||||
|
body_id: hir::BodyId,
|
||||||
|
witness: Ty<'tcx>) {
|
||||||
let body = fcx.tcx.hir.body(body_id);
|
let body = fcx.tcx.hir.body(body_id);
|
||||||
let mut visitor = InteriorVisitor {
|
let mut visitor = InteriorVisitor {
|
||||||
fcx,
|
fcx,
|
||||||
|
@ -64,7 +70,9 @@ pub fn find_interior<'a, 'gcx, 'tcx>(fcx: &'a FnCtxt<'a, 'gcx, 'tcx>, def_id: De
|
||||||
visitor.types.insert(fcx.tcx.types.bool);
|
visitor.types.insert(fcx.tcx.types.bool);
|
||||||
|
|
||||||
// Deduplicate types
|
// Deduplicate types
|
||||||
let set: FxHashSet<_> = visitor.types.into_iter().map(|t| fcx.resolve_type_vars_if_possible(&t)).collect();
|
let set: FxHashSet<_> = visitor.types.into_iter()
|
||||||
|
.map(|t| fcx.resolve_type_vars_if_possible(&t))
|
||||||
|
.collect();
|
||||||
let types: Vec<_> = set.into_iter().collect();
|
let types: Vec<_> = set.into_iter().collect();
|
||||||
|
|
||||||
let tuple = fcx.tcx.intern_tup(&types, false);
|
let tuple = fcx.tcx.intern_tup(&types, false);
|
||||||
|
|
|
@ -2567,7 +2567,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let is_closure = match arg.node {
|
let is_closure = match arg.node {
|
||||||
// TODO: Should this be applied for generators?
|
// FIXME: Should this be applied for generators?
|
||||||
hir::ExprClosure(.., None) => true,
|
hir::ExprClosure(.., None) => true,
|
||||||
_ => false
|
_ => false
|
||||||
};
|
};
|
||||||
|
|
|
@ -1159,7 +1159,7 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
if gen.is_some() {
|
if gen.is_some() {
|
||||||
return tcx.typeck_tables_of(def_id).node_id_to_type(node_id);
|
return tcx.typeck_tables_of(def_id).node_id_to_type(node_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
tcx.mk_closure(def_id, Substs::for_item(
|
tcx.mk_closure(def_id, Substs::for_item(
|
||||||
tcx, def_id,
|
tcx, def_id,
|
||||||
|def, _| {
|
|def, _| {
|
||||||
|
|
|
@ -3714,7 +3714,7 @@ impl<'a> Parser<'a> {
|
||||||
self.token.is_keyword(keywords::Gen) &&
|
self.token.is_keyword(keywords::Gen) &&
|
||||||
self.look_ahead(1, |t| t.is_keyword(keywords::Arg))
|
self.look_ahead(1, |t| t.is_keyword(keywords::Arg))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_defaultness(&self) -> bool {
|
fn is_defaultness(&self) -> bool {
|
||||||
// `pub` is included for better error messages
|
// `pub` is included for better error messages
|
||||||
self.token.is_keyword(keywords::Default) &&
|
self.token.is_keyword(keywords::Default) &&
|
||||||
|
|
|
@ -11,15 +11,15 @@
|
||||||
#![feature(generators)]
|
#![feature(generators)]
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut a = Vec::<bool>::new();
|
let mut a = Vec::<bool>::new();
|
||||||
|
|
||||||
let mut test = || {
|
let mut test = || {
|
||||||
let _: () = gen arg;
|
let _: () = gen arg;
|
||||||
yield 3;
|
yield 3;
|
||||||
a.push(true);
|
a.push(true);
|
||||||
2
|
2
|
||||||
};
|
};
|
||||||
|
|
||||||
let a1 = test();
|
let a1 = test();
|
||||||
let a2 = test(); //~ ERROR use of moved value
|
let a2 = test(); //~ ERROR use of moved value
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,19 +26,19 @@ impl<T: Generator<Return = ()>> Iterator for W<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test() -> impl Generator<Return=(), Yield=u8> {
|
fn test() -> impl Generator<Return=(), Yield=u8> {
|
||||||
for i in 1..6 {
|
for i in 1..6 {
|
||||||
yield i
|
yield i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let end = 11;
|
let end = 11;
|
||||||
|
|
||||||
let closure_test = |start| {
|
let closure_test = |start| {
|
||||||
for i in start..end {
|
for i in start..end {
|
||||||
yield i
|
yield i
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
assert!(W(test()).chain(W(closure_test(6))).eq(1..11));
|
assert!(W(test()).chain(W(closure_test(6))).eq(1..11));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue