From 9d3c59d69750e07d9446339c4b733c925d3571bc Mon Sep 17 00:00:00 2001 From: Albin Stjerna Date: Fri, 12 Jul 2019 22:49:15 +0200 Subject: [PATCH] rustfmt all the things! --- src/librustc/mir/mod.rs | 729 ++++++------------ src/librustc_mir/borrow_check/flows.rs | 9 +- src/librustc_mir/borrow_check/nll/facts.rs | 45 +- .../nll/type_check/liveness/mod.rs | 2 +- .../nll/type_check/liveness/trace.rs | 63 +- 5 files changed, 246 insertions(+), 602 deletions(-) diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 2190f122880..783964c701a 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -9,6 +9,16 @@ use crate::hir::{self, InlineAsm as HirInlineAsm}; use crate::mir::interpret::{ConstValue, InterpError, Scalar}; use crate::mir::visit::MirVisitable; +use crate::rustc_serialize as serialize; +use crate::ty::adjustment::PointerCast; +use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor}; +use crate::ty::layout::VariantIdx; +use crate::ty::print::{FmtPrinter, Printer}; +use crate::ty::subst::{Subst, SubstsRef}; +use crate::ty::{ + self, AdtDef, CanonicalUserTypeAnnotations, ClosureSubsts, GeneratorSubsts, Region, Ty, TyCtxt, + UserTypeAnnotationIndex, +}; use polonius_engine::Atom; use rustc_data_structures::bit_set::BitMatrix; use rustc_data_structures::fx::FxHashSet; @@ -18,10 +28,9 @@ use rustc_data_structures::sync::Lrc; use rustc_data_structures::sync::MappedReadGuard; use rustc_macros::HashStable; -use crate::rustc_serialize::{self as serialize}; use smallvec::SmallVec; use std::borrow::Cow; -use std::fmt::{self, Debug, Formatter, Write, Display}; +use std::fmt::{self, Debug, Display, Formatter, Write}; use std::iter::FusedIterator; use std::ops::{Index, IndexMut}; use std::slice; @@ -30,15 +39,6 @@ use syntax::ast::Name; use syntax::symbol::{InternedString, Symbol}; use syntax_pos::{Span, DUMMY_SP}; -use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor}; -use crate::ty::subst::{Subst, SubstsRef}; -use crate::ty::layout::VariantIdx; -use crate::ty::{ - self, AdtDef, CanonicalUserTypeAnnotations, ClosureSubsts, GeneratorSubsts, Region, Ty, TyCtxt, - UserTypeAnnotationIndex, -}; -use crate::ty::print::{FmtPrinter, Printer}; -use crate::ty::adjustment::{PointerCast}; pub use crate::mir::interpret::AssertMessage; @@ -225,10 +225,7 @@ pub fn basic_blocks_mut(&mut self) -> &mut IndexVec ( - &mut IndexVec>, - &mut LocalDecls<'tcx>, - ) { + ) -> (&mut IndexVec>, &mut LocalDecls<'tcx>) { self.cache.invalidate(); (&mut self.basic_blocks, &mut self.local_decls) } @@ -260,16 +257,10 @@ pub fn predecessor_locations(&self, loc: Location) -> impl Iterator Ty<'tcx> { /// Gets the location of the terminator for the given block pub fn terminator_loc(&self, bb: BasicBlock) -> Location { - Location { - block: bb, - statement_index: self[bb].statements.len(), - } + Location { block: bb, statement_index: self[bb].statements.len() } } } @@ -509,8 +497,9 @@ fn from(m: Mutability) -> Self { } } -#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, - Ord, RustcEncodable, RustcDecodable, HashStable)] +#[derive( + Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, RustcEncodable, RustcDecodable, HashStable, +)] pub enum BorrowKind { /// Data must be immutable and is aliasable. Shared, @@ -665,7 +654,7 @@ pub enum ImplicitSelfKind { MutRef, /// Represents when a function does not have a self argument or /// when a function has a `self: X` argument. - None + None, } CloneTypeFoldableAndLiftImpls! { BindingForm<'tcx>, } @@ -896,8 +885,7 @@ pub fn can_be_made_mutable(&self) -> bool { pat_span: _, }))) => true, - Some(ClearCrossCrate::Set(BindingForm::ImplicitSelf(ImplicitSelfKind::Imm))) - => true, + Some(ClearCrossCrate::Set(BindingForm::ImplicitSelf(ImplicitSelfKind::Imm))) => true, _ => false, } @@ -966,21 +954,13 @@ pub fn new_internal(ty: Ty<'tcx>, span: Span) -> Self { } #[inline] - fn new_local( - ty: Ty<'tcx>, - mutability: Mutability, - internal: bool, - span: Span, - ) -> Self { + fn new_local(ty: Ty<'tcx>, mutability: Mutability, internal: bool, span: Span) -> Self { LocalDecl { mutability, ty, user_ty: UserTypeProjections::none(), name: None, - source_info: SourceInfo { - span, - scope: OUTERMOST_SOURCE_SCOPE, - }, + source_info: SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE }, visibility_scope: OUTERMOST_SOURCE_SCOPE, internal, is_user_variable: None, @@ -997,10 +977,7 @@ pub fn new_return_place(return_ty: Ty<'_>, span: Span) -> LocalDecl<'_> { mutability: Mutability::Mut, ty: return_ty, user_ty: UserTypeProjections::none(), - source_info: SourceInfo { - span, - scope: OUTERMOST_SOURCE_SCOPE, - }, + source_info: SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE }, visibility_scope: OUTERMOST_SOURCE_SCOPE, internal: false, is_block_tail: None, @@ -1032,10 +1009,7 @@ pub struct BasicBlock { impl BasicBlock { pub fn start_location(self) -> Location { - Location { - block: self, - statement_index: 0, - } + Location { block: self, statement_index: 0 } } } @@ -1118,11 +1092,7 @@ pub enum TerminatorKind<'tcx> { Unreachable, /// Drop the Place - Drop { - location: Place<'tcx>, - target: BasicBlock, - unwind: Option, - }, + Drop { location: Place<'tcx>, target: BasicBlock, unwind: Option }, /// Drop the Place and assign the new value over it. This ensures /// that the assignment to `P` occurs *even if* the destructor for @@ -1270,80 +1240,27 @@ pub fn successors(&self) -> Successors<'_> { | GeneratorDrop | Return | Unreachable - | Call { - destination: None, - cleanup: None, - .. - } => None.into_iter().chain(&[]), + | Call { destination: None, cleanup: None, .. } => None.into_iter().chain(&[]), Goto { target: ref t } - | Call { - destination: None, - cleanup: Some(ref t), - .. + | Call { destination: None, cleanup: Some(ref t), .. } + | Call { destination: Some((_, ref t)), cleanup: None, .. } + | Yield { resume: ref t, drop: None, .. } + | DropAndReplace { target: ref t, unwind: None, .. } + | Drop { target: ref t, unwind: None, .. } + | Assert { target: ref t, cleanup: None, .. } + | FalseUnwind { real_target: ref t, unwind: None } => Some(t).into_iter().chain(&[]), + Call { destination: Some((_, ref t)), cleanup: Some(ref u), .. } + | Yield { resume: ref t, drop: Some(ref u), .. } + | DropAndReplace { target: ref t, unwind: Some(ref u), .. } + | Drop { target: ref t, unwind: Some(ref u), .. } + | Assert { target: ref t, cleanup: Some(ref u), .. } + | FalseUnwind { real_target: ref t, unwind: Some(ref u) } => { + Some(t).into_iter().chain(slice::from_ref(u)) } - | Call { - destination: Some((_, ref t)), - cleanup: None, - .. - } - | Yield { - resume: ref t, - drop: None, - .. - } - | DropAndReplace { - target: ref t, - unwind: None, - .. - } - | Drop { - target: ref t, - unwind: None, - .. - } - | Assert { - target: ref t, - cleanup: None, - .. - } - | FalseUnwind { - real_target: ref t, - unwind: None, - } => Some(t).into_iter().chain(&[]), - Call { - destination: Some((_, ref t)), - cleanup: Some(ref u), - .. - } - | Yield { - resume: ref t, - drop: Some(ref u), - .. - } - | DropAndReplace { - target: ref t, - unwind: Some(ref u), - .. - } - | Drop { - target: ref t, - unwind: Some(ref u), - .. - } - | Assert { - target: ref t, - cleanup: Some(ref u), - .. - } - | FalseUnwind { - real_target: ref t, - unwind: Some(ref u), - } => Some(t).into_iter().chain(slice::from_ref(u)), SwitchInt { ref targets, .. } => None.into_iter().chain(&targets[..]), - FalseEdges { - ref real_target, - ref imaginary_target, - } => Some(real_target).into_iter().chain(slice::from_ref(imaginary_target)), + FalseEdges { ref real_target, ref imaginary_target } => { + Some(real_target).into_iter().chain(slice::from_ref(imaginary_target)) + } } } @@ -1355,84 +1272,29 @@ pub fn successors_mut(&mut self) -> SuccessorsMut<'_> { | GeneratorDrop | Return | Unreachable - | Call { - destination: None, - cleanup: None, - .. - } => None.into_iter().chain(&mut []), + | Call { destination: None, cleanup: None, .. } => None.into_iter().chain(&mut []), Goto { target: ref mut t } - | Call { - destination: None, - cleanup: Some(ref mut t), - .. - } - | Call { - destination: Some((_, ref mut t)), - cleanup: None, - .. - } - | Yield { - resume: ref mut t, - drop: None, - .. - } - | DropAndReplace { - target: ref mut t, - unwind: None, - .. + | Call { destination: None, cleanup: Some(ref mut t), .. } + | Call { destination: Some((_, ref mut t)), cleanup: None, .. } + | Yield { resume: ref mut t, drop: None, .. } + | DropAndReplace { target: ref mut t, unwind: None, .. } + | Drop { target: ref mut t, unwind: None, .. } + | Assert { target: ref mut t, cleanup: None, .. } + | FalseUnwind { real_target: ref mut t, unwind: None } => { + Some(t).into_iter().chain(&mut []) } - | Drop { - target: ref mut t, - unwind: None, - .. + Call { destination: Some((_, ref mut t)), cleanup: Some(ref mut u), .. } + | Yield { resume: ref mut t, drop: Some(ref mut u), .. } + | DropAndReplace { target: ref mut t, unwind: Some(ref mut u), .. } + | Drop { target: ref mut t, unwind: Some(ref mut u), .. } + | Assert { target: ref mut t, cleanup: Some(ref mut u), .. } + | FalseUnwind { real_target: ref mut t, unwind: Some(ref mut u) } => { + Some(t).into_iter().chain(slice::from_mut(u)) } - | Assert { - target: ref mut t, - cleanup: None, - .. + SwitchInt { ref mut targets, .. } => None.into_iter().chain(&mut targets[..]), + FalseEdges { ref mut real_target, ref mut imaginary_target } => { + Some(real_target).into_iter().chain(slice::from_mut(imaginary_target)) } - | FalseUnwind { - real_target: ref mut t, - unwind: None, - } => Some(t).into_iter().chain(&mut []), - Call { - destination: Some((_, ref mut t)), - cleanup: Some(ref mut u), - .. - } - | Yield { - resume: ref mut t, - drop: Some(ref mut u), - .. - } - | DropAndReplace { - target: ref mut t, - unwind: Some(ref mut u), - .. - } - | Drop { - target: ref mut t, - unwind: Some(ref mut u), - .. - } - | Assert { - target: ref mut t, - cleanup: Some(ref mut u), - .. - } - | FalseUnwind { - real_target: ref mut t, - unwind: Some(ref mut u), - } => Some(t).into_iter().chain(slice::from_mut(u)), - SwitchInt { - ref mut targets, .. - } => None.into_iter().chain(&mut targets[..]), - FalseEdges { - ref mut real_target, - ref mut imaginary_target, - } => Some(real_target) - .into_iter() - .chain(slice::from_mut(imaginary_target)), } } @@ -1447,14 +1309,8 @@ pub fn unwind(&self) -> Option<&Option> { | TerminatorKind::Yield { .. } | TerminatorKind::SwitchInt { .. } | TerminatorKind::FalseEdges { .. } => None, - TerminatorKind::Call { - cleanup: ref unwind, - .. - } - | TerminatorKind::Assert { - cleanup: ref unwind, - .. - } + TerminatorKind::Call { cleanup: ref unwind, .. } + | TerminatorKind::Assert { cleanup: ref unwind, .. } | TerminatorKind::DropAndReplace { ref unwind, .. } | TerminatorKind::Drop { ref unwind, .. } | TerminatorKind::FalseUnwind { ref unwind, .. } => Some(unwind), @@ -1472,14 +1328,8 @@ pub fn unwind_mut(&mut self) -> Option<&mut Option> { | TerminatorKind::Yield { .. } | TerminatorKind::SwitchInt { .. } | TerminatorKind::FalseEdges { .. } => None, - TerminatorKind::Call { - cleanup: ref mut unwind, - .. - } - | TerminatorKind::Assert { - cleanup: ref mut unwind, - .. - } + TerminatorKind::Call { cleanup: ref mut unwind, .. } + | TerminatorKind::Assert { cleanup: ref mut unwind, .. } | TerminatorKind::DropAndReplace { ref mut unwind, .. } | TerminatorKind::Drop { ref mut unwind, .. } | TerminatorKind::FalseUnwind { ref mut unwind, .. } => Some(unwind), @@ -1489,11 +1339,7 @@ pub fn unwind_mut(&mut self) -> Option<&mut Option> { impl<'tcx> BasicBlockData<'tcx> { pub fn new(terminator: Option>) -> BasicBlockData<'tcx> { - BasicBlockData { - statements: vec![], - terminator, - is_cleanup: false, - } + BasicBlockData { statements: vec![], terminator, is_cleanup: false } } /// Accessor for terminator. @@ -1555,10 +1401,7 @@ pub fn expand_statements(&mut self, mut f: F) self.statements.resize( gap.end, Statement { - source_info: SourceInfo { - span: DUMMY_SP, - scope: OUTERMOST_SOURCE_SCOPE, - }, + source_info: SourceInfo { span: DUMMY_SP, scope: OUTERMOST_SOURCE_SCOPE }, kind: StatementKind::Nop, }, ); @@ -1617,9 +1460,7 @@ pub fn fmt_head(&self, fmt: &mut W) -> fmt::Result { use self::TerminatorKind::*; match *self { Goto { .. } => write!(fmt, "goto"), - SwitchInt { - discr: ref place, .. - } => write!(fmt, "switchInt({:?})", place), + SwitchInt { discr: ref place, .. } => write!(fmt, "switchInt({:?})", place), Return => write!(fmt, "return"), GeneratorDrop => write!(fmt, "generator_drop"), Resume => write!(fmt, "resume"), @@ -1627,17 +1468,10 @@ pub fn fmt_head(&self, fmt: &mut W) -> fmt::Result { Yield { ref value, .. } => write!(fmt, "_1 = suspend({:?})", value), Unreachable => write!(fmt, "unreachable"), Drop { ref location, .. } => write!(fmt, "drop({:?})", location), - DropAndReplace { - ref location, - ref value, - .. - } => write!(fmt, "replace({:?} <- {:?})", location, value), - Call { - ref func, - ref args, - ref destination, - .. - } => { + DropAndReplace { ref location, ref value, .. } => { + write!(fmt, "replace({:?} <- {:?})", location, value) + } + Call { ref func, ref args, ref destination, .. } => { if let Some((ref destination, _)) = *destination { write!(fmt, "{:?} = ", destination)?; } @@ -1650,12 +1484,7 @@ pub fn fmt_head(&self, fmt: &mut W) -> fmt::Result { } write!(fmt, ")") } - Assert { - ref cond, - expected, - ref msg, - .. - } => { + Assert { ref cond, expected, ref msg, .. } => { write!(fmt, "assert(")?; if !expected { write!(fmt, "!")?; @@ -1673,69 +1502,41 @@ pub fn fmt_successor_labels(&self) -> Vec> { match *self { Return | Resume | Abort | Unreachable | GeneratorDrop => vec![], Goto { .. } => vec!["".into()], - SwitchInt { - ref values, - switch_ty, - .. - } => { - ty::tls::with(|tcx| { - let param_env = ty::ParamEnv::empty(); - let switch_ty = tcx.lift_to_global(&switch_ty).unwrap(); - let size = tcx.layout_of(param_env.and(switch_ty)).unwrap().size; - values - .iter() - .map(|&u| { - tcx.mk_const(ty::Const { - val: ConstValue::Scalar( - Scalar::from_uint(u, size).into(), - ), - ty: switch_ty, - }).to_string().into() - }).chain(iter::once("otherwise".into())) - .collect() - }) + SwitchInt { ref values, switch_ty, .. } => ty::tls::with(|tcx| { + let param_env = ty::ParamEnv::empty(); + let switch_ty = tcx.lift_to_global(&switch_ty).unwrap(); + let size = tcx.layout_of(param_env.and(switch_ty)).unwrap().size; + values + .iter() + .map(|&u| { + tcx.mk_const(ty::Const { + val: ConstValue::Scalar(Scalar::from_uint(u, size).into()), + ty: switch_ty, + }) + .to_string() + .into() + }) + .chain(iter::once("otherwise".into())) + .collect() + }), + Call { destination: Some(_), cleanup: Some(_), .. } => { + vec!["return".into(), "unwind".into()] } - Call { - destination: Some(_), - cleanup: Some(_), - .. - } => vec!["return".into(), "unwind".into()], - Call { - destination: Some(_), - cleanup: None, - .. - } => vec!["return".into()], - Call { - destination: None, - cleanup: Some(_), - .. - } => vec!["unwind".into()], - Call { - destination: None, - cleanup: None, - .. - } => vec![], + Call { destination: Some(_), cleanup: None, .. } => vec!["return".into()], + Call { destination: None, cleanup: Some(_), .. } => vec!["unwind".into()], + Call { destination: None, cleanup: None, .. } => vec![], Yield { drop: Some(_), .. } => vec!["resume".into(), "drop".into()], Yield { drop: None, .. } => vec!["resume".into()], DropAndReplace { unwind: None, .. } | Drop { unwind: None, .. } => { vec!["return".into()] } - DropAndReplace { - unwind: Some(_), .. + DropAndReplace { unwind: Some(_), .. } | Drop { unwind: Some(_), .. } => { + vec!["return".into(), "unwind".into()] } - | Drop { - unwind: Some(_), .. - } => vec!["return".into(), "unwind".into()], Assert { cleanup: None, .. } => vec!["".into()], Assert { .. } => vec!["success".into(), "unwind".into()], - FalseEdges { - .. - } => { - vec!["real".into(), "imaginary".into()] - } - FalseUnwind { - unwind: Some(_), .. - } => vec!["real".into(), "cleanup".into()], + FalseEdges { .. } => vec!["real".into(), "imaginary".into()], + FalseUnwind { unwind: Some(_), .. } => vec!["real".into(), "cleanup".into()], FalseUnwind { unwind: None, .. } => vec!["real".into()], } } @@ -1785,10 +1586,7 @@ pub enum StatementKind<'tcx> { FakeRead(FakeReadCause, Place<'tcx>), /// Write the discriminant for a variant to the enum Place. - SetDiscriminant { - place: Place<'tcx>, - variant_index: VariantIdx, - }, + SetDiscriminant { place: Place<'tcx>, variant_index: VariantIdx }, /// Start a live range for the storage of the local. StorageLive(Local), @@ -1885,24 +1683,25 @@ fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result { match self.kind { Assign(ref place, ref rv) => write!(fmt, "{:?} = {:?}", place, rv), FakeRead(ref cause, ref place) => write!(fmt, "FakeRead({:?}, {:?})", cause, place), - Retag(ref kind, ref place) => - write!(fmt, "Retag({}{:?})", - match kind { - RetagKind::FnEntry => "[fn entry] ", - RetagKind::TwoPhase => "[2phase] ", - RetagKind::Raw => "[raw] ", - RetagKind::Default => "", - }, - place, - ), + Retag(ref kind, ref place) => write!( + fmt, + "Retag({}{:?})", + match kind { + RetagKind::FnEntry => "[fn entry] ", + RetagKind::TwoPhase => "[2phase] ", + RetagKind::Raw => "[raw] ", + RetagKind::Default => "", + }, + place, + ), StorageLive(ref place) => write!(fmt, "StorageLive({:?})", place), StorageDead(ref place) => write!(fmt, "StorageDead({:?})", place), - SetDiscriminant { - ref place, - variant_index, - } => write!(fmt, "discriminant({:?}) = {:?}", place, variant_index), - InlineAsm(ref asm) => - write!(fmt, "asm!({:?} : {:?} : {:?})", asm.asm, asm.outputs, asm.inputs), + SetDiscriminant { ref place, variant_index } => { + write!(fmt, "discriminant({:?}) = {:?}", place, variant_index) + } + InlineAsm(ref asm) => { + write!(fmt, "asm!({:?} : {:?} : {:?})", asm.asm, asm.outputs, asm.inputs) + } AscribeUserType(ref place, ref variance, ref c_ty) => { write!(fmt, "AscribeUserType({:?}, {:?}, {:?})", place, variance, c_ty) } @@ -1916,7 +1715,9 @@ fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result { /// A path to a value; something that can be evaluated without /// changing or disturbing program state. -#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, HashStable)] +#[derive( + Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, HashStable, +)] pub enum Place<'tcx> { Base(PlaceBase<'tcx>), @@ -1924,7 +1725,9 @@ pub enum Place<'tcx> { Projection(Box>), } -#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, HashStable)] +#[derive( + Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, HashStable, +)] pub enum PlaceBase<'tcx> { /// local variable Local(Local), @@ -1940,7 +1743,9 @@ pub struct Static<'tcx> { pub kind: StaticKind, } -#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable, RustcEncodable, RustcDecodable)] +#[derive( + Clone, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable, RustcEncodable, RustcDecodable, +)] pub enum StaticKind { Promoted(Promoted), Static(DefId), @@ -1952,15 +1757,17 @@ pub enum StaticKind { }); /// The `Projection` data structure defines things of the form `base.x`, `*b` or `b[index]`. -#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, - Hash, RustcEncodable, RustcDecodable, HashStable)] +#[derive( + Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, HashStable, +)] pub struct Projection<'tcx> { pub base: Place<'tcx>, pub elem: PlaceElem<'tcx>, - } +} -#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, - Hash, RustcEncodable, RustcDecodable, HashStable)] +#[derive( + Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, HashStable, +)] pub enum ProjectionElem { Deref, Field(Field, T), @@ -2033,7 +1840,8 @@ pub fn deref(self) -> Place<'tcx> { pub fn downcast(self, adt_def: &'tcx AdtDef, variant_index: VariantIdx) -> Place<'tcx> { self.elem(ProjectionElem::Downcast( Some(adt_def.variants[variant_index].ident.name), - variant_index)) + variant_index, + )) } pub fn downcast_unnamed(self, variant_index: VariantIdx) -> Place<'tcx> { @@ -2054,8 +1862,8 @@ pub fn elem(self, elem: PlaceElem<'tcx>) -> Place<'tcx> { // FIXME: can we safely swap the semantics of `fn base_local` below in here instead? pub fn local_or_deref_local(&self) -> Option { match self { - Place::Base(PlaceBase::Local(local)) | - Place::Projection(box Projection { + Place::Base(PlaceBase::Local(local)) + | Place::Projection(box Projection { base: Place::Base(PlaceBase::Local(local)), elem: ProjectionElem::Deref, }) => Some(*local), @@ -2090,13 +1898,9 @@ fn iterate2( op: impl FnOnce(&PlaceBase<'tcx>, ProjectionsIter<'_, 'tcx>) -> R, ) -> R { match self { - Place::Projection(interior) => interior.base.iterate2( - &Projections::List { - projection: interior, - next, - }, - op, - ), + Place::Projection(interior) => { + interior.base.iterate2(&Projections::List { projection: interior, next }, op) + } Place::Base(base) => op(base, next.iter()), } @@ -2126,10 +1930,7 @@ fn from(local: Local) -> Self { pub enum Projections<'p, 'tcx> { Empty, - List { - projection: &'p Projection<'tcx>, - next: &'p Projections<'p, 'tcx>, - } + List { projection: &'p Projection<'tcx>, next: &'p Projections<'p, 'tcx> }, } impl<'p, 'tcx> Projections<'p, 'tcx> { @@ -2188,16 +1989,15 @@ fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result { let projs_vec: Vec<_> = place_projections.collect(); for projection in projs_vec.iter().rev() { match projection.elem { - ProjectionElem::Downcast(_, _) | - ProjectionElem::Field(_, _) => { + ProjectionElem::Downcast(_, _) | ProjectionElem::Field(_, _) => { write!(fmt, "(").unwrap(); } ProjectionElem::Deref => { write!(fmt, "(*").unwrap(); } - ProjectionElem::Index(_) | - ProjectionElem::ConstantIndex { .. } | - ProjectionElem::Subslice { .. } => {} + ProjectionElem::Index(_) + | ProjectionElem::ConstantIndex { .. } + | ProjectionElem::Subslice { .. } => {} } } }); @@ -2222,18 +2022,10 @@ fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result { ProjectionElem::Index(ref index) => { write!(fmt, "[{:?}]", index)?; } - ProjectionElem::ConstantIndex { - offset, - min_length, - from_end: false, - } => { + ProjectionElem::ConstantIndex { offset, min_length, from_end: false } => { write!(fmt, "[{:?} of {:?}]", offset, min_length)?; } - ProjectionElem::ConstantIndex { - offset, - min_length, - from_end: true, - } => { + ProjectionElem::ConstantIndex { offset, min_length, from_end: true } => { write!(fmt, "[-{:?} of {:?}]", offset, min_length)?; } ProjectionElem::Subslice { from, to } if to == 0 => { @@ -2258,21 +2050,11 @@ fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result { match *self { PlaceBase::Local(id) => write!(fmt, "{:?}", id), PlaceBase::Static(box self::Static { ty, kind: StaticKind::Static(def_id) }) => { - write!( - fmt, - "({}: {:?})", - ty::tls::with(|tcx| tcx.def_path_str(def_id)), - ty - ) - }, + write!(fmt, "({}: {:?})", ty::tls::with(|tcx| tcx.def_path_str(def_id)), ty) + } PlaceBase::Static(box self::Static { ty, kind: StaticKind::Promoted(promoted) }) => { - write!( - fmt, - "({:?}: {:?})", - promoted, - ty - ) - }, + write!(fmt, "({:?}: {:?})", promoted, ty) + } } } } @@ -2403,7 +2185,6 @@ pub enum Rvalue<'tcx> { Aggregate(Box>, Vec>), } - #[derive(Clone, Copy, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)] pub enum CastKind { Misc, @@ -2421,13 +2202,7 @@ pub enum AggregateKind<'tcx> { /// active field number and is present only for union expressions /// -- e.g., for a union expression `SomeUnion { c: .. }`, the /// active field index would identity the field `c` - Adt( - &'tcx AdtDef, - VariantIdx, - SubstsRef<'tcx>, - Option, - Option, - ), + Adt(&'tcx AdtDef, VariantIdx, SubstsRef<'tcx>, Option, Option), Closure(DefId, ClosureSubsts<'tcx>), Generator(DefId, GeneratorSubsts<'tcx>, hir::GeneratorMovability), @@ -2605,8 +2380,7 @@ fn fmt_tuple(fmt: &mut Formatter<'_>, places: &[Operand<'_>]) -> fmt::Result { AggregateKind::Generator(def_id, _, _) => ty::tls::with(|tcx| { if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) { - let name = format!("[generator@{:?}]", - tcx.hir().span(hir_id)); + let name = format!("[generator@{:?}]", tcx.hir().span(hir_id)); let mut struct_fmt = fmt.debug_struct(&name); if let Some(upvars) = tcx.upvars(def_id) { @@ -2697,30 +2471,26 @@ pub fn none() -> Self { UserTypeProjections { contents: vec![] } } - pub fn from_projections(projs: impl Iterator) -> Self { + pub fn from_projections(projs: impl Iterator) -> Self { UserTypeProjections { contents: projs.collect() } } - pub fn projections_and_spans(&self) -> impl Iterator { + pub fn projections_and_spans(&self) -> impl Iterator { self.contents.iter() } - pub fn projections(&self) -> impl Iterator { + pub fn projections(&self) -> impl Iterator { self.contents.iter().map(|&(ref user_type, _span)| user_type) } - pub fn push_projection( - mut self, - user_ty: &UserTypeProjection, - span: Span, - ) -> Self { + pub fn push_projection(mut self, user_ty: &UserTypeProjection, span: Span) -> Self { self.contents.push((user_ty.clone(), span)); self } fn map_projections( mut self, - mut f: impl FnMut(UserTypeProjection) -> UserTypeProjection + mut f: impl FnMut(UserTypeProjection) -> UserTypeProjection, ) -> Self { self.contents = self.contents.drain(..).map(|(proj, span)| (f(proj), span)).collect(); self @@ -2742,12 +2512,7 @@ pub fn leaf(self, field: Field) -> Self { self.map_projections(|pat_ty_proj| pat_ty_proj.leaf(field)) } - pub fn variant( - self, - adt_def: &'tcx AdtDef, - variant_index: VariantIdx, - field: Field, - ) -> Self { + pub fn variant(self, adt_def: &'tcx AdtDef, variant_index: VariantIdx, field: Field) -> Self { self.map_projections(|pat_ty_proj| pat_ty_proj.variant(adt_def, variant_index, field)) } } @@ -2773,7 +2538,7 @@ pub struct UserTypeProjection { pub projs: Vec, } -impl Copy for ProjectionKind { } +impl Copy for ProjectionKind {} impl UserTypeProjection { pub(crate) fn index(mut self) -> Self { @@ -2804,7 +2569,8 @@ pub(crate) fn variant( ) -> Self { self.projs.push(ProjectionElem::Downcast( Some(adt_def.variants[variant_index].ident.name), - variant_index)); + variant_index, + )); self.projs.push(ProjectionElem::Field(field, ())); self } @@ -2817,15 +2583,15 @@ fn super_fold_with>(&self, folder: &mut F) -> Self { use crate::mir::ProjectionElem::*; let base = self.base.fold_with(folder); - let projs: Vec<_> = self.projs + let projs: Vec<_> = self + .projs .iter() - .map(|elem| { - match elem { - Deref => Deref, - Field(f, ()) => Field(f.clone(), ()), - Index(()) => Index(()), - elem => elem.clone(), - }}) + .map(|elem| match elem { + Deref => Deref, + Field(f, ()) => Field(f.clone(), ()), + Index(()) => Index(()), + elem => elem.clone(), + }) .collect(); UserTypeProjection { base, projs } @@ -2918,20 +2684,14 @@ fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { } impl Location { - pub const START: Location = Location { - block: START_BLOCK, - statement_index: 0, - }; + pub const START: Location = Location { block: START_BLOCK, statement_index: 0 }; /// Returns the location immediately after this one within the enclosing block. /// /// Note that if this location represents a terminator, then the /// resulting location would be out of bounds and invalid. pub fn successor_within_block(&self) -> Location { - Location { - block: self.block, - statement_index: self.statement_index + 1, - } + Location { block: self.block, statement_index: self.statement_index + 1 } } /// Returns `true` if `other` is earlier in the control flow graph than `self`. @@ -3121,8 +2881,19 @@ pub struct ClosureOutlivesRequirement<'tcx> { /// order of the category, thereby influencing diagnostic output. /// /// See also [rustc_mir::borrow_check::nll::constraints] -#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, - Hash, RustcEncodable, RustcDecodable, HashStable)] +#[derive( + Copy, + Clone, + Debug, + Eq, + PartialEq, + PartialOrd, + Ord, + Hash, + RustcEncodable, + RustcDecodable, + HashStable, +)] pub enum ConstraintCategory { Return, Yield, @@ -3285,56 +3056,27 @@ fn super_fold_with>(&self, folder: &mut F) -> Self { let kind = match self.kind { Goto { target } => Goto { target }, - SwitchInt { - ref discr, - switch_ty, - ref values, - ref targets, - } => SwitchInt { + SwitchInt { ref discr, switch_ty, ref values, ref targets } => SwitchInt { discr: discr.fold_with(folder), switch_ty: switch_ty.fold_with(folder), values: values.clone(), targets: targets.clone(), }, - Drop { - ref location, - target, - unwind, - } => Drop { - location: location.fold_with(folder), - target, - unwind, - }, - DropAndReplace { - ref location, - ref value, - target, - unwind, - } => DropAndReplace { + Drop { ref location, target, unwind } => { + Drop { location: location.fold_with(folder), target, unwind } + } + DropAndReplace { ref location, ref value, target, unwind } => DropAndReplace { location: location.fold_with(folder), value: value.fold_with(folder), target, unwind, }, - Yield { - ref value, - resume, - drop, - } => Yield { - value: value.fold_with(folder), - resume: resume, - drop: drop, - }, - Call { - ref func, - ref args, - ref destination, - cleanup, - from_hir_call, - } => { - let dest = destination - .as_ref() - .map(|&(ref loc, dest)| (loc.fold_with(folder), dest)); + Yield { ref value, resume, drop } => { + Yield { value: value.fold_with(folder), resume: resume, drop: drop } + } + Call { ref func, ref args, ref destination, cleanup, from_hir_call } => { + let dest = + destination.as_ref().map(|&(ref loc, dest)| (loc.fold_with(folder), dest)); Call { func: func.fold_with(folder), @@ -3344,13 +3086,7 @@ fn super_fold_with>(&self, folder: &mut F) -> Self { from_hir_call, } } - Assert { - ref cond, - expected, - ref msg, - target, - cleanup, - } => { + Assert { ref cond, expected, ref msg, target, cleanup } => { let msg = if let InterpError::BoundsCheck { ref len, ref index } = *msg { InterpError::BoundsCheck { len: len.fold_with(folder), @@ -3359,62 +3095,34 @@ fn super_fold_with>(&self, folder: &mut F) -> Self { } else { msg.clone() }; - Assert { - cond: cond.fold_with(folder), - expected, - msg, - target, - cleanup, - } + Assert { cond: cond.fold_with(folder), expected, msg, target, cleanup } } GeneratorDrop => GeneratorDrop, Resume => Resume, Abort => Abort, Return => Return, Unreachable => Unreachable, - FalseEdges { - real_target, - imaginary_target, - } => FalseEdges { - real_target, - imaginary_target, - }, - FalseUnwind { - real_target, - unwind, - } => FalseUnwind { - real_target, - unwind, - }, + FalseEdges { real_target, imaginary_target } => { + FalseEdges { real_target, imaginary_target } + } + FalseUnwind { real_target, unwind } => FalseUnwind { real_target, unwind }, }; - Terminator { - source_info: self.source_info, - kind, - } + Terminator { source_info: self.source_info, kind } } fn super_visit_with>(&self, visitor: &mut V) -> bool { use crate::mir::TerminatorKind::*; match self.kind { - SwitchInt { - ref discr, - switch_ty, - .. - } => discr.visit_with(visitor) || switch_ty.visit_with(visitor), + SwitchInt { ref discr, switch_ty, .. } => { + discr.visit_with(visitor) || switch_ty.visit_with(visitor) + } Drop { ref location, .. } => location.visit_with(visitor), - DropAndReplace { - ref location, - ref value, - .. - } => location.visit_with(visitor) || value.visit_with(visitor), + DropAndReplace { ref location, ref value, .. } => { + location.visit_with(visitor) || value.visit_with(visitor) + } Yield { ref value, .. } => value.visit_with(visitor), - Call { - ref func, - ref args, - ref destination, - .. - } => { + Call { ref func, ref args, ref destination, .. } => { let dest = if let Some((ref loc, _)) = *destination { loc.visit_with(visitor) } else { @@ -3422,9 +3130,7 @@ fn super_visit_with>(&self, visitor: &mut V) -> bool { }; dest || func.visit_with(visitor) || args.visit_with(visitor) } - Assert { - ref cond, ref msg, .. - } => { + Assert { ref cond, ref msg, .. } => { if cond.visit_with(visitor) { if let InterpError::BoundsCheck { ref len, ref index } = *msg { len.visit_with(visitor) || index.visit_with(visitor) @@ -3571,11 +3277,12 @@ fn super_fold_with>(&self, folder: &mut F) -> Self { fn super_visit_with>(&self, visitor: &mut Vs) -> bool { use crate::mir::ProjectionElem::*; - self.base.visit_with(visitor) || match self.elem { - Field(_, ref ty) => ty.visit_with(visitor), - Index(ref v) => v.visit_with(visitor), - _ => false, - } + self.base.visit_with(visitor) + || match self.elem { + Field(_, ref ty) => ty.visit_with(visitor), + Index(ref v) => v.visit_with(visitor), + _ => false, + } } } diff --git a/src/librustc_mir/borrow_check/flows.rs b/src/librustc_mir/borrow_check/flows.rs index 0b98dbaf58a..bb217a1f965 100644 --- a/src/librustc_mir/borrow_check/flows.rs +++ b/src/librustc_mir/borrow_check/flows.rs @@ -15,8 +15,8 @@ use crate::dataflow::move_paths::HasMoveData; use crate::dataflow::Borrows; use crate::dataflow::EverInitializedPlaces; -use crate::dataflow::{FlowAtLocation, FlowsAtLocation}; use crate::dataflow::MaybeUninitializedPlaces; +use crate::dataflow::{FlowAtLocation, FlowsAtLocation}; use either::Either; use std::fmt; use std::rc::Rc; @@ -40,12 +40,7 @@ impl<'b, 'tcx> Flows<'b, 'tcx> { ever_inits: FlowAtLocation<'tcx, EverInitializedPlaces<'b, 'tcx>>, polonius_output: Option>, ) -> Self { - Flows { - borrows, - uninits, - ever_inits, - polonius_output, - } + Flows { borrows, uninits, ever_inits, polonius_output } } crate fn borrows_in_scope( diff --git a/src/librustc_mir/borrow_check/nll/facts.rs b/src/librustc_mir/borrow_check/nll/facts.rs index 33854d991ee..05451cdfb83 100644 --- a/src/librustc_mir/borrow_check/nll/facts.rs +++ b/src/librustc_mir/borrow_check/nll/facts.rs @@ -28,8 +28,7 @@ fn write_to_dir( impl AllFactsExt for AllFacts { /// Return fn enabled(tcx: TyCtxt<'_>) -> bool { - tcx.sess.opts.debugging_opts.nll_facts - || tcx.sess.opts.debugging_opts.polonius + tcx.sess.opts.debugging_opts.nll_facts || tcx.sess.opts.debugging_opts.polonius } fn write_to_dir( @@ -91,11 +90,7 @@ struct FactWriter<'w> { } impl<'w> FactWriter<'w> { - fn write_facts_to_path( - &self, - rows: &[T], - file_name: &str, - ) -> Result<(), Box> + fn write_facts_to_path(&self, rows: &[T], file_name: &str) -> Result<(), Box> where T: FactRow, { @@ -109,19 +104,11 @@ fn write_facts_to_path( } trait FactRow { - fn write( - &self, - out: &mut File, - location_table: &LocationTable, - ) -> Result<(), Box>; + fn write(&self, out: &mut File, location_table: &LocationTable) -> Result<(), Box>; } impl FactRow for RegionVid { - fn write( - &self, - out: &mut File, - location_table: &LocationTable, - ) -> Result<(), Box> { + fn write(&self, out: &mut File, location_table: &LocationTable) -> Result<(), Box> { write_row(out, location_table, &[self]) } } @@ -131,11 +118,7 @@ impl FactRow for (A, B) A: FactCell, B: FactCell, { - fn write( - &self, - out: &mut File, - location_table: &LocationTable, - ) -> Result<(), Box> { + fn write(&self, out: &mut File, location_table: &LocationTable) -> Result<(), Box> { write_row(out, location_table, &[&self.0, &self.1]) } } @@ -146,11 +129,7 @@ impl FactRow for (A, B, C) B: FactCell, C: FactCell, { - fn write( - &self, - out: &mut File, - location_table: &LocationTable, - ) -> Result<(), Box> { + fn write(&self, out: &mut File, location_table: &LocationTable) -> Result<(), Box> { write_row(out, location_table, &[&self.0, &self.1, &self.2]) } } @@ -162,11 +141,7 @@ impl FactRow for (A, B, C, D) C: FactCell, D: FactCell, { - fn write( - &self, - out: &mut File, - location_table: &LocationTable, - ) -> Result<(), Box> { + fn write(&self, out: &mut File, location_table: &LocationTable) -> Result<(), Box> { write_row(out, location_table, &[&self.0, &self.1, &self.2, &self.3]) } } @@ -177,11 +152,7 @@ fn write_row( columns: &[&dyn FactCell], ) -> Result<(), Box> { for (index, c) in columns.iter().enumerate() { - let tail = if index == columns.len() - 1 { - "\n" - } else { - "\t" - }; + let tail = if index == columns.len() - 1 { "\n" } else { "\t" }; write!(out, "{:?}{}", c.to_string(location_table), tail)?; } Ok(()) diff --git a/src/librustc_mir/borrow_check/nll/type_check/liveness/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/liveness/mod.rs index 8633341c321..8970009b6ee 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/liveness/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/liveness/mod.rs @@ -7,7 +7,7 @@ use crate::dataflow::move_paths::MoveData; use crate::dataflow::FlowAtLocation; use crate::dataflow::MaybeInitializedPlaces; -use rustc::mir::{Local, Body}; +use rustc::mir::{Body, Local}; use rustc::ty::{RegionVid, TyCtxt}; use rustc_data_structures::fx::FxHashSet; use std::rc::Rc; diff --git a/src/librustc_mir/borrow_check/nll/type_check/liveness/trace.rs b/src/librustc_mir/borrow_check/nll/type_check/liveness/trace.rs index dc3b7bdfe30..039ed939ada 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/liveness/trace.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/liveness/trace.rs @@ -247,9 +247,7 @@ fn compute_use_live_points_for(&mut self, local: Local) { } if self.use_live_at.insert(p) { - self.cx - .elements - .push_predecessors(self.cx.body, p, &mut self.stack) + self.cx.elements.push_predecessors(self.cx.body, p, &mut self.stack) } } } @@ -287,10 +285,7 @@ fn compute_drop_live_points_for(&mut self, local: Local) { } } - debug!( - "compute_drop_live_points_for: drop_locations={:?}", - self.drop_locations - ); + debug!("compute_drop_live_points_for: drop_locations={:?}", self.drop_locations); // Reverse DFS. But for drops, we do it a bit differently. // The stack only ever stores *terminators of blocks*. Within @@ -326,17 +321,11 @@ fn compute_drop_live_points_for_block(&mut self, mpi: MovePathIndex, term_point: // block. One of them may be either a definition or use // live point. let term_location = self.cx.elements.to_location(term_point); - debug_assert_eq!( - self.cx.body.terminator_loc(term_location.block), - term_location, - ); + debug_assert_eq!(self.cx.body.terminator_loc(term_location.block), term_location,); let block = term_location.block; let entry_point = self.cx.elements.entry_point(term_location.block); for p in (entry_point..term_point).rev() { - debug!( - "compute_drop_live_points_for_block: p = {:?}", - self.cx.elements.to_location(p), - ); + debug!("compute_drop_live_points_for_block: p = {:?}", self.cx.elements.to_location(p)); if self.defs.contains(p) { debug!("compute_drop_live_points_for_block: def site"); @@ -355,10 +344,7 @@ fn compute_drop_live_points_for_block(&mut self, mpi: MovePathIndex, term_point: } for &pred_block in self.cx.body.predecessors_for(block).iter() { - debug!( - "compute_drop_live_points_for_block: pred_block = {:?}", - pred_block, - ); + debug!("compute_drop_live_points_for_block: pred_block = {:?}", pred_block,); // Check whether the variable is (at least partially) // initialized at the exit of this predecessor. If so, we @@ -389,18 +375,12 @@ fn compute_drop_live_points_for_block(&mut self, mpi: MovePathIndex, term_point: // If the terminator of this predecessor either *assigns* // our value or is a "normal use", then stop. if self.defs.contains(pred_term_point) { - debug!( - "compute_drop_live_points_for_block: defined at {:?}", - pred_term_loc - ); + debug!("compute_drop_live_points_for_block: defined at {:?}", pred_term_loc); continue; } if self.use_live_at.contains(pred_term_point) { - debug!( - "compute_drop_live_points_for_block: use-live at {:?}", - pred_term_loc - ); + debug!("compute_drop_live_points_for_block: use-live at {:?}", pred_term_loc); continue; } @@ -461,10 +441,7 @@ fn initialized_at_terminator(&mut self, block: BasicBlock, mpi: MovePathIndex) - // "just ahead" of a terminator. self.flow_inits.reset_to_entry_of(block); for statement_index in 0..self.body[block].statements.len() { - let location = Location { - block, - statement_index, - }; + let location = Location { block, statement_index }; self.flow_inits.reconstruct_statement_effect(location); self.flow_inits.apply_local_effect(location); } @@ -531,12 +508,11 @@ fn add_drop_live_facts_for( if let Some(data) = &drop_data.region_constraint_data { for &drop_location in drop_locations { - self.typeck - .push_region_constraints( - drop_location.to_locations(), - ConstraintCategory::Boring, - data, - ); + self.typeck.push_region_constraints( + drop_location.to_locations(), + ConstraintCategory::Boring, + data, + ); } } @@ -602,14 +578,9 @@ fn compute_drop_data( debug!("compute_drop_data(dropped_ty={:?})", dropped_ty,); let param_env = typeck.param_env; - let (dropck_result, region_constraint_data) = param_env - .and(DropckOutlives::new(dropped_ty)) - .fully_perform(typeck.infcx) - .unwrap(); - - DropData { - dropck_result, - region_constraint_data, - } + let (dropck_result, region_constraint_data) = + param_env.and(DropckOutlives::new(dropped_ty)).fully_perform(typeck.infcx).unwrap(); + + DropData { dropck_result, region_constraint_data } } } -- 2.44.0