Fix tidy warnings

This commit is contained in:
Alex Crichton 2017-07-05 14:57:26 -07:00 committed by John Kåre Alsaker
parent d861982ca6
commit 17c749f3ee
29 changed files with 122 additions and 75 deletions

View File

@ -33,6 +33,6 @@ pub trait Generator<Arg = ()> {
/// The type of value this generator returns.
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>;
}

View File

@ -2109,7 +2109,7 @@ impl<'a> LoweringContext<'a> {
ExprKind::ImplArg => {
hir::ExprImplArg(self.impl_arg_id())
}
// Desugar ExprIfLet
// From: `if let <pat> = <sub_expr> <body> [<else_opt>]`
ExprKind::IfLet(ref pat, ref sub_expr, ref body, ref else_opt) => {

View File

@ -1317,7 +1317,7 @@ impl<'a> State<'a> {
self.head("gen")?;
space(&mut self.s)?;
}
self.print_capture_clause(capture_clause)?;
self.print_closure_args(&decl, body)?;

View File

@ -146,7 +146,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
}
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,

View File

@ -1075,7 +1075,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RegionResolutionVisitor<'a, 'tcx> {
if let Some(ref impl_arg) = body.impl_arg {
record_var_lifetime(self, impl_arg.id, impl_arg.span);
}
// The body of the every fn is a root scope.
self.cx.parent = self.cx.var_parent;
self.visit_expr(&body.value);
@ -1161,12 +1161,13 @@ impl<'tcx> Visitor<'tcx> for YieldFinder {
if let hir::ExprSuspend(..) = expr.node {
self.0 = true;
}
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);
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::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!(),
}
}

View File

@ -1355,7 +1355,8 @@ impl<'tcx> Debug for Rvalue<'tcx> {
}
struct_fmt.field("$state", &lvs[freevars.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]);
}
});

View File

@ -204,7 +204,10 @@ impl<'tcx> Rvalue<'tcx> {
}
AggregateKind::Generator(did, substs) => {
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))
}
}

View File

@ -399,7 +399,7 @@ macro_rules! make_mir_visitor {
}
TerminatorKind::Resume |
TerminatorKind::Return |
TerminatorKind::Return |
TerminatorKind::GeneratorDrop |
TerminatorKind::Unreachable => {
}

View File

@ -2583,7 +2583,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
value: trait_ref,
obligations
} = self.generator_trait_ref(obligation, closure_def_id, substs);
debug!("confirm_generator_candidate(closure_def_id={:?}, trait_ref={:?}, obligations={:?})",
closure_def_id,
trait_ref,

View File

@ -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))
}
pub fn impl_is_default(self, node_item_def_id: DefId) -> bool {
match self.hir.as_local_node_id(node_item_def_id) {
Some(node_id) => {

View File

@ -1401,7 +1401,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
self.mk_ty(TyClosure(closure_id, closure_substs))
}
pub fn mk_generator(self,
pub fn mk_generator(self,
id: DefId,
closure_substs: ClosureSubsts<'tcx>,
interior: GeneratorInterior<'tcx>)

View File

@ -541,7 +541,9 @@ macro_rules! define_maps {
impl<$tcx> Query<$tcx> {
pub fn describe(&self, tcx: TyCtxt) -> String {
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() {
format!("{} [{}]", r, name)

View File

@ -304,13 +304,14 @@ impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::AutoBorrow<'a> {
impl<'a, 'tcx> Lift<'tcx> for ty::GenSig<'a> {
type Lifted = ty::GenSig<'tcx>;
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)| {
ty::GenSig {
impl_arg_ty,
suspend_ty,
return_ty,
}
})
tcx.lift(&(self.impl_arg_ty, self.suspend_ty, self.return_ty))
.map(|(impl_arg_ty, suspend_ty, return_ty)| {
ty::GenSig {
impl_arg_ty,
suspend_ty,
return_ty,
}
})
}
}
@ -572,7 +573,9 @@ impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
ty::TyRef(ref r, tm) => {
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::TyProjection(ref data) => ty::TyProjection(data.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::TyFnPtr(ref f) => f.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::TyProjection(ref data) => data.visit_with(visitor),
ty::TyAnon(_, ref substs) => substs.visit_with(visitor),

View File

@ -144,7 +144,7 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for GatherLoanCtxt<'a, 'tcx> {
},
_ => false,
};
if borrows_impl_arg {
span_err!(self.bccx.tcx.sess,
borrow_span,

View File

@ -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 (suspend_ty, impl_arg_ty, return_ty) = if body.is_generator() {
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)
} else {
(None, None, fn_sig.output())
};
build::construct_fn(cx, id, arguments, abi, return_ty, suspend_ty, impl_arg_ty, body)
} else {
build::construct_const(cx, body_id)

View File

@ -502,7 +502,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
block,
self.arg_count,
true));
// End all regions for scopes out of which we are breaking.
self.cfg.push_end_region(block, src_info, scope.extent);
@ -513,7 +513,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
block = next;
}
}
self.cfg.terminate(block, src_info, TerminatorKind::GeneratorDrop);
Some(result)
@ -778,7 +778,13 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
};
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)
}
@ -858,7 +864,7 @@ fn build_scope_drops<'tcx>(cfg: &mut CFG<'tcx>,
arg_count: usize,
generator_drop: bool)
-> BlockAnd<()> {
let mut iter = scope.drops(generator_drop).iter().rev().peekable();
while let Some(drop_data) = iter.next() {
let source_info = scope.source_info(drop_data.span);

View File

@ -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));
// The generator argument is ignored
@ -340,7 +341,9 @@ fn compute_layout<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
def_id: DefId,
source: MirSource,
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 {
span: mir.span,
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 allowed = tcx.erase_regions(&interior.as_slice());
for (local, decl) in mir.local_decls.iter_enumerated() {
if !live_locals.contains(&local) {
continue;
@ -363,7 +366,10 @@ fn compute_layout<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
}
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 unit = tcx.mk_nil();
@ -383,7 +389,7 @@ fn compute_layout<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let layout = GeneratorLayout {
fields: vars
};
(remap, layout)
}
@ -421,7 +427,7 @@ fn elaborate_generator_drops<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
_ => continue,
};
let unwind = if let Some(unwind) = unwind {
Unwind::To(unwind)
Unwind::To(unwind)
} else {
Unwind::InCleanup
};
@ -503,7 +509,7 @@ fn generate_drop<'a, 'tcx>(
// Remove the implicit argument
mir.arg_count = 1;
mir.local_decls.raw.pop();
// Replace the return variable
let source_info = SourceInfo {
span: mir.span,
@ -524,7 +530,7 @@ fn generate_drop<'a, 'tcx>(
mutability: Mutability::Mut,
ty: tcx.mk_ptr(ty::TypeAndMut {
ty: gen_ty,
mutbl: hir::Mutability::MutMutable,
mutbl: hir::Mutability::MutMutable,
}),
name: None,
source_info,
@ -650,7 +656,10 @@ fn generate_resume<'a, 'tcx>(
values: Cow::from(transform.bb_targets.values().map(|&i| {
ConstInt::U32(i)
}).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 {
@ -661,7 +670,7 @@ fn generate_resume<'a, 'tcx>(
}),
is_cleanup: false,
});
// Make sure we remove dead blocks to remove
// unrelated code from the drop part of the function
simplify::remove_dead_blocks(mir);

View File

@ -34,7 +34,10 @@ fn mirbug(tcx: TyCtxt, span: Span, msg: &str) {
macro_rules! span_mirbug {
($context:expr, $elem:expr, $($message:tt)*) => ({
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)*)))
})
}

View File

@ -10,7 +10,8 @@
//! 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::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)?;
for block in mir.basic_blocks().indices() {
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(", "))
};
print(w, " ", &result.ins)?;

View File

@ -171,8 +171,12 @@ impl<'a, 'tcx> mir_visit::Visitor<'tcx> for StatCollector<'a, 'tcx> {
self.record(match *msg {
AssertMessage::BoundsCheck { .. } => "AssertMessage::BoundsCheck",
AssertMessage::Math(..) => "AssertMessage::Math",
AssertMessage::GeneratorResumedAfterReturn => "AssertMessage::GeneratorResumedAfterReturn",
AssertMessage::GeneratorResumedAfterPanic => "AssertMessage::GeneratorResumedAfterPanic",
AssertMessage::GeneratorResumedAfterReturn => {
"AssertMessage::GeneratorResumedAfterReturn"
}
AssertMessage::GeneratorResumedAfterPanic => {
"AssertMessage::GeneratorResumedAfterPanic"
}
}, msg);
self.super_assert_message(msg, location);
}

View File

@ -323,7 +323,7 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> {
ErrKind::Math(err.clone())
}
mir::AssertMessage::GeneratorResumedAfterReturn |
mir::AssertMessage::GeneratorResumedAfterPanic =>
mir::AssertMessage::GeneratorResumedAfterPanic =>
span_bug!(span, "{:?} should not appear in constants?", msg),
};

View File

@ -528,7 +528,7 @@ fn arg_local_refs<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
ty::TyRef(_, mt) | ty::TyRawPtr(mt) => (mt.ty, true),
_ => (arg_ty, false)
};
let upvar_tys = match closure_ty.sty {
ty::TyClosure(def_id, substs) |
ty::TyGenerator(def_id, substs, _) => substs.upvar_tys(def_id, tcx),

View File

@ -33,7 +33,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
expr,
expected);
// FIXME: See if expected_kind here can impact generators
// It's always helpful for inference if we know the kind of
// closure sooner rather than later, so first examine the expected
// type, and see if can glean a closure kind from there.

View File

@ -31,10 +31,13 @@ impl<'a, 'gcx, 'tcx> InteriorVisitor<'a, 'gcx, 'tcx> {
if self.fcx.tcx.sess.verbose() {
if let Some(s) = scope {
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 {
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 {
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 mut visitor = InteriorVisitor {
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);
// 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 tuple = fcx.tcx.intern_tup(&types, false);

View File

@ -2567,7 +2567,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}
let is_closure = match arg.node {
// TODO: Should this be applied for generators?
// FIXME: Should this be applied for generators?
hir::ExprClosure(.., None) => true,
_ => false
};

View File

@ -1159,7 +1159,7 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
if gen.is_some() {
return tcx.typeck_tables_of(def_id).node_id_to_type(node_id);
}
tcx.mk_closure(def_id, Substs::for_item(
tcx, def_id,
|def, _| {

View File

@ -3714,7 +3714,7 @@ impl<'a> Parser<'a> {
self.token.is_keyword(keywords::Gen) &&
self.look_ahead(1, |t| t.is_keyword(keywords::Arg))
}
fn is_defaultness(&self) -> bool {
// `pub` is included for better error messages
self.token.is_keyword(keywords::Default) &&

View File

@ -11,15 +11,15 @@
#![feature(generators)]
fn main() {
let mut a = Vec::<bool>::new();
let mut a = Vec::<bool>::new();
let mut test = || {
let _: () = gen arg;
yield 3;
a.push(true);
2
};
let mut test = || {
let _: () = gen arg;
yield 3;
a.push(true);
2
};
let a1 = test();
let a2 = test(); //~ ERROR use of moved value
let a1 = test();
let a2 = test(); //~ ERROR use of moved value
}

View File

@ -26,19 +26,19 @@ impl<T: Generator<Return = ()>> Iterator for W<T> {
}
fn test() -> impl Generator<Return=(), Yield=u8> {
for i in 1..6 {
yield i
}
for i in 1..6 {
yield i
}
}
fn main() {
let end = 11;
let end = 11;
let closure_test = |start| {
for i in start..end {
yield i
}
};
let closure_test = |start| {
for i in start..end {
yield i
}
};
assert!(W(test()).chain(W(closure_test(6))).eq(1..11));
assert!(W(test()).chain(W(closure_test(6))).eq(1..11));
}