use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_middle::ty::subst::Subst;
-use rustc_middle::ty::{
- self, Binder, EarlyBinder, Predicate, PredicateKind, ToPredicate, Ty, TyCtxt,
-};
+use rustc_middle::ty::{self, Binder, Predicate, PredicateKind, ToPredicate, Ty, TyCtxt};
use rustc_trait_selection::traits;
fn sized_constraint_for_ty<'tcx>(
let adt_tys = adt.sized_constraint(tcx);
debug!("sized_constraint_for_ty({:?}) intermediate = {:?}", ty, adt_tys);
adt_tys
+ .0
.iter()
- .map(|ty| EarlyBinder(*ty).subst(tcx, substs))
+ .map(|ty| adt_tys.rebind(*ty).subst(tcx, substs))
.flat_map(|ty| sized_constraint_for_ty(tcx, adtdef, ty))
.collect()
}
}
fn impl_defaultness(tcx: TyCtxt<'_>, def_id: DefId) -> hir::Defaultness {
- let item = tcx.hir().expect_item(def_id.expect_local());
- if let hir::ItemKind::Impl(impl_) = &item.kind {
- impl_.defaultness
- } else {
- bug!("`impl_defaultness` called on {:?}", item);
+ match tcx.hir().get_by_def_id(def_id.expect_local()) {
+ hir::Node::Item(hir::Item { kind: hir::ItemKind::Impl(impl_), .. }) => impl_.defaultness,
+ hir::Node::ImplItem(hir::ImplItem { defaultness, .. })
+ | hir::Node::TraitItem(hir::TraitItem { defaultness, .. }) => *defaultness,
+ node => {
+ bug!("`impl_defaultness` called on {:?}", node);
+ }
}
}
// are any errors at that point, so outside of type inference you can be
// sure that this will succeed without errors anyway.
- if tcx.sess.opts.debugging_opts.chalk {
+ if tcx.sess.opts.unstable_opts.chalk {
let environment = well_formed_types_in_env(tcx, def_id);
predicates.extend(environment);
}
constness,
);
- let body_id = hir_id.map_or(hir::CRATE_HIR_ID, |id| {
- tcx.hir().maybe_body_owned_by(id).map_or(id, |body| body.hir_id)
- });
+ let body_id =
+ local_did.and_then(|id| tcx.hir().maybe_body_owned_by(id).map(|body| body.hir_id));
+ let body_id = match body_id {
+ Some(id) => id,
+ None if hir_id.is_some() => hir_id.unwrap(),
+ _ => hir::CRATE_HIR_ID,
+ };
+
let cause = traits::ObligationCause::misc(tcx.def_span(def_id), body_id);
- traits::normalize_param_env_or_error(tcx, def_id, unnormalized_env, cause)
+ traits::normalize_param_env_or_error(tcx, unnormalized_env, cause)
}
/// Elaborate the environment.