use crate::session::Session;
use crate::util::nodemap::{DefIdMap, FxHashMap, FxHashSet, HirIdMap, HirIdSet};
use errors::{Applicability, DiagnosticBuilder};
-use rustc_data_structures::sync::Lrc;
use rustc_macros::HashStable;
use std::borrow::Cow;
use std::cell::Cell;
use syntax::ast;
use syntax::attr;
use syntax::ptr::P;
-use syntax::symbol::{keywords, sym};
+use syntax::symbol::{kw, sym};
use syntax_pos::Span;
use crate::hir::intravisit::{self, NestedVisitorMap, Visitor};
impl<T: PartialEq> Set1<T> {
pub fn insert(&mut self, value: T) {
- if let Set1::Empty = *self {
- *self = Set1::One(value);
- return;
- }
- if let Set1::One(ref old) = *self {
- if *old == value {
- return;
- }
- }
- *self = Set1::Many;
+ *self = match self {
+ Set1::Empty => Set1::One(value),
+ Set1::One(old) if *old == value => return,
+ _ => Set1::Many,
+ };
}
}
/// See [`NamedRegionMap`].
#[derive(Default)]
pub struct ResolveLifetimes {
- defs: FxHashMap<LocalDefId, Lrc<FxHashMap<ItemLocalId, Region>>>,
- late_bound: FxHashMap<LocalDefId, Lrc<FxHashSet<ItemLocalId>>>,
+ defs: FxHashMap<LocalDefId, FxHashMap<ItemLocalId, Region>>,
+ late_bound: FxHashMap<LocalDefId, FxHashSet<ItemLocalId>>,
object_lifetime_defaults:
- FxHashMap<LocalDefId, Lrc<FxHashMap<ItemLocalId, Lrc<Vec<ObjectLifetimeDefault>>>>>,
+ FxHashMap<LocalDefId, FxHashMap<ItemLocalId, Vec<ObjectLifetimeDefault>>>,
}
impl_stable_hash_for!(struct crate::middle::resolve_lifetime::ResolveLifetimes {
named_region_map: |tcx, id| {
let id = LocalDefId::from_def_id(DefId::local(id)); // (*)
- tcx.resolve_lifetimes(LOCAL_CRATE).defs.get(&id).cloned()
+ tcx.resolve_lifetimes(LOCAL_CRATE).defs.get(&id)
},
is_late_bound_map: |tcx, id| {
tcx.resolve_lifetimes(LOCAL_CRATE)
.late_bound
.get(&id)
- .cloned()
},
object_lifetime_defaults_map: |tcx, id| {
tcx.resolve_lifetimes(LOCAL_CRATE)
.object_lifetime_defaults
.get(&id)
- .cloned()
},
..*providers
fn resolve_lifetimes<'tcx>(
tcx: TyCtxt<'_, 'tcx, 'tcx>,
for_krate: CrateNum,
-) -> Lrc<ResolveLifetimes> {
+) -> &'tcx ResolveLifetimes {
assert_eq!(for_krate, LOCAL_CRATE);
let named_region_map = krate(tcx);
for (hir_id, v) in named_region_map.defs {
let map = rl.defs.entry(hir_id.owner_local_def_id()).or_default();
- Lrc::get_mut(map).unwrap().insert(hir_id.local_id, v);
+ map.insert(hir_id.local_id, v);
}
for hir_id in named_region_map.late_bound {
let map = rl.late_bound
.entry(hir_id.owner_local_def_id())
.or_default();
- Lrc::get_mut(map).unwrap().insert(hir_id.local_id);
+ map.insert(hir_id.local_id);
}
for (hir_id, v) in named_region_map.object_lifetime_defaults {
let map = rl.object_lifetime_defaults
.entry(hir_id.owner_local_def_id())
.or_default();
- Lrc::get_mut(map)
- .unwrap()
- .insert(hir_id.local_id, Lrc::new(v));
+ map.insert(hir_id.local_id, v);
}
- Lrc::new(rl)
+ tcx.arena.alloc(rl)
}
fn krate<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>) -> NamedRegionMap {
GenericParamKind::Lifetime { .. } => {
let (name, reg) = Region::early(&self.tcx.hir(), &mut index, ¶m);
if let hir::ParamName::Plain(param_name) = name {
- if param_name.name == keywords::UnderscoreLifetime.name() {
+ if param_name.name == kw::UnderscoreLifetime {
// Pick the elided lifetime "definition" if one exists
// and use it to make an elision scope.
elision = Some(reg);
} {
debug!("id = {:?} span = {:?} name = {:?}", id, span, name);
- if name == keywords::UnderscoreLifetime.ident() {
+ if name.name == kw::UnderscoreLifetime {
continue;
}
}
};
let type_def_id = match res {
- Res::Def(DefKind::AssociatedTy, def_id)
+ Res::Def(DefKind::AssocTy, def_id)
if depth == 1 => Some(parent_def_id(self, def_id)),
Res::Def(DefKind::Variant, def_id)
if depth == 0 => Some(parent_def_id(self, def_id)),
};
let has_self = match assoc_item_kind {
- Some(hir::AssociatedItemKind::Method { has_self }) => has_self,
+ Some(hir::AssocItemKind::Method { has_self }) => has_self,
_ => false,
};
for (i, (lifetime_i, lifetime_i_name)) in lifetimes.iter().enumerate() {
if let hir::ParamName::Plain(_) = lifetime_i_name {
let name = lifetime_i_name.ident().name;
- if name == keywords::UnderscoreLifetime.name()
- || name == keywords::StaticLifetime.name()
+ if name == kw::UnderscoreLifetime
+ || name == kw::StaticLifetime
{
let mut err = struct_span_err!(
self.tcx.sess,