use fmt_macros::{Parser, Piece, Position};
use middle::astconv_util::prohibit_type_params;
use middle::cstore::LOCAL_CRATE;
-use middle::def;
+use middle::def::{self, Def};
use middle::def_id::DefId;
use middle::infer;
use middle::infer::{TypeOrigin, type_variable};
-> Inherited<'a, 'tcx> {
Inherited {
- infcx: infer::new_infer_ctxt(tcx, tables, Some(param_env), true),
+ infcx: infer::new_infer_ctxt(tcx, tables, Some(param_env)),
locals: RefCell::new(NodeMap()),
tables: tables,
deferred_call_resolutions: RefCell::new(DefIdMap()),
return ty;
}
- // If not, try resolving any new fcx obligations that have cropped up.
- self.select_new_obligations();
- ty = self.infcx().resolve_type_vars_if_possible(&ty);
- if !ty.has_infer_types() {
- debug!("resolve_type_vars_if_possible: ty={:?}", ty);
- return ty;
- }
-
- // If not, try resolving *all* pending obligations as much as
+ // If not, try resolving pending obligations as much as
// possible. This can help substantially when there are
// indirect dependencies that don't seem worth tracking
// precisely.
/// Return the dict-like variant corresponding to a given `Def`.
pub fn def_struct_variant(&self,
- def: def::Def,
+ def: Def,
span: Span)
-> Option<(ty::AdtDef<'tcx>, ty::VariantDef<'tcx>)>
{
let (adt, variant) = match def {
- def::DefVariant(enum_id, variant_id, _) => {
+ Def::Variant(enum_id, variant_id) => {
let adt = self.tcx().lookup_adt_def(enum_id);
(adt, adt.variant_with_id(variant_id))
}
- def::DefTy(did, _) | def::DefStruct(did) => {
+ Def::Struct(did) | Def::TyAlias(did) => {
let typ = self.tcx().lookup_item_type(did);
if let ty::TyStruct(adt, _) = typ.ty.sty {
(adt, adt.struct_variant())
Err(errors) => { report_fulfillment_errors(self.infcx(), &errors); }
}
}
-
- /// Try to select any fcx obligation that we haven't tried yet, in an effort
- /// to improve inference. You could just call
- /// `select_obligations_where_possible` except that it leads to repeated
- /// work.
- fn select_new_obligations(&self) {
- match
- self.inh.infcx.fulfillment_cx
- .borrow_mut()
- .select_new_obligations(self.infcx())
- {
- Ok(()) => { }
- Err(errors) => { report_fulfillment_errors(self.infcx(), &errors); }
- }
- }
-
}
impl<'a, 'tcx> RegionScope for FnCtxt<'a, 'tcx> {
// an "opportunistic" vtable resolution of any trait bounds on
// the call. This helps coercions.
if check_blocks {
- fcx.select_new_obligations();
+ fcx.select_obligations_where_possible();
}
// For variadic functions, we don't have a declared type for all of
// Find the relevant variant
let def = lookup_full_def(tcx, path.span, expr.id);
- if def == def::DefErr {
+ if def == Def::Err {
check_struct_fields_on_error(fcx, expr.id, fields, base_expr);
return;
}
} else if let Some(hir::QSelf { position: 0, .. }) = *maybe_qself {
// Create some fake resolution that can't possibly be a type.
def::PathResolution {
- base_def: def::DefMod(tcx.map.local_def_id(ast::CRATE_NODE_ID)),
+ base_def: Def::Mod(tcx.map.local_def_id(ast::CRATE_NODE_ID)),
last_private: LastMod(AllPublic),
depth: path.segments.len()
}
if let Some((opt_ty, segments, def)) =
resolve_ty_and_def_ufcs(fcx, path_res, opt_self_ty, path,
expr.span, expr.id) {
- if def != def::DefErr {
+ if def != Def::Err {
let (scheme, predicates) = type_scheme_and_predicates_for_def(fcx,
expr.span,
def);
node_id: ast::NodeId)
-> Option<(Option<Ty<'tcx>>,
&'a [hir::PathSegment],
- def::Def)>
+ Def)>
{
// If fully resolved already, we don't have to do anything.
pub fn check_representable(tcx: &ty::ctxt,
sp: Span,
item_id: ast::NodeId,
- designation: &str) -> bool {
+ _designation: &str) -> bool {
let rty = tcx.node_id_to_type(item_id);
// Check that it is possible to represent this type. This call identifies
// caught by case 1.
match rty.is_representable(tcx, sp) {
Representability::SelfRecursive => {
- struct_span_err!(tcx.sess, sp, E0072, "invalid recursive {} type", designation)
- .fileline_help(sp, "wrap the inner value in a box to make it representable")
- .emit();
+ let item_def_id = tcx.map.local_def_id(item_id);
+ traits::recursive_type_with_infinite_size_error(tcx, item_def_id).emit();
return false
}
Representability::Representable | Representability::ContainsRecursive => (),
// Returns the type parameter count and the type for the given definition.
fn type_scheme_and_predicates_for_def<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
sp: Span,
- defn: def::Def)
+ defn: Def)
-> (TypeScheme<'tcx>, GenericPredicates<'tcx>) {
match defn {
- def::DefLocal(_, nid) | def::DefUpvar(_, nid, _, _) => {
+ Def::Local(_, nid) | Def::Upvar(_, nid, _, _) => {
let typ = fcx.local_ty(sp, nid);
(ty::TypeScheme { generics: ty::Generics::empty(), ty: typ },
ty::GenericPredicates::empty())
}
- def::DefFn(id, _) | def::DefMethod(id) |
- def::DefStatic(id, _) | def::DefVariant(_, id, _) |
- def::DefStruct(id) | def::DefConst(id) | def::DefAssociatedConst(id) => {
+ Def::Fn(id) | Def::Method(id) |
+ Def::Static(id, _) | Def::Variant(_, id) |
+ Def::Struct(id) | Def::Const(id) | Def::AssociatedConst(id) => {
(fcx.tcx().lookup_item_type(id), fcx.tcx().lookup_predicates(id))
}
- def::DefTrait(_) |
- def::DefTy(..) |
- def::DefAssociatedTy(..) |
- def::DefPrimTy(_) |
- def::DefTyParam(..) |
- def::DefMod(..) |
- def::DefForeignMod(..) |
- def::DefLabel(..) |
- def::DefSelfTy(..) |
- def::DefErr => {
+ Def::Trait(_) |
+ Def::Enum(..) |
+ Def::TyAlias(..) |
+ Def::AssociatedTy(..) |
+ Def::PrimTy(_) |
+ Def::TyParam(..) |
+ Def::Mod(..) |
+ Def::ForeignMod(..) |
+ Def::Label(..) |
+ Def::SelfTy(..) |
+ Def::Err => {
fcx.ccx.tcx.sess.span_bug(sp, &format!("expected value, found {:?}", defn));
}
}
type_scheme: TypeScheme<'tcx>,
type_predicates: &ty::GenericPredicates<'tcx>,
opt_self_ty: Option<Ty<'tcx>>,
- def: def::Def,
+ def: Def,
span: Span,
node_id: ast::NodeId) {
debug!("instantiate_path(path={:?}, def={:?}, node_id={}, type_scheme={:?})",
let mut segment_spaces: Vec<_>;
match def {
// Case 1 and 1b. Reference to a *type* or *enum variant*.
- def::DefSelfTy(..) |
- def::DefStruct(..) |
- def::DefVariant(..) |
- def::DefTy(..) |
- def::DefAssociatedTy(..) |
- def::DefTrait(..) |
- def::DefPrimTy(..) |
- def::DefTyParam(..) => {
+ Def::SelfTy(..) |
+ Def::Struct(..) |
+ Def::Variant(..) |
+ Def::Enum(..) |
+ Def::TyAlias(..) |
+ Def::AssociatedTy(..) |
+ Def::Trait(..) |
+ Def::PrimTy(..) |
+ Def::TyParam(..) => {
// Everything but the final segment should have no
// parameters at all.
segment_spaces = vec![None; segments.len() - 1];
}
// Case 2. Reference to a top-level value.
- def::DefFn(..) |
- def::DefConst(..) |
- def::DefStatic(..) => {
+ Def::Fn(..) |
+ Def::Const(..) |
+ Def::Static(..) => {
segment_spaces = vec![None; segments.len() - 1];
segment_spaces.push(Some(subst::FnSpace));
}
// Case 3. Reference to a method.
- def::DefMethod(def_id) => {
+ Def::Method(def_id) => {
let container = fcx.tcx().impl_or_trait_item(def_id).container();
match container {
ty::TraitContainer(trait_did) => {
}
}
- def::DefAssociatedConst(def_id) => {
+ Def::AssociatedConst(def_id) => {
let container = fcx.tcx().impl_or_trait_item(def_id).container();
match container {
ty::TraitContainer(trait_did) => {
// Other cases. Various nonsense that really shouldn't show up
// here. If they do, an error will have been reported
// elsewhere. (I hope)
- def::DefMod(..) |
- def::DefForeignMod(..) |
- def::DefLocal(..) |
- def::DefLabel(..) |
- def::DefUpvar(..) |
- def::DefErr => {
+ Def::Mod(..) |
+ Def::ForeignMod(..) |
+ Def::Local(..) |
+ Def::Label(..) |
+ Def::Upvar(..) |
+ Def::Err => {
segment_spaces = vec![None; segments.len()];
}
}
// <id> nested anywhere inside the loop?
(block_query(b, |e| {
if let hir::ExprBreak(Some(_)) = e.node {
- lookup_full_def(cx, e.span, e.id) == def::DefLabel(id)
+ lookup_full_def(cx, e.span, e.id) == Def::Label(id)
} else {
false
}