//! used between functions, and they operate in a purely top-down
//! way. Therefore, we break lifetime name resolution into a separate pass.
-use errors::{pluralize, Applicability, DiagnosticBuilder};
-use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc::hir::map::Map;
use rustc::lint;
use rustc::middle::resolve_lifetime::*;
use rustc::ty::{self, DefIdTree, GenericParamDefKind, TyCtxt};
use rustc::{bug, span_bug};
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
+use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder};
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LOCAL_CRATE};
+use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc_hir::{GenericArg, GenericParam, LifetimeName, Node, ParamName, QPath};
use rustc_hir::{GenericParamKind, HirIdMap, HirIdSet, LifetimeParamKind};
use rustc_span::symbol::{kw, sym};
use std::mem::{replace, take};
use syntax::ast;
use syntax::attr;
-use syntax::{help, span_err, struct_span_err, walk_list};
+use syntax::walk_list;
use log::debug;
}
impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
- fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
+ type Map = Map<'tcx>;
+
+ fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> {
NestedVisitorMap::All(&self.tcx.hir())
}
| hir::ItemKind::Union(_, ref generics)
| hir::ItemKind::Trait(_, _, ref generics, ..)
| hir::ItemKind::TraitAlias(ref generics, ..)
- | hir::ItemKind::Impl(_, _, _, ref generics, ..) => {
+ | hir::ItemKind::Impl { ref generics, .. } => {
// Impls permit `'_` to be used and it is equivalent to "some fresh lifetime name".
// This is not true for other kinds of items.x
let track_lifetime_uses = match item.kind {
- hir::ItemKind::Impl(..) => true,
+ hir::ItemKind::Impl { .. } => true,
_ => false,
};
// These kinds of items have only early-bound lifetime parameters.
|| krate.impl_items.contains_key(&parent_impl_id)
|| krate.trait_items.contains_key(&parent_trait_id))
{
- span_err!(
+ struct_span_err!(
self.tcx.sess,
lifetime.span,
E0657,
"`impl Trait` can only capture lifetimes \
bound at the fn or impl level"
- );
+ )
+ .emit();
self.uninsert_lifetime_on_error(lifetime, def.unwrap());
}
}
})
{
if self.trait_ref_hack {
- span_err!(
+ struct_span_err!(
self.tcx.sess,
trait_ref.span,
E0316,
"nested quantification of lifetimes"
- );
+ )
+ .emit();
}
let next_early_index = self.next_early_index();
let scope = Scope::Binder {
gather.visit_body(body);
impl<'v, 'a, 'tcx> Visitor<'v> for GatherLabels<'a, 'tcx> {
- fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'v> {
+ type Map = Map<'v>;
+
+ fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> {
NestedVisitorMap::None
}
}
match parent.kind {
hir::ItemKind::Trait(_, _, ref generics, ..)
- | hir::ItemKind::Impl(_, _, _, ref generics, ..) => {
+ | hir::ItemKind::Impl { ref generics, .. } => {
index += generics.params.len() as u32;
}
_ => {}
}
Node::ImplItem(&hir::ImplItem { kind: hir::ImplItemKind::Method(_, body), .. }) => {
- if let hir::ItemKind::Impl(.., ref self_ty, ref impl_items) =
+ if let hir::ItemKind::Impl { ref self_ty, ref items, .. } =
self.tcx.hir().expect_item(self.tcx.hir().get_parent_item(parent)).kind
{
impl_self = Some(self_ty);
assoc_item_kind =
- impl_items.iter().find(|ii| ii.id.hir_id == parent).map(|ii| ii.kind);
+ items.iter().find(|ii| ii.id.hir_id == parent).map(|ii| ii.kind);
}
Some(body)
}
}
impl<'a> Visitor<'a> for SelfVisitor<'a> {
- fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'a> {
+ type Map = Map<'a>;
+
+ fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> {
NestedVisitorMap::None
}
}
impl<'v, 'a> Visitor<'v> for GatherLifetimes<'a> {
- fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'v> {
+ type Map = Map<'v>;
+
+ fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> {
NestedVisitorMap::None
}
}
if len == 0 {
- help!(
- db,
- "this function's return type contains a borrowed value, but \
- there is no value for it to be borrowed from"
+ db.help(
+ "this function's return type contains a borrowed value, \
+ but there is no value for it to be borrowed from",
);
self.suggest_lifetime(db, span, "consider giving it a 'static lifetime")
} else if elided_len == 0 {
- help!(
- db,
+ db.help(
"this function's return type contains a borrowed value with \
an elided lifetime, but the lifetime cannot be derived from \
- the arguments"
+ the arguments",
);
let msg = "consider giving it an explicit bounded or 'static lifetime";
self.suggest_lifetime(db, span, msg)
} else if elided_len == 1 {
- help!(
- db,
- "this function's return type contains a borrowed value, but \
- the signature does not say which {} it is borrowed from",
+ db.help(&format!(
+ "this function's return type contains a borrowed value, \
+ but the signature does not say which {} it is borrowed from",
m
- );
+ ));
true
} else {
- help!(
- db,
- "this function's return type contains a borrowed value, but \
- the signature does not say whether it is borrowed from {}",
+ db.help(&format!(
+ "this function's return type contains a borrowed value, \
+ but the signature does not say whether it is borrowed from {}",
m
- );
+ ));
true
}
}
}
impl<'v> Visitor<'v> for ConstrainedCollector {
- fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'v> {
+ type Map = Map<'v>;
+
+ fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> {
NestedVisitorMap::None
}
}
impl<'v> Visitor<'v> for AllCollector {
- fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'v> {
+ type Map = Map<'v>;
+
+ fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> {
NestedVisitorMap::None
}