diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index 972278bdf865f..9f51eb8c35a82 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -420,7 +420,10 @@ pub fn walk_lifetime<'v, V: Visitor<'v>>(visitor: &mut V, lifetime: &'v Lifetime LifetimeName::Name(name) => { visitor.visit_name(lifetime.span, name); } - LifetimeName::Static | LifetimeName::Implicit | LifetimeName::Underscore => {} + LifetimeName::Fresh(_) | + LifetimeName::Static | + LifetimeName::Implicit | + LifetimeName::Underscore => {} } } diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index f6bdfde15fc5f..ad848949f624d 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -43,8 +43,8 @@ use dep_graph::DepGraph; use hir; use hir::HirVec; -use hir::map::{Definitions, DefKey, DefPathData}; -use hir::def_id::{DefIndex, DefId, CRATE_DEF_INDEX, DefIndexAddressSpace}; +use hir::map::{DefKey, DefPathData, Definitions}; +use hir::def_id::{DefId, DefIndex, DefIndexAddressSpace, CRATE_DEF_INDEX}; use hir::def::{Def, PathResolution}; use lint::builtin::{self, PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES}; use middle::cstore::CrateStore; @@ -63,10 +63,10 @@ use syntax::errors; use syntax::ext::hygiene::{Mark, SyntaxContext}; use syntax::print::pprust; use syntax::ptr::P; -use syntax::codemap::{self, respan, Spanned, CompilerDesugaringKind}; +use syntax::codemap::{self, respan, CompilerDesugaringKind, Spanned}; use syntax::std_inject; -use syntax::symbol::{Symbol, keywords}; -use syntax::tokenstream::{TokenStream, TokenTree, Delimited}; +use syntax::symbol::{keywords, Symbol}; +use syntax::tokenstream::{Delimited, TokenStream, TokenTree}; use syntax::parse::token::Token; use syntax::util::small_vector::SmallVector; use syntax::visit::{self, Visitor}; @@ -80,13 +80,13 @@ pub struct LoweringContext<'a> { // Use to assign ids to hir nodes that do not directly correspond to an ast node sess: &'a Session, - cstore: &'a dyn CrateStore, + cstore: &'a CrateStore, // As we walk the AST we must keep track of the current 'parent' def id (in // the form of a DefIndex) so that if we create a new node which introduces // a definition, then we can properly create the def id. parent_def: Option, - resolver: &'a mut dyn Resolver, + resolver: &'a mut Resolver, name_map: FxHashMap, /// The items being lowered are collected here. @@ -107,6 +107,12 @@ pub struct LoweringContext<'a> { is_in_loop_condition: bool, is_in_trait_impl: bool, + /// What to do when we encounter either an "anonymous lifetime + /// reference". The term "anonymous" is meant to encompass both + /// `'_` lifetimes as well as fully elided cases where nothing is + /// written at all (e.g., `&T` or `std::cell::Ref`). + anonymous_lifetime_mode: AnonymousLifetimeMode, + // This is a list of in-band type definitions being generated by // Argument-position `impl Trait`. // When traversing a signature such as `fn foo(x: impl Trait)`, @@ -121,13 +127,15 @@ pub struct LoweringContext<'a> { // (i.e. it doesn't appear in the in_scope_lifetimes list), it is added // to this list. The results of this list are then added to the list of // lifetime definitions in the corresponding impl or function generics. - lifetimes_to_define: Vec<(Span, Name)>, + lifetimes_to_define: Vec<(Span, hir::LifetimeName)>, + // Whether or not in-band lifetimes are being collected. This is used to // indicate whether or not we're in a place where new lifetimes will result // in in-band lifetime definitions, such a function or an impl header. // This will always be false unless the `in_band_lifetimes` feature is // enabled. is_collecting_in_band_lifetimes: bool, + // Currently in-scope lifetimes defined in impl headers, fn headers, or HRTB. // When `is_collectin_in_band_lifetimes` is true, each lifetime is checked // against this list to see if it is already in-scope, or if a definition @@ -154,8 +162,13 @@ pub trait Resolver { /// Given suffix ["b","c","d"], creates a HIR path for `[::crate_root]::b::c::d` and resolves /// it based on `is_value`. - fn resolve_str_path(&mut self, span: Span, crate_root: Option<&str>, - components: &[&str], is_value: bool) -> hir::Path; + fn resolve_str_path( + &mut self, + span: Span, + crate_root: Option<&str>, + components: &[&str], + is_value: bool, + ) -> hir::Path; } #[derive(Clone, Copy, Debug)] @@ -176,12 +189,13 @@ enum ImplTraitContext { Disallowed, } -pub fn lower_crate(sess: &Session, - cstore: &dyn CrateStore, - dep_graph: &DepGraph, - krate: &Crate, - resolver: &mut dyn Resolver) - -> hir::Crate { +pub fn lower_crate( + sess: &Session, + cstore: &CrateStore, + dep_graph: &DepGraph, + krate: &Crate, + resolver: &mut Resolver, +) -> hir::Crate { // We're constructing the HIR here; we don't care what we will // read, since we haven't even constructed the *input* to // incr. comp. yet. @@ -204,6 +218,7 @@ pub fn lower_crate(sess: &Session, catch_scopes: Vec::new(), loop_scopes: Vec::new(), is_in_loop_condition: false, + anonymous_lifetime_mode: AnonymousLifetimeMode::PassThrough, type_def_lifetime_params: DefIdMap(), current_hir_id_owner: vec![(CRATE_DEF_INDEX, 0)], item_local_id_counters: NodeMap(), @@ -222,7 +237,7 @@ enum ParamMode { /// Any path in a type context. Explicit, /// The `module::Type` in `module::Type::method` in an expression. - Optional + Optional, } struct LoweredNodeId { @@ -236,6 +251,51 @@ enum ParenthesizedGenericArgs { Err, } +/// What to do when we encounter an **anonymous** lifetime +/// reference. Anonymous lifetime references come in two flavors. You +/// have implicit, or fully elided, references to lifetimes, like the +/// one in `&T` or `Ref`, and you have `'_` lifetimes, like `&'_ T` +/// or `Ref<'_, T>`. These often behave the same, but not always: +/// +/// - certain usages of implicit references are deprecated, like +/// `Ref`, and we sometimes just give hard errors in those cases +/// as well. +/// - for object bounds there is a difference: `Box` is not +/// the same as `Box`. +/// +/// We describe the effects of the various modes in terms of three cases: +/// +/// - **Modern** -- includes all uses of `'_`, but also the lifetime arg +/// of a `&` (e.g., the missing lifetime in something like `&T`) +/// - **Dyn Bound** -- if you have something like `Box`, +/// there is an elided lifetime bound (`Box`). These +/// elided bounds follow special rules. Note that this only covers +/// cases where *nothing* is written; the `'_` in `Box` is a case of "modern" elision. +/// - **Deprecated** -- this coverse cases like `Ref`, where the lifetime +/// parameter to ref is completely elided. `Ref<'_, T>` would be the modern, +/// non-deprecated equivalent. +/// +/// Currently, the handling of lifetime elision is somewhat spread out +/// between HIR lowering and -- as described below -- the +/// `resolve_lifetime` module. Often we "fallthrough" to that code by generating +/// an "elided" or "underscore" lifetime name. In the future, we probably want to move +/// everything into HIR lowering. +#[derive(Copy, Clone)] +enum AnonymousLifetimeMode { + /// For **Modern** cases, create a new anonymous region parameter + /// and reference that. + /// + /// For **Dyn Bound** cases, pass responsibility to + /// `resolve_lifetime` code. + /// + /// For **Deprecated** cases, report an error. + CreateParameter, + + /// Pass responsibility to `resolve_lifetime` code for all cases. + PassThrough, +} + impl<'a> LoweringContext<'a> { fn lower_crate(mut self, c: &Crate) -> hir::Crate { /// Full-crate AST visitor that inserts into a fresh @@ -252,13 +312,15 @@ impl<'a> LoweringContext<'a> { self.lctx.allocate_hir_id_counter(item.id, item); match item.node { - ItemKind::Struct(_, ref generics) | - ItemKind::Union(_, ref generics) | - ItemKind::Enum(_, ref generics) | - ItemKind::Ty(_, ref generics) | - ItemKind::Trait(_, _, ref generics, ..) => { + ItemKind::Struct(_, ref generics) + | ItemKind::Union(_, ref generics) + | ItemKind::Enum(_, ref generics) + | ItemKind::Ty(_, ref generics) + | ItemKind::Trait(_, _, ref generics, ..) => { let def_id = self.lctx.resolver.definitions().local_def_id(item.id); - let count = generics.params.iter() + let count = generics + .params + .iter() .filter(|param| param.is_lifetime_param()) .count(); self.lctx.type_def_lifetime_params.insert(def_id, count); @@ -285,7 +347,8 @@ impl<'a> LoweringContext<'a> { impl<'lcx, 'interner> ItemLowerer<'lcx, 'interner> { fn with_trait_impl_ref(&mut self, trait_impl_ref: &Option, f: F) - where F: FnOnce(&mut Self) + where + F: FnOnce(&mut Self), { let old = self.lctx.is_in_trait_impl; self.lctx.is_in_trait_impl = if let &None = trait_impl_ref { @@ -311,22 +374,24 @@ impl<'a> LoweringContext<'a> { if item_lowered { let item_lifetimes = match self.lctx.items.get(&item.id).unwrap().node { - hir::Item_::ItemImpl(_,_,_,ref generics,..) | - hir::Item_::ItemTrait(_,_,ref generics,..) => - generics.lifetimes().cloned().collect::>(), + hir::Item_::ItemImpl(_, _, _, ref generics, ..) + | hir::Item_::ItemTrait(_, _, ref generics, ..) => { + generics.lifetimes().cloned().collect::>() + } _ => Vec::new(), }; - self.lctx.with_parent_impl_lifetime_defs(&item_lifetimes, |this| { - let this = &mut ItemLowerer { lctx: this }; - if let ItemKind::Impl(_,_,_,_,ref opt_trait_ref,_,_) = item.node { - this.with_trait_impl_ref(opt_trait_ref, |this| { - visit::walk_item(this, item) - }); - } else { - visit::walk_item(this, item); - } - }); + self.lctx + .with_parent_impl_lifetime_defs(&item_lifetimes, |this| { + let this = &mut ItemLowerer { lctx: this }; + if let ItemKind::Impl(_, _, _, _, ref opt_trait_ref, _, _) = item.node { + this.with_trait_impl_ref(opt_trait_ref, |this| { + visit::walk_item(this, item) + }); + } else { + visit::walk_item(this, item); + } + }); } } @@ -379,27 +444,26 @@ impl<'a> LoweringContext<'a> { } } - fn allocate_hir_id_counter(&mut self, - owner: NodeId, - debug: &T) { + fn allocate_hir_id_counter(&mut self, owner: NodeId, debug: &T) { if self.item_local_id_counters.insert(owner, 0).is_some() { - bug!("Tried to allocate item_local_id_counter for {:?} twice", debug); + bug!( + "Tried to allocate item_local_id_counter for {:?} twice", + debug + ); } // Always allocate the first HirId for the owner itself self.lower_node_id_with_owner(owner, owner); } - fn lower_node_id_generic(&mut self, - ast_node_id: NodeId, - alloc_hir_id: F) - -> LoweredNodeId - where F: FnOnce(&mut Self) -> hir::HirId + fn lower_node_id_generic(&mut self, ast_node_id: NodeId, alloc_hir_id: F) -> LoweredNodeId + where + F: FnOnce(&mut Self) -> hir::HirId, { if ast_node_id == DUMMY_NODE_ID { return LoweredNodeId { node_id: DUMMY_NODE_ID, hir_id: hir::DUMMY_HIR_ID, - } + }; } let min_size = ast_node_id.as_usize() + 1; @@ -427,11 +491,12 @@ impl<'a> LoweringContext<'a> { } fn with_hir_id_owner(&mut self, owner: NodeId, f: F) - where F: FnOnce(&mut Self) + where + F: FnOnce(&mut Self), { let counter = self.item_local_id_counters - .insert(owner, HIR_ID_COUNTER_LOCKED) - .unwrap(); + .insert(owner, HIR_ID_COUNTER_LOCKED) + .unwrap(); let def_index = self.resolver.definitions().opt_def_index(owner).unwrap(); self.current_hir_id_owner.push((def_index, counter)); f(self); @@ -440,7 +505,9 @@ impl<'a> LoweringContext<'a> { debug_assert!(def_index == new_def_index); debug_assert!(new_counter >= counter); - let prev = self.item_local_id_counters.insert(owner, new_counter).unwrap(); + let prev = self.item_local_id_counters + .insert(owner, new_counter) + .unwrap(); debug_assert!(prev == HIR_ID_COUNTER_LOCKED); } @@ -452,9 +519,8 @@ impl<'a> LoweringContext<'a> { /// properly. Calling the method twice with the same NodeId is fine though. fn lower_node_id(&mut self, ast_node_id: NodeId) -> LoweredNodeId { self.lower_node_id_generic(ast_node_id, |this| { - let &mut (def_index, ref mut local_id_counter) = this.current_hir_id_owner - .last_mut() - .unwrap(); + let &mut (def_index, ref mut local_id_counter) = + this.current_hir_id_owner.last_mut().unwrap(); let local_id = *local_id_counter; *local_id_counter += 1; hir::HirId { @@ -464,14 +530,9 @@ impl<'a> LoweringContext<'a> { }) } - fn lower_node_id_with_owner(&mut self, - ast_node_id: NodeId, - owner: NodeId) - -> LoweredNodeId { + fn lower_node_id_with_owner(&mut self, ast_node_id: NodeId, owner: NodeId) -> LoweredNodeId { self.lower_node_id_generic(ast_node_id, |this| { - let local_id_counter = this.item_local_id_counters - .get_mut(&owner) - .unwrap(); + let local_id_counter = this.item_local_id_counters.get_mut(&owner).unwrap(); let local_id = *local_id_counter; // We want to be sure not to modify the counter in the map while it @@ -489,8 +550,7 @@ impl<'a> LoweringContext<'a> { }) } - fn record_body(&mut self, value: hir::Expr, decl: Option<&FnDecl>) - -> hir::BodyId { + fn record_body(&mut self, value: hir::Expr, decl: Option<&FnDecl>) -> hir::BodyId { let body = hir::Body { arguments: decl.map_or(hir_vec![], |decl| { decl.inputs.iter().map(|x| self.lower_arg(x)).collect() @@ -524,8 +584,7 @@ impl<'a> LoweringContext<'a> { Symbol::gensym(s) } - fn allow_internal_unstable(&self, reason: CompilerDesugaringKind, span: Span) -> Span - { + fn allow_internal_unstable(&self, reason: CompilerDesugaringKind, span: Span) -> Span { let mark = Mark::fresh(Mark::root()); mark.set_expn_info(codemap::ExpnInfo { call_site: span, @@ -539,73 +598,139 @@ impl<'a> LoweringContext<'a> { span.with_ctxt(SyntaxContext::empty().apply_mark(mark)) } - // Creates a new hir::GenericParam for every new lifetime and type parameter - // encountered while evaluating `f`. Definitions are created with the parent - // provided. If no `parent_id` is provided, no definitions will be returned. + /// Creates a new hir::GenericParam for every new lifetime and + /// type parameter encountered while evaluating `f`. Definitions + /// are created with the parent provided. If no `parent_id` is + /// provided, no definitions will be returned. + /// + /// Presuming that in-band lifetimes are enabled, then + /// `self.anonymous_lifetime_mode` will be updated to match the + /// argument while `f` is running (and restored afterwards). fn collect_in_band_defs( &mut self, - parent_id: Option, - f: F - ) -> (Vec, T) where F: FnOnce(&mut LoweringContext) -> T + parent_id: DefId, + anonymous_lifetime_mode: AnonymousLifetimeMode, + f: F, + ) -> (Vec, T) + where + F: FnOnce(&mut LoweringContext) -> T, { assert!(!self.is_collecting_in_band_lifetimes); assert!(self.lifetimes_to_define.is_empty()); + let old_anonymous_lifetime_mode = self.anonymous_lifetime_mode; + self.is_collecting_in_band_lifetimes = self.sess.features_untracked().in_band_lifetimes; + if self.is_collecting_in_band_lifetimes { + self.anonymous_lifetime_mode = anonymous_lifetime_mode; + } assert!(self.in_band_ty_params.is_empty()); - let res = f(self); self.is_collecting_in_band_lifetimes = false; + self.anonymous_lifetime_mode = old_anonymous_lifetime_mode; let in_band_ty_params = self.in_band_ty_params.split_off(0); let lifetimes_to_define = self.lifetimes_to_define.split_off(0); - let mut params = match parent_id { - Some(parent_id) => lifetimes_to_define.into_iter().map(|(span, name)| { - let def_node_id = self.next_id().node_id; - - // Add a definition for the in-band lifetime def - self.resolver.definitions().create_def_with_parent( - parent_id.index, - def_node_id, - DefPathData::LifetimeDef(name.as_str()), - DefIndexAddressSpace::High, - Mark::root(), - span - ); + let params = lifetimes_to_define + .into_iter() + .map(|(span, hir_name)| { + let def_node_id = self.next_id().node_id; + + // Get the name we'll use to make the def-path. Note + // that collisions are ok here and this shouldn't + // really show up for end-user. + let str_name = match hir_name { + hir::LifetimeName::Name(n) => n.as_str(), + hir::LifetimeName::Fresh(_) => keywords::UnderscoreLifetime.name().as_str(), + hir::LifetimeName::Implicit + | hir::LifetimeName::Underscore + | hir::LifetimeName::Static => { + span_bug!(span, "unexpected in-band lifetime name: {:?}", hir_name) + } + }; - hir::GenericParam::Lifetime(hir::LifetimeDef { - lifetime: hir::Lifetime { - id: def_node_id, - span, - name: hir::LifetimeName::Name(name), - }, - bounds: Vec::new().into(), - pure_wrt_drop: false, - in_band: true, - }) - }).collect(), - None => Vec::new(), - }; + // Add a definition for the in-band lifetime def + self.resolver.definitions().create_def_with_parent( + parent_id.index, + def_node_id, + DefPathData::LifetimeDef(str_name), + DefIndexAddressSpace::High, + Mark::root(), + span, + ); - params.extend(in_band_ty_params.into_iter().map(|tp| hir::GenericParam::Type(tp))); + hir::GenericParam::Lifetime(hir::LifetimeDef { + lifetime: hir::Lifetime { + id: def_node_id, + span, + name: hir_name, + }, + bounds: Vec::new().into(), + pure_wrt_drop: false, + in_band: true, + }) + }) + .chain( + in_band_ty_params + .into_iter() + .map(|tp| hir::GenericParam::Type(tp)), + ) + .collect(); (params, res) } + /// When there is a reference to some lifetime `'a`, and in-band + /// lifetimes are enabled, then we want to push that lifetime into + /// the vector of names to define later. In that case, it will get + /// added to the appropriate generics. + fn maybe_collect_in_band_lifetime(&mut self, span: Span, name: Name) { + if !self.is_collecting_in_band_lifetimes { + return; + } + + if self.in_scope_lifetimes.contains(&name) { + return; + } + + let hir_name = hir::LifetimeName::Name(name); + + if self.lifetimes_to_define + .iter() + .any(|(_, lt_name)| *lt_name == hir_name) + { + return; + } + + self.lifetimes_to_define.push((span, hir_name)); + } + + /// When we have either an elided or `'_` lifetime in an impl + /// header, we convert it to + fn collect_fresh_in_band_lifetime(&mut self, span: Span) -> hir::LifetimeName { + assert!(self.is_collecting_in_band_lifetimes); + let index = self.lifetimes_to_define.len(); + let hir_name = hir::LifetimeName::Fresh(index); + self.lifetimes_to_define.push((span, hir_name)); + hir_name + } + // Evaluates `f` with the lifetimes in `lt_defs` in-scope. // This is used to track which lifetimes have already been defined, and // which are new in-band lifetimes that need to have a definition created // for them. - fn with_in_scope_lifetime_defs( + fn with_in_scope_lifetime_defs<'l, T, F>( &mut self, - lt_defs: &[LifetimeDef], - f: F - ) -> T where F: FnOnce(&mut LoweringContext) -> T + lt_defs: impl Iterator, + f: F, + ) -> T + where + F: FnOnce(&mut LoweringContext) -> T, { let old_len = self.in_scope_lifetimes.len(); - let lt_def_names = lt_defs.iter().map(|lt_def| lt_def.lifetime.ident.name); + let lt_def_names = lt_defs.map(|lt_def| lt_def.lifetime.ident.name); self.in_scope_lifetimes.extend(lt_def_names); let res = f(self); @@ -619,11 +744,9 @@ impl<'a> LoweringContext<'a> { // This should only be used with generics that have already had their // in-band lifetimes added. In practice, this means that this function is // only used when lowering a child item of a trait or impl. - fn with_parent_impl_lifetime_defs( - &mut self, - lt_defs: &[hir::LifetimeDef], - f: F - ) -> T where F: FnOnce(&mut LoweringContext) -> T + fn with_parent_impl_lifetime_defs(&mut self, lt_defs: &[hir::LifetimeDef], f: F) -> T + where + F: FnOnce(&mut LoweringContext) -> T, { let old_len = self.in_scope_lifetimes.len(); let lt_def_names = lt_defs.iter().map(|lt_def| lt_def.lifetime.name.name()); @@ -635,47 +758,57 @@ impl<'a> LoweringContext<'a> { res } - // Appends in-band lifetime defs and argument-position `impl Trait` defs - // to the existing set of generics. + /// Appends in-band lifetime defs and argument-position `impl + /// Trait` defs to the existing set of generics. + /// + /// Presuming that in-band lifetimes are enabled, then + /// `self.anonymous_lifetime_mode` will be updated to match the + /// argument while `f` is running (and restored afterwards). fn add_in_band_defs( &mut self, generics: &Generics, - parent_id: Option, - f: F + parent_id: DefId, + anonymous_lifetime_mode: AnonymousLifetimeMode, + f: F, ) -> (hir::Generics, T) - where F: FnOnce(&mut LoweringContext) -> T + where + F: FnOnce(&mut LoweringContext) -> T, { - let (in_band_defs, (mut lowered_generics, res)) = - self.with_in_scope_lifetime_defs( - &generics.params - .iter() - .filter_map(|p| match *p { - GenericParam::Lifetime(ref ld) => Some(ld.clone()), - _ => None, - }) - .collect::>(), - |this| { - this.collect_in_band_defs(parent_id, |this| { - (this.lower_generics(generics), f(this)) - }) - } - ); + let (in_band_defs, (mut lowered_generics, res)) = self.with_in_scope_lifetime_defs( + generics.params.iter().filter_map(|p| match p { + GenericParam::Lifetime(ld) => Some(ld), + _ => None, + }), + |this| { + this.collect_in_band_defs(parent_id, anonymous_lifetime_mode, |this| { + (this.lower_generics(generics), f(this)) + }) + }, + ); - lowered_generics.params = - lowered_generics.params.iter().cloned().chain(in_band_defs).collect(); + lowered_generics.params = lowered_generics + .params + .iter() + .cloned() + .chain(in_band_defs) + .collect(); (lowered_generics, res) } fn with_catch_scope(&mut self, catch_id: NodeId, f: F) -> T - where F: FnOnce(&mut LoweringContext) -> T + where + F: FnOnce(&mut LoweringContext) -> T, { let len = self.catch_scopes.len(); self.catch_scopes.push(catch_id); let result = f(self); - assert_eq!(len + 1, self.catch_scopes.len(), - "catch scopes should be added and removed in stack order"); + assert_eq!( + len + 1, + self.catch_scopes.len(), + "catch scopes should be added and removed in stack order" + ); self.catch_scopes.pop().unwrap(); @@ -683,17 +816,19 @@ impl<'a> LoweringContext<'a> { } fn lower_body(&mut self, decl: Option<&FnDecl>, f: F) -> hir::BodyId - where F: FnOnce(&mut LoweringContext) -> hir::Expr + where + F: FnOnce(&mut LoweringContext) -> hir::Expr, { let prev = mem::replace(&mut self.is_generator, false); let result = f(self); let r = self.record_body(result, decl); self.is_generator = prev; - return r + return r; } fn with_loop_scope(&mut self, loop_id: NodeId, f: F) -> T - where F: FnOnce(&mut LoweringContext) -> T + where + F: FnOnce(&mut LoweringContext) -> T, { // We're no longer in the base loop's condition; we're in another loop. let was_in_loop_condition = self.is_in_loop_condition; @@ -703,8 +838,11 @@ impl<'a> LoweringContext<'a> { self.loop_scopes.push(loop_id); let result = f(self); - assert_eq!(len + 1, self.loop_scopes.len(), - "Loop scopes should be added and removed in stack order"); + assert_eq!( + len + 1, + self.loop_scopes.len(), + "Loop scopes should be added and removed in stack order" + ); self.loop_scopes.pop().unwrap(); @@ -714,7 +852,8 @@ impl<'a> LoweringContext<'a> { } fn with_loop_condition_scope(&mut self, f: F) -> T - where F: FnOnce(&mut LoweringContext) -> T + where + F: FnOnce(&mut LoweringContext) -> T, { let was_in_loop_condition = self.is_in_loop_condition; self.is_in_loop_condition = true; @@ -727,7 +866,8 @@ impl<'a> LoweringContext<'a> { } fn with_new_scopes(&mut self, f: F) -> T - where F: FnOnce(&mut LoweringContext) -> T + where + F: FnOnce(&mut LoweringContext) -> T, { let was_in_loop_condition = self.is_in_loop_condition; self.is_in_loop_condition = false; @@ -744,7 +884,8 @@ impl<'a> LoweringContext<'a> { } fn with_parent_def(&mut self, parent_id: NodeId, f: F) -> T - where F: FnOnce(&mut LoweringContext) -> T + where + F: FnOnce(&mut LoweringContext) -> T, { let old_def = self.parent_def; self.parent_def = { @@ -771,16 +912,19 @@ impl<'a> LoweringContext<'a> { if ident.ctxt == SyntaxContext::empty() { return ident.name; } - *self.name_map.entry(ident).or_insert_with(|| Symbol::from_ident(ident)) + *self.name_map + .entry(ident) + .or_insert_with(|| Symbol::from_ident(ident)) } fn lower_label(&mut self, label: Option