]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/middle/ty.rs
Rollup merge of #24072 - ebfull:explain_closure_type_err, r=pnkfelix
[rust.git] / src / librustc / middle / ty.rs
index 76581529a46f0f12156e1610c2ec9e3c5a3c06fa..0a747ba881fd62f00297e9a071f131164fd9f7c4 100644 (file)
@@ -80,7 +80,7 @@
 use collections::enum_set::{EnumSet, CLike};
 use std::collections::{HashMap, HashSet};
 use syntax::abi;
-use syntax::ast::{CrateNum, DefId, Ident, ItemTrait, LOCAL_CRATE};
+use syntax::ast::{CrateNum, DefId, ItemTrait, LOCAL_CRATE};
 use syntax::ast::{MutImmutable, MutMutable, Name, NamedField, NodeId};
 use syntax::ast::{StmtExpr, StmtSemi, StructField, UnnamedField, Visibility};
 use syntax::ast_util::{self, is_local, lit_is_str, local_def};
@@ -1092,6 +1092,13 @@ pub fn unwrap(self) -> Ty<'tcx> {
             ty::FnDiverging => unreachable!()
         }
     }
+
+    pub fn unwrap_or(self, def: Ty<'tcx>) -> Ty<'tcx> {
+        match self {
+            ty::FnConverging(t) => t,
+            ty::FnDiverging => def
+        }
+    }
 }
 
 pub type PolyFnOutput<'tcx> = Binder<FnOutput<'tcx>>;
@@ -4361,8 +4368,8 @@ pub fn named_element_ty<'tcx>(cx: &ctxt<'tcx>,
             variant_info.arg_names.as_ref()
                 .expect("must have struct enum variant if accessing a named fields")
                 .iter().zip(variant_info.args.iter())
-                .find(|&(ident, _)| ident.name == n)
-                .map(|(_ident, arg_t)| arg_t.subst(cx, substs))
+                .find(|&(&name, _)| name == n)
+                .map(|(_name, arg_t)| arg_t.subst(cx, substs))
         }
         _ => None
     }
@@ -5351,7 +5358,7 @@ pub fn ty_to_def_id(ty: Ty) -> Option<ast::DefId> {
 #[derive(Clone)]
 pub struct VariantInfo<'tcx> {
     pub args: Vec<Ty<'tcx>>,
-    pub arg_names: Option<Vec<ast::Ident>>,
+    pub arg_names: Option<Vec<ast::Name>>,
     pub ctor_ty: Option<Ty<'tcx>>,
     pub name: ast::Name,
     pub id: ast::DefId,
@@ -5398,7 +5405,7 @@ pub fn from_ast_variant(cx: &ctxt<'tcx>,
                     .map(|field| node_id_to_type(cx, field.node.id)).collect();
                 let arg_names = fields.iter().map(|field| {
                     match field.node.kind {
-                        NamedField(ident, _) => ident,
+                        NamedField(ident, _) => ident.name,
                         UnnamedField(..) => cx.sess.bug(
                             "enum_variants: all fields in struct must have a name")
                     }