self.missing_named_lifetime_spots.pop();
self.is_in_fn_syntax = was_in_fn_syntax;
}
- hir::TyKind::TraitObject(bounds, ref lifetime) => {
+ hir::TyKind::TraitObject(bounds, ref lifetime, _) => {
debug!("visit_ty: TraitObject(bounds={:?}, lifetime={:?})", bounds, lifetime);
for bound in bounds {
self.visit_poly_trait_ref(bound, hir::TraitBoundModifier::None);
// `type MyAnonTy<'b> = impl MyTrait<'b>;`
// ^ ^ this gets resolved in the scope of
// the opaque_ty generics
- let opaque_ty = self.tcx.hir().expect_item(item_id.id);
+ let opaque_ty = self.tcx.hir().item(item_id);
let (generics, bounds) = match opaque_ty.kind {
// Named opaque `impl Trait` types are reached via `TyKind::Path`.
// This arm is for `impl Trait` in the types of statics, constants and locals.
let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id);
// Ensure that the parent of the def is an item, not HRTB
let parent_id = self.tcx.hir().get_parent_node(hir_id);
- let parent_impl_id = hir::ImplItemId { hir_id: parent_id };
- let parent_trait_id = hir::TraitItemId { hir_id: parent_id };
- let krate = self.tcx.hir().krate();
-
- if !(krate.items.contains_key(&parent_id)
- || krate.impl_items.contains_key(&parent_impl_id)
- || krate.trait_items.contains_key(&parent_trait_id))
+ let parent_is_item = if let Some(parent_def_id) =
+ parent_id.as_owner()
{
+ let parent_item_id = hir::ItemId { def_id: parent_def_id };
+ let parent_impl_id = hir::ImplItemId { def_id: parent_def_id };
+ let parent_trait_id =
+ hir::TraitItemId { def_id: parent_def_id };
+ let parent_foreign_id =
+ hir::ForeignItemId { def_id: parent_def_id };
+ let krate = self.tcx.hir().krate();
+
+ krate.items.contains_key(&parent_item_id)
+ || krate.impl_items.contains_key(&parent_impl_id)
+ || krate.trait_items.contains_key(&parent_trait_id)
+ || krate.foreign_items.contains_key(&parent_foreign_id)
+ } else {
+ false
+ };
+
+ if !parent_is_item {
struct_span_err!(
self.tcx.sess,
lifetime.span,
E0657,
"`impl Trait` can only capture lifetimes \
- bound at the fn or impl level"
+ bound at the fn or impl level"
)
.emit();
self.uninsert_lifetime_on_error(lifetime, def.unwrap());
self.missing_named_lifetime_spots.push((&trait_item.generics).into());
let tcx = self.tcx;
self.visit_early_late(
- Some(tcx.hir().get_parent_item(trait_item.hir_id)),
+ Some(tcx.hir().get_parent_item(trait_item.hir_id())),
&sig.decl,
&trait_item.generics,
|this| intravisit::walk_trait_item(this, trait_item),
self.missing_named_lifetime_spots.push((&impl_item.generics).into());
let tcx = self.tcx;
self.visit_early_late(
- Some(tcx.hir().get_parent_item(impl_item.hir_id)),
+ Some(tcx.hir().get_parent_item(impl_item.hir_id())),
&sig.decl,
&impl_item.generics,
|this| intravisit::walk_impl_item(this, impl_item),
let result = object_lifetime_defaults_for_item(tcx, generics);
// Debugging aid.
- if tcx.sess.contains_name(&item.attrs, sym::rustc_object_lifetime_default) {
+ let attrs = tcx.hir().attrs(item.hir_id());
+ if tcx.sess.contains_name(attrs, sym::rustc_object_lifetime_default) {
let object_lifetime_default_reprs: String = result
.iter()
.map(|set| match *set {
tcx.sess.span_err(item.span, &object_lifetime_default_reprs);
}
- map.insert(item.hir_id, result);
+ map.insert(item.hir_id(), result);
}
_ => {}
}
// Therefore, we would compute `object_lifetime_defaults` to a
// vector like `['x, 'static]`. Note that the vector only
// includes type parameters.
- let object_lifetime_defaults = type_def_id.map_or(vec![], |def_id| {
+ let object_lifetime_defaults = type_def_id.map_or_else(Vec::new, |def_id| {
let in_body = {
let mut scope = self.scope;
loop {
self.tcx.hir().expect_item(self.tcx.hir().get_parent_item(parent)).kind
{
assoc_item_kind =
- trait_items.iter().find(|ti| ti.id.hir_id == parent).map(|ti| ti.kind);
+ trait_items.iter().find(|ti| ti.id.hir_id() == parent).map(|ti| ti.kind);
}
match *m {
hir::TraitFn::Required(_) => None,
{
impl_self = Some(self_ty);
assoc_item_kind =
- 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)
}
self.outer_index.shift_in(1);
}
match ty.kind {
- hir::TyKind::TraitObject(bounds, ref lifetime) => {
+ hir::TyKind::TraitObject(bounds, ref lifetime, _) => {
for bound in bounds {
self.visit_poly_trait_ref(bound, hir::TraitBoundModifier::None);
}