diff --git a/src/librustc/cfg/construct.rs b/src/librustc/cfg/construct.rs index a7411c9667929..a2e7ebfdb0e4b 100644 --- a/src/librustc/cfg/construct.rs +++ b/src/librustc/cfg/construct.rs @@ -30,8 +30,7 @@ struct LoopScope { break_index: CFGIndex, // where to go on a `break` } -pub fn construct<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - body: &hir::Body) -> CFG { +pub fn construct<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, body: &hir::Body) -> CFG { let mut graph = graph::Graph::new(); let entry = graph.add_node(CFGNodeData::Entry); diff --git a/src/librustc/cfg/mod.rs b/src/librustc/cfg/mod.rs index deb76e057c538..d25d58bfd1fa6 100644 --- a/src/librustc/cfg/mod.rs +++ b/src/librustc/cfg/mod.rs @@ -49,8 +49,7 @@ pub type CFGNode = graph::Node; pub type CFGEdge = graph::Edge; impl CFG { - pub fn new<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - body: &hir::Body) -> CFG { + pub fn new<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, body: &hir::Body) -> CFG { construct::construct(tcx, body) } diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs index acff8f621ac0a..82bba96dd4cc7 100644 --- a/src/librustc/dep_graph/dep_node.rs +++ b/src/librustc/dep_graph/dep_node.rs @@ -480,7 +480,8 @@ trait DepNodeParams<'gcx: 'tcx, 'tcx>: fmt::Debug { } impl<'gcx: 'tcx, 'tcx, T> DepNodeParams<'gcx, 'tcx> for T - where T: HashStable> + fmt::Debug +where + T: HashStable> + fmt::Debug, { default const CAN_RECONSTRUCT_QUERY_KEY: bool = false; diff --git a/src/librustc/dep_graph/graph.rs b/src/librustc/dep_graph/graph.rs index d15980dcbe6d6..40ccd6e7b280a 100644 --- a/src/librustc/dep_graph/graph.rs +++ b/src/librustc/dep_graph/graph.rs @@ -90,7 +90,6 @@ where } impl DepGraph { - pub fn new(prev_graph: PreviousDepGraph, prev_work_products: FxHashMap) -> DepGraph { let prev_graph_node_count = prev_graph.node_count(); @@ -559,7 +558,7 @@ impl DepGraph { pub fn try_mark_green_and_read( &self, tcx: TyCtxt<'_, '_>, - dep_node: &DepNode + dep_node: &DepNode, ) -> Option<(SerializedDepNodeIndex, DepNodeIndex)> { self.try_mark_green(tcx, dep_node).map(|(prev_index, dep_node_index)| { debug_assert!(self.is_green(&dep_node)); @@ -571,7 +570,7 @@ impl DepGraph { pub fn try_mark_green( &self, tcx: TyCtxt<'_, '_>, - dep_node: &DepNode + dep_node: &DepNode, ) -> Option<(SerializedDepNodeIndex, DepNodeIndex)> { debug_assert!(!dep_node.kind.is_eval_always()); @@ -607,7 +606,7 @@ impl DepGraph { tcx: TyCtxt<'tcx, 'tcx>, data: &DepGraphData, prev_dep_node_index: SerializedDepNodeIndex, - dep_node: &DepNode + dep_node: &DepNode, ) -> Option { debug!("try_mark_previous_green({:?}) - BEGIN", dep_node); diff --git a/src/librustc/dep_graph/safe.rs b/src/librustc/dep_graph/safe.rs index 86cba3a4580ba..62667c957cdc0 100644 --- a/src/librustc/dep_graph/safe.rs +++ b/src/librustc/dep_graph/safe.rs @@ -33,8 +33,7 @@ impl DepGraphSafe for DefId { /// The type context itself can be used to access all kinds of tracked /// state, but those accesses should always generate read events. -impl<'gcx, 'tcx> DepGraphSafe for TyCtxt<'gcx, 'tcx> { -} +impl<'gcx, 'tcx> DepGraphSafe for TyCtxt<'gcx, 'tcx> {} /// Tuples make it easy to build up state. impl DepGraphSafe for (A, B) diff --git a/src/librustc/infer/canonical/substitute.rs b/src/librustc/infer/canonical/substitute.rs index 0dace4132b808..d1310771fb353 100644 --- a/src/librustc/infer/canonical/substitute.rs +++ b/src/librustc/infer/canonical/substitute.rs @@ -14,11 +14,7 @@ use crate::ty::{self, TyCtxt}; impl<'tcx, V> Canonical<'tcx, V> { /// Instantiate the wrapped value, replacing each canonical value /// with the value given in `var_values`. - pub fn substitute( - &self, - tcx: TyCtxt<'_, 'tcx>, - var_values: &CanonicalVarValues<'tcx>, - ) -> V + pub fn substitute(&self, tcx: TyCtxt<'_, 'tcx>, var_values: &CanonicalVarValues<'tcx>) -> V where V: TypeFoldable<'tcx>, { diff --git a/src/librustc/infer/combine.rs b/src/librustc/infer/combine.rs index 21d4f3bf51197..d886efd33915f 100644 --- a/src/librustc/infer/combine.rs +++ b/src/librustc/infer/combine.rs @@ -58,12 +58,14 @@ pub enum RelationDir { } impl<'infcx, 'gcx, 'tcx> InferCtxt<'infcx, 'gcx, 'tcx> { - pub fn super_combine_tys(&self, - relation: &mut R, - a: Ty<'tcx>, - b: Ty<'tcx>) - -> RelateResult<'tcx, Ty<'tcx>> - where R: TypeRelation<'gcx, 'tcx> + pub fn super_combine_tys( + &self, + relation: &mut R, + a: Ty<'tcx>, + b: Ty<'tcx>, + ) -> RelateResult<'tcx, Ty<'tcx>> + where + R: TypeRelation<'gcx, 'tcx>, { let a_is_expected = relation.a_is_expected(); diff --git a/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs b/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs index 43a5e4a0d0e77..8631236c0e36e 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs @@ -338,7 +338,10 @@ impl NiceRegionError<'me, 'gcx, 'tcx> { } impl<'gcx, 'tcx, T> fmt::Display for Highlighted<'gcx, 'tcx, T> - where T: for<'a, 'b, 'c> Print<'gcx, 'tcx, + where + T: for<'a, 'b, 'c> Print< + 'gcx, + 'tcx, FmtPrinter<'a, 'gcx, 'tcx, &'b mut fmt::Formatter<'c>>, Error = fmt::Error, >, diff --git a/src/librustc/infer/lattice.rs b/src/librustc/infer/lattice.rs index 6f76ee9e26dc9..236ebc19340bb 100644 --- a/src/librustc/infer/lattice.rs +++ b/src/librustc/infer/lattice.rs @@ -27,7 +27,7 @@ use crate::ty::TyVar; use crate::ty::{self, Ty}; use crate::ty::relate::{RelateResult, TypeRelation}; -pub trait LatticeDir<'f, 'gcx: 'f+'tcx, 'tcx: 'f> : TypeRelation<'gcx, 'tcx> { +pub trait LatticeDir<'f, 'gcx: 'f + 'tcx, 'tcx: 'f>: TypeRelation<'gcx, 'tcx> { fn infcx(&self) -> &'f InferCtxt<'f, 'gcx, 'tcx>; fn cause(&self) -> &ObligationCause<'tcx>; diff --git a/src/librustc/infer/outlives/free_region_map.rs b/src/librustc/infer/outlives/free_region_map.rs index 2a5558a4a66fd..c2ae561fcd39f 100644 --- a/src/librustc/infer/outlives/free_region_map.rs +++ b/src/librustc/infer/outlives/free_region_map.rs @@ -28,11 +28,12 @@ impl<'tcx> FreeRegionMap<'tcx> { /// cases, this is more conservative than necessary, in order to /// avoid making arbitrary choices. See /// `TransitiveRelation::postdom_upper_bound` for more details. - pub fn lub_free_regions<'gcx>(&self, - tcx: TyCtxt<'gcx, 'tcx>, - r_a: Region<'tcx>, - r_b: Region<'tcx>) - -> Region<'tcx> { + pub fn lub_free_regions<'gcx>( + &self, + tcx: TyCtxt<'gcx, 'tcx>, + r_a: Region<'tcx>, + r_b: Region<'tcx>, + ) -> Region<'tcx> { debug!("lub_free_regions(r_a={:?}, r_b={:?})", r_a, r_b); assert!(is_free(r_a)); assert!(is_free(r_b)); diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index a35ed7e862712..c6a77a314be6a 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -1423,10 +1423,7 @@ pub fn late_lint_mod<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>( } } -fn late_lint_pass_crate<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>( - tcx: TyCtxt<'tcx, 'tcx>, - pass: T -) { +fn late_lint_pass_crate<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(tcx: TyCtxt<'tcx, 'tcx>, pass: T) { let access_levels = &tcx.privacy_access_levels(LOCAL_CRATE); let krate = tcx.hir().krate(); @@ -1461,7 +1458,7 @@ fn late_lint_pass_crate<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>( fn late_lint_crate<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>( tcx: TyCtxt<'tcx, 'tcx>, - builtin_lints: T + builtin_lints: T, ) { let mut passes = tcx.sess.lint_store.borrow().late_passes.lock().take().unwrap(); diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index d8f21ced2559d..5a17eee173d5a 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -766,9 +766,7 @@ pub fn maybe_lint_level_root(tcx: TyCtxt<'_, '_>, id: hir::HirId) -> bool { attrs.iter().any(|attr| Level::from_symbol(attr.name_or_empty()).is_some()) } -fn lint_levels<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, cnum: CrateNum) - -> &'tcx LintLevelMap -{ +fn lint_levels<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, cnum: CrateNum) -> &'tcx LintLevelMap { assert_eq!(cnum, LOCAL_CRATE); let mut builder = LintLevelMapBuilder { levels: LintLevelSets::builder(tcx.sess), diff --git a/src/librustc/middle/cstore.rs b/src/librustc/middle/cstore.rs index 2e490931525a3..f258f06b87dcc 100644 --- a/src/librustc/middle/cstore.rs +++ b/src/librustc/middle/cstore.rs @@ -211,9 +211,7 @@ pub trait CrateStore { fn crates_untracked(&self) -> Vec; // utility functions - fn encode_metadata<'tcx>(&self, - tcx: TyCtxt<'tcx, 'tcx>) - -> EncodedMetadata; + fn encode_metadata<'tcx>(&self, tcx: TyCtxt<'tcx, 'tcx>) -> EncodedMetadata; fn metadata_encoding_version(&self) -> &[u8]; } @@ -228,9 +226,7 @@ pub type CrateStoreDyn = dyn CrateStore + sync::Sync; // In order to get this left-to-right dependency ordering, we perform a // topological sort of all crates putting the leaves at the right-most // positions. -pub fn used_crates(tcx: TyCtxt<'_, '_>, prefer: LinkagePreference) - -> Vec<(CrateNum, LibSource)> -{ +pub fn used_crates(tcx: TyCtxt<'_, '_>, prefer: LinkagePreference) -> Vec<(CrateNum, LibSource)> { let mut libs = tcx.crates() .iter() .cloned() diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index 9bd80bf3f8b87..18e19e802e889 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -26,8 +26,7 @@ use syntax_pos; // explored. For example, if it's a live Node::Item that is a // function, then we should explore its block to check for codes that // may need to be marked as live. -fn should_explore<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - hir_id: hir::HirId) -> bool { +fn should_explore<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, hir_id: hir::HirId) -> bool { match tcx.hir().find_by_hir_id(hir_id) { Some(Node::Item(..)) | Some(Node::ImplItem(..)) | @@ -302,9 +301,11 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> { } } -fn has_allow_dead_code_or_lang_attr(tcx: TyCtxt<'_, '_>, - id: hir::HirId, - attrs: &[ast::Attribute]) -> bool { +fn has_allow_dead_code_or_lang_attr( + tcx: TyCtxt<'_, '_>, + id: hir::HirId, + attrs: &[ast::Attribute], +) -> bool { if attr::contains_name(attrs, sym::lang) { return true; } @@ -451,10 +452,11 @@ fn create_and_seed_worklist<'tcx>( (life_seeder.worklist, life_seeder.struct_constructors) } -fn find_live<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - access_levels: &privacy::AccessLevels, - krate: &hir::Crate) - -> FxHashSet { +fn find_live<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + access_levels: &privacy::AccessLevels, + krate: &hir::Crate, +) -> FxHashSet { let (worklist, struct_constructors) = create_and_seed_worklist(tcx, access_levels, krate); let mut symbol_visitor = MarkSymbolVisitor { worklist, diff --git a/src/librustc/middle/dependency_format.rs b/src/librustc/middle/dependency_format.rs index faa3ea27d13ff..2f6a3f2f02721 100644 --- a/src/librustc/middle/dependency_format.rs +++ b/src/librustc/middle/dependency_format.rs @@ -92,9 +92,7 @@ pub fn calculate<'tcx>(tcx: TyCtxt<'tcx, 'tcx>) { sess.dependency_formats.set(fmts); } -fn calculate_type<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - ty: config::CrateType) -> DependencyList { - +fn calculate_type<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, ty: config::CrateType) -> DependencyList { let sess = &tcx.sess; if !sess.opts.output_types.should_codegen() { @@ -242,10 +240,12 @@ fn calculate_type<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, ret } -fn add_library(tcx: TyCtxt<'_, '_>, - cnum: CrateNum, - link: LinkagePreference, - m: &mut FxHashMap) { +fn add_library( + tcx: TyCtxt<'_, '_>, + cnum: CrateNum, + link: LinkagePreference, + m: &mut FxHashMap, +) { match m.get(&cnum) { Some(&link2) => { // If the linkages differ, then we'd have two copies of the library diff --git a/src/librustc/middle/exported_symbols.rs b/src/librustc/middle/exported_symbols.rs index bebfb4b768703..9e7af280408bd 100644 --- a/src/librustc/middle/exported_symbols.rs +++ b/src/librustc/middle/exported_symbols.rs @@ -38,9 +38,7 @@ pub enum ExportedSymbol<'tcx> { } impl<'tcx> ExportedSymbol<'tcx> { - pub fn symbol_name(&self, - tcx: TyCtxt<'tcx, '_>) - -> ty::SymbolName { + pub fn symbol_name(&self, tcx: TyCtxt<'tcx, '_>) -> ty::SymbolName { match *self { ExportedSymbol::NonGeneric(def_id) => { tcx.symbol_name(ty::Instance::mono(tcx, def_id)) @@ -54,10 +52,11 @@ impl<'tcx> ExportedSymbol<'tcx> { } } - pub fn compare_stable(&self, - tcx: TyCtxt<'tcx, '_>, - other: &ExportedSymbol<'tcx>) - -> cmp::Ordering { + pub fn compare_stable( + &self, + tcx: TyCtxt<'tcx, '_>, + other: &ExportedSymbol<'tcx>, + ) -> cmp::Ordering { match *self { ExportedSymbol::NonGeneric(self_def_id) => match *other { ExportedSymbol::NonGeneric(other_def_id) => { diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index e9f435f8991f5..3ed926d758264 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -266,15 +266,15 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx, 'tcx> { /// `None` means that rvalues will be given more conservative lifetimes. /// /// See also `with_infer`, which is used *during* typeck. - pub fn new(delegate: &'a mut (dyn Delegate<'tcx>+'a), - tcx: TyCtxt<'tcx, 'tcx>, - body_owner: DefId, - param_env: ty::ParamEnv<'tcx>, - region_scope_tree: &'a region::ScopeTree, - tables: &'a ty::TypeckTables<'tcx>, - rvalue_promotable_map: Option<&'tcx ItemLocalSet>) - -> Self - { + pub fn new( + delegate: &'a mut (dyn Delegate<'tcx> + 'a), + tcx: TyCtxt<'tcx, 'tcx>, + body_owner: DefId, + param_env: ty::ParamEnv<'tcx>, + region_scope_tree: &'a region::ScopeTree, + tables: &'a ty::TypeckTables<'tcx>, + rvalue_promotable_map: Option<&'tcx ItemLocalSet>, + ) -> Self { ExprUseVisitor { mc: mc::MemCategorizationContext::new(tcx, body_owner, diff --git a/src/librustc/middle/intrinsicck.rs b/src/librustc/middle/intrinsicck.rs index 9746c7ce05c11..d3ed818c4be45 100644 --- a/src/librustc/middle/intrinsicck.rs +++ b/src/librustc/middle/intrinsicck.rs @@ -25,7 +25,7 @@ pub fn provide(providers: &mut Providers<'_>) { } struct ItemVisitor<'tcx> { - tcx: TyCtxt<'tcx, 'tcx> + tcx: TyCtxt<'tcx, 'tcx>, } struct ExprVisitor<'tcx> { @@ -36,9 +36,7 @@ struct ExprVisitor<'tcx> { /// If the type is `Option`, it will return `T`, otherwise /// the type itself. Works on most `Option`-like types. -fn unpack_option_like<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - ty: Ty<'tcx>) - -> Ty<'tcx> { +fn unpack_option_like<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { let (def, substs) = match ty.sty { ty::Adt(def, substs) => (def, substs), _ => return ty diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 43b0c64df7837..92cb407f67d7c 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -352,12 +352,14 @@ impl IrMaps<'tcx> { } } -fn visit_fn<'a, 'tcx: 'a>(ir: &mut IrMaps<'tcx>, - fk: FnKind<'tcx>, - decl: &'tcx hir::FnDecl, - body_id: hir::BodyId, - sp: Span, - id: hir::HirId) { +fn visit_fn<'a, 'tcx: 'a>( + ir: &mut IrMaps<'tcx>, + fk: FnKind<'tcx>, + decl: &'tcx hir::FnDecl, + body_id: hir::BodyId, + sp: Span, + id: hir::HirId, +) { debug!("visit_fn"); // swap in a new set of IR maps for this function body: diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index d7e8f1fb71404..4b5b901f4703e 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -287,7 +287,7 @@ impl HirNode for hir::Pat { } #[derive(Clone)] -pub struct MemCategorizationContext<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { +pub struct MemCategorizationContext<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> { pub tcx: TyCtxt<'gcx, 'tcx>, pub body_owner: DefId, pub upvars: Option<&'tcx FxIndexMap>, @@ -339,8 +339,11 @@ impl MutabilityCategory { ret } - fn from_local(tcx: TyCtxt<'_, '_>, tables: &ty::TypeckTables<'_>, - id: ast::NodeId) -> MutabilityCategory { + fn from_local( + tcx: TyCtxt<'_, '_>, + tables: &ty::TypeckTables<'_>, + id: ast::NodeId, + ) -> MutabilityCategory { let ret = match tcx.hir().get(id) { Node::Binding(p) => match p.node { PatKind::Binding(..) => { @@ -400,12 +403,13 @@ impl MutabilityCategory { } impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx, 'tcx> { - pub fn new(tcx: TyCtxt<'tcx, 'tcx>, - body_owner: DefId, - region_scope_tree: &'a region::ScopeTree, - tables: &'a ty::TypeckTables<'tcx>, - rvalue_promotable_map: Option<&'tcx ItemLocalSet>) - -> MemCategorizationContext<'a, 'tcx, 'tcx> { + pub fn new( + tcx: TyCtxt<'tcx, 'tcx>, + body_owner: DefId, + region_scope_tree: &'a region::ScopeTree, + tables: &'a ty::TypeckTables<'tcx>, + rvalue_promotable_map: Option<&'tcx ItemLocalSet>, + ) -> MemCategorizationContext<'a, 'tcx, 'tcx> { MemCategorizationContext { tcx, body_owner, diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index 116ce7525dab5..b0068a191da4c 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -27,9 +27,7 @@ use crate::hir::intravisit; // Returns true if the given item must be inlined because it may be // monomorphized or it was marked with `#[inline]`. This will only return // true for functions. -fn item_might_be_inlined(tcx: TyCtxt<'tcx, 'tcx>, - item: &hir::Item, - attrs: CodegenFnAttrs) -> bool { +fn item_might_be_inlined(tcx: TyCtxt<'tcx, 'tcx>, item: &hir::Item, attrs: CodegenFnAttrs) -> bool { if attrs.requests_inline() { return true } @@ -44,9 +42,11 @@ fn item_might_be_inlined(tcx: TyCtxt<'tcx, 'tcx>, } } -fn method_might_be_inlined<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - impl_item: &hir::ImplItem, - impl_src: DefId) -> bool { +fn method_might_be_inlined<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + impl_item: &hir::ImplItem, + impl_src: DefId, +) -> bool { let codegen_fn_attrs = tcx.codegen_fn_attrs(impl_item.hir_id.owner_def_id()); let generics = tcx.generics_of(tcx.hir().local_def_id_from_hir_id(impl_item.hir_id)); if codegen_fn_attrs.requests_inline() || generics.requires_monomorphization(tcx) { diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 3c99ec391533c..5968933721de6 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -646,9 +646,11 @@ impl<'tcx> ScopeTree { /// Assuming that the provided region was defined within this `ScopeTree`, /// returns the outermost `Scope` that the region outlives. - pub fn early_free_scope<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>, - br: &ty::EarlyBoundRegion) - -> Scope { + pub fn early_free_scope<'gcx>( + &self, + tcx: TyCtxt<'gcx, 'tcx>, + br: &ty::EarlyBoundRegion, + ) -> Scope { let param_owner = tcx.parent(br.def_id).unwrap(); let param_owner_id = tcx.hir().as_local_hir_id(param_owner).unwrap(); @@ -677,8 +679,7 @@ impl<'tcx> ScopeTree { /// Assuming that the provided region was defined within this `ScopeTree`, /// returns the outermost `Scope` that the region outlives. - pub fn free_scope<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>, fr: &ty::FreeRegion) - -> Scope { + pub fn free_scope<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>, fr: &ty::FreeRegion) -> Scope { let param_owner = match fr.bound_region { ty::BoundRegion::BrNamed(def_id, _) => { tcx.parent(def_id).unwrap() @@ -734,9 +735,11 @@ impl<'tcx> ScopeTree { } /// Records the lifetime of a local variable as `cx.var_parent` -fn record_var_lifetime(visitor: &mut RegionResolutionVisitor<'_>, - var_id: hir::ItemLocalId, - _sp: Span) { +fn record_var_lifetime( + visitor: &mut RegionResolutionVisitor<'_>, + var_id: hir::ItemLocalId, + _sp: Span, +) { match visitor.cx.var_parent { None => { // this can happen in extern fn declarations like @@ -977,9 +980,11 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h visitor.cx = prev_cx; } -fn resolve_local<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, - pat: Option<&'tcx hir::Pat>, - init: Option<&'tcx hir::Expr>) { +fn resolve_local<'tcx>( + visitor: &mut RegionResolutionVisitor<'tcx>, + pat: Option<&'tcx hir::Pat>, + init: Option<&'tcx hir::Expr>, +) { debug!("resolve_local(pat={:?}, init={:?})", pat, init); let blk_scope = visitor.cx.var_parent.map(|(p, _)| p); @@ -1130,8 +1135,8 @@ fn resolve_local<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, fn record_rvalue_scope_if_borrow_expr<'tcx>( visitor: &mut RegionResolutionVisitor<'tcx>, expr: &hir::Expr, - blk_id: Option) - { + blk_id: Option, + ) { match expr.node { hir::ExprKind::AddrOf(_, ref subexpr) => { record_rvalue_scope_if_borrow_expr(visitor, &subexpr, blk_id); @@ -1178,9 +1183,11 @@ fn resolve_local<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, /// | /// /// Note: ET is intended to match "rvalues or places based on rvalues". - fn record_rvalue_scope<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, - expr: &hir::Expr, - blk_scope: Option) { + fn record_rvalue_scope<'tcx>( + visitor: &mut RegionResolutionVisitor<'tcx>, + expr: &hir::Expr, + blk_scope: Option, + ) { let mut expr = expr; loop { // Note: give all the expressions matching `ET` with the @@ -1327,9 +1334,7 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> { } } -fn region_scope_tree<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) - -> &'tcx ScopeTree -{ +fn region_scope_tree<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> &'tcx ScopeTree { let closure_base_def_id = tcx.closure_base_def_id(def_id); if closure_base_def_id != def_id { return tcx.region_scope_tree(closure_base_def_id); diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 32577e019e0c2..edd5cb4541a96 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -368,10 +368,7 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) { /// entire crate. You should not read the result of this query /// directly, but rather use `named_region_map`, `is_late_bound_map`, /// etc. -fn resolve_lifetimes<'tcx>( - tcx: TyCtxt<'tcx, 'tcx>, - for_krate: CrateNum, -) -> &'tcx ResolveLifetimes { +fn resolve_lifetimes<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, for_krate: CrateNum) -> &'tcx ResolveLifetimes { assert_eq!(for_krate, LOCAL_CRATE); let named_region_map = krate(tcx); @@ -1256,9 +1253,7 @@ fn extract_labels(ctxt: &mut LifetimeContext<'_, '_>, body: &hir::Body) { } } -fn compute_object_lifetime_defaults( - tcx: TyCtxt<'_, '_>, -) -> HirIdMap> { +fn compute_object_lifetime_defaults(tcx: TyCtxt<'_, '_>) -> HirIdMap> { let mut map = HirIdMap::default(); for item in tcx.hir().krate().items.values() { match item.node { diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index 30c4a46271c21..dbd008256b024 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -452,7 +452,7 @@ impl<'tcx> Index<'tcx> { AnnotationKind::Required, |v| intravisit::walk_crate(v, krate)); } - return index + return index; } pub fn local_stability(&self, id: HirId) -> Option<&'tcx Stability> { @@ -924,7 +924,7 @@ fn unnecessary_stable_feature_lint<'tcx>( tcx: TyCtxt<'tcx, 'tcx>, span: Span, feature: Symbol, - since: Symbol + since: Symbol, ) { tcx.lint_hir(lint::builtin::STABLE_FEATURES, hir::CRATE_HIR_ID, diff --git a/src/librustc/mir/interpret/error.rs b/src/librustc/mir/interpret/error.rs index 35ac2ccb28922..009cab3bd0315 100644 --- a/src/librustc/mir/interpret/error.rs +++ b/src/librustc/mir/interpret/error.rs @@ -75,18 +75,15 @@ impl<'tcx> fmt::Display for FrameInfo<'tcx> { } impl<'gcx, 'tcx> ConstEvalErr<'tcx> { - pub fn struct_error(&self, + pub fn struct_error( + &self, tcx: TyCtxtAt<'gcx, 'tcx>, - message: &str) - -> Result, ErrorHandled> - { + message: &str, + ) -> Result, ErrorHandled> { self.struct_generic(tcx, message, None) } - pub fn report_as_error(&self, - tcx: TyCtxtAt<'gcx, 'tcx>, - message: &str - ) -> ErrorHandled { + pub fn report_as_error(&self, tcx: TyCtxtAt<'gcx, 'tcx>, message: &str) -> ErrorHandled { let err = self.struct_error(tcx, message); match err { Ok(mut err) => { @@ -97,7 +94,8 @@ impl<'gcx, 'tcx> ConstEvalErr<'tcx> { } } - pub fn report_as_lint(&self, + pub fn report_as_lint( + &self, tcx: TyCtxtAt<'gcx, 'tcx>, message: &str, lint_root: hir::HirId, @@ -172,10 +170,7 @@ impl<'gcx, 'tcx> ConstEvalErr<'tcx> { } } -pub fn struct_error<'gcx, 'tcx>( - tcx: TyCtxtAt<'gcx, 'tcx>, - msg: &str, -) -> DiagnosticBuilder<'tcx> { +pub fn struct_error<'gcx, 'tcx>(tcx: TyCtxtAt<'gcx, 'tcx>, msg: &str) -> DiagnosticBuilder<'tcx> { struct_span_err!(tcx.sess, tcx.span, E0080, "{}", msg) } diff --git a/src/librustc/mir/interpret/mod.rs b/src/librustc/mir/interpret/mod.rs index 89b2403fa6a03..f68385ec26759 100644 --- a/src/librustc/mir/interpret/mod.rs +++ b/src/librustc/mir/interpret/mod.rs @@ -142,12 +142,10 @@ pub struct AllocDecodingSession<'s> { } impl<'s> AllocDecodingSession<'s> { - // Decodes an AllocId in a thread-safe way. - pub fn decode_alloc_id(&self, - decoder: &mut D) - -> Result - where D: TyDecoder<'tcx>, + pub fn decode_alloc_id(&self, decoder: &mut D) -> Result + where + D: TyDecoder<'tcx>, { // Read the index of the allocation let idx = decoder.read_u32()? as usize; diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 90a683b733362..e73023d9a8cc9 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -3158,7 +3158,7 @@ pub enum ClosureOutlivesSubject<'tcx> { /* * TypeFoldable implementations for MIR types - */ +*/ CloneTypeFoldableAndLiftImpls! { BlockTailInfo, diff --git a/src/librustc/mir/mono.rs b/src/librustc/mir/mono.rs index 0b095c2f0de56..cf1126efc0f86 100644 --- a/src/librustc/mir/mono.rs +++ b/src/librustc/mir/mono.rs @@ -87,9 +87,7 @@ impl<'tcx> MonoItem<'tcx> { } } - pub fn instantiation_mode(&self, - tcx: TyCtxt<'tcx, 'tcx>) - -> InstantiationMode { + pub fn instantiation_mode(&self, tcx: TyCtxt<'tcx, 'tcx>) -> InstantiationMode { let inline_in_all_cgus = tcx.sess.opts.debugging_opts.inline_in_all_cgus.unwrap_or_else(|| { tcx.sess.opts.optimize != OptLevel::No @@ -195,11 +193,12 @@ impl<'tcx> MonoItem<'tcx> { } }; - fn to_string_internal<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - prefix: &str, - instance: Instance<'tcx>, - debug: bool) - -> String { + fn to_string_internal<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + prefix: &str, + instance: Instance<'tcx>, + debug: bool, + ) -> String { let mut result = String::with_capacity(32); result.push_str(prefix); let printer = DefPathBasedNames::new(tcx, false, false); @@ -369,17 +368,16 @@ impl<'tcx> CodegenUnit<'tcx> { }) } - pub fn items_in_deterministic_order(&self, - tcx: TyCtxt<'tcx, 'tcx>) - -> Vec<(MonoItem<'tcx>, - (Linkage, Visibility))> { + pub fn items_in_deterministic_order( + &self, + tcx: TyCtxt<'tcx, 'tcx>, + ) -> Vec<(MonoItem<'tcx>, (Linkage, Visibility))> { // The codegen tests rely on items being process in the same order as // they appear in the file, so for local items, we sort by node_id first #[derive(PartialEq, Eq, PartialOrd, Ord)] pub struct ItemSortKey(Option, SymbolName); - fn item_sort_key<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - item: MonoItem<'tcx>) -> ItemSortKey { + fn item_sort_key<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, item: MonoItem<'tcx>) -> ItemSortKey { ItemSortKey(match item { MonoItem::Fn(ref instance) => { match instance.def { diff --git a/src/librustc/mir/tcx.rs b/src/librustc/mir/tcx.rs index 1d5f726567314..76d7d98b90256 100644 --- a/src/librustc/mir/tcx.rs +++ b/src/librustc/mir/tcx.rs @@ -33,8 +33,7 @@ impl<'gcx, 'tcx> PlaceTy<'tcx> { /// not carry a `Ty` for `T`.) /// /// Note that the resulting type has not been normalized. - pub fn field_ty(self, tcx: TyCtxt<'gcx, 'tcx>, f: &Field) -> Ty<'tcx> - { + pub fn field_ty(self, tcx: TyCtxt<'gcx, 'tcx>, f: &Field) -> Ty<'tcx> { let answer = match self.ty.sty { ty::Adt(adt_def, substs) => { let variant_def = match self.variant_index { @@ -57,10 +56,7 @@ impl<'gcx, 'tcx> PlaceTy<'tcx> { /// Convenience wrapper around `projection_ty_core` for /// `PlaceElem`, where we can just use the `Ty` that is already /// stored inline on field projection elems. - pub fn projection_ty(self, tcx: TyCtxt<'gcx, 'tcx>, - elem: &PlaceElem<'tcx>) - -> PlaceTy<'tcx> - { + pub fn projection_ty(self, tcx: TyCtxt<'gcx, 'tcx>, elem: &PlaceElem<'tcx>) -> PlaceTy<'tcx> { self.projection_ty_core(tcx, elem, |_, _, ty| ty) } @@ -73,10 +69,11 @@ impl<'gcx, 'tcx> PlaceTy<'tcx> { self, tcx: TyCtxt<'gcx, 'tcx>, elem: &ProjectionElem, - mut handle_field: impl FnMut(&Self, &Field, &T) -> Ty<'tcx>) - -> PlaceTy<'tcx> + mut handle_field: impl FnMut(&Self, &Field, &T) -> Ty<'tcx>, + ) -> PlaceTy<'tcx> where - V: ::std::fmt::Debug, T: ::std::fmt::Debug + V: ::std::fmt::Debug, + T: ::std::fmt::Debug, { let answer = match *elem { ProjectionElem::Deref => { @@ -122,7 +119,8 @@ BraceStructTypeFoldableImpl! { impl<'tcx> Place<'tcx> { pub fn ty<'gcx, D>(&self, local_decls: &D, tcx: TyCtxt<'gcx, 'tcx>) -> PlaceTy<'tcx> - where D: HasLocalDecls<'tcx> + where + D: HasLocalDecls<'tcx>, { match *self { Place::Base(PlaceBase::Local(index)) => @@ -142,7 +140,8 @@ pub enum RvalueInitializationState { impl<'tcx> Rvalue<'tcx> { pub fn ty<'gcx, D>(&self, local_decls: &D, tcx: TyCtxt<'gcx, 'tcx>) -> Ty<'tcx> - where D: HasLocalDecls<'tcx> + where + D: HasLocalDecls<'tcx>, { match *self { Rvalue::Use(ref operand) => operand.ty(local_decls, tcx), @@ -223,7 +222,8 @@ impl<'tcx> Rvalue<'tcx> { impl<'tcx> Operand<'tcx> { pub fn ty<'gcx, D>(&self, local_decls: &D, tcx: TyCtxt<'gcx, 'tcx>) -> Ty<'tcx> - where D: HasLocalDecls<'tcx> + where + D: HasLocalDecls<'tcx>, { match self { &Operand::Copy(ref l) | @@ -234,10 +234,12 @@ impl<'tcx> Operand<'tcx> { } impl<'tcx> BinOp { - pub fn ty<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>, - lhs_ty: Ty<'tcx>, - rhs_ty: Ty<'tcx>) - -> Ty<'tcx> { + pub fn ty<'gcx>( + &self, + tcx: TyCtxt<'gcx, 'tcx>, + lhs_ty: Ty<'tcx>, + rhs_ty: Ty<'tcx>, + ) -> Ty<'tcx> { // FIXME: handle SIMD correctly match self { &BinOp::Add | &BinOp::Sub | &BinOp::Mul | &BinOp::Div | &BinOp::Rem | diff --git a/src/librustc/traits/codegen/mod.rs b/src/librustc/traits/codegen/mod.rs index 469fd6f97666a..f2c173230765b 100644 --- a/src/librustc/traits/codegen/mod.rs +++ b/src/librustc/traits/codegen/mod.rs @@ -18,11 +18,10 @@ use crate::ty::fold::TypeFoldable; /// that type check should guarantee to us that all nested /// obligations *could be* resolved if we wanted to. /// Assumes that this is run after the entire crate has been successfully type-checked. -pub fn codegen_fulfill_obligation<'tcx>(ty: TyCtxt<'tcx, 'tcx>, - (param_env, trait_ref): - (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)) - -> Vtable<'tcx, ()> -{ +pub fn codegen_fulfill_obligation<'tcx>( + ty: TyCtxt<'tcx, 'tcx>, + (param_env, trait_ref): (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>), +) -> Vtable<'tcx, ()> { // Remove any references to regions; this helps improve caching. let trait_ref = ty.erase_regions(&trait_ref); diff --git a/src/librustc/traits/coherence.rs b/src/librustc/traits/coherence.rs index 95e96036b4992..83f9796364163 100644 --- a/src/librustc/traits/coherence.rs +++ b/src/librustc/traits/coherence.rs @@ -183,10 +183,10 @@ fn overlap_within_probe( Some(OverlapResult { impl_header, intercrate_ambiguity_causes, involves_placeholder }) } -pub fn trait_ref_is_knowable<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'tcx>, - trait_ref: ty::TraitRef<'tcx>) - -> Option -{ +pub fn trait_ref_is_knowable<'gcx, 'tcx>( + tcx: TyCtxt<'gcx, 'tcx>, + trait_ref: ty::TraitRef<'tcx>, +) -> Option { debug!("trait_ref_is_knowable(trait_ref={:?})", trait_ref); if orphan_check_trait_ref(tcx, trait_ref, InCrate::Remote).is_ok() { // A downstream or cousin crate is allowed to implement some @@ -229,9 +229,10 @@ pub fn trait_ref_is_knowable<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'tcx>, } } -pub fn trait_ref_is_local_or_fundamental<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'tcx>, - trait_ref: ty::TraitRef<'tcx>) - -> bool { +pub fn trait_ref_is_local_or_fundamental<'gcx, 'tcx>( + tcx: TyCtxt<'gcx, 'tcx>, + trait_ref: ty::TraitRef<'tcx>, +) -> bool { trait_ref.def_id.krate == LOCAL_CRATE || tcx.has_attr(trait_ref.def_id, sym::fundamental) } @@ -246,10 +247,10 @@ pub enum OrphanCheckErr<'tcx> { /// /// 1. All type parameters in `Self` must be "covered" by some local type constructor. /// 2. Some local type must appear in `Self`. -pub fn orphan_check<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'tcx>, - impl_def_id: DefId) - -> Result<(), OrphanCheckErr<'tcx>> -{ +pub fn orphan_check<'gcx, 'tcx>( + tcx: TyCtxt<'gcx, 'tcx>, + impl_def_id: DefId, +) -> Result<(), OrphanCheckErr<'tcx>> { debug!("orphan_check({:?})", impl_def_id); // We only except this routine to be invoked on implementations @@ -353,11 +354,11 @@ pub fn orphan_check<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'tcx>, /// /// Note that this function is never called for types that have both type /// parameters and inference variables. -fn orphan_check_trait_ref<'tcx>(tcx: TyCtxt<'_, '_>, - trait_ref: ty::TraitRef<'tcx>, - in_crate: InCrate) - -> Result<(), OrphanCheckErr<'tcx>> -{ +fn orphan_check_trait_ref<'tcx>( + tcx: TyCtxt<'_, '_>, + trait_ref: ty::TraitRef<'tcx>, + in_crate: InCrate, +) -> Result<(), OrphanCheckErr<'tcx>> { debug!("orphan_check_trait_ref(trait_ref={:?}, in_crate={:?})", trait_ref, in_crate); @@ -430,8 +431,7 @@ fn orphan_check_trait_ref<'tcx>(tcx: TyCtxt<'_, '_>, } } -fn uncovered_tys<'tcx>(tcx: TyCtxt<'_, '_>, ty: Ty<'tcx>, in_crate: InCrate) - -> Vec> { +fn uncovered_tys<'tcx>(tcx: TyCtxt<'_, '_>, ty: Ty<'tcx>, in_crate: InCrate) -> Vec> { if ty_is_local_constructor(ty, in_crate) { vec![] } else if fundamental_ty(ty) { diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 50eac8f069058..1fb325ae05669 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -1242,15 +1242,17 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { err } - fn report_closure_arg_mismatch(&self, - span: Span, - found_span: Option, - expected_ref: ty::PolyTraitRef<'tcx>, - found: ty::PolyTraitRef<'tcx>) - -> DiagnosticBuilder<'tcx> - { - fn build_fn_sig_string<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'tcx>, - trait_ref: &ty::TraitRef<'tcx>) -> String { + fn report_closure_arg_mismatch( + &self, + span: Span, + found_span: Option, + expected_ref: ty::PolyTraitRef<'tcx>, + found: ty::PolyTraitRef<'tcx>, + ) -> DiagnosticBuilder<'tcx> { + fn build_fn_sig_string<'gcx, 'tcx>( + tcx: TyCtxt<'gcx, 'tcx>, + trait_ref: &ty::TraitRef<'tcx>, + ) -> String { let inputs = trait_ref.substs.type_at(1); let sig = if let ty::Tuple(inputs) = inputs.sty { tcx.mk_fn_sig( @@ -1447,10 +1449,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { /// Returns `true` if the trait predicate may apply for *some* assignment /// to the type parameters. - fn predicate_can_apply(&self, - param_env: ty::ParamEnv<'tcx>, - pred: ty::PolyTraitRef<'tcx>) - -> bool { + fn predicate_can_apply( + &self, + param_env: ty::ParamEnv<'tcx>, + pred: ty::PolyTraitRef<'tcx>, + ) -> bool { struct ParamToVarFolder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { infcx: &'a InferCtxt<'a, 'gcx, 'tcx>, var_map: FxHashMap, Ty<'tcx>> diff --git a/src/librustc/traits/mod.rs b/src/librustc/traits/mod.rs index b478824129909..01be8de172c26 100644 --- a/src/librustc/traits/mod.rs +++ b/src/librustc/traits/mod.rs @@ -710,13 +710,13 @@ pub fn type_known_to_meet_bound_modulo_regions<'a, 'gcx, 'tcx>( } } -fn do_normalize_predicates<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - region_context: DefId, - cause: ObligationCause<'tcx>, - elaborated_env: ty::ParamEnv<'tcx>, - predicates: Vec>) - -> Result>, ErrorReported> -{ +fn do_normalize_predicates<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + region_context: DefId, + cause: ObligationCause<'tcx>, + elaborated_env: ty::ParamEnv<'tcx>, + predicates: Vec>, +) -> Result>, ErrorReported> { debug!( "do_normalize_predicates(predicates={:?}, region_context={:?}, cause={:?})", predicates, @@ -795,12 +795,12 @@ fn do_normalize_predicates<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, // FIXME: this is gonna need to be removed ... /// Normalizes the parameter environment, reporting errors if they occur. -pub fn normalize_param_env_or_error<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - region_context: DefId, - unnormalized_env: ty::ParamEnv<'tcx>, - cause: ObligationCause<'tcx>) - -> ty::ParamEnv<'tcx> -{ +pub fn normalize_param_env_or_error<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + region_context: DefId, + unnormalized_env: ty::ParamEnv<'tcx>, + cause: ObligationCause<'tcx>, +) -> ty::ParamEnv<'tcx> { // I'm not wild about reporting errors here; I'd prefer to // have the errors get reported at a defined place (e.g., // during typeck). Instead I have all parameter @@ -936,10 +936,10 @@ pub fn fully_normalize<'a, 'gcx, 'tcx, T>( /// environment. If this returns false, then either normalize /// encountered an error or one of the predicates did not hold. Used /// when creating vtables to check for unsatisfiable methods. -fn normalize_and_test_predicates<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - predicates: Vec>) - -> bool -{ +fn normalize_and_test_predicates<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + predicates: Vec>, +) -> bool { debug!("normalize_and_test_predicates(predicates={:?})", predicates); @@ -965,10 +965,10 @@ fn normalize_and_test_predicates<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, result } -fn substitute_normalize_and_test_predicates<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - key: (DefId, SubstsRef<'tcx>)) - -> bool -{ +fn substitute_normalize_and_test_predicates<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + key: (DefId, SubstsRef<'tcx>), +) -> bool { debug!("substitute_normalize_and_test_predicates(key={:?})", key); @@ -985,9 +985,8 @@ fn substitute_normalize_and_test_predicates<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, #[inline] // FIXME(#35870): avoid closures being unexported due to `impl Trait`. fn vtable_methods<'tcx>( tcx: TyCtxt<'tcx, 'tcx>, - trait_ref: ty::PolyTraitRef<'tcx>) - -> &'tcx [Option<(DefId, SubstsRef<'tcx>)>] -{ + trait_ref: ty::PolyTraitRef<'tcx>, +) -> &'tcx [Option<(DefId, SubstsRef<'tcx>)>] { debug!("vtable_methods({:?})", trait_ref); tcx.arena.alloc_from_iter( diff --git a/src/librustc/traits/object_safety.rs b/src/librustc/traits/object_safety.rs index 88961c1dc81f1..01b81b182af96 100644 --- a/src/librustc/traits/object_safety.rs +++ b/src/librustc/traits/object_safety.rs @@ -84,7 +84,6 @@ pub enum MethodViolationCode { } impl<'tcx> TyCtxt<'tcx, 'tcx> { - /// Returns the object safety violations that affect /// astconv -- currently, `Self` in supertraits. This is needed /// because `object_safety_violations` can't be used during @@ -703,7 +702,6 @@ impl<'tcx> TyCtxt<'tcx, 'tcx> { } } -pub(super) fn is_object_safe_provider<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - trait_def_id: DefId) -> bool { +pub(super) fn is_object_safe_provider<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, trait_def_id: DefId) -> bool { tcx.object_safety_violations(trait_def_id).is_empty() } diff --git a/src/librustc/traits/on_unimplemented.rs b/src/librustc/traits/on_unimplemented.rs index 85af5efb42413..fe190db5fdbee 100644 --- a/src/librustc/traits/on_unimplemented.rs +++ b/src/librustc/traits/on_unimplemented.rs @@ -35,12 +35,13 @@ impl OnUnimplementedNote { } } -fn parse_error(tcx: TyCtxt<'_, '_>, span: Span, - message: &str, - label: &str, - note: Option<&str>) - -> ErrorReported -{ +fn parse_error( + tcx: TyCtxt<'_, '_>, + span: Span, + message: &str, + label: &str, + note: Option<&str>, +) -> ErrorReported { let mut diag = struct_span_err!( tcx.sess, span, E0232, "{}", message); diag.span_label(span, label); @@ -52,13 +53,13 @@ fn parse_error(tcx: TyCtxt<'_, '_>, span: Span, } impl<'gcx, 'tcx> OnUnimplementedDirective { - fn parse(tcx: TyCtxt<'gcx, 'tcx>, - trait_def_id: DefId, - items: &[NestedMetaItem], - span: Span, - is_root: bool) - -> Result - { + fn parse( + tcx: TyCtxt<'gcx, 'tcx>, + trait_def_id: DefId, + items: &[NestedMetaItem], + span: Span, + is_root: bool, + ) -> Result { let mut errored = false; let mut item_iter = items.iter(); @@ -132,12 +133,11 @@ impl<'gcx, 'tcx> OnUnimplementedDirective { } } - - pub fn of_item(tcx: TyCtxt<'gcx, 'tcx>, - trait_def_id: DefId, - impl_def_id: DefId) - -> Result, ErrorReported> - { + pub fn of_item( + tcx: TyCtxt<'gcx, 'tcx>, + trait_def_id: DefId, + impl_def_id: DefId, + ) -> Result, ErrorReported> { let attrs = tcx.get_attrs(impl_def_id); let attr = if let Some(item) = attr::find_by_name(&attrs, sym::rustc_on_unimplemented) { @@ -164,12 +164,12 @@ impl<'gcx, 'tcx> OnUnimplementedDirective { result } - pub fn evaluate(&self, - tcx: TyCtxt<'gcx, 'tcx>, - trait_ref: ty::TraitRef<'tcx>, - options: &[(Symbol, Option)]) - -> OnUnimplementedNote - { + pub fn evaluate( + &self, + tcx: TyCtxt<'gcx, 'tcx>, + trait_ref: ty::TraitRef<'tcx>, + options: &[(Symbol, Option)], + ) -> OnUnimplementedNote { let mut message = None; let mut label = None; let mut note = None; @@ -215,12 +215,12 @@ impl<'gcx, 'tcx> OnUnimplementedDirective { } impl<'gcx, 'tcx> OnUnimplementedFormatString { - fn try_parse(tcx: TyCtxt<'gcx, 'tcx>, - trait_def_id: DefId, - from: LocalInternedString, - err_sp: Span) - -> Result - { + fn try_parse( + tcx: TyCtxt<'gcx, 'tcx>, + trait_def_id: DefId, + from: LocalInternedString, + err_sp: Span, + ) -> Result { let result = OnUnimplementedFormatString(from); result.verify(tcx, trait_def_id, err_sp)?; Ok(result) diff --git a/src/librustc/traits/query/dropck_outlives.rs b/src/librustc/traits/query/dropck_outlives.rs index e2cb5cb89d98a..90df5ed10d78f 100644 --- a/src/librustc/traits/query/dropck_outlives.rs +++ b/src/librustc/traits/query/dropck_outlives.rs @@ -85,12 +85,7 @@ pub struct DropckOutlivesResult<'tcx> { } impl<'tcx> DropckOutlivesResult<'tcx> { - pub fn report_overflows( - &self, - tcx: TyCtxt<'_, 'tcx>, - span: Span, - ty: Ty<'tcx>, - ) { + pub fn report_overflows(&self, tcx: TyCtxt<'_, 'tcx>, span: Span, ty: Ty<'tcx>) { if let Some(overflow_ty) = self.overflows.iter().next() { let mut err = struct_span_err!( tcx.sess, diff --git a/src/librustc/traits/specialize/mod.rs b/src/librustc/traits/specialize/mod.rs index d395f7199fb2c..27891bed2b76e 100644 --- a/src/librustc/traits/specialize/mod.rs +++ b/src/librustc/traits/specialize/mod.rs @@ -149,10 +149,10 @@ pub fn find_associated_item<'tcx>( /// Specialization is determined by the sets of types to which the impls apply; /// `impl1` specializes `impl2` if it applies to a subset of the types `impl2` applies /// to. -pub(super) fn specializes<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - (impl1_def_id, impl2_def_id): (DefId, DefId)) - -> bool -{ +pub(super) fn specializes<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + (impl1_def_id, impl2_def_id): (DefId, DefId), +) -> bool { debug!("specializes({:?}, {:?})", impl1_def_id, impl2_def_id); // The feature gate should prevent introducing new specializations, but not diff --git a/src/librustc/traits/specialize/specialization_graph.rs b/src/librustc/traits/specialize/specialization_graph.rs index 89116fac7303b..2e86d40a3ad54 100644 --- a/src/librustc/traits/specialize/specialization_graph.rs +++ b/src/librustc/traits/specialize/specialization_graph.rs @@ -83,9 +83,7 @@ enum Inserted { impl<'gcx, 'tcx> Children { /// Insert an impl into this set of children without comparing to any existing impls. - fn insert_blindly(&mut self, - tcx: TyCtxt<'gcx, 'tcx>, - impl_def_id: DefId) { + fn insert_blindly(&mut self, tcx: TyCtxt<'gcx, 'tcx>, impl_def_id: DefId) { let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap(); if let Some(sty) = fast_reject::simplify_type(tcx, trait_ref.self_ty(), false) { debug!("insert_blindly: impl_def_id={:?} sty={:?}", impl_def_id, sty); @@ -99,9 +97,7 @@ impl<'gcx, 'tcx> Children { /// Removes an impl from this set of children. Used when replacing /// an impl with a parent. The impl must be present in the list of /// children already. - fn remove_existing(&mut self, - tcx: TyCtxt<'gcx, 'tcx>, - impl_def_id: DefId) { + fn remove_existing(&mut self, tcx: TyCtxt<'gcx, 'tcx>, impl_def_id: DefId) { let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap(); let vec: &mut Vec; if let Some(sty) = fast_reject::simplify_type(tcx, trait_ref.self_ty(), false) { @@ -118,12 +114,12 @@ impl<'gcx, 'tcx> Children { /// Attempt to insert an impl into this set of children, while comparing for /// specialization relationships. - fn insert(&mut self, - tcx: TyCtxt<'gcx, 'tcx>, - impl_def_id: DefId, - simplified_self: Option) - -> Result - { + fn insert( + &mut self, + tcx: TyCtxt<'gcx, 'tcx>, + impl_def_id: DefId, + simplified_self: Option, + ) -> Result { let mut last_lint = None; let mut replace_children = Vec::new(); @@ -293,10 +289,11 @@ impl<'gcx, 'tcx> Graph { /// Insert a local impl into the specialization graph. If an existing impl /// conflicts with it (has overlap, but neither specializes the other), /// information about the area of overlap is returned in the `Err`. - pub fn insert(&mut self, - tcx: TyCtxt<'gcx, 'tcx>, - impl_def_id: DefId) - -> Result, OverlapError> { + pub fn insert( + &mut self, + tcx: TyCtxt<'gcx, 'tcx>, + impl_def_id: DefId, + ) -> Result, OverlapError> { assert!(impl_def_id.is_local()); let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap(); @@ -386,10 +383,12 @@ impl<'gcx, 'tcx> Graph { } /// Insert cached metadata mapping from a child impl back to its parent. - pub fn record_impl_from_cstore(&mut self, - tcx: TyCtxt<'gcx, 'tcx>, - parent: DefId, - child: DefId) { + pub fn record_impl_from_cstore( + &mut self, + tcx: TyCtxt<'gcx, 'tcx>, + parent: DefId, + child: DefId, + ) { if self.parent.insert(child, parent).is_some() { bug!("When recording an impl from the crate store, information about its parent \ was already present."); @@ -423,10 +422,7 @@ impl<'gcx, 'tcx> Node { } /// Iterate over the items defined directly by the given (impl or trait) node. - pub fn items( - &self, - tcx: TyCtxt<'gcx, 'tcx>, - ) -> ty::AssocItemsIterator<'gcx, 'tcx> { + pub fn items(&self, tcx: TyCtxt<'gcx, 'tcx>) -> ty::AssocItemsIterator<'gcx, 'tcx> { tcx.associated_items(self.def_id()) } @@ -508,10 +504,11 @@ impl<'gcx, 'tcx> Ancestors<'gcx> { /// Walk up the specialization ancestors of a given impl, starting with that /// impl itself. -pub fn ancestors(tcx: TyCtxt<'tcx, '_>, - trait_def_id: DefId, - start_from_impl: DefId) - -> Ancestors<'tcx> { +pub fn ancestors( + tcx: TyCtxt<'tcx, '_>, + trait_def_id: DefId, + start_from_impl: DefId, +) -> Ancestors<'tcx> { let specialization_graph = tcx.specialization_graph_of(trait_def_id); Ancestors { trait_def_id, diff --git a/src/librustc/traits/util.rs b/src/librustc/traits/util.rs index ef4f6472c87ec..c5ff174e94436 100644 --- a/src/librustc/traits/util.rs +++ b/src/librustc/traits/util.rs @@ -12,9 +12,10 @@ use crate::util::nodemap::FxHashSet; use super::{Obligation, ObligationCause, PredicateObligation, SelectionContext, Normalized}; -fn anonymize_predicate<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'tcx>, - pred: &ty::Predicate<'tcx>) - -> ty::Predicate<'tcx> { +fn anonymize_predicate<'gcx, 'tcx>( + tcx: TyCtxt<'gcx, 'tcx>, + pred: &ty::Predicate<'tcx>, +) -> ty::Predicate<'tcx> { match *pred { ty::Predicate::Trait(ref data) => ty::Predicate::Trait(tcx.anonymize_late_bound_regions(data)), @@ -95,26 +96,23 @@ pub struct Elaborator<'gcx, 'tcx> { pub fn elaborate_trait_ref<'gcx, 'tcx>( tcx: TyCtxt<'gcx, 'tcx>, - trait_ref: ty::PolyTraitRef<'tcx>) - -> Elaborator<'gcx, 'tcx> -{ + trait_ref: ty::PolyTraitRef<'tcx>, +) -> Elaborator<'gcx, 'tcx> { elaborate_predicates(tcx, vec![trait_ref.to_predicate()]) } pub fn elaborate_trait_refs<'gcx, 'tcx>( tcx: TyCtxt<'gcx, 'tcx>, - trait_refs: impl Iterator>) - -> Elaborator<'gcx, 'tcx> -{ + trait_refs: impl Iterator>, +) -> Elaborator<'gcx, 'tcx> { let predicates = trait_refs.map(|trait_ref| trait_ref.to_predicate()).collect(); elaborate_predicates(tcx, predicates) } pub fn elaborate_predicates<'gcx, 'tcx>( tcx: TyCtxt<'gcx, 'tcx>, - mut predicates: Vec>) - -> Elaborator<'gcx, 'tcx> -{ + mut predicates: Vec>, +) -> Elaborator<'gcx, 'tcx> { let mut visited = PredicateSet::new(tcx); predicates.retain(|pred| visited.insert(pred)); Elaborator { stack: predicates, visited } @@ -256,15 +254,17 @@ impl Iterator for Elaborator<'gcx, 'tcx> { pub type Supertraits<'gcx, 'tcx> = FilterToTraits>; -pub fn supertraits<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'tcx>, - trait_ref: ty::PolyTraitRef<'tcx>) - -> Supertraits<'gcx, 'tcx> { +pub fn supertraits<'gcx, 'tcx>( + tcx: TyCtxt<'gcx, 'tcx>, + trait_ref: ty::PolyTraitRef<'tcx>, +) -> Supertraits<'gcx, 'tcx> { elaborate_trait_ref(tcx, trait_ref).filter_to_traits() } -pub fn transitive_bounds<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'tcx>, - bounds: impl Iterator>) - -> Supertraits<'gcx, 'tcx> { +pub fn transitive_bounds<'gcx, 'tcx>( + tcx: TyCtxt<'gcx, 'tcx>, + bounds: impl Iterator>, +) -> Supertraits<'gcx, 'tcx> { elaborate_trait_refs(tcx, bounds).filter_to_traits() } @@ -339,7 +339,7 @@ impl<'tcx> TraitAliasExpansionInfo<'tcx> { pub fn expand_trait_aliases<'gcx, 'tcx>( tcx: TyCtxt<'gcx, 'tcx>, - trait_refs: impl IntoIterator, Span)> + trait_refs: impl IntoIterator, Span)>, ) -> TraitAliasExpander<'gcx, 'tcx> { let items: Vec<_> = trait_refs .into_iter() @@ -420,10 +420,10 @@ pub struct SupertraitDefIds<'gcx, 'tcx> { visited: FxHashSet, } -pub fn supertrait_def_ids<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'tcx>, - trait_def_id: DefId) - -> SupertraitDefIds<'gcx, 'tcx> -{ +pub fn supertrait_def_ids<'gcx, 'tcx>( + tcx: TyCtxt<'gcx, 'tcx>, + trait_def_id: DefId, +) -> SupertraitDefIds<'gcx, 'tcx> { SupertraitDefIds { tcx, stack: vec![trait_def_id], diff --git a/src/librustc/ty/_match.rs b/src/librustc/ty/_match.rs index 38a85c21963ce..213f556f9acac 100644 --- a/src/librustc/ty/_match.rs +++ b/src/librustc/ty/_match.rs @@ -20,7 +20,7 @@ use crate::mir::interpret::ConstValue; /// important thing about the result is Ok/Err. Also, matching never /// affects any type variables or unification state. pub struct Match<'gcx, 'tcx> { - tcx: TyCtxt<'gcx, 'tcx> + tcx: TyCtxt<'gcx, 'tcx>, } impl Match<'gcx, 'tcx> { diff --git a/src/librustc/ty/adjustment.rs b/src/librustc/ty/adjustment.rs index d5fe106085160..e1f86bee4babb 100644 --- a/src/librustc/ty/adjustment.rs +++ b/src/librustc/ty/adjustment.rs @@ -104,8 +104,11 @@ pub struct OverloadedDeref<'tcx> { } impl<'gcx, 'tcx> OverloadedDeref<'tcx> { - pub fn method_call(&self, tcx: TyCtxt<'gcx, 'tcx>, source: Ty<'tcx>) - -> (DefId, SubstsRef<'tcx>) { + pub fn method_call( + &self, + tcx: TyCtxt<'gcx, 'tcx>, + source: Ty<'tcx>, + ) -> (DefId, SubstsRef<'tcx>) { let trait_def_id = match self.mutbl { hir::MutImmutable => tcx.lang_items().deref_trait(), hir::MutMutable => tcx.lang_items().deref_mut_trait() diff --git a/src/librustc/ty/codec.rs b/src/librustc/ty/codec.rs index 7f89b2ccfdb5b..ea5d088d540fd 100644 --- a/src/librustc/ty/codec.rs +++ b/src/librustc/ty/codec.rs @@ -132,25 +132,28 @@ pub trait TyDecoder<'tcx>: Decoder { #[inline] pub fn decode_arena_allocable( - decoder: &mut D + decoder: &mut D, ) -> Result<&'tcx T, D::Error> - where D: TyDecoder<'tcx>, +where + D: TyDecoder<'tcx>, { Ok(decoder.tcx().arena.alloc(Decodable::decode(decoder)?)) } #[inline] pub fn decode_arena_allocable_slice( - decoder: &mut D + decoder: &mut D, ) -> Result<&'tcx [T], D::Error> - where D: TyDecoder<'tcx>, +where + D: TyDecoder<'tcx>, { Ok(decoder.tcx().arena.alloc_from_iter( as Decodable>::decode(decoder)?)) } #[inline] pub fn decode_cnum(decoder: &mut D) -> Result - where D: TyDecoder<'tcx>, +where + D: TyDecoder<'tcx>, { let cnum = CrateNum::from_u32(u32::decode(decoder)?); Ok(decoder.map_encoded_cnum_to_current(cnum)) @@ -158,7 +161,8 @@ pub fn decode_cnum(decoder: &mut D) -> Result #[inline] pub fn decode_ty(decoder: &mut D) -> Result, D::Error> - where D: TyDecoder<'tcx>, +where + D: TyDecoder<'tcx>, { // Handle shorthands first, if we have an usize > 0x80. if decoder.positioned_at_shorthand() { @@ -176,9 +180,9 @@ pub fn decode_ty(decoder: &mut D) -> Result, D::Error> } #[inline] -pub fn decode_predicates(decoder: &mut D) - -> Result, D::Error> - where D: TyDecoder<'tcx>, +pub fn decode_predicates(decoder: &mut D) -> Result, D::Error> +where + D: TyDecoder<'tcx>, { Ok(ty::GenericPredicates { parent: Decodable::decode(decoder)?, @@ -201,7 +205,8 @@ pub fn decode_predicates(decoder: &mut D) #[inline] pub fn decode_substs(decoder: &mut D) -> Result, D::Error> - where D: TyDecoder<'tcx>, +where + D: TyDecoder<'tcx>, { let len = decoder.read_usize()?; let tcx = decoder.tcx(); @@ -210,33 +215,36 @@ pub fn decode_substs(decoder: &mut D) -> Result, D::Error> #[inline] pub fn decode_region(decoder: &mut D) -> Result, D::Error> - where D: TyDecoder<'tcx>, +where + D: TyDecoder<'tcx>, { Ok(decoder.tcx().mk_region(Decodable::decode(decoder)?)) } #[inline] -pub fn decode_ty_slice(decoder: &mut D) - -> Result<&'tcx ty::List>, D::Error> - where D: TyDecoder<'tcx>, +pub fn decode_ty_slice(decoder: &mut D) -> Result<&'tcx ty::List>, D::Error> +where + D: TyDecoder<'tcx>, { let len = decoder.read_usize()?; Ok(decoder.tcx().mk_type_list((0..len).map(|_| Decodable::decode(decoder)))?) } #[inline] -pub fn decode_adt_def(decoder: &mut D) - -> Result<&'tcx ty::AdtDef, D::Error> - where D: TyDecoder<'tcx>, +pub fn decode_adt_def(decoder: &mut D) -> Result<&'tcx ty::AdtDef, D::Error> +where + D: TyDecoder<'tcx>, { let def_id = DefId::decode(decoder)?; Ok(decoder.tcx().adt_def(def_id)) } #[inline] -pub fn decode_existential_predicate_slice(decoder: &mut D) - -> Result<&'tcx ty::List>, D::Error> - where D: TyDecoder<'tcx>, +pub fn decode_existential_predicate_slice( + decoder: &mut D, +) -> Result<&'tcx ty::List>, D::Error> +where + D: TyDecoder<'tcx>, { let len = decoder.read_usize()?; Ok(decoder.tcx() @@ -244,9 +252,9 @@ pub fn decode_existential_predicate_slice(decoder: &mut D) } #[inline] -pub fn decode_canonical_var_infos(decoder: &mut D) - -> Result, D::Error> - where D: TyDecoder<'tcx>, +pub fn decode_canonical_var_infos(decoder: &mut D) -> Result, D::Error> +where + D: TyDecoder<'tcx>, { let len = decoder.read_usize()?; let interned: Result, _> = (0..len).map(|_| Decodable::decode(decoder)) @@ -256,17 +264,17 @@ pub fn decode_canonical_var_infos(decoder: &mut D) } #[inline] -pub fn decode_const(decoder: &mut D) - -> Result<&'tcx ty::Const<'tcx>, D::Error> - where D: TyDecoder<'tcx>, +pub fn decode_const(decoder: &mut D) -> Result<&'tcx ty::Const<'tcx>, D::Error> +where + D: TyDecoder<'tcx>, { Ok(decoder.tcx().mk_const(Decodable::decode(decoder)?)) } #[inline] -pub fn decode_allocation(decoder: &mut D) - -> Result<&'tcx Allocation, D::Error> - where D: TyDecoder<'tcx>, +pub fn decode_allocation(decoder: &mut D) -> Result<&'tcx Allocation, D::Error> +where + D: TyDecoder<'tcx>, { Ok(decoder.tcx().intern_const_alloc(Decodable::decode(decoder)?)) } diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 106637a5b2041..4e255edfe8563 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -1678,10 +1678,7 @@ impl<'gcx> GlobalCtxt<'gcx> { /// Call the closure with a local `TyCtxt` using the given arena. /// `interners` is a slot passed so we can create a CtxtInterners /// with the same lifetime as `arena`. - pub fn enter_local<'tcx, F, R>( - &'gcx self, - f: F - ) -> R + pub fn enter_local<'tcx, F, R>(&'gcx self, f: F) -> R where F: FnOnce(TyCtxt<'gcx, 'tcx>) -> R, 'gcx: 'tcx, @@ -1732,41 +1729,41 @@ pub trait Lift<'tcx>: fmt::Debug { macro_rules! nop_lift { ($ty:ty => $lifted:ty) => { impl<'a, 'tcx> Lift<'tcx> for $ty { - type Lifted = $lifted; - fn lift_to_tcx<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>) -> Option { - if tcx.interners.arena.in_arena(*self as *const _) { - return Some(unsafe { mem::transmute(*self) }); - } - // Also try in the global tcx if we're not that. - if !tcx.is_global() { - self.lift_to_tcx(tcx.global_tcx()) - } else { - None + type Lifted = $lifted; + fn lift_to_tcx<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>) -> Option { + if tcx.interners.arena.in_arena(*self as *const _) { + return Some(unsafe { mem::transmute(*self) }); + } + // Also try in the global tcx if we're not that. + if !tcx.is_global() { + self.lift_to_tcx(tcx.global_tcx()) + } else { + None + } + } } - } - } }; } macro_rules! nop_list_lift { ($ty:ty => $lifted:ty) => { impl<'a, 'tcx> Lift<'tcx> for &'a List<$ty> { - type Lifted = &'tcx List<$lifted>; - fn lift_to_tcx<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>) -> Option { - if self.is_empty() { - return Some(List::empty()); - } - if tcx.interners.arena.in_arena(*self as *const _) { - return Some(unsafe { mem::transmute(*self) }); - } - // Also try in the global tcx if we're not that. - if !tcx.is_global() { - self.lift_to_tcx(tcx.global_tcx()) - } else { - None + type Lifted = &'tcx List<$lifted>; + fn lift_to_tcx<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>) -> Option { + if self.is_empty() { + return Some(List::empty()); + } + if tcx.interners.arena.in_arena(*self as *const _) { + return Some(unsafe { mem::transmute(*self) }); + } + // Also try in the global tcx if we're not that. + if !tcx.is_global() { + self.lift_to_tcx(tcx.global_tcx()) + } else { + None + } + } } - } - } }; } @@ -1941,7 +1938,8 @@ pub mod tls { /// This happens once per rustc session and TyCtxts only exists /// inside the `f` function. pub fn enter_global<'gcx, F, R>(gcx: &'gcx GlobalCtxt<'gcx>, f: F) -> R - where F: FnOnce(TyCtxt<'gcx, 'gcx>) -> R + where + F: FnOnce(TyCtxt<'gcx, 'gcx>) -> R, { // Update GCX_PTR to indicate there's a GlobalCtxt available GCX_PTR.with(|lock| { @@ -1978,7 +1976,8 @@ pub mod tls { /// Creates a TyCtxt and ImplicitCtxt based on the GCX_PTR thread local. /// This is used in the deadlock handler. pub unsafe fn with_global(f: F) -> R - where F: for<'gcx, 'tcx> FnOnce(TyCtxt<'gcx, 'tcx>) -> R + where + F: for<'gcx, 'tcx> FnOnce(TyCtxt<'gcx, 'tcx>) -> R, { let gcx = GCX_PTR.with(|lock| *lock.lock()); assert!(gcx != 0); @@ -2031,7 +2030,8 @@ pub mod tls { /// the current ImplicitCtxt's tcx field. #[inline] pub fn with_related_context<'gcx, 'tcx1, F, R>(tcx: TyCtxt<'gcx, 'tcx1>, f: F) -> R - where F: for<'b, 'tcx2> FnOnce(&ImplicitCtxt<'b, 'gcx, 'tcx2>) -> R + where + F: for<'b, 'tcx2> FnOnce(&ImplicitCtxt<'b, 'gcx, 'tcx2>) -> R, { with_context(|context| { unsafe { @@ -2049,7 +2049,8 @@ pub mod tls { /// a different local interner from the current ImplicitCtxt's tcx field. #[inline] pub fn with_fully_related_context<'gcx, 'tcx, F, R>(tcx: TyCtxt<'gcx, 'tcx>, f: F) -> R - where F: for<'b> FnOnce(&ImplicitCtxt<'b, 'gcx, 'tcx>) -> R + where + F: for<'b> FnOnce(&ImplicitCtxt<'b, 'gcx, 'tcx>) -> R, { with_context(|context| { unsafe { @@ -2065,7 +2066,8 @@ pub mod tls { /// Panics if there is no ImplicitCtxt available #[inline] pub fn with(f: F) -> R - where F: for<'gcx, 'tcx> FnOnce(TyCtxt<'gcx, 'tcx>) -> R + where + F: for<'gcx, 'tcx> FnOnce(TyCtxt<'gcx, 'tcx>) -> R, { with_context(|context| f(context.tcx)) } @@ -2074,7 +2076,8 @@ pub mod tls { /// The closure is passed None if there is no ImplicitCtxt available #[inline] pub fn with_opt(f: F) -> R - where F: for<'gcx, 'tcx> FnOnce(Option>) -> R + where + F: for<'gcx, 'tcx> FnOnce(Option>) -> R, { with_context_opt(|opt_context| f(opt_context.map(|context| context.tcx))) } diff --git a/src/librustc/ty/fast_reject.rs b/src/librustc/ty/fast_reject.rs index 238865c866e50..d32ad0f5c6d50 100644 --- a/src/librustc/ty/fast_reject.rs +++ b/src/librustc/ty/fast_reject.rs @@ -55,11 +55,11 @@ pub enum SimplifiedTypeGen /// then we can't say much about whether two types would unify. Put another way, /// `can_simplify_params` should be true if type parameters appear free in `ty` and `false` if they /// are to be considered bound. -pub fn simplify_type<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'tcx>, - ty: Ty<'_>, - can_simplify_params: bool) - -> Option -{ +pub fn simplify_type<'gcx, 'tcx>( + tcx: TyCtxt<'gcx, 'tcx>, + ty: Ty<'_>, + can_simplify_params: bool, +) -> Option { match ty.sty { ty::Bool => Some(BoolSimplifiedType), ty::Char => Some(CharSimplifiedType), diff --git a/src/librustc/ty/fold.rs b/src/librustc/ty/fold.rs index 00ef9446fb194..c79dad04df624 100644 --- a/src/librustc/ty/fold.rs +++ b/src/librustc/ty/fold.rs @@ -155,7 +155,7 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone { /// default implementation that does an "identity" fold. Within each /// identity fold, it should invoke `foo.fold_with(self)` to fold each /// sub-item. -pub trait TypeFolder<'gcx: 'tcx, 'tcx> : Sized { +pub trait TypeFolder<'gcx: 'tcx, 'tcx>: Sized { fn tcx<'a>(&'a self) -> TyCtxt<'gcx, 'tcx>; fn fold_binder(&mut self, t: &Binder) -> Binder @@ -199,9 +199,10 @@ pub trait TypeVisitor<'tcx> : Sized { // Some sample folders pub struct BottomUpFolder<'gcx, 'tcx, F, G, H> - where F: FnMut(Ty<'tcx>) -> Ty<'tcx>, - G: FnMut(ty::Region<'tcx>) -> ty::Region<'tcx>, - H: FnMut(&'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx>, +where + F: FnMut(Ty<'tcx>) -> Ty<'tcx>, + G: FnMut(ty::Region<'tcx>) -> ty::Region<'tcx>, + H: FnMut(&'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx>, { pub tcx: TyCtxt<'gcx, 'tcx>, pub ty_op: F, @@ -210,11 +211,14 @@ pub struct BottomUpFolder<'gcx, 'tcx, F, G, H> } impl<'gcx, 'tcx, F, G, H> TypeFolder<'gcx, 'tcx> for BottomUpFolder<'gcx, 'tcx, F, G, H> - where F: FnMut(Ty<'tcx>) -> Ty<'tcx>, - G: FnMut(ty::Region<'tcx>) -> ty::Region<'tcx>, - H: FnMut(&'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx>, +where + F: FnMut(Ty<'tcx>) -> Ty<'tcx>, + G: FnMut(ty::Region<'tcx>) -> ty::Region<'tcx>, + H: FnMut(&'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx>, { - fn tcx<'b>(&'b self) -> TyCtxt<'gcx, 'tcx> { self.tcx } + fn tcx<'b>(&'b self) -> TyCtxt<'gcx, 'tcx> { + self.tcx + } fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { let t = ty.super_fold_with(self); @@ -361,7 +365,7 @@ impl<'gcx, 'tcx> TyCtxt<'gcx, 'tcx> { /// visited by this folder; only regions that occur free will be /// visited by `fld_r`. -pub struct RegionFolder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { +pub struct RegionFolder<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> { tcx: TyCtxt<'gcx, 'tcx>, skipped_regions: &'a mut bool, @@ -373,10 +377,8 @@ pub struct RegionFolder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { /// Callback invokes for each free region. The `DebruijnIndex` /// points to the binder *just outside* the ones we have passed /// through. - fold_region_fn: &'a mut (dyn FnMut( - ty::Region<'tcx>, - ty::DebruijnIndex, - ) -> ty::Region<'tcx> + 'a), + fold_region_fn: + &'a mut (dyn FnMut(ty::Region<'tcx>, ty::DebruijnIndex) -> ty::Region<'tcx> + 'a), } impl<'a, 'gcx, 'tcx> RegionFolder<'a, 'gcx, 'tcx> { @@ -396,7 +398,9 @@ impl<'a, 'gcx, 'tcx> RegionFolder<'a, 'gcx, 'tcx> { } impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for RegionFolder<'a, 'gcx, 'tcx> { - fn tcx<'b>(&'b self) -> TyCtxt<'gcx, 'tcx> { self.tcx } + fn tcx<'b>(&'b self) -> TyCtxt<'gcx, 'tcx> { + self.tcx + } fn fold_binder>(&mut self, t: &ty::Binder) -> ty::Binder { self.current_index.shift_in(1); @@ -445,9 +449,10 @@ impl<'a, 'gcx, 'tcx> BoundVarReplacer<'a, 'gcx, 'tcx> { fld_t: &'a mut G, fld_c: &'a mut H, ) -> Self - where F: FnMut(ty::BoundRegion) -> ty::Region<'tcx>, - G: FnMut(ty::BoundTy) -> Ty<'tcx>, - H: FnMut(ty::BoundVar, Ty<'tcx>) -> &'tcx ty::Const<'tcx>, + where + F: FnMut(ty::BoundRegion) -> ty::Region<'tcx>, + G: FnMut(ty::BoundTy) -> Ty<'tcx>, + H: FnMut(ty::BoundVar, Ty<'tcx>) -> &'tcx ty::Const<'tcx>, { BoundVarReplacer { tcx, @@ -460,7 +465,9 @@ impl<'a, 'gcx, 'tcx> BoundVarReplacer<'a, 'gcx, 'tcx> { } impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for BoundVarReplacer<'a, 'gcx, 'tcx> { - fn tcx<'b>(&'b self) -> TyCtxt<'gcx, 'tcx> { self.tcx } + fn tcx<'b>(&'b self) -> TyCtxt<'gcx, 'tcx> { + self.tcx + } fn fold_binder>(&mut self, t: &ty::Binder) -> ty::Binder { self.current_index.shift_in(1); @@ -741,7 +748,9 @@ impl Shifter<'gcx, 'tcx> { } impl TypeFolder<'gcx, 'tcx> for Shifter<'gcx, 'tcx> { - fn tcx<'b>(&'b self) -> TyCtxt<'gcx, 'tcx> { self.tcx } + fn tcx<'b>(&'b self) -> TyCtxt<'gcx, 'tcx> { + self.tcx + } fn fold_binder>(&mut self, t: &ty::Binder) -> ty::Binder { self.current_index.shift_in(1); @@ -820,7 +829,7 @@ impl TypeFolder<'gcx, 'tcx> for Shifter<'gcx, 'tcx> { pub fn shift_region<'gcx, 'tcx>( tcx: TyCtxt<'gcx, 'tcx>, region: ty::Region<'tcx>, - amount: u32 + amount: u32, ) -> ty::Region<'tcx> { match region { ty::ReLateBound(debruijn, br) if amount > 0 => { @@ -832,22 +841,20 @@ pub fn shift_region<'gcx, 'tcx>( } } -pub fn shift_vars<'gcx, 'tcx, T>( - tcx: TyCtxt<'gcx, 'tcx>, - value: &T, - amount: u32 -) -> T where T: TypeFoldable<'tcx> { +pub fn shift_vars<'gcx, 'tcx, T>(tcx: TyCtxt<'gcx, 'tcx>, value: &T, amount: u32) -> T +where + T: TypeFoldable<'tcx>, +{ debug!("shift_vars(value={:?}, amount={})", value, amount); value.fold_with(&mut Shifter::new(tcx, amount, Direction::In)) } -pub fn shift_out_vars<'gcx, 'tcx, T>( - tcx: TyCtxt<'gcx, 'tcx>, - value: &T, - amount: u32 -) -> T where T: TypeFoldable<'tcx> { +pub fn shift_out_vars<'gcx, 'tcx, T>(tcx: TyCtxt<'gcx, 'tcx>, value: &T, amount: u32) -> T +where + T: TypeFoldable<'tcx>, +{ debug!("shift_out_vars(value={:?}, amount={})", value, amount); diff --git a/src/librustc/ty/inhabitedness/def_id_forest.rs b/src/librustc/ty/inhabitedness/def_id_forest.rs index 0573249e57c9a..023460096a882 100644 --- a/src/librustc/ty/inhabitedness/def_id_forest.rs +++ b/src/librustc/ty/inhabitedness/def_id_forest.rs @@ -52,17 +52,14 @@ impl<'gcx, 'tcx> DefIdForest { } /// Tests whether the forest contains a given DefId. - pub fn contains(&self, - tcx: TyCtxt<'gcx, 'tcx>, - id: DefId) -> bool - { + pub fn contains(&self, tcx: TyCtxt<'gcx, 'tcx>, id: DefId) -> bool { self.root_ids.iter().any(|root_id| tcx.is_descendant_of(id, *root_id)) } /// Calculate the intersection of a collection of forests. - pub fn intersection(tcx: TyCtxt<'gcx, 'tcx>, - iter: I) -> DefIdForest - where I: IntoIterator + pub fn intersection(tcx: TyCtxt<'gcx, 'tcx>, iter: I) -> DefIdForest + where + I: IntoIterator, { let mut iter = iter.into_iter(); let mut ret = if let Some(first) = iter.next() { @@ -97,9 +94,9 @@ impl<'gcx, 'tcx> DefIdForest { } /// Calculate the union of a collection of forests. - pub fn union(tcx: TyCtxt<'gcx, 'tcx>, - iter: I) -> DefIdForest - where I: IntoIterator + pub fn union(tcx: TyCtxt<'gcx, 'tcx>, iter: I) -> DefIdForest + where + I: IntoIterator, { let mut ret = DefIdForest::empty(); let mut next_ret = SmallVec::new(); diff --git a/src/librustc/ty/inhabitedness/mod.rs b/src/librustc/ty/inhabitedness/mod.rs index 54558fd6561ac..b9e34e0cabc65 100644 --- a/src/librustc/ty/inhabitedness/mod.rs +++ b/src/librustc/ty/inhabitedness/mod.rs @@ -108,11 +108,7 @@ impl<'gcx, 'tcx> TyCtxt<'gcx, 'tcx> { impl<'gcx, 'tcx> AdtDef { /// Calculate the forest of DefIds from which this adt is visibly uninhabited. - fn uninhabited_from( - &self, - tcx: TyCtxt<'gcx, 'tcx>, - substs: SubstsRef<'tcx>) -> DefIdForest - { + fn uninhabited_from(&self, tcx: TyCtxt<'gcx, 'tcx>, substs: SubstsRef<'tcx>) -> DefIdForest { // Non-exhaustive ADTs from other crates are always considered inhabited. if self.is_variant_list_non_exhaustive() && !self.did.is_local() { DefIdForest::empty() @@ -130,8 +126,8 @@ impl<'gcx, 'tcx> VariantDef { &self, tcx: TyCtxt<'gcx, 'tcx>, substs: SubstsRef<'tcx>, - adt_kind: AdtKind) -> DefIdForest - { + adt_kind: AdtKind, + ) -> DefIdForest { let is_enum = match adt_kind { // For now, `union`s are never considered uninhabited. // The precise semantics of inhabitedness with respect to unions is currently undecided. @@ -182,8 +178,7 @@ impl<'gcx, 'tcx> FieldDef { impl<'gcx, 'tcx> TyS<'tcx> { /// Calculate the forest of DefIds from which this type is visibly uninhabited. - fn uninhabited_from(&self, tcx: TyCtxt<'gcx, 'tcx>) -> DefIdForest - { + fn uninhabited_from(&self, tcx: TyCtxt<'gcx, 'tcx>) -> DefIdForest { match self.sty { Adt(def, substs) => def.uninhabited_from(tcx, substs), diff --git a/src/librustc/ty/instance.rs b/src/librustc/ty/instance.rs index a48f88220f417..16df0da88207b 100644 --- a/src/librustc/ty/instance.rs +++ b/src/librustc/ty/instance.rs @@ -43,10 +43,7 @@ pub enum InstanceDef<'tcx> { } impl<'tcx> Instance<'tcx> { - pub fn ty(&self, - tcx: TyCtxt<'tcx, 'tcx>) - -> Ty<'tcx> - { + pub fn ty(&self, tcx: TyCtxt<'tcx, 'tcx>) -> Ty<'tcx> { let ty = tcx.type_of(self.def.def_id()); tcx.subst_and_normalize_erasing_regions( self.substs, @@ -140,10 +137,7 @@ impl<'tcx> InstanceDef<'tcx> { tcx.get_attrs(self.def_id()) } - pub fn is_inline( - &self, - tcx: TyCtxt<'tcx, 'tcx> - ) -> bool { + pub fn is_inline(&self, tcx: TyCtxt<'tcx, 'tcx>) -> bool { use crate::hir::map::DefPathData; let def_id = match *self { ty::InstanceDef::Item(def_id) => def_id, @@ -156,10 +150,7 @@ impl<'tcx> InstanceDef<'tcx> { } } - pub fn requires_local( - &self, - tcx: TyCtxt<'tcx, 'tcx> - ) -> bool { + pub fn requires_local(&self, tcx: TyCtxt<'tcx, 'tcx>) -> bool { if self.is_inline(tcx) { return true } @@ -245,10 +236,12 @@ impl<'b, 'tcx> Instance<'tcx> { /// Presuming that coherence and type-check have succeeded, if this method is invoked /// in a monomorphic context (i.e., like during codegen), then it is guaranteed to return /// `Some`. - pub fn resolve(tcx: TyCtxt<'tcx, 'tcx>, - param_env: ty::ParamEnv<'tcx>, - def_id: DefId, - substs: SubstsRef<'tcx>) -> Option> { + pub fn resolve( + tcx: TyCtxt<'tcx, 'tcx>, + param_env: ty::ParamEnv<'tcx>, + def_id: DefId, + substs: SubstsRef<'tcx>, + ) -> Option> { debug!("resolve(def_id={:?}, substs={:?})", def_id, substs); let result = if let Some(trait_def_id) = tcx.trait_of_item(def_id) { debug!(" => associated item, attempting to find impl in param_env {:#?}", param_env); @@ -297,10 +290,12 @@ impl<'b, 'tcx> Instance<'tcx> { result } - pub fn resolve_for_vtable(tcx: TyCtxt<'tcx, 'tcx>, - param_env: ty::ParamEnv<'tcx>, - def_id: DefId, - substs: SubstsRef<'tcx>) -> Option> { + pub fn resolve_for_vtable( + tcx: TyCtxt<'tcx, 'tcx>, + param_env: ty::ParamEnv<'tcx>, + def_id: DefId, + substs: SubstsRef<'tcx>, + ) -> Option> { debug!("resolve(def_id={:?}, substs={:?})", def_id, substs); let fn_sig = tcx.fn_sig(def_id); let is_vtable_shim = @@ -320,9 +315,8 @@ impl<'b, 'tcx> Instance<'tcx> { tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId, substs: ty::ClosureSubsts<'tcx>, - requested_kind: ty::ClosureKind) - -> Instance<'tcx> - { + requested_kind: ty::ClosureKind, + ) -> Instance<'tcx> { let actual_kind = substs.closure_kind(def_id, tcx); match needs_fn_once_adapter_shim(actual_kind, requested_kind) { @@ -331,11 +325,7 @@ impl<'b, 'tcx> Instance<'tcx> { } } - pub fn resolve_drop_in_place( - tcx: TyCtxt<'tcx, 'tcx>, - ty: Ty<'tcx>) - -> ty::Instance<'tcx> - { + pub fn resolve_drop_in_place(tcx: TyCtxt<'tcx, 'tcx>, ty: Ty<'tcx>) -> ty::Instance<'tcx> { let def_id = tcx.require_lang_item(DropInPlaceFnLangItem); let substs = tcx.intern_substs(&[ty.into()]); Instance::resolve(tcx, ty::ParamEnv::reveal_all(), def_id, substs).unwrap() @@ -344,9 +334,8 @@ impl<'b, 'tcx> Instance<'tcx> { pub fn fn_once_adapter_instance( tcx: TyCtxt<'tcx, 'tcx>, closure_did: DefId, - substs: ty::ClosureSubsts<'tcx>) - -> Instance<'tcx> - { + substs: ty::ClosureSubsts<'tcx>, + ) -> Instance<'tcx> { debug!("fn_once_adapter_shim({:?}, {:?})", closure_did, substs); diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs index 65b6f93e251d6..efbae81a5dd52 100644 --- a/src/librustc/ty/layout.rs +++ b/src/librustc/ty/layout.rs @@ -28,17 +28,16 @@ use rustc_target::abi::call::{ ArgAttribute, ArgAttributes, ArgType, Conv, FnType, IgnoreMode, PassMode, Reg, RegKind }; - - pub trait IntegerExt { fn to_ty<'tcx>(&self, tcx: TyCtxt<'tcx, 'tcx>, signed: bool) -> Ty<'tcx>; fn from_attr(cx: &C, ity: attr::IntType) -> Integer; - fn repr_discr<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - ty: Ty<'tcx>, - repr: &ReprOptions, - min: i128, - max: i128) - -> (Integer, bool); + fn repr_discr<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + ty: Ty<'tcx>, + repr: &ReprOptions, + min: i128, + max: i128, + ) -> (Integer, bool); } impl IntegerExt for Integer { @@ -77,12 +76,13 @@ impl IntegerExt for Integer { /// signed discriminant range and #[repr] attribute. /// N.B.: u128 values above i128::MAX will be treated as signed, but /// that shouldn't affect anything, other than maybe debuginfo. - fn repr_discr<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - ty: Ty<'tcx>, - repr: &ReprOptions, - min: i128, - max: i128) - -> (Integer, bool) { + fn repr_discr<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + ty: Ty<'tcx>, + repr: &ReprOptions, + min: i128, + max: i128, + ) -> (Integer, bool) { // Theoretically, negative values could be larger in unsigned representation // than the unsigned representation of the signed minimum. However, if there // are any negative values, the only valid unsigned representation is u128 @@ -171,10 +171,10 @@ impl<'tcx> fmt::Display for LayoutError<'tcx> { } } -fn layout_raw<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) - -> Result<&'tcx LayoutDetails, LayoutError<'tcx>> -{ +fn layout_raw<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>, +) -> Result<&'tcx LayoutDetails, LayoutError<'tcx>> { ty::tls::with_related_context(tcx, move |icx| { let rec_limit = *tcx.sess.recursion_limit.get(); let (param_env, ty) = query.into_parts(); @@ -1604,10 +1604,11 @@ pub enum SizeSkeleton<'tcx> { } impl<'tcx> SizeSkeleton<'tcx> { - pub fn compute(ty: Ty<'tcx>, - tcx: TyCtxt<'tcx, 'tcx>, - param_env: ty::ParamEnv<'tcx>) - -> Result, LayoutError<'tcx>> { + pub fn compute( + ty: Ty<'tcx>, + tcx: TyCtxt<'tcx, 'tcx>, + param_env: ty::ParamEnv<'tcx>, + ) -> Result, LayoutError<'tcx>> { debug_assert!(!ty.has_infer_types()); // First try computing a static layout. diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 76681fe2e8cf4..71955764e100b 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -957,11 +957,11 @@ impl<'gcx, 'tcx> Generics { false } - pub fn region_param(&'tcx self, - param: &EarlyBoundRegion, - tcx: TyCtxt<'gcx, 'tcx>) - -> &'tcx GenericParamDef - { + pub fn region_param( + &'tcx self, + param: &EarlyBoundRegion, + tcx: TyCtxt<'gcx, 'tcx>, + ) -> &'tcx GenericParamDef { if let Some(index) = param.index.checked_sub(self.parent_count as u32) { let param = &self.params[index as usize]; match param.kind { @@ -975,10 +975,11 @@ impl<'gcx, 'tcx> Generics { } /// Returns the `GenericParamDef` associated with this `ParamTy`. - pub fn type_param(&'tcx self, - param: &ParamTy, - tcx: TyCtxt<'gcx, 'tcx>) - -> &'tcx GenericParamDef { + pub fn type_param( + &'tcx self, + param: &ParamTy, + tcx: TyCtxt<'gcx, 'tcx>, + ) -> &'tcx GenericParamDef { if let Some(index) = param.index.checked_sub(self.parent_count as u32) { let param = &self.params[index as usize]; match param.kind { @@ -992,10 +993,11 @@ impl<'gcx, 'tcx> Generics { } /// Returns the `ConstParameterDef` associated with this `ParamConst`. - pub fn const_param(&'tcx self, - param: &ParamConst, - tcx: TyCtxt<'gcx, 'tcx>) - -> &GenericParamDef { + pub fn const_param( + &'tcx self, + param: &ParamConst, + tcx: TyCtxt<'gcx, 'tcx>, + ) -> &GenericParamDef { if let Some(index) = param.index.checked_sub(self.parent_count as u32) { let param = &self.params[index as usize]; match param.kind { @@ -1020,23 +1022,32 @@ impl<'tcx> serialize::UseSpecializedEncodable for GenericPredicates<'tcx> {} impl<'tcx> serialize::UseSpecializedDecodable for GenericPredicates<'tcx> {} impl<'gcx, 'tcx> GenericPredicates<'tcx> { - pub fn instantiate(&self, tcx: TyCtxt<'gcx, 'tcx>, substs: SubstsRef<'tcx>) - -> InstantiatedPredicates<'tcx> { + pub fn instantiate( + &self, + tcx: TyCtxt<'gcx, 'tcx>, + substs: SubstsRef<'tcx>, + ) -> InstantiatedPredicates<'tcx> { let mut instantiated = InstantiatedPredicates::empty(); self.instantiate_into(tcx, &mut instantiated, substs); instantiated } - pub fn instantiate_own(&self, tcx: TyCtxt<'gcx, 'tcx>, substs: SubstsRef<'tcx>) - -> InstantiatedPredicates<'tcx> { + pub fn instantiate_own( + &self, + tcx: TyCtxt<'gcx, 'tcx>, + substs: SubstsRef<'tcx>, + ) -> InstantiatedPredicates<'tcx> { InstantiatedPredicates { predicates: self.predicates.iter().map(|(p, _)| p.subst(tcx, substs)).collect(), } } - fn instantiate_into(&self, tcx: TyCtxt<'gcx, 'tcx>, - instantiated: &mut InstantiatedPredicates<'tcx>, - substs: SubstsRef<'tcx>) { + fn instantiate_into( + &self, + tcx: TyCtxt<'gcx, 'tcx>, + instantiated: &mut InstantiatedPredicates<'tcx>, + substs: SubstsRef<'tcx>, + ) { if let Some(def_id) = self.parent { tcx.predicates_of(def_id).instantiate_into(tcx, instantiated, substs); } @@ -1045,25 +1056,28 @@ impl<'gcx, 'tcx> GenericPredicates<'tcx> { ); } - pub fn instantiate_identity(&self, tcx: TyCtxt<'gcx, 'tcx>) - -> InstantiatedPredicates<'tcx> { + pub fn instantiate_identity(&self, tcx: TyCtxt<'gcx, 'tcx>) -> InstantiatedPredicates<'tcx> { let mut instantiated = InstantiatedPredicates::empty(); self.instantiate_identity_into(tcx, &mut instantiated); instantiated } - fn instantiate_identity_into(&self, tcx: TyCtxt<'gcx, 'tcx>, - instantiated: &mut InstantiatedPredicates<'tcx>) { + fn instantiate_identity_into( + &self, + tcx: TyCtxt<'gcx, 'tcx>, + instantiated: &mut InstantiatedPredicates<'tcx>, + ) { if let Some(def_id) = self.parent { tcx.predicates_of(def_id).instantiate_identity_into(tcx, instantiated); } instantiated.predicates.extend(self.predicates.iter().map(|&(p, _)| p)) } - pub fn instantiate_supertrait(&self, tcx: TyCtxt<'gcx, 'tcx>, - poly_trait_ref: &ty::PolyTraitRef<'tcx>) - -> InstantiatedPredicates<'tcx> - { + pub fn instantiate_supertrait( + &self, + tcx: TyCtxt<'gcx, 'tcx>, + poly_trait_ref: &ty::PolyTraitRef<'tcx>, + ) -> InstantiatedPredicates<'tcx> { assert_eq!(self.parent, None); InstantiatedPredicates { predicates: self.predicates.iter().map(|(pred, _)| { @@ -1134,10 +1148,11 @@ impl<'gcx, 'tcx> Predicate<'tcx> { /// poly-trait-ref holds. This is slightly different from a normal /// substitution in terms of what happens with bound regions. See /// lengthy comment below for details. - pub fn subst_supertrait(&self, tcx: TyCtxt<'gcx, 'tcx>, - trait_ref: &ty::PolyTraitRef<'tcx>) - -> ty::Predicate<'tcx> - { + pub fn subst_supertrait( + &self, + tcx: TyCtxt<'gcx, 'tcx>, + trait_ref: &ty::PolyTraitRef<'tcx>, + ) -> ty::Predicate<'tcx> { // The interaction between HRTB and supertraits is not entirely // obvious. Let me walk you (and myself) through an example. // @@ -2140,7 +2155,6 @@ impl ReprOptions { pub fn inhibit_union_abi_opt(&self) -> bool { self.c() } - } impl<'gcx, 'tcx> AdtDef { @@ -2150,7 +2164,7 @@ impl<'gcx, 'tcx> AdtDef { did: DefId, kind: AdtKind, variants: IndexVec, - repr: ReprOptions + repr: ReprOptions, ) -> Self { debug!("AdtDef::new({:?}, {:?}, {:?}, {:?})", did, kind, variants, repr); let mut flags = AdtFlags::NO_ADT_FLAGS; @@ -2427,10 +2441,11 @@ impl<'gcx, 'tcx> AdtDef { /// discriminant (the last one before the requested variant), /// assuming there are no constant-evaluation errors there. #[inline] - pub fn discriminant_for_variant(&self, - tcx: TyCtxt<'gcx, 'tcx>, - variant_index: VariantIdx) - -> Discr<'tcx> { + pub fn discriminant_for_variant( + &self, + tcx: TyCtxt<'gcx, 'tcx>, + variant_index: VariantIdx, + ) -> Discr<'tcx> { let (val, offset) = self.discriminant_def_for_variant(variant_index); let explicit_value = val .and_then(|expr_did| self.eval_explicit_discr(tcx, expr_did)) @@ -2483,10 +2498,7 @@ impl<'gcx, 'tcx> AdtDef { tcx.adt_sized_constraint(self.did).0 } - fn sized_constraint_for_ty(&self, - tcx: TyCtxt<'tcx, 'tcx>, - ty: Ty<'tcx>) - -> Vec> { + fn sized_constraint_for_ty(&self, tcx: TyCtxt<'tcx, 'tcx>, ty: Ty<'tcx>) -> Vec> { let result = match ty.sty { Bool | Char | Int(..) | Uint(..) | Float(..) | RawPtr(..) | Ref(..) | FnDef(..) | FnPtr(_) | @@ -2763,9 +2775,7 @@ impl<'gcx, 'tcx> TyCtxt<'gcx, 'tcx> { /// Returns an iterator of the `DefId`s for all body-owners in this /// crate. If you would prefer to iterate over the bodies /// themselves, you can do `self.hir().krate().body_ids.iter()`. - pub fn body_owners( - self, - ) -> impl Iterator + Captures<'gcx> + 'tcx { + pub fn body_owners(self) -> impl Iterator + Captures<'gcx> + 'tcx { self.hir().krate() .body_ids .iter() @@ -2889,10 +2899,7 @@ impl<'gcx, 'tcx> TyCtxt<'gcx, 'tcx> { }) } - pub fn associated_items( - self, - def_id: DefId, - ) -> AssocItemsIterator<'gcx, 'tcx> { + pub fn associated_items(self, def_id: DefId) -> AssocItemsIterator<'gcx, 'tcx> { // Ideally, we would use `-> impl Iterator` here, but it falls // afoul of the conservative "capture [restrictions]" we put // in place, so we use a hand-written iterator. @@ -3176,9 +3183,7 @@ pub struct AdtSizedConstraint<'tcx>(pub &'tcx [Ty<'tcx>]); /// such. /// - a Error, if a type contained itself. The representability /// check should catch this case. -fn adt_sized_constraint<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - def_id: DefId) - -> AdtSizedConstraint<'tcx> { +fn adt_sized_constraint<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> AdtSizedConstraint<'tcx> { let def = tcx.adt_def(def_id); let result = tcx.mk_type_list(def.variants.iter().flat_map(|v| { @@ -3192,9 +3197,7 @@ fn adt_sized_constraint<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, AdtSizedConstraint(result) } -fn associated_item_def_ids<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - def_id: DefId) - -> &'tcx [DefId] { +fn associated_item_def_ids<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> &'tcx [DefId] { let id = tcx.hir().as_local_hir_id(def_id).unwrap(); let item = tcx.hir().expect_item_by_hir_id(id); match item.node { @@ -3247,10 +3250,7 @@ pub fn is_impl_trait_defn(tcx: TyCtxt<'_, '_>, def_id: DefId) -> Option { } /// See `ParamEnv` struct definition for details. -fn param_env<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - def_id: DefId) - -> ParamEnv<'tcx> -{ +fn param_env<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> ParamEnv<'tcx> { // The param_env of an impl Trait type is its defining function's param_env if let Some(parent) = is_impl_trait_defn(tcx, def_id) { return param_env(tcx, parent); @@ -3285,28 +3285,25 @@ fn param_env<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, traits::normalize_param_env_or_error(tcx, def_id, unnormalized_env, cause) } -fn crate_disambiguator<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - crate_num: CrateNum) -> CrateDisambiguator { +fn crate_disambiguator<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, crate_num: CrateNum) -> CrateDisambiguator { assert_eq!(crate_num, LOCAL_CRATE); tcx.sess.local_crate_disambiguator() } -fn original_crate_name<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - crate_num: CrateNum) -> Symbol { +fn original_crate_name<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, crate_num: CrateNum) -> Symbol { assert_eq!(crate_num, LOCAL_CRATE); tcx.crate_name.clone() } -fn crate_hash<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - crate_num: CrateNum) - -> Svh { +fn crate_hash<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, crate_num: CrateNum) -> Svh { assert_eq!(crate_num, LOCAL_CRATE); tcx.hir().crate_hash } -fn instance_def_size_estimate<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - instance_def: InstanceDef<'tcx>) - -> usize { +fn instance_def_size_estimate<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + instance_def: InstanceDef<'tcx>, +) -> usize { match instance_def { InstanceDef::Item(..) | InstanceDef::DropGlue(..) => { @@ -3321,10 +3318,7 @@ fn instance_def_size_estimate<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, /// If `def_id` is an issue 33140 hack impl, returns its self type; otherwise, returns `None`. /// /// See [`ImplOverlapKind::Issue33140`] for more details. -fn issue33140_self_ty<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - def_id: DefId) - -> Option> -{ +fn issue33140_self_ty<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> Option> { debug!("issue33140_self_ty({:?})", def_id); let trait_ref = tcx.impl_trait_ref(def_id).unwrap_or_else(|| { diff --git a/src/librustc/ty/query/config.rs b/src/librustc/ty/query/config.rs index c595d37989cb1..bd5f33eea7bc5 100644 --- a/src/librustc/ty/query/config.rs +++ b/src/librustc/ty/query/config.rs @@ -54,14 +54,12 @@ pub(crate) trait QueryDescription<'tcx>: QueryAccessors<'tcx> { false } - fn try_load_from_disk(_: TyCtxt<'tcx, 'tcx>, - _: SerializedDepNodeIndex) - -> Option { + fn try_load_from_disk(_: TyCtxt<'tcx, 'tcx>, _: SerializedDepNodeIndex) -> Option { bug!("QueryDescription::load_from_disk() called for an unsupported query.") } } -impl<'tcx, M: QueryAccessors<'tcx, Key=DefId>> QueryDescription<'tcx> for M { +impl<'tcx, M: QueryAccessors<'tcx, Key = DefId>> QueryDescription<'tcx> for M { default fn describe(tcx: TyCtxt<'_, '_>, def_id: DefId) -> Cow<'static, str> { if !tcx.sess.verbose() { format!("processing `{}`", tcx.def_path_str(def_id)).into() diff --git a/src/librustc/ty/query/job.rs b/src/librustc/ty/query/job.rs index f8fc2c1012586..f300d82e372e9 100644 --- a/src/librustc/ty/query/job.rs +++ b/src/librustc/ty/query/job.rs @@ -340,7 +340,7 @@ fn connected_to_root<'tcx>( fn pick_query<'a, 'tcx, T, F: Fn(&T) -> (Span, Lrc>)>( tcx: TyCtxt<'tcx, '_>, queries: &'a [T], - f: F + f: F, ) -> &'a T { // Deterministically pick an entry point // FIXME: Sort this instead @@ -366,7 +366,7 @@ fn pick_query<'a, 'tcx, T, F: Fn(&T) -> (Span, Lrc>)>( fn remove_cycle<'tcx>( jobs: &mut Vec>>, wakelist: &mut Vec>>, - tcx: TyCtxt<'tcx, '_> + tcx: TyCtxt<'tcx, '_>, ) -> bool { let mut visited = FxHashSet::default(); let mut stack = Vec::new(); diff --git a/src/librustc/ty/query/keys.rs b/src/librustc/ty/query/keys.rs index 96a98b45f1f69..af13bbc24efd9 100644 --- a/src/librustc/ty/query/keys.rs +++ b/src/librustc/ty/query/keys.rs @@ -136,7 +136,7 @@ impl<'tcx> Key for (&'tcx ty::Const<'tcx>, mir::Field) { } } -impl<'tcx> Key for ty::PolyTraitRef<'tcx>{ +impl<'tcx> Key for ty::PolyTraitRef<'tcx> { fn query_crate(&self) -> CrateNum { self.def_id().krate } diff --git a/src/librustc/ty/query/on_disk_cache.rs b/src/librustc/ty/query/on_disk_cache.rs index 71ea4ac772c31..bc28396a6f9f8 100644 --- a/src/librustc/ty/query/on_disk_cache.rs +++ b/src/librustc/ty/query/on_disk_cache.rs @@ -156,12 +156,14 @@ impl<'sess> OnDiskCache<'sess> { } } - pub fn serialize<'tcx, E>(&self, - tcx: TyCtxt<'tcx, 'tcx>, - encoder: &mut E) - -> Result<(), E::Error> - where E: ty_codec::TyEncoder - { + pub fn serialize<'tcx, E>( + &self, + tcx: TyCtxt<'tcx, 'tcx>, + encoder: &mut E, + ) -> Result<(), E::Error> + where + E: ty_codec::TyEncoder, + { // Serializing the DepGraph should not modify it: tcx.dep_graph.with_ignore(|| { // Allocate SourceFileIndices @@ -326,10 +328,11 @@ impl<'sess> OnDiskCache<'sess> { } /// Loads a diagnostic emitted during the previous compilation session. - pub fn load_diagnostics<'tcx>(&self, - tcx: TyCtxt<'tcx, 'tcx>, - dep_node_index: SerializedDepNodeIndex) - -> Vec { + pub fn load_diagnostics<'tcx>( + &self, + tcx: TyCtxt<'tcx, 'tcx>, + dep_node_index: SerializedDepNodeIndex, + ) -> Vec { let diagnostics: Option = self.load_indexed( tcx, dep_node_index, @@ -354,11 +357,13 @@ impl<'sess> OnDiskCache<'sess> { /// Returns the cached query result if there is something in the cache for /// the given `SerializedDepNodeIndex`; otherwise returns `None`. - pub fn try_load_query_result<'tcx, T>(&self, - tcx: TyCtxt<'tcx, 'tcx>, - dep_node_index: SerializedDepNodeIndex) - -> Option - where T: Decodable + pub fn try_load_query_result<'tcx, T>( + &self, + tcx: TyCtxt<'tcx, 'tcx>, + dep_node_index: SerializedDepNodeIndex, + ) -> Option + where + T: Decodable, { self.load_indexed(tcx, dep_node_index, @@ -382,14 +387,15 @@ impl<'sess> OnDiskCache<'sess> { x.extend(Into::>::into(diagnostics)); } - fn load_indexed<'tcx, T>(&self, - tcx: TyCtxt<'tcx, 'tcx>, - dep_node_index: SerializedDepNodeIndex, - index: &FxHashMap, - debug_tag: &'static str) - -> Option - where T: Decodable + fn load_indexed<'tcx, T>( + &self, + tcx: TyCtxt<'tcx, 'tcx>, + dep_node_index: SerializedDepNodeIndex, + index: &FxHashMap, + debug_tag: &'static str, + ) -> Option + where + T: Decodable, { let pos = index.get(&dep_node_index).cloned()?; @@ -423,10 +429,10 @@ impl<'sess> OnDiskCache<'sess> { // current-session-CrateNum. There might be CrateNums from the previous // Session that don't occur in the current one. For these, the mapping // maps to None. - fn compute_cnum_map(tcx: TyCtxt<'_, '_>, - prev_cnums: &[(u32, String, CrateDisambiguator)]) - -> IndexVec> - { + fn compute_cnum_map( + tcx: TyCtxt<'_, '_>, + prev_cnums: &[(u32, String, CrateDisambiguator)], + ) -> IndexVec> { tcx.dep_graph.with_ignore(|| { let current_cnums = tcx.all_crate_nums(LOCAL_CRATE).iter().map(|&cnum| { let crate_name = tcx.original_crate_name(cnum) @@ -524,7 +530,6 @@ fn decode_tagged<'a, 'tcx, D, T, V>(decoder: &mut D, Ok(value) } - impl<'a, 'tcx> ty_codec::TyDecoder<'tcx> for CacheDecoder<'a, 'tcx> { #[inline] fn tcx(&self) -> TyCtxt<'tcx, 'tcx> { @@ -583,7 +588,7 @@ impl<'a, 'tcx> ty_codec::TyDecoder<'tcx> for CacheDecoder<'a, 'tcx> { } } -implement_ty_decoder!( CacheDecoder<'a, 'tcx> ); +implement_ty_decoder!(CacheDecoder<'a, 'tcx>); impl<'a, 'tcx> SpecializedDecoder for CacheDecoder<'a, 'tcx> { fn specialized_decode(&mut self) -> Result { @@ -724,7 +729,8 @@ impl<'a, 'tcx> SpecializedDecoder for CacheDecoder<'a, 'tcx> { } impl<'a, 'tcx, T: Decodable> SpecializedDecoder> -for CacheDecoder<'a, 'tcx> { + for CacheDecoder<'a, 'tcx> +{ #[inline] fn specialized_decode(&mut self) -> Result, Self::Error> { let discr = u8::decode(self)?; @@ -757,7 +763,8 @@ struct CacheEncoder<'a, 'tcx, E: ty_codec::TyEncoder> { } impl<'a, 'tcx, E> CacheEncoder<'a, 'tcx, E> - where E: 'a + ty_codec::TyEncoder +where + E: 'a + ty_codec::TyEncoder, { fn source_file_index(&mut self, source_file: Lrc) -> SourceFileIndex { self.file_to_file_index[&(&*source_file as *const SourceFile)] @@ -784,7 +791,8 @@ impl<'a, 'tcx, E> CacheEncoder<'a, 'tcx, E> } impl<'a, 'tcx, E> SpecializedEncoder for CacheEncoder<'a, 'tcx, E> - where E: 'a + ty_codec::TyEncoder +where + E: 'a + ty_codec::TyEncoder, { fn specialized_encode(&mut self, alloc_id: &interpret::AllocId) -> Result<(), Self::Error> { use std::collections::hash_map::Entry; @@ -803,7 +811,8 @@ impl<'a, 'tcx, E> SpecializedEncoder for CacheEncoder<'a, 't } impl<'a, 'tcx, E> SpecializedEncoder for CacheEncoder<'a, 'tcx, E> - where E: 'a + ty_codec::TyEncoder +where + E: 'a + ty_codec::TyEncoder, { fn specialized_encode(&mut self, span: &Span) -> Result<(), Self::Error> { @@ -859,7 +868,8 @@ impl<'a, 'tcx, E> SpecializedEncoder for CacheEncoder<'a, 'tcx, E> } impl<'a, 'tcx, E> ty_codec::TyEncoder for CacheEncoder<'a, 'tcx, E> - where E: 'a + ty_codec::TyEncoder +where + E: 'a + ty_codec::TyEncoder, { #[inline] fn position(&self) -> usize { @@ -868,7 +878,8 @@ impl<'a, 'tcx, E> ty_codec::TyEncoder for CacheEncoder<'a, 'tcx, E> } impl<'a, 'tcx, E> SpecializedEncoder for CacheEncoder<'a, 'tcx, E> - where E: 'a + ty_codec::TyEncoder +where + E: 'a + ty_codec::TyEncoder, { #[inline] fn specialized_encode(&mut self, cnum: &CrateNum) -> Result<(), Self::Error> { @@ -877,7 +888,8 @@ impl<'a, 'tcx, E> SpecializedEncoder for CacheEncoder<'a, 'tcx, E> } impl<'a, 'tcx, E> SpecializedEncoder> for CacheEncoder<'a, 'tcx, E> - where E: 'a + ty_codec::TyEncoder +where + E: 'a + ty_codec::TyEncoder, { #[inline] fn specialized_encode(&mut self, ty: &Ty<'tcx>) -> Result<(), Self::Error> { @@ -886,9 +898,9 @@ impl<'a, 'tcx, E> SpecializedEncoder> for CacheEncoder<'a, 'tcx, E> } } -impl<'a, 'tcx, E> SpecializedEncoder> - for CacheEncoder<'a, 'tcx, E> - where E: 'a + ty_codec::TyEncoder +impl<'a, 'tcx, E> SpecializedEncoder> for CacheEncoder<'a, 'tcx, E> +where + E: 'a + ty_codec::TyEncoder, { #[inline] fn specialized_encode(&mut self, @@ -900,7 +912,8 @@ impl<'a, 'tcx, E> SpecializedEncoder> } impl<'a, 'tcx, E> SpecializedEncoder for CacheEncoder<'a, 'tcx, E> - where E: 'a + ty_codec::TyEncoder +where + E: 'a + ty_codec::TyEncoder, { #[inline] fn specialized_encode(&mut self, id: &hir::HirId) -> Result<(), Self::Error> { @@ -916,9 +929,9 @@ impl<'a, 'tcx, E> SpecializedEncoder for CacheEncoder<'a, 'tcx, E> } } - impl<'a, 'tcx, E> SpecializedEncoder for CacheEncoder<'a, 'tcx, E> - where E: 'a + ty_codec::TyEncoder +where + E: 'a + ty_codec::TyEncoder, { #[inline] fn specialized_encode(&mut self, id: &DefId) -> Result<(), Self::Error> { @@ -928,7 +941,8 @@ impl<'a, 'tcx, E> SpecializedEncoder for CacheEncoder<'a, 'tcx, E> } impl<'a, 'tcx, E> SpecializedEncoder for CacheEncoder<'a, 'tcx, E> - where E: 'a + ty_codec::TyEncoder +where + E: 'a + ty_codec::TyEncoder, { #[inline] fn specialized_encode(&mut self, id: &LocalDefId) -> Result<(), Self::Error> { @@ -937,7 +951,8 @@ impl<'a, 'tcx, E> SpecializedEncoder for CacheEncoder<'a, 'tcx, E> } impl<'a, 'tcx, E> SpecializedEncoder for CacheEncoder<'a, 'tcx, E> - where E: 'a + ty_codec::TyEncoder +where + E: 'a + ty_codec::TyEncoder, { fn specialized_encode(&mut self, _: &DefIndex) -> Result<(), Self::Error> { bug!("Encoding DefIndex without context.") @@ -947,7 +962,8 @@ impl<'a, 'tcx, E> SpecializedEncoder for CacheEncoder<'a, 'tcx, E> // NodeIds are not stable across compilation sessions, so we store them in their // HirId representation. This allows use to map them to the current NodeId. impl<'a, 'tcx, E> SpecializedEncoder for CacheEncoder<'a, 'tcx, E> - where E: 'a + ty_codec::TyEncoder +where + E: 'a + ty_codec::TyEncoder, { #[inline] fn specialized_encode(&mut self, node_id: &NodeId) -> Result<(), Self::Error> { @@ -956,18 +972,16 @@ impl<'a, 'tcx, E> SpecializedEncoder for CacheEncoder<'a, 'tcx, E> } } -impl<'a, 'tcx> SpecializedEncoder -for CacheEncoder<'a, 'tcx, opaque::Encoder> -{ +impl<'a, 'tcx> SpecializedEncoder for CacheEncoder<'a, 'tcx, opaque::Encoder> { fn specialized_encode(&mut self, f: &Fingerprint) -> Result<(), Self::Error> { f.encode_opaque(&mut self.encoder) } } -impl<'a, 'tcx, E, T> SpecializedEncoder> -for CacheEncoder<'a, 'tcx, E> - where E: 'a + ty_codec::TyEncoder, - T: Encodable, +impl<'a, 'tcx, E, T> SpecializedEncoder> for CacheEncoder<'a, 'tcx, E> +where + E: 'a + ty_codec::TyEncoder, + T: Encodable, { #[inline] fn specialized_encode(&mut self, @@ -994,7 +1008,8 @@ macro_rules! encoder_methods { } impl<'a, 'tcx, E> Encoder for CacheEncoder<'a, 'tcx, E> - where E: 'a + ty_codec::TyEncoder +where + E: 'a + ty_codec::TyEncoder, { type Error = E::Error; @@ -1064,13 +1079,15 @@ impl<'a> SpecializedDecoder for opaque::Decoder<'a> { } } -fn encode_query_results<'a, 'tcx, Q, E>(tcx: TyCtxt<'tcx, 'tcx>, - encoder: &mut CacheEncoder<'a, 'tcx, E>, - query_result_index: &mut EncodedQueryResultIndex) - -> Result<(), E::Error> - where Q: super::config::QueryDescription<'tcx>, - E: 'a + TyEncoder, - Q::Value: Encodable, +fn encode_query_results<'a, 'tcx, Q, E>( + tcx: TyCtxt<'tcx, 'tcx>, + encoder: &mut CacheEncoder<'a, 'tcx, E>, + query_result_index: &mut EncodedQueryResultIndex, +) -> Result<(), E::Error> +where + Q: super::config::QueryDescription<'tcx>, + E: 'a + TyEncoder, + Q::Value: Encodable, { let desc = &format!("encode_query_results for {}", unsafe { ::std::intrinsics::type_name::() }); diff --git a/src/librustc/ty/query/plumbing.rs b/src/librustc/ty/query/plumbing.rs index 639aa8e2c34b8..662d653b2a173 100644 --- a/src/librustc/ty/query/plumbing.rs +++ b/src/librustc/ty/query/plumbing.rs @@ -256,10 +256,10 @@ impl<'gcx, 'tcx> TyCtxt<'gcx, 'tcx> { self, job: Lrc>, diagnostics: Option<&Lock>>, - compute: F) - -> R + compute: F, + ) -> R where - F: for<'lcx> FnOnce(TyCtxt<'gcx, 'lcx>) -> R + F: for<'lcx> FnOnce(TyCtxt<'gcx, 'lcx>) -> R, { // The TyCtxt stored in TLS has the same global interner lifetime // as `self`, so we use `with_related_context` to relate the 'gcx lifetimes @@ -285,9 +285,8 @@ impl<'gcx, 'tcx> TyCtxt<'gcx, 'tcx> { #[cold] pub(super) fn report_cycle( self, - CycleError { usage, cycle: stack }: CycleError<'gcx> - ) -> DiagnosticBuilder<'tcx> - { + CycleError { usage, cycle: stack }: CycleError<'gcx>, + ) -> DiagnosticBuilder<'tcx> { assert!(!stack.is_empty()); let fix_span = |span: Span, query: &Query<'gcx>| { @@ -1148,10 +1147,7 @@ macro_rules! define_provider_struct { /// then `force_from_dep_node()` should not fail for it. Otherwise, you can just /// add it to the "We don't have enough information to reconstruct..." group in /// the match below. -pub fn force_from_dep_node<'tcx>( - tcx: TyCtxt<'tcx, 'tcx>, - dep_node: &DepNode -) -> bool { +pub fn force_from_dep_node<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, dep_node: &DepNode) -> bool { use crate::dep_graph::RecoverKey; // We must avoid ever having to call force_from_dep_node() for a diff --git a/src/librustc/ty/relate.rs b/src/librustc/ty/relate.rs index 247f3fea89d15..2bd38ff70d4c5 100644 --- a/src/librustc/ty/relate.rs +++ b/src/librustc/ty/relate.rs @@ -22,7 +22,7 @@ pub enum Cause { ExistentialRegionBound, // relating an existential region bound } -pub trait TypeRelation<'gcx: 'tcx, 'tcx> : Sized { +pub trait TypeRelation<'gcx: 'tcx, 'tcx>: Sized { fn tcx(&self) -> TyCtxt<'gcx, 'tcx>; /// Returns a static string we can use for printouts. @@ -94,20 +94,26 @@ pub trait TypeRelation<'gcx: 'tcx, 'tcx> : Sized { } pub trait Relate<'tcx>: TypeFoldable<'tcx> { - fn relate<'a, 'gcx, R>(relation: &mut R, a: &Self, b: &Self) - -> RelateResult<'tcx, Self> - where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a; + fn relate<'a, 'gcx, R>(relation: &mut R, a: &Self, b: &Self) -> RelateResult<'tcx, Self> + where + R: TypeRelation<'gcx, 'tcx>, + 'gcx: 'a + 'tcx, + 'tcx: 'a; } /////////////////////////////////////////////////////////////////////////// // Relate impls impl<'tcx> Relate<'tcx> for ty::TypeAndMut<'tcx> { - fn relate<'a, 'gcx, R>(relation: &mut R, - a: &ty::TypeAndMut<'tcx>, - b: &ty::TypeAndMut<'tcx>) - -> RelateResult<'tcx, ty::TypeAndMut<'tcx>> - where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a + fn relate<'a, 'gcx, R>( + relation: &mut R, + a: &ty::TypeAndMut<'tcx>, + b: &ty::TypeAndMut<'tcx>, + ) -> RelateResult<'tcx, ty::TypeAndMut<'tcx>> + where + R: TypeRelation<'gcx, 'tcx>, + 'gcx: 'a + 'tcx, + 'tcx: 'a, { debug!("{}.mts({:?}, {:?})", relation.tag(), @@ -127,12 +133,16 @@ impl<'tcx> Relate<'tcx> for ty::TypeAndMut<'tcx> { } } -pub fn relate_substs<'a, 'gcx, 'tcx, R>(relation: &mut R, - variances: Option<&[ty::Variance]>, - a_subst: SubstsRef<'tcx>, - b_subst: SubstsRef<'tcx>) - -> RelateResult<'tcx, SubstsRef<'tcx>> - where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a +pub fn relate_substs<'a, 'gcx, 'tcx, R>( + relation: &mut R, + variances: Option<&[ty::Variance]>, + a_subst: SubstsRef<'tcx>, + b_subst: SubstsRef<'tcx>, +) -> RelateResult<'tcx, SubstsRef<'tcx>> +where + R: TypeRelation<'gcx, 'tcx>, + 'gcx: 'a + 'tcx, + 'tcx: 'a, { let tcx = relation.tcx(); @@ -145,11 +155,15 @@ pub fn relate_substs<'a, 'gcx, 'tcx, R>(relation: &mut R, } impl<'tcx> Relate<'tcx> for ty::FnSig<'tcx> { - fn relate<'a, 'gcx, R>(relation: &mut R, - a: &ty::FnSig<'tcx>, - b: &ty::FnSig<'tcx>) - -> RelateResult<'tcx, ty::FnSig<'tcx>> - where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a + fn relate<'a, 'gcx, R>( + relation: &mut R, + a: &ty::FnSig<'tcx>, + b: &ty::FnSig<'tcx>, + ) -> RelateResult<'tcx, ty::FnSig<'tcx>> + where + R: TypeRelation<'gcx, 'tcx>, + 'gcx: 'a + 'tcx, + 'tcx: 'a, { let tcx = relation.tcx(); @@ -185,11 +199,15 @@ impl<'tcx> Relate<'tcx> for ty::FnSig<'tcx> { } impl<'tcx> Relate<'tcx> for ast::Unsafety { - fn relate<'a, 'gcx, R>(relation: &mut R, - a: &ast::Unsafety, - b: &ast::Unsafety) - -> RelateResult<'tcx, ast::Unsafety> - where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a + fn relate<'a, 'gcx, R>( + relation: &mut R, + a: &ast::Unsafety, + b: &ast::Unsafety, + ) -> RelateResult<'tcx, ast::Unsafety> + where + R: TypeRelation<'gcx, 'tcx>, + 'gcx: 'a + 'tcx, + 'tcx: 'a, { if a != b { Err(TypeError::UnsafetyMismatch(expected_found(relation, a, b))) @@ -200,11 +218,15 @@ impl<'tcx> Relate<'tcx> for ast::Unsafety { } impl<'tcx> Relate<'tcx> for abi::Abi { - fn relate<'a, 'gcx, R>(relation: &mut R, - a: &abi::Abi, - b: &abi::Abi) - -> RelateResult<'tcx, abi::Abi> - where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a + fn relate<'a, 'gcx, R>( + relation: &mut R, + a: &abi::Abi, + b: &abi::Abi, + ) -> RelateResult<'tcx, abi::Abi> + where + R: TypeRelation<'gcx, 'tcx>, + 'gcx: 'a + 'tcx, + 'tcx: 'a, { if a == b { Ok(*a) @@ -215,11 +237,15 @@ impl<'tcx> Relate<'tcx> for abi::Abi { } impl<'tcx> Relate<'tcx> for ty::ProjectionTy<'tcx> { - fn relate<'a, 'gcx, R>(relation: &mut R, - a: &ty::ProjectionTy<'tcx>, - b: &ty::ProjectionTy<'tcx>) - -> RelateResult<'tcx, ty::ProjectionTy<'tcx>> - where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a + fn relate<'a, 'gcx, R>( + relation: &mut R, + a: &ty::ProjectionTy<'tcx>, + b: &ty::ProjectionTy<'tcx>, + ) -> RelateResult<'tcx, ty::ProjectionTy<'tcx>> + where + R: TypeRelation<'gcx, 'tcx>, + 'gcx: 'a + 'tcx, + 'tcx: 'a, { if a.item_def_id != b.item_def_id { Err(TypeError::ProjectionMismatched( @@ -235,11 +261,15 @@ impl<'tcx> Relate<'tcx> for ty::ProjectionTy<'tcx> { } impl<'tcx> Relate<'tcx> for ty::ExistentialProjection<'tcx> { - fn relate<'a, 'gcx, R>(relation: &mut R, - a: &ty::ExistentialProjection<'tcx>, - b: &ty::ExistentialProjection<'tcx>) - -> RelateResult<'tcx, ty::ExistentialProjection<'tcx>> - where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a + fn relate<'a, 'gcx, R>( + relation: &mut R, + a: &ty::ExistentialProjection<'tcx>, + b: &ty::ExistentialProjection<'tcx>, + ) -> RelateResult<'tcx, ty::ExistentialProjection<'tcx>> + where + R: TypeRelation<'gcx, 'tcx>, + 'gcx: 'a + 'tcx, + 'tcx: 'a, { if a.item_def_id != b.item_def_id { Err(TypeError::ProjectionMismatched( @@ -257,11 +287,15 @@ impl<'tcx> Relate<'tcx> for ty::ExistentialProjection<'tcx> { } impl<'tcx> Relate<'tcx> for Vec> { - fn relate<'a, 'gcx, R>(relation: &mut R, - a: &Vec>, - b: &Vec>) - -> RelateResult<'tcx, Vec>> - where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a + fn relate<'a, 'gcx, R>( + relation: &mut R, + a: &Vec>, + b: &Vec>, + ) -> RelateResult<'tcx, Vec>> + where + R: TypeRelation<'gcx, 'tcx>, + 'gcx: 'a + 'tcx, + 'tcx: 'a, { // To be compatible, `a` and `b` must be for precisely the // same set of traits and item names. We always require that @@ -280,11 +314,15 @@ impl<'tcx> Relate<'tcx> for Vec> { } impl<'tcx> Relate<'tcx> for ty::TraitRef<'tcx> { - fn relate<'a, 'gcx, R>(relation: &mut R, - a: &ty::TraitRef<'tcx>, - b: &ty::TraitRef<'tcx>) - -> RelateResult<'tcx, ty::TraitRef<'tcx>> - where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a + fn relate<'a, 'gcx, R>( + relation: &mut R, + a: &ty::TraitRef<'tcx>, + b: &ty::TraitRef<'tcx>, + ) -> RelateResult<'tcx, ty::TraitRef<'tcx>> + where + R: TypeRelation<'gcx, 'tcx>, + 'gcx: 'a + 'tcx, + 'tcx: 'a, { // Different traits cannot be related if a.def_id != b.def_id { @@ -297,11 +335,15 @@ impl<'tcx> Relate<'tcx> for ty::TraitRef<'tcx> { } impl<'tcx> Relate<'tcx> for ty::ExistentialTraitRef<'tcx> { - fn relate<'a, 'gcx, R>(relation: &mut R, - a: &ty::ExistentialTraitRef<'tcx>, - b: &ty::ExistentialTraitRef<'tcx>) - -> RelateResult<'tcx, ty::ExistentialTraitRef<'tcx>> - where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a + fn relate<'a, 'gcx, R>( + relation: &mut R, + a: &ty::ExistentialTraitRef<'tcx>, + b: &ty::ExistentialTraitRef<'tcx>, + ) -> RelateResult<'tcx, ty::ExistentialTraitRef<'tcx>> + where + R: TypeRelation<'gcx, 'tcx>, + 'gcx: 'a + 'tcx, + 'tcx: 'a, { // Different traits cannot be related if a.def_id != b.def_id { @@ -323,11 +365,15 @@ TupleStructTypeFoldableImpl! { } impl<'tcx> Relate<'tcx> for GeneratorWitness<'tcx> { - fn relate<'a, 'gcx, R>(relation: &mut R, - a: &GeneratorWitness<'tcx>, - b: &GeneratorWitness<'tcx>) - -> RelateResult<'tcx, GeneratorWitness<'tcx>> - where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a + fn relate<'a, 'gcx, R>( + relation: &mut R, + a: &GeneratorWitness<'tcx>, + b: &GeneratorWitness<'tcx>, + ) -> RelateResult<'tcx, GeneratorWitness<'tcx>> + where + R: TypeRelation<'gcx, 'tcx>, + 'gcx: 'a + 'tcx, + 'tcx: 'a, { assert_eq!(a.0.len(), b.0.len()); let tcx = relation.tcx(); @@ -337,11 +383,15 @@ impl<'tcx> Relate<'tcx> for GeneratorWitness<'tcx> { } impl<'tcx> Relate<'tcx> for Ty<'tcx> { - fn relate<'a, 'gcx, R>(relation: &mut R, - a: &Ty<'tcx>, - b: &Ty<'tcx>) - -> RelateResult<'tcx, Ty<'tcx>> - where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a + fn relate<'a, 'gcx, R>( + relation: &mut R, + a: &Ty<'tcx>, + b: &Ty<'tcx>, + ) -> RelateResult<'tcx, Ty<'tcx>> + where + R: TypeRelation<'gcx, 'tcx>, + 'gcx: 'a + 'tcx, + 'tcx: 'a, { relation.tys(a, b) } @@ -350,11 +400,15 @@ impl<'tcx> Relate<'tcx> for Ty<'tcx> { /// The main "type relation" routine. Note that this does not handle /// inference artifacts, so you should filter those out before calling /// it. -pub fn super_relate_tys<'a, 'gcx, 'tcx, R>(relation: &mut R, - a: Ty<'tcx>, - b: Ty<'tcx>) - -> RelateResult<'tcx, Ty<'tcx>> - where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a +pub fn super_relate_tys<'a, 'gcx, 'tcx, R>( + relation: &mut R, + a: Ty<'tcx>, + b: Ty<'tcx>, +) -> RelateResult<'tcx, Ty<'tcx>> +where + R: TypeRelation<'gcx, 'tcx>, + 'gcx: 'a + 'tcx, + 'tcx: 'a, { let tcx = relation.tcx(); debug!("super_relate_tys: a={:?} b={:?}", a, b); @@ -553,10 +607,12 @@ pub fn super_relate_tys<'a, 'gcx, 'tcx, R>(relation: &mut R, pub fn super_relate_consts<'a, 'gcx, 'tcx, R>( relation: &mut R, a: &'tcx ty::Const<'tcx>, - b: &'tcx ty::Const<'tcx> + b: &'tcx ty::Const<'tcx>, ) -> RelateResult<'tcx, &'tcx ty::Const<'tcx>> where - R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a + R: TypeRelation<'gcx, 'tcx>, + 'gcx: 'a + 'tcx, + 'tcx: 'a, { let tcx = relation.tcx(); @@ -632,12 +688,12 @@ where } impl<'tcx> Relate<'tcx> for &'tcx ty::List> { - fn relate<'a, 'gcx, R>(relation: &mut R, - a: &Self, - b: &Self) - -> RelateResult<'tcx, Self> - where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a { - + fn relate<'a, 'gcx, R>(relation: &mut R, a: &Self, b: &Self) -> RelateResult<'tcx, Self> + where + R: TypeRelation<'gcx, 'tcx>, + 'gcx: 'a + 'tcx, + 'tcx: 'a, + { if a.len() != b.len() { return Err(TypeError::ExistentialMismatch(expected_found(relation, a, b))); } @@ -657,11 +713,15 @@ impl<'tcx> Relate<'tcx> for &'tcx ty::List> { } impl<'tcx> Relate<'tcx> for ty::ClosureSubsts<'tcx> { - fn relate<'a, 'gcx, R>(relation: &mut R, - a: &ty::ClosureSubsts<'tcx>, - b: &ty::ClosureSubsts<'tcx>) - -> RelateResult<'tcx, ty::ClosureSubsts<'tcx>> - where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a + fn relate<'a, 'gcx, R>( + relation: &mut R, + a: &ty::ClosureSubsts<'tcx>, + b: &ty::ClosureSubsts<'tcx>, + ) -> RelateResult<'tcx, ty::ClosureSubsts<'tcx>> + where + R: TypeRelation<'gcx, 'tcx>, + 'gcx: 'a + 'tcx, + 'tcx: 'a, { let substs = relate_substs(relation, None, a.substs, b.substs)?; Ok(ty::ClosureSubsts { substs }) @@ -669,11 +729,15 @@ impl<'tcx> Relate<'tcx> for ty::ClosureSubsts<'tcx> { } impl<'tcx> Relate<'tcx> for ty::GeneratorSubsts<'tcx> { - fn relate<'a, 'gcx, R>(relation: &mut R, - a: &ty::GeneratorSubsts<'tcx>, - b: &ty::GeneratorSubsts<'tcx>) - -> RelateResult<'tcx, ty::GeneratorSubsts<'tcx>> - where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a + fn relate<'a, 'gcx, R>( + relation: &mut R, + a: &ty::GeneratorSubsts<'tcx>, + b: &ty::GeneratorSubsts<'tcx>, + ) -> RelateResult<'tcx, ty::GeneratorSubsts<'tcx>> + where + R: TypeRelation<'gcx, 'tcx>, + 'gcx: 'a + 'tcx, + 'tcx: 'a, { let substs = relate_substs(relation, None, a.substs, b.substs)?; Ok(ty::GeneratorSubsts { substs }) @@ -681,55 +745,71 @@ impl<'tcx> Relate<'tcx> for ty::GeneratorSubsts<'tcx> { } impl<'tcx> Relate<'tcx> for SubstsRef<'tcx> { - fn relate<'a, 'gcx, R>(relation: &mut R, - a: &SubstsRef<'tcx>, - b: &SubstsRef<'tcx>) - -> RelateResult<'tcx, SubstsRef<'tcx>> - where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a + fn relate<'a, 'gcx, R>( + relation: &mut R, + a: &SubstsRef<'tcx>, + b: &SubstsRef<'tcx>, + ) -> RelateResult<'tcx, SubstsRef<'tcx>> + where + R: TypeRelation<'gcx, 'tcx>, + 'gcx: 'a + 'tcx, + 'tcx: 'a, { relate_substs(relation, None, a, b) } } impl<'tcx> Relate<'tcx> for ty::Region<'tcx> { - fn relate<'a, 'gcx, R>(relation: &mut R, - a: &ty::Region<'tcx>, - b: &ty::Region<'tcx>) - -> RelateResult<'tcx, ty::Region<'tcx>> - where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a + fn relate<'a, 'gcx, R>( + relation: &mut R, + a: &ty::Region<'tcx>, + b: &ty::Region<'tcx>, + ) -> RelateResult<'tcx, ty::Region<'tcx>> + where + R: TypeRelation<'gcx, 'tcx>, + 'gcx: 'a + 'tcx, + 'tcx: 'a, { relation.regions(*a, *b) } } impl<'tcx> Relate<'tcx> for &'tcx ty::Const<'tcx> { - fn relate<'a, 'gcx, R>(relation: &mut R, - a: &&'tcx ty::Const<'tcx>, - b: &&'tcx ty::Const<'tcx>) - -> RelateResult<'tcx, &'tcx ty::Const<'tcx>> - where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a + fn relate<'a, 'gcx, R>( + relation: &mut R, + a: &&'tcx ty::Const<'tcx>, + b: &&'tcx ty::Const<'tcx>, + ) -> RelateResult<'tcx, &'tcx ty::Const<'tcx>> + where + R: TypeRelation<'gcx, 'tcx>, + 'gcx: 'a + 'tcx, + 'tcx: 'a, { relation.consts(*a, *b) } } impl<'tcx, T: Relate<'tcx>> Relate<'tcx> for ty::Binder { - fn relate<'a, 'gcx, R>(relation: &mut R, - a: &ty::Binder, - b: &ty::Binder) - -> RelateResult<'tcx, ty::Binder> - where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a + fn relate<'a, 'gcx, R>( + relation: &mut R, + a: &ty::Binder, + b: &ty::Binder, + ) -> RelateResult<'tcx, ty::Binder> + where + R: TypeRelation<'gcx, 'tcx>, + 'gcx: 'a + 'tcx, + 'tcx: 'a, { relation.binders(a, b) } } impl<'tcx, T: Relate<'tcx>> Relate<'tcx> for Rc { - fn relate<'a, 'gcx, R>(relation: &mut R, - a: &Rc, - b: &Rc) - -> RelateResult<'tcx, Rc> - where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a + fn relate<'a, 'gcx, R>(relation: &mut R, a: &Rc, b: &Rc) -> RelateResult<'tcx, Rc> + where + R: TypeRelation<'gcx, 'tcx>, + 'gcx: 'a + 'tcx, + 'tcx: 'a, { let a: &T = a; let b: &T = b; @@ -738,11 +818,11 @@ impl<'tcx, T: Relate<'tcx>> Relate<'tcx> for Rc { } impl<'tcx, T: Relate<'tcx>> Relate<'tcx> for Box { - fn relate<'a, 'gcx, R>(relation: &mut R, - a: &Box, - b: &Box) - -> RelateResult<'tcx, Box> - where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a + fn relate<'a, 'gcx, R>(relation: &mut R, a: &Box, b: &Box) -> RelateResult<'tcx, Box> + where + R: TypeRelation<'gcx, 'tcx>, + 'gcx: 'a + 'tcx, + 'tcx: 'a, { let a: &T = a; let b: &T = b; @@ -754,10 +834,12 @@ impl<'tcx> Relate<'tcx> for Kind<'tcx> { fn relate<'a, 'gcx, R>( relation: &mut R, a: &Kind<'tcx>, - b: &Kind<'tcx> + b: &Kind<'tcx>, ) -> RelateResult<'tcx, Kind<'tcx>> where - R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a, + R: TypeRelation<'gcx, 'tcx>, + 'gcx: 'a + 'tcx, + 'tcx: 'a, { match (a.unpack(), b.unpack()) { (UnpackedKind::Lifetime(a_lt), UnpackedKind::Lifetime(b_lt)) => { @@ -786,9 +868,12 @@ impl<'tcx> Relate<'tcx> for ty::TraitPredicate<'tcx> { fn relate<'a, 'gcx, R>( relation: &mut R, a: &ty::TraitPredicate<'tcx>, - b: &ty::TraitPredicate<'tcx> + b: &ty::TraitPredicate<'tcx>, ) -> RelateResult<'tcx, ty::TraitPredicate<'tcx>> - where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'tcx, 'tcx: 'a + where + R: TypeRelation<'gcx, 'tcx>, + 'gcx: 'tcx, + 'tcx: 'a, { Ok(ty::TraitPredicate { trait_ref: relation.relate(&a.trait_ref, &b.trait_ref)?, @@ -802,7 +887,10 @@ impl<'tcx> Relate<'tcx> for ty::ProjectionPredicate<'tcx> { a: &ty::ProjectionPredicate<'tcx>, b: &ty::ProjectionPredicate<'tcx>, ) -> RelateResult<'tcx, ty::ProjectionPredicate<'tcx>> - where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'tcx, 'tcx: 'a + where + R: TypeRelation<'gcx, 'tcx>, + 'gcx: 'tcx, + 'tcx: 'a, { Ok(ty::ProjectionPredicate { projection_ty: relation.relate(&a.projection_ty, &b.projection_ty)?, @@ -815,9 +903,12 @@ impl<'tcx> Relate<'tcx> for traits::WhereClause<'tcx> { fn relate<'a, 'gcx, R>( relation: &mut R, a: &traits::WhereClause<'tcx>, - b: &traits::WhereClause<'tcx> + b: &traits::WhereClause<'tcx>, ) -> RelateResult<'tcx, traits::WhereClause<'tcx>> - where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'tcx, 'tcx: 'a + where + R: TypeRelation<'gcx, 'tcx>, + 'gcx: 'tcx, + 'tcx: 'a, { use crate::traits::WhereClause::*; match (a, b) { @@ -852,9 +943,12 @@ impl<'tcx> Relate<'tcx> for traits::WellFormed<'tcx> { fn relate<'a, 'gcx, R>( relation: &mut R, a: &traits::WellFormed<'tcx>, - b: &traits::WellFormed<'tcx> + b: &traits::WellFormed<'tcx>, ) -> RelateResult<'tcx, traits::WellFormed<'tcx>> - where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'tcx, 'tcx: 'a + where + R: TypeRelation<'gcx, 'tcx>, + 'gcx: 'tcx, + 'tcx: 'a, { use crate::traits::WellFormed::*; match (a, b) { @@ -869,9 +963,12 @@ impl<'tcx> Relate<'tcx> for traits::FromEnv<'tcx> { fn relate<'a, 'gcx, R>( relation: &mut R, a: &traits::FromEnv<'tcx>, - b: &traits::FromEnv<'tcx> + b: &traits::FromEnv<'tcx>, ) -> RelateResult<'tcx, traits::FromEnv<'tcx>> - where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'tcx, 'tcx: 'a + where + R: TypeRelation<'gcx, 'tcx>, + 'gcx: 'tcx, + 'tcx: 'a, { use crate::traits::FromEnv::*; match (a, b) { @@ -886,9 +983,12 @@ impl<'tcx> Relate<'tcx> for traits::DomainGoal<'tcx> { fn relate<'a, 'gcx, R>( relation: &mut R, a: &traits::DomainGoal<'tcx>, - b: &traits::DomainGoal<'tcx> + b: &traits::DomainGoal<'tcx>, ) -> RelateResult<'tcx, traits::DomainGoal<'tcx>> - where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'tcx, 'tcx: 'a + where + R: TypeRelation<'gcx, 'tcx>, + 'gcx: 'tcx, + 'tcx: 'a, { use crate::traits::DomainGoal::*; match (a, b) { @@ -909,9 +1009,12 @@ impl<'tcx> Relate<'tcx> for traits::Goal<'tcx> { fn relate<'a, 'gcx, R>( relation: &mut R, a: &traits::Goal<'tcx>, - b: &traits::Goal<'tcx> + b: &traits::Goal<'tcx>, ) -> RelateResult<'tcx, traits::Goal<'tcx>> - where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'tcx, 'tcx: 'a + where + R: TypeRelation<'gcx, 'tcx>, + 'gcx: 'tcx, + 'tcx: 'a, { use crate::traits::GoalKind::*; match (a, b) { @@ -955,9 +1058,12 @@ impl<'tcx> Relate<'tcx> for traits::Goals<'tcx> { fn relate<'a, 'gcx, R>( relation: &mut R, a: &traits::Goals<'tcx>, - b: &traits::Goals<'tcx> + b: &traits::Goals<'tcx>, ) -> RelateResult<'tcx, traits::Goals<'tcx>> - where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'tcx, 'tcx: 'a + where + R: TypeRelation<'gcx, 'tcx>, + 'gcx: 'tcx, + 'tcx: 'a, { if a.len() != b.len() { return Err(TypeError::Mismatch); @@ -973,9 +1079,12 @@ impl<'tcx> Relate<'tcx> for traits::Clause<'tcx> { fn relate<'a, 'gcx, R>( relation: &mut R, a: &traits::Clause<'tcx>, - b: &traits::Clause<'tcx> + b: &traits::Clause<'tcx>, ) -> RelateResult<'tcx, traits::Clause<'tcx>> - where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'tcx, 'tcx: 'a + where + R: TypeRelation<'gcx, 'tcx>, + 'gcx: 'tcx, + 'tcx: 'a, { use crate::traits::Clause::*; match (a, b) { @@ -998,9 +1107,12 @@ impl<'tcx> Relate<'tcx> for traits::Clauses<'tcx> { fn relate<'a, 'gcx, R>( relation: &mut R, a: &traits::Clauses<'tcx>, - b: &traits::Clauses<'tcx> + b: &traits::Clauses<'tcx>, ) -> RelateResult<'tcx, traits::Clauses<'tcx>> - where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'tcx, 'tcx: 'a + where + R: TypeRelation<'gcx, 'tcx>, + 'gcx: 'tcx, + 'tcx: 'a, { if a.len() != b.len() { return Err(TypeError::Mismatch); @@ -1016,9 +1128,12 @@ impl<'tcx> Relate<'tcx> for traits::ProgramClause<'tcx> { fn relate<'a, 'gcx, R>( relation: &mut R, a: &traits::ProgramClause<'tcx>, - b: &traits::ProgramClause<'tcx> + b: &traits::ProgramClause<'tcx>, ) -> RelateResult<'tcx, traits::ProgramClause<'tcx>> - where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'tcx, 'tcx: 'a + where + R: TypeRelation<'gcx, 'tcx>, + 'gcx: 'tcx, + 'tcx: 'a, { Ok(traits::ProgramClause { goal: relation.relate(&a.goal, &b.goal)?, @@ -1032,9 +1147,12 @@ impl<'tcx> Relate<'tcx> for traits::Environment<'tcx> { fn relate<'a, 'gcx, R>( relation: &mut R, a: &traits::Environment<'tcx>, - b: &traits::Environment<'tcx> + b: &traits::Environment<'tcx>, ) -> RelateResult<'tcx, traits::Environment<'tcx>> - where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'tcx, 'tcx: 'a + where + R: TypeRelation<'gcx, 'tcx>, + 'gcx: 'tcx, + 'tcx: 'a, { Ok(traits::Environment { clauses: relation.relate(&a.clauses, &b.clauses)?, @@ -1043,14 +1161,18 @@ impl<'tcx> Relate<'tcx> for traits::Environment<'tcx> { } impl<'tcx, G> Relate<'tcx> for traits::InEnvironment<'tcx, G> - where G: Relate<'tcx> +where + G: Relate<'tcx>, { fn relate<'a, 'gcx, R>( relation: &mut R, a: &traits::InEnvironment<'tcx, G>, - b: &traits::InEnvironment<'tcx, G> + b: &traits::InEnvironment<'tcx, G>, ) -> RelateResult<'tcx, traits::InEnvironment<'tcx, G>> - where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'tcx, 'tcx: 'a + where + R: TypeRelation<'gcx, 'tcx>, + 'gcx: 'tcx, + 'tcx: 'a, { Ok(traits::InEnvironment { environment: relation.relate(&a.environment, &b.environment)?, @@ -1062,11 +1184,12 @@ impl<'tcx, G> Relate<'tcx> for traits::InEnvironment<'tcx, G> /////////////////////////////////////////////////////////////////////////// // Error handling -pub fn expected_found<'a, 'gcx, 'tcx, R, T>(relation: &mut R, - a: &T, - b: &T) - -> ExpectedFound - where R: TypeRelation<'gcx, 'tcx>, T: Clone, 'gcx: 'a+'tcx, 'tcx: 'a +pub fn expected_found<'a, 'gcx, 'tcx, R, T>(relation: &mut R, a: &T, b: &T) -> ExpectedFound +where + R: TypeRelation<'gcx, 'tcx>, + T: Clone, + 'gcx: 'a + 'tcx, + 'tcx: 'a, { expected_found_bool(relation.a_is_expected(), a, b) } diff --git a/src/librustc/ty/structural_impls.rs b/src/librustc/ty/structural_impls.rs index a6584173fd280..35c61f83fceb2 100644 --- a/src/librustc/ty/structural_impls.rs +++ b/src/librustc/ty/structural_impls.rs @@ -450,8 +450,7 @@ impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialPredicate<'a> { impl<'a, 'tcx> Lift<'tcx> for ty::TraitPredicate<'a> { type Lifted = ty::TraitPredicate<'tcx>; - fn lift_to_tcx<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>) - -> Option> { + fn lift_to_tcx<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>) -> Option> { tcx.lift(&self.trait_ref).map(|trait_ref| ty::TraitPredicate { trait_ref, }) @@ -460,8 +459,7 @@ impl<'a, 'tcx> Lift<'tcx> for ty::TraitPredicate<'a> { impl<'a, 'tcx> Lift<'tcx> for ty::SubtypePredicate<'a> { type Lifted = ty::SubtypePredicate<'tcx>; - fn lift_to_tcx<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>) - -> Option> { + fn lift_to_tcx<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>) -> Option> { tcx.lift(&(self.a, self.b)).map(|(a, b)| ty::SubtypePredicate { a_is_expected: self.a_is_expected, a, @@ -470,7 +468,7 @@ impl<'a, 'tcx> Lift<'tcx> for ty::SubtypePredicate<'a> { } } -impl<'tcx, A: Copy+Lift<'tcx>, B: Copy+Lift<'tcx>> Lift<'tcx> for ty::OutlivesPredicate { +impl<'tcx, A: Copy + Lift<'tcx>, B: Copy + Lift<'tcx>> Lift<'tcx> for ty::OutlivesPredicate { type Lifted = ty::OutlivesPredicate; fn lift_to_tcx<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>) -> Option { tcx.lift(&(self.0, self.1)).map(|(a, b)| ty::OutlivesPredicate(a, b)) @@ -479,8 +477,7 @@ impl<'tcx, A: Copy+Lift<'tcx>, B: Copy+Lift<'tcx>> Lift<'tcx> for ty::OutlivesPr impl<'a, 'tcx> Lift<'tcx> for ty::ProjectionTy<'a> { type Lifted = ty::ProjectionTy<'tcx>; - fn lift_to_tcx<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>) - -> Option> { + fn lift_to_tcx<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>) -> Option> { tcx.lift(&self.substs).map(|substs| { ty::ProjectionTy { item_def_id: self.item_def_id, @@ -492,8 +489,7 @@ impl<'a, 'tcx> Lift<'tcx> for ty::ProjectionTy<'a> { impl<'a, 'tcx> Lift<'tcx> for ty::ProjectionPredicate<'a> { type Lifted = ty::ProjectionPredicate<'tcx>; - fn lift_to_tcx<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>) - -> Option> { + fn lift_to_tcx<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>) -> Option> { tcx.lift(&(self.projection_ty, self.ty)).map(|(projection_ty, ty)| { ty::ProjectionPredicate { projection_ty, diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index 5036408af39cc..dc2d96ee8b946 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -335,9 +335,11 @@ impl<'tcx> ClosureSubsts<'tcx> { } #[inline] - pub fn upvar_tys(self, def_id: DefId, tcx: TyCtxt<'_, '_>) -> - impl Iterator> + 'tcx - { + pub fn upvar_tys( + self, + def_id: DefId, + tcx: TyCtxt<'_, '_>, + ) -> impl Iterator> + 'tcx { let SplitClosureSubsts { upvar_kinds, .. } = self.split(def_id, tcx); upvar_kinds.iter().map(|t| { if let UnpackedKind::Type(ty) = t.unpack() { @@ -422,9 +424,11 @@ impl<'tcx> GeneratorSubsts<'tcx> { } #[inline] - pub fn upvar_tys(self, def_id: DefId, tcx: TyCtxt<'_, '_>) -> - impl Iterator> + 'tcx - { + pub fn upvar_tys( + self, + def_id: DefId, + tcx: TyCtxt<'_, '_>, + ) -> impl Iterator> + 'tcx { let SplitGeneratorSubsts { upvar_kinds, .. } = self.split(def_id, tcx); upvar_kinds.iter().map(|t| { if let UnpackedKind::Type(ty) = t.unpack() { @@ -489,7 +493,10 @@ impl<'gcx, 'tcx> GeneratorSubsts<'tcx> { /// out of range. #[inline] pub fn discriminant_for_variant( - &self, def_id: DefId, tcx: TyCtxt<'gcx, 'tcx>, variant_index: VariantIdx + &self, + def_id: DefId, + tcx: TyCtxt<'gcx, 'tcx>, + variant_index: VariantIdx, ) -> Discr<'tcx> { // Generators don't support explicit discriminant values, so they are // the same as the variant index. @@ -501,8 +508,10 @@ impl<'gcx, 'tcx> GeneratorSubsts<'tcx> { /// variant indices. #[inline] pub fn discriminants( - &'tcx self, def_id: DefId, tcx: TyCtxt<'gcx, 'tcx> - ) -> impl Iterator)> + Captures<'gcx> { + &'tcx self, + def_id: DefId, + tcx: TyCtxt<'gcx, 'tcx>, + ) -> impl Iterator)> + Captures<'gcx> { self.variant_range(def_id, tcx).map(move |index| { (index, Discr { val: index.as_usize() as u128, ty: self.discr_ty(tcx) }) }) @@ -533,9 +542,11 @@ impl<'gcx, 'tcx> GeneratorSubsts<'tcx> { /// The locals are grouped by their variant number. Note that some locals may /// be repeated in multiple variants. #[inline] - pub fn state_tys(self, def_id: DefId, tcx: TyCtxt<'gcx, 'tcx>) -> - impl Iterator> + Captures<'gcx>> - { + pub fn state_tys( + self, + def_id: DefId, + tcx: TyCtxt<'gcx, 'tcx>, + ) -> impl Iterator> + Captures<'gcx>> { let layout = tcx.generator_layout(def_id); layout.variant_fields.iter().map(move |variant| { variant.iter().map(move |field| { @@ -547,9 +558,11 @@ impl<'gcx, 'tcx> GeneratorSubsts<'tcx> { /// This is the types of the fields of a generator which are not stored in a /// variant. #[inline] - pub fn prefix_tys(self, def_id: DefId, tcx: TyCtxt<'gcx, 'tcx>) -> - impl Iterator> - { + pub fn prefix_tys( + self, + def_id: DefId, + tcx: TyCtxt<'gcx, 'tcx>, + ) -> impl Iterator> { self.upvar_tys(def_id, tcx) } } @@ -562,9 +575,11 @@ pub enum UpvarSubsts<'tcx> { impl<'tcx> UpvarSubsts<'tcx> { #[inline] - pub fn upvar_tys(self, def_id: DefId, tcx: TyCtxt<'_, '_>) -> - impl Iterator> + 'tcx - { + pub fn upvar_tys( + self, + def_id: DefId, + tcx: TyCtxt<'_, '_>, + ) -> impl Iterator> + 'tcx { let upvar_kinds = match self { UpvarSubsts::Closure(substs) => substs.split(def_id, tcx).upvar_kinds, UpvarSubsts::Generator(substs) => substs.split(def_id, tcx).upvar_kinds, @@ -607,12 +622,10 @@ impl<'gcx, 'tcx> ExistentialPredicate<'tcx> { (AutoTrait(_), _) => Ordering::Greater, } } - } impl<'gcx, 'tcx> Binder> { - pub fn with_self_ty(&self, tcx: TyCtxt<'gcx, 'tcx>, self_ty: Ty<'tcx>) - -> ty::Predicate<'tcx> { + pub fn with_self_ty(&self, tcx: TyCtxt<'gcx, 'tcx>, self_ty: Ty<'tcx>) -> ty::Predicate<'tcx> { use crate::ty::ToPredicate; match *self.skip_binder() { ExistentialPredicate::Trait(tr) => Binder(tr).with_self_ty(tcx, self_ty).to_predicate(), @@ -764,10 +777,11 @@ impl<'tcx> TraitRef<'tcx> { self.substs.types() } - pub fn from_method(tcx: TyCtxt<'_, 'tcx>, - trait_id: DefId, - substs: SubstsRef<'tcx>) - -> ty::TraitRef<'tcx> { + pub fn from_method( + tcx: TyCtxt<'_, 'tcx>, + trait_id: DefId, + substs: SubstsRef<'tcx>, + ) -> ty::TraitRef<'tcx> { let defs = tcx.generics_of(trait_id); ty::TraitRef { @@ -817,9 +831,10 @@ impl<'gcx, 'tcx> ExistentialTraitRef<'tcx> { self.substs.types() } - pub fn erase_self_ty(tcx: TyCtxt<'gcx, 'tcx>, - trait_ref: ty::TraitRef<'tcx>) - -> ty::ExistentialTraitRef<'tcx> { + pub fn erase_self_ty( + tcx: TyCtxt<'gcx, 'tcx>, + trait_ref: ty::TraitRef<'tcx>, + ) -> ty::ExistentialTraitRef<'tcx> { // Assert there is a Self. trait_ref.substs.type_at(0); @@ -833,8 +848,7 @@ impl<'gcx, 'tcx> ExistentialTraitRef<'tcx> { /// we convert the principal trait-ref into a normal trait-ref, /// you must give *some* self type. A common choice is `mk_err()` /// or some placeholder type. - pub fn with_self_ty(&self, tcx: TyCtxt<'gcx, 'tcx>, self_ty: Ty<'tcx>) - -> ty::TraitRef<'tcx> { + pub fn with_self_ty(&self, tcx: TyCtxt<'gcx, 'tcx>, self_ty: Ty<'tcx>) -> ty::TraitRef<'tcx> { // otherwise the escaping vars would be captured by the binder // debug_assert!(!self_ty.has_escaping_bound_vars()); @@ -856,9 +870,7 @@ impl<'tcx> PolyExistentialTraitRef<'tcx> { /// we convert the principal trait-ref into a normal trait-ref, /// you must give *some* self type. A common choice is `mk_err()` /// or some placeholder type. - pub fn with_self_ty(&self, tcx: TyCtxt<'_, 'tcx>, - self_ty: Ty<'tcx>) - -> ty::PolyTraitRef<'tcx> { + pub fn with_self_ty(&self, tcx: TyCtxt<'_, 'tcx>, self_ty: Ty<'tcx>) -> ty::PolyTraitRef<'tcx> { self.map_bound(|trait_ref| trait_ref.with_self_ty(tcx, self_ty)) } } @@ -992,7 +1004,9 @@ impl<'tcx> ProjectionTy<'tcx> { /// Construct a `ProjectionTy` by searching the trait from `trait_ref` for the /// associated item named `item_name`. pub fn from_ref_and_name( - tcx: TyCtxt<'_, '_>, trait_ref: ty::TraitRef<'tcx>, item_name: Ident + tcx: TyCtxt<'_, '_>, + trait_ref: ty::TraitRef<'tcx>, + item_name: Ident, ) -> ProjectionTy<'tcx> { let item_def_id = tcx.associated_items(trait_ref.def_id).find(|item| { item.kind == ty::AssocKind::Type && @@ -1421,10 +1435,11 @@ impl<'tcx, 'gcx> ExistentialProjection<'tcx> { } } - pub fn with_self_ty(&self, tcx: TyCtxt<'gcx, 'tcx>, - self_ty: Ty<'tcx>) - -> ty::ProjectionPredicate<'tcx> - { + pub fn with_self_ty( + &self, + tcx: TyCtxt<'gcx, 'tcx>, + self_ty: Ty<'tcx>, + ) -> ty::ProjectionPredicate<'tcx> { // otherwise the escaping regions would be captured by the binders debug_assert!(!self_ty.has_escaping_bound_vars()); @@ -1439,8 +1454,11 @@ impl<'tcx, 'gcx> ExistentialProjection<'tcx> { } impl<'tcx, 'gcx> PolyExistentialProjection<'tcx> { - pub fn with_self_ty(&self, tcx: TyCtxt<'gcx, 'tcx>, self_ty: Ty<'tcx>) - -> ty::PolyProjectionPredicate<'tcx> { + pub fn with_self_ty( + &self, + tcx: TyCtxt<'gcx, 'tcx>, + self_ty: Ty<'tcx>, + ) -> ty::PolyProjectionPredicate<'tcx> { self.map_bound(|p| p.with_self_ty(tcx, self_ty)) } @@ -2099,7 +2117,7 @@ impl<'gcx, 'tcx> TyS<'tcx> { pub fn discriminant_for_variant( &self, tcx: TyCtxt<'gcx, 'tcx>, - variant_index: VariantIdx + variant_index: VariantIdx, ) -> Option> { match self.sty { TyKind::Adt(adt, _) => Some(adt.discriminant_for_variant(tcx, variant_index)), @@ -2239,11 +2257,7 @@ static_assert_size!(Const<'_>, 40); impl<'tcx> Const<'tcx> { #[inline] - pub fn from_scalar( - tcx: TyCtxt<'_, 'tcx>, - val: Scalar, - ty: Ty<'tcx>, - ) -> &'tcx Self { + pub fn from_scalar(tcx: TyCtxt<'_, 'tcx>, val: Scalar, ty: Ty<'tcx>) -> &'tcx Self { tcx.mk_const(Self { val: ConstValue::Scalar(val), ty, @@ -2279,11 +2293,7 @@ impl<'tcx> Const<'tcx> { } #[inline] - pub fn to_bits( - &self, - tcx: TyCtxt<'_, 'tcx>, - ty: ParamEnvAnd<'tcx, Ty<'tcx>>, - ) -> Option { + pub fn to_bits(&self, tcx: TyCtxt<'_, 'tcx>, ty: ParamEnvAnd<'tcx, Ty<'tcx>>) -> Option { if self.ty != ty.value { return None; } @@ -2324,11 +2334,7 @@ impl<'tcx> Const<'tcx> { } #[inline] - pub fn unwrap_bits( - &self, - tcx: TyCtxt<'_, '_>, - ty: ParamEnvAnd<'tcx, Ty<'tcx>>, - ) -> u128 { + pub fn unwrap_bits(&self, tcx: TyCtxt<'_, '_>, ty: ParamEnvAnd<'tcx, Ty<'tcx>>) -> u128 { self.assert_bits(tcx, ty).unwrap_or_else(|| bug!("expected bits of {}, got {:#?}", ty.value, self)) } diff --git a/src/librustc/ty/subst.rs b/src/librustc/ty/subst.rs index 60579bcf3a5b4..a47217138aa1a 100644 --- a/src/librustc/ty/subst.rs +++ b/src/librustc/ty/subst.rs @@ -194,10 +194,7 @@ impl<'a, 'gcx, 'tcx> InternalSubsts<'tcx> { /// var bound at index `0`. For types, we use a `BoundVar` index equal to /// the type parameter index. For regions, we use the `BoundRegion::BrNamed` /// variant (which has a `DefId`). - pub fn bound_vars_for_item( - tcx: TyCtxt<'gcx, 'tcx>, - def_id: DefId - ) -> SubstsRef<'tcx> { + pub fn bound_vars_for_item(tcx: TyCtxt<'gcx, 'tcx>, def_id: DefId) -> SubstsRef<'tcx> { Self::for_item(tcx, def_id, |param, _| { match param.kind { ty::GenericParamDefKind::Type { .. } => { @@ -233,11 +230,9 @@ impl<'a, 'gcx, 'tcx> InternalSubsts<'tcx> { /// The closures get to observe the `InternalSubsts` as they're /// being built, which can be used to correctly /// substitute defaults of generic parameters. - pub fn for_item(tcx: TyCtxt<'gcx, 'tcx>, - def_id: DefId, - mut mk_kind: F) - -> SubstsRef<'tcx> - where F: FnMut(&ty::GenericParamDef, &[Kind<'tcx>]) -> Kind<'tcx> + pub fn for_item(tcx: TyCtxt<'gcx, 'tcx>, def_id: DefId, mut mk_kind: F) -> SubstsRef<'tcx> + where + F: FnMut(&ty::GenericParamDef, &[Kind<'tcx>]) -> Kind<'tcx>, { let defs = tcx.generics_of(def_id); let count = defs.count(); @@ -246,12 +241,14 @@ impl<'a, 'gcx, 'tcx> InternalSubsts<'tcx> { tcx.intern_substs(&substs) } - pub fn extend_to(&self, - tcx: TyCtxt<'gcx, 'tcx>, - def_id: DefId, - mut mk_kind: F) - -> SubstsRef<'tcx> - where F: FnMut(&ty::GenericParamDef, &[Kind<'tcx>]) -> Kind<'tcx> + pub fn extend_to( + &self, + tcx: TyCtxt<'gcx, 'tcx>, + def_id: DefId, + mut mk_kind: F, + ) -> SubstsRef<'tcx> + where + F: FnMut(&ty::GenericParamDef, &[Kind<'tcx>]) -> Kind<'tcx>, { Self::for_item(tcx, def_id, |param, substs| { self.get(param.index as usize) @@ -260,11 +257,13 @@ impl<'a, 'gcx, 'tcx> InternalSubsts<'tcx> { }) } - fn fill_item(substs: &mut SmallVec<[Kind<'tcx>; 8]>, - tcx: TyCtxt<'gcx, 'tcx>, - defs: &ty::Generics, - mk_kind: &mut F) - where F: FnMut(&ty::GenericParamDef, &[Kind<'tcx>]) -> Kind<'tcx> + fn fill_item( + substs: &mut SmallVec<[Kind<'tcx>; 8]>, + tcx: TyCtxt<'gcx, 'tcx>, + defs: &ty::Generics, + mk_kind: &mut F, + ) where + F: FnMut(&ty::GenericParamDef, &[Kind<'tcx>]) -> Kind<'tcx>, { if let Some(def_id) = defs.parent { let parent_defs = tcx.generics_of(def_id); @@ -372,16 +371,17 @@ impl<'a, 'gcx, 'tcx> InternalSubsts<'tcx> { /// in a different item, with `target_substs` as the base for /// the target impl/trait, with the source child-specific /// parameters (e.g., method parameters) on top of that base. - pub fn rebase_onto(&self, tcx: TyCtxt<'gcx, 'tcx>, - source_ancestor: DefId, - target_substs: SubstsRef<'tcx>) - -> SubstsRef<'tcx> { + pub fn rebase_onto( + &self, + tcx: TyCtxt<'gcx, 'tcx>, + source_ancestor: DefId, + target_substs: SubstsRef<'tcx>, + ) -> SubstsRef<'tcx> { let defs = tcx.generics_of(source_ancestor); tcx.mk_substs(target_substs.iter().chain(&self[defs.params.len()..]).cloned()) } - pub fn truncate_to(&self, tcx: TyCtxt<'gcx, 'tcx>, generics: &ty::Generics) - -> SubstsRef<'tcx> { + pub fn truncate_to(&self, tcx: TyCtxt<'gcx, 'tcx>, generics: &ty::Generics) -> SubstsRef<'tcx> { tcx.mk_substs(self.iter().take(generics.count()).cloned()) } } @@ -414,23 +414,25 @@ impl<'tcx> serialize::UseSpecializedDecodable for SubstsRef<'tcx> {} // there is more information available (for better errors). pub trait Subst<'tcx>: Sized { - fn subst<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>, - substs: &[Kind<'tcx>]) -> Self { + fn subst<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>, substs: &[Kind<'tcx>]) -> Self { self.subst_spanned(tcx, substs, None) } - fn subst_spanned<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>, - substs: &[Kind<'tcx>], - span: Option) - -> Self; + fn subst_spanned<'gcx>( + &self, + tcx: TyCtxt<'gcx, 'tcx>, + substs: &[Kind<'tcx>], + span: Option, + ) -> Self; } -impl<'tcx, T:TypeFoldable<'tcx>> Subst<'tcx> for T { - fn subst_spanned<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>, - substs: &[Kind<'tcx>], - span: Option) - -> T - { +impl<'tcx, T: TypeFoldable<'tcx>> Subst<'tcx> for T { + fn subst_spanned<'gcx>( + &self, + tcx: TyCtxt<'gcx, 'tcx>, + substs: &[Kind<'tcx>], + span: Option, + ) -> T { let mut folder = SubstFolder { tcx, substs, span, @@ -444,7 +446,7 @@ impl<'tcx, T:TypeFoldable<'tcx>> Subst<'tcx> for T { /////////////////////////////////////////////////////////////////////////// // The actual substitution engine itself is a type folder. -struct SubstFolder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { +struct SubstFolder<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> { tcx: TyCtxt<'gcx, 'tcx>, substs: &'a [Kind<'tcx>], diff --git a/src/librustc/ty/trait_def.rs b/src/librustc/ty/trait_def.rs index 9c82082f8f5c7..1f99d97605c79 100644 --- a/src/librustc/ty/trait_def.rs +++ b/src/librustc/ty/trait_def.rs @@ -64,9 +64,11 @@ impl<'gcx, 'tcx> TraitDef { } } - pub fn ancestors(&self, tcx: TyCtxt<'gcx, 'tcx>, - of_impl: DefId) - -> specialization_graph::Ancestors<'gcx> { + pub fn ancestors( + &self, + tcx: TyCtxt<'gcx, 'tcx>, + of_impl: DefId, + ) -> specialization_graph::Ancestors<'gcx> { specialization_graph::ancestors(tcx, self.def_id, of_impl) } } @@ -148,9 +150,10 @@ impl<'gcx, 'tcx> TyCtxt<'gcx, 'tcx> { } // Query provider for `trait_impls_of`. -pub(super) fn trait_impls_of_provider<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - trait_id: DefId) - -> &'tcx TraitImpls { +pub(super) fn trait_impls_of_provider<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + trait_id: DefId, +) -> &'tcx TraitImpls { let mut impls = TraitImpls::default(); { diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs index a88b3eaa586a3..57319db63404a 100644 --- a/src/librustc/ty/util.rs +++ b/src/librustc/ty/util.rs @@ -105,8 +105,11 @@ impl<'tcx> Discr<'tcx> { pub trait IntTypeExt { fn to_ty<'gcx, 'tcx>(&self, tcx: TyCtxt<'gcx, 'tcx>) -> Ty<'tcx>; - fn disr_incr<'tcx>(&self, tcx: TyCtxt<'tcx, 'tcx>, val: Option>) - -> Option>; + fn disr_incr<'tcx>( + &self, + tcx: TyCtxt<'tcx, 'tcx>, + val: Option>, + ) -> Option>; fn initial_discriminant<'tcx>(&self, tcx: TyCtxt<'tcx, 'tcx>) -> Discr<'tcx>; } @@ -178,10 +181,11 @@ pub enum Representability { } impl<'tcx> ty::ParamEnv<'tcx> { - pub fn can_type_implement_copy(self, - tcx: TyCtxt<'tcx, 'tcx>, - self_type: Ty<'tcx>) - -> Result<(), CopyImplementationError<'tcx>> { + pub fn can_type_implement_copy( + self, + tcx: TyCtxt<'tcx, 'tcx>, + self_type: Ty<'tcx>, + ) -> Result<(), CopyImplementationError<'tcx>> { // FIXME: (@jroesch) float this code up tcx.infer_ctxt().enter(|infcx| { let (adt, substs) = match self_type.sty { @@ -695,11 +699,12 @@ impl<'tcx> ty::TyS<'tcx> { /// does copies even when the type actually doesn't satisfy the /// full requirements for the `Copy` trait (cc #29149) -- this /// winds up being reported as an error during NLL borrow check. - pub fn is_copy_modulo_regions(&'tcx self, - tcx: TyCtxt<'tcx, 'tcx>, - param_env: ty::ParamEnv<'tcx>, - span: Span) - -> bool { + pub fn is_copy_modulo_regions( + &'tcx self, + tcx: TyCtxt<'tcx, 'tcx>, + param_env: ty::ParamEnv<'tcx>, + span: Span, + ) -> bool { tcx.at(span).is_copy_raw(param_env.and(self)) } @@ -709,10 +714,11 @@ impl<'tcx> ty::TyS<'tcx> { /// over-approximation in generic contexts, where one can have /// strange rules like `>::Bar: Sized` that /// actually carry lifetime requirements. - pub fn is_sized(&'tcx self, - tcx_at: TyCtxtAt<'tcx, 'tcx>, - param_env: ty::ParamEnv<'tcx>)-> bool - { + pub fn is_sized( + &'tcx self, + tcx_at: TyCtxtAt<'tcx, 'tcx>, + param_env: ty::ParamEnv<'tcx>, + ) -> bool { tcx_at.is_sized_raw(param_env.and(self)) } @@ -723,11 +729,12 @@ impl<'tcx> ty::TyS<'tcx> { /// optimization as well as the rules around static values. Note /// that the `Freeze` trait is not exposed to end users and is /// effectively an implementation detail. - pub fn is_freeze(&'tcx self, - tcx: TyCtxt<'tcx, 'tcx>, - param_env: ty::ParamEnv<'tcx>, - span: Span)-> bool - { + pub fn is_freeze( + &'tcx self, + tcx: TyCtxt<'tcx, 'tcx>, + param_env: ty::ParamEnv<'tcx>, + span: Span, + ) -> bool { tcx.at(span).is_freeze_raw(param_env.and(self)) } @@ -738,10 +745,7 @@ impl<'tcx> ty::TyS<'tcx> { /// (Note that this implies that if `ty` has a destructor attached, /// then `needs_drop` will definitely return `true` for `ty`.) #[inline] - pub fn needs_drop(&'tcx self, - tcx: TyCtxt<'tcx, 'tcx>, - param_env: ty::ParamEnv<'tcx>) - -> bool { + pub fn needs_drop(&'tcx self, tcx: TyCtxt<'tcx, 'tcx>, param_env: ty::ParamEnv<'tcx>) -> bool { tcx.needs_drop_raw(param_env.and(self)).0 } @@ -760,11 +764,7 @@ impl<'tcx> ty::TyS<'tcx> { /// Check whether a type is representable. This means it cannot contain unboxed /// structural recursion. This check is needed for structs and enums. - pub fn is_representable(&'tcx self, - tcx: TyCtxt<'tcx, 'tcx>, - sp: Span) - -> Representability - { + pub fn is_representable(&'tcx self, tcx: TyCtxt<'tcx, 'tcx>, sp: Span) -> Representability { // Iterate until something non-representable is found fn fold_repr>(iter: It) -> Representability { iter.fold(Representability::Representable, |r1, r2| { @@ -779,12 +779,12 @@ impl<'tcx> ty::TyS<'tcx> { } fn are_inner_types_recursive<'tcx>( - tcx: TyCtxt<'tcx, 'tcx>, sp: Span, + tcx: TyCtxt<'tcx, 'tcx>, + sp: Span, seen: &mut Vec>, representable_cache: &mut FxHashMap, Representability>, - ty: Ty<'tcx>) - -> Representability - { + ty: Ty<'tcx>, + ) -> Representability { match ty.sty { Tuple(ref ts) => { // Find non representable @@ -843,8 +843,8 @@ impl<'tcx> ty::TyS<'tcx> { sp: Span, seen: &mut Vec>, representable_cache: &mut FxHashMap, Representability>, - ty: Ty<'tcx>) -> Representability - { + ty: Ty<'tcx>, + ) -> Representability { debug!("is_type_structurally_recursive: {:?} {:?}", ty, sp); if let Some(representability) = representable_cache.get(ty) { debug!("is_type_structurally_recursive: {:?} {:?} - (cached) {:?}", @@ -864,8 +864,8 @@ impl<'tcx> ty::TyS<'tcx> { sp: Span, seen: &mut Vec>, representable_cache: &mut FxHashMap, Representability>, - ty: Ty<'tcx>) -> Representability - { + ty: Ty<'tcx>, + ) -> Representability { match ty.sty { Adt(def, _) => { { @@ -937,10 +937,7 @@ impl<'tcx> ty::TyS<'tcx> { } } -fn is_copy_raw<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) - -> bool -{ +fn is_copy_raw<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool { let (param_env, ty) = query.into_parts(); let trait_def_id = tcx.require_lang_item(lang_items::CopyTraitLangItem); tcx.infer_ctxt() @@ -953,10 +950,7 @@ fn is_copy_raw<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, )) } -fn is_sized_raw<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) - -> bool -{ +fn is_sized_raw<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool { let (param_env, ty) = query.into_parts(); let trait_def_id = tcx.require_lang_item(lang_items::SizedTraitLangItem); tcx.infer_ctxt() @@ -969,10 +963,7 @@ fn is_sized_raw<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, )) } -fn is_freeze_raw<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) - -> bool -{ +fn is_freeze_raw<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool { let (param_env, ty) = query.into_parts(); let trait_def_id = tcx.require_lang_item(lang_items::FreezeTraitLangItem); tcx.infer_ctxt() @@ -988,10 +979,10 @@ fn is_freeze_raw<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, #[derive(Clone, HashStable)] pub struct NeedsDrop(pub bool); -fn needs_drop_raw<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) - -> NeedsDrop -{ +fn needs_drop_raw<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>, +) -> NeedsDrop { let (param_env, ty) = query.into_parts(); let needs_drop = |ty: Ty<'tcx>| -> bool { diff --git a/src/librustc/ty/wf.rs b/src/librustc/ty/wf.rs index f0378b2e084df..1ed88f395a943 100644 --- a/src/librustc/ty/wf.rs +++ b/src/librustc/ty/wf.rs @@ -510,9 +510,8 @@ impl<'a, 'gcx, 'tcx> WfPredicates<'a, 'gcx, 'tcx> { /// `ty::required_region_bounds`, see that for more information. pub fn object_region_bounds<'gcx, 'tcx>( tcx: TyCtxt<'gcx, 'tcx>, - existential_predicates: ty::Binder<&'tcx ty::List>>) - -> Vec> -{ + existential_predicates: ty::Binder<&'tcx ty::List>>, +) -> Vec> { // Since we don't actually *know* the self type for an object, // this "open(err)" serves as a kind of dummy standin -- basically // a placeholder type. diff --git a/src/librustc_borrowck/borrowck/check_loans.rs b/src/librustc_borrowck/borrowck/check_loans.rs index 94219650a8e82..45a92daab0dfb 100644 --- a/src/librustc_borrowck/borrowck/check_loans.rs +++ b/src/librustc_borrowck/borrowck/check_loans.rs @@ -179,11 +179,13 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for CheckLoanCtxt<'a, 'tcx> { fn decl_without_init(&mut self, _id: hir::HirId, _span: Span) { } } -pub fn check_loans<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, - dfcx_loans: &LoanDataFlow<'tcx>, - move_data: &move_data::FlowedMoveData<'tcx>, - all_loans: &[Loan<'tcx>], - body: &hir::Body) { +pub fn check_loans<'a, 'tcx>( + bccx: &BorrowckCtxt<'a, 'tcx>, + dfcx_loans: &LoanDataFlow<'tcx>, + move_data: &move_data::FlowedMoveData<'tcx>, + all_loans: &[Loan<'tcx>], + body: &hir::Body, +) { debug!("check_loans(body id={})", body.value.hir_id); let def_id = bccx.tcx.hir().body_owner_def_id(body.id()); diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index aa94e100f334f..e8644d2416db7 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -73,9 +73,7 @@ pub struct AnalysisData<'tcx> { pub move_data: move_data::FlowedMoveData<'tcx>, } -fn borrowck<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, owner_def_id: DefId) - -> &'tcx BorrowCheckResult -{ +fn borrowck<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, owner_def_id: DefId) -> &'tcx BorrowCheckResult { assert!(tcx.use_ast_borrowck() || tcx.migrate_borrowck()); debug!("borrowck(body_owner_def_id={:?})", owner_def_id); @@ -141,12 +139,14 @@ fn borrowck<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, owner_def_id: DefId) }) } -fn build_borrowck_dataflow_data<'a, 'c, 'tcx, F>(this: &mut BorrowckCtxt<'a, 'tcx>, - force_analysis: bool, - body_id: hir::BodyId, - get_cfg: F) - -> Option> - where F: FnOnce(&mut BorrowckCtxt<'a, 'tcx>) -> &'c cfg::CFG +fn build_borrowck_dataflow_data<'a, 'c, 'tcx, F>( + this: &mut BorrowckCtxt<'a, 'tcx>, + force_analysis: bool, + body_id: hir::BodyId, + get_cfg: F, +) -> Option> +where + F: FnOnce(&mut BorrowckCtxt<'a, 'tcx>) -> &'c cfg::CFG, { // Check the body of fn items. let (all_loans, move_data) = @@ -195,9 +195,8 @@ fn build_borrowck_dataflow_data<'a, 'c, 'tcx, F>(this: &mut BorrowckCtxt<'a, 'tc pub fn build_borrowck_dataflow_data_for_fn<'a, 'tcx>( tcx: TyCtxt<'tcx, 'tcx>, body_id: hir::BodyId, - cfg: &cfg::CFG) - -> (BorrowckCtxt<'a, 'tcx>, AnalysisData<'tcx>) -{ + cfg: &cfg::CFG, +) -> (BorrowckCtxt<'a, 'tcx>, AnalysisData<'tcx>) { let owner_id = tcx.hir().body_owner(body_id); let owner_def_id = tcx.hir().local_def_id(owner_id); let tables = tcx.typeck_tables_of(owner_def_id); @@ -238,7 +237,6 @@ pub struct BorrowckCtxt<'a, 'tcx> { signalled_any_error: Cell, } - impl BorrowckCtxt<'_, 'tcx> { fn signal_error(&self) { self.signalled_any_error.set(SignalledError::SawSomeError); @@ -390,8 +388,7 @@ pub enum LoanPathElem<'tcx> { LpInterior(Option, InteriorKind), } -fn closure_to_block(closure_id: LocalDefId, - tcx: TyCtxt<'_, '_>) -> HirId { +fn closure_to_block(closure_id: LocalDefId, tcx: TyCtxt<'_, '_>) -> HirId { let closure_id = tcx.hir().local_def_id_to_node_id(closure_id); match tcx.hir().get(closure_id) { Node::Expr(expr) => match expr.node { diff --git a/src/librustc_borrowck/borrowck/move_data.rs b/src/librustc_borrowck/borrowck/move_data.rs index 81d5a49a805c9..38bf590a36fb8 100644 --- a/src/librustc_borrowck/borrowck/move_data.rs +++ b/src/librustc_borrowck/borrowck/move_data.rs @@ -47,7 +47,7 @@ pub struct FlowedMoveData<'tcx> { // We could (and maybe should, for efficiency) combine both move // and assign data flow into one, but this way it's easier to // distinguish the bits that correspond to moves and assignments. - pub dfcx_assign: AssignDataFlow<'tcx> + pub dfcx_assign: AssignDataFlow<'tcx>, } /// Index into `MoveData.paths`, used like a pointer @@ -223,8 +223,7 @@ impl MoveData<'tcx> { /// Returns the existing move path index for `lp`, if any, and otherwise adds a new index for /// `lp` and any of its base paths that do not yet have an index. - pub fn move_path(&self, tcx: TyCtxt<'tcx, 'tcx>, - lp: Rc>) -> MovePathIndex { + pub fn move_path(&self, tcx: TyCtxt<'tcx, 'tcx>, lp: Rc>) -> MovePathIndex { if let Some(&index) = self.path_map.borrow().get(&lp) { return index; } @@ -311,10 +310,13 @@ impl MoveData<'tcx> { } /// Adds a new move entry for a move of `lp` that occurs at location `id` with kind `kind`. - pub fn add_move(&self, tcx: TyCtxt<'tcx, 'tcx>, - orig_lp: Rc>, - id: hir::ItemLocalId, - kind: MoveKind) { + pub fn add_move( + &self, + tcx: TyCtxt<'tcx, 'tcx>, + orig_lp: Rc>, + id: hir::ItemLocalId, + kind: MoveKind, + ) { // Moving one union field automatically moves all its fields. Also move siblings of // all parent union fields, moves do not propagate upwards automatically. let mut lp = orig_lp.clone(); @@ -340,10 +342,13 @@ impl MoveData<'tcx> { self.add_move_helper(tcx, orig_lp, id, kind); } - fn add_move_helper(&self, tcx: TyCtxt<'tcx, 'tcx>, - lp: Rc>, - id: hir::ItemLocalId, - kind: MoveKind) { + fn add_move_helper( + &self, + tcx: TyCtxt<'tcx, 'tcx>, + lp: Rc>, + id: hir::ItemLocalId, + kind: MoveKind, + ) { debug!("add_move(lp={:?}, id={:?}, kind={:?})", lp, id, @@ -365,10 +370,13 @@ impl MoveData<'tcx> { /// Adds a new record for an assignment to `lp` that occurs at location `id` with the given /// `span`. - pub fn add_assignment(&self, tcx: TyCtxt<'tcx, 'tcx>, - lp: Rc>, - assign_id: hir::ItemLocalId, - span: Span) { + pub fn add_assignment( + &self, + tcx: TyCtxt<'tcx, 'tcx>, + lp: Rc>, + assign_id: hir::ItemLocalId, + span: Span, + ) { // Assigning to one union field automatically assigns to all its fields. if let LpExtend(ref base_lp, mutbl, LpInterior(opt_variant_id, interior)) = lp.kind { if let ty::Adt(adt_def, _) = base_lp.ty.sty { @@ -395,10 +403,13 @@ impl MoveData<'tcx> { self.add_assignment_helper(tcx, lp, assign_id, span); } - fn add_assignment_helper(&self, tcx: TyCtxt<'tcx, 'tcx>, - lp: Rc>, - assign_id: hir::ItemLocalId, - span: Span) { + fn add_assignment_helper( + &self, + tcx: TyCtxt<'tcx, 'tcx>, + lp: Rc>, + assign_id: hir::ItemLocalId, + span: Span, + ) { debug!("add_assignment(lp={:?}, assign_id={:?}", lp, assign_id); let path_index = self.move_path(tcx, lp.clone()); @@ -427,10 +438,12 @@ impl MoveData<'tcx> { /// Moves are generated by moves and killed by assignments and /// scoping. Assignments are generated by assignment to variables and /// killed by scoping. See `README.md` for more details. - fn add_gen_kills(&self, - bccx: &BorrowckCtxt<'_, 'tcx>, - dfcx_moves: &mut MoveDataFlow<'_>, - dfcx_assign: &mut AssignDataFlow<'_>) { + fn add_gen_kills( + &self, + bccx: &BorrowckCtxt<'_, 'tcx>, + dfcx_moves: &mut MoveDataFlow<'_>, + dfcx_assign: &mut AssignDataFlow<'_>, + ) { for (i, the_move) in self.moves.borrow().iter().enumerate() { dfcx_moves.add_gen(the_move.id, i); } @@ -534,11 +547,13 @@ impl MoveData<'tcx> { ret } - fn kill_moves(&self, - path: MovePathIndex, - kill_id: hir::ItemLocalId, - kill_kind: KillFrom, - dfcx_moves: &mut MoveDataFlow<'_>) { + fn kill_moves( + &self, + path: MovePathIndex, + kill_id: hir::ItemLocalId, + kill_kind: KillFrom, + dfcx_moves: &mut MoveDataFlow<'_>, + ) { // We can only perform kills for paths that refer to a unique location, // since otherwise we may kill a move from one location with an // assignment referring to another location. @@ -556,11 +571,12 @@ impl MoveData<'tcx> { } impl<'tcx> FlowedMoveData<'tcx> { - pub fn new(move_data: MoveData<'tcx>, - bccx: &BorrowckCtxt<'_, 'tcx>, - cfg: &cfg::CFG, - body: &hir::Body) - -> FlowedMoveData<'tcx> { + pub fn new( + move_data: MoveData<'tcx>, + bccx: &BorrowckCtxt<'_, 'tcx>, + cfg: &cfg::CFG, + body: &hir::Body, + ) -> FlowedMoveData<'tcx> { let tcx = bccx.tcx; let mut dfcx_moves = diff --git a/src/librustc_borrowck/dataflow.rs b/src/librustc_borrowck/dataflow.rs index 4e49fa57cb99c..a42fbb72c03a8 100644 --- a/src/librustc_borrowck/dataflow.rs +++ b/src/librustc_borrowck/dataflow.rs @@ -51,7 +51,6 @@ pub struct DataFlowContext<'tcx, O> { // `id_range`, there is a range of words equal to `words_per_id`. // So, to access the bits for any given id, you take a slice of // the full vector (see the method `compute_id_range()`). - /// bits generated as we exit the cfg node. Updated by `add_gen()`. gens: Vec, @@ -82,7 +81,7 @@ pub trait DataFlowOperator : BitwiseOperator { struct PropagationContext<'a, 'tcx, O> { dfcx: &'a mut DataFlowContext<'tcx, O>, - changed: bool + changed: bool, } fn get_cfg_indices<'a>(id: hir::ItemLocalId, @@ -98,7 +97,7 @@ impl<'tcx, O: DataFlowOperator> DataFlowContext<'tcx, O> { } } -impl<'tcx, O:DataFlowOperator> pprust::PpAnn for DataFlowContext<'tcx, O> { +impl<'tcx, O: DataFlowOperator> pprust::PpAnn for DataFlowContext<'tcx, O> { fn nested(&self, state: &mut pprust::State<'_>, nested: pprust::Nested) -> io::Result<()> { pprust::PpAnn::nested(self.tcx.hir(), state, nested) } @@ -225,12 +224,14 @@ pub enum KillFrom { } impl<'tcx, O: DataFlowOperator> DataFlowContext<'tcx, O> { - pub fn new(tcx: TyCtxt<'tcx, 'tcx>, - analysis_name: &'static str, - body: Option<&hir::Body>, - cfg: &cfg::CFG, - oper: O, - bits_per_id: usize) -> DataFlowContext<'tcx, O> { + pub fn new( + tcx: TyCtxt<'tcx, 'tcx>, + analysis_name: &'static str, + body: Option<&hir::Body>, + cfg: &cfg::CFG, + oper: O, + bits_per_id: usize, + ) -> DataFlowContext<'tcx, O> { let usize_bits = mem::size_of::() * 8; let words_per_id = (bits_per_id + usize_bits - 1) / usize_bits; let num_nodes = cfg.graph.all_nodes().len(); diff --git a/src/librustc_borrowck/graphviz.rs b/src/librustc_borrowck/graphviz.rs index 69c0aa0c6f766..1f2480666959e 100644 --- a/src/librustc_borrowck/graphviz.rs +++ b/src/librustc_borrowck/graphviz.rs @@ -61,11 +61,14 @@ impl<'a, 'tcx> DataflowLabeller<'a, 'tcx> { } } - fn build_set(&self, - e: EntryOrExit, - cfgidx: CFGIndex, - dfcx: &DataFlowContext<'tcx, O>, - mut to_lp: F) -> String where + fn build_set( + &self, + e: EntryOrExit, + cfgidx: CFGIndex, + dfcx: &DataFlowContext<'tcx, O>, + mut to_lp: F, + ) -> String + where F: FnMut(usize) -> Rc>, { let mut saw_some = false; diff --git a/src/librustc_codegen_llvm/base.rs b/src/librustc_codegen_llvm/base.rs index 60c141ab566da..c552cc9223862 100644 --- a/src/librustc_codegen_llvm/base.rs +++ b/src/librustc_codegen_llvm/base.rs @@ -44,7 +44,7 @@ use crate::value::Value; pub fn write_compressed_metadata<'a, 'gcx>( tcx: TyCtxt<'gcx, 'gcx>, metadata: &EncodedMetadata, - llvm_module: &mut ModuleLlvm + llvm_module: &mut ModuleLlvm, ) { use std::io::Write; use flate2::Compression; diff --git a/src/librustc_codegen_llvm/context.rs b/src/librustc_codegen_llvm/context.rs index d0b2b6846f788..0a780fecf41de 100644 --- a/src/librustc_codegen_llvm/context.rs +++ b/src/librustc_codegen_llvm/context.rs @@ -47,8 +47,8 @@ pub struct CodegenCx<'ll, 'tcx: 'll> { /// Cache instances of monomorphic and polymorphic items pub instances: RefCell, &'ll Value>>, /// Cache generated vtables - pub vtables: RefCell, Option>), &'ll Value>>, + pub vtables: + RefCell, Option>), &'ll Value>>, /// Cache of constant strings, pub const_cstr_cache: RefCell>, @@ -207,10 +207,11 @@ pub unsafe fn create_module( } impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { - crate fn new(tcx: TyCtxt<'tcx, 'tcx>, - codegen_unit: Arc>, - llvm_module: &'ll crate::ModuleLlvm) - -> Self { + crate fn new( + tcx: TyCtxt<'tcx, 'tcx>, + codegen_unit: Arc>, + llvm_module: &'ll crate::ModuleLlvm, + ) -> Self { // An interesting part of Windows which MSVC forces our hand on (and // apparently MinGW didn't) is the usage of `dllimport` and `dllexport` // attributes in LLVM IR as well as native dependencies (in C these diff --git a/src/librustc_codegen_llvm/debuginfo/metadata.rs b/src/librustc_codegen_llvm/debuginfo/metadata.rs index 4fad236c32dd3..c4d9f79e8d301 100644 --- a/src/librustc_codegen_llvm/debuginfo/metadata.rs +++ b/src/librustc_codegen_llvm/debuginfo/metadata.rs @@ -894,10 +894,11 @@ fn pointer_type_metadata( } } -pub fn compile_unit_metadata(tcx: TyCtxt<'_, '_>, - codegen_unit_name: &str, - debug_context: &CrateDebugContext<'ll, '_>) - -> &'ll DIDescriptor { +pub fn compile_unit_metadata( + tcx: TyCtxt<'_, '_>, + codegen_unit_name: &str, + debug_context: &CrateDebugContext<'ll, '_>, +) -> &'ll DIDescriptor { let mut name_in_debuginfo = match tcx.sess.local_crate_source_file { Some(ref path) => path.clone(), None => PathBuf::from(&*tcx.crate_name(LOCAL_CRATE).as_str()), diff --git a/src/librustc_codegen_llvm/lib.rs b/src/librustc_codegen_llvm/lib.rs index 17a6fe090b905..2e922ad5fcd3b 100644 --- a/src/librustc_codegen_llvm/lib.rs +++ b/src/librustc_codegen_llvm/lib.rs @@ -111,7 +111,7 @@ impl ExtraBackendMethods for LlvmCodegenBackend { &self, tcx: TyCtxt<'gcx, 'gcx>, metadata: &EncodedMetadata, - llvm_module: &mut ModuleLlvm + llvm_module: &mut ModuleLlvm, ) { base::write_compressed_metadata(tcx, metadata, llvm_module) } @@ -119,7 +119,7 @@ impl ExtraBackendMethods for LlvmCodegenBackend { &self, tcx: TyCtxt<'gcx, 'gcx>, mods: &mut ModuleLlvm, - kind: AllocatorKind + kind: AllocatorKind, ) { unsafe { allocator::codegen(tcx, mods, kind) } } @@ -289,7 +289,7 @@ impl CodegenBackend for LlvmCodegenBackend { tcx: TyCtxt<'tcx, 'tcx>, metadata: EncodedMetadata, need_metadata_module: bool, - rx: mpsc::Receiver> + rx: mpsc::Receiver>, ) -> Box { box rustc_codegen_ssa::base::codegen_crate( LlvmCodegenBackend(()), tcx, metadata, need_metadata_module, rx) diff --git a/src/librustc_codegen_ssa/back/symbol_export.rs b/src/librustc_codegen_ssa/back/symbol_export.rs index e805cb0003f05..e1693b7c2ef1b 100644 --- a/src/librustc_codegen_ssa/back/symbol_export.rs +++ b/src/librustc_codegen_ssa/back/symbol_export.rs @@ -46,10 +46,10 @@ pub fn crates_export_threshold(crate_types: &[config::CrateType]) -> SymbolExpor } } -fn reachable_non_generics_provider<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - cnum: CrateNum) - -> &'tcx DefIdMap -{ +fn reachable_non_generics_provider<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + cnum: CrateNum, +) -> &'tcx DefIdMap { assert_eq!(cnum, LOCAL_CRATE); if !tcx.sess.opts.output_types.should_codegen() { @@ -157,9 +157,7 @@ fn reachable_non_generics_provider<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, tcx.arena.alloc(reachable_non_generics) } -fn is_reachable_non_generic_provider_local<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - def_id: DefId) - -> bool { +fn is_reachable_non_generic_provider_local<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> bool { let export_threshold = threshold(tcx); if let Some(&level) = tcx.reachable_non_generics(def_id.krate).get(&def_id) { @@ -169,17 +167,14 @@ fn is_reachable_non_generic_provider_local<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, } } -fn is_reachable_non_generic_provider_extern<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - def_id: DefId) - -> bool { +fn is_reachable_non_generic_provider_extern<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> bool { tcx.reachable_non_generics(def_id.krate).contains_key(&def_id) } -fn exported_symbols_provider_local<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - cnum: CrateNum) - -> Arc, - SymbolExportLevel)>> -{ +fn exported_symbols_provider_local<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + cnum: CrateNum, +) -> Arc, SymbolExportLevel)>> { assert_eq!(cnum, LOCAL_CRATE); if !tcx.sess.opts.output_types.should_codegen() { @@ -280,9 +275,8 @@ fn exported_symbols_provider_local<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, fn upstream_monomorphizations_provider<'tcx>( tcx: TyCtxt<'tcx, 'tcx>, - cnum: CrateNum) - -> &'tcx DefIdMap, CrateNum>> -{ + cnum: CrateNum, +) -> &'tcx DefIdMap, CrateNum>> { debug_assert!(cnum == LOCAL_CRATE); let cnums = tcx.all_crate_nums(LOCAL_CRATE); @@ -330,9 +324,8 @@ fn upstream_monomorphizations_provider<'tcx>( fn upstream_monomorphizations_for_provider<'tcx>( tcx: TyCtxt<'tcx, 'tcx>, - def_id: DefId) - -> Option<&'tcx FxHashMap, CrateNum>> -{ + def_id: DefId, +) -> Option<&'tcx FxHashMap, CrateNum>> { debug_assert!(!def_id.is_local()); tcx.upstream_monomorphizations(LOCAL_CRATE).get(&def_id) } diff --git a/src/librustc_codegen_ssa/back/write.rs b/src/librustc_codegen_ssa/back/write.rs index 894884e19c3fd..5a7ca4af4b867 100644 --- a/src/librustc_codegen_ssa/back/write.rs +++ b/src/librustc_codegen_ssa/back/write.rs @@ -378,7 +378,7 @@ pub fn start_async_codegen( tcx: TyCtxt<'_, '_>, metadata: EncodedMetadata, coordinator_receive: Receiver>, - total_cgus: usize + total_cgus: usize, ) -> OngoingCodegen { let sess = tcx.sess; let crate_name = tcx.crate_name(LOCAL_CRATE); @@ -1005,7 +1005,7 @@ fn start_executing_work( jobserver: Client, modules_config: Arc, metadata_config: Arc, - allocator_config: Arc + allocator_config: Arc, ) -> thread::JoinHandle> { let coordinator_send = tcx.tx_to_llvm_workers.lock().clone(); let sess = tcx.sess; @@ -1861,9 +1861,11 @@ impl OngoingCodegen { }, work_products) } - pub fn submit_pre_codegened_module_to_llvm(&self, - tcx: TyCtxt<'_, '_>, - module: ModuleCodegen) { + pub fn submit_pre_codegened_module_to_llvm( + &self, + tcx: TyCtxt<'_, '_>, + module: ModuleCodegen, + ) { self.wait_for_signal_to_codegen_item(); self.check_for_errors(tcx.sess); @@ -1913,7 +1915,7 @@ pub fn submit_codegened_module_to_llvm( _backend: &B, tcx: TyCtxt<'_, '_>, module: ModuleCodegen, - cost: u64 + cost: u64, ) { let llvm_work_item = WorkItem::Optimize(module); drop(tcx.tx_to_llvm_workers.lock().send(Box::new(Message::CodegenDone:: { @@ -1925,7 +1927,7 @@ pub fn submit_codegened_module_to_llvm( pub fn submit_post_lto_module_to_llvm( _backend: &B, tcx: TyCtxt<'_, '_>, - module: CachedModuleCodegen + module: CachedModuleCodegen, ) { let llvm_work_item = WorkItem::CopyPostLtoArtifacts(module); drop(tcx.tx_to_llvm_workers.lock().send(Box::new(Message::CodegenDone:: { @@ -1937,7 +1939,7 @@ pub fn submit_post_lto_module_to_llvm( pub fn submit_pre_lto_module_to_llvm( _backend: &B, tcx: TyCtxt<'_, '_>, - module: CachedModuleCodegen + module: CachedModuleCodegen, ) { let filename = pre_lto_bitcode_filename(&module.name); let bc_path = in_incr_comp_dir_sess(tcx.sess, &filename); diff --git a/src/librustc_codegen_ssa/base.rs b/src/librustc_codegen_ssa/base.rs index 517d19c56a565..9c34b5e4f7927 100644 --- a/src/librustc_codegen_ssa/base.rs +++ b/src/librustc_codegen_ssa/base.rs @@ -483,9 +483,8 @@ pub fn codegen_crate( tcx: TyCtxt<'tcx, 'tcx>, metadata: EncodedMetadata, need_metadata_module: bool, - rx: mpsc::Receiver> + rx: mpsc::Receiver>, ) -> OngoingCodegen { - check_for_rustc_errors_attr(tcx); // Skip crate items and just output metadata in -Z no-codegen mode. @@ -776,7 +775,7 @@ impl CrateInfo { info.missing_lang_items.insert(cnum, missing); } - return info + return info; } } @@ -850,9 +849,7 @@ pub fn provide_both(providers: &mut Providers<'_>) { }; } -fn determine_cgu_reuse<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - cgu: &CodegenUnit<'tcx>) - -> CguReuse { +fn determine_cgu_reuse<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, cgu: &CodegenUnit<'tcx>) -> CguReuse { if !tcx.dep_graph.is_fully_enabled() { return CguReuse::No } diff --git a/src/librustc_codegen_ssa/common.rs b/src/librustc_codegen_ssa/common.rs index 82af0049affc9..66baf06bfb46d 100644 --- a/src/librustc_codegen_ssa/common.rs +++ b/src/librustc_codegen_ssa/common.rs @@ -122,11 +122,7 @@ mod temp_stable_hash_impls { } } -pub fn langcall(tcx: TyCtxt<'_, '_>, - span: Option, - msg: &str, - li: LangItem) - -> DefId { +pub fn langcall(tcx: TyCtxt<'_, '_>, span: Option, msg: &str, li: LangItem) -> DefId { tcx.lang_items().require(li).unwrap_or_else(|s| { let msg = format!("{} {}", msg, s); match span { diff --git a/src/librustc_codegen_ssa/debuginfo/type_names.rs b/src/librustc_codegen_ssa/debuginfo/type_names.rs index 50847b09805e9..943fd254030d2 100644 --- a/src/librustc_codegen_ssa/debuginfo/type_names.rs +++ b/src/librustc_codegen_ssa/debuginfo/type_names.rs @@ -8,10 +8,11 @@ use rustc_data_structures::fx::FxHashSet; // any caching, i.e., calling the function twice with the same type will also do // the work twice. The `qualified` parameter only affects the first level of the // type name, further levels (i.e., type parameters) are always fully qualified. -pub fn compute_debuginfo_type_name<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - t: Ty<'tcx>, - qualified: bool) - -> String { +pub fn compute_debuginfo_type_name<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + t: Ty<'tcx>, + qualified: bool, +) -> String { let mut result = String::with_capacity(64); let mut visited = FxHashSet::default(); push_debuginfo_type_name(tcx, t, qualified, &mut result, &mut visited); @@ -20,12 +21,13 @@ pub fn compute_debuginfo_type_name<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, // Pushes the name of the type as it should be stored in debuginfo on the // `output` String. See also compute_debuginfo_type_name(). -pub fn push_debuginfo_type_name<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - t: Ty<'tcx>, - qualified: bool, - output: &mut String, - visited: &mut FxHashSet>) { - +pub fn push_debuginfo_type_name<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + t: Ty<'tcx>, + qualified: bool, + output: &mut String, + visited: &mut FxHashSet>, +) { // When targeting MSVC, emit C++ style type names for compatibility with // .natvis visualizers (and perhaps other existing native debuggers?) let cpp_like_names = tcx.sess.target.target.options.is_like_msvc; @@ -208,10 +210,12 @@ pub fn push_debuginfo_type_name<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, } } - fn push_item_name(tcx: TyCtxt<'tcx, 'tcx>, - def_id: DefId, - qualified: bool, - output: &mut String) { + fn push_item_name( + tcx: TyCtxt<'tcx, 'tcx>, + def_id: DefId, + qualified: bool, + output: &mut String, + ) { if qualified { output.push_str(&tcx.crate_name(def_id.krate).as_str()); for path_element in tcx.def_path(def_id).data { @@ -228,10 +232,12 @@ pub fn push_debuginfo_type_name<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, // reconstructed for items from non-local crates. For local crates, this // would be possible but with inlining and LTO we have to use the least // common denominator - otherwise we would run into conflicts. - fn push_type_params<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - substs: SubstsRef<'tcx>, - output: &mut String, - visited: &mut FxHashSet>) { + fn push_type_params<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + substs: SubstsRef<'tcx>, + output: &mut String, + visited: &mut FxHashSet>, + ) { if substs.types().next().is_none() { return; } diff --git a/src/librustc_codegen_ssa/traits/backend.rs b/src/librustc_codegen_ssa/traits/backend.rs index e6532f47bc86f..160e554f8565c 100644 --- a/src/librustc_codegen_ssa/traits/backend.rs +++ b/src/librustc_codegen_ssa/traits/backend.rs @@ -42,13 +42,9 @@ pub trait ExtraBackendMethods: CodegenBackend + WriteBackendMethods + Sized + Se &self, tcx: TyCtxt<'gcx, 'gcx>, mods: &mut Self::Module, - kind: AllocatorKind - ); - fn compile_codegen_unit<'a, 'tcx: 'a>( - &self, - tcx: TyCtxt<'tcx, 'tcx>, - cgu_name: InternedString, + kind: AllocatorKind, ); + fn compile_codegen_unit<'a, 'tcx: 'a>(&self, tcx: TyCtxt<'tcx, 'tcx>, cgu_name: InternedString); // If find_features is true this won't access `sess.crate_types` by assuming // that `is_pie_binary` is false. When we discover LLVM target features // `sess.crate_types` is uninitialized so we cannot access it. diff --git a/src/librustc_codegen_utils/codegen_backend.rs b/src/librustc_codegen_utils/codegen_backend.rs index 521ef23b825fd..1bf03c0c45c6d 100644 --- a/src/librustc_codegen_utils/codegen_backend.rs +++ b/src/librustc_codegen_utils/codegen_backend.rs @@ -6,7 +6,6 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")] #![deny(warnings)] - #![feature(box_syntax)] use std::any::Any; @@ -39,7 +38,7 @@ pub trait CodegenBackend { tcx: TyCtxt<'tcx, 'tcx>, metadata: EncodedMetadata, need_metadata_module: bool, - rx: mpsc::Receiver> + rx: mpsc::Receiver>, ) -> Box; /// This is called on the returned `Box` from `codegen_backend` diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index a447baa7f41a8..4f19a7bbc8b92 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -154,12 +154,14 @@ pub fn parse_pretty(sess: &Session, impl PpSourceMode { /// Constructs a `PrinterSupport` object and passes it to `f`. - fn call_with_pp_support<'tcx, A, F>(&self, - sess: &'tcx Session, - tcx: Option>, - f: F) - -> A - where F: FnOnce(&dyn PrinterSupport) -> A + fn call_with_pp_support<'tcx, A, F>( + &self, + sess: &'tcx Session, + tcx: Option>, + f: F, + ) -> A + where + F: FnOnce(&dyn PrinterSupport) -> A, { match *self { PpmNormal | PpmEveryBodyLoops | PpmExpanded => { @@ -186,12 +188,9 @@ impl PpSourceMode { _ => panic!("Should use call_with_pp_support_hir"), } } - fn call_with_pp_support_hir<'tcx, A, F>( - &self, - tcx: TyCtxt<'tcx, 'tcx>, - f: F - ) -> A - where F: FnOnce(&dyn HirPrinterSupport<'_>, &hir::Crate) -> A + fn call_with_pp_support_hir<'tcx, A, F>(&self, tcx: TyCtxt<'tcx, 'tcx>, f: F) -> A + where + F: FnOnce(&dyn HirPrinterSupport<'_>, &hir::Crate) -> A, { match *self { PpmNormal => { @@ -454,7 +453,6 @@ impl<'a> pprust::PpAnn for HygieneAnnotation<'a> { } } - struct TypedAnnotation<'a, 'tcx: 'a> { tcx: TyCtxt<'tcx, 'tcx>, tables: Cell<&'a ty::TypeckTables<'tcx>>, @@ -617,12 +615,13 @@ impl UserIdentifiedItem { } } -fn print_flowgraph<'tcx, W: Write>(variants: Vec, - tcx: TyCtxt<'tcx, 'tcx>, - code: blocks::Code<'tcx>, - mode: PpFlowGraphMode, - mut out: W) - -> io::Result<()> { +fn print_flowgraph<'tcx, W: Write>( + variants: Vec, + tcx: TyCtxt<'tcx, 'tcx>, + code: blocks::Code<'tcx>, + mode: PpFlowGraphMode, + mut out: W, +) -> io::Result<()> { let body_id = match code { blocks::Code::Expr(expr) => { // Find the function this expression is from. @@ -760,7 +759,8 @@ pub fn print_after_hir_lowering<'tcx>( krate: &ast::Crate, ppm: PpMode, opt_uii: Option, - ofile: Option<&Path>) { + ofile: Option<&Path>, +) { if ppm.needs_analysis() { abort_on_err(print_with_analysis( tcx, @@ -869,7 +869,7 @@ fn print_with_analysis<'tcx>( tcx: TyCtxt<'tcx, 'tcx>, ppm: PpMode, uii: Option, - ofile: Option<&Path> + ofile: Option<&Path>, ) -> Result<(), ErrorReported> { let nodeid = if let Some(uii) = uii { debug!("pretty printing for {:?}", uii); diff --git a/src/librustc_incremental/assert_dep_graph.rs b/src/librustc_incremental/assert_dep_graph.rs index 5e41b8c9efda2..0ddcc42ef123c 100644 --- a/src/librustc_incremental/assert_dep_graph.rs +++ b/src/librustc_incremental/assert_dep_graph.rs @@ -184,10 +184,11 @@ impl Visitor<'tcx> for IfThisChanged<'tcx> { } } -fn check_paths<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - if_this_changed: &Sources, - then_this_would_need: &Targets) -{ +fn check_paths<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + if_this_changed: &Sources, + then_this_would_need: &Targets, +) { // Return early here so as not to construct the query, which is not cheap. if if_this_changed.is_empty() { for &(target_span, _, _, _) in then_this_would_need { diff --git a/src/librustc_incremental/persist/save.rs b/src/librustc_incremental/persist/save.rs index 6f175acebf95d..f31718fe50776 100644 --- a/src/librustc_incremental/persist/save.rs +++ b/src/librustc_incremental/persist/save.rs @@ -129,8 +129,7 @@ fn save_in(sess: &Session, path_buf: PathBuf, encode: F) } } -fn encode_dep_graph(tcx: TyCtxt<'_, '_>, - encoder: &mut Encoder) { +fn encode_dep_graph(tcx: TyCtxt<'_, '_>, encoder: &mut Encoder) { // First encode the commandline arguments hash tcx.sess.opts.dep_tracking_hash().encode(encoder).unwrap(); @@ -234,8 +233,7 @@ fn encode_work_product_index(work_products: &FxHashMap, - encoder: &mut Encoder) { +fn encode_query_cache(tcx: TyCtxt<'_, '_>, encoder: &mut Encoder) { time(tcx.sess, "serialize query result cache", || { tcx.serialize_query_result_cache(encoder).unwrap(); }) diff --git a/src/librustc_interface/passes.rs b/src/librustc_interface/passes.rs index 2fc78dcddd040..d76ae18741213 100644 --- a/src/librustc_interface/passes.rs +++ b/src/librustc_interface/passes.rs @@ -798,7 +798,7 @@ declare_box_region_type!( impl BoxedGlobalCtxt { pub fn enter(&mut self, f: F) -> R where - F: for<'tcx> FnOnce(TyCtxt<'tcx, 'tcx>) -> R + F: for<'tcx> FnOnce(TyCtxt<'tcx, 'tcx>) -> R, { self.access(|gcx| ty::tls::enter_global(gcx, |tcx| f(tcx))) } @@ -878,10 +878,7 @@ pub fn create_global_ctxt( /// Runs the resolution, type-checking, region checking and other /// miscellaneous analysis passes on the crate. -fn analysis<'tcx>( - tcx: TyCtxt<'tcx, 'tcx>, - cnum: CrateNum, -) -> Result<()> { +fn analysis<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, cnum: CrateNum) -> Result<()> { assert_eq!(cnum, LOCAL_CRATE); let sess = tcx.sess; diff --git a/src/librustc_interface/proc_macro_decls.rs b/src/librustc_interface/proc_macro_decls.rs index 864b59d8a84c4..49f892ac299f4 100644 --- a/src/librustc_interface/proc_macro_decls.rs +++ b/src/librustc_interface/proc_macro_decls.rs @@ -10,10 +10,7 @@ pub fn find<'tcx>(tcx: TyCtxt<'tcx, 'tcx>) -> Option { tcx.proc_macro_decls_static(LOCAL_CRATE) } -fn proc_macro_decls_static<'tcx>( - tcx: TyCtxt<'tcx, 'tcx>, - cnum: CrateNum, -) -> Option { +fn proc_macro_decls_static<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, cnum: CrateNum) -> Option { assert_eq!(cnum, LOCAL_CRATE); let mut finder = Finder { decls: None }; diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index 494f0b6676052..edaacf7749407 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -555,11 +555,12 @@ fn ty_is_known_nonnull<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, ty: Ty<'tcx>) -> bool { /// to function pointers, references, core::num::NonZero*, /// core::ptr::NonNull, and #[repr(transparent)] newtypes. /// FIXME: This duplicates code in codegen. -fn is_repr_nullable_ptr<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - ty: Ty<'tcx>, - ty_def: &'tcx ty::AdtDef, - substs: SubstsRef<'tcx>) - -> bool { +fn is_repr_nullable_ptr<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + ty: Ty<'tcx>, + ty_def: &'tcx ty::AdtDef, + substs: SubstsRef<'tcx>, +) -> bool { if ty_def.variants.len() != 2 { return false; } diff --git a/src/librustc_macros/src/query.rs b/src/librustc_macros/src/query.rs index bb6595b5a8036..8b7dc557c59ca 100644 --- a/src/librustc_macros/src/query.rs +++ b/src/librustc_macros/src/query.rs @@ -314,7 +314,7 @@ fn process_modifiers(query: &mut Query) -> QueryModifiers { fn add_query_description_impl( query: &Query, modifiers: QueryModifiers, - impls: &mut proc_macro2::TokenStream + impls: &mut proc_macro2::TokenStream, ) { let name = &query.name; let arg = &query.arg; diff --git a/src/librustc_metadata/cstore_impl.rs b/src/librustc_metadata/cstore_impl.rs index 75020693461a4..7d07331cfff70 100644 --- a/src/librustc_metadata/cstore_impl.rs +++ b/src/librustc_metadata/cstore_impl.rs @@ -550,10 +550,7 @@ impl CrateStore for cstore::CStore { self.do_postorder_cnums_untracked() } - fn encode_metadata<'tcx>(&self, - tcx: TyCtxt<'tcx, 'tcx>) - -> EncodedMetadata - { + fn encode_metadata<'tcx>(&self, tcx: TyCtxt<'tcx, 'tcx>) -> EncodedMetadata { encoder::encode_metadata(tcx) } diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index 017c38e0f9d50..9ec31e33f9e06 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -55,7 +55,9 @@ pub trait Metadata<'a, 'tcx>: Copy { fn raw_bytes(self) -> &'a [u8]; fn cdata(self) -> Option<&'a CrateMetadata> { None } fn sess(self) -> Option<&'a Session> { None } - fn tcx(self) -> Option> { None } + fn tcx(self) -> Option> { + None + } fn decoder(self, pos: usize) -> DecodeContext<'a, 'tcx> { let tcx = self.tcx(); @@ -170,7 +172,6 @@ impl<'a, 'tcx> DecodeContext<'a, 'tcx> { } impl<'a, 'tcx> TyDecoder<'tcx> for DecodeContext<'a, 'tcx> { - #[inline] fn tcx(&self) -> TyCtxt<'tcx, 'tcx> { self.tcx.expect("missing TyCtxt in DecodeContext") @@ -551,7 +552,7 @@ impl<'a, 'tcx> CrateMetadata { item: &Entry<'_>, index: DefIndex, parent_did: DefId, - adt_kind: ty::AdtKind + adt_kind: ty::AdtKind, ) -> ty::VariantDef { let data = match item.kind { EntryKind::Variant(data) | @@ -588,10 +589,7 @@ impl<'a, 'tcx> CrateMetadata { ) } - pub fn get_adt_def(&self, - item_id: DefIndex, - tcx: TyCtxt<'tcx, 'tcx>) - -> &'tcx ty::AdtDef { + pub fn get_adt_def(&self, item_id: DefIndex, tcx: TyCtxt<'tcx, 'tcx>) -> &'tcx ty::AdtDef { let item = self.entry(item_id); let did = self.local_def_id(item_id); @@ -616,24 +614,27 @@ impl<'a, 'tcx> CrateMetadata { tcx.alloc_adt_def(did, kind, variants, repr) } - pub fn get_predicates(&self, - item_id: DefIndex, - tcx: TyCtxt<'tcx, 'tcx>) - -> ty::GenericPredicates<'tcx> { + pub fn get_predicates( + &self, + item_id: DefIndex, + tcx: TyCtxt<'tcx, 'tcx>, + ) -> ty::GenericPredicates<'tcx> { self.entry(item_id).predicates.unwrap().decode((self, tcx)) } - pub fn get_predicates_defined_on(&self, - item_id: DefIndex, - tcx: TyCtxt<'tcx, 'tcx>) - -> ty::GenericPredicates<'tcx> { + pub fn get_predicates_defined_on( + &self, + item_id: DefIndex, + tcx: TyCtxt<'tcx, 'tcx>, + ) -> ty::GenericPredicates<'tcx> { self.entry(item_id).predicates_defined_on.unwrap().decode((self, tcx)) } - pub fn get_super_predicates(&self, - item_id: DefIndex, - tcx: TyCtxt<'tcx, 'tcx>) - -> ty::GenericPredicates<'tcx> { + pub fn get_super_predicates( + &self, + item_id: DefIndex, + tcx: TyCtxt<'tcx, 'tcx>, + ) -> ty::GenericPredicates<'tcx> { let super_predicates = match self.entry(item_id).kind { EntryKind::Trait(data) => data.decode(self).super_predicates, EntryKind::TraitAlias(data) => data.decode(self).super_predicates, @@ -700,10 +701,11 @@ impl<'a, 'tcx> CrateMetadata { self.get_impl_data(id).coerce_unsized_info } - pub fn get_impl_trait(&self, - id: DefIndex, - tcx: TyCtxt<'tcx, 'tcx>) - -> Option> { + pub fn get_impl_trait( + &self, + id: DefIndex, + tcx: TyCtxt<'tcx, 'tcx>, + ) -> Option> { self.get_impl_data(id).trait_ref.map(|tr| tr.decode((self, tcx))) } @@ -720,10 +722,7 @@ impl<'a, 'tcx> CrateMetadata { } /// Iterates over the language items in the given crate. - pub fn get_lang_items( - &self, - tcx: TyCtxt<'tcx, '_>, - ) -> &'tcx [(DefId, usize)] { + pub fn get_lang_items(&self, tcx: TyCtxt<'tcx, '_>) -> &'tcx [(DefId, usize)] { if self.proc_macros.is_some() { // Proc macro crates do not export any lang-items to the target. &[] @@ -884,10 +883,11 @@ impl<'a, 'tcx> CrateMetadata { self.maybe_entry(id).and_then(|item| item.decode(self).mir).is_some() } - pub fn maybe_get_optimized_mir(&self, - tcx: TyCtxt<'tcx, 'tcx>, - id: DefIndex) - -> Option> { + pub fn maybe_get_optimized_mir( + &self, + tcx: TyCtxt<'tcx, 'tcx>, + id: DefIndex, + ) -> Option> { match self.is_proc_macro(id) { true => None, false => self.entry(id).mir.map(|mir| mir.decode((self, tcx))), @@ -1020,7 +1020,7 @@ impl<'a, 'tcx> CrateMetadata { pub fn get_inherent_implementations_for_type( &self, tcx: TyCtxt<'tcx, '_>, - id: DefIndex + id: DefIndex, ) -> &'tcx [DefId] { tcx.arena.alloc_from_iter(self.entry(id) .inherent_impls @@ -1085,10 +1085,7 @@ impl<'a, 'tcx> CrateMetadata { } } - pub fn get_foreign_modules( - &self, - tcx: TyCtxt<'tcx, '_>, - ) -> &'tcx [ForeignModule] { + pub fn get_foreign_modules(&self, tcx: TyCtxt<'tcx, '_>) -> &'tcx [ForeignModule] { if self.proc_macros.is_some() { // Proc macro crates do not have any *target* foreign modules. &[] @@ -1111,10 +1108,7 @@ impl<'a, 'tcx> CrateMetadata { })) } - pub fn get_missing_lang_items( - &self, - tcx: TyCtxt<'tcx, '_>, - ) -> &'tcx [lang_items::LangItem] { + pub fn get_missing_lang_items(&self, tcx: TyCtxt<'tcx, '_>) -> &'tcx [lang_items::LangItem] { if self.proc_macros.is_some() { // Proc macro crates do not depend on any target weak lang-items. &[] @@ -1135,9 +1129,10 @@ impl<'a, 'tcx> CrateMetadata { arg_names.decode(self).collect() } - pub fn exported_symbols(&self, - tcx: TyCtxt<'tcx, 'tcx>) - -> Vec<(ExportedSymbol<'tcx>, SymbolExportLevel)> { + pub fn exported_symbols( + &self, + tcx: TyCtxt<'tcx, 'tcx>, + ) -> Vec<(ExportedSymbol<'tcx>, SymbolExportLevel)> { if self.proc_macros.is_some() { // If this crate is a custom derive crate, then we're not even going to // link those in so we skip those crates. @@ -1192,10 +1187,7 @@ impl<'a, 'tcx> CrateMetadata { } } - pub fn fn_sig(&self, - id: DefIndex, - tcx: TyCtxt<'tcx, 'tcx>) - -> ty::PolyFnSig<'tcx> { + pub fn fn_sig(&self, id: DefIndex, tcx: TyCtxt<'tcx, 'tcx>) -> ty::PolyFnSig<'tcx> { let sig = match self.entry(id).kind { EntryKind::Fn(data) | EntryKind::ForeignFn(data) => data.decode(self).sig, diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index ee7ffa1b06628..5c73ee43c059c 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -217,8 +217,7 @@ impl<'tcx> SpecializedEncoder for EncodeContext<'tcx> { } } -impl<'tcx, T: Encodable> SpecializedEncoder> -for EncodeContext<'tcx> { +impl<'tcx, T: Encodable> SpecializedEncoder> for EncodeContext<'tcx> { fn specialized_encode(&mut self, _: &mir::ClearCrossCrate) -> Result<(), Self::Error> { @@ -233,7 +232,6 @@ impl<'tcx> TyEncoder for EncodeContext<'tcx> { } impl<'tcx> EncodeContext<'tcx> { - fn emit_node R, R>(&mut self, f: F) -> R { assert_eq!(self.lazy_state, LazyState::NoNode); let pos = self.position(); @@ -1865,9 +1863,7 @@ impl<'tcx, 'v> ItemLikeVisitor<'v> for ImplVisitor<'tcx> { // will allow us to slice the metadata to the precise length that we just // generated regardless of trailing bytes that end up in it. -pub fn encode_metadata<'tcx>(tcx: TyCtxt<'tcx, 'tcx>) - -> EncodedMetadata -{ +pub fn encode_metadata<'tcx>(tcx: TyCtxt<'tcx, 'tcx>) -> EncodedMetadata { let mut encoder = opaque::Encoder::new(vec![]); encoder.emit_raw_bytes(METADATA_HEADER); diff --git a/src/librustc_metadata/foreign_modules.rs b/src/librustc_metadata/foreign_modules.rs index 7520fb607c5fa..63260312fa6de 100644 --- a/src/librustc_metadata/foreign_modules.rs +++ b/src/librustc_metadata/foreign_modules.rs @@ -9,7 +9,7 @@ pub fn collect<'tcx>(tcx: TyCtxt<'tcx, 'tcx>) -> Vec { modules: Vec::new(), }; tcx.hir().krate().visit_all_item_likes(&mut collector); - return collector.modules + return collector.modules; } struct Collector<'tcx> { diff --git a/src/librustc_metadata/link_args.rs b/src/librustc_metadata/link_args.rs index 1c50b0f293a62..576b0da1fd8e2 100644 --- a/src/librustc_metadata/link_args.rs +++ b/src/librustc_metadata/link_args.rs @@ -18,7 +18,7 @@ pub fn collect<'tcx>(tcx: TyCtxt<'tcx, 'tcx>) -> Vec { } } - return collector.args + return collector.args; } struct Collector { diff --git a/src/librustc_metadata/native_libs.rs b/src/librustc_metadata/native_libs.rs index bcd91eb22cf1f..ef74fdf8a9e54 100644 --- a/src/librustc_metadata/native_libs.rs +++ b/src/librustc_metadata/native_libs.rs @@ -18,7 +18,7 @@ pub fn collect<'tcx>(tcx: TyCtxt<'tcx, 'tcx>) -> Vec { }; tcx.hir().krate().visit_all_item_likes(&mut collector); collector.process_command_line(); - return collector.libs + return collector.libs; } pub fn relevant_lib(sess: &Session, lib: &NativeLibrary) -> bool { diff --git a/src/librustc_mir/borrow_check/borrow_set.rs b/src/librustc_mir/borrow_check/borrow_set.rs index 85a5669dfe142..5accf2abdadbf 100644 --- a/src/librustc_mir/borrow_check/borrow_set.rs +++ b/src/librustc_mir/borrow_check/borrow_set.rs @@ -125,9 +125,8 @@ impl<'tcx> BorrowSet<'tcx> { tcx: TyCtxt<'_, 'tcx>, body: &Body<'tcx>, locals_are_invalidated_at_exit: bool, - move_data: &MoveData<'tcx> + move_data: &MoveData<'tcx>, ) -> Self { - let mut visitor = GatherBorrows { tcx, body, diff --git a/src/librustc_mir/borrow_check/path_utils.rs b/src/librustc_mir/borrow_check/path_utils.rs index 10a92253f9f64..978f12af9a1ad 100644 --- a/src/librustc_mir/borrow_check/path_utils.rs +++ b/src/librustc_mir/borrow_check/path_utils.rs @@ -22,7 +22,7 @@ pub(super) enum Control { } /// Encapsulates the idea of iterating over every borrow that involves a particular path -pub(super) fn each_borrow_involving_path<'tcx, 'gcx: 'tcx, F, I, S> ( +pub(super) fn each_borrow_involving_path<'tcx, 'gcx: 'tcx, F, I, S>( s: &mut S, tcx: TyCtxt<'gcx, 'tcx>, body: &Body<'tcx>, @@ -33,7 +33,7 @@ pub(super) fn each_borrow_involving_path<'tcx, 'gcx: 'tcx, F, I, S> ( mut op: F, ) where F: FnMut(&mut S, BorrowIndex, &BorrowData<'tcx>) -> Control, - I: Iterator + I: Iterator, { let (access, place) = access_place; diff --git a/src/librustc_mir/borrow_check/place_ext.rs b/src/librustc_mir/borrow_check/place_ext.rs index b969f0fd3c7aa..542cdf273695d 100644 --- a/src/librustc_mir/borrow_check/place_ext.rs +++ b/src/librustc_mir/borrow_check/place_ext.rs @@ -15,7 +15,7 @@ crate trait PlaceExt<'tcx> { tcx: TyCtxt<'_, 'tcx>, body: &Body<'tcx>, locals_state_at_exit: &LocalsStateAtExit, - ) -> bool; + ) -> bool; } impl<'tcx> PlaceExt<'tcx> for Place<'tcx> { diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index f4b6f438163f9..579a403f3aca7 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -186,7 +186,7 @@ pub fn mir_build<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> Body<'tcx> { /// can change `'tcx` so we have to transmute afterwards. struct GlobalizeMir<'gcx> { tcx: TyCtxt<'gcx, 'gcx>, - span: Span + span: Span, } impl<'gcx: 'tcx, 'tcx> MutVisitor<'tcx> for GlobalizeMir<'gcx> { @@ -234,10 +234,11 @@ impl<'gcx: 'tcx, 'tcx> MutVisitor<'tcx> for GlobalizeMir<'gcx> { /////////////////////////////////////////////////////////////////////////// // BuildMir -- walks a crate, looking for fn items and methods to build MIR from -fn liberated_closure_env_ty<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'tcx>, - closure_expr_id: hir::HirId, - body_id: hir::BodyId) - -> Ty<'tcx> { +fn liberated_closure_env_ty<'gcx, 'tcx>( + tcx: TyCtxt<'gcx, 'tcx>, + closure_expr_id: hir::HirId, + body_id: hir::BodyId, +) -> Ty<'tcx> { let closure_ty = tcx.body_tables(body_id).node_type(closure_expr_id); let (closure_def_id, closure_substs) = match closure_ty.sty { @@ -551,10 +552,7 @@ macro_rules! unpack { }; } -fn should_abort_on_panic<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'tcx>, - fn_def_id: DefId, - abi: Abi) - -> bool { +fn should_abort_on_panic<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'tcx>, fn_def_id: DefId, abi: Abi) -> bool { // Not callable from C, so we can safely unwind through these if abi == Abi::Rust || abi == Abi::RustCall { return false; } diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index 458e68cfcc59e..fb031f9e7ec16 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -308,9 +308,7 @@ impl interpret::MayLeak for ! { } } -impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> - for CompileTimeInterpreter<'mir, 'tcx> -{ +impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir, 'tcx> { type MemoryKinds = !; type PointerTag = (); @@ -454,18 +452,13 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> } #[inline(always)] - fn stack_push( - _ecx: &mut InterpretCx<'mir, 'tcx, Self>, - ) -> InterpResult<'tcx> { + fn stack_push(_ecx: &mut InterpretCx<'mir, 'tcx, Self>) -> InterpResult<'tcx> { Ok(()) } /// Called immediately before a stack frame gets popped. #[inline(always)] - fn stack_pop( - _ecx: &mut InterpretCx<'mir, 'tcx, Self>, - _extra: (), - ) -> InterpResult<'tcx> { + fn stack_pop(_ecx: &mut InterpretCx<'mir, 'tcx, Self>, _extra: ()) -> InterpResult<'tcx> { Ok(()) } } @@ -511,7 +504,7 @@ pub fn const_variant_index<'tcx>( pub fn error_to_const_error<'mir, 'tcx>( ecx: &InterpretCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>, - mut error: InterpErrorInfo<'tcx> + mut error: InterpErrorInfo<'tcx>, ) -> ConstEvalErr<'tcx> { error.print_backtrace(); let stacktrace = ecx.generate_stacktrace(None); diff --git a/src/librustc_mir/dataflow/drop_flag_effects.rs b/src/librustc_mir/dataflow/drop_flag_effects.rs index 6a536dc427bee..dc2893cb3303d 100644 --- a/src/librustc_mir/dataflow/drop_flag_effects.rs +++ b/src/librustc_mir/dataflow/drop_flag_effects.rs @@ -46,9 +46,11 @@ pub fn move_path_children_matching<'tcx, F>(move_data: &MoveData<'tcx>, /// is no need to maintain separate drop flags to track such state. // // FIXME: we have to do something for moving slice patterns. -fn place_contents_drop_state_cannot_differ<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'tcx>, - body: &Body<'tcx>, - place: &mir::Place<'tcx>) -> bool { +fn place_contents_drop_state_cannot_differ<'gcx, 'tcx>( + tcx: TyCtxt<'gcx, 'tcx>, + body: &Body<'tcx>, + place: &mir::Place<'tcx>, +) -> bool { let ty = place.ty(body, tcx).ty; match ty.sty { ty::Array(..) => { @@ -77,8 +79,9 @@ pub(crate) fn on_lookup_result_bits<'gcx, 'tcx, F>( body: &Body<'tcx>, move_data: &MoveData<'tcx>, lookup_result: LookupResult, - each_child: F) - where F: FnMut(MovePathIndex) + each_child: F, +) where + F: FnMut(MovePathIndex), { match lookup_result { LookupResult::Parent(..) => { @@ -95,15 +98,16 @@ pub(crate) fn on_all_children_bits<'gcx, 'tcx, F>( body: &Body<'tcx>, move_data: &MoveData<'tcx>, move_path_index: MovePathIndex, - mut each_child: F) - where F: FnMut(MovePathIndex) + mut each_child: F, +) where + F: FnMut(MovePathIndex), { fn is_terminal_path<'gcx, 'tcx>( tcx: TyCtxt<'gcx, 'tcx>, body: &Body<'tcx>, move_data: &MoveData<'tcx>, - path: MovePathIndex) -> bool - { + path: MovePathIndex, + ) -> bool { place_contents_drop_state_cannot_differ( tcx, body, &move_data.move_paths[path].place) } @@ -113,8 +117,9 @@ pub(crate) fn on_all_children_bits<'gcx, 'tcx, F>( body: &Body<'tcx>, move_data: &MoveData<'tcx>, move_path_index: MovePathIndex, - each_child: &mut F) - where F: FnMut(MovePathIndex) + each_child: &mut F, + ) where + F: FnMut(MovePathIndex), { each_child(move_path_index); @@ -136,8 +141,9 @@ pub(crate) fn on_all_drop_children_bits<'gcx, 'tcx, F>( body: &Body<'tcx>, ctxt: &MoveDataParamEnv<'gcx, 'tcx>, path: MovePathIndex, - mut each_child: F) - where F: FnMut(MovePathIndex) + mut each_child: F, +) where + F: FnMut(MovePathIndex), { on_all_children_bits(tcx, body, &ctxt.move_data, path, |child| { let place = &ctxt.move_data.move_paths[path].place; @@ -158,8 +164,9 @@ pub(crate) fn drop_flag_effects_for_function_entry<'gcx, 'tcx, F>( tcx: TyCtxt<'gcx, 'tcx>, body: &Body<'tcx>, ctxt: &MoveDataParamEnv<'gcx, 'tcx>, - mut callback: F) - where F: FnMut(MovePathIndex, DropFlagState) + mut callback: F, +) where + F: FnMut(MovePathIndex, DropFlagState), { let move_data = &ctxt.move_data; for arg in body.args_iter() { @@ -176,8 +183,9 @@ pub(crate) fn drop_flag_effects_for_location<'gcx, 'tcx, F>( body: &Body<'tcx>, ctxt: &MoveDataParamEnv<'gcx, 'tcx>, loc: Location, - mut callback: F) - where F: FnMut(MovePathIndex, DropFlagState) + mut callback: F, +) where + F: FnMut(MovePathIndex, DropFlagState), { let move_data = &ctxt.move_data; debug!("drop_flag_effects_for_location({:?})", loc); @@ -208,8 +216,9 @@ pub(crate) fn for_location_inits<'gcx, 'tcx, F>( body: &Body<'tcx>, move_data: &MoveData<'tcx>, loc: Location, - mut callback: F) - where F: FnMut(MovePathIndex) + mut callback: F, +) where + F: FnMut(MovePathIndex), { for ii in &move_data.init_loc_map[loc] { let init = move_data.inits[*ii]; diff --git a/src/librustc_mir/dataflow/impls/mod.rs b/src/librustc_mir/dataflow/impls/mod.rs index c1d302744858e..4148ffc465cf4 100644 --- a/src/librustc_mir/dataflow/impls/mod.rs +++ b/src/librustc_mir/dataflow/impls/mod.rs @@ -70,11 +70,11 @@ pub struct MaybeInitializedPlaces<'a, 'gcx: 'tcx, 'tcx: 'a> { } impl<'a, 'gcx: 'tcx, 'tcx> MaybeInitializedPlaces<'a, 'gcx, 'tcx> { - pub fn new(tcx: TyCtxt<'gcx, 'tcx>, - body: &'a Body<'tcx>, - mdpe: &'a MoveDataParamEnv<'gcx, 'tcx>) - -> Self - { + pub fn new( + tcx: TyCtxt<'gcx, 'tcx>, + body: &'a Body<'tcx>, + mdpe: &'a MoveDataParamEnv<'gcx, 'tcx>, + ) -> Self { MaybeInitializedPlaces { tcx: tcx, body: body, mdpe: mdpe } } } @@ -125,11 +125,11 @@ pub struct MaybeUninitializedPlaces<'a, 'gcx: 'tcx, 'tcx: 'a> { } impl<'a, 'gcx, 'tcx> MaybeUninitializedPlaces<'a, 'gcx, 'tcx> { - pub fn new(tcx: TyCtxt<'gcx, 'tcx>, - body: &'a Body<'tcx>, - mdpe: &'a MoveDataParamEnv<'gcx, 'tcx>) - -> Self - { + pub fn new( + tcx: TyCtxt<'gcx, 'tcx>, + body: &'a Body<'tcx>, + mdpe: &'a MoveDataParamEnv<'gcx, 'tcx>, + ) -> Self { MaybeUninitializedPlaces { tcx: tcx, body: body, mdpe: mdpe } } } @@ -179,11 +179,11 @@ pub struct DefinitelyInitializedPlaces<'a, 'gcx: 'tcx, 'tcx: 'a> { } impl<'a, 'gcx, 'tcx: 'a> DefinitelyInitializedPlaces<'a, 'gcx, 'tcx> { - pub fn new(tcx: TyCtxt<'gcx, 'tcx>, - body: &'a Body<'tcx>, - mdpe: &'a MoveDataParamEnv<'gcx, 'tcx>) - -> Self - { + pub fn new( + tcx: TyCtxt<'gcx, 'tcx>, + body: &'a Body<'tcx>, + mdpe: &'a MoveDataParamEnv<'gcx, 'tcx>, + ) -> Self { DefinitelyInitializedPlaces { tcx: tcx, body: body, mdpe: mdpe } } } @@ -228,11 +228,11 @@ pub struct EverInitializedPlaces<'a, 'gcx: 'tcx, 'tcx: 'a> { } impl<'a, 'gcx: 'tcx, 'tcx: 'a> EverInitializedPlaces<'a, 'gcx, 'tcx> { - pub fn new(tcx: TyCtxt<'gcx, 'tcx>, - body: &'a Body<'tcx>, - mdpe: &'a MoveDataParamEnv<'gcx, 'tcx>) - -> Self - { + pub fn new( + tcx: TyCtxt<'gcx, 'tcx>, + body: &'a Body<'tcx>, + mdpe: &'a MoveDataParamEnv<'gcx, 'tcx>, + ) -> Self { EverInitializedPlaces { tcx: tcx, body: body, mdpe: mdpe } } } diff --git a/src/librustc_mir/dataflow/mod.rs b/src/librustc_mir/dataflow/mod.rs index ae7690554f84e..10e46507d5a26 100644 --- a/src/librustc_mir/dataflow/mod.rs +++ b/src/librustc_mir/dataflow/mod.rs @@ -121,29 +121,36 @@ pub struct MoveDataParamEnv<'gcx, 'tcx> { pub(crate) param_env: ty::ParamEnv<'gcx>, } -pub(crate) fn do_dataflow<'a, 'gcx, 'tcx, BD, P>(tcx: TyCtxt<'gcx, 'tcx>, - body: &'a Body<'tcx>, - def_id: DefId, - attributes: &[ast::Attribute], - dead_unwinds: &BitSet, - bd: BD, - p: P) - -> DataflowResults<'tcx, BD> - where BD: BitDenotation<'tcx> + InitialFlow, - P: Fn(&BD, BD::Idx) -> DebugFormatted +pub(crate) fn do_dataflow<'a, 'gcx, 'tcx, BD, P>( + tcx: TyCtxt<'gcx, 'tcx>, + body: &'a Body<'tcx>, + def_id: DefId, + attributes: &[ast::Attribute], + dead_unwinds: &BitSet, + bd: BD, + p: P, +) -> DataflowResults<'tcx, BD> +where + BD: BitDenotation<'tcx> + InitialFlow, + P: Fn(&BD, BD::Idx) -> DebugFormatted, { let flow_state = DataflowAnalysis::new(body, dead_unwinds, bd); flow_state.run(tcx, def_id, attributes, p) } -impl<'a, 'gcx: 'tcx, 'tcx: 'a, BD> DataflowAnalysis<'a, 'tcx, BD> where BD: BitDenotation<'tcx> +impl<'a, 'gcx: 'tcx, 'tcx: 'a, BD> DataflowAnalysis<'a, 'tcx, BD> +where + BD: BitDenotation<'tcx>, { - pub(crate) fn run

(self, - tcx: TyCtxt<'gcx, 'tcx>, - def_id: DefId, - attributes: &[ast::Attribute], - p: P) -> DataflowResults<'tcx, BD> - where P: Fn(&BD, BD::Idx) -> DebugFormatted + pub(crate) fn run

( + self, + tcx: TyCtxt<'gcx, 'tcx>, + def_id: DefId, + attributes: &[ast::Attribute], + p: P, + ) -> DataflowResults<'tcx, BD> + where + P: Fn(&BD, BD::Idx) -> DebugFormatted, { let name_found = |sess: &Session, attrs: &[ast::Attribute], name| -> Option { if let Some(item) = has_rustc_mir_with(attrs, name) { diff --git a/src/librustc_mir/dataflow/move_paths/builder.rs b/src/librustc_mir/dataflow/move_paths/builder.rs index e437620272134..3acbf2a2f6987 100644 --- a/src/librustc_mir/dataflow/move_paths/builder.rs +++ b/src/librustc_mir/dataflow/move_paths/builder.rs @@ -204,7 +204,7 @@ impl<'a, 'gcx, 'tcx> MoveDataBuilder<'a, 'gcx, 'tcx> { pub(super) fn gather_moves<'gcx, 'tcx>( body: &Body<'tcx>, - tcx: TyCtxt<'gcx, 'tcx> + tcx: TyCtxt<'gcx, 'tcx>, ) -> Result, (MoveData<'tcx>, Vec<(Place<'tcx>, MoveError<'tcx>)>)> { let mut builder = MoveDataBuilder::new(body, tcx); diff --git a/src/librustc_mir/dataflow/move_paths/mod.rs b/src/librustc_mir/dataflow/move_paths/mod.rs index aa8a1e54a6570..33b8134eec918 100644 --- a/src/librustc_mir/dataflow/move_paths/mod.rs +++ b/src/librustc_mir/dataflow/move_paths/mod.rs @@ -306,8 +306,10 @@ impl<'tcx> MoveError<'tcx> { } impl<'gcx, 'tcx> MoveData<'tcx> { - pub fn gather_moves(body: &Body<'tcx>, tcx: TyCtxt<'gcx, 'tcx>) - -> Result, MoveError<'tcx>)>)> { + pub fn gather_moves( + body: &Body<'tcx>, + tcx: TyCtxt<'gcx, 'tcx>, + ) -> Result, MoveError<'tcx>)>)> { builder::gather_moves(body, tcx) } diff --git a/src/librustc_mir/hair/pattern/_match.rs b/src/librustc_mir/hair/pattern/_match.rs index 9da51cae21830..71a274f456a0e 100644 --- a/src/librustc_mir/hair/pattern/_match.rs +++ b/src/librustc_mir/hair/pattern/_match.rs @@ -195,7 +195,7 @@ pub fn expand_pattern<'a, 'tcx>(cx: &MatchCheckCtxt<'a, 'tcx>, pat: Pattern<'tcx } struct LiteralExpander<'tcx> { - tcx: TyCtxt<'tcx, 'tcx> + tcx: TyCtxt<'tcx, 'tcx>, } impl LiteralExpander<'tcx> { @@ -368,8 +368,10 @@ impl<'a, 'tcx> MatchCheckCtxt<'a, 'tcx> { tcx: TyCtxt<'tcx, 'tcx>, param_env: ty::ParamEnv<'tcx>, module: DefId, - f: F) -> R - where F: for<'b> FnOnce(MatchCheckCtxt<'b, 'tcx>) -> R + f: F, + ) -> R + where + F: for<'b> FnOnce(MatchCheckCtxt<'b, 'tcx>) -> R, { let pattern_arena = TypedArena::default(); @@ -827,9 +829,7 @@ struct IntRange<'tcx> { } impl<'tcx> IntRange<'tcx> { - fn from_ctor(tcx: TyCtxt<'tcx, 'tcx>, - ctor: &Constructor<'tcx>) - -> Option> { + fn from_ctor(tcx: TyCtxt<'tcx, 'tcx>, ctor: &Constructor<'tcx>) -> Option> { // Floating-point ranges are permitted and we don't want // to consider them when constructing integer ranges. fn is_integral<'tcx>(ty: Ty<'tcx>) -> bool { @@ -867,9 +867,7 @@ impl<'tcx> IntRange<'tcx> { } } - fn from_pat(tcx: TyCtxt<'tcx, 'tcx>, - mut pat: &Pattern<'tcx>) - -> Option> { + fn from_pat(tcx: TyCtxt<'tcx, 'tcx>, mut pat: &Pattern<'tcx>) -> Option> { let range = loop { match pat.kind { box PatternKind::Constant { value } => break ConstantValue(value), @@ -917,10 +915,11 @@ impl<'tcx> IntRange<'tcx> { /// Returns a collection of ranges that spans the values covered by `ranges`, subtracted /// by the values covered by `self`: i.e., `ranges \ self` (in set notation). - fn subtract_from(self, - tcx: TyCtxt<'tcx, 'tcx>, - ranges: Vec>) - -> Vec> { + fn subtract_from( + self, + tcx: TyCtxt<'tcx, 'tcx>, + ranges: Vec>, + ) -> Vec> { let ranges = ranges.into_iter().filter_map(|r| { IntRange::from_ctor(tcx, &r).map(|i| i.range) }); @@ -1429,7 +1428,7 @@ fn slice_pat_covered_by_const<'tcx>( const_val: &'tcx ty::Const<'tcx>, prefix: &[Pattern<'tcx>], slice: &Option>, - suffix: &[Pattern<'tcx>] + suffix: &[Pattern<'tcx>], ) -> Result { let data: &[u8] = match (const_val.val, &const_val.ty.sty) { (ConstValue::ByRef(ptr, alloc), ty::Array(t, n)) => { @@ -1476,10 +1475,7 @@ fn slice_pat_covered_by_const<'tcx>( // Whether to evaluate a constructor using exhaustive integer matching. This is true if the // constructor is a range or constant with an integer type. -fn should_treat_range_exhaustively( - tcx: TyCtxt<'tcx, 'tcx>, - ctor: &Constructor<'tcx>, -) -> bool { +fn should_treat_range_exhaustively(tcx: TyCtxt<'tcx, 'tcx>, ctor: &Constructor<'tcx>) -> bool { let ty = match ctor { ConstantValue(value) => value.ty, ConstantRange(_, _, ty, _) => ty, diff --git a/src/librustc_mir/hair/pattern/mod.rs b/src/librustc_mir/hair/pattern/mod.rs index 67325e7b75c83..4b6be426e5178 100644 --- a/src/librustc_mir/hair/pattern/mod.rs +++ b/src/librustc_mir/hair/pattern/mod.rs @@ -335,10 +335,12 @@ pub struct PatternContext<'a, 'tcx: 'a> { } impl<'a, 'tcx> Pattern<'tcx> { - pub fn from_hir(tcx: TyCtxt<'tcx, 'tcx>, - param_env_and_substs: ty::ParamEnvAnd<'tcx, SubstsRef<'tcx>>, - tables: &'a ty::TypeckTables<'tcx>, - pat: &'tcx hir::Pat) -> Self { + pub fn from_hir( + tcx: TyCtxt<'tcx, 'tcx>, + param_env_and_substs: ty::ParamEnvAnd<'tcx, SubstsRef<'tcx>>, + tables: &'a ty::TypeckTables<'tcx>, + pat: &'tcx hir::Pat, + ) -> Self { let mut pcx = PatternContext::new(tcx, param_env_and_substs, tables); let result = pcx.lower_pattern(pat); if !pcx.errors.is_empty() { @@ -351,9 +353,11 @@ impl<'a, 'tcx> Pattern<'tcx> { } impl<'a, 'tcx> PatternContext<'a, 'tcx> { - pub fn new(tcx: TyCtxt<'tcx, 'tcx>, - param_env_and_substs: ty::ParamEnvAnd<'tcx, SubstsRef<'tcx>>, - tables: &'a ty::TypeckTables<'tcx>) -> Self { + pub fn new( + tcx: TyCtxt<'tcx, 'tcx>, + param_env_and_substs: ty::ParamEnvAnd<'tcx, SubstsRef<'tcx>>, + tables: &'a ty::TypeckTables<'tcx>, + ) -> Self { PatternContext { tcx, param_env: param_env_and_substs.param_env, diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index 134c23e56e223..45c1f71e95043 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -43,10 +43,8 @@ pub struct InterpretCx<'mir, 'tcx, M: Machine<'mir, 'tcx>> { pub(crate) stack: Vec>, /// A cache for deduplicating vtables - pub(super) vtables: FxHashMap< - (Ty<'tcx>, Option>), - Pointer - >, + pub(super) vtables: + FxHashMap<(Ty<'tcx>, Option>), Pointer>, } /// A stack frame. @@ -160,9 +158,7 @@ impl<'tcx, Tag: Copy + 'static> LocalState<'tcx, Tag> { } } -impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> HasDataLayout - for InterpretCx<'mir, 'tcx, M> -{ +impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> HasDataLayout for InterpretCx<'mir, 'tcx, M> { #[inline] fn data_layout(&self) -> &layout::TargetDataLayout { &self.tcx.data_layout @@ -170,7 +166,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> HasDataLayout } impl<'mir, 'tcx, M> layout::HasTyCtxt<'tcx> for InterpretCx<'mir, 'tcx, M> - where M: Machine<'mir, 'tcx> +where + M: Machine<'mir, 'tcx>, { #[inline] fn tcx(&self) -> TyCtxt<'tcx, 'tcx> { @@ -179,16 +176,15 @@ impl<'mir, 'tcx, M> layout::HasTyCtxt<'tcx> for InterpretCx<'mir, 'tcx, M> } impl<'mir, 'tcx, M> layout::HasParamEnv<'tcx> for InterpretCx<'mir, 'tcx, M> - where M: Machine<'mir, 'tcx> +where + M: Machine<'mir, 'tcx>, { fn param_env(&self) -> ty::ParamEnv<'tcx> { self.param_env } } -impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> LayoutOf - for InterpretCx<'mir, 'tcx, M> -{ +impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> LayoutOf for InterpretCx<'mir, 'tcx, M> { type Ty = Ty<'tcx>; type TyLayout = InterpResult<'tcx, TyLayout<'tcx>>; @@ -200,11 +196,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> LayoutOf } impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> { - pub fn new( - tcx: TyCtxtAt<'tcx, 'tcx>, - param_env: ty::ParamEnv<'tcx>, - machine: M, - ) -> Self { + pub fn new(tcx: TyCtxtAt<'tcx, 'tcx>, param_env: ty::ParamEnv<'tcx>, machine: M) -> Self { InterpretCx { machine, tcx, diff --git a/src/librustc_mir/interpret/intrinsics/type_name.rs b/src/librustc_mir/interpret/intrinsics/type_name.rs index 8ef9b75e4be3b..a44a20adbca0e 100644 --- a/src/librustc_mir/interpret/intrinsics/type_name.rs +++ b/src/librustc_mir/interpret/intrinsics/type_name.rs @@ -225,10 +225,7 @@ pub fn type_name<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, ty: Ty<'tcx>) -> &'tcx ty::Const } /// Directly returns an `Allocation` containing an absolute path representation of the given type. -pub(super) fn alloc_type_name<'tcx>( - tcx: TyCtxt<'tcx, 'tcx>, - ty: Ty<'tcx> -) -> &'tcx Allocation { +pub(super) fn alloc_type_name<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, ty: Ty<'tcx>) -> &'tcx Allocation { let path = AbsolutePathPrinter { tcx, path: String::new() }.print_type(ty).unwrap().path; let alloc = Allocation::from_byte_aligned_bytes(path.into_bytes()); tcx.intern_const_alloc(alloc) diff --git a/src/librustc_mir/interpret/machine.rs b/src/librustc_mir/interpret/machine.rs index 32ab29114f2cd..97e65733bd409 100644 --- a/src/librustc_mir/interpret/machine.rs +++ b/src/librustc_mir/interpret/machine.rs @@ -201,9 +201,7 @@ pub trait Machine<'mir, 'tcx>: Sized { } /// Called immediately before a new stack frame got pushed - fn stack_push( - ecx: &mut InterpretCx<'mir, 'tcx, Self>, - ) -> InterpResult<'tcx, Self::FrameExtra>; + fn stack_push(ecx: &mut InterpretCx<'mir, 'tcx, Self>) -> InterpResult<'tcx, Self::FrameExtra>; /// Called immediately after a stack frame gets popped fn stack_pop( diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index 8f941ed5c6235..d9f522ab12f24 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -69,9 +69,7 @@ pub struct Memory<'mir, 'tcx, M: Machine<'mir, 'tcx>> { pub(super) tcx: TyCtxtAt<'tcx, 'tcx>, } -impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> HasDataLayout - for Memory<'mir, 'tcx, M> -{ +impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> HasDataLayout for Memory<'mir, 'tcx, M> { #[inline] fn data_layout(&self) -> &TargetDataLayout { &self.tcx.data_layout @@ -80,12 +78,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> HasDataLayout // FIXME: Really we shouldn't clone memory, ever. Snapshot machinery should instead // carefully copy only the reachable parts. -impl<'mir, 'tcx, M> - Clone -for - Memory<'mir, 'tcx, M> +impl<'mir, 'tcx, M> Clone for Memory<'mir, 'tcx, M> where - M: Machine<'mir, 'tcx, PointerTag=(), AllocExtra=(), MemoryExtra=()>, + M: Machine<'mir, 'tcx, PointerTag = (), AllocExtra = (), MemoryExtra = ()>, M::MemoryMap: AllocMap, Allocation)>, { fn clone(&self) -> Self { @@ -641,7 +636,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { /// Interning (for CTFE) impl<'mir, 'tcx, M> Memory<'mir, 'tcx, M> where - M: Machine<'mir, 'tcx, PointerTag=(), AllocExtra=(), MemoryExtra=()>, + M: Machine<'mir, 'tcx, PointerTag = (), AllocExtra = (), MemoryExtra = ()>, // FIXME: Working around https://github.com/rust-lang/rust/issues/24159 M::MemoryMap: AllocMap, Allocation)>, { diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs index f5d30d2aeb351..b8bb54815d8bf 100644 --- a/src/librustc_mir/interpret/place.rs +++ b/src/librustc_mir/interpret/place.rs @@ -294,7 +294,7 @@ impl<'mir, 'tcx, Tag, M> InterpretCx<'mir, 'tcx, M> where // FIXME: Working around https://github.com/rust-lang/rust/issues/54385 Tag: ::std::fmt::Debug + Copy + Eq + Hash + 'static, - M: Machine<'mir, 'tcx, PointerTag=Tag>, + M: Machine<'mir, 'tcx, PointerTag = Tag>, // FIXME: Working around https://github.com/rust-lang/rust/issues/24159 M::MemoryMap: AllocMap, Allocation)>, M::AllocExtra: AllocationExtra, @@ -396,8 +396,7 @@ where pub fn mplace_array_fields( &self, base: MPlaceTy<'tcx, Tag>, - ) -> - InterpResult<'tcx, impl Iterator>> + 'tcx> + ) -> InterpResult<'tcx, impl Iterator>> + 'tcx> { let len = base.len(self)?; // also asserts that we have a type where this makes sense let stride = match base.layout.fields { diff --git a/src/librustc_mir/interpret/snapshot.rs b/src/librustc_mir/interpret/snapshot.rs index 1258dc041b83a..f52fa0cd48272 100644 --- a/src/librustc_mir/interpret/snapshot.rs +++ b/src/librustc_mir/interpret/snapshot.rs @@ -43,8 +43,7 @@ pub(crate) struct InfiniteLoopDetector<'mir, 'tcx> { snapshots: FxHashSet>, } -impl<'mir, 'tcx> InfiniteLoopDetector<'mir, 'tcx> -{ +impl<'mir, 'tcx> InfiniteLoopDetector<'mir, 'tcx> { pub fn observe_and_analyze( &mut self, tcx: TyCtxt<'tcx, 'tcx>, @@ -392,7 +391,7 @@ struct InterpSnapshot<'mir, 'tcx> { impl InterpSnapshot<'mir, 'tcx> { fn new( memory: &Memory<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>, - stack: &[Frame<'mir, 'tcx>] + stack: &[Frame<'mir, 'tcx>], ) -> Self { InterpSnapshot { memory: memory.clone(), @@ -407,7 +406,6 @@ impl InterpSnapshot<'mir, 'tcx> { // Start with the stack, iterate and recursively snapshot self.stack.iter().map(|frame| frame.snapshot(&self.memory)).collect() } - } impl<'mir, 'tcx> Hash for InterpSnapshot<'mir, 'tcx> { diff --git a/src/librustc_mir/interpret/validity.rs b/src/librustc_mir/interpret/validity.rs index ef11fce513cd5..8a8cc0fe1d174 100644 --- a/src/librustc_mir/interpret/validity.rs +++ b/src/librustc_mir/interpret/validity.rs @@ -235,8 +235,8 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, 'tcx, M } } -impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> - ValueVisitor<'mir, 'tcx, M> for ValidityVisitor<'rt, 'mir, 'tcx, M> +impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M> + for ValidityVisitor<'rt, 'mir, 'tcx, M> { type V = OpTy<'tcx, M::PointerTag>; diff --git a/src/librustc_mir/interpret/visitor.rs b/src/librustc_mir/interpret/visitor.rs index accf9914e0d0e..9150f16526ba7 100644 --- a/src/librustc_mir/interpret/visitor.rs +++ b/src/librustc_mir/interpret/visitor.rs @@ -14,8 +14,7 @@ use super::{ // A thing that we can project into, and that has a layout. // This wouldn't have to depend on `Machine` but with the current type inference, // that's just more convenient to work with (avoids repeating all the `Machine` bounds). -pub trait Value<'mir, 'tcx, M: Machine<'mir, 'tcx>>: Copy -{ +pub trait Value<'mir, 'tcx, M: Machine<'mir, 'tcx>>: Copy { /// Gets this value's layout. fn layout(&self) -> TyLayout<'tcx>; @@ -45,9 +44,7 @@ pub trait Value<'mir, 'tcx, M: Machine<'mir, 'tcx>>: Copy // Operands and memory-places are both values. // Places in general are not due to `place_field` having to do `force_allocation`. -impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Value<'mir, 'tcx, M> - for OpTy<'tcx, M::PointerTag> -{ +impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Value<'mir, 'tcx, M> for OpTy<'tcx, M::PointerTag> { #[inline(always)] fn layout(&self) -> TyLayout<'tcx> { self.layout @@ -84,9 +81,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Value<'mir, 'tcx, M> ecx.operand_field(self, field) } } -impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Value<'mir, 'tcx, M> - for MPlaceTy<'tcx, M::PointerTag> -{ +impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Value<'mir, 'tcx, M> for MPlaceTy<'tcx, M::PointerTag> { #[inline(always)] fn layout(&self) -> TyLayout<'tcx> { self.layout diff --git a/src/librustc_mir/lints.rs b/src/librustc_mir/lints.rs index 1cd48312412cc..621fb8a4b22b3 100644 --- a/src/librustc_mir/lints.rs +++ b/src/librustc_mir/lints.rs @@ -7,9 +7,7 @@ use rustc::mir::{self, Body, TerminatorKind}; use rustc::ty::{self, AssocItem, AssocItemContainer, Instance, TyCtxt}; use rustc::ty::subst::InternalSubsts; -pub fn check(tcx: TyCtxt<'tcx, 'tcx>, - body: &Body<'tcx>, - def_id: DefId) { +pub fn check(tcx: TyCtxt<'tcx, 'tcx>, body: &Body<'tcx>, def_id: DefId) { let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); if let Some(fn_like_node) = FnLikeNode::from_node(tcx.hir().get_by_hir_id(hir_id)) { @@ -17,10 +15,12 @@ pub fn check(tcx: TyCtxt<'tcx, 'tcx>, } } -fn check_fn_for_unconditional_recursion(tcx: TyCtxt<'tcx, 'tcx>, - fn_kind: FnKind<'_>, - body: &Body<'tcx>, - def_id: DefId) { +fn check_fn_for_unconditional_recursion( + tcx: TyCtxt<'tcx, 'tcx>, + fn_kind: FnKind<'_>, + body: &Body<'tcx>, + def_id: DefId, +) { if let FnKind::Closure(_) = fn_kind { // closures can't recur, so they don't matter. return; diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index 30d1ea726f9a8..0b7dbfeacda59 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -281,10 +281,10 @@ impl<'tcx> InliningMap<'tcx> { } } -pub fn collect_crate_mono_items<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - mode: MonoItemCollectionMode) - -> (FxHashSet>, - InliningMap<'tcx>) { +pub fn collect_crate_mono_items<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + mode: MonoItemCollectionMode, +) -> (FxHashSet>, InliningMap<'tcx>) { let roots = time(tcx.sess, "collecting roots", || { collect_roots(tcx, mode) }); @@ -315,9 +315,10 @@ pub fn collect_crate_mono_items<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, // Find all non-generic items by walking the HIR. These items serve as roots to // start monomorphizing from. -fn collect_roots<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - mode: MonoItemCollectionMode) - -> Vec> { +fn collect_roots<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + mode: MonoItemCollectionMode, +) -> Vec> { debug!("Collecting roots"); let mut roots = Vec::new(); @@ -347,11 +348,13 @@ fn collect_roots<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, } // Collect all monomorphized items reachable from `starting_point` -fn collect_items_rec<'a, 'tcx: 'a>(tcx: TyCtxt<'tcx, 'tcx>, - starting_point: MonoItem<'tcx>, - visited: MTRef<'_, MTLock>>>, - recursion_depths: &mut DefIdMap, - inlining_map: MTRef<'_, MTLock>>) { +fn collect_items_rec<'a, 'tcx: 'a>( + tcx: TyCtxt<'tcx, 'tcx>, + starting_point: MonoItem<'tcx>, + visited: MTRef<'_, MTLock>>>, + recursion_depths: &mut DefIdMap, + inlining_map: MTRef<'_, MTLock>>, +) { if !visited.lock_mut().insert(starting_point.clone()) { // We've been here already, no need to search again. return; @@ -413,10 +416,12 @@ fn collect_items_rec<'a, 'tcx: 'a>(tcx: TyCtxt<'tcx, 'tcx>, debug!("END collect_items_rec({})", starting_point.to_string(tcx, true)); } -fn record_accesses<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - caller: MonoItem<'tcx>, - callees: &[MonoItem<'tcx>], - inlining_map: MTRef<'_, MTLock>>) { +fn record_accesses<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + caller: MonoItem<'tcx>, + callees: &[MonoItem<'tcx>], + inlining_map: MTRef<'_, MTLock>>, +) { let is_inlining_candidate = |mono_item: &MonoItem<'tcx>| { mono_item.instantiation_mode(tcx) == InstantiationMode::LocalCopy }; @@ -429,10 +434,11 @@ fn record_accesses<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, inlining_map.lock_mut().record_accesses(caller, accesses); } -fn check_recursion_limit<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - instance: Instance<'tcx>, - recursion_depths: &mut DefIdMap) - -> (DefId, usize) { +fn check_recursion_limit<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + instance: Instance<'tcx>, + recursion_depths: &mut DefIdMap, +) -> (DefId, usize) { let def_id = instance.def_id(); let recursion_depth = recursion_depths.get(&def_id).cloned().unwrap_or(0); debug!(" => recursion depth={}", recursion_depth); @@ -463,9 +469,7 @@ fn check_recursion_limit<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, (def_id, recursion_depth) } -fn check_type_length_limit<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - instance: Instance<'tcx>) -{ +fn check_type_length_limit<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, instance: Instance<'tcx>) { let type_length = instance.substs.types().flat_map(|ty| ty.walk()).count(); let const_length = instance.substs.consts().flat_map(|ct| ct.ty.walk()).count(); debug!(" => type length={}, const length={}", type_length, const_length); @@ -679,20 +683,22 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> { } } -fn visit_drop_use<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - ty: Ty<'tcx>, - is_direct_call: bool, - output: &mut Vec>) -{ +fn visit_drop_use<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + ty: Ty<'tcx>, + is_direct_call: bool, + output: &mut Vec>, +) { let instance = Instance::resolve_drop_in_place(tcx, ty); visit_instance_use(tcx, instance, is_direct_call, output); } -fn visit_fn_use<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - ty: Ty<'tcx>, - is_direct_call: bool, - output: &mut Vec>) -{ +fn visit_fn_use<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + ty: Ty<'tcx>, + is_direct_call: bool, + output: &mut Vec>, +) { if let ty::FnDef(def_id, substs) = ty.sty { let instance = ty::Instance::resolve(tcx, ty::ParamEnv::reveal_all(), @@ -702,11 +708,12 @@ fn visit_fn_use<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, } } -fn visit_instance_use<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - instance: ty::Instance<'tcx>, - is_direct_call: bool, - output: &mut Vec>) -{ +fn visit_instance_use<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + instance: ty::Instance<'tcx>, + is_direct_call: bool, + output: &mut Vec>, +) { debug!("visit_item_use({:?}, is_direct_call={:?})", instance, is_direct_call); if !should_monomorphize_locally(tcx, &instance) { return @@ -741,8 +748,7 @@ fn visit_instance_use<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, // Returns true if we should codegen an instance in the local crate. // Returns false if we can just link to the upstream crate and therefore don't // need a mono item. -fn should_monomorphize_locally<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, instance: &Instance<'tcx>) - -> bool { +fn should_monomorphize_locally<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, instance: &Instance<'tcx>) -> bool { let def_id = match instance.def { ty::InstanceDef::Item(def_id) => def_id, ty::InstanceDef::VtableShim(..) | @@ -776,10 +782,11 @@ fn should_monomorphize_locally<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, instance: &Instanc } return true; - fn is_available_upstream_generic<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - def_id: DefId, - substs: SubstsRef<'tcx>) - -> bool { + fn is_available_upstream_generic<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + def_id: DefId, + substs: SubstsRef<'tcx>, + ) -> bool { debug_assert!(!def_id.is_local()); // If we are not in share generics mode, we don't link to upstream @@ -841,10 +848,11 @@ fn should_monomorphize_locally<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, instance: &Instanc /// /// Finally, there is also the case of custom unsizing coercions, e.g., for /// smart pointers such as `Rc` and `Arc`. -fn find_vtable_types_for_unsizing<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - source_ty: Ty<'tcx>, - target_ty: Ty<'tcx>) - -> (Ty<'tcx>, Ty<'tcx>) { +fn find_vtable_types_for_unsizing<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + source_ty: Ty<'tcx>, + target_ty: Ty<'tcx>, +) -> (Ty<'tcx>, Ty<'tcx>) { let ptr_vtable = |inner_source: Ty<'tcx>, inner_target: Ty<'tcx>| { let type_has_metadata = |ty: Ty<'tcx>| -> bool { use syntax_pos::DUMMY_SP; @@ -914,10 +922,12 @@ fn create_fn_mono_item<'tcx>(instance: Instance<'tcx>) -> MonoItem<'tcx> { /// Creates a `MonoItem` for each method that is referenced by the vtable for /// the given trait/impl pair. -fn create_mono_items_for_vtable_methods<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - trait_ty: Ty<'tcx>, - impl_ty: Ty<'tcx>, - output: &mut Vec>) { +fn create_mono_items_for_vtable_methods<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + trait_ty: Ty<'tcx>, + impl_ty: Ty<'tcx>, + output: &mut Vec>, +) { assert!(!trait_ty.needs_subst() && !trait_ty.has_escaping_bound_vars() && !impl_ty.needs_subst() && !impl_ty.has_escaping_bound_vars()); @@ -1112,9 +1122,11 @@ fn item_requires_monomorphization<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) generics.requires_monomorphization(tcx) } -fn create_mono_items_for_default_impls<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - item: &'tcx hir::Item, - output: &mut Vec>) { +fn create_mono_items_for_default_impls<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + item: &'tcx hir::Item, + output: &mut Vec>, +) { match item.node { hir::ItemKind::Impl(_, _, _, ref generics, .., ref impl_item_refs) => { for param in &generics.params { @@ -1207,10 +1219,11 @@ fn collect_miri<'tcx>( } /// Scan the MIR in order to find function calls, closures, and drop-glue -fn collect_neighbours<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - instance: Instance<'tcx>, - output: &mut Vec>) -{ +fn collect_neighbours<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + instance: Instance<'tcx>, + output: &mut Vec>, +) { let body = tcx.instance_mir(instance.def); MirNeighborCollector { @@ -1237,9 +1250,7 @@ fn collect_neighbours<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, } } -fn def_id_to_string<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - def_id: DefId) - -> String { +fn def_id_to_string<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> String { let mut output = String::new(); let printer = DefPathBasedNames::new(tcx, false, false); printer.push_def_path(def_id, &mut output); diff --git a/src/librustc_mir/monomorphize/item.rs b/src/librustc_mir/monomorphize/item.rs index 2ba9600dfc9f0..1450534af5e56 100644 --- a/src/librustc_mir/monomorphize/item.rs +++ b/src/librustc_mir/monomorphize/item.rs @@ -62,9 +62,7 @@ pub trait MonoItemExt<'tcx>: fmt::Debug { } } } - fn instantiation_mode(&self, - tcx: TyCtxt<'tcx, 'tcx>) - -> InstantiationMode { + fn instantiation_mode(&self, tcx: TyCtxt<'tcx, 'tcx>) -> InstantiationMode { let inline_in_all_cgus = tcx.sess.opts.debugging_opts.inline_in_all_cgus.unwrap_or_else(|| { tcx.sess.opts.optimize != OptLevel::No @@ -170,11 +168,12 @@ pub trait MonoItemExt<'tcx>: fmt::Debug { } }; - fn to_string_internal<'a, 'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - prefix: &str, - instance: Instance<'tcx>, - debug: bool) - -> String { + fn to_string_internal<'a, 'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + prefix: &str, + instance: Instance<'tcx>, + debug: bool, + ) -> String { let mut result = String::with_capacity(32); result.push_str(prefix); let printer = DefPathBasedNames::new(tcx, false, false); diff --git a/src/librustc_mir/monomorphize/mod.rs b/src/librustc_mir/monomorphize/mod.rs index 929c2126b4d9e..667c0d7b29c5e 100644 --- a/src/librustc_mir/monomorphize/mod.rs +++ b/src/librustc_mir/monomorphize/mod.rs @@ -5,10 +5,11 @@ use rustc::ty::{self, Ty, TyCtxt}; pub mod collector; pub mod partitioning; -pub fn custom_coerce_unsize_info<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - source_ty: Ty<'tcx>, - target_ty: Ty<'tcx>) - -> CustomCoerceUnsized { +pub fn custom_coerce_unsize_info<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + source_ty: Ty<'tcx>, + target_ty: Ty<'tcx>, +) -> CustomCoerceUnsized { let def_id = tcx.lang_items().coerce_unsized_trait().unwrap(); let trait_ref = ty::Binder::bind(ty::TraitRef { diff --git a/src/librustc_mir/monomorphize/partitioning.rs b/src/librustc_mir/monomorphize/partitioning.rs index 38c887751b68f..f05ccc45c9c4c 100644 --- a/src/librustc_mir/monomorphize/partitioning.rs +++ b/src/librustc_mir/monomorphize/partitioning.rs @@ -125,12 +125,14 @@ fn fallback_cgu_name(name_builder: &mut CodegenUnitNameBuilder<'_, '_>) -> Inter name_builder.build_cgu_name(LOCAL_CRATE, &["fallback"], Some("cgu")) } -pub fn partition<'tcx, I>(tcx: TyCtxt<'tcx, 'tcx>, - mono_items: I, - strategy: PartitioningStrategy, - inlining_map: &InliningMap<'tcx>) - -> Vec> - where I: Iterator> +pub fn partition<'tcx, I>( + tcx: TyCtxt<'tcx, 'tcx>, + mono_items: I, + strategy: PartitioningStrategy, + inlining_map: &InliningMap<'tcx>, +) -> Vec> +where + I: Iterator>, { // In the first step, we place all regular monomorphizations into their // respective 'home' codegen unit. Regular monomorphizations are all @@ -201,10 +203,12 @@ struct PostInliningPartitioning<'tcx> { internalization_candidates: FxHashSet>, } -fn place_root_mono_items<'tcx, I>(tcx: TyCtxt<'tcx, 'tcx>, - mono_items: I) - -> PreInliningPartitioning<'tcx> - where I: Iterator> +fn place_root_mono_items<'tcx, I>( + tcx: TyCtxt<'tcx, 'tcx>, + mono_items: I, +) -> PreInliningPartitioning<'tcx> +where + I: Iterator>, { let mut roots = FxHashSet::default(); let mut codegen_units = FxHashMap::default(); @@ -463,9 +467,11 @@ fn default_visibility(tcx: TyCtxt<'_, '_>, id: DefId, is_generic: bool) -> Visib } } -fn merge_codegen_units<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - initial_partitioning: &mut PreInliningPartitioning<'tcx>, - target_cgu_count: usize) { +fn merge_codegen_units<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + initial_partitioning: &mut PreInliningPartitioning<'tcx>, + target_cgu_count: usize, +) { assert!(target_cgu_count >= 1); let codegen_units = &mut initial_partitioning.codegen_units; @@ -585,9 +591,11 @@ fn place_inlined_mono_items<'tcx>(initial_partitioning: PreInliningPartitioning< } } -fn internalize_symbols<'tcx>(_tcx: TyCtxt<'tcx, 'tcx>, - partitioning: &mut PostInliningPartitioning<'tcx>, - inlining_map: &InliningMap<'tcx>) { +fn internalize_symbols<'tcx>( + _tcx: TyCtxt<'tcx, 'tcx>, + partitioning: &mut PostInliningPartitioning<'tcx>, + inlining_map: &InliningMap<'tcx>, +) { if partitioning.codegen_units.len() == 1 { // Fast path for when there is only one codegen unit. In this case we // can internalize all candidates, since there is nowhere else they @@ -650,9 +658,10 @@ fn internalize_symbols<'tcx>(_tcx: TyCtxt<'tcx, 'tcx>, } } -fn characteristic_def_id_of_mono_item<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - mono_item: MonoItem<'tcx>) - -> Option { +fn characteristic_def_id_of_mono_item<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + mono_item: MonoItem<'tcx>, +) -> Option { match mono_item { MonoItem::Fn(instance) => { let def_id = match instance.def { @@ -698,12 +707,13 @@ fn characteristic_def_id_of_mono_item<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, type CguNameCache = FxHashMap<(DefId, bool), InternedString>; -fn compute_codegen_unit_name(tcx: TyCtxt<'_, '_>, - name_builder: &mut CodegenUnitNameBuilder<'_, '_>, - def_id: DefId, - volatile: bool, - cache: &mut CguNameCache) - -> InternedString { +fn compute_codegen_unit_name( + tcx: TyCtxt<'_, '_>, + name_builder: &mut CodegenUnitNameBuilder<'_, '_>, + def_id: DefId, + volatile: bool, + cache: &mut CguNameCache, +) -> InternedString { // Find the innermost module that is not nested within a function. let mut current_def_id = def_id; let mut cgu_def_id = None; @@ -752,17 +762,17 @@ fn compute_codegen_unit_name(tcx: TyCtxt<'_, '_>, }).clone() } -fn numbered_codegen_unit_name(name_builder: &mut CodegenUnitNameBuilder<'_, '_>, - index: usize) - -> InternedString { +fn numbered_codegen_unit_name( + name_builder: &mut CodegenUnitNameBuilder<'_, '_>, + index: usize, +) -> InternedString { name_builder.build_cgu_name_no_mangle(LOCAL_CRATE, &["cgu"], Some(index)) } -fn debug_dump<'a, 'b, 'tcx, I>(tcx: TyCtxt<'tcx, 'tcx>, - label: &str, - cgus: I) - where I: Iterator>, - 'tcx: 'a + 'b +fn debug_dump<'a, 'b, 'tcx, I>(tcx: TyCtxt<'tcx, 'tcx>, label: &str, cgus: I) +where + I: Iterator>, + 'tcx: 'a + 'b, { if cfg!(debug_assertions) { debug!("{}", label); @@ -788,7 +798,8 @@ fn debug_dump<'a, 'b, 'tcx, I>(tcx: TyCtxt<'tcx, 'tcx>, #[inline(never)] // give this a place in the profiler fn assert_symbols_are_distinct<'a, 'tcx: 'a, I>(tcx: TyCtxt<'tcx, 'tcx>, mono_items: I) - where I: Iterator> +where + I: Iterator>, { let mut symbols: Vec<_> = mono_items.map(|mono_item| { (mono_item, mono_item.symbol_name(tcx)) @@ -833,8 +844,7 @@ fn assert_symbols_are_distinct<'a, 'tcx: 'a, I>(tcx: TyCtxt<'tcx, 'tcx>, mono_it fn collect_and_partition_mono_items<'tcx>( tcx: TyCtxt<'tcx, 'tcx>, cnum: CrateNum, -) -> (Arc, Arc>>>) -{ +) -> (Arc, Arc>>>) { assert_eq!(cnum, LOCAL_CRATE); let collection_mode = match tcx.sess.opts.debugging_opts.print_mono_items { diff --git a/src/librustc_mir/shim.rs b/src/librustc_mir/shim.rs index f63e6996ddcbf..ea11901672a23 100644 --- a/src/librustc_mir/shim.rs +++ b/src/librustc_mir/shim.rs @@ -26,10 +26,7 @@ pub fn provide(providers: &mut Providers<'_>) { providers.mir_shims = make_shim; } -fn make_shim<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - instance: ty::InstanceDef<'tcx>) - -> &'tcx Body<'tcx> -{ +fn make_shim<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, instance: ty::InstanceDef<'tcx>) -> &'tcx Body<'tcx> { debug!("make_shim({:?})", instance); let mut result = match instance { @@ -166,11 +163,11 @@ fn local_decls_for_sig<'tcx>(sig: &ty::FnSig<'tcx>, span: Span) .collect() } -fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - def_id: DefId, - ty: Option>) - -> Body<'tcx> -{ +fn build_drop_shim<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + def_id: DefId, + ty: Option>, +) -> Body<'tcx> { debug!("build_drop_shim(def_id={:?}, ty={:?})", def_id, ty); // Check if this is a generator, if so, return the drop glue for it @@ -273,7 +270,9 @@ impl<'a, 'tcx> DropElaborator<'a, 'tcx> for DropShimElaborator<'a, 'tcx> { fn patch(&mut self) -> &mut MirPatch<'tcx> { &mut self.patch } fn body(&self) -> &'a Body<'tcx> { self.body } - fn tcx(&self) -> TyCtxt<'tcx, 'tcx> { self.tcx } + fn tcx(&self) -> TyCtxt<'tcx, 'tcx> { + self.tcx + } fn param_env(&self) -> ty::ParamEnv<'tcx> { self.param_env } fn drop_style(&self, _path: Self::Path, mode: DropFlagMode) -> DropStyle { @@ -306,11 +305,7 @@ impl<'a, 'tcx> DropElaborator<'a, 'tcx> for DropShimElaborator<'a, 'tcx> { } /// Builds a `Clone::clone` shim for `self_ty`. Here, `def_id` is `Clone::clone`. -fn build_clone_shim<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - def_id: DefId, - self_ty: Ty<'tcx>) - -> Body<'tcx> -{ +fn build_clone_shim<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId, self_ty: Ty<'tcx>) -> Body<'tcx> { debug!("build_clone_shim(def_id={:?})", def_id); let mut builder = CloneShimBuilder::new(tcx, def_id, self_ty); @@ -350,9 +345,7 @@ struct CloneShimBuilder<'tcx> { } impl CloneShimBuilder<'tcx> { - fn new(tcx: TyCtxt<'tcx, 'tcx>, - def_id: DefId, - self_ty: Ty<'tcx>) -> Self { + fn new(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId, self_ty: Ty<'tcx>) -> Self { // we must subst the self_ty because it's // otherwise going to be TySelf and we can't index // or access fields of a Place of type TySelf. @@ -691,13 +684,13 @@ impl CloneShimBuilder<'tcx> { /// /// If `untuple_args` is a vec of types, the second argument of the /// function will be untupled as these types. -fn build_call_shim<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - def_id: DefId, - rcvr_adjustment: Adjustment, - call_kind: CallKind, - untuple_args: Option<&[Ty<'tcx>]>) - -> Body<'tcx> -{ +fn build_call_shim<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + def_id: DefId, + rcvr_adjustment: Adjustment, + call_kind: CallKind, + untuple_args: Option<&[Ty<'tcx>]>, +) -> Body<'tcx> { debug!("build_call_shim(def_id={:?}, rcvr_adjustment={:?}, \ call_kind={:?}, untuple_args={:?})", def_id, rcvr_adjustment, call_kind, untuple_args); diff --git a/src/librustc_mir/transform/add_call_guards.rs b/src/librustc_mir/transform/add_call_guards.rs index f71a1b42611d1..56c824167e185 100644 --- a/src/librustc_mir/transform/add_call_guards.rs +++ b/src/librustc_mir/transform/add_call_guards.rs @@ -31,10 +31,12 @@ pub use self::AddCallGuards::*; */ impl MirPass for AddCallGuards { - fn run_pass<'tcx>(&self, - _tcx: TyCtxt<'tcx, 'tcx>, - _src: MirSource<'tcx>, - body: &mut Body<'tcx>) { + fn run_pass<'tcx>( + &self, + _tcx: TyCtxt<'tcx, 'tcx>, + _src: MirSource<'tcx>, + body: &mut Body<'tcx>, + ) { self.add_call_guards(body); } } diff --git a/src/librustc_mir/transform/add_moves_for_packed_drops.rs b/src/librustc_mir/transform/add_moves_for_packed_drops.rs index e0b8805ebfb34..673b13a22d3d7 100644 --- a/src/librustc_mir/transform/add_moves_for_packed_drops.rs +++ b/src/librustc_mir/transform/add_moves_for_packed_drops.rs @@ -40,11 +40,7 @@ use crate::util; pub struct AddMovesForPackedDrops; impl MirPass for AddMovesForPackedDrops { - fn run_pass<'tcx>(&self, - tcx: TyCtxt<'tcx, 'tcx>, - src: MirSource<'tcx>, - body: &mut Body<'tcx>) - { + fn run_pass<'tcx>(&self, tcx: TyCtxt<'tcx, 'tcx>, src: MirSource<'tcx>, body: &mut Body<'tcx>) { debug!("add_moves_for_packed_drops({:?} @ {:?})", src, body.span); add_moves_for_packed_drops(tcx, body, src.def_id()); } @@ -53,8 +49,8 @@ impl MirPass for AddMovesForPackedDrops { pub fn add_moves_for_packed_drops<'tcx>( tcx: TyCtxt<'tcx, 'tcx>, body: &mut Body<'tcx>, - def_id: DefId) -{ + def_id: DefId, +) { let patch = add_moves_for_packed_drops_patch(tcx, body, def_id); patch.apply(body); } @@ -62,9 +58,8 @@ pub fn add_moves_for_packed_drops<'tcx>( fn add_moves_for_packed_drops_patch<'tcx>( tcx: TyCtxt<'tcx, 'tcx>, body: &Body<'tcx>, - def_id: DefId) - -> MirPatch<'tcx> -{ + def_id: DefId, +) -> MirPatch<'tcx> { let mut patch = MirPatch::new(body); let param_env = tcx.param_env(def_id); @@ -96,8 +91,8 @@ fn add_move_for_packed_drop<'tcx>( patch: &mut MirPatch<'tcx>, terminator: &Terminator<'tcx>, loc: Location, - is_cleanup: bool) -{ + is_cleanup: bool, +) { debug!("add_move_for_packed_drop({:?} @ {:?})", terminator, loc); let (location, target, unwind) = match terminator.kind { TerminatorKind::Drop { ref location, target, unwind } => diff --git a/src/librustc_mir/transform/add_retag.rs b/src/librustc_mir/transform/add_retag.rs index 8f6c83e170294..a67fce9028a32 100644 --- a/src/librustc_mir/transform/add_retag.rs +++ b/src/librustc_mir/transform/add_retag.rs @@ -74,11 +74,12 @@ fn may_have_reference<'gcx, 'tcx>(ty: Ty<'tcx>, tcx: TyCtxt<'gcx, 'tcx>) -> bool } impl MirPass for AddRetag { - fn run_pass<'tcx>(&self, - tcx: TyCtxt<'tcx, 'tcx>, - _src: MirSource<'tcx>, - body: &mut Body<'tcx>) - { + fn run_pass<'tcx>( + &self, + tcx: TyCtxt<'tcx, 'tcx>, + _src: MirSource<'tcx>, + body: &mut Body<'tcx>, + ) { if !tcx.sess.opts.debugging_opts.mir_emit_retag { return; } diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 84462c3940df4..0adb37b8722a3 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -480,11 +480,12 @@ impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for UnusedUnsafeVisitor<'a> { } } -fn check_unused_unsafe<'a, 'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - def_id: DefId, - used_unsafe: &FxHashSet, - unsafe_blocks: &'a mut Vec<(hir::HirId, bool)>) -{ +fn check_unused_unsafe<'a, 'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + def_id: DefId, + used_unsafe: &FxHashSet, + unsafe_blocks: &'a mut Vec<(hir::HirId, bool)>, +) { let body_id = tcx.hir().as_local_hir_id(def_id).and_then(|hir_id| { tcx.hir().maybe_body_owned_by_by_hir_id(hir_id) @@ -505,9 +506,7 @@ fn check_unused_unsafe<'a, 'tcx>(tcx: TyCtxt<'tcx, 'tcx>, hir::intravisit::Visitor::visit_body(&mut visitor, body); } -fn unsafety_check_result<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) - -> UnsafetyCheckResult -{ +fn unsafety_check_result<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> UnsafetyCheckResult { debug!("unsafety_violations({:?})", def_id); // N.B., this borrow is valid because all the consumers of @@ -566,9 +565,11 @@ fn unsafe_derive_on_repr_packed<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) { } /// Returns the `HirId` for an enclosing scope that is also `unsafe`. -fn is_enclosed(tcx: TyCtxt<'_, '_>, - used_unsafe: &FxHashSet, - id: hir::HirId) -> Option<(String, hir::HirId)> { +fn is_enclosed( + tcx: TyCtxt<'_, '_>, + used_unsafe: &FxHashSet, + id: hir::HirId, +) -> Option<(String, hir::HirId)> { let parent_id = tcx.hir().get_parent_node_by_hir_id(id); if parent_id != id { if used_unsafe.contains(&parent_id) { @@ -589,9 +590,7 @@ fn is_enclosed(tcx: TyCtxt<'_, '_>, } } -fn report_unused_unsafe(tcx: TyCtxt<'_, '_>, - used_unsafe: &FxHashSet, - id: hir::HirId) { +fn report_unused_unsafe(tcx: TyCtxt<'_, '_>, used_unsafe: &FxHashSet, id: hir::HirId) { let span = tcx.sess.source_map().def_span(tcx.hir().span_by_hir_id(id)); let msg = "unnecessary `unsafe` block"; let mut db = tcx.struct_span_lint_hir(UNUSED_UNSAFE, id, span, msg); diff --git a/src/librustc_mir/transform/cleanup_post_borrowck.rs b/src/librustc_mir/transform/cleanup_post_borrowck.rs index f552e635299e9..fb4fdf73a9389 100644 --- a/src/librustc_mir/transform/cleanup_post_borrowck.rs +++ b/src/librustc_mir/transform/cleanup_post_borrowck.rs @@ -27,10 +27,12 @@ pub struct CleanupNonCodegenStatements; pub struct DeleteNonCodegenStatements; impl MirPass for CleanupNonCodegenStatements { - fn run_pass<'tcx>(&self, - _tcx: TyCtxt<'tcx, 'tcx>, - _source: MirSource<'tcx>, - body: &mut Body<'tcx>) { + fn run_pass<'tcx>( + &self, + _tcx: TyCtxt<'tcx, 'tcx>, + _source: MirSource<'tcx>, + body: &mut Body<'tcx>, + ) { let mut delete = DeleteNonCodegenStatements; delete.visit_body(body); } diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 4a363f465a74f..dfc2e7e7c9d86 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -31,10 +31,12 @@ use crate::transform::{MirPass, MirSource}; pub struct ConstProp; impl MirPass for ConstProp { - fn run_pass<'tcx>(&self, - tcx: TyCtxt<'tcx, 'tcx>, - source: MirSource<'tcx>, - body: &mut Body<'tcx>) { + fn run_pass<'tcx>( + &self, + tcx: TyCtxt<'tcx, 'tcx>, + source: MirSource<'tcx>, + body: &mut Body<'tcx>, + ) { // will be evaluated by miri and produce its errors there if source.promoted.is_some() { return; @@ -599,9 +601,11 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { } } -fn type_size_of<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - param_env: ty::ParamEnv<'tcx>, - ty: Ty<'tcx>) -> Option { +fn type_size_of<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + param_env: ty::ParamEnv<'tcx>, + ty: Ty<'tcx>, +) -> Option { tcx.layout_of(param_env.and(ty)).ok().map(|layout| layout.size.bytes()) } diff --git a/src/librustc_mir/transform/copy_prop.rs b/src/librustc_mir/transform/copy_prop.rs index 6282c7855f35c..aeb3ed5a2eca8 100644 --- a/src/librustc_mir/transform/copy_prop.rs +++ b/src/librustc_mir/transform/copy_prop.rs @@ -30,10 +30,12 @@ use crate::util::def_use::DefUseAnalysis; pub struct CopyPropagation; impl MirPass for CopyPropagation { - fn run_pass<'tcx>(&self, - tcx: TyCtxt<'tcx, 'tcx>, - _source: MirSource<'tcx>, - body: &mut Body<'tcx>) { + fn run_pass<'tcx>( + &self, + tcx: TyCtxt<'tcx, 'tcx>, + _source: MirSource<'tcx>, + body: &mut Body<'tcx>, + ) { // We only run when the MIR optimization level is > 1. // This avoids a slow pass, and messing up debug info. if tcx.sess.opts.debugging_opts.mir_opt_level <= 1 { diff --git a/src/librustc_mir/transform/deaggregator.rs b/src/librustc_mir/transform/deaggregator.rs index 5ba7ba193d00e..87704f1221656 100644 --- a/src/librustc_mir/transform/deaggregator.rs +++ b/src/librustc_mir/transform/deaggregator.rs @@ -6,10 +6,12 @@ use crate::util::expand_aggregate; pub struct Deaggregator; impl MirPass for Deaggregator { - fn run_pass<'tcx>(&self, - tcx: TyCtxt<'tcx, 'tcx>, - _source: MirSource<'tcx>, - body: &mut Body<'tcx>) { + fn run_pass<'tcx>( + &self, + tcx: TyCtxt<'tcx, 'tcx>, + _source: MirSource<'tcx>, + body: &mut Body<'tcx>, + ) { let (basic_blocks, local_decls) = body.basic_blocks_and_local_decls_mut(); let local_decls = &*local_decls; for bb in basic_blocks { diff --git a/src/librustc_mir/transform/dump_mir.rs b/src/librustc_mir/transform/dump_mir.rs index 52aafdef87ecb..96be0e6f6a9d7 100644 --- a/src/librustc_mir/transform/dump_mir.rs +++ b/src/librustc_mir/transform/dump_mir.rs @@ -18,11 +18,12 @@ impl MirPass for Marker { Cow::Borrowed(self.0) } - fn run_pass<'tcx>(&self, - _tcx: TyCtxt<'tcx, 'tcx>, - _source: MirSource<'tcx>, - _body: &mut Body<'tcx>) - { + fn run_pass<'tcx>( + &self, + _tcx: TyCtxt<'tcx, 'tcx>, + _source: MirSource<'tcx>, + _body: &mut Body<'tcx>, + ) { } } @@ -37,13 +38,14 @@ impl fmt::Display for Disambiguator { } } - -pub fn on_mir_pass<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - pass_num: &dyn fmt::Display, - pass_name: &str, - source: MirSource<'tcx>, - body: &Body<'tcx>, - is_after: bool) { +pub fn on_mir_pass<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + pass_num: &dyn fmt::Display, + pass_name: &str, + source: MirSource<'tcx>, + body: &Body<'tcx>, + is_after: bool, +) { if mir_util::dump_enabled(tcx, pass_name, source) { mir_util::dump_mir(tcx, Some(pass_num), @@ -55,11 +57,7 @@ pub fn on_mir_pass<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, } } -pub fn emit_mir<'tcx>( - tcx: TyCtxt<'tcx, 'tcx>, - outputs: &OutputFilenames) - -> io::Result<()> -{ +pub fn emit_mir<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, outputs: &OutputFilenames) -> io::Result<()> { let path = outputs.path(OutputType::Mir); let mut f = File::create(&path)?; mir_util::write_mir_pretty(tcx, None, &mut f)?; diff --git a/src/librustc_mir/transform/elaborate_drops.rs b/src/librustc_mir/transform/elaborate_drops.rs index 2a187753626fd..bf6237fa91acf 100644 --- a/src/librustc_mir/transform/elaborate_drops.rs +++ b/src/librustc_mir/transform/elaborate_drops.rs @@ -21,11 +21,7 @@ use syntax_pos::Span; pub struct ElaborateDrops; impl MirPass for ElaborateDrops { - fn run_pass<'tcx>(&self, - tcx: TyCtxt<'tcx, 'tcx>, - src: MirSource<'tcx>, - body: &mut Body<'tcx>) - { + fn run_pass<'tcx>(&self, tcx: TyCtxt<'tcx, 'tcx>, src: MirSource<'tcx>, body: &mut Body<'tcx>) { debug!("elaborate_drops({:?} @ {:?})", src, body.span); let def_id = src.def_id(); @@ -77,13 +73,12 @@ impl MirPass for ElaborateDrops { /// Returns the set of basic blocks whose unwind edges are known /// to not be reachable, because they are `drop` terminators /// that can't drop anything. -fn find_dead_unwinds< 'tcx>( +fn find_dead_unwinds<'tcx>( tcx: TyCtxt<'tcx, 'tcx>, body: &Body<'tcx>, def_id: hir::def_id::DefId, - env: &MoveDataParamEnv<'tcx, 'tcx>) - -> BitSet -{ + env: &MoveDataParamEnv<'tcx, 'tcx>, +) -> BitSet { debug!("find_dead_unwinds({:?})", body.span); // We only need to do this pass once, because unwind edges can only // reach cleanup blocks, which can't have unwind edges themselves. @@ -141,12 +136,13 @@ struct InitializationData { } impl InitializationData { - fn apply_location<'tcx>(&mut self, - tcx: TyCtxt<'tcx, 'tcx>, - body: &Body<'tcx>, - env: &MoveDataParamEnv<'tcx, 'tcx>, - loc: Location) - { + fn apply_location<'tcx>( + &mut self, + tcx: TyCtxt<'tcx, 'tcx>, + body: &Body<'tcx>, + env: &MoveDataParamEnv<'tcx, 'tcx>, + loc: Location, + ) { drop_flag_effects_for_location(tcx, body, env, loc, |path, df| { debug!("at location {:?}: setting {:?} to {:?}", loc, path, df); @@ -294,7 +290,7 @@ struct ElaborateDropsCtxt<'a, 'tcx: 'a> { body: &'a Body<'tcx>, env: &'a MoveDataParamEnv<'tcx, 'tcx>, flow_inits: DataflowResults<'tcx, MaybeInitializedPlaces<'a, 'tcx, 'tcx>>, - flow_uninits: DataflowResults<'tcx, MaybeUninitializedPlaces<'a, 'tcx, 'tcx>>, + flow_uninits: DataflowResults<'tcx, MaybeUninitializedPlaces<'a, 'tcx, 'tcx>>, drop_flags: FxHashMap, patch: MirPatch<'tcx>, } diff --git a/src/librustc_mir/transform/erase_regions.rs b/src/librustc_mir/transform/erase_regions.rs index 78713fee82cd8..39d5770ee9a09 100644 --- a/src/librustc_mir/transform/erase_regions.rs +++ b/src/librustc_mir/transform/erase_regions.rs @@ -50,10 +50,7 @@ impl MutVisitor<'tcx> for EraseRegionsVisitor<'tcx> { pub struct EraseRegions; impl MirPass for EraseRegions { - fn run_pass<'tcx>(&self, - tcx: TyCtxt<'tcx, 'tcx>, - _: MirSource<'tcx>, - body: &mut Body<'tcx>) { + fn run_pass<'tcx>(&self, tcx: TyCtxt<'tcx, 'tcx>, _: MirSource<'tcx>, body: &mut Body<'tcx>) { EraseRegionsVisitor::new(tcx).visit_body(body); } } diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs index a3fef7c97b4c2..d369fec8c1e67 100644 --- a/src/librustc_mir/transform/generator.rs +++ b/src/librustc_mir/transform/generator.rs @@ -311,9 +311,10 @@ impl MutVisitor<'tcx> for TransformVisitor<'tcx> { } fn make_generator_state_argument_indirect<'tcx>( - tcx: TyCtxt<'tcx, 'tcx>, - def_id: DefId, - body: &mut Body<'tcx>) { + tcx: TyCtxt<'tcx, 'tcx>, + def_id: DefId, + body: &mut Body<'tcx>, +) { let gen_ty = body.local_decls.raw[1].ty; let region = ty::ReFree(ty::FreeRegion { @@ -335,9 +336,7 @@ fn make_generator_state_argument_indirect<'tcx>( DerefArgVisitor.visit_body(body); } -fn make_generator_state_argument_pinned<'tcx>( - tcx: TyCtxt<'tcx, 'tcx>, - body: &mut Body<'tcx>) { +fn make_generator_state_argument_pinned<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, body: &mut Body<'tcx>) { let ref_gen_ty = body.local_decls.raw[1].ty; let pin_did = tcx.lang_items().pin_type().unwrap(); @@ -678,16 +677,18 @@ impl<'body, 'tcx: 'body, 's> StorageConflictVisitor<'body, 'tcx, 's> { } } -fn compute_layout<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - source: MirSource<'tcx>, - upvars: &Vec>, - interior: Ty<'tcx>, - movable: bool, - body: &mut Body<'tcx>) - -> (FxHashMap, VariantIdx, usize)>, - GeneratorLayout<'tcx>, - FxHashMap) -{ +fn compute_layout<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + source: MirSource<'tcx>, + upvars: &Vec>, + interior: Ty<'tcx>, + movable: bool, + body: &mut Body<'tcx>, +) -> ( + FxHashMap, VariantIdx, usize)>, + GeneratorLayout<'tcx>, + FxHashMap, +) { // Use a liveness analysis to compute locals which are live across a suspension point let LivenessInfo { live_locals, live_locals_at_suspension_points, storage_conflicts, storage_liveness @@ -767,10 +768,12 @@ fn compute_layout<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, (remap, layout, storage_liveness) } -fn insert_switch<'tcx>(body: &mut Body<'tcx>, - cases: Vec<(usize, BasicBlock)>, - transform: &TransformVisitor<'tcx>, - default: TerminatorKind<'tcx>) { +fn insert_switch<'tcx>( + body: &mut Body<'tcx>, + cases: Vec<(usize, BasicBlock)>, + transform: &TransformVisitor<'tcx>, + default: TerminatorKind<'tcx>, +) { let default_block = insert_term_block(body, default); let (assign, discr) = transform.get_discr(body); let switch = TerminatorKind::SwitchInt { @@ -797,9 +800,7 @@ fn insert_switch<'tcx>(body: &mut Body<'tcx>, } } -fn elaborate_generator_drops<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - def_id: DefId, - body: &mut Body<'tcx>) { +fn elaborate_generator_drops<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId, body: &mut Body<'tcx>) { use crate::util::elaborate_drops::{elaborate_drop, Unwind}; use crate::util::patch::MirPatch; use crate::shim::DropShimElaborator; @@ -849,13 +850,14 @@ fn elaborate_generator_drops<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, } fn create_generator_drop_shim<'tcx>( - tcx: TyCtxt<'tcx, 'tcx>, - transform: &TransformVisitor<'tcx>, - def_id: DefId, - source: MirSource<'tcx>, - gen_ty: Ty<'tcx>, - body: &Body<'tcx>, - drop_clean: BasicBlock) -> Body<'tcx> { + tcx: TyCtxt<'tcx, 'tcx>, + transform: &TransformVisitor<'tcx>, + def_id: DefId, + source: MirSource<'tcx>, + gen_ty: Ty<'tcx>, + body: &Body<'tcx>, + drop_clean: BasicBlock, +) -> Body<'tcx> { let mut body = body.clone(); let source_info = source_info(&body); @@ -939,9 +941,11 @@ fn insert_term_block<'tcx>(body: &mut Body<'tcx>, kind: TerminatorKind<'tcx>) -> term_block } -fn insert_panic_block<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - body: &mut Body<'tcx>, - message: AssertMessage<'tcx>) -> BasicBlock { +fn insert_panic_block<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + body: &mut Body<'tcx>, + message: AssertMessage<'tcx>, +) -> BasicBlock { let assert_block = BasicBlock::new(body.basic_blocks().len()); let term = TerminatorKind::Assert { cond: Operand::Constant(box Constant { @@ -970,11 +974,12 @@ fn insert_panic_block<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, } fn create_generator_resume_function<'tcx>( - tcx: TyCtxt<'tcx, 'tcx>, - transform: TransformVisitor<'tcx>, - def_id: DefId, - source: MirSource<'tcx>, - body: &mut Body<'tcx>) { + tcx: TyCtxt<'tcx, 'tcx>, + transform: TransformVisitor<'tcx>, + def_id: DefId, + source: MirSource<'tcx>, + body: &mut Body<'tcx>, +) { // Poison the generator when it unwinds for block in body.basic_blocks_mut() { let source_info = block.terminator().source_info; @@ -1042,10 +1047,14 @@ fn insert_clean_drop<'tcx>(body: &mut Body<'tcx>) -> BasicBlock { drop_clean } -fn create_cases<'tcx, F>(body: &mut Body<'tcx>, - transform: &TransformVisitor<'tcx>, - target: F) -> Vec<(usize, BasicBlock)> - where F: Fn(&SuspensionPoint) -> Option { +fn create_cases<'tcx, F>( + body: &mut Body<'tcx>, + transform: &TransformVisitor<'tcx>, + target: F, +) -> Vec<(usize, BasicBlock)> +where + F: Fn(&SuspensionPoint) -> Option, +{ let source_info = source_info(body); transform.suspension_points.iter().filter_map(|point| { @@ -1083,10 +1092,12 @@ fn create_cases<'tcx, F>(body: &mut Body<'tcx>, } impl MirPass for StateTransform { - fn run_pass<'tcx>(&self, - tcx: TyCtxt<'tcx, 'tcx>, - source: MirSource<'tcx>, - body: &mut Body<'tcx>) { + fn run_pass<'tcx>( + &self, + tcx: TyCtxt<'tcx, 'tcx>, + source: MirSource<'tcx>, + body: &mut Body<'tcx>, + ) { let yield_ty = if let Some(yield_ty) = body.yield_ty { yield_ty } else { diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs index 2818c11da4697..55c035f2858a2 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -38,10 +38,12 @@ struct CallSite<'tcx> { } impl MirPass for Inline { - fn run_pass<'tcx>(&self, - tcx: TyCtxt<'tcx, 'tcx>, - source: MirSource<'tcx>, - body: &mut Body<'tcx>) { + fn run_pass<'tcx>( + &self, + tcx: TyCtxt<'tcx, 'tcx>, + source: MirSource<'tcx>, + body: &mut Body<'tcx>, + ) { if tcx.sess.opts.debugging_opts.mir_opt_level >= 2 { Inliner { tcx, source }.run_pass(body); } @@ -631,9 +633,11 @@ impl Inliner<'tcx> { } } -fn type_size_of<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - param_env: ty::ParamEnv<'tcx>, - ty: Ty<'tcx>) -> Option { +fn type_size_of<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + param_env: ty::ParamEnv<'tcx>, + ty: Ty<'tcx>, +) -> Option { tcx.layout_of(param_env.and(ty)).ok().map(|layout| layout.size.bytes()) } @@ -643,7 +647,7 @@ fn type_size_of<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, * Integrates blocks from the callee function into the calling function. * Updates block indices, references to locals and other control flow * stuff. - */ +*/ struct Integrator<'a, 'tcx: 'a> { block_idx: usize, args: &'a [Local], diff --git a/src/librustc_mir/transform/instcombine.rs b/src/librustc_mir/transform/instcombine.rs index 89be1ba0bdf2f..2194b780ab967 100644 --- a/src/librustc_mir/transform/instcombine.rs +++ b/src/librustc_mir/transform/instcombine.rs @@ -12,10 +12,7 @@ use crate::transform::{MirPass, MirSource}; pub struct InstCombine; impl MirPass for InstCombine { - fn run_pass<'tcx>(&self, - tcx: TyCtxt<'tcx, 'tcx>, - _: MirSource<'tcx>, - body: &mut Body<'tcx>) { + fn run_pass<'tcx>(&self, tcx: TyCtxt<'tcx, 'tcx>, _: MirSource<'tcx>, body: &mut Body<'tcx>) { // We only run when optimizing MIR (at any level). if tcx.sess.opts.debugging_opts.mir_opt_level == 0 { return diff --git a/src/librustc_mir/transform/lower_128bit.rs b/src/librustc_mir/transform/lower_128bit.rs index 2b28eeb801ff8..34a982f72761f 100644 --- a/src/librustc_mir/transform/lower_128bit.rs +++ b/src/librustc_mir/transform/lower_128bit.rs @@ -10,10 +10,12 @@ use crate::transform::{MirPass, MirSource}; pub struct Lower128Bit; impl MirPass for Lower128Bit { - fn run_pass<'tcx>(&self, - tcx: TyCtxt<'tcx, 'tcx>, - _src: MirSource<'tcx>, - body: &mut Body<'tcx>) { + fn run_pass<'tcx>( + &self, + tcx: TyCtxt<'tcx, 'tcx>, + _src: MirSource<'tcx>, + body: &mut Body<'tcx>, + ) { let debugging_override = tcx.sess.opts.debugging_opts.lower_128bit_ops; let target_default = tcx.sess.host.options.i128_lowering; if !debugging_override.unwrap_or(target_default) { @@ -21,7 +23,7 @@ impl MirPass for Lower128Bit { } self.lower_128bit_ops(tcx, body); - } +} } impl Lower128Bit { @@ -126,9 +128,10 @@ fn check_lang_item_type<'tcx, D>( lhs: &Operand<'tcx>, rhs: &Operand<'tcx>, local_decls: &D, - tcx: TyCtxt<'tcx, 'tcx>) --> DefId - where D: HasLocalDecls<'tcx> + tcx: TyCtxt<'tcx, 'tcx>, +) -> DefId +where + D: HasLocalDecls<'tcx>, { let did = tcx.require_lang_item(lang_item); let poly_sig = tcx.fn_sig(did); @@ -142,9 +145,13 @@ fn check_lang_item_type<'tcx, D>( did } -fn lower_to<'tcx, D>(statement: &Statement<'tcx>, local_decls: &D, tcx: TyCtxt<'tcx, 'tcx>) - -> Option<(LangItem, RhsKind)> - where D: HasLocalDecls<'tcx> +fn lower_to<'tcx, D>( + statement: &Statement<'tcx>, + local_decls: &D, + tcx: TyCtxt<'tcx, 'tcx>, +) -> Option<(LangItem, RhsKind)> +where + D: HasLocalDecls<'tcx>, { match statement.kind { StatementKind::Assign(_, box Rvalue::BinaryOp(bin_op, ref lhs, _)) => { diff --git a/src/librustc_mir/transform/mod.rs b/src/librustc_mir/transform/mod.rs index eb89648826748..6f369acec6440 100644 --- a/src/librustc_mir/transform/mod.rs +++ b/src/librustc_mir/transform/mod.rs @@ -56,8 +56,7 @@ fn is_mir_available<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> bool { /// Finds the full set of `DefId`s within the current crate that have /// MIR associated with them. -fn mir_keys<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, krate: CrateNum) - -> &'tcx DefIdSet { +fn mir_keys<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, krate: CrateNum) -> &'tcx DefIdSet { assert_eq!(krate, LOCAL_CRATE); let mut set = DefIdSet::default(); @@ -142,10 +141,12 @@ pub trait MirPass { default_name::() } - fn run_pass<'tcx>(&self, - tcx: TyCtxt<'tcx, 'tcx>, - source: MirSource<'tcx>, - body: &mut Body<'tcx>); + fn run_pass<'tcx>( + &self, + tcx: TyCtxt<'tcx, 'tcx>, + source: MirSource<'tcx>, + body: &mut Body<'tcx>, + ); } pub fn run_passes( diff --git a/src/librustc_mir/transform/no_landing_pads.rs b/src/librustc_mir/transform/no_landing_pads.rs index 638aa1e7e02de..6f3f2269d44d2 100644 --- a/src/librustc_mir/transform/no_landing_pads.rs +++ b/src/librustc_mir/transform/no_landing_pads.rs @@ -9,10 +9,7 @@ use crate::transform::{MirPass, MirSource}; pub struct NoLandingPads; impl MirPass for NoLandingPads { - fn run_pass<'tcx>(&self, - tcx: TyCtxt<'tcx, 'tcx>, - _: MirSource<'tcx>, - body: &mut Body<'tcx>) { + fn run_pass<'tcx>(&self, tcx: TyCtxt<'tcx, 'tcx>, _: MirSource<'tcx>, body: &mut Body<'tcx>) { no_landing_pads(tcx, body) } } diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index 7bbaa99798d5f..f3d05f065ce73 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -155,7 +155,7 @@ struct Promoter<'a, 'tcx: 'a> { /// If true, all nested temps are also kept in the /// source MIR, not moved to the promoted MIR. - keep_original: bool + keep_original: bool, } impl<'a, 'tcx> Promoter<'a, 'tcx> { @@ -369,10 +369,12 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Promoter<'a, 'tcx> { } } -pub fn promote_candidates<'tcx>(body: &mut Body<'tcx>, - tcx: TyCtxt<'tcx, 'tcx>, - mut temps: IndexVec, - candidates: Vec) { +pub fn promote_candidates<'tcx>( + body: &mut Body<'tcx>, + tcx: TyCtxt<'tcx, 'tcx>, + mut temps: IndexVec, + candidates: Vec, +) { // Visit candidates in reverse, in case they're nested. debug!("promote_candidates({:?})", candidates); diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 32d3b4589629c..125411a717d1e 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -652,11 +652,7 @@ impl Deref for Checker<'a, 'tcx> { } impl<'a, 'tcx> Checker<'a, 'tcx> { - fn new(tcx: TyCtxt<'tcx, 'tcx>, - def_id: DefId, - body: &'a Body<'tcx>, - mode: Mode) - -> Self { + fn new(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId, body: &'a Body<'tcx>, mode: Mode) -> Self { assert!(def_id.is_local()); let mut rpo = traversal::reverse_postorder(body); let temps = promote_consts::collect_temps(body, &mut rpo); @@ -1472,9 +1468,7 @@ pub fn provide(providers: &mut Providers<'_>) { }; } -fn mir_const_qualif<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - def_id: DefId) - -> (u8, &'tcx BitSet) { +fn mir_const_qualif<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> (u8, &'tcx BitSet) { // N.B., this `borrow()` is guaranteed to be valid (i.e., the value // cannot yet be stolen), because `mir_validated()`, which steals // from `mir_const(), forces this query to execute before @@ -1492,10 +1486,7 @@ fn mir_const_qualif<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, pub struct QualifyAndPromoteConstants; impl MirPass for QualifyAndPromoteConstants { - fn run_pass<'tcx>(&self, - tcx: TyCtxt<'tcx, 'tcx>, - src: MirSource<'tcx>, - body: &mut Body<'tcx>) { + fn run_pass<'tcx>(&self, tcx: TyCtxt<'tcx, 'tcx>, src: MirSource<'tcx>, body: &mut Body<'tcx>) { // There's not really any point in promoting errorful MIR. if body.return_ty().references_error() { tcx.sess.delay_span_bug(body.span, "QualifyAndPromoteConstants: MIR had errors"); diff --git a/src/librustc_mir/transform/qualify_min_const_fn.rs b/src/librustc_mir/transform/qualify_min_const_fn.rs index 449d2d32456bd..7f5afb2394a46 100644 --- a/src/librustc_mir/transform/qualify_min_const_fn.rs +++ b/src/librustc_mir/transform/qualify_min_const_fn.rs @@ -8,11 +8,7 @@ use syntax_pos::Span; type McfResult = Result<(), (Span, Cow<'static, str>)>; -pub fn is_min_const_fn( - tcx: TyCtxt<'tcx, 'tcx>, - def_id: DefId, - body: &'a Body<'tcx>, -) -> McfResult { +pub fn is_min_const_fn(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId, body: &'a Body<'tcx>) -> McfResult { let mut current = def_id; loop { let predicates = tcx.predicates_of(current); @@ -79,12 +75,7 @@ pub fn is_min_const_fn( Ok(()) } -fn check_ty( - tcx: TyCtxt<'tcx, 'tcx>, - ty: Ty<'tcx>, - span: Span, - fn_def_id: DefId, -) -> McfResult { +fn check_ty(tcx: TyCtxt<'tcx, 'tcx>, ty: Ty<'tcx>, span: Span, fn_def_id: DefId) -> McfResult { for ty in ty.walk() { match ty.sty { ty::Ref(_, _, hir::Mutability::MutMutable) => return Err(( diff --git a/src/librustc_mir/transform/remove_noop_landing_pads.rs b/src/librustc_mir/transform/remove_noop_landing_pads.rs index 23541a6e6bc7e..1a23fdce050b0 100644 --- a/src/librustc_mir/transform/remove_noop_landing_pads.rs +++ b/src/librustc_mir/transform/remove_noop_landing_pads.rs @@ -9,10 +9,7 @@ use crate::util::patch::MirPatch; /// code for these. pub struct RemoveNoopLandingPads; -pub fn remove_noop_landing_pads<'tcx>( - tcx: TyCtxt<'tcx, 'tcx>, - body: &mut Body<'tcx>) -{ +pub fn remove_noop_landing_pads<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, body: &mut Body<'tcx>) { if tcx.sess.no_landing_pads() { return } @@ -22,10 +19,12 @@ pub fn remove_noop_landing_pads<'tcx>( } impl MirPass for RemoveNoopLandingPads { - fn run_pass<'tcx>(&self, - tcx: TyCtxt<'tcx, 'tcx>, - _src: MirSource<'tcx>, - body: &mut Body<'tcx>) { + fn run_pass<'tcx>( + &self, + tcx: TyCtxt<'tcx, 'tcx>, + _src: MirSource<'tcx>, + body: &mut Body<'tcx>, + ) { remove_noop_landing_pads(tcx, body); } } diff --git a/src/librustc_mir/transform/rustc_peek.rs b/src/librustc_mir/transform/rustc_peek.rs index 2a25cd2c9573a..1d57f5e27164d 100644 --- a/src/librustc_mir/transform/rustc_peek.rs +++ b/src/librustc_mir/transform/rustc_peek.rs @@ -25,8 +25,7 @@ use crate::dataflow::has_rustc_mir_with; pub struct SanityCheck; impl MirPass for SanityCheck { - fn run_pass<'tcx>(&self, tcx: TyCtxt<'tcx, 'tcx>, - src: MirSource<'tcx>, body: &mut Body<'tcx>) { + fn run_pass<'tcx>(&self, tcx: TyCtxt<'tcx, 'tcx>, src: MirSource<'tcx>, body: &mut Body<'tcx>) { let def_id = src.def_id(); if !tcx.has_attr(def_id, sym::rustc_mir) { debug!("skipping rustc_peek::SanityCheck on {}", tcx.def_path_str(def_id)); @@ -84,12 +83,14 @@ impl MirPass for SanityCheck { /// (If there are any calls to `rustc_peek` that do not match the /// expression form above, then that emits an error as well, but those /// errors are not intended to be used for unit tests.) -pub fn sanity_check_via_rustc_peek<'tcx, O>(tcx: TyCtxt<'tcx, 'tcx>, - body: &Body<'tcx>, - def_id: DefId, - _attributes: &[ast::Attribute], - results: &DataflowResults<'tcx, O>) - where O: BitDenotation<'tcx, Idx=MovePathIndex> + HasMoveData<'tcx> +pub fn sanity_check_via_rustc_peek<'tcx, O>( + tcx: TyCtxt<'tcx, 'tcx>, + body: &Body<'tcx>, + def_id: DefId, + _attributes: &[ast::Attribute], + results: &DataflowResults<'tcx, O>, +) where + O: BitDenotation<'tcx, Idx = MovePathIndex> + HasMoveData<'tcx>, { debug!("sanity_check_via_rustc_peek def_id: {:?}", def_id); // FIXME: this is not DRY. Figure out way to abstract this and @@ -101,11 +102,13 @@ pub fn sanity_check_via_rustc_peek<'tcx, O>(tcx: TyCtxt<'tcx, 'tcx>, } } -fn each_block<'tcx, O>(tcx: TyCtxt<'tcx, 'tcx>, - body: &Body<'tcx>, - results: &DataflowResults<'tcx, O>, - bb: mir::BasicBlock) where - O: BitDenotation<'tcx, Idx=MovePathIndex> + HasMoveData<'tcx> +fn each_block<'tcx, O>( + tcx: TyCtxt<'tcx, 'tcx>, + body: &Body<'tcx>, + results: &DataflowResults<'tcx, O>, + bb: mir::BasicBlock, +) where + O: BitDenotation<'tcx, Idx = MovePathIndex> + HasMoveData<'tcx>, { let move_data = results.0.operator.move_data(); let mir::BasicBlockData { ref statements, ref terminator, is_cleanup: _ } = body[bb]; @@ -214,9 +217,10 @@ fn each_block<'tcx, O>(tcx: TyCtxt<'tcx, 'tcx>, form `&expr`")); } -fn is_rustc_peek<'a, 'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - terminator: &'a Option>) - -> Option<(&'a [mir::Operand<'tcx>], Span)> { +fn is_rustc_peek<'a, 'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + terminator: &'a Option>, +) -> Option<(&'a [mir::Operand<'tcx>], Span)> { if let Some(mir::Terminator { ref kind, source_info, .. }) = *terminator { if let mir::TerminatorKind::Call { func: ref oper, ref args, .. } = *kind { if let mir::Operand::Constant(ref func) = *oper { diff --git a/src/librustc_mir/transform/simplify.rs b/src/librustc_mir/transform/simplify.rs index 65838946a7859..ba3a00517ffb0 100644 --- a/src/librustc_mir/transform/simplify.rs +++ b/src/librustc_mir/transform/simplify.rs @@ -57,10 +57,12 @@ impl MirPass for SimplifyCfg { Cow::Borrowed(&self.label) } - fn run_pass<'tcx>(&self, - _tcx: TyCtxt<'tcx, 'tcx>, - _src: MirSource<'tcx>, - body: &mut Body<'tcx>) { + fn run_pass<'tcx>( + &self, + _tcx: TyCtxt<'tcx, 'tcx>, + _src: MirSource<'tcx>, + body: &mut Body<'tcx>, + ) { debug!("SimplifyCfg({:?}) - simplifying {:?}", self.label, body); simplify_cfg(body); } @@ -296,10 +298,7 @@ pub fn remove_dead_blocks(body: &mut Body<'_>) { pub struct SimplifyLocals; impl MirPass for SimplifyLocals { - fn run_pass<'tcx>(&self, - tcx: TyCtxt<'tcx, 'tcx>, - _: MirSource<'tcx>, - body: &mut Body<'tcx>) { + fn run_pass<'tcx>(&self, tcx: TyCtxt<'tcx, 'tcx>, _: MirSource<'tcx>, body: &mut Body<'tcx>) { let mut marker = DeclMarker { locals: BitSet::new_empty(body.local_decls.len()) }; marker.visit_body(body); // Return pointer and arguments are always live diff --git a/src/librustc_mir/transform/simplify_branches.rs b/src/librustc_mir/transform/simplify_branches.rs index 6f6dd1a7c8095..a1c3fec32fcf1 100644 --- a/src/librustc_mir/transform/simplify_branches.rs +++ b/src/librustc_mir/transform/simplify_branches.rs @@ -19,10 +19,12 @@ impl MirPass for SimplifyBranches { Cow::Borrowed(&self.label) } - fn run_pass<'tcx>(&self, - tcx: TyCtxt<'tcx, 'tcx>, - _src: MirSource<'tcx>, - body: &mut Body<'tcx>) { + fn run_pass<'tcx>( + &self, + tcx: TyCtxt<'tcx, 'tcx>, + _src: MirSource<'tcx>, + body: &mut Body<'tcx>, + ) { for block in body.basic_blocks_mut() { let terminator = block.terminator_mut(); terminator.kind = match terminator.kind { diff --git a/src/librustc_mir/transform/uniform_array_move_out.rs b/src/librustc_mir/transform/uniform_array_move_out.rs index f71c30e587d7b..4e961d80f4c82 100644 --- a/src/librustc_mir/transform/uniform_array_move_out.rs +++ b/src/librustc_mir/transform/uniform_array_move_out.rs @@ -37,10 +37,12 @@ use crate::util::patch::MirPatch; pub struct UniformArrayMoveOut; impl MirPass for UniformArrayMoveOut { - fn run_pass<'tcx>(&self, - tcx: TyCtxt<'tcx, 'tcx>, - _src: MirSource<'tcx>, - body: &mut Body<'tcx>) { + fn run_pass<'tcx>( + &self, + tcx: TyCtxt<'tcx, 'tcx>, + _src: MirSource<'tcx>, + body: &mut Body<'tcx>, + ) { let mut patch = MirPatch::new(body); { let mut visitor = UniformArrayMoveOutVisitor{body, patch: &mut patch, tcx}; @@ -162,10 +164,12 @@ impl<'a, 'tcx> UniformArrayMoveOutVisitor<'a, 'tcx> { pub struct RestoreSubsliceArrayMoveOut; impl MirPass for RestoreSubsliceArrayMoveOut { - fn run_pass<'tcx>(&self, - tcx: TyCtxt<'tcx, 'tcx>, - _src: MirSource<'tcx>, - body: &mut Body<'tcx>) { + fn run_pass<'tcx>( + &self, + tcx: TyCtxt<'tcx, 'tcx>, + _src: MirSource<'tcx>, + body: &mut Body<'tcx>, + ) { let mut patch = MirPatch::new(body); { let mut visitor = RestoreDataCollector { diff --git a/src/librustc_mir/util/alignment.rs b/src/librustc_mir/util/alignment.rs index c171bef4c96c4..b23ce28f30120 100644 --- a/src/librustc_mir/util/alignment.rs +++ b/src/librustc_mir/util/alignment.rs @@ -4,12 +4,14 @@ use rustc::mir::*; /// Returns `true` if this place is allowed to be less aligned /// than its containing struct (because it is within a packed /// struct). -pub fn is_disaligned<'tcx, L>(tcx: TyCtxt<'tcx, 'tcx>, - local_decls: &L, - param_env: ty::ParamEnv<'tcx>, - place: &Place<'tcx>) - -> bool - where L: HasLocalDecls<'tcx> +pub fn is_disaligned<'tcx, L>( + tcx: TyCtxt<'tcx, 'tcx>, + local_decls: &L, + param_env: ty::ParamEnv<'tcx>, + place: &Place<'tcx>, +) -> bool +where + L: HasLocalDecls<'tcx>, { debug!("is_disaligned({:?})", place); if !is_within_packed(tcx, local_decls, place) { @@ -32,11 +34,9 @@ pub fn is_disaligned<'tcx, L>(tcx: TyCtxt<'tcx, 'tcx>, } } -fn is_within_packed<'tcx, L>(tcx: TyCtxt<'tcx, 'tcx>, - local_decls: &L, - place: &Place<'tcx>) - -> bool - where L: HasLocalDecls<'tcx> +fn is_within_packed<'tcx, L>(tcx: TyCtxt<'tcx, 'tcx>, local_decls: &L, place: &Place<'tcx>) -> bool +where + L: HasLocalDecls<'tcx>, { let mut place = place; while let &Place::Projection(box Projection { diff --git a/src/librustc_mir/util/elaborate_drops.rs b/src/librustc_mir/util/elaborate_drops.rs index efcb23aab2ed9..f6cc1033b777c 100644 --- a/src/librustc_mir/util/elaborate_drops.rs +++ b/src/librustc_mir/util/elaborate_drops.rs @@ -70,7 +70,7 @@ impl Unwind { } } -pub trait DropElaborator<'a, 'tcx: 'a> : fmt::Debug { +pub trait DropElaborator<'a, 'tcx: 'a>: fmt::Debug { type Path : Copy + fmt::Debug; fn patch(&mut self) -> &mut MirPatch<'tcx>; diff --git a/src/librustc_mir/util/graphviz.rs b/src/librustc_mir/util/graphviz.rs index 2dc6c9061bf7a..0746434c184b5 100644 --- a/src/librustc_mir/util/graphviz.rs +++ b/src/librustc_mir/util/graphviz.rs @@ -8,11 +8,13 @@ use std::io::{self, Write}; use super::pretty::dump_mir_def_ids; /// Write a graphviz DOT graph of a list of MIRs. -pub fn write_mir_graphviz<'tcx, W>(tcx: TyCtxt<'_, 'tcx>, - single: Option, - w: &mut W) - -> io::Result<()> - where W: Write +pub fn write_mir_graphviz<'tcx, W>( + tcx: TyCtxt<'_, 'tcx>, + single: Option, + w: &mut W, +) -> io::Result<()> +where + W: Write, { for def_id in dump_mir_def_ids(tcx, single) { let body = &tcx.optimized_mir(def_id); @@ -32,11 +34,14 @@ pub fn graphviz_safe_def_name(def_id: DefId) -> String { } /// Write a graphviz DOT graph of the MIR. -pub fn write_mir_fn_graphviz<'tcx, W>(tcx: TyCtxt<'_, 'tcx>, - def_id: DefId, - body: &Body<'_>, - w: &mut W) -> io::Result<()> - where W: Write +pub fn write_mir_fn_graphviz<'tcx, W>( + tcx: TyCtxt<'_, 'tcx>, + def_id: DefId, + body: &Body<'_>, + w: &mut W, +) -> io::Result<()> +where + W: Write, { writeln!(w, "digraph Mir_{} {{", graphviz_safe_def_name(def_id))?; @@ -133,11 +138,12 @@ fn write_edges(source: BasicBlock, body: &Body<'_>, w: &mut W) -> io:: /// Write the graphviz DOT label for the overall graph. This is essentially a block of text that /// will appear below the graph, showing the type of the `fn` this MIR represents and the types of /// all the variables and temporaries. -fn write_graph_label<'gcx, 'tcx, W: Write>(tcx: TyCtxt<'gcx, 'tcx>, - def_id: DefId, - body: &Body<'_>, - w: &mut W) - -> io::Result<()> { +fn write_graph_label<'gcx, 'tcx, W: Write>( + tcx: TyCtxt<'gcx, 'tcx>, + def_id: DefId, + body: &Body<'_>, + w: &mut W, +) -> io::Result<()> { write!(w, " label=) { }; } -fn const_is_rvalue_promotable_to_static<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - def_id: DefId) - -> bool -{ +fn const_is_rvalue_promotable_to_static<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> bool { assert!(def_id.is_local()); let hir_id = tcx.hir().as_local_hir_id(def_id) @@ -51,10 +48,7 @@ fn const_is_rvalue_promotable_to_static<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, tcx.rvalue_promotable_map(def_id).contains(&body_id.hir_id.local_id) } -fn rvalue_promotable_map<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - def_id: DefId) - -> &'tcx ItemLocalSet -{ +fn rvalue_promotable_map<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> &'tcx ItemLocalSet { let outer_def_id = tcx.closure_base_def_id(def_id); if outer_def_id != def_id { return tcx.rvalue_promotable_map(outer_def_id); diff --git a/src/librustc_plugin/build.rs b/src/librustc_plugin/build.rs index f269d3af91f89..f5cb04c743250 100644 --- a/src/librustc_plugin/build.rs +++ b/src/librustc_plugin/build.rs @@ -34,10 +34,7 @@ pub fn find_plugin_registrar<'tcx>(tcx: TyCtxt<'tcx, 'tcx>) -> Option { tcx.plugin_registrar_fn(LOCAL_CRATE) } -fn plugin_registrar_fn<'tcx>( - tcx: TyCtxt<'tcx, 'tcx>, - cnum: CrateNum, -) -> Option { +fn plugin_registrar_fn<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, cnum: CrateNum) -> Option { assert_eq!(cnum, LOCAL_CRATE); let mut finder = RegistrarFinder { registrars: Vec::new() }; diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 38e102345b3e7..a2da014c912d1 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -74,7 +74,8 @@ trait DefIdVisitor<'tcx> { } struct DefIdVisitorSkeleton<'v, 'tcx, V> - where V: DefIdVisitor<'tcx> + ?Sized +where + V: DefIdVisitor<'tcx> + ?Sized, { def_id_visitor: &'v mut V, visited_opaque_tys: FxHashSet, @@ -82,7 +83,8 @@ struct DefIdVisitorSkeleton<'v, 'tcx, V> } impl<'tcx, V> DefIdVisitorSkeleton<'_, 'tcx, V> - where V: DefIdVisitor<'tcx> + ?Sized +where + V: DefIdVisitor<'tcx> + ?Sized, { fn visit_trait(&mut self, trait_ref: TraitRef<'tcx>) -> bool { let TraitRef { def_id, substs } = trait_ref; @@ -125,7 +127,8 @@ impl<'tcx, V> DefIdVisitorSkeleton<'_, 'tcx, V> } impl<'tcx, V> TypeVisitor<'tcx> for DefIdVisitorSkeleton<'_, 'tcx, V> - where V: DefIdVisitor<'tcx> + ?Sized +where + V: DefIdVisitor<'tcx> + ?Sized, { fn visit_ty(&mut self, ty: Ty<'tcx>) -> bool { let tcx = self.def_id_visitor.tcx(); @@ -220,8 +223,10 @@ impl<'tcx, V> TypeVisitor<'tcx> for DefIdVisitorSkeleton<'_, 'tcx, V> } } -fn def_id_visibility<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) - -> (ty::Visibility, Span, &'static str) { +fn def_id_visibility<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + def_id: DefId, +) -> (ty::Visibility, Span, &'static str) { match tcx.hir().as_local_hir_id(def_id) { Some(hir_id) => { let vis = match tcx.hir().get_by_hir_id(hir_id) { @@ -323,16 +328,20 @@ fn def_id_visibility<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) // Set the correct `TypeckTables` for the given `item_id` (or an empty table if // there is no `TypeckTables` for the item). -fn item_tables<'a, 'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - hir_id: hir::HirId, - empty_tables: &'a ty::TypeckTables<'tcx>) - -> &'a ty::TypeckTables<'tcx> { +fn item_tables<'a, 'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + hir_id: hir::HirId, + empty_tables: &'a ty::TypeckTables<'tcx>, +) -> &'a ty::TypeckTables<'tcx> { let def_id = tcx.hir().local_def_id_from_hir_id(hir_id); if tcx.has_typeck_tables(def_id) { tcx.typeck_tables_of(def_id) } else { empty_tables } } -fn min<'tcx>(vis1: ty::Visibility, vis2: ty::Visibility, tcx: TyCtxt<'tcx, 'tcx>) - -> ty::Visibility { +fn min<'tcx>( + vis1: ty::Visibility, + vis2: ty::Visibility, + tcx: TyCtxt<'tcx, 'tcx>, +) -> ty::Visibility { if vis1.is_at_least(vis2, tcx) { vis2 } else { vis1 } } @@ -343,7 +352,7 @@ fn min<'tcx>(vis1: ty::Visibility, vis2: ty::Visibility, tcx: TyCtxt<'tcx, 'tcx> /// in crates that have been updated to use pub(restricted). //////////////////////////////////////////////////////////////////////////////// struct PubRestrictedVisitor<'tcx> { - tcx: TyCtxt<'tcx, 'tcx>, + tcx: TyCtxt<'tcx, 'tcx>, has_pub_restricted: bool, } @@ -383,8 +392,11 @@ trait VisibilityLike: Sized { // Returns an over-approximation (`skip_assoc_tys` = true) of visibility due to // associated types for which we can't determine visibility precisely. - fn of_impl<'a, 'tcx>(hir_id: hir::HirId, tcx: TyCtxt<'tcx, 'tcx>, - access_levels: &'a AccessLevels) -> Self { + fn of_impl<'a, 'tcx>( + hir_id: hir::HirId, + tcx: TyCtxt<'tcx, 'tcx>, + access_levels: &'a AccessLevels, + ) -> Self { let mut find = FindMin { tcx, access_levels, min: Self::MAX }; let def_id = tcx.hir().local_def_id_from_hir_id(hir_id); find.visit(tcx.type_of(def_id)); @@ -460,8 +472,11 @@ impl EmbargoVisitor<'tcx> { } } - fn reach(&mut self, item_id: hir::HirId, access_level: Option) - -> ReachEverythingInTheInterfaceVisitor<'_, 'tcx> { + fn reach( + &mut self, + item_id: hir::HirId, + access_level: Option, + ) -> ReachEverythingInTheInterfaceVisitor<'_, 'tcx> { ReachEverythingInTheInterfaceVisitor { access_level: cmp::min(access_level, Some(AccessLevel::Reachable)), item_def_id: self.tcx.hir().local_def_id_from_hir_id(item_id), @@ -1647,8 +1662,11 @@ struct PrivateItemsInPublicInterfacesVisitor<'a, 'tcx: 'a> { } impl<'a, 'tcx> PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> { - fn check(&self, item_id: hir::HirId, required_visibility: ty::Visibility) - -> SearchInterfaceForPrivateItemsVisitor<'tcx> { + fn check( + &self, + item_id: hir::HirId, + required_visibility: ty::Visibility, + ) -> SearchInterfaceForPrivateItemsVisitor<'tcx> { let mut has_old_errors = false; // Slow path taken only if there any errors in the crate. @@ -1841,10 +1859,7 @@ fn check_mod_privacy<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, module_def_id: DefId) { intravisit::walk_mod(&mut visitor, module, hir_id); } -fn privacy_access_levels<'tcx>( - tcx: TyCtxt<'tcx, 'tcx>, - krate: CrateNum, -) -> &'tcx AccessLevels { +fn privacy_access_levels<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, krate: CrateNum) -> &'tcx AccessLevels { assert_eq!(krate, LOCAL_CRATE); // Build up a set of all exported items in the AST. This is a set of all diff --git a/src/librustc_traits/chalk_context/mod.rs b/src/librustc_traits/chalk_context/mod.rs index 77f59ae6c32ce..7a519ac2ebea8 100644 --- a/src/librustc_traits/chalk_context/mod.rs +++ b/src/librustc_traits/chalk_context/mod.rs @@ -527,7 +527,7 @@ impl ChalkContextLift<'tcx> for ChalkArenas<'a> { fn lift_ex_clause_to_tcx( ex_clause: &ChalkExClause<'a>, - tcx: TyCtxt<'gcx, 'tcx> + tcx: TyCtxt<'gcx, 'tcx>, ) -> Option { Some(ChalkExClause { subst: tcx.lift(&ex_clause.subst)?, @@ -539,7 +539,7 @@ impl ChalkContextLift<'tcx> for ChalkArenas<'a> { fn lift_delayed_literal_to_tcx( literal: &DelayedLiteral>, - tcx: TyCtxt<'gcx, 'tcx> + tcx: TyCtxt<'gcx, 'tcx>, ) -> Option { Some(match literal { DelayedLiteral::CannotProve(()) => DelayedLiteral::CannotProve(()), @@ -674,11 +674,8 @@ crate fn provide(p: &mut Providers<'_>) { crate fn evaluate_goal<'tcx>( tcx: TyCtxt<'tcx, 'tcx>, - goal: ChalkCanonicalGoal<'tcx> -) -> Result< - &'tcx Canonical<'tcx, QueryResponse<'tcx, ()>>, - traits::query::NoSolution -> { + goal: ChalkCanonicalGoal<'tcx>, +) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, ()>>, traits::query::NoSolution> { use crate::lowering::Lower; use rustc::traits::WellFormed; diff --git a/src/librustc_traits/chalk_context/program_clauses/builtin.rs b/src/librustc_traits/chalk_context/program_clauses/builtin.rs index 7dc8264832249..3c9b335e77769 100644 --- a/src/librustc_traits/chalk_context/program_clauses/builtin.rs +++ b/src/librustc_traits/chalk_context/program_clauses/builtin.rs @@ -18,7 +18,7 @@ fn builtin_impl_clause( tcx: TyCtxt<'_, 'tcx>, ty: Ty<'tcx>, nested: &[Kind<'tcx>], - trait_def_id: DefId + trait_def_id: DefId, ) -> ProgramClause<'tcx> { ProgramClause { goal: ty::TraitPredicate { @@ -47,7 +47,7 @@ crate fn assemble_builtin_unsize_impls<'tcx>( unsize_def_id: DefId, source: Ty<'tcx>, target: Ty<'tcx>, - clauses: &mut Vec> + clauses: &mut Vec>, ) { match (&source.sty, &target.sty) { (ty::Dynamic(data_a, ..), ty::Dynamic(data_b, ..)) => { @@ -122,7 +122,7 @@ crate fn assemble_builtin_sized_impls<'tcx>( tcx: TyCtxt<'_, 'tcx>, sized_def_id: DefId, ty: Ty<'tcx>, - clauses: &mut Vec> + clauses: &mut Vec>, ) { let mut push_builtin_impl = |ty: Ty<'tcx>, nested: &[Kind<'tcx>]| { let clause = builtin_impl_clause(tcx, ty, nested, sized_def_id); @@ -226,7 +226,7 @@ crate fn assemble_builtin_copy_clone_impls<'tcx>( tcx: TyCtxt<'_, 'tcx>, trait_def_id: DefId, ty: Ty<'tcx>, - clauses: &mut Vec> + clauses: &mut Vec>, ) { let mut push_builtin_impl = |ty: Ty<'tcx>, nested: &[Kind<'tcx>]| { let clause = builtin_impl_clause(tcx, ty, nested, trait_def_id); diff --git a/src/librustc_traits/chalk_context/program_clauses/mod.rs b/src/librustc_traits/chalk_context/program_clauses/mod.rs index 8702bc7dbc089..ae2283c3672e7 100644 --- a/src/librustc_traits/chalk_context/program_clauses/mod.rs +++ b/src/librustc_traits/chalk_context/program_clauses/mod.rs @@ -21,7 +21,7 @@ use self::builtin::*; fn assemble_clauses_from_impls<'tcx>( tcx: TyCtxt<'_, 'tcx>, trait_def_id: DefId, - clauses: &mut Vec> + clauses: &mut Vec>, ) { tcx.for_each_impl(trait_def_id, |impl_def_id| { clauses.extend( @@ -35,7 +35,7 @@ fn assemble_clauses_from_impls<'tcx>( fn assemble_clauses_from_assoc_ty_values<'tcx>( tcx: TyCtxt<'_, 'tcx>, trait_def_id: DefId, - clauses: &mut Vec> + clauses: &mut Vec>, ) { tcx.for_each_impl(trait_def_id, |impl_def_id| { for def_id in tcx.associated_item_def_ids(impl_def_id).iter() { diff --git a/src/librustc_traits/chalk_context/program_clauses/primitive.rs b/src/librustc_traits/chalk_context/program_clauses/primitive.rs index a1d9e7e0cde23..fd7b5ec55b08b 100644 --- a/src/librustc_traits/chalk_context/program_clauses/primitive.rs +++ b/src/librustc_traits/chalk_context/program_clauses/primitive.rs @@ -17,7 +17,7 @@ use std::iter; crate fn wf_clause_for_raw_ptr<'tcx>( tcx: TyCtxt<'_, 'tcx>, - mutbl: hir::Mutability + mutbl: hir::Mutability, ) -> Clauses<'tcx> { let ptr_ty = generic_types::raw_ptr(tcx, mutbl); @@ -37,7 +37,7 @@ crate fn wf_clause_for_fn_ptr<'tcx>( arity_and_output: usize, variadic: bool, unsafety: hir::Unsafety, - abi: abi::Abi + abi: abi::Abi, ) -> Clauses<'tcx> { let fn_ptr = generic_types::fn_ptr(tcx, arity_and_output, variadic, unsafety, abi); @@ -84,7 +84,7 @@ crate fn wf_clause_for_slice<'tcx>(tcx: TyCtxt<'_, 'tcx>) -> Clauses<'tcx> { crate fn wf_clause_for_array<'tcx>( tcx: TyCtxt<'_, 'tcx>, - length: &'tcx ty::Const<'tcx> + length: &'tcx ty::Const<'tcx>, ) -> Clauses<'tcx> { let ty = generic_types::bound(tcx, 0); let array_ty = tcx.mk_ty(ty::Array(ty, length)); @@ -114,10 +114,7 @@ crate fn wf_clause_for_array<'tcx>( tcx.mk_clauses(iter::once(wf_clause)) } -crate fn wf_clause_for_tuple<'tcx>( - tcx: TyCtxt<'_, 'tcx>, - arity: usize -) -> Clauses<'tcx> { +crate fn wf_clause_for_tuple<'tcx>(tcx: TyCtxt<'_, 'tcx>, arity: usize) -> Clauses<'tcx> { let type_list = generic_types::type_list(tcx, arity); let tuple_ty = tcx.mk_ty(ty::Tuple(type_list)); @@ -158,10 +155,7 @@ crate fn wf_clause_for_tuple<'tcx>( tcx.mk_clauses(iter::once(wf_clause)) } -crate fn wf_clause_for_ref<'tcx>( - tcx: TyCtxt<'_, 'tcx>, - mutbl: hir::Mutability -) -> Clauses<'tcx> { +crate fn wf_clause_for_ref<'tcx>(tcx: TyCtxt<'_, 'tcx>, mutbl: hir::Mutability) -> Clauses<'tcx> { let region = tcx.mk_region( ty::ReLateBound(ty::INNERMOST, ty::BoundRegion::BrAnon(0)) ); @@ -185,10 +179,7 @@ crate fn wf_clause_for_ref<'tcx>( tcx.mk_clauses(iter::once(wf_clause)) } -crate fn wf_clause_for_fn_def<'tcx>( - tcx: TyCtxt<'_, 'tcx>, - def_id: DefId -) -> Clauses<'tcx> { +crate fn wf_clause_for_fn_def<'tcx>(tcx: TyCtxt<'_, 'tcx>, def_id: DefId) -> Clauses<'tcx> { let fn_def = generic_types::fn_def(tcx, def_id); let wf_clause = ProgramClause { diff --git a/src/librustc_traits/generic_types.rs b/src/librustc_traits/generic_types.rs index 7eb1cd093a82f..dca7fb0dae3d4 100644 --- a/src/librustc_traits/generic_types.rs +++ b/src/librustc_traits/generic_types.rs @@ -26,7 +26,7 @@ crate fn fn_ptr( arity_and_output: usize, c_variadic: bool, unsafety: hir::Unsafety, - abi: abi::Abi + abi: abi::Abi, ) -> Ty<'tcx> { let inputs_and_output = tcx.mk_type_list( (0..arity_and_output).into_iter() diff --git a/src/librustc_traits/implied_outlives_bounds.rs b/src/librustc_traits/implied_outlives_bounds.rs index 88bc61886b7d4..1bb04eab4c4bb 100644 --- a/src/librustc_traits/implied_outlives_bounds.rs +++ b/src/librustc_traits/implied_outlives_bounds.rs @@ -26,8 +26,8 @@ fn implied_outlives_bounds<'tcx>( tcx: TyCtxt<'tcx, 'tcx>, goal: CanonicalTyGoal<'tcx>, ) -> Result< - &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Vec>>>, - NoSolution, + &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Vec>>>, + NoSolution, > { tcx.infer_ctxt() .enter_canonical_trait_query(&goal, |infcx, _fulfill_cx, key| { diff --git a/src/librustc_traits/lowering/environment.rs b/src/librustc_traits/lowering/environment.rs index 537b6d3e09012..bab74e80ea6e9 100644 --- a/src/librustc_traits/lowering/environment.rs +++ b/src/librustc_traits/lowering/environment.rs @@ -160,10 +160,7 @@ crate fn program_clauses_for_env<'tcx>( ); } -crate fn environment<'tcx>( - tcx: TyCtxt<'tcx, 'tcx>, - def_id: DefId -) -> Environment<'tcx> { +crate fn environment<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> Environment<'tcx> { use super::{Lower, IntoFromEnvGoal}; use rustc::hir::{Node, TraitItemKind, ImplItemKind, ItemKind, ForeignItemKind}; diff --git a/src/librustc_traits/lowering/mod.rs b/src/librustc_traits/lowering/mod.rs index c73f61f070e37..59cd58ea23d14 100644 --- a/src/librustc_traits/lowering/mod.rs +++ b/src/librustc_traits/lowering/mod.rs @@ -155,10 +155,7 @@ impl<'tcx> IntoWellFormedGoal for DomainGoal<'tcx> { } } -crate fn program_clauses_for<'tcx>( - tcx: TyCtxt<'tcx, 'tcx>, - def_id: DefId, -) -> Clauses<'tcx> { +crate fn program_clauses_for<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> Clauses<'tcx> { // FIXME(eddyb) this should only be using `def_kind`. match tcx.def_key(def_id).disambiguated_data.data { DefPathData::TypeNs(..) => match tcx.def_kind(def_id) { @@ -184,10 +181,7 @@ crate fn program_clauses_for<'tcx>( } } -fn program_clauses_for_trait<'tcx>( - tcx: TyCtxt<'tcx, 'tcx>, - def_id: DefId, -) -> Clauses<'tcx> { +fn program_clauses_for_trait<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> Clauses<'tcx> { // `trait Trait where WC { .. } // P0 == Self` // Rule Implemented-From-Env (see rustc guide) @@ -343,10 +337,7 @@ fn program_clauses_for_impl(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> Clauses<' tcx.mk_clauses(iter::once(Clause::ForAll(ty::Binder::bind(clause)))) } -pub fn program_clauses_for_type_def<'tcx>( - tcx: TyCtxt<'tcx, 'tcx>, - def_id: DefId, -) -> Clauses<'tcx> { +pub fn program_clauses_for_type_def<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> Clauses<'tcx> { // Rule WellFormed-Type // // `struct Ty where WC1, ..., WCm` diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 9730623b552ac..2c9309a1696cf 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -2420,9 +2420,11 @@ impl<'gcx, 'tcx> Bounds<'tcx> { /// where-clauses). Because some of our bounds listings (e.g., /// regions) don't include the self-type, you must supply the /// self-type here (the `param_ty` parameter). - pub fn predicates(&self, tcx: TyCtxt<'gcx, 'tcx>, param_ty: Ty<'tcx>) - -> Vec<(ty::Predicate<'tcx>, Span)> - { + pub fn predicates( + &self, + tcx: TyCtxt<'gcx, 'tcx>, + param_ty: Ty<'tcx>, + ) -> Vec<(ty::Predicate<'tcx>, Span)> { // If it could be sized, and is, add the `Sized` predicate. let sized_predicate = self.implicitly_sized.and_then(|span| { tcx.lang_items().sized_trait().map(|sized| { diff --git a/src/librustc_typeck/check/autoderef.rs b/src/librustc_typeck/check/autoderef.rs index 8cb4360e65d3d..ce92551c0133f 100644 --- a/src/librustc_typeck/check/autoderef.rs +++ b/src/librustc_typeck/check/autoderef.rs @@ -240,8 +240,10 @@ impl<'a, 'gcx, 'tcx> Autoderef<'a, 'gcx, 'tcx> { } pub fn report_autoderef_recursion_limit_error<'gcx, 'tcx>( - tcx: TyCtxt<'gcx, 'tcx>, span: Span, ty: Ty<'tcx>) -{ + tcx: TyCtxt<'gcx, 'tcx>, + span: Span, + ty: Ty<'tcx>, +) { // We've reached the recursion limit, error gracefully. let suggested_limit = *tcx.sess.recursion_limit.get() * 2; let msg = format!("reached the recursion limit while auto-dereferencing `{:?}`", diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index 7c24ea1641493..32ac7cd69e2e3 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -23,12 +23,14 @@ use super::{Inherited, FnCtxt, potentially_plural_count}; /// - `trait_m`: the method in the trait /// - `impl_trait_ref`: the TraitRef corresponding to the trait implementation -pub fn compare_impl_method<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - impl_m: &ty::AssocItem, - impl_m_span: Span, - trait_m: &ty::AssocItem, - impl_trait_ref: ty::TraitRef<'tcx>, - trait_item_span: Option) { +pub fn compare_impl_method<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + impl_m: &ty::AssocItem, + impl_m_span: Span, + trait_m: &ty::AssocItem, + impl_trait_ref: ty::TraitRef<'tcx>, + trait_item_span: Option, +) { debug!("compare_impl_method(impl_trait_ref={:?})", impl_trait_ref); @@ -73,12 +75,13 @@ pub fn compare_impl_method<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, } } -fn compare_predicate_entailment<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - impl_m: &ty::AssocItem, - impl_m_span: Span, - trait_m: &ty::AssocItem, - impl_trait_ref: ty::TraitRef<'tcx>) - -> Result<(), ErrorReported> { +fn compare_predicate_entailment<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + impl_m: &ty::AssocItem, + impl_m_span: Span, + trait_m: &ty::AssocItem, + impl_trait_ref: ty::TraitRef<'tcx>, +) -> Result<(), ErrorReported> { let trait_to_impl_substs = impl_trait_ref.substs; // This node-id should be used for the `body_id` field on each @@ -355,14 +358,15 @@ fn compare_predicate_entailment<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, }) } -fn check_region_bounds_on_impl_method<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - span: Span, - impl_m: &ty::AssocItem, - trait_m: &ty::AssocItem, - trait_generics: &ty::Generics, - impl_generics: &ty::Generics, - trait_to_skol_substs: SubstsRef<'tcx>) - -> Result<(), ErrorReported> { +fn check_region_bounds_on_impl_method<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + span: Span, + impl_m: &ty::AssocItem, + trait_m: &ty::AssocItem, + trait_generics: &ty::Generics, + impl_generics: &ty::Generics, + trait_to_skol_substs: SubstsRef<'tcx>, +) -> Result<(), ErrorReported> { let trait_params = trait_generics.own_counts().lifetimes; let impl_params = impl_generics.own_counts().lifetimes; @@ -495,13 +499,13 @@ fn extract_spans_for_error_reporting<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a } } -fn compare_self_type<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - impl_m: &ty::AssocItem, - impl_m_span: Span, - trait_m: &ty::AssocItem, - impl_trait_ref: ty::TraitRef<'tcx>) - -> Result<(), ErrorReported> -{ +fn compare_self_type<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + impl_m: &ty::AssocItem, + impl_m_span: Span, + trait_m: &ty::AssocItem, + impl_trait_ref: ty::TraitRef<'tcx>, +) -> Result<(), ErrorReported> { // Try to give more informative error messages about self typing // mismatches. Note that any mismatch will also be detected // below, where we construct a canonical function type that @@ -695,12 +699,13 @@ fn compare_number_of_generics<'tcx>( } } -fn compare_number_of_method_arguments<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - impl_m: &ty::AssocItem, - impl_m_span: Span, - trait_m: &ty::AssocItem, - trait_item_span: Option) - -> Result<(), ErrorReported> { +fn compare_number_of_method_arguments<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + impl_m: &ty::AssocItem, + impl_m_span: Span, + trait_m: &ty::AssocItem, + trait_item_span: Option, +) -> Result<(), ErrorReported> { let impl_m_fty = tcx.fn_sig(impl_m.def_id); let trait_m_fty = tcx.fn_sig(trait_m.def_id); let trait_number_args = trait_m_fty.inputs().skip_binder().len(); @@ -779,10 +784,11 @@ fn compare_number_of_method_arguments<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, Ok(()) } -fn compare_synthetic_generics<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - impl_m: &ty::AssocItem, - trait_m: &ty::AssocItem) - -> Result<(), ErrorReported> { +fn compare_synthetic_generics<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + impl_m: &ty::AssocItem, + trait_m: &ty::AssocItem, +) -> Result<(), ErrorReported> { // FIXME(chrisvittal) Clean up this function, list of FIXME items: // 1. Better messages for the span labels // 2. Explanation as to what is going on @@ -951,11 +957,13 @@ fn compare_synthetic_generics<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, } } -pub fn compare_const_impl<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - impl_c: &ty::AssocItem, - impl_c_span: Span, - trait_c: &ty::AssocItem, - impl_trait_ref: ty::TraitRef<'tcx>) { +pub fn compare_const_impl<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + impl_c: &ty::AssocItem, + impl_c_span: Span, + trait_c: &ty::AssocItem, + impl_trait_ref: ty::TraitRef<'tcx>, +) { debug!("compare_const_impl(impl_trait_ref={:?})", impl_trait_ref); tcx.infer_ctxt().enter(|infcx| { diff --git a/src/librustc_typeck/check/intrinsic.rs b/src/librustc_typeck/check/intrinsic.rs index 2a553db5e5dde..0b800fe8247c7 100644 --- a/src/librustc_typeck/check/intrinsic.rs +++ b/src/librustc_typeck/check/intrinsic.rs @@ -79,8 +79,7 @@ pub fn intrisic_operation_unsafety(intrinsic: &str) -> hir::Unsafety { /// Remember to add all intrinsics here, in librustc_codegen_llvm/intrinsic.rs, /// and in libcore/intrinsics.rs -pub fn check_intrinsic_type<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - it: &hir::ForeignItem) { +pub fn check_intrinsic_type<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, it: &hir::ForeignItem) { let param = |n| tcx.mk_ty_param(n, InternedString::intern(&format!("P{}", n))); let name = it.ident.as_str(); @@ -400,8 +399,7 @@ pub fn check_intrinsic_type<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, } /// Type-check `extern "platform-intrinsic" { ... }` functions. -pub fn check_platform_intrinsic_type<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - it: &hir::ForeignItem) { +pub fn check_platform_intrinsic_type<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, it: &hir::ForeignItem) { let param = |n| { let name = InternedString::intern(&format!("P{}", n)); tcx.mk_ty_param(n, name) diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index 8d55f3afdfd8a..5aab440dc16d0 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -395,10 +395,10 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) { providers.method_autoderef_steps = method_autoderef_steps; } -fn method_autoderef_steps<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'gcx>, - goal: CanonicalTyGoal<'tcx>) - -> MethodAutoderefStepsResult<'gcx> -{ +fn method_autoderef_steps<'gcx, 'tcx>( + tcx: TyCtxt<'gcx, 'gcx>, + goal: CanonicalTyGoal<'tcx>, +) -> MethodAutoderefStepsResult<'gcx> { debug!("method_autoderef_steps({:?})", goal); tcx.infer_ctxt().enter_with_canonical(DUMMY_SP, &goal, |ref infcx, goal, inference_vars| { diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 227b0c7035451..c4157bb60e9da 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -817,10 +817,12 @@ fn compute_all_traits<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'tcx>) -> Vec { // Cross-crate: let mut external_mods = FxHashSet::default(); - fn handle_external_res(tcx: TyCtxt<'_, '_>, - traits: &mut Vec, - external_mods: &mut FxHashSet, - res: Res) { + fn handle_external_res( + tcx: TyCtxt<'_, '_>, + traits: &mut Vec, + external_mods: &mut FxHashSet, + res: Res, + ) { match res { Res::Def(DefKind::Trait, def_id) | Res::Def(DefKind::TraitAlias, def_id) => { @@ -859,7 +861,7 @@ struct UsePlacementFinder<'tcx, 'gcx> { target_module: hir::HirId, span: Option, found_use: bool, - tcx: TyCtxt<'gcx, 'tcx> + tcx: TyCtxt<'gcx, 'tcx>, } impl UsePlacementFinder<'tcx, 'gcx> { diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index ba30f481596df..d62536ccb4669 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -594,8 +594,7 @@ pub struct InheritedBuilder<'gcx, 'tcx> { } impl Inherited<'_, 'gcx, 'tcx> { - pub fn build(tcx: TyCtxt<'gcx, 'gcx>, def_id: DefId) - -> InheritedBuilder<'gcx, 'tcx> { + pub fn build(tcx: TyCtxt<'gcx, 'gcx>, def_id: DefId) -> InheritedBuilder<'gcx, 'tcx> { let hir_id_root = if def_id.is_local() { let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); DefId::local(hir_id.owner) @@ -612,7 +611,8 @@ impl Inherited<'_, 'gcx, 'tcx> { impl<'gcx, 'tcx> InheritedBuilder<'gcx, 'tcx> { fn enter(&'tcx mut self, f: F) -> R - where F: for<'a> FnOnce(Inherited<'a, 'gcx, 'tcx>) -> R + where + F: for<'a> FnOnce(Inherited<'a, 'gcx, 'tcx>) -> R, { let def_id = self.def_id; self.infcx.enter(|infcx| f(Inherited::new(infcx, def_id))) @@ -685,7 +685,9 @@ impl Inherited<'a, 'gcx, 'tcx> { } } -struct CheckItemTypesVisitor<'tcx> { tcx: TyCtxt<'tcx, 'tcx> } +struct CheckItemTypesVisitor<'tcx> { + tcx: TyCtxt<'tcx, 'tcx>, +} impl ItemLikeVisitor<'tcx> for CheckItemTypesVisitor<'tcx> { fn visit_item(&mut self, i: &'tcx hir::Item) { @@ -741,9 +743,7 @@ pub fn provide(providers: &mut Providers<'_>) { }; } -fn adt_destructor<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - def_id: DefId) - -> Option { +fn adt_destructor<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> Option { tcx.calculate_dtor(def_id, &mut dropck::check_drop_impl) } @@ -756,10 +756,10 @@ fn adt_destructor<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, /// may not succeed. In some cases where this function returns `None` /// (notably closures), `typeck_tables(def_id)` would wind up /// redirecting to the owning function. -fn primary_body_of<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - id: hir::HirId) - -> Option<(hir::BodyId, Option<&'tcx hir::FnDecl>)> -{ +fn primary_body_of<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + id: hir::HirId, +) -> Option<(hir::BodyId, Option<&'tcx hir::FnDecl>)> { match tcx.hir().get_by_hir_id(id) { Node::Item(item) => { match item.node { @@ -797,9 +797,7 @@ fn primary_body_of<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, } } -fn has_typeck_tables<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - def_id: DefId) - -> bool { +fn has_typeck_tables<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> bool { // Closures' tables come from their outermost function, // as they are part of the same "inference environment". let outer_def_id = tcx.closure_base_def_id(def_id); @@ -811,15 +809,11 @@ fn has_typeck_tables<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, primary_body_of(tcx, id).is_some() } -fn used_trait_imports<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - def_id: DefId) - -> &'tcx DefIdSet { +fn used_trait_imports<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> &'tcx DefIdSet { &*tcx.typeck_tables_of(def_id).used_trait_imports } -fn typeck_tables_of<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - def_id: DefId) - -> &'tcx ty::TypeckTables<'tcx> { +fn typeck_tables_of<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> &'tcx ty::TypeckTables<'tcx> { // Closures' tables come from their outermost function, // as they are part of the same "inference environment". let outer_def_id = tcx.closure_base_def_id(def_id); @@ -1287,9 +1281,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>, (fcx, gen_ty) } -fn check_struct<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - id: hir::HirId, - span: Span) { +fn check_struct<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, id: hir::HirId, span: Span) { let def_id = tcx.hir().local_def_id_from_hir_id(id); let def = tcx.adt_def(def_id); def.destructor(tcx); // force the destructor to be evaluated @@ -1303,9 +1295,7 @@ fn check_struct<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, check_packed(tcx, span, def_id); } -fn check_union<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - id: hir::HirId, - span: Span) { +fn check_union<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, id: hir::HirId, span: Span) { let def_id = tcx.hir().local_def_id_from_hir_id(id); let def = tcx.adt_def(def_id); def.destructor(tcx); // force the destructor to be evaluated @@ -1314,12 +1304,7 @@ fn check_union<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, check_packed(tcx, span, def_id); } -fn check_opaque<'tcx>( - tcx: TyCtxt<'tcx, 'tcx>, - def_id: DefId, - substs: SubstsRef<'tcx>, - span: Span, -) { +fn check_opaque<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId, substs: SubstsRef<'tcx>, span: Span) { if let Err(partially_expanded_type) = tcx.try_expand_impl_trait_type(def_id, substs) { let mut err = struct_span_err!( tcx.sess, span, E0720, @@ -1472,18 +1457,17 @@ fn maybe_check_static_with_link_section(tcx: TyCtxt<'_, '_>, id: DefId, span: Sp } } -fn check_on_unimplemented<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - trait_def_id: DefId, - item: &hir::Item) { +fn check_on_unimplemented<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, trait_def_id: DefId, item: &hir::Item) { let item_def_id = tcx.hir().local_def_id_from_hir_id(item.hir_id); // an error would be reported if this fails. let _ = traits::OnUnimplementedDirective::of_item(tcx, trait_def_id, item_def_id); } -fn report_forbidden_specialization<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - impl_item: &hir::ImplItem, - parent_impl: DefId) -{ +fn report_forbidden_specialization<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + impl_item: &hir::ImplItem, + parent_impl: DefId, +) { let mut err = struct_span_err!( tcx.sess, impl_item.span, E0520, "`{}` specializes an item from a parent `impl`, but \ @@ -1506,12 +1490,13 @@ fn report_forbidden_specialization<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, err.emit(); } -fn check_specialization_validity<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - trait_def: &ty::TraitDef, - trait_item: &ty::AssocItem, - impl_id: DefId, - impl_item: &hir::ImplItem) -{ +fn check_specialization_validity<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + trait_def: &ty::TraitDef, + trait_item: &ty::AssocItem, + impl_id: DefId, + impl_item: &hir::ImplItem, +) { let ancestors = trait_def.ancestors(tcx, impl_id); let kind = match impl_item.node { @@ -1532,11 +1517,13 @@ fn check_specialization_validity<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, } -fn check_impl_items_against_trait<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - impl_span: Span, - impl_id: DefId, - impl_trait_ref: ty::TraitRef<'tcx>, - impl_item_refs: &[hir::ImplItemRef]) { +fn check_impl_items_against_trait<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + impl_span: Span, + impl_id: DefId, + impl_trait_ref: ty::TraitRef<'tcx>, + impl_item_refs: &[hir::ImplItemRef], +) { let impl_span = tcx.sess.source_map().def_span(impl_span); // If the trait reference itself is erroneous (so the compilation is going @@ -1693,10 +1680,7 @@ fn check_impl_items_against_trait<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, /// Checks whether a type can be represented in memory. In particular, it /// identifies types that contain themselves without indirection through a /// pointer, which would mean their size is unbounded. -fn check_representable<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - sp: Span, - item_def_id: DefId) - -> bool { +fn check_representable<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, sp: Span, item_def_id: DefId) -> bool { let rty = tcx.type_of(item_def_id); // Check that it is possible to represent this type. This call identifies @@ -1715,7 +1699,7 @@ fn check_representable<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, } Representability::Representable | Representability::ContainsRecursive => (), } - return true + return true; } pub fn check_simd<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, sp: Span, def_id: DefId) { @@ -1771,9 +1755,11 @@ fn check_packed<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, sp: Span, def_id: DefId) { } } -fn check_packed_inner<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - def_id: DefId, - stack: &mut Vec) -> bool { +fn check_packed_inner<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + def_id: DefId, + stack: &mut Vec, +) -> bool { let t = tcx.type_of(def_id); if stack.contains(&def_id) { debug!("check_packed_inner: {:?} is recursive", t); @@ -1881,10 +1867,12 @@ fn check_transparent<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, sp: Span, def_id: DefId) { } #[allow(trivial_numeric_casts)] -pub fn check_enum<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - sp: Span, - vs: &'tcx [hir::Variant], - id: hir::HirId) { +pub fn check_enum<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + sp: Span, + vs: &'tcx [hir::Variant], + id: hir::HirId, +) { let def_id = tcx.hir().local_def_id_from_hir_id(id); let def = tcx.adt_def(def_id); def.destructor(tcx); // force the destructor to be evaluated @@ -1945,10 +1933,12 @@ pub fn check_enum<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, check_transparent(tcx, sp, def_id); } -fn report_unexpected_variant_res<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'tcx>, - res: Res, - span: Span, - qpath: &QPath) { +fn report_unexpected_variant_res<'gcx, 'tcx>( + tcx: TyCtxt<'gcx, 'tcx>, + res: Res, + span: Span, + qpath: &QPath, +) { span_err!(tcx.sess, span, E0533, "expected unit struct/variant or constant, found {} `{}`", res.descr(), @@ -1956,7 +1946,9 @@ fn report_unexpected_variant_res<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'tcx>, } impl<'a, 'gcx, 'tcx> AstConv<'gcx, 'tcx> for FnCtxt<'a, 'gcx, 'tcx> { - fn tcx<'b>(&'b self) -> TyCtxt<'gcx, 'tcx> { self.tcx } + fn tcx<'b>(&'b self) -> TyCtxt<'gcx, 'tcx> { + self.tcx + } fn get_type_parameter_bounds(&self, _: Span, def_id: DefId) -> &'tcx ty::GenericPredicates<'tcx> @@ -5700,9 +5692,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } } -pub fn check_bounds_are_used<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - generics: &ty::Generics, - ty: Ty<'tcx>) { +pub fn check_bounds_are_used<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, generics: &ty::Generics, ty: Ty<'tcx>) { let own_counts = generics.own_counts(); debug!( "check_bounds_are_used(n_tys={}, n_cts={}, ty={:?})", diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index 31d85be17b4c0..83711a32e23a5 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -33,9 +33,9 @@ struct CheckWfFcxBuilder<'gcx, 'tcx> { } impl<'gcx, 'tcx> CheckWfFcxBuilder<'gcx, 'tcx> { - fn with_fcx(&'tcx mut self, f: F) where - F: for<'b> FnOnce(&FnCtxt<'b, 'gcx, 'tcx>, - TyCtxt<'gcx, 'gcx>) -> Vec> + fn with_fcx(&'tcx mut self, f: F) + where + F: for<'b> FnOnce(&FnCtxt<'b, 'gcx, 'tcx>, TyCtxt<'gcx, 'gcx>) -> Vec>, { let id = self.id; let span = self.span; @@ -178,10 +178,12 @@ pub fn check_impl_item<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) { check_associated_item(tcx, impl_item.hir_id, impl_item.span, method_sig); } -fn check_associated_item<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - item_id: hir::HirId, - span: Span, - sig_if_method: Option<&hir::MethodSig>) { +fn check_associated_item<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + item_id: hir::HirId, + span: Span, + sig_if_method: Option<&hir::MethodSig>, +) { debug!("check_associated_item: {:?}", item_id); let code = ObligationCauseCode::MiscObligation; @@ -225,13 +227,18 @@ fn check_associated_item<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, }) } -fn for_item<'gcx: 'tcx, 'tcx>(tcx: TyCtxt<'gcx, 'gcx>, item: &hir::Item) - -> CheckWfFcxBuilder<'gcx, 'tcx> { +fn for_item<'gcx: 'tcx, 'tcx>( + tcx: TyCtxt<'gcx, 'gcx>, + item: &hir::Item, +) -> CheckWfFcxBuilder<'gcx, 'tcx> { for_id(tcx, item.hir_id, item.span) } -fn for_id<'gcx: 'tcx, 'tcx>(tcx: TyCtxt<'gcx, 'gcx>, id: hir::HirId, span: Span) - -> CheckWfFcxBuilder<'gcx, 'tcx> { +fn for_id<'gcx: 'tcx, 'tcx>( + tcx: TyCtxt<'gcx, 'gcx>, + id: hir::HirId, + span: Span, +) -> CheckWfFcxBuilder<'gcx, 'tcx> { let def_id = tcx.hir().local_def_id_from_hir_id(id); CheckWfFcxBuilder { inherited: Inherited::build(tcx, def_id), @@ -242,9 +249,13 @@ fn for_id<'gcx: 'tcx, 'tcx>(tcx: TyCtxt<'gcx, 'gcx>, id: hir::HirId, span: Span) } /// In a type definition, we check that to ensure that the types of the fields are well-formed. -fn check_type_defn<'tcx, F>(tcx: TyCtxt<'tcx, 'tcx>, - item: &hir::Item, all_sized: bool, mut lookup_fields: F) - where F: for<'fcx, 'gcx, 'tcx2> FnMut(&FnCtxt<'fcx, 'gcx, 'tcx2>) -> Vec> +fn check_type_defn<'tcx, F>( + tcx: TyCtxt<'tcx, 'tcx>, + item: &hir::Item, + all_sized: bool, + mut lookup_fields: F, +) where + F: for<'fcx, 'gcx, 'tcx2> FnMut(&FnCtxt<'fcx, 'gcx, 'tcx2>) -> Vec>, { for_item(tcx, item).with_fcx(|fcx, fcx_tcx| { let variants = lookup_fields(fcx); @@ -380,11 +391,12 @@ fn check_item_type<'tcx>( }); } -fn check_impl<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - item: &hir::Item, - ast_self_ty: &hir::Ty, - ast_trait_ref: &Option) -{ +fn check_impl<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + item: &hir::Item, + ast_self_ty: &hir::Ty, + ast_trait_ref: &Option, +) { debug!("check_impl: {:?}", item); for_item(tcx, item).with_fcx(|fcx, tcx| { @@ -574,13 +586,14 @@ fn check_where_clauses<'gcx, 'fcx, 'tcx>( } } -fn check_fn_or_method<'fcx, 'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'gcx>, - fcx: &FnCtxt<'fcx, 'gcx, 'tcx>, - span: Span, - sig: ty::PolyFnSig<'tcx>, - def_id: DefId, - implied_bounds: &mut Vec>) -{ +fn check_fn_or_method<'fcx, 'gcx, 'tcx>( + tcx: TyCtxt<'gcx, 'gcx>, + fcx: &FnCtxt<'fcx, 'gcx, 'tcx>, + span: Span, + sig: ty::PolyFnSig<'tcx>, + def_id: DefId, + implied_bounds: &mut Vec>, +) { let sig = fcx.normalize_associated_types_in(span, &sig); let sig = fcx.tcx.liberate_late_bound_regions(def_id, &sig); @@ -930,10 +943,11 @@ fn receiver_is_valid<'fcx, 'tcx, 'gcx>( true } -fn check_variances_for_type_defn<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - item: &hir::Item, - hir_generics: &hir::Generics) -{ +fn check_variances_for_type_defn<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + item: &hir::Item, + hir_generics: &hir::Generics, +) { let item_def_id = tcx.hir().local_def_id_from_hir_id(item.hir_id); let ty = tcx.type_of(item_def_id); if tcx.has_error_field(ty) { @@ -971,10 +985,7 @@ fn check_variances_for_type_defn<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, } } -fn report_bivariance<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - span: Span, - param_name: ast::Name) -{ +fn report_bivariance<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, span: Span, param_name: ast::Name) { let mut err = error_392(tcx, span, param_name); let suggested_marker_id = tcx.lang_items().phantom_data(); @@ -1133,8 +1144,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } } -fn error_392<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, span: Span, param_name: ast::Name) - -> DiagnosticBuilder<'tcx> { +fn error_392<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + span: Span, + param_name: ast::Name, +) -> DiagnosticBuilder<'tcx> { let mut err = struct_span_err!(tcx.sess, span, E0392, "parameter `{}` is never used", param_name); err.span_label(span, "unused parameter"); diff --git a/src/librustc_typeck/coherence/builtin.rs b/src/librustc_typeck/coherence/builtin.rs index 653095e41f425..1eb3d108f786c 100644 --- a/src/librustc_typeck/coherence/builtin.rs +++ b/src/librustc_typeck/coherence/builtin.rs @@ -28,12 +28,13 @@ pub fn check_trait<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, trait_def_id: DefId) { struct Checker<'tcx> { tcx: TyCtxt<'tcx, 'tcx>, - trait_def_id: DefId + trait_def_id: DefId, } impl<'tcx> Checker<'tcx> { fn check(&self, trait_def_id: Option, mut f: F) -> &Self - where F: FnMut(TyCtxt<'tcx, 'tcx>, DefId) + where + F: FnMut(TyCtxt<'tcx, 'tcx>, DefId), { if Some(self.trait_def_id) == trait_def_id { for &impl_id in self.tcx.hir().trait_impls(self.trait_def_id) { @@ -153,10 +154,7 @@ fn visit_implementation_of_coerce_unsized(tcx: TyCtxt<'tcx, 'tcx>, impl_did: Def } } -fn visit_implementation_of_dispatch_from_dyn<'tcx>( - tcx: TyCtxt<'tcx, 'tcx>, - impl_did: DefId, -) { +fn visit_implementation_of_dispatch_from_dyn<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, impl_did: DefId) { debug!("visit_implementation_of_dispatch_from_dyn: impl_did={:?}", impl_did); if impl_did.is_local() { @@ -324,9 +322,7 @@ fn visit_implementation_of_dispatch_from_dyn<'tcx>( } } -pub fn coerce_unsized_info<'gcx>(gcx: TyCtxt<'gcx, 'gcx>, - impl_did: DefId) - -> CoerceUnsizedInfo { +pub fn coerce_unsized_info<'gcx>(gcx: TyCtxt<'gcx, 'gcx>, impl_did: DefId) -> CoerceUnsizedInfo { debug!("compute_coerce_unsized_info(impl_did={:?})", impl_did); let coerce_unsized_trait = gcx.lang_items().coerce_unsized_trait().unwrap(); diff --git a/src/librustc_typeck/coherence/inherent_impls.rs b/src/librustc_typeck/coherence/inherent_impls.rs index 8214fc50fed87..d6c2d56a9adf7 100644 --- a/src/librustc_typeck/coherence/inherent_impls.rs +++ b/src/librustc_typeck/coherence/inherent_impls.rs @@ -17,9 +17,10 @@ use syntax::ast; use syntax_pos::Span; /// On-demand query: yields a map containing all types mapped to their inherent impls. -pub fn crate_inherent_impls<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - crate_num: CrateNum) - -> &'tcx CrateInherentImpls { +pub fn crate_inherent_impls<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + crate_num: CrateNum, +) -> &'tcx CrateInherentImpls { assert_eq!(crate_num, LOCAL_CRATE); let krate = tcx.hir().krate(); @@ -32,9 +33,7 @@ pub fn crate_inherent_impls<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, } /// On-demand query: yields a vector of the inherent impls for a specific type. -pub fn inherent_impls<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - ty_def_id: DefId) - -> &'tcx [DefId] { +pub fn inherent_impls<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, ty_def_id: DefId) -> &'tcx [DefId] { assert!(ty_def_id.is_local()); // NB. Until we adopt the red-green dep-tracking algorithm (see diff --git a/src/librustc_typeck/coherence/inherent_impls_overlap.rs b/src/librustc_typeck/coherence/inherent_impls_overlap.rs index feddd9f0b3cb0..d557a9c871b12 100644 --- a/src/librustc_typeck/coherence/inherent_impls_overlap.rs +++ b/src/librustc_typeck/coherence/inherent_impls_overlap.rs @@ -5,15 +5,14 @@ use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::traits::{self, IntercrateMode}; use rustc::ty::TyCtxt; -pub fn crate_inherent_impls_overlap_check<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - crate_num: CrateNum) { +pub fn crate_inherent_impls_overlap_check<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, crate_num: CrateNum) { assert_eq!(crate_num, LOCAL_CRATE); let krate = tcx.hir().krate(); krate.visit_all_item_likes(&mut InherentOverlapChecker { tcx }); } struct InherentOverlapChecker<'tcx> { - tcx: TyCtxt<'tcx, 'tcx> + tcx: TyCtxt<'tcx, 'tcx>, } impl InherentOverlapChecker<'tcx> { diff --git a/src/librustc_typeck/coherence/mod.rs b/src/librustc_typeck/coherence/mod.rs index 421fdccc1fa25..3be46722ecccd 100644 --- a/src/librustc_typeck/coherence/mod.rs +++ b/src/librustc_typeck/coherence/mod.rs @@ -43,7 +43,7 @@ fn check_impl<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, hir_id: HirId) { fn enforce_trait_manually_implementable( tcx: TyCtxt<'_, '_>, impl_def_id: DefId, - trait_def_id: DefId + trait_def_id: DefId, ) { let did = Some(trait_def_id); let li = tcx.lang_items(); @@ -99,7 +99,7 @@ fn enforce_trait_manually_implementable( fn enforce_empty_impls_for_marker_traits( tcx: TyCtxt<'_, '_>, impl_def_id: DefId, - trait_def_id: DefId + trait_def_id: DefId, ) { if !tcx.trait_def(trait_def_id).is_marker { return; diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index a78af7875b9c4..e1af8d8f46f70 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -381,11 +381,7 @@ impl ItemCtxt<'tcx> { /// parameter with ID `param_id`. We use this so as to avoid running /// `ast_ty_to_ty`, because we want to avoid triggering an all-out /// conversion of the type to avoid inducing unnecessary cycles. -fn is_param<'tcx>( - tcx: TyCtxt<'tcx, 'tcx>, - ast_ty: &hir::Ty, - param_id: hir::HirId, -) -> bool { +fn is_param<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, ast_ty: &hir::Ty, param_id: hir::HirId) -> bool { if let hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) = ast_ty.node { match path.res { Res::SelfTy(Some(def_id), None) | Res::Def(DefKind::TyParam, def_id) => { @@ -578,7 +574,7 @@ fn convert_variant<'tcx>( discr: ty::VariantDiscr, def: &hir::VariantData, adt_kind: ty::AdtKind, - parent_did: DefId + parent_did: DefId, ) -> ty::VariantDef { let mut seen_fields: FxHashMap = Default::default(); let hir_id = tcx.hir().as_local_hir_id(variant_did.unwrap_or(parent_did)).unwrap(); @@ -779,10 +775,7 @@ fn trait_def<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> &'tcx ty::TraitDef tcx.arena.alloc(def) } -fn has_late_bound_regions<'tcx>( - tcx: TyCtxt<'tcx, 'tcx>, - node: Node<'tcx>, -) -> Option { +fn has_late_bound_regions<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, node: Node<'tcx>) -> Option { struct LateBoundRegionsDetector<'tcx> { tcx: TyCtxt<'tcx, 'tcx>, outer_index: ty::DebruijnIndex, @@ -1479,10 +1472,7 @@ pub fn checked_type_of<'tcx>( }) } -fn find_existential_constraints<'tcx>( - tcx: TyCtxt<'tcx, 'tcx>, - def_id: DefId, -) -> Ty<'tcx> { +fn find_existential_constraints<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> { use rustc::hir::{ImplItem, Item, TraitItem}; debug!("find_existential_constraints({:?})", def_id); @@ -1776,10 +1766,7 @@ fn fn_sig<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> ty::PolyFnSig<'tcx> { } } -fn impl_trait_ref<'tcx>( - tcx: TyCtxt<'tcx, 'tcx>, - def_id: DefId, -) -> Option> { +fn impl_trait_ref<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> Option> { let icx = ItemCtxt::new(tcx, def_id); let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); @@ -2301,10 +2288,7 @@ fn is_foreign_item<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> bool { } } -fn static_mutability<'tcx>( - tcx: TyCtxt<'tcx, 'tcx>, - def_id: DefId, -) -> Option { +fn static_mutability<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> Option { match tcx.hir().get_if_local(def_id) { Some(Node::Item(&hir::Item { node: hir::ItemKind::Static(_, mutbl, _), .. diff --git a/src/librustc_typeck/constrained_generic_params.rs b/src/librustc_typeck/constrained_generic_params.rs index c26de71a20ba3..3d424ce89dbc5 100644 --- a/src/librustc_typeck/constrained_generic_params.rs +++ b/src/librustc_typeck/constrained_generic_params.rs @@ -86,11 +86,12 @@ impl<'tcx> TypeVisitor<'tcx> for ParameterCollector { } } -pub fn identify_constrained_generic_params<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - predicates: &ty::GenericPredicates<'tcx>, - impl_trait_ref: Option>, - input_parameters: &mut FxHashSet) -{ +pub fn identify_constrained_generic_params<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + predicates: &ty::GenericPredicates<'tcx>, + impl_trait_ref: Option>, + input_parameters: &mut FxHashSet, +) { let mut predicates = predicates.predicates.clone(); setup_constraining_predicates(tcx, &mut predicates, impl_trait_ref, input_parameters); } @@ -136,11 +137,12 @@ pub fn identify_constrained_generic_params<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, /// which is determined by 1, which requires `U`, that is determined /// by 0. I should probably pick a less tangled example, but I can't /// think of any. -pub fn setup_constraining_predicates<'tcx>(tcx: TyCtxt<'_, '_>, - predicates: &mut [(ty::Predicate<'tcx>, Span)], - impl_trait_ref: Option>, - input_parameters: &mut FxHashSet) -{ +pub fn setup_constraining_predicates<'tcx>( + tcx: TyCtxt<'_, '_>, + predicates: &mut [(ty::Predicate<'tcx>, Span)], + impl_trait_ref: Option>, + input_parameters: &mut FxHashSet, +) { // The canonical way of doing the needed topological sort // would be a DFS, but getting the graph and its ownership // right is annoying, so I am using an in-place fixed-point iteration, diff --git a/src/librustc_typeck/impl_wf_check.rs b/src/librustc_typeck/impl_wf_check.rs index 6a7bdf48ae9d4..e13a664be0564 100644 --- a/src/librustc_typeck/impl_wf_check.rs +++ b/src/librustc_typeck/impl_wf_check.rs @@ -92,10 +92,11 @@ impl ItemLikeVisitor<'tcx> for ImplWfCheck<'tcx> { fn visit_impl_item(&mut self, _impl_item: &'tcx hir::ImplItem) { } } -fn enforce_impl_params_are_constrained<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - impl_def_id: DefId, - impl_item_refs: &[hir::ImplItemRef]) -{ +fn enforce_impl_params_are_constrained<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + impl_def_id: DefId, + impl_item_refs: &[hir::ImplItemRef], +) { // Every lifetime used in an associated type must be constrained. let impl_self_ty = tcx.type_of(impl_def_id); let impl_generics = tcx.generics_of(impl_def_id); @@ -171,11 +172,7 @@ fn enforce_impl_params_are_constrained<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, // used elsewhere are not projected back out. } -fn report_unused_parameter(tcx: TyCtxt<'_, '_>, - span: Span, - kind: &str, - name: &str) -{ +fn report_unused_parameter(tcx: TyCtxt<'_, '_>, span: Span, kind: &str, name: &str) { struct_span_err!( tcx.sess, span, E0207, "the {} parameter `{}` is not constrained by the \ @@ -186,9 +183,10 @@ fn report_unused_parameter(tcx: TyCtxt<'_, '_>, } /// Enforce that we do not have two items in an impl with the same name. -fn enforce_impl_items_are_distinct<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - impl_item_refs: &[hir::ImplItemRef]) -{ +fn enforce_impl_items_are_distinct<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + impl_item_refs: &[hir::ImplItemRef], +) { let mut seen_type_items = FxHashMap::default(); let mut seen_value_items = FxHashMap::default(); for impl_item_ref in impl_item_refs { diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index cb8e699351aa6..ce8bb975f9866 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -124,8 +124,7 @@ pub struct TypeAndSubsts<'tcx> { ty: Ty<'tcx>, } -fn check_type_alias_enum_variants_enabled<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'tcx>, - span: Span) { +fn check_type_alias_enum_variants_enabled<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'tcx>, span: Span) { if !tcx.features().type_alias_enum_variants { let mut err = tcx.sess.struct_span_err( span, @@ -140,10 +139,7 @@ fn check_type_alias_enum_variants_enabled<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'tcx>, } } -fn require_c_abi_if_c_variadic(tcx: TyCtxt<'_, '_>, - decl: &hir::FnDecl, - abi: Abi, - span: Span) { +fn require_c_abi_if_c_variadic(tcx: TyCtxt<'_, '_>, decl: &hir::FnDecl, abi: Abi, span: Span) { if decl.c_variadic && !(abi == Abi::C || abi == Abi::Cdecl) { let mut err = struct_span_err!(tcx.sess, span, E0045, "C-variadic function must have C or cdecl calling convention"); @@ -151,11 +147,12 @@ fn require_c_abi_if_c_variadic(tcx: TyCtxt<'_, '_>, } } -fn require_same_types<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - cause: &ObligationCause<'tcx>, - expected: Ty<'tcx>, - actual: Ty<'tcx>) - -> bool { +fn require_same_types<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + cause: &ObligationCause<'tcx>, + expected: Ty<'tcx>, + actual: Ty<'tcx>, +) -> bool { tcx.infer_ctxt().enter(|ref infcx| { let param_env = ty::ParamEnv::empty(); let mut fulfill_cx = TraitEngine::new(infcx.tcx); @@ -318,9 +315,7 @@ pub fn provide(providers: &mut Providers<'_>) { impl_wf_check::provide(providers); } -pub fn check_crate<'tcx>(tcx: TyCtxt<'tcx, 'tcx>) - -> Result<(), ErrorReported> -{ +pub fn check_crate<'tcx>(tcx: TyCtxt<'tcx, 'tcx>) -> Result<(), ErrorReported> { tcx.sess.profiler(|p| p.start_activity("type-check crate")); // this ensures that later parts of type checking can assume that items @@ -392,8 +387,10 @@ pub fn hir_ty_to_ty<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, hir_ty: &hir::Ty) -> Ty<'tcx> astconv::AstConv::ast_ty_to_ty(&item_cx, hir_ty) } -pub fn hir_trait_to_predicates<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, hir_trait: &hir::TraitRef) - -> (ty::PolyTraitRef<'tcx>, Bounds<'tcx>) { +pub fn hir_trait_to_predicates<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + hir_trait: &hir::TraitRef, +) -> (ty::PolyTraitRef<'tcx>, Bounds<'tcx>) { // In case there are any projections, etc., find the "environment" // def-ID that will be used to determine the traits/predicates in // scope. This is derived from the enclosing item-like thing. diff --git a/src/librustc_typeck/variance/mod.rs b/src/librustc_typeck/variance/mod.rs index c8079210022f6..22422081bc44e 100644 --- a/src/librustc_typeck/variance/mod.rs +++ b/src/librustc_typeck/variance/mod.rs @@ -34,8 +34,10 @@ pub fn provide(providers: &mut Providers<'_>) { }; } -fn crate_variances<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, crate_num: CrateNum) - -> &'tcx CrateVariancesMap<'tcx> { +fn crate_variances<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + crate_num: CrateNum, +) -> &'tcx CrateVariancesMap<'tcx> { assert_eq!(crate_num, LOCAL_CRATE); let mut arena = arena::TypedArena::default(); let terms_cx = terms::determine_parameters_to_be_inferred(tcx, &mut arena); @@ -43,8 +45,7 @@ fn crate_variances<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, crate_num: CrateNum) tcx.arena.alloc(solve::solve_constraints(constraints_cx)) } -fn variances_of<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, item_def_id: DefId) - -> &'tcx [ty::Variance] { +fn variances_of<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, item_def_id: DefId) -> &'tcx [ty::Variance] { let id = tcx.hir().as_local_hir_id(item_def_id).expect("expected local def-id"); let unsupported = || { // Variance not relevant. diff --git a/src/librustc_typeck/variance/terms.rs b/src/librustc_typeck/variance/terms.rs index e566500571335..4f8bb0c4e462d 100644 --- a/src/librustc_typeck/variance/terms.rs +++ b/src/librustc_typeck/variance/terms.rs @@ -64,9 +64,10 @@ pub struct TermsContext<'a, 'tcx: 'a> { pub inferred_terms: Vec>, } -pub fn determine_parameters_to_be_inferred<'a, 'tcx>(tcx: TyCtxt<'tcx, 'tcx>, - arena: &'a mut TypedArena>) - -> TermsContext<'a, 'tcx> { +pub fn determine_parameters_to_be_inferred<'a, 'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + arena: &'a mut TypedArena>, +) -> TermsContext<'a, 'tcx> { let mut terms_cx = TermsContext { tcx, arena, diff --git a/src/librustc_typeck/variance/test.rs b/src/librustc_typeck/variance/test.rs index 3f55b3360154c..f43c200425505 100644 --- a/src/librustc_typeck/variance/test.rs +++ b/src/librustc_typeck/variance/test.rs @@ -8,7 +8,7 @@ pub fn test_variance<'tcx>(tcx: TyCtxt<'tcx, 'tcx>) { } struct VarianceTest<'tcx> { - tcx: TyCtxt<'tcx, 'tcx> + tcx: TyCtxt<'tcx, 'tcx>, } impl ItemLikeVisitor<'tcx> for VarianceTest<'tcx> { diff --git a/src/test/ui/pattern/const-pat-ice.stderr b/src/test/ui/pattern/const-pat-ice.stderr index c4f6e0212621f..7ddeac4abca13 100644 --- a/src/test/ui/pattern/const-pat-ice.stderr +++ b/src/test/ui/pattern/const-pat-ice.stderr @@ -1,4 +1,4 @@ -thread 'rustc' panicked at 'assertion failed: rows.iter().all(|r| r.len() == v.len())', src/librustc_mir/hair/pattern/_match.rs:1085:5 +thread 'rustc' panicked at 'assertion failed: rows.iter().all(|r| r.len() == v.len())', src/librustc_mir/hair/pattern/_match.rs:1084:5 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace. error: internal compiler error: unexpected panic