-use check::{Inherited, FnCtxt};
-use constrained_type_params::{identify_constrained_type_params, Parameter};
+use crate::check::{Inherited, FnCtxt};
+use crate::constrained_type_params::{identify_constrained_type_params, Parameter};
-use hir::def_id::DefId;
+use crate::hir::def_id::DefId;
use rustc::traits::{self, ObligationCauseCode};
use rustc::ty::{self, Lift, Ty, TyCtxt, TyKind, GenericParamDefKind, TypeFoldable, ToPredicate};
use rustc::ty::subst::{Subst, Substs};
use syntax_pos::Span;
use errors::{DiagnosticBuilder, DiagnosticId};
-use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
+use rustc::hir::itemlikevisit::ItemLikeVisitor;
use rustc::hir;
/// Helper type of a temporary returned by `.for_item(...)`.
/// `F: for<'b, 'tcx> where 'gcx: 'tcx FnOnce(FnCtxt<'b, 'gcx, 'tcx>)`.
struct CheckWfFcxBuilder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
inherited: super::InheritedBuilder<'a, 'gcx, 'tcx>,
- id: ast::NodeId,
+ id: hir::HirId,
span: Span,
param_env: ty::ParamEnv<'tcx>,
}
/// not included it frequently leads to confusing errors in fn bodies. So it's better to check
/// the types first.
pub fn check_item_well_formed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) {
- let node_id = tcx.hir().as_local_node_id(def_id).unwrap();
- let item = tcx.hir().expect_item(node_id);
+ let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
+ let item = tcx.hir().expect_item_by_hir_id(hir_id);
- debug!("check_item_well_formed(it.id={}, it.name={})",
- item.id,
+ debug!("check_item_well_formed(it.hir_id={:?}, it.name={})",
+ item.hir_id,
tcx.item_path_str(def_id));
match item.node {
// won't be allowed unless there's an *explicit* implementation of `Send`
// for `T`
hir::ItemKind::Impl(_, polarity, defaultness, _, ref trait_ref, ref self_ty, _) => {
- let is_auto = tcx.impl_trait_ref(tcx.hir().local_def_id(item.id))
+ let is_auto = tcx.impl_trait_ref(tcx.hir().local_def_id_from_hir_id(item.hir_id))
.map_or(false, |trait_ref| tcx.trait_is_auto(trait_ref.def_id));
if let (hir::Defaultness::Default { .. }, true) = (defaultness, is_auto) {
tcx.sess.span_err(item.span, "impls of auto traits cannot be default");
fn for_id<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'gcx>, id: ast::NodeId, span: Span)
-> CheckWfFcxBuilder<'a, 'gcx, 'tcx> {
let def_id = tcx.hir().local_def_id(id);
+ let hir_id = tcx.hir().node_to_hir_id(id);
CheckWfFcxBuilder {
inherited: Inherited::build(tcx, def_id),
- id,
+ id: hir_id,
span,
param_env: tcx.param_env(def_id),
}
});
}
-/// Checks where clauses and inline bounds that are declared on def_id.
+/// Checks where-clauses and inline bounds that are declared on `def_id`.
fn check_where_clauses<'a, 'gcx, 'fcx, 'tcx>(
tcx: TyCtxt<'a, 'gcx, 'gcx>,
fcx: &FnCtxt<'fcx, 'gcx, 'tcx>,
if let ty::Opaque(def_id, substs) = ty.sty {
trace!("check_existential_types: opaque_ty, {:?}, {:?}", def_id, substs);
let generics = tcx.generics_of(def_id);
- // only check named existential types
- if generics.parent.is_none() {
+ // only check named existential types defined in this crate
+ if generics.parent.is_none() && def_id.is_local() {
let opaque_node_id = tcx.hir().as_local_node_id(def_id).unwrap();
if may_define_existential_type(tcx, fn_def_id, opaque_node_id) {
trace!("check_existential_types may define. Generics: {:#?}", generics);
/// through a `*const/mut T` raw pointer. If the feature is not enabled, the requirements are more
/// strict: `receiver_ty` must implement `Receiver` and directly implement `Deref<Target=self_ty>`.
///
-/// NB: there are cases this function returns `true` but causes an error to be emitted,
+/// N.B., there are cases this function returns `true` but causes an error to be emitted,
/// particularly when `receiver_ty` derefs to a type that is the same as `self_ty` but has the
/// wrong lifetime. Be careful of this if you are calling this function speculatively.
fn receiver_is_valid<'fcx, 'tcx, 'gcx>(
err.emit();
}
-fn reject_shadowing_parameters(tcx: TyCtxt, def_id: DefId) {
+fn reject_shadowing_parameters(tcx: TyCtxt<'_, '_, '_>, def_id: DefId) {
let generics = tcx.generics_of(def_id);
let parent = tcx.generics_of(generics.parent.unwrap());
let impl_params: FxHashMap<_, _> = parent.params.iter().flat_map(|param| match param.kind {
}
}
-/// Feature gates RFC 2056 - trivial bounds, checking for global bounds that
+/// Feature gates RFC 2056 -- trivial bounds, checking for global bounds that
/// aren't true.
fn check_false_global_bounds<'a, 'gcx, 'tcx>(
fcx: &FnCtxt<'a, 'gcx, 'tcx>,
span: Span,
- id: ast::NodeId)
+ id: hir::HirId)
{
use rustc::ty::TypeFoldable;
let empty_env = ty::ParamEnv::empty();
- let def_id = fcx.tcx.hir().local_def_id(id);
+ let def_id = fcx.tcx.hir().local_def_id_from_hir_id(id);
let predicates = fcx.tcx.predicates_of(def_id).predicates
.iter()
.map(|(p, _)| *p)
}
}
-impl<'a, 'tcx, 'v> Visitor<'v> for CheckTypeWellFormedVisitor<'a, 'tcx> {
- fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'v> {
- NestedVisitorMap::None
- }
-
- fn visit_item(&mut self, i: &hir::Item) {
+impl<'a, 'tcx> ItemLikeVisitor<'tcx> for CheckTypeWellFormedVisitor<'a, 'tcx> {
+ fn visit_item(&mut self, i: &'tcx hir::Item) {
debug!("visit_item: {:?}", i);
let def_id = self.tcx.hir().local_def_id(i.id);
- ty::query::queries::check_item_well_formed::ensure(self.tcx, def_id);
- intravisit::walk_item(self, i);
+ self.tcx.ensure().check_item_well_formed(def_id);
}
- fn visit_trait_item(&mut self, trait_item: &'v hir::TraitItem) {
+ fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem) {
debug!("visit_trait_item: {:?}", trait_item);
let def_id = self.tcx.hir().local_def_id(trait_item.id);
- ty::query::queries::check_trait_item_well_formed::ensure(self.tcx, def_id);
- intravisit::walk_trait_item(self, trait_item)
+ self.tcx.ensure().check_trait_item_well_formed(def_id);
}
- fn visit_impl_item(&mut self, impl_item: &'v hir::ImplItem) {
+ fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) {
debug!("visit_impl_item: {:?}", impl_item);
let def_id = self.tcx.hir().local_def_id(impl_item.id);
- ty::query::queries::check_impl_item_well_formed::ensure(self.tcx, def_id);
- intravisit::walk_impl_item(self, impl_item)
+ self.tcx.ensure().check_impl_item_well_formed(def_id);
}
}
err
}
-fn error_194(tcx: TyCtxt, span: Span, trait_decl_span: Span, name: &str) {
+fn error_194(tcx: TyCtxt<'_, '_, '_>, span: Span, trait_decl_span: Span, name: &str) {
struct_span_err!(tcx.sess, span, E0194,
"type parameter `{}` shadows another type parameter of the same name",
name)